Skip to content

feat: add redemption program#16

Open
alexjaniak wants to merge 19 commits intomainfrom
redeem
Open

feat: add redemption program#16
alexjaniak wants to merge 19 commits intomainfrom
redeem

Conversation

@alexjaniak
Copy link
Collaborator

Summary

Adds a new redemption program for liquidating treasury tokens.

Features

  • Admin initializes vault with price and deposits quote tokens
  • Admin can withdraw funds
  • Users redeem base tokens for quote tokens at set price

Program ID

rdm5xmgfjVn2WXCNrdEuBDoj3JJHt7K6M82jBnXf1Ef

Structure

  • initialize - Admin sets price, deposits quote tokens
  • withdraw - Admin reclaims funds
  • redeem - Users exchange base for quote at set rate

- 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
@alexjaniak alexjaniak force-pushed the redeem branch 2 times, most recently from be94103 to 84f0e04 Compare February 17, 2026 18:19
alexjaniak and others added 8 commits February 17, 2026 13:26
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
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.

2 participants