← Back to Pull requests

feat(portfolio-contract)!: delegated reward claims and swaps from signed evidence #12980

Closed
unknown closed this pull request without merging on Nov 24, 2026 20:07 UTC
View on GitHub
unknown unknown commented on Nov 24, 2026 07:54 UTC
Author

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, and Planner.rebalance with a plan in its params). Reward plans never go through the asynchronous resolvePlan, 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.proof is renamed proofs, 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, assertEvmAccountRef and evmChainOf are exported from places, and evidence validation and the contract's binding both use them instead of private copies and casts.

  • portfolio-api: rewardClaimProtocols maps 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-encoded swap() 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 signed calldataSuffix (0x if none), bounded to MAX_ONE_INCH_CALLDATA_SUFFIX_BYTES (32). Swap instructions are unreleased and nothing produces them yet, so the field is required.

  • orchestration: a ContractCall may carry an optional calldataSuffix, which constructContractCall appends 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 setTargetAllocation now advances rebalanceCount too. 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. setTargetAllocation with a plan now also requires effective rebalance, so { allocation: true, rebalance: false } only updates targets.
    3. createdAtPolicyVersion is published on delegated claimRewards flows, as on rebalance flows (AGO-1284).
    4. Execution only from bound steps (feat!): MovementDesc.claimRewards / swap become ClaimRewardsSelector / SwapSelector. The old ClaimRewardsParams, SwapDesc and OneInchSwapDesc are 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 signed minAmountOut of 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 executor data or 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.
    - vetRewardSwapBudgets funds each swap from signed claimed-reward holdings 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.
    - vetRewardPlan vets 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 rebalance may now also supply a plan with signed observations, vetted against the current target.
    - Plans of rebalance and setTargetAllocation may include reward steps, given effective claimRewards.
    - 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), when setTargetAllocation supplies one.
    - Planner.claimRewards(portfolioId, params) forwards the same signed params to the planner's delegation.
    - The delegation client's methods and Planner.rebalance now return promises.
    8. Planner rebalance with signed observations: Planner.rebalance also 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 / tokenSwap summaries from their evidence, instead of their movement's claimRewards / swap, whose selector indexes refer to unpublished observations. FlowStep keeps those two fields, deprecated and loosely typed, for steps published before this upgrade. Proofs and route data are not published.
    10. Docs: agent-delegation.md and agentic-reward-claims-and-swaps.md describe 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, so maybeAutoClaim is stubbed until AGO-625.

    Security Considerations

  • New authority: agents can now claim rewards and swap reward tokens. The amounts and targets come only from attestor-signed evidence, re-checked against contract configuration at submission and again before dispatch.

  • Trust boundary: the contract trusts the attestor's claim evidence and swap routes. Its own checks limit what a compromised attestor could do:

  • - 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.
  • Existing delegations gain authority: grants signed by users only carry 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.

  • Order of checks: an unauthorized caller is rejected before any signature verification work.

  • Swap expiry is checked against the chain time at verification (verifiedAt), not again at execution. Execution still enforces the signed minAmountOut.
  • 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-api that 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 produce calldataSuffix for each swap instruction: the bytes after 1inch's ABI-encoded swap() arguments, or 0x. Readers of published flow steps should use rewardClaim / tokenSwap; new steps no longer carry claimRewards / swap (ymax-web reads neither).

    Testing Considerations

  • New reward-bindings.test.ts, covering binding, the protected-token denyset, slippage, expiry and swap budgets. one-inch.test.ts is rewritten.

  • Calldata suffix: signing, tampering, removal, malformed hex and the length bound (portfolio-api); appending, or not, in constructContractCall (orchestration); the reconstructed router call equal byte for byte to the encoded swap() 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, rebalanceCount accounting, and both Planner.rebalance forms.

  • 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.

  • Three contract-level tests of the old claim plans (core Aave, vaults Morpho/Compound) are removed, since the old plan format is gone. The Merkl scenario and the flow-level tests replace them.

  • End-to-end validation on ymax0/ymax1 is AGO-1722.
  • Upgrade Considerations

  • Deployment order:

  • - The ymax-planner stub must be deployed before or with this contract. A planner still on the old three-argument claimRewards would 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.
  • In-flight claim flows: a flow with an old-format claim or swap step has no bound step. After the upgrade it fails, when its plan is resolved or replayed, instead of claiming or swapping. Auto-claim is only enabled on ymax0, so check for in-flight claim flows there before upgrading.

  • Durable state: the additions (bound steps on plans, createdAtPolicyVersion) are all optional, so existing state needs no migration.
  • 🤖 Generated with Claude Code

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: gibson042 Review duration: 732m
    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
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 20.5% · Safe to merge
    20.5%