UNPKG

pumpfun-swap-sdk

Version:

SDK for interacting with the PumpFun AMM on Solana

27 lines (26 loc) 1.08 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ceilDiv = ceilDiv; exports.fee = fee; exports.getPumpAmmProgram = getPumpAmmProgram; const bn_js_1 = __importDefault(require("bn.js")); const anchor_1 = require("@coral-xyz/anchor"); const pump_amm_json_1 = __importDefault(require("../idl/pump_amm.json")); const pda_1 = require("./pda"); function ceilDiv(a, b) { if (b.isZero()) { throw new Error('Cannot divide by zero.'); } return a.add(b.subn(1)).div(b); } function fee(amount, basisPoints) { return ceilDiv(amount.mul(basisPoints), new bn_js_1.default(10000)); } function getPumpAmmProgram(connection, programId = pda_1.PUMP_AMM_PROGRAM_ID) { const pumpAmmIdlAddressOverride = { ...pump_amm_json_1.default }; pumpAmmIdlAddressOverride.address = programId; return new anchor_1.Program(pumpAmmIdlAddressOverride, new anchor_1.AnchorProvider(connection, null, {})); }