UNPKG

@hyperionxyz/sdk

Version:

This SDK allows you to interact with the Hyperion API. You can use it to request data, create pools/positions and more.

1,111 lines (1,110 loc) 31 kB
var v = Object.defineProperty; var L = (n, t, e) => t in n ? v(n, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : n[t] = e; var d = (n, t, e) => L(n, typeof t != "symbol" ? t + "" : t, e); import { AccountAddress as H, Network as A, Aptos as G, AptosConfig as j } from "@aptos-labs/ts-sdk"; import { TokenPairs as b, Token as U } from "aptos-tool"; import i from "bignumber.js"; import F from "long"; import { CallArgument as y } from "@aptos-labs/script-composer-sdk"; i.config({ EXPONENTIAL_AT: 1e9 }); const l = (n) => F.fromInt(i(n).dp(0).toNumber()).toUnsigned().toInt(), q = 1.0001, K = (n) => Math.log(new i(n).toNumber()) / Math.log(q), N = () => Math.floor(100 * 365 * 24 * 60 * 60 + Date.now() / 1e3), W = "-443636", D = "443636"; var z = /* @__PURE__ */ ((n) => (n[n["PER_0.01_SPACING_1"] = 0] = "PER_0.01_SPACING_1", n[n["PER_0.05_SPACING_5"] = 1] = "PER_0.05_SPACING_5", n[n["PER_0.3_SPACING_60"] = 2] = "PER_0.3_SPACING_60", n[n.PER_1_SPACING_200 = 3] = "PER_1_SPACING_200", n[n["PER_0.1_SPACING_20"] = 4] = "PER_0.1_SPACING_20", n[n["PER_0.25_SPACING_50"] = 5] = "PER_0.25_SPACING_50", n))(z || {}); const It = ["1", "5", "30", "100", "10", "25"], Y = [1, 10, 60, 200, 20, 50], Ot = [ -443636, -443630, -443580, -443600, -443620, -443600 ], Bt = [ 443636, 443630, 443580, 443600, 443620, 443600 ], Rt = 184467440737095520, T = (n, t) => { const e = Y[t]; return new i(n).div(e).dp(0, i.ROUND_HALF_UP).times(e).toString(); }, $t = ({ price: n, feeTierIndex: t, decimalsRatio: e }) => { const o = K(new i(n).div(e)); return isNaN(o) ? null : i(o).lt(0) ? i.max( T(o, t), T(W, t) ) : i.min( T(o, t), T(D, t) ); }, qt = ({ tick: n, decimalsRatio: t }) => new i(Math.pow(q, new i(n).dp(0).toNumber())).times(t).toString(), x = !1, f = (n) => { if (!n.currencyA || !n.currencyB) throw new Error( "currencyA and currencyB are required and can not be empty" ); if (!n.currencyA.startsWith("0x") || !n.currencyB.startsWith("0x")) throw new Error( "currencyA and currencyB must be valid aptos account/token address" ); }, w = (n) => { if ((!n.slippage || i(n.slippage).isNaN()) && (n.slippage = 0.5), i(n.slippage).lt(0)) throw new Error("slippage must be greater than 0"); if (i(n.slippage).gt(20)) throw new Error("slippage must be less than 20"); }, h = (n, t) => new i(n).minus(i(n).times(t).div(100)).dp(0).toNumber(); i.config({ EXPONENTIAL_AT: 1e9 }); class V { constructor(t) { d(this, "_sdk"); this._sdk = t; } async fetchAllPools() { const t = await this._sdk.requestModule.get( "/base/data/pools/stats" ); return (t == null ? void 0 : t.items) || []; } async fetchPoolById({ poolId: t }) { const e = await this._sdk.requestModule.get( "/base/data/pools/stats", { poolId: t } ); return (e == null ? void 0 : e.items) || []; } async getPoolByTokenPairAndFeeTier({ token1: t, token2: e, feeTier: o }) { const r = await this._sdk.requestModule.get( "/base/data/pools/by-token-pair", { token1: t, token2: e, feeTier: o } ); return (r == null ? void 0 : r.item) || r || {}; } // TODO: fetch pool by tokenPair Addresses and fee rate /** * Creates a liquidity pool * * This method is used to initialize a liquidity pool. */ async createPoolTransactionPayload(t) { f(t), w(t); const e = [t.currencyA, t.currencyB], o = [ i(t.currencyAAmount).toNumber(), i(t.currencyBAmount).toNumber() ], r = o.map( (c) => h(c, t.slippage) ), a = [ i(t.feeTierIndex).toNumber(), x, l(t.tickLower), l(t.tickUpper), l(t.currentPriceTick), ...o, ...r, N() ], s = [...a]; return [s[5], s[6]] = [s[6], s[5]], [s[7], s[8]] = [s[8], s[7]], [s[2], s[3], s[4]] = [ l(i(t.tickUpper).times(-1).toNumber()), l(i(t.tickLower).times(-1).toNumber()), l(i(t.currentPriceTick).times(-1).toNumber()) ], b.TokenPairTypeCheck(e, [ { function: `${this._sdk.sdkOptions.contractAddress}::router_adapter::create_liquidity_entry`, typeArguments: [], functionArguments: [...e, ...a] }, { function: `${this._sdk.sdkOptions.contractAddress}::router_adapter::create_liquidity_both_coin_entry`, typeArguments: [...e], functionArguments: [...a] }, { function: `${this._sdk.sdkOptions.contractAddress}::router_adapter::create_liquidity_coin_entry`, typeArguments: [e[0]], functionArguments: [e[1], ...a] }, // fa & coin { function: `${this._sdk.sdkOptions.contractAddress}::router_adapter::create_liquidity_coin_entry`, // TokenB typeArguments: [e[1]], // TokenA // [AmountB, AmountA] // [SlippageB, SlippageA] functionArguments: [e[0], ...s] } ]); } async fetchTicks({ poolId: t }) { const e = await this._sdk.requestModule.get( `/base/data/pools/${t}/liquidity-accumulation` ); return (e == null ? void 0 : e.items) || []; } // TODO: return data type in docs // [number_a, number_b] async estCurrencyAAmountFromB(t) { const e = { function: `${this._sdk.sdkOptions.contractAddress}::router_v3::optimal_liquidity_amounts_from_b`, typeArguments: [], functionArguments: [ l(t.tickLower), l(t.tickUpper), l(t.currentPriceTick), t.currencyA, t.currencyB, t.feeTierIndex, t.currencyBAmount, 0, 0 ] }; return console.log(e), await this._sdk.AptosClient.view({ payload: e }); } async estCurrencyBAmountFromA(t) { const e = { function: `${this._sdk.sdkOptions.contractAddress}::router_v3::optimal_liquidity_amounts_from_a`, typeArguments: [], functionArguments: [ // fixed tick order l(t.tickLower), l(t.tickUpper), l(t.currentPriceTick), t.currencyA, t.currencyB, t.feeTierIndex, t.currencyAAmount, 0, 0 ] }; return await this._sdk.AptosClient.view({ payload: e }); } } i.config({ EXPONENTIAL_AT: 1e9 }); class X { constructor(t) { d(this, "_sdk"); this._sdk = t; } async fetchAllPositionsByAddress({ address: t }) { const e = await this._sdk.requestModule.get( "/base/data/positions", { address: t } ); return Array.isArray(e) ? e : (e == null ? void 0 : e.items) || []; } async fetchPositionById(t) { const e = await this._sdk.requestModule.get( "/base/data/liquidity/ownerships", { objectId: t.positionId, ownerAddress: t.address } ); return (e == null ? void 0 : e.items) || []; } /** * Fetch the history of Fee Reward claim * * @param args * @returns */ async fetchFeeHistory(t) { var o; const e = await this._sdk.requestModule.get( "/base/data/rewards/claimed-fees", { objectId: t.positionId, ownerAddress: t.address } ); return (o = e == null ? void 0 : e.items) == null ? void 0 : o.filter((r) => !new i(r.amount).isEqualTo(0)); } // async fetchFeePayload({ positionId }: { positionId: string }) { // return { // function: `${this._sdk.sdkOptions.contractAddress}::pool_v3::get_pending_fees`, // typeArguments: [], // functionArguments: [positionId], // }; // } /** * Adds liquidity to a liquidity pool * * This method is used to add liquidity to a liquidity pool. */ async addLiquidityTransactionPayload(t) { f(t), w(t); const e = [t.currencyA, t.currencyB], o = [ i(t.currencyAAmount).toNumber(), i(t.currencyBAmount).toNumber() ], r = o.map( (c) => h(c, t.slippage) ), a = [ i(t.feeTierIndex).toNumber(), x, ...o, ...r, N() ], s = [...a]; return [s[2], s[3]] = [s[3], s[2]], [s[4], s[5]] = [s[5], s[4]], b.TokenPairTypeCheck(e, [ { function: `${this._sdk.sdkOptions.contractAddress}::router_adapter::add_liquidity_entry`, typeArguments: [], functionArguments: [t.positionId, ...e, ...a] }, { function: `${this._sdk.sdkOptions.contractAddress}::router_adapter::add_liquidity_both_coin_entry`, typeArguments: [...e], functionArguments: [t.positionId, ...a] }, { function: `${this._sdk.sdkOptions.contractAddress}::router_adapter::add_liquidity_coin_entry`, typeArguments: [e[0]], functionArguments: [t.positionId, e[1], ...a] }, { function: `${this._sdk.sdkOptions.contractAddress}::router_adapter::add_liquidity_coin_entry`, typeArguments: [e[1]], functionArguments: [ t.positionId, e[0], ...s ] } ]); } /** * Removes liquidity from a liquidity pool * * This method is used to remove liquidity from a liquidity pool. */ removeLiquidityTransactionPayload(t) { if (console.log(t), f(t), w(t), !H.isValid({ input: t.recipient, strict: !0 }).valid) throw new Error("Invalid recipient address"); const e = [t.currencyA, t.currencyB], r = [ i(t.currencyAAmount).toNumber(), i(t.currencyBAmount).toNumber() ].map( (s) => h(s, t.slippage) ), a = [ t.positionId, i(t.deltaLiquidity).dp(0).toNumber(), ...r, t.recipient, N() ]; return b.TokenPairTypeCheck(e, [ { function: `${this._sdk.sdkOptions.contractAddress}::router_adapter::remove_liquidity_entry_v2`, typeArguments: [], functionArguments: a }, { function: `${this._sdk.sdkOptions.contractAddress}::router_adapter::remove_liquidity_both_coins_entry_v2`, typeArguments: [...e], functionArguments: a }, { function: `${this._sdk.sdkOptions.contractAddress}::router_adapter::remove_liquidity_coin_entry_v2`, typeArguments: [e[0]], functionArguments: a }, { function: `${this._sdk.sdkOptions.contractAddress}::router_adapter::remove_liquidity_coin_entry_v2`, typeArguments: [e[1]], functionArguments: a } ]); } claimFeeTransactionPayload({ positionId: t, recipient: e }) { return { function: `${this._sdk.sdkOptions.contractAddress}::router_v3::claim_fees`, typeArguments: [], functionArguments: [[t], e] }; } claimRewardTransactionPayload({ positionId: t, recipient: e }) { return { function: `${this._sdk.sdkOptions.contractAddress}::router_v3::claim_rewards`, typeArguments: [], functionArguments: [t, e] }; } claimAllRewardsTransactionPayload({ positionId: t, recipient: e }) { return { function: `${this._sdk.sdkOptions.contractAddress}::router_v3::claim_fees_and_rewards`, typeArguments: [], functionArguments: [[t], e] }; } /** * * @param positionId * * @returns [currencyAAmount, currencyBAmount] */ async fetchTokensAmountByPositionId({ positionId: t }) { const e = { function: `${this._sdk.sdkOptions.contractAddress}::router_v3::get_amount_by_liquidity`, typeArguments: [], functionArguments: [t] }; return await this._sdk.AptosClient.view({ payload: e }); } } function J(n) { return n.replace(/\/v1\/graphql\/?$/, "").replace(/\/$/, ""); } class Q { constructor(t) { d(this, "_apiHost"); this._apiHost = J(t.indexerURL); } async get(t, e = {}) { const o = new URL(t, `${this._apiHost}/`); Object.entries(e).forEach(([a, s]) => { s !== void 0 && o.searchParams.set(a, s.toString()); }); const r = await fetch(o, { method: "GET", headers: { "Content-Type": "application/json" } }); if (!r.ok) throw new Error( `Hyperion API request failed: ${r.status} ${r.statusText}` ); return await r.json(); } get indexerURL() { return this._apiHost; } } i.config({ EXPONENTIAL_AT: 1e9 }); class Z { constructor(t) { d(this, "_sdk"); this._sdk = t; } fetchRewardsPayload({ positionId: t }) { return { function: `${this._sdk.sdkOptions.contractAddress}::pool_v3::get_pending_rewards`, typeArguments: [], functionArguments: [t] }; } /** * Fetch the history of Fee Farm claim * * @param args * @returns */ async fetchRewardHistory(t) { var o; const e = await this._sdk.requestModule.get( "/base/data/rewards/claimed-farms", { objectId: t.positionId, ownerAddress: t.address } ); return (o = e == null ? void 0 : e.items) == null ? void 0 : o.filter((r) => !new i(r.amount).isEqualTo(0)); } claimRewardPayload({ positionId: t, recipient: e }) { return { function: `${this._sdk.sdkOptions.contractAddress}::router_v3::claim_rewards`, typeArguments: [], functionArguments: [t, e] }; } } const k = "0xc3290d98d622b9ab354277e0b1c5e66552f9784d2d4fb473ff321b9338485117", tt = "hyperion-aggregator"; async function E(n, t) { let e = await P( n, "0x1::fungible_asset::Metadata", t ); return (await n.addBatchedCalls({ function: "0x1::fungible_asset::zero", typeArguments: ["0x1::fungible_asset::Metadata"], functionArguments: [e] }))[0]; } async function et(n, t, e) { return (await n.addBatchedCalls({ function: "0x1::fungible_asset::extract", typeArguments: [], functionArguments: [t.borrowMut(), e] }))[0]; } async function C(n, t, e) { await n.addBatchedCalls({ function: "0x1::fungible_asset::merge", typeArguments: [], functionArguments: [t.borrowMut(), e] }); } async function nt(n, t, e) { return (await n.addBatchedCalls({ function: "0x1::primary_fungible_store::withdraw", typeArguments: ["0x1::fungible_asset::Metadata"], functionArguments: [y.newSigner(0), t, e] }))[0]; } async function m(n, t, e) { await n.addBatchedCalls({ function: "0x1::primary_fungible_store::deposit", typeArguments: [], functionArguments: [t, e] }); } async function I(n, t) { return (await n.addBatchedCalls({ function: "0x1::fungible_asset::amount", typeArguments: [], functionArguments: [t.borrow()] }))[0]; } async function P(n, t, e) { return (await n.addBatchedCalls({ function: "0x1::object::address_to_object", typeArguments: [t], functionArguments: [e] }))[0]; } async function ot(n, t, e, o) { return (await n.addBatchedCalls({ function: `${k}::tool::split_fa_proportionlly`, typeArguments: [], functionArguments: [t.borrowMut(), e, o * 100] }))[0]; } async function R(n, t, e) { await n.addBatchedCalls({ function: `${k}::tool::fa_amount_check`, typeArguments: [], functionArguments: [t.borrow(), e] }); } async function st(n, t, e, o) { await n.addBatchedCalls({ function: `${k}::tool::deposit_fa_exact`, typeArguments: [], functionArguments: [t, e.borrowMut(), o] }); } async function rt(n) { return (await n.addBatchedCalls({ function: `${k}::tool::get_signer_address`, typeArguments: [], functionArguments: [y.newSigner(0)] }))[0]; } const at = "0x4bf51972879e3b95c4781a5cdcb9e1ee24ef483e7d22f2d903626f126df62bd1"; async function it(n, t, e, o) { return (await n.addBatchedCalls({ function: `${at}::router::swap`, typeArguments: [], functionArguments: [t, 0, e, o] }))[0]; } async function ct(n, t, e, o, r, a, s, c, u) { let p = await I(n, a), _ = await n.addBatchedCalls({ function: `${c.contractAddress}::partnership::swap`, typeArguments: [], functionArguments: [ e, o, r, p, a, s, u || tt ] }); return await m(n, t, _[1]), _[2]; } const O = "0x7730cd28ee1cdc9e999336cbc430f99e7c44397c0aa77516f6f23a78559bb5"; async function ut(n, t, e, o) { let r = await P( n, "0x1::fungible_asset::Metadata", o ); return (await n.addBatchedCalls({ function: `${O}::pool::swap_exact_in_stable`, typeArguments: [], functionArguments: [y.newSigner(0), t, e, r] }))[0]; } async function dt(n, t, e, o) { let r = await P( n, "0x1::fungible_asset::Metadata", o ); return (await n.addBatchedCalls({ function: `${O}::pool::swap_exact_in_metastable`, typeArguments: [], functionArguments: [y.newSigner(0), t, e, r] }))[0]; } async function pt(n, t, e, o) { return (await n.addBatchedCalls({ function: `${O}::pool::swap_exact_in_weighted`, typeArguments: [], functionArguments: [y.newSigner(0), t, e, o] }))[0]; } async function lt(n, t, e, o, r, a, s, c) { return (await n.addBatchedCalls({ function: `${k}::tool::swap_in_emoji`, typeArguments: [t, e], functionArguments: [ y.newSigner(0), r, a, s, c, o ] }))[1]; } async function _t(n, t, e, o, r, a) { let s; return s = await ct( n, o.copy(), t.poolId, t.a2b, !0, e, t.sqrtPriceLimit, r, a ), s; } async function mt(n, t, e) { let o; if (t.poolType == "stable") o = !0; else if (t.poolType == "unstable") o = !1; else throw "pool type mismatch"; return await it( n, e, t.toToken.tokenType, o ); } async function yt(n, t, e) { let o; if (t.poolType == "stable") o = await ut( n, t.poolId, e, t.toToken.tokenType ); else if (t.poolType == "weighted") o = await pt( n, t.poolId, e, t.toToken.tokenType ); else if (t.poolType == "meta") o = await dt( n, t.poolId, e, t.toToken.tokenType ); else throw "type mismatch"; return o; } async function At(n, t, e) { return await lt( n, t.firstType, t.secondType, e, t.poolId, t.isSell, t.integrator, t.integratorFee ); } async function ft(n, t, e, o, r, a) { let s; if (t.dexName == "Hyperion") s = await _t( n, t, e, o.copy(), r, a ); else if (t.dexName == "Cellana") s = await mt(n, t, e); else if (t.dexName == "ThalaSwapV2") s = await yt(n, t, e); else if (t.dexName == "EmojiCoin") s = await At(n, t, e); else throw "Dex Not Supported"; return s; } async function $(n, t, e, o, r, a) { for (const s of t) { let c; c = await E(n, s.toToken.tokenType); let u = await ft( n, s, e, o.copy(), r, a ); await C(n, c, u), e = c; } return e; } class wt { constructor(t) { d(this, "_sdk"); this._sdk = t; } /** * Fetch the aggregate swap route * @param args AggregateSwapRouteArgs * @param args.amount The amount of the input token * @param args.from The address of the input token * @param args.input The address of the input token, either equals to args.from or args.to * @param args.slippage The slippage tolerance * @param args.to The address of the output token * @returns */ async fetchAggregateSwapRoute(t) { const e = new URLSearchParams({ slippage: t.slippage.toString(), amount: t.amount.toString(), from: t.from, input: t.input, to: t.to }), o = await fetch( `${this._sdk.sdkOptions.hyperionAPIHost}/base/aggregator/getAggRoute?${e.toString()}`, { method: "GET", headers: { "Content-Type": "application/json" } } ); if (!o.ok) throw new Error( `Failed to fetch aggregate swap route: ${o.statusText}` ); return await o.json(); } /** * Generate the aggregate swap transaction script * @param args AggregateSwapInfoResult & { builder: AptosScriptComposer; partnershipId?: string } * @param args.builder The builder of the transaction * @param args.partnershipId The partnership ID, only work on MAINNET * @returns The transaction script */ async generateAggregateSwapTransactionScript(t) { const { builder: e } = t; let o = await rt(e), r; t.exactIn ? r = Number(t.fromTokenAmount) : r = Number(t.maxFromTokenAmount); let a, s, c = await P( e, "0x1::fungible_asset::Metadata", t.fromToken.address ); s = await nt(e, c, r), a = await I(e, s); const u = await E(e, t.toToken.address); for (const p of t.quotes.route) { let _; _ = await et(e, s, p.amountIn); let g = await $( e, p.routeTaken, _, o.copy(), this._sdk.sdkOptions, t.partnershipId ); await C(e, u, g); } if (t.exactIn) await R(e, u, Number(t.minToTokenAmount)), await m(e, o.copy(), u), await m(e, o.copy(), s); else { let p = 0; await R(e, u, Number(t.toTokenAmount)), await st( e, o.copy(), u, Number(t.toTokenAmount) ); let _; _ = await E(e, t.fromToken.address), a = await I(e, u); for (const g of t.quotes.refundRoute) { let B, S = g.percentage; p += S, p == 100 && (S = 100), B = await ot( e, u, a.copy(), S ); let M = await $( e, g.routeTaken, B, o.copy(), this._sdk.sdkOptions, t.partnershipId ); await C(e, _, M); } if (await m(e, o.copy(), u), await m(e, o.copy(), s), await m(e, o.copy(), _), p != 100) throw "not 100% refund"; } } } class ht { constructor(t) { d(this, "_sdk"); d(this, "_aggregateSwapHelper"); this._sdk = t, this._aggregateSwapHelper = new wt(t); } /** * Generate the transaction payload for swap * @param args SwapTransactionPayloadArgs * @param args.currencyA The FA address of currency * @param args.currencyB The FA address of currency * @param args.currencyAAmount The amount of the input token * @param args.currencyBAmount The amount of the output token * @param args.slippage The slippage tolerance * @param args.poolRoute The pool route * @param args.recipient The recipient address * @returns The transaction payload for swap */ swapTransactionPayload(t) { f(t), w(t); const e = [t.currencyA, t.currencyB], o = [t.currencyAAmount, t.currencyBAmount], r = [ o[0], h(o[1], t.slippage) ], a = [...e]; a.forEach((c, u) => { if ((c == null ? void 0 : c.indexOf("::")) > -1) { const p = new U({ coinType: c, // for construct Token instance, useless & meaningless name: "token", symbol: "token", decimals: 5, assetType: "" }); p.faTypeCalculate(), p.faType && (a[u] = p.faType); } }); const s = [ t.poolRoute, ...a, ...r, t.recipient ]; return b.TokenPairTypeCheck(e, [ { function: `${this._sdk.sdkOptions.contractAddress}::router_v3::swap_batch`, typeArguments: [], functionArguments: [...s] }, // ================ // if the from token is coin token { function: `${this._sdk.sdkOptions.contractAddress}::router_v3::swap_batch_coin_entry`, typeArguments: [e[0]], functionArguments: [...s] }, { function: `${this._sdk.sdkOptions.contractAddress}::router_v3::swap_batch_coin_entry`, typeArguments: [e[0]], functionArguments: [...s] }, // ================ { function: `${this._sdk.sdkOptions.contractAddress}::router_v3::swap_batch`, typeArguments: [], functionArguments: [...s] } ]); } /** * Generate the transaction payload for swap with partnership * @param args SwapTransactionPayloadArgs & { partnership: string } * @param args.currencyA The FA address of currency * @param args.currencyB The FA address of currency * @param args.currencyAAmount The amount of the input token * @param args.currencyBAmount The amount of the output token * @param args.slippage The slippage tolerance * @param args.poolRoute The pool route * @param args.recipient The recipient address * @param args.partnership The partnership address * @returns */ swapWithPartnershipTransactionPayload(t) { if (f(t), w(t), !t.partnership || t.partnership.length === 0) throw new Error("partnership is required"); const e = [t.currencyA, t.currencyB], o = [t.currencyAAmount, t.currencyBAmount], r = [ o[0], h(o[1], t.slippage) ]; return { function: `${this._sdk.sdkOptions.contractAddress}::partnership::swap_batch_directly_deposit`, typeArguments: [], functionArguments: [ t.poolRoute, e[0], e[1], ...r, t.partnership ] }; } /** * Estimate the amount of currency A from currency B * @param args EstFromAmountArgs * @param args.amount The amount of the input token * @param args.from The address of the input token * @param args.to The address of the output token * @param args.safeMode Whether to use safe mode, only work on MAINNET * @returns */ async estFromAmount(t) { const e = new URLSearchParams({ amount: t.amount.toString(), from: t.from, to: t.to, safeMode: t.safeMode ? "true" : "false", flag: "out" }); return await (await fetch( `${this._sdk.sdkOptions.hyperionAPIHost}/base/rate/getSwapInfo?${e.toString()}`, { method: "GET", headers: { "Content-Type": "application/json" } } )).json(); } /** * Estimate the amount of currency B from currency A * @param args EstFromAmountArgs * @param args.amount The amount of the input token * @param args.from The address of the input token * @param args.to The address of the output token * @param args.safeMode Whether to use safe mode, only work on MAINNET * @returns */ async estToAmount(t) { const e = new URLSearchParams({ amount: t.amount.toString(), from: t.from, to: t.to, safeMode: t.safeMode ? "true" : "false", flag: "in" }); return await (await fetch( `${this._sdk.sdkOptions.hyperionAPIHost}/base/rate/getSwapInfo?${e.toString()}`, { method: "GET", headers: { "Content-Type": "application/json" } } )).json(); } /** * Estimate the amount of currency A from currency B by aggregate swap * @param args AggregateSwapRouteArgs * @param args.amount The amount of the input token * @param args.from The address of the input token * @param args.input The address of the input token, either equals to args.from or args.to * @param args.slippage The slippage tolerance * @param args.to The address of the output token * @returns The result of aggregate swap * * @example * ```ts * // Estimate the result of currency A from currency B by aggregate swap * const result = await SDK.Swap.estAmountByAggregateSwap({ * amount: "10000000", * from: "A_AssetType", * input: "B_AssetType", * slippage: 0.1, * to: "B_AssetType", * }); * console.log(result); * ``` * * or * ```ts * // Estimate the result of currency B from currency A by aggregate swap * const result = await SDK.Swap.estAmountByAggregateSwap({ * amount: "10000000", * from: "B_AssetType", * input: "A_AssetType", * slippage: 0.1, * to: "A_AssetType", * }); * console.log(result); * ``` */ async estAmountByAggregateSwap(t) { if (this._sdk.sdkOptions.network !== A.MAINNET) throw new Error("Aggregate swap is only supported on MAINNET"); return await this._aggregateSwapHelper.fetchAggregateSwapRoute(t); } /** * Generate the transaction script for aggregate swap * @param args AggregateSwapRouteArgs * @param args.amount The amount of the input token * @param args.from The address of the input token * @param args.input The address of the input token, either equals to args.from or args.to * @param args.slippage The slippage tolerance * @param args.to The address of the output token * @param args.builder The builder of the transaction * @param args.partnershipId The partnership ID, only work on MAINNET * @returns The transaction script for aggregate swap */ async generateAggregateSwapTransactionScript(t) { if (this._sdk.sdkOptions.network !== A.MAINNET) throw new Error("Aggregate swap is only supported on MAINNET"); return await this._aggregateSwapHelper.generateAggregateSwapTransactionScript( t ); } } const kt = { network: A.TESTNET, contractAddress: "0x69faed94da99abb7316cb3ec2eeaa1b961a47349fad8c584f67a930b0d14fec7", hyperionFullNodeIndexerURL: "https://api-testnet.hyperion.xyz", hyperionAPIHost: "https://api-testnet.hyperion.xyz", APTOS_API_KEY: "" }, gt = { network: A.MAINNET, contractAddress: "0x8b4a2c4bb53857c718a04c020b98f8c2e1f99a68b0f57389a8bf5434cd22e05c", hyperionFullNodeIndexerURL: "https://api.hyperion.xyz", hyperionAPIHost: "https://api.hyperion.xyz", APTOS_API_KEY: "" }; function xt(n) { const { network: t, APTOS_API_KEY: e } = n; return new Tt({ ...t == A.MAINNET ? gt : kt, APTOS_API_KEY: e }); } class Tt { constructor(t) { d(this, "_options"); d(this, "_requestModule"); d(this, "_pool"); d(this, "_position"); d(this, "_swap"); d(this, "_reward"); d(this, "_aptosClient"); this._options = t, this._requestModule = new Q({ indexerURL: this._options.hyperionFullNodeIndexerURL }), this._pool = new V(this), this._position = new X(this), this._swap = new ht(this), this._reward = new Z(this); const e = { API_KEY: this._options.APTOS_API_KEY }; this._aptosClient = new G( new j({ network: this._options.network, clientConfig: e }) ); } get Pool() { return this._pool; } get Position() { return this._position; } get Swap() { return this._swap; } get Reward() { return this._reward; } get AptosClient() { return this._aptosClient; } get sdkOptions() { return this._options; } get requestModule() { return this._requestModule; } } export { q as BASE, z as FeeTierIndex, It as FeeTierItems, Y as FeeTierStep, D as HIGHEST_TICK, Bt as HighestTickByStep, Tt as HyperionSDK, W as LOWEST_TICK, Ot as LowestTickByStep, x as POOL_STABLE_TYPE, f as currencyCheck, xt as initHyperionSDK, K as logBase, N as poolDeadline, $t as priceToTick, T as roundTickBySpacing, h as slippageCalculator, w as slippageCheck, l as tickComplement, qt as tickToPrice, Rt as u64Max };