@t2000/sdk 3.1.1 → 3.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { Transaction, coinWithBalance } from '@mysten/sui/transactions';
1
+ import { coinWithBalance, Transaction } from '@mysten/sui/transactions';
2
2
  import { AggregatorClient, Env } from '@cetusprotocol/aggregator-sdk';
3
3
  import BN from 'bn.js';
4
4
  import { EventEmitter } from 'eventemitter3';
@@ -645,155 +645,6 @@ var require_lodash = __commonJS({
645
645
  }
646
646
  });
647
647
 
648
- // src/protocols/volo.ts
649
- var volo_exports = {};
650
- __export(volo_exports, {
651
- MIN_STAKE_MIST: () => MIN_STAKE_MIST,
652
- SUI_SYSTEM_STATE: () => SUI_SYSTEM_STATE,
653
- VOLO_METADATA: () => VOLO_METADATA,
654
- VOLO_PKG: () => VOLO_PKG,
655
- VOLO_POOL: () => VOLO_POOL,
656
- VSUI_TYPE: () => VSUI_TYPE,
657
- addStakeVSuiToTx: () => addStakeVSuiToTx,
658
- addUnstakeVSuiToTx: () => addUnstakeVSuiToTx,
659
- buildStakeVSuiTx: () => buildStakeVSuiTx,
660
- buildUnstakeVSuiTx: () => buildUnstakeVSuiTx,
661
- getVoloStats: () => getVoloStats
662
- });
663
- async function getVoloStats() {
664
- const res = await fetch(VOLO_STATS_URL, {
665
- signal: AbortSignal.timeout(8e3)
666
- });
667
- if (!res.ok) {
668
- throw new Error(`VOLO stats API error: HTTP ${res.status}`);
669
- }
670
- const data = await res.json();
671
- const d = data.data ?? data;
672
- return {
673
- apy: d.apy ?? 0,
674
- exchangeRate: d.exchange_rate ?? d.exchangeRate ?? 1,
675
- tvl: d.tvl ?? 0
676
- };
677
- }
678
- async function buildStakeVSuiTx(_client, address, amountMist) {
679
- if (amountMist < MIN_STAKE_MIST) {
680
- throw new Error(`Minimum stake is 1 SUI (${MIN_STAKE_MIST} MIST). Got: ${amountMist}`);
681
- }
682
- const tx = new Transaction();
683
- tx.setSender(address);
684
- const [suiCoin] = tx.splitCoins(tx.gas, [amountMist]);
685
- const [vSuiCoin] = tx.moveCall({
686
- target: `${VOLO_PKG}::stake_pool::stake`,
687
- arguments: [
688
- tx.object(VOLO_POOL),
689
- tx.object(VOLO_METADATA),
690
- tx.object(SUI_SYSTEM_STATE),
691
- suiCoin
692
- ]
693
- });
694
- tx.transferObjects([vSuiCoin], address);
695
- return tx;
696
- }
697
- async function buildUnstakeVSuiTx(client, address, amountMist) {
698
- const balResp = await client.getBalance({ owner: address, coinType: VSUI_TYPE });
699
- const totalBalance = BigInt(balResp.totalBalance);
700
- if (totalBalance === 0n) {
701
- throw new Error("No vSUI found in wallet.");
702
- }
703
- const tx = new Transaction();
704
- tx.setSender(address);
705
- const requested = amountMist === "all" ? totalBalance : amountMist;
706
- if (requested > totalBalance) {
707
- throw new Error(`Insufficient vSUI: need ${requested} MIST, have ${totalBalance}`);
708
- }
709
- const vSuiCoin = coinWithBalance({ type: VSUI_TYPE, balance: requested })(tx);
710
- const [suiCoin] = tx.moveCall({
711
- target: `${VOLO_PKG}::stake_pool::unstake`,
712
- arguments: [
713
- tx.object(VOLO_POOL),
714
- tx.object(VOLO_METADATA),
715
- tx.object(SUI_SYSTEM_STATE),
716
- vSuiCoin
717
- ]
718
- });
719
- tx.transferObjects([suiCoin], address);
720
- return tx;
721
- }
722
- async function addStakeVSuiToTx(tx, client, address, input) {
723
- if (input.amountMist < MIN_STAKE_MIST) {
724
- throw new Error(`Minimum stake is 1 SUI (${MIN_STAKE_MIST} MIST). Got: ${input.amountMist}`);
725
- }
726
- let suiCoin;
727
- if (input.inputCoin) {
728
- suiCoin = input.inputCoin;
729
- } else {
730
- const balResp = await client.getBalance({ owner: address, coinType: SUI_TYPE });
731
- const totalBalance = BigInt(balResp.totalBalance);
732
- if (totalBalance < input.amountMist) {
733
- throw new Error(`Insufficient SUI: need ${input.amountMist} MIST, have ${totalBalance}`);
734
- }
735
- suiCoin = coinWithBalance({
736
- type: SUI_TYPE,
737
- balance: input.amountMist,
738
- useGasCoin: false
739
- })(tx);
740
- }
741
- const [vSuiCoin] = tx.moveCall({
742
- target: `${VOLO_PKG}::stake_pool::stake`,
743
- arguments: [
744
- tx.object(VOLO_POOL),
745
- tx.object(VOLO_METADATA),
746
- tx.object(SUI_SYSTEM_STATE),
747
- suiCoin
748
- ]
749
- });
750
- return { coin: vSuiCoin, effectiveAmountMist: input.amountMist };
751
- }
752
- async function addUnstakeVSuiToTx(tx, client, address, input) {
753
- let vSuiCoin;
754
- if (input.inputCoin) {
755
- if (input.amountMist === "all") {
756
- vSuiCoin = input.inputCoin;
757
- } else {
758
- [vSuiCoin] = tx.splitCoins(input.inputCoin, [input.amountMist]);
759
- }
760
- } else {
761
- const balResp = await client.getBalance({ owner: address, coinType: VSUI_TYPE });
762
- const totalBalance = BigInt(balResp.totalBalance);
763
- if (totalBalance === 0n) {
764
- throw new Error("No vSUI found in wallet.");
765
- }
766
- const requested = input.amountMist === "all" ? totalBalance : input.amountMist;
767
- if (requested > totalBalance) {
768
- throw new Error(`Insufficient vSUI: need ${requested} MIST, have ${totalBalance}`);
769
- }
770
- vSuiCoin = coinWithBalance({ type: VSUI_TYPE, balance: requested })(tx);
771
- }
772
- const [suiCoin] = tx.moveCall({
773
- target: `${VOLO_PKG}::stake_pool::unstake`,
774
- arguments: [
775
- tx.object(VOLO_POOL),
776
- tx.object(VOLO_METADATA),
777
- tx.object(SUI_SYSTEM_STATE),
778
- vSuiCoin
779
- ]
780
- });
781
- return { coin: suiCoin, effectiveAmountMist: input.amountMist };
782
- }
783
- var VOLO_PKG, VOLO_POOL, VOLO_METADATA, VSUI_TYPE, SUI_SYSTEM_STATE, MIN_STAKE_MIST, VOLO_STATS_URL;
784
- var init_volo = __esm({
785
- "src/protocols/volo.ts"() {
786
- init_token_registry();
787
- VOLO_PKG = "0x68d22cf8bdbcd11ecba1e094922873e4080d4d11133e2443fddda0bfd11dae20";
788
- VOLO_POOL = "0x2d914e23d82fedef1b5f56a32d5c64bdcc3087ccfea2b4d6ea51a71f587840e5";
789
- VOLO_METADATA = "0x680cd26af32b2bde8d3361e804c53ec1d1cfe24c7f039eb7f549e8dfde389a60";
790
- VSUI_TYPE = "0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT";
791
- SUI_SYSTEM_STATE = "0x05";
792
- MIN_STAKE_MIST = 1000000000n;
793
- VOLO_STATS_URL = "https://open-api.naviprotocol.io/api/volo/stats";
794
- }
795
- });
796
-
797
648
  // src/wallet/coinSelection.ts
