UNPKG

@dinolab/crypto-mm

Version:

Crypto Market Maker

77 lines 3.35 kB
"use strict"; 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 raydium_sdk_v2_1 = require("@raydium-io/raydium-sdk-v2"); // @ts-ignore const bn_js_1 = __importDefault(require("bn.js")); class RaydiumDex { constructor(rpcUrl) { this.connection = new web3_js_1.Connection(rpcUrl); } async createPool(tokenAddress, tokenAmount, nativeAmount, ownerKeypair, testnet = false) { try { const raydium = await raydium_sdk_v2_1.Raydium.load({ owner: ownerKeypair, connection: this.connection, cluster: testnet ? "devnet" : "mainnet", disableFeatureCheck: true, disableLoadToken: false, blockhashCommitment: "finalized", }); const mintA = await raydium.token.getTokenInfo(tokenAddress); const mintB = await raydium.token.getTokenInfo("So11111111111111111111111111111111111111112"); const programId = testnet ? raydium_sdk_v2_1.DEVNET_PROGRAM_ID.CREATE_CPMM_POOL_PROGRAM : raydium_sdk_v2_1.CREATE_CPMM_POOL_PROGRAM; const poolFeeAccount = testnet ? raydium_sdk_v2_1.DEVNET_PROGRAM_ID.CREATE_CPMM_POOL_FEE_ACC : raydium_sdk_v2_1.CREATE_CPMM_POOL_FEE_ACC; const feeConfigs = await raydium.api.getCpmmConfigs(); if (raydium.cluster === "devnet") { feeConfigs.forEach((config) => { config.id = (0, raydium_sdk_v2_1.getCpmmPdaAmmConfigId)(programId, config.index).publicKey.toBase58(); }); } const { execute, extInfo, transaction } = await raydium.cpmm.createPool({ programId, poolFeeAccount, mintA, mintB, mintAAmount: new bn_js_1.default(tokenAmount), mintBAmount: new bn_js_1.default(nativeAmount), startTime: new bn_js_1.default(0), feeConfig: feeConfigs[0], associatedOnly: false, ownerInfo: { useSOLBalance: true, }, txVersion: raydium_sdk_v2_1.TxVersion.V0, }); (0, raydium_sdk_v2_1.printSimulate)([transaction]); const { txId } = await execute({ sendAndConfirm: true }); console.log(`✅ Create pool successfully. Transaction ID: ${txId}`); return { lpAddress: extInfo.address.lpMint.toString(), txId }; } catch (e) { console.error(`❌ Error creating liquidity pool. Error: ${e}`); throw e; } } async addLiquidity(tokenAddress, tokenAmount, nativeAmount, ownerKeypair, testnet = false) { return ""; // HM - Test } async removeLiquidity(tokenAddress, percent, ownerKeypair, testnet = false) { return ""; // HM - Test } async swap(fromToken, toToken, fromAmount, ownerKeypair, testnet = false) { return ""; } } exports.default = RaydiumDex; //# sourceMappingURL=raydium.js.map