@t2000/cli 1.11.0 → 1.11.2

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.
@@ -100,6 +100,7 @@ import {
100
100
  mapWalletError,
101
101
  mistToSui,
102
102
  naviDescriptor,
103
+ normalizeAsset,
103
104
  normalizeCoinType,
104
105
  parseSuiRpcTx,
105
106
  queryHistory,
@@ -120,7 +121,7 @@ import {
120
121
  usdcToRaw,
121
122
  validateAddress,
122
123
  walletExists
123
- } from "./chunk-33M73WY4.js";
124
+ } from "./chunk-VZAS6UYO.js";
124
125
  import "./chunk-HZYKWFI3.js";
125
126
  import "./chunk-V7PXDEKG.js";
126
127
  import "./chunk-Q2LY5BHK.js";
@@ -227,6 +228,7 @@ export {
227
228
  mapWalletError,
228
229
  mistToSui,
229
230
  naviDescriptor,
231
+ normalizeAsset,
230
232
  normalizeCoinType,
231
233
  parseSuiRpcTx,
232
234
  queryHistory,
@@ -248,4 +250,4 @@ export {
248
250
  validateAddress,
249
251
  walletExists
250
252
  };
251
- //# sourceMappingURL=dist-LMVL6TMD.js.map
253
+ //# sourceMappingURL=dist-B5ZXK5PZ.js.map
@@ -132583,6 +132583,95 @@ var init_volo = __esm2({
132583
132583
  VOLO_STATS_URL = "https://open-api.naviprotocol.io/api/volo/stats";
132584
132584
  }
132585
132585
  });
132586
+ var coinSelection_exports = {};
132587
+ __export2(coinSelection_exports, {
132588
+ fetchAllCoins: () => fetchAllCoins,
132589
+ selectAndSplitCoin: () => selectAndSplitCoin,
132590
+ selectSuiCoin: () => selectSuiCoin
132591
+ });
132592
+ function getMergeCache(tx) {
132593
+ let cache = ptbMergeCache.get(tx);
132594
+ if (!cache) {
132595
+ cache = /* @__PURE__ */ new Map();
132596
+ ptbMergeCache.set(tx, cache);
132597
+ }
132598
+ return cache;
132599
+ }
132600
+ async function fetchAllCoins(client, owner, coinType) {
132601
+ const ids = [];
132602
+ let totalBalance = 0n;
132603
+ let cursor;
132604
+ let hasNext = true;
132605
+ while (hasNext) {
132606
+ const page = await client.getCoins({ owner, coinType, cursor: cursor ?? void 0 });
132607
+ for (const c of page.data) {
132608
+ ids.push(c.coinObjectId);
132609
+ totalBalance += BigInt(c.balance);
132610
+ }
132611
+ cursor = page.nextCursor;
132612
+ hasNext = page.hasNextPage;
132613
+ }
132614
+ return { ids, totalBalance };
132615
+ }
132616
+ async function selectAndSplitCoin(tx, client, owner, coinType, amount2, options = {}) {
132617
+ const cache = getMergeCache(tx);
132618
+ const cacheKey2 = `${owner}|${coinType}`;
132619
+ const cached3 = cache.get(cacheKey2);
132620
+ if (cached3) {
132621
+ const allowSwapAll2 = options.allowSwapAll ?? true;
132622
+ if (amount2 !== "all" && amount2 > cached3.remaining && !allowSwapAll2) {
132623
+ throw new T2000Error("INSUFFICIENT_BALANCE", `Insufficient balance for ${coinType}`, {
132624
+ available: cached3.remaining.toString(),
132625
+ required: amount2.toString()
132626
+ });
132627
+ }
132628
+ const requested2 = amount2 === "all" ? cached3.remaining : amount2;
132629
+ const swapAll2 = amount2 === "all" || requested2 >= cached3.remaining;
132630
+ const effectiveAmount2 = swapAll2 ? cached3.remaining : requested2;
132631
+ const coin2 = swapAll2 ? cached3.primary : tx.splitCoins(cached3.primary, [effectiveAmount2])[0];
132632
+ cached3.remaining = swapAll2 ? 0n : cached3.remaining - effectiveAmount2;
132633
+ return { coin: coin2, effectiveAmount: effectiveAmount2, swapAll: swapAll2 };
132634
+ }
132635
+ const { ids, totalBalance } = await fetchAllCoins(client, owner, coinType);
132636
+ if (ids.length === 0) {
132637
+ throw new T2000Error("INSUFFICIENT_BALANCE", `No coins found for ${coinType}`);
132638
+ }
132639
+ const allowSwapAll = options.allowSwapAll ?? true;
132640
+ if (amount2 !== "all" && amount2 > totalBalance && !allowSwapAll) {
132641
+ throw new T2000Error("INSUFFICIENT_BALANCE", `Insufficient balance for ${coinType}`, {
132642
+ available: totalBalance.toString(),
132643
+ required: amount2.toString()
132644
+ });
132645
+ }
132646
+ const requested = amount2 === "all" ? totalBalance : amount2;
132647
+ const swapAll = amount2 === "all" || requested >= totalBalance;
132648
+ const effectiveAmount = swapAll ? totalBalance : requested;
132649
+ const primary = tx.object(ids[0]);
132650
+ if (ids.length > 1) {
132651
+ tx.mergeCoins(primary, ids.slice(1).map((id) => tx.object(id)));
132652
+ }
132653
+ const coin = swapAll ? primary : tx.splitCoins(primary, [effectiveAmount])[0];
132654
+ cache.set(cacheKey2, {
132655
+ primary,
132656
+ remaining: swapAll ? 0n : totalBalance - effectiveAmount
132657
+ });
132658
+ return { coin, effectiveAmount, swapAll };
132659
+ }
132660
+ async function selectSuiCoin(tx, client, owner, amountMist, sponsoredContext) {
132661
+ if (sponsoredContext) {
132662
+ const { SUI_TYPE: SUI_TYPE22 } = await Promise.resolve().then(() => (init_token_registry(), token_registry_exports));
132663
+ return selectAndSplitCoin(tx, client, owner, SUI_TYPE22, amountMist);
132664
+ }
132665
+ const [coin] = tx.splitCoins(tx.gas, [amountMist]);
132666
+ return { coin, effectiveAmount: amountMist, swapAll: false };
132667
+ }
132668
+ var ptbMergeCache;
132669
+ var init_coinSelection = __esm2({
132670
+ "src/wallet/coinSelection.ts"() {
132671
+ init_errors8();
132672
+ ptbMergeCache = /* @__PURE__ */ new WeakMap();
132673
+ }
132674
+ });
132586
132675
  var cetus_swap_exports = {};
