UNPKG

@mercurial-finance/dynamic-amm-sdk

Version:

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

51 lines 2.91 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 { Wallet } from '@coral-xyz/anchor'; import { Connection, Keypair, PublicKey } from '@solana/web3.js'; import BN from 'bn.js'; import fs from 'fs'; import AmmImpl from '../amm'; function loadKeypairFromFile(filename) { const secret = JSON.parse(fs.readFileSync(filename).toString()); const secretKey = Uint8Array.from(secret); return Keypair.fromSecretKey(secretKey); } const connection = new Connection('https://api.devnet.solana.com'); const payerKP = loadKeypairFromFile('~/.config/solana/id.json'); const payerWallet = new Wallet(payerKP); console.log('payer %s', payerKP.publicKey); function createPool(tokenAMint, tokenBMint, tokenAAmount, tokenBAmount, config, payer) { return __awaiter(this, void 0, void 0, function* () { const transactions = yield AmmImpl.createPermissionlessConstantProductPoolWithConfig(connection, payer.publicKey, tokenAMint, tokenBMint, tokenAAmount, tokenBAmount, config); for (const transaction of transactions) { transaction.sign(payer); const txHash = yield connection.sendRawTransaction(transaction.serialize()); yield connection.confirmTransaction(txHash, 'finalized'); console.log('Transaction %s', txHash); } }); } function main() { return __awaiter(this, void 0, void 0, function* () { const tokenAMint = new PublicKey('BjhBG7jkHYMBMos2HtRdFrw8rvSguBe5c3a3EJYXhyUf'); const tokenBMint = new PublicKey('9KMeJp868Pdk8PrJEkwoAHMA1ctdxfVhe2TjeS4BcWjs'); // Retrieve config accounts where authorized pool creator key is the payerKP const configs = yield AmmImpl.getPoolConfigsWithPoolCreatorAuthority(connection, payerWallet.publicKey); // Select config which the fees fit your requirement. Please contact meteora team if you're not whitelisted. const config = configs[0]; // Create pool and deposit const tokenADepositAmount = new BN(1000000); const tokenBDepositAmount = new BN(1000000); // Create pool yield createPool(tokenAMint, tokenBMint, tokenADepositAmount, tokenBDepositAmount, config.publicKey, payerWallet.payer); }); } main(); //# sourceMappingURL=create_pool_with_authorized_config.js.map