BuilderBonus: Safe-only timelocked Market repoint #16
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "feat/bonus-migration"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Stacked on #15 (base
feat/circuit-breaker). Decided 2026-11-13: BuilderBonus must be able to move to a new Market when the Market is redeployed, before launch. No deployment in this PR.Design: repoint in place (chosen) vs a new BuilderBonus per Market
marketchanged by a Safe-only timelocked repoint. All program state stays in one contract: per-period builder and customer counts, cancel bars (barredUntil), exclusions,minBounty,reservedCount,awarded,totalOwedand the TSKR budget. A repoint changes only the pointer, so it can't reset any cap or bar.returnExcesswould strand the budget for unused slots. Any copy or offset scheme adds a privileged one-off import path, which is a larger surface than a pointer change.slots[market][jobId]). Job ids restart on every Market, so this avoids collisions.reserve(jobId)only takes jobs from the current Market;finalize,withdraw,expireandcancelAwardtake the slot's Market, so slots reserved before a repoint settle against the Market that reserved them. Honest in-flight bonuses are kept and a job can't be counted twice.Repoint
scheduleRepoint(newMarket): owner only; the target must be a contract that answersjobCount()with one word and must differ from the current Market; one pending repoint at a time (an expired one doesn't block). EmitsRepointScheduled(from, to, eta).executeRepoint(): owner only, frometa(REPOINT_DELAY= 48 hours) untileta + REPOINT_WINDOW(7 days), thenRepointExpired. Re-checks the target. EmitsMarketRepointed(from, to).cancelRepoint(): owner only, any time while one is scheduled. EmitsRepointCancelled(to).MarketRepointed(0, market).MIN_FEE_BPS200, the 1,000 USDCminBounty, and the 2-period bar on both parties after a cancel.Budget: funded pool plus a 10M lifetime ceiling (DECIDED 2026-11-13)
MAX_TOTAL= 10M TSKR, withtotalPaidandlifetimeCommitted() = totalPaid + committed().reserverevertsLifetimeCapReachedif the new earmark would take it above the ceiling.finalizenever hits it.reservedCount,committed() = totalOwed + reservedCount * BONUS,available() = balance - committed(floored at 0).reserverequiresavailable() >= BONUS(NotFunded), so a reserved job'sfinalizenever fails for lack of funds.returnExcesssends onlyavailable(), and only to the allocation vault.Claim deadline and expiry
claimableaggregate are removed.withdraw(market, jobIds): builder only (NotBuilder), all or nothing, per award.claimableAtuntilclaimableAt + 180 daysplus the builder's observed held time (exclusive). Before that window:TooEarly.withdrawskips ids that can never pay, and revertsNothingToWithdrawif nothing is paid. Skipped ids:NotBuilder(someone else's id, or an unknown one)BadStatus(a reservation only)TooEarlyAccountHeld/HoldCheckFailed), so a hold always blocks every payout.expirefront-run can't fail a builder's batch, and a duplicate id is paid once.expire(market, jobIds): anyone can call it. It skips ids that can't expire yet. It setsExpired, takesBONUSofftotalOwedand emitsBonusExpired. Period counts stay used and nobody is barred.claimWindow(market, jobId)returns (start, deadline).expireruns the same fail-closed hold check for the award's builder (held, revert or garbage on any Market not ignored) and skips the id, so a held builder's award is never expired.holdClock) is driven by the permissionlesspokeHold(builder);expireandwithdrawdrive it too. It starts when a hold is first observed (HoldObserved) and stops when the hold is observed cleared (HoldCleared(builder, heldFor)).heldBaselinestores the credit at award time, so holds before an award don't count.HoldPlaced/HoldRenewed/HoldLiftedand at eachuntil.isHeldcall (at most 50,000) per Market ever current, per due id, and per id of a builder whose clock is running. TheInsufficientGasguard applies.Hostile or stuck Market: revocation (M-1, L-3, L-4)
revokeMarket(m)(owner only, final, instant). It works on any Market that was ever current, including the current one, and recordsrevokedAt. After it:reserverevertsRevokedMarket()ifmis current.claimableAt <= revokedAtstill pay until their 180-day deadline.claimableAt > revokedAt) can't be withdrawn (RevokedMarket). Only the Safe can void them, withvoidAwards(m, ids), which skips other ids.finalize(m, id)(voids without callingm) orreleaseSlots(m, ids)(Reserved slots only, other ids skipped).SlotVoided.cancelAwards(m, ids, reason): owner-only batch cancel with the 2-period bars. An empty reason reverts; ids that aren't pending awards inside the 14 days are skipped, not reverted. The runbook has the Safe cancel flagged awards before revoking.Per-Market period cap (timelocked increases)
marketPeriodCapdefaults to 250 reservations and 250 awards per Market per 30-day period. It can be set from 1 to 5,000 (MAX_MARKET_PERIOD_CAP).setMarketPeriodCap(cap):MarketPeriodCapIncreaseCancelled).pendingCap,pendingCapEta,MarketPeriodCapIncreaseScheduled).BadCap.executeMarketPeriodCap()runs from 48 hours after scheduling until 7 days after that (TooEarly/RepointExpired).cancelMarketPeriodCap()cancels a pending increase. A new schedule replaces the old one and restarts the delay.MarketPeriodCapReached; it can be retried next period.Withdraw hold checks: fail closed (L-1, L-2)
withdrawcallsisHeld(50,000 gas each) on every Market that was ever current, revoked or not.truerevertsAccountHeld(account).HoldCheckFailed(market). The skip-and-event behaviour is removed.InsufficientGas()guard is kept, so the caller must forward enough gas for each check.scheduleIgnoreHolds(m)(IgnoreHoldsScheduled(m, eta)), thenexecuteIgnoreHolds(m)from 48 hours to 7 days after (HoldsIgnoredSet(m, true)).cancelIgnoreHolds(m)(IgnoreHoldsCancelled). An unexecuted schedule expires.honourHolds(m)clears the flag and any pending schedule at once (HoldsIgnoredSet(m, false)).ABI changes (BuilderBonus, vs
main)scheduleRepoint(address)0x36f3b04c,executeRepoint()0x89c8f6d0,cancelRepoint()0x196cfe2a,pendingMarket()0xe70f15eb,pendingMarketEta()0xe47c081a,REPOINT_DELAY()0xe3e6e243,REPOINT_WINDOW()0x7384dc06.market()is now a storage variable.finalize(address,uint256)0x0553e156,cancelAward(address,uint256,string)0x67cec78d,slots(address,uint256)0xb5f95d9b,qualifies(address,uint256,Job)0xb73e4204.reserve(uint256)is unchanged.withdraw(address,uint256[])0x8293744bandexpire(address,uint256[])0x6fee75aaclaimWindow(address,uint256)0x027e5c46,committed()0x9b6b9664,available()0x48a0d754,reservedCount()0xc38f7617,CLAIM_WINDOW()0x9f34fc80revokeMarket(address)0x29527b82,releaseSlots(address,uint256[])0xc178e524,voidAwards(address,uint256[])0x3f96408c,cancelAwards(address,uint256[],string)0x919e49e0setMarketPeriodCap(uint256)0x92f5bf77,executeMarketPeriodCap()0xc3a8db8a,cancelMarketPeriodCap()0x37a53dac,pendingCap()0x200ad79c,pendingCapEta()0x65621dc5scheduleIgnoreHolds(address)0x7bc6be3b,executeIgnoreHolds(address)0x79f651a8,cancelIgnoreHolds(address)0x54df62c5,honourHolds(address)0x498f0368marketPeriodCap()0xf431f3ad,marketPeriod(address,uint256)0x6db3fb58,marketState(address)0xa7a9a62c(known, revoked, holdsIgnored, revokedAt, ignoreHoldsEta),markets(uint256)0xb1283e77,marketsLength()0xa5402544,DEFAULT_MARKET_PERIOD_CAP()0x3cd5bc0b,MAX_MARKET_PERIOD_CAP()0xe7206f84,HOLD_CHECK_GAS()0xb7b9e33eClaimExpired()(past-deadline ids are skipped now),withdraw()0x3ccfd60b,unlock(address,uint256)0x7eee288d,claimable(address)0x402914f5,slotsUsed()0xbee2d1cf,MAX_BONUSES()0x88023256; eventBonusUnlockedand errorCapReached().SlotReserved(uint256 indexed jobId, address indexed builder, uint256 indexed period, uint256 reservedCount, address market)0x1911f691a9a4766962588fb14bcce650bae92d9a25a8869cc824064f6d3b26e9. Its 4th field is now the earmarked reservation count, not slots used.BonusAwarded(... address indexed market, uint256 amount, uint256 awarded, uint64 claimableAt)0x01021a989f04d43e7cd1eb76cb40037dafc4d84d7d7b6d4c0b8dff11e2466a90BonusCancelled(...)0xd4d838bf34f94c61dad05f2d5d83a2ebc6a2c6c979f23a736d958708f462ceb9SlotReleased(...)0x83e3981d6ea372aa363d0ca739f3831b5c7eaa1da23df45f0b8c0b9c401c1b57BonusClaimed(uint256 indexed jobId, address indexed builder, address indexed market, uint256 amount)0xf957dcd5d8e121c35d1be9e62b9e9b9a01e2bd4088b0358745836a2809f5d62fBonusExpired(...)0x9b40822509ce8549f5979de7f8d513461d9f2359335be1564578a5705d5705c4RepointScheduled0xcf0d8c2cec18428c57ea056f7768ae93fa7d9950f767b54be022d23a9881d53aRepointCancelled0x38583e2bc13a49188425acd641a802373dc0fdebd4120858b6a1b0bf8b8d1cd0MarketRepointed0xdc87b3539265de7805d26cb20f770a3009bab8e3608eaeb3ac15feece65af3a8MarketRevoked(address indexed)0x773e25ce1a503d1493ecf52f9b9b5cf4ae9ea2ba1dd06ffc052feac43ea0a013SlotVoided0x1037a3de4085d54a686f9833ac1a984ff83733bdf76ee2d787e3929e23107035MarketPeriodCapSet(uint256)0xa48057cfd44812b421bbf99e7074b1bbcafc74eef7304fe42a6ba8a0b805f436MarketPeriodCapIncreaseScheduled(uint256,uint64)0x6f90721656d2d051a59a65530e146d70bcca3a54b88cf53ff347651d514c3015MarketPeriodCapIncreaseCancelled(uint256)0xd03c3f65f7e4449b2da250aa5050b0434bfaef705e5e99c1d066c998769bebb5IgnoreHoldsScheduled(address indexed,uint64)0x1a8bcb24cb2d40ea8cfdb6ce6d92ada3354241cf985d6c42d2ac81e882816d62IgnoreHoldsCancelled(address indexed)0xf03c657948f07477e2f3661a9005813ee490542e7c0bdea36529f163778387e3HoldsIgnoredSet(address indexed,bool)0xcb08c9fdfaf2cc058ac62ab8741e1ed89bc52b8758686a6ec718023eb79ea70dHoldObserved(address indexed builder)0xcb725322f71f7b6df17f15b2b5aa08631d40ac673142b181ba455da4038c40edHoldCleared(address indexed builder, uint256 heldFor)0xf4b8699323f3ce580372a8fd4934bd4ce95db85feaf1cf53c7042cf82b616b04bb06199: eventHoldCheckFailed(address,address)0x2d8223d4…. It is now an error,HoldCheckFailed(address)0x66af4bf0.MAX_TOTAL()0xcd60fe35(same selector as before, now the lifetime TSKR ceiling),totalPaid()0xe7b0f666,lifetimeCommitted()0x183a5e82,pokeHold(address)0x300c0699,holdClock(address)0x73428ab3(since, credit),heldBaseline(address,uint256)0x9771078c; errorLifetimeCapReached()0x5537755e.BadMarket(),RepointPending(),NoRepoint(),RepointExpired(),RevokedMarket(),MarketPeriodCapReached(),BadCap(),InsufficientGas(),NotBuilder(),NotPending(),HoldCheckFailed(address).abis/arbitrum-sepoliais not changed: it describes the deployed contracts.Tests
test/BonusRepoint.t.sol(18): schedule/execute/cancel/expiry with boundaries, access, target checks, carry-over of counts, bars, exclusions and budget, old-Market slots settle in place, and a hostile Market bounded by the caps and the pool.test/BonusRevoke.t.sol(20):voidAwardsreverts for non-owners); the Safe voids the unmatured ones; nobody is barred.revokedAtstill pays and still expires; an unmatured one can't be withdrawn.finalizevoids on a revoked Market; a stuck Market's reservations can be released permissionlessly;cancelAwardsskips mixed ids (matured, withdrawn, cancelled, reserved, unknown).withdraw, also after revoke; a revoked Market's real hold blocks.honourHoldsis instant.test/BonusPool.t.sol(18):test/BuilderBonus.t.solandtest/invariant/BonusInvariant.t.sol(accounting: withdrawn + expired + owed == awarded; runs start at 4,990 awarded to cross the former 5,000).test/BonusLifetime.t.sol(14):expireneeds gas.MAX_TOTAL: paid, owed and earmarked count toward it; a withdrawal frees nothing; cancel, void, expiry and release free headroom.test/BonusPool.t.sol,test/BonusRevoke.t.sol): expired, swept-ahead, claimed, cancelled, released, past-deadline and duplicate ids are skipped;NotBuilder, unknown, reserved,TooEarlyand holds still revert; on a revoked Market an unmatured id is skipped while the matured one pays.invariant_LifetimeCap.forge testwith the fork RPC set: 342 passed, 0 failed, 0 skipped.forge coverage --ir-minimumon BuilderBonus: 100% branches (83/83), 100% functions, 99.3% statements and 99.0% lines. The 3 lines reported as unhit are mapping artifacts of--ir-minimum; the tests exercise them: the instant cap decrease,cancelMarketPeriodCap, and withdraw closing a cleared hold clock.Size
BuilderBonus runtime is 14,479 B (10,097 B under the limit). TaskulerMarket is unchanged at 24,146 B (430 B margin).
Docs
revokedAt, cap default 250 with timelocked increases, 48-hour repoint delay, pool as the only limit, 180-day deadline, fail-closed holds with a timelocked ignore flag; 2:01 PM decisions confirmed by George directly; 2:51 PM: L-5 hold clock and the 10M lifetime ceiling).honourHolds); cap increase timelock; monitoring of the new events; the Safe runsvoidAwardson a revoked Market's unmatured awards right after the revoke; the keeper callspokeHoldon Market hold events and at eachuntil.feat/circuit-breaker(e04d98e) in, with no force push.marketand the old ABI, so Sepolia needs a fresh BuilderBonus and a deploy PR after this merges.