Skip to content

feat(contracts): flexible fee structure (#430) and multi-token support (#436) - #492

Merged
nayt9 merged 2 commits into
stowp:mainfrom
Peace-001:feat/flexible-fees-and-multi-token
Oct 30, 2026
Merged

nayt9 merged 2 commits into
stowp:mainfrom
Peace-001:feat/flexible-fees-and-multi-token

Conversation

@Peace-001

Copy link
Copy Markdown

Summary

Closes #430
Closes #436

Adds configurable fee percentages with fee recipient management, and multi-token support with a token whitelist and conversion logic. Both features follow the existing contract patterns (instance storage for config, persistent for per-user data, checked arithmetic, admin-gated setters).


Issue #430 — Flexible Fee Structure

New file: contracts/savings-vault/src/fees.rs

Requirement Implementation
Configurable fee percentages set_fee_bps(bps) — admin sets a fee in basis points (1/100 %). Capped at 1 000 bps (10%) as a sanity ceiling. Defaults to 0 (no fee).
Fee recipient management set_fee_recipient(addr) — admin configures where fees are sent. Defaults to the admin address when unset.
Fee calculation optimization calculate_fee(amount) — uses checked arithmetic: amount * fee_bps / 10_000, floored. Short-circuits to (0, amount) when fee_bps == 0 without touching the multiplication path.
Integration helpers transfer_in_with_fee and transfer_out_with_fee wrap the existing storage::transfer_in/out with automatic fee deduction, so any module can opt into fee-aware transfers.

New DataKey variants

  • FeeBps — instance storage for the fee rate.
  • FeeRecipient — instance storage for the recipient address.

Public entrypoints added to lib.rs

fee_bps(), set_fee_bps(bps), fee_recipient(), set_fee_recipient(addr)

Tests (9)

  • Fee defaults to zero
  • set_fee_bps stores value
  • Rejects bps > 1 000
  • Recipient defaults to admin
  • set_fee_recipient stores value
  • Zero bps returns full amount
  • 50 bps on 1M = 5 000 fee
  • 100 bps on 1M = 10 000 fee
  • Small amounts floor correctly

Issue #436 — Multi-Token Support

New file: contracts/savings-vault/src/multitoken.rs

Requirement Implementation
Support multiple stablecoins deposit_token(from, token_addr, amount) and withdraw_token(owner, token_addr, amount) — deposit/withdraw any whitelisted token. Per-token balances tracked via Map<Address, i128>.
Token whitelist add_token(addr) / remove_token(addr) — admin manages the accepted token list. Primary vault token (set at initialize) is always included and cannot be removed. is_whitelisted checks membership.
Conversion logic set_conversion_rate(from, to, rate) — admin sets rates in 1/1 000 000 units (1 000 000 = 1:1). convert_balance(owner, from, to, amount) converts a user's balance from one token to another at the configured rate — purely accounting, no on-chain swap needed since the vault holds both tokens.

New DataKey variants

  • TokenWhitelist — instance storage, Vec<Address> of accepted tokens.
  • TokenBalance(Address) — persistent, Map<Address, i128> per-user balances.
  • ConversionRate(Address, Address) — instance storage for per-pair rates.

Public entrypoints added to lib.rs

token_whitelist(), add_token(), remove_token(), deposit_token(), withdraw_token(), token_balances(), set_conversion_rate(), conversion_rate(), convert_balance()

Tests (11)

  • Whitelist defaults to primary token
  • add_token appends
  • Add is idempotent
  • remove_token removes
  • Primary token cannot be removed
  • Non-existent token removal rejected
  • New user has empty balances
  • set_conversion_rate stores value
  • Same-token conversion rejected
  • Non-whitelisted conversion rejected
  • Unset rate returns NotFound

Files changed

File Type Change
contracts/savings-vault/src/fees.rs New Fee configuration, calculation, and transfer helpers
contracts/savings-vault/src/multitoken.rs New Whitelist, multi-token deposit/withdraw, conversion
contracts/savings-vault/src/types.rs Modified 5 new DataKey variants: FeeBps, FeeRecipient, TokenWhitelist, TokenBalance, ConversionRate
contracts/savings-vault/src/lib.rs Modified Module declarations + 13 new public entrypoints
contracts/savings-vault/src/events.rs Modified Event topic constants for fee and multi-token events

@vercel

vercel Bot commented Oct 22, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
stow Error Error Oct 30, 2026 6:53pm UTC

@nayt9
nayt9 merged commit 1a7ed5b into stowp:main Oct 30, 2026
0 of 5 checks passed

This branch had an error being deployed

1 failed deployment
Preview — 3dab3f4a Deployed Oct 30, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Create multi-token support Create flexible fee structure

3 participants