UNPKG

@accret/bridge-sdk

Version:
66 lines 2.8 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getMayanQuote = getMayanQuote; exports.getMayanTokenList = getMayanTokenList; exports.executeMayanSwap = executeMayanSwap; const getQuote_1 = require("./getQuote"); const utils_1 = require("../../utils"); const getTokenList_1 = require("./getTokenList"); const buildTransaction_1 = require("./buildTransaction"); /** * @description Fetches a quote for swapping tokens on the Mayan network * @param params - The parameters for fetching a Mayan quote * @param params.fromChain - The chain from which to swap * @param params.fromToken - The token to swap from * @param params.toChain - The chain to which to swap * @param params.toToken - The token to swap to * @param params.amount - The amount to swap * @param params.slippageBps - The slippage in basis points (default is 50) * @param params.referrer - The referrer for the swap (optional) * @param params.referrerBps - The referrer basis points (optional) * @param params.referrerAddress - The referrer address (optional) * @returns A promise that resolves to the best quote for the swap */ async function getMayanQuote(params) { const mayanQuote = await (0, getQuote_1.getQuote)({ fromChain: (0, utils_1.getChainInfo)(params.fromChain).mayan, fromToken: params.fromToken, toChain: (0, utils_1.getChainInfo)(params.toChain).mayan, toToken: params.toToken, amount: params.amount, slippageBps: params.slippageBps || 50, }); if (!mayanQuote || mayanQuote.length === 0) { throw new Error("No quotes found for the given parameters"); } const bestQuote = mayanQuote[0]; if (!bestQuote) { throw new Error("No best quote found"); } return bestQuote; } /** * @description Fetches the token list for a specific Mayan chain * @param chain - The chain for which to fetch the token list * @returns A promise that resolves to the token list response */ async function getMayanTokenList(chain) { const chainInfo = (0, utils_1.getChainInfo)(chain).mayan; if (!chainInfo) { throw new Error(`Unsupported chain: ${chain}`); } const tokenList = await (0, getTokenList_1.getTokenList)(chainInfo); return tokenList; } /** * @description Executes a swap on the Mayan network * @param quote - The quote object containing swap details * @param destAddr - The destination address for the swap * @param privateKey - The private key of the wallet initiating the swap * @returns The transaction hash of the executed swap */ async function executeMayanSwap({ quote, destAddr, privateKey, }) { const txHash = await (0, buildTransaction_1.buildTransaction)(quote, destAddr, privateKey); return txHash; } //# sourceMappingURL=index.js.map