UNPKG

@mercurial-finance/dynamic-amm-sdk

Version:

Mercurial Vaults SDK is a typescript library that allows you to interact with Mercurial v2's AMM.

52 lines 2.92 kB
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; import { Connection, PublicKey, Keypair } from '@solana/web3.js'; import { Wallet, AnchorProvider } from '@coral-xyz/anchor'; import AmmImpl from '../amm'; import fs from 'fs'; import os from 'os'; function loadKeypairFromFile(filename) { const secret = JSON.parse(fs.readFileSync(filename.replace('~', os.homedir)).toString()); const secretKey = Uint8Array.from(secret); return Keypair.fromSecretKey(secretKey); } const payerKP = loadKeypairFromFile('~/.config/solana/id.json'); const payerWallet = new Wallet(payerKP); console.log('Wallet Address: %s \n', payerKP.publicKey); const mainnetConnection = new Connection('https://api.mainnet-beta.solana.com'); const provider = new AnchorProvider(mainnetConnection, payerWallet, { commitment: 'confirmed', }); function getPoolInfo(poolAddress) { return __awaiter(this, void 0, void 0, function* () { const pool = yield AmmImpl.create(provider.connection, poolAddress); const poolInfo = pool.poolInfo; console.log('Pool Address: %s', poolAddress.toString()); const poolTokenAddress = yield pool.getPoolTokenMint(); console.log('Pool LP Token Mint Address: %s', poolTokenAddress.toString()); const LockedLpAmount = yield pool.getLockedLpAmount(); console.log('Locked Lp Amount: %s', LockedLpAmount.toNumber()); const lpSupply = yield pool.getLpSupply(); console.log('Pool LP Supply: %s \n', lpSupply.toNumber() / Math.pow(10, pool.decimals)); console.log('tokenA %s Amount: %s ', pool.tokenAMint.address, poolInfo.tokenAAmount.toNumber() / Math.pow(10, pool.tokenAMint.decimals)); console.log('tokenB %s Amount: %s', pool.tokenBMint.address, poolInfo.tokenBAmount.toNumber() / Math.pow(10, pool.tokenBMint.decimals)); console.log('virtualPrice: %s', poolInfo.virtualPrice); console.log('virtualPriceRaw to String: %s \n', poolInfo.virtualPriceRaw.toString()); }); } function main() { return __awaiter(this, void 0, void 0, function* () { // mainnet-beta, SOL-USDC const poolAddress = '6SWtsTzXrurtVWZdEHvnQdE9oM8tTtyg8rfEo3b4nM93'; yield getPoolInfo(new PublicKey(poolAddress)); }); } main(); //# sourceMappingURL=get_pool_info.js.map