Open
Conversation
- Add new redemption program structure following vault pattern - Program ID: rdm5xmgfjVn2WXCNrdEuBDoj3JJHt7K6M82jBnXf1Ef - Add to Anchor.toml (devnet, localnet, mainnet) - Create lib.rs, state.rs, errors.rs, constants.rs, instructions/mod.rs - Store keypair in .keys/redemption.json
Implements a secure token redemption system for liquidating treasury: ## Instructions - initialize: Admin sets price and deposits quote tokens - deposit: Admin adds more quote tokens - withdraw: Admin reclaims quote and/or collected base tokens - redeem: Users exchange base tokens for quote at set price ## Security - Overflow protection using u128 intermediate calculations - InsufficientVaultBalance check before any transfers - Zero-amount validation on all operations - QuoteAmountTooSmall prevents dust redemptions - Admin-only access control on deposit/withdraw - PDA-signed transfers for vault operations ## State - RedemptionVault: stores admin, mints, price, decimals, stats - Events emitted for all operations for indexing
- Remove deposit instruction (use initialize once) - Remove tracking stats - Slim down state, errors, constants - Cleaner code structure
- Add nonce field to RedemptionVault for multiple vaults per mint pair - PDA seeds now: [VAULT_SEED, base_mint, quote_mint, nonce] - Restore full AGPL license headers - Add doc comments to handlers
- Use InterfaceAccount for Mint and TokenAccount - Use Interface<TokenInterface> for token programs - Separate base_token_program and quote_token_program - Use transfer_checked for all transfers - Store quote_decimals in vault state
Tests: - Initialize vault (9-dec base, 6-dec quote, 0.0002758 price) - Redeem 1M base → ~275.8 quote - InsufficientBalance error when over-redeeming - Admin withdrawal of remaining funds
be94103 to
84f0e04
Compare
Config vars: - BASE_MINT: FAIR token (9 dec) - QUOTE_MINT: USDC (6 dec) - PRICE: 276 (0.000276 USDC per FAIR) - DEPOSIT: 10 USDC - NONCE: configurable
No more env vars needed. Just run: npx tsx scripts/init-vault.ts Or override cluster: npx tsx scripts/init-vault.ts --cluster devnet
- New deposit instruction in redemption program - deposit-vault.ts script for easy deposits - Admin can add more quote tokens anytime
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
Adds a new
redemptionprogram for liquidating treasury tokens.Features
Program ID
rdm5xmgfjVn2WXCNrdEuBDoj3JJHt7K6M82jBnXf1EfStructure
initialize- Admin sets price, deposits quote tokenswithdraw- Admin reclaims fundsredeem- Users exchange base for quote at set rate