1. Bot Identity
| Layer | Strategy Strategy |
|---|
| Bot class | Alpha Strategy |
|---|
| Authority | Trade |
|---|
| Status | PLANNED |
|---|
| Readiness | Spec started |
|---|
| Runs before | Risk guardrail pipeline |
|---|
| Runs after | Observation bus / internal analytics |
|---|
| Applies to | User pUSD balances that exceed idle_threshold_usd after maintaining min_reserve_pct, eligible for rotation to whitelisted yield routes |
|---|
| Default mode | shadow_only |
|---|
| User-visible | Advanced details only |
|---|
| Developer owner | Polytraders core — Strategy pod |
|---|
2. Purpose
FundingRotationBot manages idle pUSD capital by rotating between pre-approved safe-yield routes and Polymarket deployment, ensuring the user's deployable budget is efficiently allocated without exceeding configured reserve requirements. All rotation decisions require the user's opt-in and stay within a whitelisted route set.
3. Why This Bot Matters
Yield route fails while capital is deployed
If the external yield route experiences issues while capital is locked in it, the bot may be unable to recall capital to Polymarket when new opportunities arise.
Stale input data
Acting on stale signals for FundingRotationBot produces trades based on outdated market conditions, generating adverse fills.
Emitting OrderIntents while KillSwitch is active bypasses risk controls.
No worked examples on this bot yet. Worked examples are optional but strongly recommended — they turn an abstract failure mode into something a developer can verify in a fixture.
6. Parameter Guide
| Parameter | Default | Warning | Hard | What it controls |
|---|
| idle_threshold_usd | 1000 | 500 | 100 | Minimum idle pUSD balance before the bot considers rotating capital to a yield route. |
| min_reserve_pct | 0.2 | 0.1 | 0.05 | Minimum fraction of total balance to keep as liquid pUSD reserve, never deployed. |
| route_whitelist | ['aave_polygon_pusdc', 'idle_polymarket'] | None | None | Whitelist of approved capital rotation routes. Only routes on this list may receive deployed capital. |
| require_user_optin | True | None | None | If true, capital rotation requires explicit one-time user opt-in for each new route. |
7. Detailed Parameter Instructions
idle_threshold_usd
What it means
Minimum idle pUSD balance before the bot considers rotating capital to a yield route.
Default
{ "idle_threshold_usd": 1000 }
Why this default matters
1000 pUSD threshold avoids excess rotation on small balances where gas costs and fees exceed yield.
Threshold logic
| Condition | Action |
|---|
| >= 1000 pUSD | Evaluate rotation |
| 500–1000 pUSD | WARN FRB_LOW_IDLE; proceed with caution |
| < 100 pUSD | SKIP FRB_BELOW_ROTATION_FLOOR |
Developer check
if idle_usd < params.hard: return skip('FRB_BELOW_ROTATION_FLOOR')
User-facing English
Idle balance too low for capital rotation.
min_reserve_pct
What it means
Minimum fraction of total balance to keep as liquid pUSD reserve, never deployed.
Default
{ "min_reserve_pct": 0.2 }
Why this default matters
20% reserve ensures liquidity for new opportunities without full capital lock-up.
Threshold logic
| Condition | Action |
|---|
| >= 20% | Maintain reserve; rotate remainder |
| 10–20% | WARN FRB_LOW_RESERVE |
| < 5% | HARD_REJECT FRB_RESERVE_BREACH |
Developer check
if reserve_pct < params.hard: return skip('FRB_RESERVE_BREACH')
User-facing English
Reserve requirement would be breached; rotation blocked.
route_whitelist
What it means
Whitelist of approved capital rotation routes. Only routes on this list may receive deployed capital.
Default
{ "route_whitelist": ["aave_polygon_pusdc", "idle_polymarket"] }
Why this default matters
Restricts rotation to vetted, low-risk yield routes.
Threshold logic
| Condition | Action |
|---|
| route not in whitelist | HARD_REJECT FRB_ROUTE_NOT_WHITELISTED |
Developer check
if route not in params.route_whitelist: return skip('FRB_ROUTE_NOT_WHITELISTED')
User-facing English
The rotation route is not on the approved list.
require_user_optin
What it means
If true, capital rotation requires explicit one-time user opt-in for each new route.
Default
{ "require_user_optin": true }
Why this default matters
Prevents automated capital movement without user awareness.
Threshold logic
| Condition | Action |
|---|
| not opted in | HARD_REJECT FRB_OPTIN_REQUIRED |
Developer check
if require_user_optin and not user_optedin: return skip('FRB_OPTIN_REQUIRED')
User-facing English
User opt-in is required before capital can be rotated to this route.
8. Default Configuration
{
"bot_id": "strat.fundingrotationbot",
"version": "0.1.0",
"mode": "shadow_only",
"defaults": {
"idle_threshold_usd": 1000,
"min_reserve_pct": 0.2,
"route_whitelist": [
"aave_polygon_pusdc",
"idle_polymarket"
],
"require_user_optin": true
},
"locked": {
"idle_threshold_usd": {
"min": 100
},
"min_reserve_pct": {
"min": 0.05
}
}
}
9. Implementation Flow
- Check KillSwitch; if active, emit no OrderIntents.
- FETCH FundingRotationBot analytics signal from internal engine.
- IF signal below hard floor: SKIP, emit sampled DecisionReport FRB_NO_EDGE.
- FETCH clob_public market status; skip if closed or resolved.
- FETCH ws_market book; compute current mid and available depth.
- IF signal < warning threshold: WARN FRB_MARGINAL; reduce size 50%.
- Compute order size = min(max_size_param, available_depth).
- EMIT IOC OrderIntent with builder code.
- EMIT DecisionReport with intent_emitted=true, reason=FRB_TRADE.
10. Reference Implementation
Pseudocode is language-agnostic. FETCH = read input. EMIT = produce output. IF/THEN/ELSE = decision. Translate directly to TypeScript, Python, Go, or Rust.
FUNCTION onSignalUpdate(market_id, signal):
ks = FETCH internal.killswitch.status
IF ks.active: RETURN
// Hard floor gate
IF signal.score < params.idle_threshold_usd_hard:
IF random() < 0.01:
EMIT DecisionReport(intent_emitted=false, reason='FRB_NO_EDGE')
RETURN
mkt = FETCH clob_public.GET('/markets/' + market_id)
IF mkt.closed OR mkt.resolved: RETURN
// Warning threshold check
sizeMultiplier = 0.5 IF signal.score < params.idle_threshold_usd_warn ELSE 1.0
IF sizeMultiplier < 1.0: WARN('FRB_MARGINAL')
// Book snapshot
book = FETCH ws_market.book(market_id)
mid = (book.best_bid + book.best_ask) / 2
depth = FETCH clob_public.depth(market_id)
// Size computation
orderSize = toPusdUnits(min(params.min_reserve_pct * sizeMultiplier, depth.available))
EMIT OrderIntent(market=market_id, outcome='YES', side='buy', price=mid,
size_pUSD=orderSize, tif='IOC', builder=internalBuilderCode)
EMIT DecisionReport(intent_emitted=true, signal_score=signal.score,
reason='FRB_TRADE')
SDK calls used
ws_market.subscribe('book', [market_id])fetchClobPublic('/markets/' + market_id)internal.analyticsEngine.signal(market_id)buildOrderTypedData(orderParams, {name:'CTFExchange', version:'2', chainId:137})internal.builder_code
Complexity: O(1) per signal update per market
11. Wire Examples
Input — what arrives on the wire
FundingRotationBot analytics signal — internal (analytics engine)
{
"market_id": "0xfundingr000000000000000000000000000000000000000000000000000000000001",
"signal_score": "0.75",
"received_at_ms": 1746790800000
}
Output — what the bot emits
OrderIntent — FundingRotationBot IOC buy YES
{
"intent_id": "oi_01HFRB0000001A",
"market_id": "0xfundingr000000000000000000000000000000000000000000000000000000000001",
"outcome": "YES",
"side": "buy",
"price": "0.540",
"size_pUSD": "200.00",
"tif": "IOC",
"builder": {
"code": "0x706f6c7974726164657273000000000000000000000000000000000000000000",
"fee_bps": 25
},
"decision": {
"signal_score": 0.75,
"reasons": [
"FRB_TRADE"
]
}
}
12. Decision Logic
APPROVE
All gates passed, KillSwitch inactive, market open. Emit IOC OrderIntent.
RESHAPE_REQUIRED
Not applicable — reshaping handled by downstream Risk guardrail.
REJECT
Signal below hard floor; stale data; market closed; KillSwitch active.
WARNING_ONLY
Signal in warning zone triggers 50% size reduction.
13. Standard Decision Output
This bot returns a OrderIntent object. See OrderIntent schema.
{
"intent_id": "oi_01HFRB0000001A",
"trace_id": "tr_01HFRB000TR001",
"market_id": "0xfundingr000000000000000000000000000000000000000000000000000000000001",
"outcome": "YES",
"side": "buy",
"price": "0.540",
"size_pUSD": "200.00",
"tif": "IOC",
"post_only": false,
"builder": {
"code": "0x706f6c7974726164657273000000000000000000000000000000000000000000",
"fee_bps": 25
},
"negrisk_aware": false,
"decision": {
"signal_score": 0.75,
"reasons": [
"FRB_TRADE"
]
},
"comment": "fees are operator-set at match time in V2 \u2014 feeRateBps is NOT on the signed order"
}
14. Reason Codes
| Code | Severity | Meaning | Action | User-facing message |
|---|
FRB_TRADE | INFO | All gates passed. IOC OrderIntent emitted for FundingRotationBot. | Emit IOC OrderIntent. | A FundingRotationBot trade was placed. |
FRB_MARGINAL | WARN | Edge is within the warning threshold; size reduced 50%. | Emit at 50% size; log warning. | A small edge was found; a reduced-size FundingRotationBot trade was placed. |
FRB_NO_EDGE | INFO | Edge below hard floor. Skipping. | Skip; emit sampled DecisionReport. | The edge was too small to justify a trade. |
FRB_HARD_REJECT | HARD_REJECT | A critical gate condition blocked the trade (stale data, kill switch, or hard parameter breach). | Skip; no OrderIntent. | A safety condition blocked the trade. |
KILL_SWITCH_ACTIVE | HARD_REJECT | Global kill switch is active. | Skip all markets; no OrderIntents emitted. | Trading is currently paused. |
15. Metrics & Logs
Metrics emitted
| Metric | Type | Unit | Labels | Meaning |
|---|
polytraders_strat_fundingrotationbot_decisions_total | counter | count | verdict, reason_code | Total evaluation cycles by verdict and reason code. |
polytraders_strat_fundingrotationbot_signal_score | histogram | score | | Distribution of analytics signal scores at evaluation. |
polytraders_strat_fundingrotationbot_intents_emitted_total | counter | count | outcome | Total IOC OrderIntents emitted. |
polytraders_strat_fundingrotationbot_eval_latency_ms | histogram | milliseconds | | Latency from signal receipt to OrderIntent emit. |
Alerts
| Alert | Condition | Severity | Runbook |
|---|
FundingRotationBotStaleFeed | rate(polytraders_strat_fundingrotationbot_decisions_total{reason_code='STALE_MARKET_DATA'}[5m]) > 0.1 | warn | #runbook-fundingrotationbot-stale |
FundingRotationBotKillSwitch | rate(polytraders_strat_fundingrotationbot_decisions_total{reason_code='KILL_SWITCH_ACTIVE'}[1m]) > 0 | page | #runbook-killswitch |
FundingRotationBotNoEdge | rate(polytraders_strat_fundingrotationbot_decisions_total{verdict='skip',reason_code='FRB_NO_EDGE'}[10m]) / rate(polytraders_strat_fundingrotationbot_decisions_total[10m]) > 0.95 | warn | #runbook-fundingrotationbot-edge |
16. Developer Reporting
{
"bot_id": "strat.fundingrotationbot",
"market_id": "0xfundingr000000000000000000000000000000000000000000000000000000000001",
"signal_score": 0.75,
"intent_emitted": true,
"reason": "FRB_TRADE",
"emitted_at_ms": 1746790800000
}
17. Plain-English Reporting
| Situation | User-facing explanation |
|---|
| FundingRotationBot trade placed | The FundingRotationBot strategy detected a suitable opportunity and placed a trade. |
| Edge too small — no trade | The signal was below the minimum threshold. No trade was placed. |
| Safety gate active — no trade | A safety condition (stale data, kill switch, or parameter limit) blocked the trade. |
18. Failure-Mode Block
| main_failure_mode | If the external yield route experiences issues while capital is locked in it, the bot may be unable to recall capital to Polymarket when new opportunities arise. |
|---|
| false_positive_risk | Signal mis-fires when market conditions change rapidly, producing trades that quickly move against the FundingRotationBot thesis. |
|---|
| false_negative_risk | Hard floor set too conservatively misses genuine opportunities. |
|---|
| safe_fallback | If ws_market feed stale or analytics signal unavailable, skip without emitting any OrderIntent. |
|---|
| required_dependencies | ws_market, clob_public, internal FundingRotationBot analytics engine, KillSwitch, internal builder code |
|---|
19. Failure-Injection Recipes
| Scenario | How to inject | Expected behaviour | Recovery |
|---|
SIGNAL_UNAVAILABLE | Cut internal analytics engine connection | | Automatic when engine reconnects. |
HARD_FLOOR_BREACH | Inject signal below hard floor | | Automatic on next valid signal. |
KILL_SWITCH_ON | Set killswitch.active=true | | Automatic on manual KillSwitch reset. |
20. State & Persistence
Cold-start recovery
On cold start, signals rebuilt from next analytics engine poll.
21. Concurrency & Idempotency
| Aspect | Specification |
|---|
| Execution model | actor-per-market |
| Max in-flight | 25 |
| Idempotency key | intent_id |
| Per-call timeout (ms) | 300 |
| Backpressure strategy | drop oldest signal per market_id when queue > 2 |
| Locking / mutual exclusion | per-market_id mutex for signal state |
22. Dependencies
Depends on (must run first)
| Bot | Why | Contract |
|---|
| risk.kill_switch | Checked first; blocks all intent emission when active. | |
Emits to (downstream consumers)
External services
| Service | Endpoint | SLA assumed | On failure |
|---|
| Polymarket CLOB WebSocket (ws_market) | | best-effort | |
| Internal FundingRotationBot analytics engine | | internal SLA | |
23. Security Surfaces
Abuse vectors considered
- Signal injection to produce false FundingRotationBot trades
- Order sizing parameter manipulation to exceed position limits
Mitigations
- FundingRotationBot analytics signals sourced from authenticated internal engine only
- Hard limits on position size enforced before OrderIntent emission
- Builder code injected from secure internal config
24. Polymarket V2 Compatibility
| Aspect | Value |
|---|
| CLOB version | v2 |
| Collateral asset | pUSD |
| EIP-712 Exchange domain version | 2 |
| Aware of builderCode field | yes |
| Aware of negative-risk markets | no |
| Multi-chain ready | no |
| SDK used | py-clob-client-v2 |
| Settlement contract | CTFExchangeV2 |
| Notes | Bot not yet implemented; designed against V2 schema (pUSD, builder codes, V2 EIP-712 domain). feeRateBps not present on any signed OrderIntent. |
API surfaces declared
clob_publicclob_authdatainternal
Networks supported
polygon
25. Versioning & Migration
| Field | Value |
|---|
| spec | 2.0.0 |
| implementation | 0.1.0 |
| schema | 2 |
| released | None |
| planned_release | Q3-2026 |
Migration history
| Date | From | To | Reason | Action taken |
|---|
| 2026-04-28 | n/a | v2-spec | Spec drafted post-CLOB-V2 cutover; bot not yet implemented | Designed against V2 schema (pUSD, builder codes, V2 EIP-712 domain) |
26. Acceptance Tests
Unit Tests
| Test | Setup | Expected result |
|---|
| Emit IOC when signal=0.75 and all gates pass | standard config | IOC OrderIntent; reason=FRB_TRADE |
| Skip when signal below hard floor | signal=below_hard | No OrderIntent; sampled reason=FRB_NO_EDGE |
| Skip when KillSwitch active | killswitch.active=true | No OrderIntents emitted |
Integration Tests
| Test | Expected result |
|---|
| Full cycle: signal → computation → IOC OrderIntent on Polygon testnet | Order has builder.code, no feeRateBps, EIP-712 domain v2 |
Property Tests
| Property | Required behaviour |
|---|
| Bot never emits OrderIntent when KillSwitch is active | Always true |
| feeRateBps never present on any signed OrderIntent | Always true |
27. Operational Runbook
FundingRotationBot incidents are typically stale analytics feeds or kill-switch activations. Hard-floor skips are normal.
On-call actions
| Alert | First step | Diagnosis | Mitigation | Escalate to |
|---|
FundingRotationBotStaleFeed | | | | |
FundingRotationBotKillSwitch | | | | |
FundingRotationBotNoEdge | | | | |
Manual overrides
Healthcheck
GET /internal/health/fundingrotationbot -> 200 if Analytics engine active; signal age < 60s; KillSwitch inactive.. Red: Analytics engine down or KillSwitch active..
29. Developer Checklist
Ready-to-ship score: 27/27 sections complete · 100%
| Requirement | Status |
|---|
| Purpose defined | ✓ done |
| Required inputs listed | ✓ done |
| Parameters defined | ✓ done |
| Defaults defined | ✓ done |
| Warning thresholds defined | ✓ done |
| Hard thresholds defined | ✓ done |
| Safe fallback defined | ✓ done |
| Structured output defined | ✓ done |
| Developer log defined | ✓ done |
| Plain-English explanation | ✓ done |
| Unit tests defined | ✓ done |
| Integration tests defined | ✓ done |
| Property tests defined | ✓ done |
| Failure-mode block complete | ✓ done |
| Reference implementation pseudocode | ✓ done |
| Wire examples (input + output) | ✓ done |
| Reason codes listed | ✓ done |
| Metrics & logs defined | ✓ done |
| State & persistence defined | ✓ done |
| Concurrency & idempotency defined | ✓ done |
| Dependencies declared | ✓ done |
| Security surfaces declared | ✓ done |
| Polymarket V2 compatibility declared | ✓ done |
| Version & migration history declared | ✓ done |
| Operational runbook defined | ✓ done |
| Promotion gates defined | ✓ done |
| Failure-injection recipes defined | ✓ done |