← Back to Pull requests

feat(portfolio-api): claim evidence, swap instructions, selectors and effective permissions #12973

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

refs: AGO-1718

Description

Adds the @agoric/portfolio-api declarations 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 / SwapDesc and the plan fields that use them are unchanged.

  • Effective permissions: getEffectivePortfolioPermissions resolves inheritance stepwise, allocation → rebalance → claimRewards. An absent permission inherits its parent's effective value. An explicit false blocks inheritance, so { allocation: true, rebalance: false } cannot claim.

  • Account-level claimable rewards: claimable-reward holdings may now be attributed to an EVM account (@chain), not only to an instrument, for example unattributed Merkl rewards.

  • Signed claim evidence and swap instructions: PortfolioObservations gains four optional arrays, together typed as SelectableObservations because plan steps select their entries by index: aaveClaims, compoundClaims and merklClaims (claim evidence), and oneInchSwaps (OneInchSwapInstructions).

  • - They use the repo-local EIP-712 optional field 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 address values, 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. Holding tokenIds 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).
    - getMerklClaimExpectedAmount returns the cumulative-minus-claimed increment.
  • Converters validate a copy: both observation converters now deep-copy their input once, then validate and return that copy. Before, portfolioObservationsToEIP712 validated the caller's syncState and typed holdings, then read them again to build its result.

  • Slippage cap: new Endo-free reward-swaps.ts with MAX_REWARD_SWAP_SLIPPAGE_BPS = 200 and getMinAmountOutForSlippage, which rounds up. YDS and the contract share the same rule.

  • Selectors: ClaimRewardsSelector ({ protocol, index }) and SwapSelector ({ provider: '1inch', index }), with shapes, including RewardClaimProtocolShape and SwapProviderShape (for the existing SwapProvider type). They are standalone types for now; switching MovementDesc over to them is left to AGO-1720 / AGO-625.

  • Supporting types: EvmAccountRef names an EVM @chain account place (and replaces existing inline spellings of it), and HexBytes is defined with orchestration's generic EIP-712 typed-data types.

  • Design note: docs-design/agentic-reward-claims-and-swaps.md sketches 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 by claimRewards, so tokenIn must be a reward token held as claimed-reward or 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 resolvePlan takes 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.ts verifies 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 getEffectivePortfolioPermissions yet: getAuthorizedDelegation still requires the exact permission flag. Switching it over is deferred to AGO-1720, because it expands authority. Grants signed by users only carry allocation, so on upgrade every existing { allocation: … } agent delegation would gain rebalance and claimRewards. Today's test 'allocation delegation cannot use rebalance' asserts the opposite. Planner grants from setAutoFeatures store explicit booleans and resolve the same either way.

    🤖 Generated with Claude Code

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: gibson042 Review duration: 2287m
    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
    0.75
    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
    Sensitive Paths sensitive_paths
    0.075
    Real PR Conversation Timeline
    1 comments
    "Review active on #12973"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed sensitive_module
    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: 75.2% (HIGH) · Higher = larger blast radius
    75.2%
    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: 29.7% · Safe to merge
    29.7%