132587
132676
  __export2(cetus_swap_exports, {
132588
132677
  OVERLAY_FEE_RATE: () => OVERLAY_FEE_RATE,
@@ -132677,17 +132766,10 @@ async function addSwapToTx(tx, client, address2, input) {
132677
132766
  inputCoin = input.inputCoin;
132678
132767
  effectiveRaw = requestedRaw;
132679
132768
  } else {
132680
- const { ids, totalBalance } = await fetchAllCoinsForSwap(client, address2, fromType);
132681
- if (ids.length === 0) {
132682
- throw new T2000Error2("INSUFFICIENT_BALANCE", `No ${input.from} coins found in wallet`);
132683
- }
132684
- const swapAll = requestedRaw >= totalBalance;
132685
- effectiveRaw = swapAll ? totalBalance : requestedRaw;
132686
- const primary = tx.object(ids[0]);
132687
- if (ids.length > 1) {
132688
- tx.mergeCoins(primary, ids.slice(1).map((id) => tx.object(id)));
132689
- }
132690
- inputCoin = swapAll ? primary : tx.splitCoins(primary, [effectiveRaw])[0];
132769
+ const { selectAndSplitCoin: selectAndSplitCoin2 } = await Promise.resolve().then(() => (init_coinSelection(), coinSelection_exports));
132770
+ const result = await selectAndSplitCoin2(tx, client, address2, fromType, requestedRaw);
132771
+ inputCoin = result.coin;
132772
+ effectiveRaw = result.effectiveAmount;
132691
132773
  }
132692
132774
  const route = await findSwapRoute({
132693
132775
  walletAddress: address2,
@@ -132719,22 +132801,6 @@ async function addSwapToTx(tx, client, address2, input) {
132719
132801
  route
132720
132802
  };
132721
132803
  }
132722
- async function fetchAllCoinsForSwap(client, owner, coinType) {
132723
- const ids = [];
132724
- let totalBalance = 0n;
132725
- let cursor;
132726
- let hasNext = true;
132727
- while (hasNext) {
132728
- const page = await client.getCoins({ owner, coinType, cursor: cursor ?? void 0 });
132729
- for (const c of page.data) {
132730
- ids.push(c.coinObjectId);
132731
- totalBalance += BigInt(c.balance);
132732
- }
132733
- cursor = page.nextCursor;
132734
- hasNext = page.hasNextPage;
132735
- }
132736
- return { ids, totalBalance };
132737
- }
132738
132804
  async function simulateSwap(params) {
132739
132805
  const client = getClient3(params.walletAddress, params.overlayFee);
132740
132806
  try {
@@ -138984,9 +139050,10 @@ var T2000 = class _T2000 extends import_index2.default {
138984
139050
  }
138985
139051
  };
138986
139052
  init_errors8();
138987
- init_errors8();
139053
+ init_coinSelection();
138988
139054
  init_cetus_swap();
138989
139055
  init_volo();
139056
+ init_coinSelection();
138990
139057
  init_token_registry();
138991
139058
  init_errors8();
138992
139059
  init_errors8();
@@ -140327,7 +140394,7 @@ ${context}
140327
140394
  })
140328
140395
  );
140329
140396
  }
140330
- var PKG_VERSION = "1.11.0";
140397
+ var PKG_VERSION = "1.11.2";
140331
140398
  console.log = (...args) => console.error("[log]", ...args);
140332
140399
  console.warn = (...args) => console.error("[warn]", ...args);
140333
140400
  async function startMcpServer(opts) {
@@ -140417,4 +140484,4 @@ axios/dist/node/axios.cjs:
140417
140484
  @scure/bip39/index.js:
140418
140485
  (*! scure-bip39 - MIT License (c) 2022 Patricio Palladino, Paul Miller (paulmillr.com) *)
140419
140486
  */
140420
- //# sourceMappingURL=dist-LEDCCBZK.js.map
140487
+ //# sourceMappingURL=dist-RE42ANOX.js.map