798
649
  var coinSelection_exports = {};
799
650
  __export(coinSelection_exports, {
@@ -1139,6 +990,65 @@ var init_cetus_swap = __esm({
1139
990
  }
1140
991
  });
1141
992
 
993
+ // src/swap-quote.ts
994
+ var swap_quote_exports = {};
995
+ __export(swap_quote_exports, {
996
+ getSwapQuote: () => getSwapQuote
997
+ });
998
+ async function getSwapQuote(params) {
999
+ const { findSwapRoute: findSwapRoute2, resolveTokenType: resolveTokenType2 } = await Promise.resolve().then(() => (init_cetus_swap(), cetus_swap_exports));
1000
+ const fromType = resolveTokenType2(params.from);
1001
+ const toType = resolveTokenType2(params.to);
1002
+ if (!fromType) {
1003
+ throw new T2000Error(
1004
+ "ASSET_NOT_SUPPORTED",
1005
+ `Unknown token: ${params.from}. Provide the symbol (USDC, SUI, ...) or full coin type.`
1006
+ );
1007
+ }
1008
+ if (!toType) {
1009
+ throw new T2000Error(
1010
+ "ASSET_NOT_SUPPORTED",
1011
+ `Unknown token: ${params.to}. Provide the symbol (USDC, SUI, ...) or full coin type.`
1012
+ );
1013
+ }
1014
+ const byAmountIn = params.byAmountIn ?? true;
1015
+ const fromDecimals = getDecimalsForCoinType(fromType);
1016
+ const rawAmount = BigInt(Math.floor(params.amount * 10 ** fromDecimals));
1017
+ const route = await findSwapRoute2({
1018
+ walletAddress: params.walletAddress,
1019
+ from: fromType,
1020
+ to: toType,
1021
+ amount: rawAmount,
1022
+ byAmountIn,
1023
+ providers: params.providers
1024
+ });
1025
+ if (!route) throw new T2000Error("SWAP_FAILED", `No swap route found for ${params.from} -> ${params.to}.`);
1026
+ if (route.insufficientLiquidity) {
1027
+ throw new T2000Error("SWAP_FAILED", `Insufficient liquidity for ${params.from} -> ${params.to}.`);
1028
+ }
1029
+ const toDecimals = getDecimalsForCoinType(toType);
1030
+ const fromAmount = Number(route.amountIn) / 10 ** fromDecimals;
1031
+ const toAmount = Number(route.amountOut) / 10 ** toDecimals;
1032
+ const routeDesc = route.routerData.paths?.map((p) => p.provider).filter(Boolean).slice(0, 3).join(" + ") ?? "Cetus Aggregator";
1033
+ const { serializeCetusRoute: serializeCetusRoute2 } = await Promise.resolve().then(() => (init_cetus_swap(), cetus_swap_exports));
1034
+ const serializedRoute = serializeCetusRoute2(route, { fromCoinType: fromType, toCoinType: toType });
1035
+ return {
1036
+ fromToken: params.from,
1037
+ toToken: params.to,
1038
+ fromAmount,
1039
+ toAmount,
1040
+ priceImpact: route.priceImpact,
1041
+ route: routeDesc,
1042
+ serializedRoute
1043
+ };
1044
+ }
1045
+ var init_swap_quote = __esm({
1046
+ "src/swap-quote.ts"() {
1047
+ init_errors();
1048
+ init_token_registry();
1049
+ }
1050
+ });
1051
+
1142
1052
  // src/constants.ts
1143
1053
  init_errors();
1144
1054
  var MIST_PER_SUI = 1000000000n;
@@ -1204,7 +1114,8 @@ var SUPPORTED_ASSETS = {
1204
1114
  displayName: "XAUM"
1205
1115
  }
1206
1116
  };
