Skip to content

[#320] Fix SDK royalty ABI and client — wrong getRoyaltyInfo/claimRoyalties #321

@realproject7

Description

@realproject7

Context

Audit #320 confirmed (all 5 reviewers: T2-1, T2-2, T2-3, T2a, T2b) that the SDK has wrong ABI definitions and client logic for getRoyaltyInfo and claimRoyalties, verified against the actual Mint Club V2 contract source (MCV2_Royalty.sol) and PlotLink's own IMCV2_Bond.sol interface.

Additionally, the re-review against plotlink-contracts source confirmed the web app MCV2 ABI (lib/price.ts) has incorrect output types for 4 functions. These should be corrected for ABI accuracy.

Note: T2b's re-review claimed chainPlot and PlotChained are missing a title param — this is incorrect. The source at StoryFactory.sol:38-45 and :154 clearly includes title. Disregard that finding.

Part 1: Fix SDK royalty ABI and client (CRITICAL)

Bug Details

Function SDK (wrong) Contract (correct, matches web app)
getRoyaltyInfo inputs: (token, beneficiary), outputs: (unclaimed) — 1 output inputs: (wallet, reserveToken), outputs: (balance, claimed) — 2 outputs
claimRoyalties SDK client passes storyline token address Contract expects reserve token address (WETH on testnet, $PLOT on mainnet)

Impact: SDK getRoyaltyInfo() returns garbage data. SDK/CLI claimRoyalties() fails or claims the wrong asset. All royalty features in the CLI (claim, status) are broken.

Files to Change

  1. packages/sdk/src/abi.ts (lines 131-148)

    • Fix getRoyaltyInfo: inputs to (wallet: address, reserveToken: address), outputs to (balance: uint256, claimed: uint256)
    • Fix claimRoyalties: rename input to reserveToken for clarity
  2. packages/sdk/src/client.ts

    • getRoyaltyInfo() (lines 502-511): pass args as (beneficiary, reserveTokenAddress) in correct order; return both balance and claimed; resolve reserve token from tokenBond() internally or accept it as parameter
    • claimRoyalties() (lines 520-533): change parameter from storyline token to reserve token address
    • Update RoyaltyInfo type (line 102-104): add claimed field alongside unclaimed (rename to balance)
  3. packages/cli/src/commands/claim.ts

    • Already reads reserveToken from tokenBond() result (line 29) — pass it to claimRoyalties() instead of the storyline token address
  4. packages/cli/src/commands/status.ts (if it calls getRoyaltyInfo)

    • Update to match new SDK method signature

Part 2: Fix web app MCV2 ABI output types (minor, ABI accuracy)

The re-review confirmed via IMCV2_Bond.sol that 4 functions in lib/price.ts have incorrect output declarations:

Function Contract (IMCV2_Bond.sol) Web ABI (lib/price.ts) current
getReserveForToken returns (uint256 reserveAmount, uint256 royalty) 1 output only
getRefundForTokens returns (uint256 refundAmount, uint256 royalty) 1 output only
mint returns uint256 outputs: []
burn returns uint256 outputs: []

Impact: mint/burn missing returns are harmless (return values unused). getReserveForToken/getRefundForTokens — viem returns the first tuple element which is the correct cost/refund value, so trading estimates work correctly. The second value (royalty) is informational only. Not a functional bug, but ABI should match the contract for accuracy.

Files to Change

  1. lib/price.ts (lines 16-58)
    • Update getReserveForToken outputs to [{ name: "reserveAmount" }, { name: "royalty" }]
    • Update getRefundForTokens outputs to [{ name: "refundAmount" }, { name: "royalty" }]
    • Update mint outputs to [{ name: "", type: "uint256" }]
    • Update burn outputs to [{ name: "", type: "uint256" }]
    • Ensure TradingWidget.tsx still reads the correct value (first element of tuple, or destructure explicitly)

Acceptance Criteria

  • SDK getRoyaltyInfo ABI matches MCV2_Royalty contract (2 inputs, 2 outputs)
  • SDK client passes (beneficiary, reserveToken) in correct order
  • SDK claimRoyalties accepts and passes reserve token address
  • CLI claim command passes reserve token (already available from tokenBond())
  • Web app lib/price.ts MCV2 ABI output types match IMCV2_Bond.sol
  • TradingWidget trading estimates still work correctly after ABI update
  • npm run build and npm run typecheck pass

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent/T3Assigned to T3 builder agentbugSomething isn't workingphase/5-tradingPhase 5: Token Trading

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions