Meteora Pool Farm SDK
Getting started
NPM: https://www.npmjs.com/package/@mercurial-finance/farming-sdk
SDK: https://github.com/MeteoraAg/reward-pool
Discord: https://discord.com/channels/841152225564950528/864859354335412224
Install
- Install deps
npm i @mercurial-finance/farming-sdk @project-serum/anchor @solana/web3.js @solana/spl-token @solana/spl-token-registry
- Initialize AmmImpl instance
import PoolFarmImpl from "@mercurial-finance/farming-sdk";
import { PublicKey } from "@solana/web3.js";
import { Wallet, AnchorProvider } from "@project-serum/anchor";
const mainnetConnection = new Connection("https://api.mainnet-beta.solana.com");
const mockWallet = new Wallet(new Keypair());
const provider = new AnchorProvider(mainnetConnection, mockWallet, {
commitment: "confirmed",
});
const farmingPools = await PoolFarmImpl.getFarmAddressesByPoolAddress(
MAINNET_POOL.USDC_USDT
);
const farmingPool = farmingPools[0];
const farm = await PoolFarmImpl.create(connection, farmingPool);
- To interact with the PoolFarmImpl
const tokenList = await fetch('https://token.jup.ag/all').then(res => res.json());
const USDC = tokenList.find(token => token.address === <USDC_ADDRESS>);
const USDT = tokenList.find(token => token.address === <USDT_ADDRESS>);
const pool = await AmmImpl.create(connection, MAINNET_POOL.USDC_USDT, USDC, USDT);
const lpBalance = await pool.getUserBalance(mockWallet.publicKey);
const stakeTx = await farm.deposit(mockWallet.publicKey, lpBalance);
const stakeResult = await provider.sendAndConfirm(stakeTx);
const farmBalance = await farm.getUserBalance(mockWallet.publicKey);
const unStakeTx = await farm.withdraw(mockWallet.publicKey, farmBalance);
const unstakeResult = await provider.sendAndConfirm(depositTx);