import { initAccountToken, initializeMint, mintTo } from './pretest/helper' import { BN, AnchorProvider, Wallet, web3 } from '@project-serum/anchor' import { Keypair, PublicKey } from '@solana/web3.js' import { decode } from 'bs58' import Balancer, { BalancerAmm, MintActionStates } from '../dist/lib' const MINT_SIZE = 6 const PRIV_KEY_FOR_TEST = '2EoKt7jkF3eJrN1adzX9yvTaXLMyvZSg4wFFM9Swhwyi3ERsDgWGPDgU52NGjnn4TbaNDGpHUeYbxDW3A6RPE9Ze' describe('balancer-amm', () => { // Configure the client to use the local cluster. const wallet = new Wallet( web3.Keypair.fromSecretKey(decode(PRIV_KEY_FOR_TEST)), ) const connection = new web3.Connection( 'https://api.devnet.solana.com', 'confirmed', ) const provider = new AnchorProvider(connection, wallet, { // skipPreflight: true, commitment: 'confirmed', }) const balancerProgram = new Balancer( provider, '6SRa2Kc3G4wTG319G4Se6yrRWeS1A1Hj79BC3o7X9v6T', ) const MINTS_CONFIGS: { // mint keypair: Keypair weight: BN amountIn: BN }[] = [] // Pool let POOL_PUBKEY: PublicKey let POOL_PUBKEY_2: PublicKey let FEE = new BN(500_000_000) // 50% let TAX_FEE = new BN(100_000_000) // 10% let taxman = web3.Keypair.generate() let mintLpt = web3.Keypair.generate() before('Is generate data!', async () => { for (let i = 0; i < MINT_SIZE; i++) { const newMint = Keypair.generate() await initializeMint(newMint, provider) await initAccountToken(newMint.publicKey, provider) await mintTo(new BN(10000000000), newMint.publicKey, provider) MINTS_CONFIGS.push({ keypair: newMint, amountIn: new BN(1000000000).div(new BN(2)), weight: new BN(50), }) } }) it('Is initialized pool!', async () => { const { poolAddress } = await balancerProgram.initializePool({ fee: FEE, taxFee: TAX_FEE, mintsConfigs: MINTS_CONFIGS.map((e) => { return { publicKey: e.keypair.publicKey, action: MintActionStates.Active, amountIn: e.amountIn, weight: e.weight, } }), taxMan: taxman.publicKey, mintLpt, }) console.log('poolAddress: ', poolAddress) POOL_PUBKEY = new PublicKey(poolAddress) }) it('Is fetched pool data!', async () => { const daa = await balancerProgram.getPoolData(POOL_PUBKEY) }) it('Is fetched call pool', async () => { const { txId, poolAddress } = await balancerProgram.initializePool({ fee: FEE, taxFee: TAX_FEE, mintsConfigs: MINTS_CONFIGS.map((e) => { return { publicKey: e.keypair.publicKey, action: MintActionStates.Active, amountIn: e.amountIn, weight: e.weight, } }), taxMan: taxman.publicKey, }) POOL_PUBKEY_2 = new PublicKey(poolAddress) }) it('Is initialized join!', async () => { for (let i = 0; i < MINT_SIZE; i++) { const mintConfig = MINTS_CONFIGS[i] await balancerProgram.initializeJoin({ amountIn: mintConfig.amountIn, poolAddress: POOL_PUBKEY.toBase58(), mint: mintConfig.keypair.publicKey, }) } }) it('Is add full side liquidity!', async () => { // anchor.utils.features.set('debug-logs') const amounts_in = MINTS_CONFIGS.map((e, idx) => e.amountIn.mul(new BN(idx)), ) // Add your test here. const tx = await balancerProgram.addLiquidity( POOL_PUBKEY.toBase58(), amounts_in, ) }) it('Is add sided liquidity!', async () => { // Add your test here. const mintCongig = MINTS_CONFIGS[0] await balancerProgram.addSidedLiquidity( POOL_PUBKEY.toBase58(), mintCongig.keypair.publicKey, mintCongig.amountIn, ) }) it('Is remove liquidity!', async () => { const mintCongig = MINTS_CONFIGS[0] await balancerProgram.removeLiquidity( POOL_PUBKEY.toBase58(), mintCongig.amountIn, ) }) it('Is remove sided liquidity!', async () => { await balancerProgram.removeSidedLiquidity( POOL_PUBKEY.toBase58(), MINTS_CONFIGS[0].keypair.publicKey, new BN(5000000), ) }) it('Is swap!', async () => { // Add your test here. const bidMint = MINTS_CONFIGS[0] const askMint = MINTS_CONFIGS[0] await balancerProgram.swap( new BN(100000000), bidMint.keypair.publicKey.toBase58(), askMint.keypair.publicKey.toBase58(), POOL_PUBKEY.toBase58(), new BN(0), ) }) it('Is Route!', async () => { // set('debug-logs') // Add your test here. // const bidMint = MINTS_CONFIGS[0] // const askMint = MINTS_CONFIGS[0] await balancerProgram.route( new BN(100), [ { bidMint: MINTS_CONFIGS[0].keypair.publicKey.toBase58(), askMint: MINTS_CONFIGS[1].keypair.publicKey.toBase58(), pool: POOL_PUBKEY.toBase58(), }, { bidMint: MINTS_CONFIGS[1].keypair.publicKey.toBase58(), askMint: MINTS_CONFIGS[2].keypair.publicKey.toBase58(), pool: POOL_PUBKEY.toBase58(), }, ], new BN(0), ) }) it('Is update weights!', async () => { // Add your test here. await balancerProgram.updateWeights({ poolAddress: POOL_PUBKEY.toBase58(), weights: MINTS_CONFIGS.map((e) => new BN(50)), }) }) it('Is freeze pool!', async () => { // Add your test here. await balancerProgram.freezePool({ poolAddress: POOL_PUBKEY.toBase58(), }) }) it('Is thaw pool!', async () => { // Add your test here. await balancerProgram.thawPool({ poolAddress: POOL_PUBKEY.toBase58(), }) }) it('Is updated mints state!', async () => { // Add your test here. await balancerProgram.updateActions({ poolAddress: POOL_PUBKEY.toBase58(), actions: MINTS_CONFIGS.map((e) => { return { active: {} } }), }) }) it('Is update fee!', async () => { let fee = 2 let taxFee = 3 await balancerProgram.updateFee( POOL_PUBKEY.toBase58(), new BN(fee), new BN(taxFee), ) }) it('Is transfer owner ship!', async () => { // Add your test here. let new_owner = Keypair.generate() await balancerProgram.transferOwnership({ poolAddress: POOL_PUBKEY.toBase58(), newOwner: new_owner.publicKey.toBase58(), }) }) })