A Solana program for migrating tokens from one mint to another using configurable migration strategies.
This Anchor program enables users to migrate their tokens from an old token mint to a new token mint based on predefined migration strategies. The program supports three migration strategies:
- ProRata: Calculates withdrawal amounts based on proportional supply of both tokens
- Fixed: Scales the deposited amount up or down by 10^e for decimal redenomination
- Ratio: Applies a fixed rational rate
numerator / denominatorto the deposited amount
- Node.js and Yarn
- Rust and Cargo
- Solana CLI (v2.3.0) tools
- Anchor CLI (v0.31.1)
# Install dependencies
yarn install
# Build the program
anchor build# Run tests
anchor test# Deploy to localnet
anchor deploy
# Deploy to devnet/mainnet
anchor deploy --provider.cluster devnetThe admin can initialize a new token migration strategy:
await program.methods.initialize(
mintFrom, // Source token mint
mintTo, // Destination token mint
{ fixed: { e: 0 } } // Migration strategy
)Users can migrate their tokens using the configured strategy:
await program.methods.migrate(
new BN(amount) // Amount to migrate
)Proportionally distributes new tokens based on supply ratios:
withdraw_amount = (supply_to * deposit_amount) / supply_from
Scales amounts by powers of 10:
Fixed(1): Multiply by 10 (e.g., 100 → 1000)Fixed(-1): Divide by 10 (e.g., 100 → 10)Fixed(0): 1:1 ratio (e.g., 100 → 100)
Applies a fixed rational conversion rate, ignoring token supply:
withdraw_amount = floor(deposit_amount * numerator / denominator)
Ratio { numerator: 3, denominator: 2 }: 3 out per 2 in (e.g., 100 → 150)Ratio { numerator: 1, denominator: 2 }: 1 out per 2 in (e.g., 100 → 50)Ratio { numerator: 1, denominator: 1 }: 1:1 ratio (e.g., 100 → 100)
Both numerator and denominator must be non-zero. Like Fixed, this operates on raw base units and is not decimal-aware: if the mints have different decimals, fold the 10^(decimals_to - decimals_from) factor into the ratio. Division floors; the residue stays in the vault.
MIT