@mercurial-finance/dynamic-amm-sdk
Version:
Mercurial Vaults SDK is a typescript library that allows you to interact with Mercurial v2's AMM.
44 lines • 2.38 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const web3_js_1 = require("@solana/web3.js");
const anchor_1 = require("@coral-xyz/anchor");
const amm_1 = __importDefault(require("../amm"));
const fs_1 = __importDefault(require("fs"));
const os_1 = __importDefault(require("os"));
function loadKeypairFromFile(filename) {
const secret = JSON.parse(fs_1.default.readFileSync(filename.replace('~', os_1.default.homedir)).toString());
const secretKey = Uint8Array.from(secret);
return web3_js_1.Keypair.fromSecretKey(secretKey);
}
const payerKP = loadKeypairFromFile('~/.config/solana/id.json');
const payerWallet = new anchor_1.Wallet(payerKP);
console.log('Wallet Address: %s \n', payerKP.publicKey);
const mainnetConnection = new web3_js_1.Connection('https://api.mainnet-beta.solana.com');
const provider = new anchor_1.AnchorProvider(mainnetConnection, payerWallet, {
commitment: 'confirmed',
});
async function getPoolInfo(poolAddress) {
const pool = await amm_1.default.create(provider.connection, poolAddress);
const poolInfo = pool.poolInfo;
console.log('Pool Address: %s', poolAddress.toString());
const poolTokenAddress = await pool.getPoolTokenMint();
console.log('Pool LP Token Mint Address: %s', poolTokenAddress.toString());
const LockedLpAmount = await pool.getLockedLpAmount();
console.log('Locked Lp Amount: %s', LockedLpAmount.toNumber());
const lpSupply = await 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());
}
async function main() {
// mainnet-beta, SOL-USDC
const poolAddress = '6SWtsTzXrurtVWZdEHvnQdE9oM8tTtyg8rfEo3b4nM93';
await getPoolInfo(new web3_js_1.PublicKey(poolAddress));
}
main();
//# sourceMappingURL=get_pool_info.js.map