0.4.5 • Published 1 year ago
@blockchainbros/vidar-amm-sdk v0.4.5
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
npm install @blockchainbros/vidar-amm-sdkCore 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 poolfeeVault: 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
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
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
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
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
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)
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
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
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
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
0.4.5
1 year ago
0.4.4
1 year ago
0.4.3
1 year ago
0.4.2
1 year ago
0.4.1
1 year ago
0.4.0
1 year ago
0.3.1
1 year ago
0.3.0
1 year ago
0.2.0
1 year ago
0.1.12
1 year ago
0.1.11
1 year ago
0.1.10
1 year ago
0.1.9
1 year ago
0.1.8
1 year ago
0.1.7
1 year ago
0.1.6
1 year ago
0.1.5
1 year ago
0.1.4
1 year ago
0.1.3
1 year ago
0.1.2
1 year ago
0.1.1
1 year ago
0.1.0
1 year ago