A Solana program that enables token swapping with tiered NFT bonuses, vesting mechanisms, and special support for OG holders.
The DEFAI Swap program allows users to:
- Swap DEFAI tokens for tiered NFTs with random bonuses
- Claim vested tokens over a 90-day period
- Special OG Tier 0 access for whitelisted holders with 10:1 vesting
- Progressive tax system to prevent gaming
- Emergency controls and multi-level security
- 5 Tiers of NFTs: Each with different price points and bonus ranges
- Tier 0 (OG): Free mint for whitelisted holders, no bonus
- Tier 1 (Train): 0-15% bonus
- Tier 2 (Boat): 15-50% bonus
- Tier 3 (Plane): 20-100% bonus
- Tier 4 (Rocket): 50-300% bonus
- 90-day linear vesting period
- 2-day cliff period before claims
- Support for both NFT-based and airdrop vesting
- Progressive tax starting at 5%
- Increases by 1% per swap (max 30%)
- Resets after 24 hours of inactivity
- OG Tier 0: Merkle proof-based whitelist for original holders
- 10:1 Airdrop: Separate vesting for airdrop recipients (no NFT)
- Reroll Mechanism: Users can reroll their bonus for a tax fee
- VRF Support: Optional integration with Switchboard VRF for true randomness
# Ensure you're in the security-auditor directory
cd security-auditor
# Build the program
anchor build --skip-lint
# The built program will be at:
# target/deploy/defai_swap.so- Program ID:
FxtwFmgibGqiiSQgpXy34eoDYjbTaXTCsvpvpzX2VReA - Localnet:
2rpNRpFnZEbb9Xoonieg7THkKnYEQhZoSK8bKNtVaVLS
The program requires initialization in the following order:
-
Initialize Main Config
await program.methods.initialize([ price_tier1, // e.g., 10000 * 10^6 for 10k DEFAI price_tier2, // e.g., 20000 * 10^6 price_tier3, // e.g., 30000 * 10^6 price_tier4, // e.g., 40000 * 10^6 price_tier5 // e.g., 50000 * 10^6 ])
-
Initialize Collection
await program.methods.initializeCollection( tierNames, // ["OG", "Train", "Boat", "Plane", "Rocket"] tierSymbols, // ["OG", "TRN", "BOT", "PLN", "RKT"] tierPrices, // [0, 10000, 20000, 30000, 50000] * 10^6 tierSupplies, // [1000, 2000, 1500, 1000, 500] tierUriPrefixes, // IPFS URIs for each tier ogTier0MerkleRoot, // Merkle root for OG holders airdropMerkleRoot // Merkle root for 10:1 airdrop )
-
Initialize User Tax State (per user)
await program.methods.initializeUserTax()
// Tax Configuration
const INITIAL_TAX_BPS: u16 = 500; // 5%
const TAX_INCREMENT_BPS: u16 = 100; // 1% increment
const TAX_CAP_BPS: u16 = 3000; // 30% maximum
// Vesting Configuration
const VESTING_DURATION: i64 = 90 * 24 * 60 * 60; // 90 days
const CLIFF_DURATION: i64 = 2 * 24 * 60 * 60; // 2 days
// Admin Timelock
const ADMIN_TIMELOCK_DURATION: i64 = 48 * 60 * 60; // 48 hoursawait program.methods.swapDefaiForPnftV6(
tier, // 0-4
metadataUri,
name,
symbol
)await program.methods.swapOgTier0ForPnftV6(
vestingAmount, // From merkle proof
merkleProof, // Proof array
metadataUri,
name,
symbol
)await program.methods.claimVestedV6()await program.methods.claimAirdrop(
amount, // AIRDROP amount from merkle proof
merkleProof
)- Merkle Proof Verification: Ensures only authorized users can claim OG/airdrop tokens
- Progressive Tax: Prevents swap spamming
- Timelock: 48-hour delay for admin actions
- Pause Mechanism: Emergency protocol pause
- Secure Randomness: Multiple entropy sources for bonus generation
InsufficientOldTokens: Not enough OLD tokens providedInsufficientDefaiTokens: Not enough DEFAI tokens providedNoLiquidity: Tier supply exhaustedInvalidTier: Invalid tier specifiedNotOnOgWhitelist: User not on OG whitelistOgTier0AlreadyClaimed: OG NFT already claimedStillInCliff: Vesting cliff period not overNothingToClaim: No vested tokens to claim
SwapExecuted: Emitted when a swap is completedVestingClaimed: Emitted when vested tokens are claimedRedemptionExecuted: Emitted when NFT is redeemedBonusRerolled: Emitted when bonus is rerolledAdminAction: Emitted for admin operations