@mercurial-finance/dynamic-amm-sdk
Version:
Mercurial Vaults SDK is a typescript library that allows you to interact with Mercurial v2's AMM.
43 lines • 2.41 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const anchor_1 = require("@coral-xyz/anchor");
const web3_js_1 = require("@solana/web3.js");
const bn_js_1 = __importDefault(require("bn.js"));
const fs_1 = __importDefault(require("fs"));
const amm_1 = __importDefault(require("../amm"));
function loadKeypairFromFile(filename) {
const secret = JSON.parse(fs_1.default.readFileSync(filename).toString());
const secretKey = Uint8Array.from(secret);
return web3_js_1.Keypair.fromSecretKey(secretKey);
}
const connection = new web3_js_1.Connection('https://api.devnet.solana.com');
const payerKP = loadKeypairFromFile('~/.config/solana/id.json');
const payerWallet = new anchor_1.Wallet(payerKP);
console.log('payer %s', payerKP.publicKey);
async function createPool(tokenAMint, tokenBMint, tokenAAmount, tokenBAmount, config, payer) {
const transactions = await amm_1.default.createPermissionlessConstantProductPoolWithConfig(connection, payer.publicKey, tokenAMint, tokenBMint, tokenAAmount, tokenBAmount, config);
for (const transaction of transactions) {
transaction.sign(payer);
const txHash = await connection.sendRawTransaction(transaction.serialize());
await connection.confirmTransaction(txHash, 'finalized');
console.log('Transaction %s', txHash);
}
}
async function main() {
const tokenAMint = new web3_js_1.PublicKey('BjhBG7jkHYMBMos2HtRdFrw8rvSguBe5c3a3EJYXhyUf');
const tokenBMint = new web3_js_1.PublicKey('9KMeJp868Pdk8PrJEkwoAHMA1ctdxfVhe2TjeS4BcWjs');
// Retrieve config accounts where authorized pool creator key is the payerKP
const configs = await amm_1.default.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_js_1.default(1000000);
const tokenBDepositAmount = new bn_js_1.default(1000000);
// Create pool
await createPool(tokenAMint, tokenBMint, tokenADepositAmount, tokenBDepositAmount, config.publicKey, payerWallet.payer);
}
main();
//# sourceMappingURL=create_pool_with_authorized_config.js.map