feat(portfolio-api): claim evidence, swap instructions, selectors and effective permissions #12973
All Vouch review confidence checks passed
Residual risk 0.30 = Change Risk (0.75) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.75 · 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
Sensitive Paths
sensitive_paths
0.075
Real PR Conversation Timeline
1 comments
"Review active on #12973"
general
weight: 0.35
gibson042
refs: AGO-1718
Description
Adds the
@agoric/portfolio-apideclarations needed for agentic reward claims and swaps (AGO-1620). The observation service (YDS) signs claim evidence and swap instructions alongside a portfolio's observations. Plan steps then select them by index. The contract will verify what was signed and derive the calls it executes from it.This PR only adds the shared API. Contract enforcement lands in AGO-1720, and YDS evidence in AGO-1719. Everything is additive: the existing
ClaimRewardsParams/SwapDescand the plan fields that use them are unchanged.getEffectivePortfolioPermissionsresolves inheritance stepwise, allocation → rebalance → claimRewards. An absent permission inherits its parent's effective value. An explicitfalseblocks inheritance, so{ allocation: true, rebalance: false }cannot claim.claimable-rewardholdings may now be attributed to an EVM account (@chain), not only to an instrument, for example unattributed Merkl rewards.PortfolioObservationsgains four optional arrays, together typed asSelectableObservationsbecause plan steps select their entries by index:aaveClaims,compoundClaimsandmerklClaims(claim evidence), andoneInchSwaps(OneInchSwapInstructions).- They use the repo-local EIP-712
optionalfield support. A message without evidence keeps exactly the current signed types and hash.- An absent array ("not requested") and an empty array ("nothing found") are distinct and both signed.
- Evidence addresses are EIP-712
addressvalues, which hash the same regardless of case, so they may be lowercase or EIP-55 checksummed, and are compared case-insensitively. Signing (viem) rejects other mixed case; like the shared EIP-712 layer, the converters don't verify checksums. HoldingtokenIds stay lowercase because they are signed as strings (AGO-1684).- The converters only check what the EIP-712 layer does not: non-zero token and distributor addresses, matching instrument/protocol, EVM account places, no duplicate claims,
claimedAmount ≤ cumulativeAmount,minAmountOut ≤ quotedAmountOut, and so on. Policy checks are left to the contract (AGO-1720).-
getMerklClaimExpectedAmountreturns the cumulative-minus-claimed increment.portfolioObservationsToEIP712validated the caller'ssyncStateand typed holdings, then read them again to build its result.reward-swaps.tswithMAX_REWARD_SWAP_SLIPPAGE_BPS = 200andgetMinAmountOutForSlippage, which rounds up. YDS and the contract share the same rule.ClaimRewardsSelector({ protocol, index }) andSwapSelector({ provider: '1inch', index }), with shapes, includingRewardClaimProtocolShapeandSwapProviderShape(for the existingSwapProvidertype). They are standalone types for now; switchingMovementDescover to them is left to AGO-1720 / AGO-625.EvmAccountRefnames an EVM@chainaccount place (and replaces existing inline spellings of it), andHexBytesis defined with orchestration's generic EIP-712 typed-data types.docs-design/agentic-reward-claims-and-swaps.mdsketches the flow, a Merkl claim → 1inch swap example, and the key invariants, including swap eligibility: until there is a separate swap permission, swapping is implied byclaimRewards, sotokenInmust be a reward token held asclaimed-rewardor claimed earlier in the same plan.Security Considerations
The new types grant no authority on their own. The contract's observation verifier uses these shared converters, so a contract built with this PR already accepts and authenticates evidence and account-level claimable holdings. Nothing acts on them yet: selecting and executing evidence stays gated on AGO-1720. New tests confirm that tampering with or dropping signed evidence fails attestor verification.
The planner's
resolvePlantakes unsigned observations, and its pattern still rejects claim evidence and swap instructions, which are only accepted from signed observations for now. Its type,PlannerPlanObservations, now says so. Whether the planner may supply them is for AGO-625 / AGO-1720.Already-deployed contract bundles reject signed fields they do not recognize. They will refuse observations that carry evidence or account-level claimable holdings until a bundle built with this API is deployed, which matches the intended deploy order (contract first).
Scaling Considerations
None. The evidence arrays are only present when explicitly requested from YDS.
Documentation Considerations
Adds the design note above. API docs are in the source.
Testing Considerations
portfolio-api: unit tests for effective permissions, account-level claimable holdings, and evidence round-trips: all 16 present/absent combinations, baseline hash unchanged, absent vs empty, digest sensitivity, invalid input on encoding and decoding, checksummed addresses signing like lowercase ones and compared case-insensitively, malformed primitives rejected by the EIP-712 layer, and use without lockdown. Also tests for the shapes, selectors, the slippage helper, and type tests.portfolio-contract:observation-verifier.test.tsverifies real viem-signed observations with evidence, and rejects tampered and stripped evidence.Upgrade Considerations
No contract or vat code changes. The old formats need no migration.
The contract does not use
getEffectivePortfolioPermissionsyet:getAuthorizedDelegationstill requires the exact permission flag. Switching it over is deferred to AGO-1720, because it expands authority. Grants signed by users only carryallocation, so on upgrade every existing{ allocation: … }agent delegation would gainrebalanceandclaimRewards. Today's test'allocation delegation cannot use rebalance'asserts the opposite. Planner grants fromsetAutoFeaturesstore explicit booleans and resolve the same either way.🤖 Generated with Claude Code