feat(portfolio-contract)!: delegated reward claims and swaps from signed evidence #12980
All Vouch review confidence checks passed
Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #12980"
general
weight: 0.35
gibson042
closes: AGO-1720
closes: AGO-1284
closes: AGO-1776
refs: AGO-1620, AGO-1718 (#12973), AGO-625, AGO-1664, AGO-1772, AGO-1747
Description
Lets a delegated agent, or the planner through its own delegation, claim protocol rewards and swap them for USDC. Each claim and swap must be backed by evidence the observation service (YDS) signed alongside the portfolio's observations (#12973). A plan step only selects evidence by index. The contract verifies the signed observations, derives the exact call it will make (a bound step), vets the whole plan before starting any flow, and executes only from bound steps.
Scope: external agents and the automatic planner submit reward plans the same way: a complete plan with signed observations, through their delegation (
Planner.claimRewards, andPlanner.rebalancewith a plan in its params). Reward plans never go through the asynchronousresolvePlan, which still rejects reward evidence; migrating that resolver to signed observations is AGO-1664. Planless rebalance and its asynchronous resolution are unchanged.Commits are focused and best reviewed one at a time. Five shared commits come first:
portfolio-api:MerklClaimEvidence.proofis renamedproofs, the name Merkl's rewards API gives the same field, in the type, its shape and its EIP-712 type. Claim evidence is unreleased and nothing produces it yet.portfolio-api:isEvmAccountRef,assertEvmAccountRefandevmChainOfare exported fromplaces, and evidence validation and the contract's binding both use them instead of private copies and casts.portfolio-api:rewardClaimProtocolsmaps each reward claim protocol to its evidence array, and Aave and Compound to the yield protocol of their instruments. Evidence validation and the contract's binding derive both from it instead of pairing names by hand.portfolio-api: the 1inch API appends bytes after the ABI-encodedswap()arguments (4 so far, per the AGO-1747 spike), of unconfirmed meaning and with no known effect on execution (AGO-1776). Swap instructions now carry them as a signedcalldataSuffix(0xif none), bounded toMAX_ONE_INCH_CALLDATA_SUFFIX_BYTES(32). Swap instructions are unreleased and nothing produces them yet, so the field is required.orchestration: aContractCallmay carry an optionalcalldataSuffix, whichconstructContractCallappends after the encoded call. Both GMP paths (legacy and router) encode through it. Calls without one encode as before.Then the contract:
1. Fix: a plan supplied with
setTargetAllocationnow advancesrebalanceCounttoo. Before, the same sync state could be reused to submit another plan.2. Effective permissions: delegated authority is checked with
getEffectivePortfolioPermissions, so permissions inherit stepwise: allocation → rebalance → claimRewards.setTargetAllocationwith a plan now also requires effectiverebalance, so{ allocation: true, rebalance: false }only updates targets.3.
createdAtPolicyVersionis published on delegatedclaimRewardsflows, as on rebalance flows (AGO-1284).4. Execution only from bound steps (
feat!):MovementDesc.claimRewards/swapbecomeClaimRewardsSelector/SwapSelector. The oldClaimRewardsParams,SwapDescandOneInchSwapDescare removed, with no compatibility for the old experimental plans.- Aave claims all accrued rewards of the token, and Compound claims whatever is owed.
- Merkl claims are now account-level (
@Chain → @Chain), for the account's own address, instead of going through an ERC4626 instrument.- 1inch swaps spend exactly
amountIn, require at least the signedminAmountOutof the configured USDC, and set no partial-fill flags.- Every bound step is re-checked against the movement and the flow's contract configuration before dispatch.
- Right after: bound swaps keep the signed
calldataSuffix, and the router call appends it after the arguments the contract reconstructs. It is not part of the executordataor of any fund-safety field, and is not published.5. Binding (
reward-bindings.ts):- Claims use only configured contracts and promise no proceeds: their payout is an estimate.
- Swaps must output the chain's configured USDC, have zero flags, be unexpired, and allow at most
MAX_REWARD_SWAP_SLIPPAGE_BPS(200) of slippage.- A swap can never spend a principal or cash token known to contract configuration, whatever the attestor signed. It fails closed if that configuration is incomplete.
-
vetRewardSwapBudgetsfunds each swap from signedclaimed-rewardholdings plus earlier claims in the same plan, counting each once.6. Plan vetting (
delegation-limits.ts):- A claim moves no value. A swap credits its account with only its enforced minimum output, which later movements may spend.
- The partial-failure check counts that minimum toward the portfolio total, which excludes rewards, but only in outcomes where the swap completed, so proceeds may be fully reinvested at the target. The vault-share mandate counts it too. This is conservative for a position already above its target, which swap proceeds cannot help grow.
-
vetRewardPlanvets claim-only plans, which need no target allocation.7. Entry points (
feat!,delegation.exo.ts,portfolio.exo.ts):- Delegated
claimRewards({ syncState, agentMemo?, plan, signedObservations })may only claim and swap.- Delegated
rebalancemay now also supply a plan with signed observations, vetted against the current target.- Plans of
rebalanceandsetTargetAllocationmay include reward steps, given effectiveclaimRewards.- Authority is checked before verifying observations and again on submission. Reward steps only act on an existing chain account, and on an existing position for Aave and Compound claims.
- Every request is fully vetted before a flow starts, so a rejected request leaves nothing behind. An accepted plan advances
rebalanceCount, as when the planner resolves one or, since (1), whensetTargetAllocationsupplies one.-
Planner.claimRewards(portfolioId, params)forwards the same signed params to the planner's delegation.- The delegation client's methods and
Planner.rebalancenow return promises.8. Planner
rebalancewith signed observations:Planner.rebalancealso accepts a plan with signed observations in its params, vetted by its delegation like any agent's. The separate-plan form still works, so the planner can switch over when ready. Exactly one plan must be supplied.9. Readable steps: claim and swap flow steps publish
rewardClaim/tokenSwapsummaries from their evidence, instead of their movement'sclaimRewards/swap, whose selector indexes refer to unpublished observations.FlowStepkeeps those two fields, deprecated and loosely typed, for steps published before this upgrade. Proofs and route data are not published.10. Docs:
agent-delegation.mdandagentic-reward-claims-and-swaps.mddescribe the entry points and the trust boundary.11. End-to-end scenario for the planner: the Merkl claim → 1inch swap contract test also runs for the planner, claiming through its delegation under the owner's auto-claim.
services/ymax-planner: automatic claims built the removed plan format, somaybeAutoClaimis stubbed until AGO-625.Security Considerations
- Swaps must output configured USDC within the slippage cap.
- Configured principal and cash tokens can never be swapped.
- Claims only target configured contracts and the portfolio's own accounts.
- For reward tokens the configuration doesn't know, attestor integrity remains an assumption. The design doc states this.
allocation. With stepwise inheritance, every existing{ allocation: … }agent delegation can also rebalance and claim rewards. This is the intended design. Planner grants store explicit booleans and are unaffected.verifiedAt), not again at execution. Execution still enforces the signedminAmountOut.Scaling Considerations
Merkl proofs and 1inch route data travel in the signed observations of each submission. They are held in the flow's bound steps but never published. Published step summaries are small.
Documentation Considerations
The design docs are updated (see above). Consumers of
@agoric/portfolio-apithat built claim or swap plans with the removed types must switch to selectors and signed evidence (YDS: AGO-1719, MCP: AGO-1721). YDS must also producecalldataSuffixfor each swap instruction: the bytes after 1inch's ABI-encodedswap()arguments, or0x. Readers of published flow steps should userewardClaim/tokenSwap; new steps no longer carryclaimRewards/swap(ymax-web reads neither).Testing Considerations
reward-bindings.test.ts, covering binding, the protected-token denyset, slippage, expiry and swap budgets.one-inch.test.tsis rewritten.portfolio-api); appending, or not, inconstructContractCall(orchestration); the reconstructed router call equal byte for byte to the encodedswap()call followed by the suffix (portfolio.flows.test.ts), and carried end to end (agentic-planning.contract.test.ts).delegation-limits.test.ts: reward steps in plan vetting.portfolio.flows.test.ts: Aave, Compound and Merkl claim execution from bound steps, and a matrix of binding mismatches rejected before dispatch.portfolio.exo.test.ts/planner.exo.test.ts: the permission matrix, up-front rejection leaving no flow behind,rebalanceCountaccounting, and bothPlanner.rebalanceforms.agentic-planning.contract.test.ts: an end-to-end Merkl claim → 1inch swap with a failed dependent swap, published summaries, and rejection of a protected token, both for an external agent and for the planner claiming under auto-claim.Upgrade Considerations
- The ymax-planner stub must be deployed before or with this contract. A planner still on the old three-argument
claimRewardswould be rejected.- YDS must index the new entry points and the two-argument planner
claimRewards(AGO-1772). Already-indexed planner claims in the old format won't parse after the API upgrade; only test transactions on ymax0 should exist in that format.createdAtPolicyVersion) are all optional, so existing state needs no migration.🤖 Generated with Claude Code