Repository navigation
feat(contracts): flexible fee structure (#430) and multi-token support (#436) - #492
Merged
Merged
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This branch had an error being deployed
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.
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.rsset_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).set_fee_recipient(addr)— admin configures where fees are sent. Defaults to the admin address when unset.calculate_fee(amount)— uses checked arithmetic:amount * fee_bps / 10_000, floored. Short-circuits to(0, amount)whenfee_bps == 0without touching the multiplication path.transfer_in_with_feeandtransfer_out_with_feewrap the existingstorage::transfer_in/outwith 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.rsfee_bps(),set_fee_bps(bps),fee_recipient(),set_fee_recipient(addr)Tests (9)
set_fee_bpsstores valueset_fee_recipientstores valueIssue #436 — Multi-Token Support
New file:
contracts/savings-vault/src/multitoken.rsdeposit_token(from, token_addr, amount)andwithdraw_token(owner, token_addr, amount)— deposit/withdraw any whitelisted token. Per-token balances tracked viaMap<Address, i128>.add_token(addr)/remove_token(addr)— admin manages the accepted token list. Primary vault token (set atinitialize) is always included and cannot be removed.is_whitelistedchecks membership.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.rstoken_whitelist(),add_token(),remove_token(),deposit_token(),withdraw_token(),token_balances(),set_conversion_rate(),conversion_rate(),convert_balance()Tests (11)
add_tokenappendsremove_tokenremovesset_conversion_ratestores valueNotFoundFiles changed
contracts/savings-vault/src/fees.rscontracts/savings-vault/src/multitoken.rscontracts/savings-vault/src/types.rsFeeBps,FeeRecipient,TokenWhitelist,TokenBalance,ConversionRatecontracts/savings-vault/src/lib.rscontracts/savings-vault/src/events.rs