@t2000/cli 1.0.1 → 1.1.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.
@@ -35,6 +35,7 @@ import {
35
35
  SafeguardError,
36
36
  T2000,
37
37
  T2000Error,
38
+ T2000_OVERLAY_FEE_WALLET,
38
39
  TOKEN_MAP,
39
40
  USDC_DECIMALS,
40
41
  USDC_TYPE,
@@ -48,7 +49,7 @@ import {
48
49
  WAL_TYPE,
49
50
  WBTC_TYPE,
50
51
  ZkLoginSigner,
51
- addCollectFeeToTx,
52
+ addFeeTransfer,
52
53
  allDescriptors,
53
54
  assertAllowedAsset,
54
55
  buildStakeVSuiTx,
@@ -105,7 +106,7 @@ import {
105
106
  usdcToRaw,
106
107
  validateAddress,
107
108
  walletExists
108
- } from "./chunk-G2DXW5RK.js";
109
+ } from "./chunk-KDR2GPAB.js";
109
110
  import "./chunk-V7PXDEKG.js";
110
111
  import "./chunk-Q2LY5BHK.js";
111
112
  import "./chunk-3XUF7GM3.js";
@@ -146,6 +147,7 @@ export {
146
147
  SafeguardError,
147
148
  T2000,
148
149
  T2000Error,
150
+ T2000_OVERLAY_FEE_WALLET,
149
151
  TOKEN_MAP,
150
152
  USDC_DECIMALS,
151
153
  USDC_TYPE,
@@ -159,7 +161,7 @@ export {
159
161
  WAL_TYPE,
160
162
  WBTC_TYPE,
161
163
  ZkLoginSigner,
162
- addCollectFeeToTx,
164
+ addFeeTransfer,
163
165
  allDescriptors,
164
166
  assertAllowedAsset,
165
167
  buildStakeVSuiTx,
@@ -217,4 +219,4 @@ export {
217
219
  validateAddress,
218
220
  walletExists
219
221
  };
220
- //# sourceMappingURL=dist-4CCB73ET.js.map
222
+ //# sourceMappingURL=dist-67XBQC7P.js.map
@@ -130097,18 +130097,22 @@ __export2(cetus_swap_exports, {
130097
130097
  resolveTokenType: () => resolveTokenType,
130098
130098
  simulateSwap: () => simulateSwap
130099
130099
  });
130100
- function getClient3(walletAddress) {
130101
- if (clientInstance) return clientInstance;
130102
- clientInstance = new AggregatorClient({
130100
+ function getClient3(walletAddress, overlayFee) {
130101
+ const rate = overlayFee?.rate ?? 0;
130102
+ const receiver = overlayFee?.receiver ?? "";
130103
+ const key = `${walletAddress}|${rate}|${receiver}`;
130104
+ const cached3 = clientCache.get(key);
130105
+ if (cached3) return cached3;
130106
+ const client = new AggregatorClient({
130103
130107
  signer: walletAddress,
130104
130108
  env: Env.Mainnet,
130105
- overlayFeeRate: OVERLAY_FEE_RATE,
130106
- overlayFeeReceiver: OVERLAY_FEE_RECEIVER
130109
+ ...rate > 0 && receiver ? { overlayFeeRate: rate, overlayFeeReceiver: receiver } : {}
130107
130110
  });
130108
- return clientInstance;
130111
+ clientCache.set(key, client);
130112
+ return client;
130109
130113
  }
130110
130114
  async function findSwapRoute(params) {
130111
- const client = getClient3(params.walletAddress);
130115
+ const client = getClient3(params.walletAddress, params.overlayFee);
130112
130116
  const findParams = {
130113
130117
  from: params.from,
130114
130118
  target: params.to,
@@ -130145,7 +130149,7 @@ function normalizePriceImpact(value) {
130145
130149
  return Number.isFinite(n) ? n : 0;
130146
130150
  }
130147
130151
  async function buildSwapTx(params) {
130148
- const client = getClient3(params.walletAddress);
130152
+ const client = getClient3(params.walletAddress, params.overlayFee);
130149
130153
  const clampedSlippage = Math.max(1e-3, Math.min(params.slippage, 0.05));
130150
130154
  const outputCoin = await client.routerSwap({
130151
130155
  router: params.route.routerData,
@@ -130156,7 +130160,7 @@ async function buildSwapTx(params) {
130156
130160
  return outputCoin;
130157
130161
  }
130158
130162
  async function simulateSwap(params) {
130159
- const client = getClient3(params.walletAddress);
130163
+ const client = getClient3(params.walletAddress, params.overlayFee);
130160
130164
  try {
130161
130165
  await client.devInspectTransactionBlock(params.tx);
130162
130166
  return { success: true };
@@ -130165,22 +130169,16 @@ async function simulateSwap(params) {
130165
130169
  }
130166
130170
  }
130167
130171
  var OVERLAY_FEE_RATE;
130168
- var OVERLAY_FEE_RECEIVER;
130169
- var clientInstance;
130172
+ var clientCache;
130170
130173
  var init_cetus_swap = __esm2({
130171
130174
  "src/protocols/cetus-swap.ts"() {
130172
130175
  init_token_registry();
130173
130176
  OVERLAY_FEE_RATE = 1e-3;
130174
- OVERLAY_FEE_RECEIVER = process.env.T2000_TREASURY_ADDRESS ?? "0x3bb501b8300125dca59019247941a42af6b292a150ce3cfcce9449456be2ec91";
130175
- clientInstance = null;
130177
+ clientCache = /* @__PURE__ */ new Map();
130176
130178
  }
130177
130179
  });
130178
130180
  init_errors7();
130179
130181
  var MIST_PER_SUI2 = 1000000000n;
130180
- var USDC_DECIMALS = 6;
130181
- var BPS_DENOMINATOR = 10000n;
130182
- var SAVE_FEE_BPS = 10n;
130183
- var BORROW_FEE_BPS = 5n;
130184
130182
  var SUPPORTED_ASSETS = {
130185
130183
  USDC: {
130186
130184
  type: "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC",
@@ -130264,12 +130262,12 @@ function assertAllowedAsset(op, asset) {
130264
130262
  );
130265
130263
  }
130266
130264
  }
130267
- var T2000_PACKAGE_ID = process.env.T2000_PACKAGE_ID ?? "0xd775fcc66eae26797654d435d751dea56b82eeb999de51fd285348e573b968ad";
130268
- var T2000_CONFIG_ID = process.env.T2000_CONFIG_ID ?? "0x08ba26f0d260b5edf6a19c71492b3eb914906a7419baf2df1426765157e5862a";
130269
- var T2000_TREASURY_ID = process.env.T2000_TREASURY_ID ?? "0xf420ec0dcad44433042fb56e1413fb88d3ff65be94fcf425ef9ff750164590e8";
130265
+ process.env.T2000_PACKAGE_ID ?? "0xd775fcc66eae26797654d435d751dea56b82eeb999de51fd285348e573b968ad";
130266
+ process.env.T2000_CONFIG_ID ?? "0x08ba26f0d260b5edf6a19c71492b3eb914906a7419baf2df1426765157e5862a";
130267
+ process.env.T2000_OVERLAY_FEE_WALLET ?? "0x5366efbf2b4fe5767fe2e78eb197aa5f5d138d88ac3333fbf3f80a1927da473a";
130270
130268
  var DEFAULT_RPC_URL = "https://fullnode.mainnet.sui.io:443";
130271
130269
  var DEFAULT_KEY_PATH = "~/.t2000/wallet.key";
130272
- var API_BASE_URL = process.env.T2000_API_URL ?? "https://api.t2000.ai";
130270
+ process.env.T2000_API_URL ?? "https://api.t2000.ai";
130273
130271
  var CETUS_USDC_SUI_POOL = "0x51e883ba7c0b566a26cbc8a94cd33eb0abd418a77cc1e60ad22fd9b1f29cd2ab";
130274
130272
  init_errors7();
130275
130273
  var cachedClient = null;
@@ -130429,9 +130427,6 @@ var ZkLoginSigner = class {
130429
130427
  }
130430
130428
  };
130431
130429
  init_errors7();
130432
- function usdcToRaw(amount2) {
130433
- return BigInt(Math.round(amount2 * 10 ** USDC_DECIMALS));
130434
- }
130435
130430
  function stableToRaw(amount2, decimals2) {
130436
130431
  return BigInt(Math.round(amount2 * 10 ** decimals2));
130437
130432
  }
@@ -130738,55 +130733,6 @@ function extractCommands(txBlock) {
130738
130733
  return result;
130739
130734
  }
130740
130735
  init_token_registry();
130741
- var FEE_RATES = {
130742
- save: SAVE_FEE_BPS,
130743
- borrow: BORROW_FEE_BPS
130744
- };
130745
- var OP_CODES = {
130746
- save: 0,
130747
- borrow: 2
130748
- };
130749
- function calculateFee(operation, amount2) {
130750
- const bps2 = FEE_RATES[operation];
130751
- const feeAmount = amount2 * Number(bps2) / Number(BPS_DENOMINATOR);
130752
- const rawAmount = usdcToRaw(feeAmount);
130753
- return {
130754
- amount: feeAmount,
130755
- asset: "USDC",
130756
- rate: Number(bps2) / Number(BPS_DENOMINATOR),
130757
- rawAmount
130758
- };
130759
- }
130760
- function addCollectFeeToTx(tx, paymentCoin, operation) {
130761
- const bps2 = FEE_RATES[operation];
130762
- if (bps2 <= 0n) return;
130763
- tx.moveCall({
130764
- target: `${T2000_PACKAGE_ID}::treasury::collect_fee`,
130765
- typeArguments: [SUPPORTED_ASSETS.USDC.type],
130766
- arguments: [
130767
- tx.object(T2000_TREASURY_ID),
130768
- tx.object(T2000_CONFIG_ID),
130769
- paymentCoin,
130770
- tx.pure.u8(OP_CODES[operation])
130771
- ]
130772
- });
130773
- }
130774
- async function reportFee(agentAddress, operation, feeAmount, feeRate, txDigest) {
130775
- try {
130776
- await fetch(`${API_BASE_URL}/api/fees`, {
130777
- method: "POST",
130778
- headers: { "Content-Type": "application/json" },
130779
- body: JSON.stringify({
130780
- agentAddress,
130781
- operation,
130782
- feeAmount: feeAmount.toString(),
130783
- feeRate: feeRate.toString(),
130784
- txDigest
130785
- })
130786
- });
130787
- } catch {
130788
- }
130789
- }
130790
130736
  function ulebEncode2(num2) {
130791
130737
  let bigNum = BigInt(num2);
130792
130738
  const arr = [];
@@ -134545,9 +134491,6 @@ async function buildSaveTx(client, address2, amount2, options = {}) {
134545
134491
  const tx = new Transaction();
134546
134492
  tx.setSender(address2);
134547
134493
  const coinObj = mergeCoins(tx, coins);
134548
- if (options.collectFee) {
134549
- addCollectFeeToTx(tx, coinObj, "save");
134550
- }
134551
134494
  const rawAmount = Math.min(Number(stableToRaw(amount2, assetInfo.decimals)), Number(totalBalance));
134552
134495
  try {
134553
134496
  await Ce(tx, assetInfo.type, coinObj, {
@@ -134618,9 +134561,6 @@ async function addWithdrawToTx(tx, client, address2, amount2, options = {}) {
134618
134561
  async function addSaveToTx(tx, _client, _address, coin, options = {}) {
134619
134562
  const asset = options.asset ?? "USDC";
134620
134563
  const assetInfo = resolveAssetInfo(asset);
134621
- if (options.collectFee) {
134622
- addCollectFeeToTx(tx, coin, "save");
134623
- }
134624
134564
  try {
134625
134565
  await Ce(tx, assetInfo.type, coin, { env: "prod" });
134626
134566
  } catch (err) {
@@ -134651,9 +134591,6 @@ async function buildBorrowTx(client, address2, amount2, options = {}) {
134651
134591
  await refreshOracle(tx, client, address2, { skipPythUpdate: options.skipPythUpdate });
134652
134592
  try {
134653
134593
  const borrowedCoin = await Xe(tx, assetInfo.type, rawAmount, sdkOptions(client));
134654
- if (options.collectFee) {
134655
- addCollectFeeToTx(tx, borrowedCoin, "borrow");
134656
- }
134657
134594
  tx.transferObjects([borrowedCoin], address2);
134658
134595
  } catch (err) {
134659
134596
  const msg = err instanceof Error ? err.message : String(err);
@@ -134661,6 +134598,22 @@ async function buildBorrowTx(client, address2, amount2, options = {}) {
134661
134598
  }
134662
134599
  return tx;
134663
134600
  }
134601
+ async function addBorrowToTx(tx, client, address2, amount2, options = {}) {
134602
+ if (!amount2 || amount2 <= 0 || !Number.isFinite(amount2)) {
134603
+ throw new T2000Error("INVALID_AMOUNT", "Borrow amount must be a positive number");
134604
+ }
134605
+ const asset = options.asset ?? "USDC";
134606
+ const assetInfo = resolveAssetInfo(asset);
134607
+ const rawAmount = Number(stableToRaw(amount2, assetInfo.decimals));
134608
+ await refreshOracle(tx, client, address2, { skipPythUpdate: options.skipPythUpdate });
134609
+ try {
134610
+ const borrowedCoin = await Xe(tx, assetInfo.type, rawAmount, sdkOptions(client));
134611
+ return borrowedCoin;
134612
+ } catch (err) {
134613
+ const msg = err instanceof Error ? err.message : String(err);
134614
+ throw new T2000Error("PROTOCOL_UNAVAILABLE", `NAVI borrow failed: ${msg}`);
134615
+ }
134616
+ }
134664
134617
  async function buildRepayTx(client, address2, amount2, options = {}) {
134665
134618
  if (!amount2 || amount2 <= 0 || !Number.isFinite(amount2)) {
134666
134619
  throw new T2000Error("INVALID_AMOUNT", "Repay amount must be a positive number");
@@ -134959,9 +134912,9 @@ var NaviAdapter = class {
134959
134912
  async getHealth(address2) {
134960
134913
  return getHealthFactor(this.client, address2);
134961
134914
  }
134962
- async buildSaveTx(address2, amount2, asset, options) {
134915
+ async buildSaveTx(address2, amount2, asset) {
134963
134916
  const normalized = normalizeAsset(asset);
134964
- const tx = await buildSaveTx(this.client, address2, amount2, { ...options, asset: normalized });
134917
+ const tx = await buildSaveTx(this.client, address2, amount2, { asset: normalized });
134965
134918
  return { tx };
134966
134919
  }
134967
134920
  async buildWithdrawTx(address2, amount2, asset, options) {
@@ -134999,9 +134952,16 @@ var NaviAdapter = class {
134999
134952
  skipPythUpdate: options?.skipPythUpdate
135000
134953
  });
135001
134954
  }
135002
- async addSaveToTx(tx, address2, coin, asset, options) {
134955
+ async addSaveToTx(tx, address2, coin, asset) {
135003
134956
  const normalized = normalizeAsset(asset);
135004
- return addSaveToTx(tx, this.client, address2, coin, { ...options, asset: normalized });
134957
+ return addSaveToTx(tx, this.client, address2, coin, { asset: normalized });
134958
+ }
134959
+ async addBorrowToTx(tx, address2, amount2, asset, options) {
134960
+ const normalized = normalizeAsset(asset);
134961
+ return addBorrowToTx(tx, this.client, address2, amount2, {
134962
+ asset: normalized,
134963
+ skipPythUpdate: options?.skipPythUpdate
134964
+ });
135005
134965
  }
135006
134966
  async addRepayToTx(tx, address2, coin, asset, options) {
135007
134967
  const normalized = normalizeAsset(asset);
@@ -135735,7 +135695,6 @@ var T2000 = class _T2000 extends import_index2.default {
135735
135695
  );
135736
135696
  }
135737
135697
  }
135738
- const fee = calculateFee("save", amount2);
135739
135698
  const saveAmount = amount2;
135740
135699
  const adapter2 = await this.resolveLending(params.protocol, asset, "save");
135741
135700
  const canPTB = !!adapter2.addSaveToTx;
@@ -135748,14 +135707,13 @@ var T2000 = class _T2000 extends import_index2.default {
135748
135707
  const merged = this._mergeCoinsInTx(tx2, coins);
135749
135708
  const rawAmount = BigInt(Math.floor(saveAmount * 10 ** assetInfo.decimals));
135750
135709
  const [inputCoin] = tx2.splitCoins(merged, [rawAmount]);
135751
- await adapter2.addSaveToTx(tx2, this._address, inputCoin, asset, { collectFee: true });
135710
+ await adapter2.addSaveToTx(tx2, this._address, inputCoin, asset);
135752
135711
  return tx2;
135753
135712
  }
135754
- const { tx } = await adapter2.buildSaveTx(this._address, saveAmount, asset, { collectFee: true });
135713
+ const { tx } = await adapter2.buildSaveTx(this._address, saveAmount, asset);
135755
135714
  return tx;
135756
135715
  });
135757
135716
  const rates = await adapter2.getRates(asset);
135758
- reportFee(this._address, "save", fee.amount, fee.rate, gasResult.digest);
135759
135717
  this.emitBalanceChange(asset, saveAmount, "save", gasResult.digest);
135760
135718
  let savingsBalance = saveAmount;
135761
135719
  for (let attempt = 0; attempt < 3; attempt++) {
@@ -135775,7 +135733,7 @@ var T2000 = class _T2000 extends import_index2.default {
135775
135733
  tx: gasResult.digest,
135776
135734
  amount: saveAmount,
135777
135735
  apy: rates.saveApy,
135778
- fee: fee.amount,
135736
+ fee: 0,
135779
135737
  gasCost: gasResult.gasCostSui,
135780
135738
  savingsBalance
135781
135739
  };
@@ -136038,21 +135996,19 @@ var T2000 = class _T2000 extends import_index2.default {
136038
135996
  currentHF: maxResult.currentHF
136039
135997
  });
136040
135998
  }
136041
- const fee = calculateFee("borrow", params.amount);
136042
135999
  const borrowAmount = params.amount;
136043
136000
  const gasResult = await executeTx(this.client, this._signer, async () => {
136044
- const { tx } = await adapter2.buildBorrowTx(this._address, borrowAmount, asset, { collectFee: true });
136001
+ const { tx } = await adapter2.buildBorrowTx(this._address, borrowAmount, asset);
136045
136002
  return tx;
136046
136003
  });
136047
136004
  const hf = await adapter2.getHealth(this._address);
136048
- reportFee(this._address, "borrow", fee.amount, fee.rate, gasResult.digest);
136049
136005
  this.emitBalanceChange(asset, borrowAmount, "borrow", gasResult.digest);
136050
136006
  return {
136051
136007
  success: true,
136052
136008
  tx: gasResult.digest,
136053
136009
  amount: borrowAmount,
136054
136010
  asset,
136055
- fee: fee.amount,
136011
+ fee: 0,
136056
136012
  healthFactor: hf.healthFactor,
136057
136013
  gasCost: gasResult.gasCostSui
136058
136014
  };
@@ -136325,7 +136281,7 @@ var T2000 = class _T2000 extends import_index2.default {
136325
136281
  if (coins.length === 0) throw new T2000Error("INSUFFICIENT_BALANCE", "No USDC coins after swap");
136326
136282
  const merged = this._mergeCoinsInTx(tx, coins);
136327
136283
  const [inputCoin] = tx.splitCoins(merged, [gainedRaw]);
136328
- await adapter2.addSaveToTx(tx, this._address, inputCoin, "USDC", { collectFee: false });
136284
+ await adapter2.addSaveToTx(tx, this._address, inputCoin, "USDC");
136329
136285
  return tx;
136330
136286
  });
136331
136287
  depositTx = depositResult.digest;
@@ -137784,7 +137740,7 @@ ${context}
137784
137740
  })
137785
137741
  );
137786
137742
  }
137787
- var PKG_VERSION = "1.0.1";
137743
+ var PKG_VERSION = "1.1.0";
137788
137744
  console.log = (...args) => console.error("[log]", ...args);
137789
137745
  console.warn = (...args) => console.error("[warn]", ...args);
137790
137746
  async function startMcpServer(opts) {
@@ -137874,4 +137830,4 @@ axios/dist/node/axios.cjs:
137874
137830
  *)
137875
137831
  *)
137876
137832
  */
137877
- //# sourceMappingURL=dist-R6F53QGO.js.map
137833
+ //# sourceMappingURL=dist-SLM2OSSP.js.map