UNPKG

@prism-hq/prism-ag

Version:

Prism Aggregator

49 lines (48 loc) 1.88 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.marcopoloRoute = void 0; const web3_js_1 = require("@solana/web3.js"); const jsbi_1 = __importDefault(require("jsbi")); var SwapMode; (function (SwapMode) { SwapMode["ExactIn"] = "ExactIn"; SwapMode["ExactOut"] = "ExactOut"; })(SwapMode || (SwapMode = {})); function marcopoloRoute(fromCoin, toCoin, fromCoinAmount, option, liquidityData, settings) { try { let pool = liquidityData.marcopolo[option.marcopolo.poolAddress.toBase58()]; let quoteParams = { sourceMint: new web3_js_1.PublicKey(fromCoin.mintAddress), destinationMint: new web3_js_1.PublicKey(toCoin.mintAddress), amount: jsbi_1.default.BigInt(Math.floor(fromCoinAmount * 10 ** fromCoin.decimals)), swapMode: SwapMode.ExactIn, }; let quote = pool.marcopolo.getQuote(quoteParams); let received = +(jsbi_1.default.toNumber(quote.outAmount) / 10 ** toCoin.decimals).toFixed(toCoin.decimals); let fees = 0; let amountWithFees = received; let priceImpact = quote.priceImpactPct; return { from: fromCoin.symbol, amountIn: fromCoinAmount, to: toCoin.symbol, amountOut: received, amountWithFees: amountWithFees, minimumReceived: amountWithFees * (1 - settings.slippage / 100), provider: "marcoPolo", fees: fees, priceImpact: priceImpact, routeData: { pool: pool.marcopolo, fromCoin: fromCoin, toCoin: toCoin, } }; } catch (e) { } } exports.marcopoloRoute = marcopoloRoute;