UNPKG

@blockchainbros/vidar-amm-sdk

Version:
229 lines (174 loc) 5.42 kB
# Vidar AMM SDK TypeScript SDK for interacting with the **Vidar AMM** smart contracts on the **Solana blockchain**. Supports liquidity provision, staking, rewards claiming, token swaps (including optional commit-reveal), and full pool lifecycle management. ## Installation ```bash npm install @blockchainbros/vidar-amm-sdk ``` --- ## Core Concepts ### LP Tokens (`lpMint`) When you provide liquidity, you receive **LP tokens** which represent your ownership share in a pool. These tokens are minted via `lpMint`. * Add liquidity → mint LP tokens * Remove liquidity → burn LP tokens * Stake LP tokens → lock them for yield rewards ### Vaults * `vaultA`, `vaultB`: Store the two assets of the pool * `feeVault`: Accumulates trading fees (90% to LPs, 10% to admin) * `stakingRewardVault`: Distributes staking rewards (from fees, not inflation) * `lpStakeVault`: Holds LP tokens from stakers --- ## SDK Usage ### Initialize SDK ```ts import { loadVidarAmm } from '@blockchainbros/vidar-amm-sdk'; const program = loadVidarAmm( 'https://api.mainnet-beta.solana.com', wallet, // Anchor-compatible wallet 'confirmed' ); ``` --- ## Pool Lifecycle ### Initialize Pool ```ts import { initializePool } from '@blockchainbros/vidar-amm-sdk'; const tx = await initializePool(program, { payer: wallet.publicKey, pool: new PublicKey('...'), authority: new PublicKey('...'), tokenA: new PublicKey('...'), tokenB: new PublicKey('...'), vaultA: new PublicKey('...'), vaultB: new PublicKey('...'), feeVault: new PublicKey('...'), stakingRewardVault: new PublicKey('...'), lpStakeVault: new PublicKey('...'), lpMint: new PublicKey('...') }, { feeBasisPoints: 30, tickSpacing: 60, lowerTick: -60, upperTick: 60 }); ``` --- ## Liquidity Operations ### Add Liquidity ```ts import { addLiquidity } from '@blockchainbros/vidar-amm-sdk'; const tx = await addLiquidity(program, { user: wallet.publicKey, pool: new PublicKey('...'), userTokenA: new PublicKey('...'), userTokenB: new PublicKey('...'), vaultA: new PublicKey('...'), vaultB: new PublicKey('...'), lpMint: new PublicKey('...'), userLpToken: new PublicKey('...'), authority: new PublicKey('...'), position: new PublicKey('...') }, new BN('1000000000'), new BN('1000000000')); ``` ### Remove Liquidity ```ts import { removeLiquidity } from '@blockchainbros/vidar-amm-sdk'; const tx = await removeLiquidity(program, { user: wallet.publicKey, pool: new PublicKey('...'), vaultA: new PublicKey('...'), vaultB: new PublicKey('...'), userTokenA: new PublicKey('...'), userTokenB: new PublicKey('...'), lpMint: new PublicKey('...'), userLpToken: new PublicKey('...'), position: new PublicKey('...'), authority: new PublicKey('...') }, new BN('1000000000')); ``` --- ## Swap Operations ### Instant Swap ```ts import { swap } from '@blockchainbros/vidar-amm-sdk'; const tx = await swap(program, { user: wallet.publicKey, pool: new PublicKey('...'), userSource: new PublicKey('...'), userDestination: new PublicKey('...'), vaultSource: new PublicKey('...'), vaultDestination: new PublicKey('...'), feeVault: new PublicKey('...'), stakingRewardVault: new PublicKey('...'), authority: new PublicKey('...') }, new BN('1000000000'), new BN('900000000')); ``` ### Commit-Reveal Swap (if enabled) ```ts import { swapCommit, swapReveal } from '@blockchainbros/vidar-amm-sdk'; // 1. Commit hash await swapCommit(program, { user: wallet.publicKey, commitIndex: new PublicKey('...'), pool: new PublicKey('...') }, hash, nonce); // 2. Reveal with actual amounts and preimage await swapReveal(program, { user: wallet.publicKey, pool: new PublicKey('...'), commit: new PublicKey('...'), vaultSource: new PublicKey('...'), vaultDestination: new PublicKey('...'), userSource: new PublicKey('...'), userDestination: new PublicKey('...'), feeVault: new PublicKey('...'), stakingRewardVault: new PublicKey('...'), authority: new PublicKey('...') }, amountIn, minAmountOut, deadline, nonce); ``` --- ## Staking & Rewards ### Stake LP Tokens ```ts import { stake } from '@blockchainbros/vidar-amm-sdk'; await stake(program, { user: wallet.publicKey, pool: new PublicKey('...'), userLpToken: new PublicKey('...'), stakeVault: new PublicKey('...'), authority: new PublicKey('...'), stakeAccount: new PublicKey('...') }, new BN('1000000000')); ``` ### Unstake ```ts import { unstake } from '@blockchainbros/vidar-amm-sdk'; await unstake(program, { user: wallet.publicKey, pool: new PublicKey('...'), userLpToken: new PublicKey('...'), stakeVault: new PublicKey('...'), stakeAccount: new PublicKey('...'), authority: new PublicKey('...') }, new BN('1000000000')); ``` ### Claim Rewards ```ts import { claimRewards } from '@blockchainbros/vidar-amm-sdk'; await claimRewards(program, { user: wallet.publicKey, pool: new PublicKey('...'), stakeAccount: new PublicKey('...'), stakingRewardVault: new PublicKey('...'), lpStakeVault: new PublicKey('...'), userRewardAccount: new PublicKey('...'), authority: new PublicKey('...') }); ``` --- ## Fee & Reward Distribution Model * **90% of trading fees** go to LPs (automatically added to the pool) * **10% of trading fees** go to protocol `feeVault` (for admin use) * **No inflation**: all rewards are from real volume and protocol usage --- ## License MIT