1207
- var STABLE_ASSETS = ["USDC"];
1117
+ var STABLE_ASSETS = ["USDC", "USDsui"];
1118
+ var SAVEABLE_ASSETS = ["USDC", "USDsui"];
1208
1119
  var ALL_NAVI_ASSETS = Object.keys(SUPPORTED_ASSETS);
1209
1120
  var OPERATION_ASSETS = {
1210
1121
  save: ["USDC", "USDsui"],
@@ -6009,7 +5920,7 @@ var ProtocolRegistry = class {
6009
5920
  }
6010
5921
  async bestSaveRateAcrossAssets() {
6011
5922
  const candidates = [];
6012
- for (const asset of STABLE_ASSETS) {
5923
+ for (const asset of SAVEABLE_ASSETS) {
6013
5924
  for (const adapter of this.lending.values()) {
6014
5925
  if (!adapter.supportedAssets.includes(asset)) continue;
6015
5926
  if (!adapter.capabilities.includes("save")) continue;
@@ -6029,7 +5940,7 @@ var ProtocolRegistry = class {
6029
5940
  async allRatesAcrossAssets() {
6030
5941
  const results = [];
6031
5942
  const seen = /* @__PURE__ */ new Set();
6032
- for (const asset of STABLE_ASSETS) {
5943
+ for (const asset of SAVEABLE_ASSETS) {
6033
5944
  if (seen.has(asset)) continue;
6034
5945
  seen.add(asset);
6035
5946
  for (const adapter of this.lending.values()) {
@@ -6639,51 +6550,14 @@ var T2000 = class _T2000 extends EventEmitter {
6639
6550
  receipt: paymentDigest ? { reference: paymentDigest, timestamp: (/* @__PURE__ */ new Date()).toISOString() } : void 0
6640
6551
  };
6641
6552
  }
6642
- // -- VOLO vSUI Staking --
6643
- async stakeVSui(params) {
6644
- this.enforcer.assertNotLocked();
6645
- const { buildStakeVSuiTx: buildStakeVSuiTx2, getVoloStats: getVoloStats2 } = await Promise.resolve().then(() => (init_volo(), volo_exports));
6646
- const amountMist = BigInt(Math.floor(params.amount * Number(MIST_PER_SUI)));
6647
- const stats = await getVoloStats2();
6648
- const gasResult = await executeTx(this.client, this._signer, async () => {
6649
- return buildStakeVSuiTx2(this.client, this._address, amountMist);
6650
- });
6651
- const vSuiReceived = params.amount / stats.exchangeRate;
6652
- return {
6653
- success: true,
6654
- tx: gasResult.digest,
6655
- amountSui: params.amount,
6656
- vSuiReceived,
6657
- apy: stats.apy,
6658
- gasCost: gasResult.gasCostSui
6659
- };
6660
- }
6661
- async unstakeVSui(params) {
6662
- this.enforcer.assertNotLocked();
6663
- const { buildUnstakeVSuiTx: buildUnstakeVSuiTx2, getVoloStats: getVoloStats2, VSUI_TYPE: VSUI_TYPE2 } = await Promise.resolve().then(() => (init_volo(), volo_exports));
6664
- let amountMist;
6665
- let vSuiAmount;
6666
- if (params.amount === "all") {
6667
- amountMist = "all";
6668
- const bal = await this.client.getBalance({ owner: this._address, coinType: VSUI_TYPE2 });
6669
- vSuiAmount = Number(bal.totalBalance) / 1e9;
6670
- } else {
6671
- amountMist = BigInt(Math.floor(params.amount * 1e9));
6672
- vSuiAmount = params.amount;
6673
- }
6674
- const stats = await getVoloStats2();
6675
- const gasResult = await executeTx(this.client, this._signer, async () => {
6676
- return buildUnstakeVSuiTx2(this.client, this._address, amountMist);
6677
- });
6678
- const suiReceived = vSuiAmount * stats.exchangeRate;
6679
- return {
6680
- success: true,
6681
- tx: gasResult.digest,
6682
- vSuiAmount,
6683
- suiReceived,
6684
- gasCost: gasResult.gasCostSui
6685
- };
6686
- }
6553
+ // [S.323 / 2026-05-25] VOLO vSUI staking surfaces removed (full cut).
6554
+ // Engine cut Volo in S.277; SDK + CLI + MCP followed in S.323 because the
6555
+ // product surface (five products: Passport / Intelligence / Finance / Pay
6556
+ // / Store) doesn't include a staking primitive. vSUI still appears in the
6557
+ // codebase as a passive token (NAVI reward rewards, Cetus swap routing),
6558
+ // but there is no longer any way to MINT or REDEEM vSUI through t2000.
6559
+ // History: see spec/archive/v07e/AUDIT_V07E_EARNS_ITS_KEEP_2026-05-23.md
6560
+ // and the S.323 build-tracker entry.
6687
6561
  // -- Swap --
6688
6562
  async swap(params) {
6689
6563
  this.enforcer.assertNotLocked();
@@ -6791,36 +6665,24 @@ var T2000 = class _T2000 extends EventEmitter {
6791
6665
  gasCost: gasResult.gasCostSui
6792
6666
  };
6793
6667
  }
6668
+ /**
6669
+ * [SPEC_AGENTIC_STACK P1 / SDK F2 — 2026-05-25]
6670
+ * Thin wrapper around the standalone `getSwapQuote()`. Pre-Phase 1 this method
6671
+ * was ~50 LoC duplicating `swap-quote.ts` — missing `serializedRoute` (SPEC 20.2
6672
+ * fast-path) and the `providers` allow-list (Bug A fix / Pyth-dependent
6673
+ * provider filter for sponsored callers). Routing both API surfaces through
6674
+ * one implementation ensures fixes land for both.
6675
+ */
6794
6676
  async swapQuote(params) {
6795
- const { findSwapRoute: findSwapRoute2, resolveTokenType: resolveTokenType2 } = await Promise.resolve().then(() => (init_cetus_swap(), cetus_swap_exports));
6796
- const fromType = resolveTokenType2(params.from);
6797
- const toType = resolveTokenType2(params.to);
6798
- if (!fromType) throw new T2000Error("ASSET_NOT_SUPPORTED", `Unknown token: ${params.from}. Provide the full coin type.`);
6799
- if (!toType) throw new T2000Error("ASSET_NOT_SUPPORTED", `Unknown token: ${params.to}. Provide the full coin type.`);
6800
- const byAmountIn = params.byAmountIn ?? true;
6801
- const fromDecimals = getDecimalsForCoinType(fromType);
6802
- const rawAmount = BigInt(Math.floor(params.amount * 10 ** fromDecimals));
6803
- const route = await findSwapRoute2({
6677
+ const { getSwapQuote: getSwapQuote2 } = await Promise.resolve().then(() => (init_swap_quote(), swap_quote_exports));
6678
+ return getSwapQuote2({
6804
6679
  walletAddress: this._address,
6805
- from: fromType,
6806
- to: toType,
6807
- amount: rawAmount,
6808
- byAmountIn
6680
+ from: params.from,
6681
+ to: params.to,
6682
+ amount: params.amount,
6683
+ byAmountIn: params.byAmountIn,
6684
+ providers: params.providers
6809
6685
  });
6810
- if (!route) throw new T2000Error("SWAP_NO_ROUTE", `No swap route found for ${params.from} -> ${params.to}.`);
6811
- if (route.insufficientLiquidity) throw new T2000Error("SWAP_NO_ROUTE", `Insufficient liquidity for ${params.from} -> ${params.to}.`);
6812
- const toDecimals = getDecimalsForCoinType(toType);
6813
- const fromAmount = Number(route.amountIn) / 10 ** fromDecimals;
6814
- const toAmount = Number(route.amountOut) / 10 ** toDecimals;
6815
- const routeDesc = route.routerData.paths?.map((p) => p.provider).filter(Boolean).slice(0, 3).join(" + ") ?? "Cetus Aggregator";
6816
- return {
6817
- fromToken: params.from,
6818
- toToken: params.to,
6819
- fromAmount,
6820
- toAmount,
6821
- priceImpact: route.priceImpact,
6822
- route: routeDesc
6823
- };
6824
6686
  }
6825
6687
  // -- Wallet --
6826
6688
  address() {
@@ -6951,6 +6813,16 @@ var T2000 = class _T2000 extends EventEmitter {
6951
6813
  ].join("\n")
6952
6814
  };
6953
6815
  }
6816
+ /**
6817
+ * [SPEC_AGENTIC_STACK P1 / SDK F2 (CLI rename support) — 2026-05-25]
6818
+ * Preferred alias of `deposit()`. The CLI surface is `t2000 fund` post-Phase 1
6819
+ * (more intuitive than "deposit" which sounds like a NAVI lending action).
6820
+ * `deposit()` stays as the canonical method name for back-compat; it is NOT
6821
+ * deprecated. This wrapper exists so SDK consumers can mirror CLI naming.
6822
+ */
6823
+ async fund() {
6824
+ return this.deposit();
6825
+ }
6954
6826
  receive(params) {
6955
6827
  const amount = params?.amount ?? null;
6956
6828
  const currency = params?.currency ?? "USDC";
@@ -7665,7 +7537,7 @@ var T2000 = class _T2000 extends EventEmitter {
7665
7537
  this.emit("yield", {
7666
7538
  earned: result.dailyEarning,
7667
7539
  total: result.totalYieldEarned,
7668
- apy: result.currentApy / 100,
7540
+ apy: result.currentApy,
7669
7541
  timestamp: Date.now()
7670
7542
  });
7671
7543
  }
@@ -7912,7 +7784,6 @@ async function buildHarvestRewardsTx(client, address, options = {}) {
7912
7784
 
7913
7785
  // src/composeTx.ts
7914
7786
  init_cetus_swap();
7915
- init_volo();
7916
7787
  init_coinSelection();
7917
7788
  init_token_registry();
7918
7789
  init_errors();
@@ -8136,41 +8007,8 @@ var WRITE_APPENDER_REGISTRY = {
8136
8007
  expectedUsdcDeposited: plan.expectedUsdcDeposited
8137
8008
  }
8138
8009
  };
8139
- },
8140
- volo_stake: async (tx, input, ctx) => {
8141
- if (input.amountSui <= 0) {
8142
- throw new T2000Error("INVALID_AMOUNT", "Stake amount must be greater than zero");
8143
- }
8144
- const amountMist = BigInt(Math.floor(input.amountSui * 1e9));
8145
- const result = await addStakeVSuiToTx(tx, ctx.client, ctx.sender, {
8146
- amountMist,
8147
- inputCoin: ctx.chainedCoin
8148
- });
8149
- if (!ctx.isOutputConsumed) {
8150
- tx.transferObjects([result.coin], ctx.sender);
8151
- }
8152
- return {
8153
- preview: { toolName: "volo_stake", effectiveAmountMist: result.effectiveAmountMist },
8154
- outputCoin: result.coin
8155
- };
8156
- },
8157
- volo_unstake: async (tx, input, ctx) => {
8158
- const amountMist = input.amountVSui === "all" ? "all" : BigInt(Math.floor(input.amountVSui * 1e9));
8159
- if (amountMist !== "all" && amountMist <= 0n) {
8160
- throw new T2000Error("INVALID_AMOUNT", "Unstake amount must be greater than zero");
8161
- }
8162
- const result = await addUnstakeVSuiToTx(tx, ctx.client, ctx.sender, {
8163
- amountMist,
8164
- inputCoin: ctx.chainedCoin
8165
- });
8166
- if (!ctx.isOutputConsumed) {
8167
- tx.transferObjects([result.coin], ctx.sender);
8168
- }
8169
- return {
8170
- preview: { toolName: "volo_unstake", effectiveAmountMist: result.effectiveAmountMist },
8171
- outputCoin: result.coin
8172
- };
8173
8010
  }
8011
+ // [S.323 / 2026-05-25] volo_stake / volo_unstake appenders removed.
8174
8012
  };
8175
8013
  function deriveAllowedAddressesFromPtb(tx) {
8176
8014
  const addresses = /* @__PURE__ */ new Set();
@@ -8231,7 +8069,7 @@ async function composeTx(opts) {
8231
8069
  if (producer.toolName === "save_deposit" || producer.toolName === "repay_debt" || producer.toolName === "send_transfer" || producer.toolName === "claim_rewards") {
8232
8070
  throw new T2000Error(
8233
8071
  "CHAIN_MODE_INVALID",
8234
- `Step ${i} (${step.toolName}) references step ${idx} (${producer.toolName}) as producer, but '${producer.toolName}' is a terminal consumer that does not produce a chainable coin handle. Allowed producers: withdraw, borrow, swap_execute, volo_stake, volo_unstake.`
8072
+ `Step ${i} (${step.toolName}) references step ${idx} (${producer.toolName}) as producer, but '${producer.toolName}' is a terminal consumer that does not produce a chainable coin handle. Allowed producers: withdraw, borrow, swap_execute.`
8235
8073
  );
8236
8074
  }
8237
8075
  consumedSteps.add(idx);
@@ -8447,61 +8285,10 @@ function parseMoveAbort(errorStr) {
8447
8285
  return { reason: errorStr };
8448
8286
  }
8449
8287
 
8450
- // src/swap-quote.ts
8451
- init_errors();
8452
- init_token_registry();
8453
- async function getSwapQuote(params) {
8454
- const { findSwapRoute: findSwapRoute2, resolveTokenType: resolveTokenType2 } = await Promise.resolve().then(() => (init_cetus_swap(), cetus_swap_exports));
8455
- const fromType = resolveTokenType2(params.from);
8456
- const toType = resolveTokenType2(params.to);
8457
- if (!fromType) {
8458
- throw new T2000Error(
8459
- "ASSET_NOT_SUPPORTED",
8460
- `Unknown token: ${params.from}. Provide the symbol (USDC, SUI, ...) or full coin type.`
8461
- );
8462
- }
8463
- if (!toType) {
8464
- throw new T2000Error(
8465
- "ASSET_NOT_SUPPORTED",
8466
- `Unknown token: ${params.to}. Provide the symbol (USDC, SUI, ...) or full coin type.`
8467
- );
8468
- }
8469
- const byAmountIn = params.byAmountIn ?? true;
8470
- const fromDecimals = getDecimalsForCoinType(fromType);
8471
- const rawAmount = BigInt(Math.floor(params.amount * 10 ** fromDecimals));
8472
- const route = await findSwapRoute2({
8473
- walletAddress: params.walletAddress,
8474
- from: fromType,
8475
- to: toType,
8476
- amount: rawAmount,
8477
- byAmountIn,
8478
- providers: params.providers
8479
- });
8480
- if (!route) throw new T2000Error("SWAP_FAILED", `No swap route found for ${params.from} -> ${params.to}.`);
8481
- if (route.insufficientLiquidity) {
8482
- throw new T2000Error("SWAP_FAILED", `Insufficient liquidity for ${params.from} -> ${params.to}.`);
8483
- }
8484
- const toDecimals = getDecimalsForCoinType(toType);
8485
- const fromAmount = Number(route.amountIn) / 10 ** fromDecimals;
8486
- const toAmount = Number(route.amountOut) / 10 ** toDecimals;
8487
- const routeDesc = route.routerData.paths?.map((p) => p.provider).filter(Boolean).slice(0, 3).join(" + ") ?? "Cetus Aggregator";
8488
- const { serializeCetusRoute: serializeCetusRoute2 } = await Promise.resolve().then(() => (init_cetus_swap(), cetus_swap_exports));
8489
- const serializedRoute = serializeCetusRoute2(route, { fromCoinType: fromType, toCoinType: toType });
8490
- return {
8491
- fromToken: params.from,
8492
- toToken: params.to,
8493
- fromAmount,
8494
- toAmount,
8495
- priceImpact: route.priceImpact,
8496
- route: routeDesc,
8497
- serializedRoute
8498
- };
8499
- }
8500
-
8501
8288
  // src/index.ts
8289
+ init_swap_quote();
8502
8290
  init_cetus_swap();
8503
8291
  init_token_registry();
8504
- init_volo();
8505
8292
  var AUDRIC_PARENT_NAME = "audric.sui";
8506
8293
  var AUDRIC_PARENT_NFT_ID = "0x070456e283ec988b6302bdd6cc5172bbdcb709998cf116586fb98d19b0870198";
8507
8294
  var LABEL_PATTERN = /^[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/;
@@ -8569,6 +8356,6 @@ function displayHandle(label) {
8569
8356
  (*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
8570
8357
  */
8571
8358
 
8572
- export { ALL_NAVI_ASSETS, AUDRIC_PARENT_NAME, AUDRIC_PARENT_NFT_ID, BORROW_FEE_BPS, BPS_DENOMINATOR, CETUS_USDC_SUI_POOL, CLOCK_ID, COIN_REGISTRY, ContactManager, DEFAULT_NETWORK, DEFAULT_SAFEGUARD_CONFIG, ETH_TYPE, GAS_RESERVE_MIN, HF_CRITICAL_THRESHOLD, HF_WARN_THRESHOLD, IKA_TYPE, InvalidAddressError, KNOWN_TARGETS, KeypairSigner, LABEL_PATTERNS, LOFI_TYPE, MANIFEST_TYPE, MIST_PER_SUI, NAVX_TYPE, NaviAdapter, OPERATION_ASSETS, OUTBOUND_OPS, OVERLAY_FEE_RATE, ProtocolRegistry, SAVE_FEE_BPS, SPONSORED_PYTH_DEPENDENT_PROVIDERS, STABLE_ASSETS, SUINS_NAME_REGEX, SUI_ADDRESS_REGEX, SUI_ADDRESS_STRICT_REGEX, SUI_DECIMALS, SUI_TYPE, SUPPORTED_ASSETS, SafeguardEnforcer, SafeguardError, SuinsNotRegisteredError, SuinsRpcError, T2000, T2000Error, T2000_OVERLAY_FEE_WALLET, TOKEN_MAP, USDC_DECIMALS, USDC_TYPE, USDE_TYPE, USDSUI_TYPE, USDT_TYPE, VOLO_METADATA, VOLO_PKG, VOLO_POOL, VSUI_TYPE, WAL_TYPE, WBTC_TYPE, WRITE_APPENDER_REGISTRY, ZkLoginSigner, addClaimRewardsToTx, addFeeTransfer, addSendToTx, addStakeVSuiToTx, addSwapToTx, addUnstakeVSuiToTx, aggregateClaimableRewards, allDescriptors, assertAllowedAsset, buildAddLeafTx, buildClaimRewardsTx, buildHarvestRewardsTx, buildRevokeLeafTx, buildSendTx, buildStakeVSuiTx, buildSwapTx, buildUnstakeVSuiTx, calculateFee, classifyAction, classifyLabel, classifyTransaction, composeTx, deriveAllowedAddressesFromPtb, deserializeCetusRoute, displayHandle, exportPrivateKey, extractAllUserLegs, extractTransferDetails, extractTxCommands, extractTxSender, fallbackLabel, fetchAllCoins, findSwapRoute, formatAssetAmount, formatSui, formatUsd, fullHandle, generateKeypair, getAddress, getCoinMeta, getDecimals, getDecimalsForCoinType, getFinancialSummary, getPendingRewards, getPendingRewardsByAddress, getRates, getSponsoredSwapProviders, getSwapQuote, getTier, getVoloStats, isAllowedAsset, isCetusRouteFresh, isInRegistry, isSupported, isTier1, isTier2, keypairFromPrivateKey, loadKey, looksLikeSuiNs, mapMoveAbortCode, mapWalletError, mistToSui, naviDescriptor, normalizeAddressInput, normalizeAsset, normalizeCoinType, parseSuiRpcTx, queryHistory, queryTransaction, rawToStable, rawToUsdc, refineLendingLabel, resolveAddressToSuinsViaRpc, resolveSuinsViaRpc, resolveSymbol, resolveTokenType, saveKey, selectAndSplitCoin, selectSuiCoin, serializeCetusRoute, simulateTransaction, stableToRaw, suiToMist, throwIfSimulationFailed, truncateAddress, usdcToRaw, validateAddress, validateLabel, verifyCetusRouteCoinMatch, walletExists };
8359
+ export { ALL_NAVI_ASSETS, AUDRIC_PARENT_NAME, AUDRIC_PARENT_NFT_ID, BORROW_FEE_BPS, BPS_DENOMINATOR, CETUS_USDC_SUI_POOL, CLOCK_ID, COIN_REGISTRY, ContactManager, DEFAULT_NETWORK, DEFAULT_SAFEGUARD_CONFIG, ETH_TYPE, GAS_RESERVE_MIN, HF_CRITICAL_THRESHOLD, HF_WARN_THRESHOLD, IKA_TYPE, InvalidAddressError, KNOWN_TARGETS, KeypairSigner, LABEL_PATTERNS, LOFI_TYPE, MANIFEST_TYPE, MIST_PER_SUI, NAVX_TYPE, NaviAdapter, OPERATION_ASSETS, OUTBOUND_OPS, OVERLAY_FEE_RATE, ProtocolRegistry, SAVEABLE_ASSETS, SAVE_FEE_BPS, SPONSORED_PYTH_DEPENDENT_PROVIDERS, STABLE_ASSETS, SUINS_NAME_REGEX, SUI_ADDRESS_REGEX, SUI_ADDRESS_STRICT_REGEX, SUI_DECIMALS, SUI_TYPE, SUPPORTED_ASSETS, SafeguardEnforcer, SafeguardError, SuinsNotRegisteredError, SuinsRpcError, T2000, T2000Error, T2000_OVERLAY_FEE_WALLET, TOKEN_MAP, USDC_DECIMALS, USDC_TYPE, USDE_TYPE, USDSUI_TYPE, USDT_TYPE, WAL_TYPE, WBTC_TYPE, WRITE_APPENDER_REGISTRY, ZkLoginSigner, addClaimRewardsToTx, addFeeTransfer, addSendToTx, addSwapToTx, aggregateClaimableRewards, allDescriptors, assertAllowedAsset, buildAddLeafTx, buildClaimRewardsTx, buildHarvestRewardsTx, buildRevokeLeafTx, buildSendTx, buildSwapTx, calculateFee, classifyAction, classifyLabel, classifyTransaction, composeTx, deriveAllowedAddressesFromPtb, deserializeCetusRoute, displayHandle, exportPrivateKey, extractAllUserLegs, extractTransferDetails, extractTxCommands, extractTxSender, fallbackLabel, fetchAllCoins, findSwapRoute, formatAssetAmount, formatSui, formatUsd, fullHandle, generateKeypair, getAddress, getCoinMeta, getDecimals, getDecimalsForCoinType, getFinancialSummary, getPendingRewards, getPendingRewardsByAddress, getRates, getSponsoredSwapProviders, getSwapQuote, getTier, isAllowedAsset, isCetusRouteFresh, isInRegistry, isSupported, isTier1, isTier2, keypairFromPrivateKey, loadKey, looksLikeSuiNs, mapMoveAbortCode, mapWalletError, mistToSui, naviDescriptor, normalizeAddressInput, normalizeAsset, normalizeCoinType, parseSuiRpcTx, queryHistory, queryTransaction, rawToStable, rawToUsdc, refineLendingLabel, resolveAddressToSuinsViaRpc, resolveSuinsViaRpc, resolveSymbol, resolveTokenType, saveKey, selectAndSplitCoin, selectSuiCoin, serializeCetusRoute, simulateTransaction, stableToRaw, suiToMist, throwIfSimulationFailed, truncateAddress, usdcToRaw, validateAddress, validateLabel, verifyCetusRouteCoinMatch, walletExists };
8573
8360
  //# sourceMappingURL=index.js.map
8574
8361
  //# sourceMappingURL=index.js.map