Program ID: FarmuwXPWXvefWUeqFAa5w6rifLkq5X6E8bimYvrhCB1
Install
Install dependencies
npm i @mercurial-finance/farming-sdk @project-serum/anchor @solana/web3.js @solana/spl-token @solana/spl-token-registry
Initialize PoolFarmImpl instance
import { PoolFarmImpl } from"@mercurial-finance/farming-sdk";import { Wallet, AnchorProvider } from"@coral-xyz/anchor";import { Connection, PublicKey, Keypair } from"@solana/web3.js";// Connection, Wallet, and AnchorProvider to interact with the networkconstmainnetConnection=newConnection("https://api.mainnet-beta.solana.com");constmockWallet=newWallet(newKeypair());constprovider=newAnchorProvider(mainnetConnection, mockWallet, { commitment:"confirmed",});// Alternatively, to use Solana Wallet AdapterconstUSDC_acUSDC_POOL=newPublicKey("6ZLKLjMd2KzH7PPHCXUPgbMAtdTT37VgTtdeXWLoJppr"); // Pool Address can get from https://docs.meteora.ag/dynamic-pools-integration/dynamic-pool-api/pool-infoconstfarmingPools=awaitPoolFarmImpl.getFarmAddressesByPoolAddress( USDC_acUSDC_POOL);// farmingPools is an array (A pool can have multiple farms)constfarmingPool= farmingPools[0];constfarm=awaitPoolFarmImpl.create( mainnetConnection,farmingPool.farmAddress);
To interact with the PoolFarmImpl
Stake
// https://station.jup.ag/blog/jupiter-token-list-api#endpointsconsttokenList=awaitfetch('https://token.jup.ag/all').then(res =>res.json());constUSDC=tokenList.find(token =>token.address === <USDC_ADDRESS>);constUSDT=tokenList.find(token =>token.address === <USDT_ADDRESS>);// Get pool lp balance from `@mercurial-finance/dynamic-amm-sdk` packageconstpool=awaitAmmImpl.create(connection,MAINNET_POOL.USDC_USDT,USDC,USDT);constlpBalance=awaitpool.getUserBalance(mockWallet.publicKey);conststakeTx=awaitfarm.deposit(mockWallet.publicKey, lpBalance); // Web3 Transaction ObjectconststakeResult=awaitprovider.sendAndConfirm(stakeTx); // Transaction hash