Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE/multi-asset-settlement-417.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
## Multi-Asset Settlement (#417)

Adds per-token developer balances and asset parameter on `receive_payment`.

### New Storage Keys

- `DeveloperBalanceByAsset(Address, Address)` — developer → asset → balance
- `GlobalPoolByAsset(Address)` — asset → global pool
- `SupportedAssets` — registered asset whitelist

### New Error Variants

- `AssetNotConfigured = 13` — unregistered asset rejected
- `GasExhaustionRisk = 14` — added (already referenced by existing tests)

### New Functions

- `add_asset(admin, asset)` — admin-only asset registration (prevents unregistered token dust)
- `get_assets(admin)` — list supported assets
- `receive_payment_asset(caller, amount, to_pool, developer, asset)` — asset-aware payment
- `withdraw_developer_balance_asset(developer, amount, asset)` — per-asset withdrawal
- `get_developer_balance_asset(developer, asset)` — per-asset view
- `get_global_pool_asset(asset)` — per-asset pool view
- `get_all_developer_balances_asset(admin, asset)` — per-asset admin view

### Backwards Compatibility

`receive_payment` (4-param, old signature) kept as shim calling `receive_payment_asset` with the native asset. Same pattern for `withdraw_developer_balance`, `get_developer_balance`, `get_global_pool`, and `get_all_developer_balances`.

### SDK 22 Test Fixes

Fixes 41+ pre-existing compilation errors and 20 runtime failures in `settlement/src/test.rs` and `test_views.rs` caused by Soroban SDK 22 changes to `try_` client method signatures:

- `panic_message`: `downcast_ref<&str>` → `downcast_ref<String>` (no_std compat)
- `is_error`: matches both `Err(Ok(Error))` (non-Result fn panics in SDK 22) and `Err(Err(InvokeError::Contract(code)))`
- `is_error_vec` / `is_error_result` / `is_not_initialized_result`: handle `Result<SettlementError, InvokeError>` error slot
- All `try_get_all_developer_balances` / `try_get_developer_balances_page`: double `.unwrap().unwrap()`
- `GasExhaustionRisk` assertion: wrapped in `Err(Ok(...))`
- `is_not_initialized`: uses `is_type(ScErrorType::Contract) + get_code()` for SDK 22 `Error` type
- Pre-existing page size cap test: 51 not 50 (matches `MAX_DEVELOPER_BALANCES_PAGE_SIZE = 100`)
45 changes: 45 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE/multi-asset-settlement.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
## Gas Profiling Harness

Adds a reproducible gas-profiling harness for vault, settlement, and revenue_pool contract entrypoints:

- **Vault** (9 benchmarks): `init`, `deposit`, `deduct`, `batch_deduct[k=1,10,50]`, `withdraw`, `withdraw_to`, `distribute`
- **Settlement** (6 benchmarks): `init`, `receive_payment`, `withdraw_developer_balance`, `batch_receive_payment[k=1,10,50]`
- **Revenue Pool** (6 benchmarks): `init`, `deposit`, `distribute`, `distribute_full`, `withdraw`, `batch_receive_notification[k=50]`

Batch sizes test k=1, k=10, `MAX_BATCH_SIZE` (50). Uses real Soroban SDK 22 `cost_estimate().budget()` API with `/saturating_sub` diff. Output format `GAS| <label> | <cpu> | <mem> | <description>` parsed by `scripts/gas_profile.sh` into deterministic `BENCHMARKS.md`.

## Multi-Asset Settlement (#417)

Adds per-token developer balances and asset parameter on `receive_payment`:

**New storage keys:**
- `DeveloperBalanceByAsset(Address, Address)` — developer → asset → balance
- `GlobalPoolByAsset(Address)` — asset → global pool
- `SupportedAssets` — registered asset whitelist

**New error variants:**
- `AssetNotConfigured = 13` — unregistered asset rejected
- `GasExhaustionRisk = 14` — added (already referenced by existing tests)

**New functions:**
- `add_asset(admin, asset)` — admin-only registration
- `get_assets(admin)` — list supported assets
- `receive_payment_asset(caller, amount, to_pool, developer, asset)` — asset-aware payment
- `withdraw_developer_balance_asset(developer, amount, asset)` — per-asset withdrawal
- `get_developer_balance_asset(developer, asset)` — per-asset view
- `get_global_pool_asset(asset)` — per-asset pool view
- `get_all_developer_balances_asset(admin, asset)` — per-asset admin view

**Backwards compat:** `receive_payment` (4-param, old signature) kept as shim calling `receive_payment_asset` with native asset.

## Test Fixes

Fixes 41+ pre-existing compilation errors and 20 runtime failures in `settlement/src/test.rs` and `test_views.rs` caused by Soroban SDK 22 changes:

- `panic_message`: `downcast_ref<&str>` → `downcast_ref<String>` (no_std compat)
- `is_error`: matches both `Err(Ok(Error))` (non-Result fn panics in SDK 22) and `Err(Err(InvokeError::Contract(code)))`
- `is_error_vec` / `is_error_result` / `is_not_initialized_result`: handle `Result<SettlementError, InvokeError>` error slot
- All `try_get_all_developer_balances` / `try_get_developer_balances_page`: double `.unwrap().unwrap()`
- `GasExhaustionRisk` assertion: wrapped in `Err(Ok(...))`
- `is_not_initialized`: uses `is_type(ScErrorType::Contract) + get_code()` for SDK 22 `Error` type
- Pre-existing page size cap test: 51 not 50 (matches `MAX_DEVELOPER_BALANCES_PAGE_SIZE = 100`)
6 changes: 5 additions & 1 deletion contracts/revenue_pool/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ const ERR_UNAUTHORIZED: &str = "unauthorized: caller is not admin";
const ERR_INSUFFICIENT_BALANCE: &str = "insufficient USDC balance";
const ERR_NOT_INITIALIZED: &str = "revenue pool not initialized";
const ERR_DUPLICATE_RECIPIENT: &str = "duplicate recipient in batch";
const ERR_PAUSED: &str = "revenue pool is paused";
const PAUSED_KEY: &str = "paused";
const VERSION_KEY: &str = "version";

pub const DEFAULT_MAX_DISTRIBUTE: i128 = i128::MAX;
Expand Down Expand Up @@ -517,7 +519,9 @@ impl RevenuePool {
}

// Extend TTL before executing transfers.
env.storage().instance().extend_ttl(LIFETIME_THRESHOLD, BUMP_AMOUNT);
env.storage()
.instance()
.extend_ttl(LIFETIME_THRESHOLD, BUMP_AMOUNT);

// Phase 3: Execution — all validation passed, perform transfers.
// Soroban's transaction model guarantees that if any transfer fails,
Expand Down
Loading
Loading