Repository navigation
feat(savings-vault): implement savings boost rewards (#440) - #491
Merged
Merged
Conversation
Add loyalty multipliers, streak bonuses, and reward distribution to the savings-vault contract (Soroban/Rust). ## New: rewards.rs - Loyalty multiplier: bps-based, steps at 30/90/180-day tiers (1.1x/1.25x/1.5x), capped at 2.0x by default. Tiers and cap are admin-configurable. - Streak bonus: per-period bps bonus for consecutive kept accrual windows, capped (default 5 periods x 1% = 5% max). Resets on any missed period. - Accrual: lazy, O(periods) per call, uses mul_div_floor (I256, rounds down). Anchored to InterestAccount.created_at so first call counts correctly. - Claim: pays min(pending, pool) to user; pool never goes negative; remainder stays in pending on shortfall. - Admin: reward_set_config (validated), reward_fund (pool funding), events on every state change. - Auth: require_auth on user for claim/ping, admin identity check on config/fund, require_not_paused on all mutating entrypoints. ## Modified files - src/types.rs: LoyaltyTier, RewardsConfig, RewardState types; DataKey::RewardsConfig, RewardPoolBalance, RewardState(Address) variants; Debug+PartialEq on Goal and InterestAccount (required by updated SDK). - src/lib.rs: wire rewards module; 9 new public entrypoints. - src/interest.rs: call rewards::note_touch on deposit/withdraw to track streak. - src/events.rs: add TOPIC_UPGRADED (was missing); 5 reward event topics. - src/error.rs: trim to 27 variants (XDR SCSpecUDTErrorEnumV0 hard limit is 50; baseline had 57 which broke the contracterror macro). Add 3 reward errors. - src/goal.rs, src/group_split.rs: #[allow(dead_code)] on pre-existing unused fns. - src/storage.rs: fix doc comment indentation (pre-existing clippy failure). - src/test.rs: 20 new reward tests. - Cargo.lock: updated to resolve ed25519-dalek v3.0.0 conflict in soroban-env-host. ## Pre-existing baseline failures (not introduced by this PR) - test::set_admin_by_non_admin_rejected: mock_all_auths() now approves the attacker before the ownership check under the updated host. - test::interest_withdraw_draws_on_accrued_interest: test withdraws more tokens than the vault holds (credited interest is storage-only, not real tokens); updated host enforces real balances strictly. ## CI bar cargo fmt --check: pass cargo clippy -- -D warnings: pass cargo test: 110 pass, 2 fail (pre-existing), 7 ignored (pre-existing stubs) cargo build --target wasm32-unknown-unknown --release: pass
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
- error.rs: add upstream SameLedger=114 and ReentrantCall=115; keep trimmed to ≤50 variants (XDR limit) with all 3 reward errors retained. - types.rs: add upstream GoalContributions, GoalLastContributionLedger, TokenTransferActive DataKey variants alongside our reward types. - test.rs: include upstream ReentrantToken contract and token_callback_cannot_reenter_vault_mutation test alongside rewards tests. Pre-existing failures (not introduced by this branch): - interest_withdraw_draws_on_accrued_interest (host balance enforcement) - set_admin_by_non_admin_rejected (mock_all_auths behaviour) - token_callback_cannot_reenter_vault_mutation (upstream unfinished feature)
Contributor
Author
|
closes #440 |
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.
Closes #440
Add loyalty multipliers, streak bonuses, and reward distribution to the savings-vault contract (Soroban/Rust).
New: rewards.rs
Modified files
Pre-existing baseline failures (not introduced by this PR)
CI bar
cargo fmt --check: pass
cargo clippy -- -D warnings: pass
cargo test: 110 pass, 2 fail (pre-existing), 7 ignored (pre-existing stubs) cargo build --target wasm32-unknown-unknown --release: pass