feat: per-token settlement balances#547
Merged
greatest0fallt1me merged 1 commit intoJun 27, 2026
Merged
Conversation
Track balances per (developer, token) tuple instead of single-token. Add migration helper for legacy DeveloperBalanceV1 entries. All receive_payment, withdraw, batch, and view functions accept a token parameter. Vault contract updated to pass token. Closes CalloraOrg#495
|
@jerryjuche Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
Contributor
|
Merged via direct push to main (admin) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
close #495
Summary
Implements per-token settlement support for multi-asset revenue tracking (Closes #495).
What changed
contracts/settlement/src/types.rs(new):StorageKey::DeveloperBalance(Address, Address)— map keyed by(developer, token). LegacyDeveloperBalanceV1(Address)retained for migration. AddedMAX_BATCH_SIZE(50) andMAX_DEVELOPER_BALANCES_PAGE_SIZE(100) constants.DeveloperBalancestruct includestokenfield.contracts/settlement/src/lib.rs: Allreceive_payment,batch_receive_payment,withdraw_developer_balance,force_credit_developer, and view functions now accept atoken: Addressparameter. Themigrate_developer_balancefunction reads legacyDeveloperBalanceV1and writes to per-tokenDeveloperBalance(dev, usdc).contracts/settlement/src/test_multi_asset.rs(new): 10 tests covering:contracts/vault/src/lib.rs: Settlement trait updated to passtoken: Address. Bothdeductandbatch_deductnow pass the underlying token address.contracts/settlement/src/test.rs,test_invariant.rs,test_views.rs,vault/test_reentrancy.rs,tests/e2e_full_cycle.rs: Updated all call sites for new signatures.Key design decisions
StorageKey::DeveloperBalance(dev, token)— O(1) point read/write, no iterationDeveloperBalanceV1kept at discriminant 5; new key at discriminant 6 (backward-compatible)Acceptance criteria checklist
require_authon all state-changing entrypointsunwrap()in production)Test output
141 passed; 3 failed (all pre-existing, unrelated to this PR)
The 3 pre-existing failures are:
test_cancel_admin_transfer_success—unwrap()onNone(vesting logic bug)test_get_all_developer_balances_large_index— expectedGasExhaustionRiskerrortest_upgrade_and_get_version— non-existent WASM hashFollow-ups
get_all_developer_balancesfor all tokens simultaneously (requires index per token)Security note
All state-changing entrypoints require authorization. Arithmetic uses
checked_add/checked_sub. Nounwrap()in production code paths. The token parameter is validated by the balance key — a wrong token simply reads a different storage slot. Migration is admin-only and idempotent.