@t2000/sdk 4.4.0 → 5.0.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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @t2000/sdk
2
2
 
3
- The TypeScript SDK for Agent Wallets on Sui. One class (`T2000`) — wallet signing, gasless USDC + USDsui sends, Cetus swap routing, MPP paid API access, and programmatic NAVI lending builders.
3
+ The TypeScript SDK for Agent Wallets on Sui. One class (`T2000`) — wallet signing, gasless USDC + USDsui sends, Cetus swap routing, and x402 paid-API access (pay any API in USDC, no keys).
4
4
 
5
5
  [![npm @t2000/sdk](https://img.shields.io/npm/v/@t2000/sdk?label=%40t2000%2Fsdk)](https://www.npmjs.com/package/@t2000/sdk)
6
6
  [![npm @t2000/cli](https://img.shields.io/npm/v/@t2000/cli?label=%40t2000%2Fcli)](https://www.npmjs.com/package/@t2000/cli)
@@ -29,11 +29,11 @@ await agent.swap({ from: 'USDC', to: 'SUI', amount: 100 }); // Cetus, ne
29
29
  await agent.pay({ url: 'https://mpp.t2000.ai/openai/v1/chat/completions', method: 'POST', body, maxPrice: 0.10 });
30
30
  ```
31
31
 
32
- USDC + USDsui sends and MPP USDC payments are gasless (Sui foundation's `0x2::balance::send_funds` sponsor). SUI sends and Cetus swaps need gas — keep ~0.05 SUI on hand.
32
+ USDC + USDsui sends and x402 USDC payments are gasless (Sui foundation's `0x2::balance::send_funds` sponsor). SUI sends and Cetus swaps need gas — keep ~0.05 SUI on hand.
33
33
 
34
34
  ## Full reference
35
35
 
36
- Factory methods, full API surface, supported assets, NAVI lending builders, error handling, architecture →
36
+ Factory methods, full API surface, supported assets, Cetus swap routing, x402 payments, error handling, architecture →
37
37
  **[developers.t2000.ai/agent-sdk](https://developers.t2000.ai/agent-sdk)**
38
38
 
39
39
  ## License
package/dist/browser.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
- require('@mysten/sui/jsonRpc');
4
3
  require('@mysten/sui/grpc');
4
+ require('@mysten/sui/graphql');
5
5
  var utils = require('@mysten/sui/utils');
6
6
  var aggregatorSdk = require('@cetusprotocol/aggregator-sdk');
7
7
  require('bn.js');
@@ -106,21 +106,6 @@ var init_errors = __esm({
106
106
  });
107
107
 
108
108
  // src/token-registry.ts
109
- function isTier1(coinType) {
110
- const meta = BY_TYPE.get(coinType);
111
- return meta?.tier === 1;
112
- }
113
- function isTier2(coinType) {
114
- const meta = BY_TYPE.get(coinType);
115
- return meta?.tier === 2;
116
- }
117
- function isSupported(coinType) {
118
- const meta = BY_TYPE.get(coinType);
119
- return meta?.tier !== void 0;
120
- }
121
- function getTier(coinType) {
122
- return BY_TYPE.get(coinType)?.tier;
123
- }
124
109
  function getDecimalsForCoinType(coinType) {
125
110
  const direct = BY_TYPE.get(coinType);
126
111
  if (direct) return direct.decimals;
@@ -153,25 +138,25 @@ exports.COIN_REGISTRY = void 0; var BY_TYPE; exports.TOKEN_MAP = void 0; exports
153
138
  var init_token_registry = __esm({
154
139
  "src/token-registry.ts"() {
155
140
  exports.COIN_REGISTRY = {
156
- // ── Tier 1 — Financial layer ──────────────────────────────────────────
157
- USDC: { type: "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC", decimals: 6, symbol: "USDC", tier: 1 },
158
- // ── Tier 2Swap assets (15 tokens) ──────────────────────────────────
159
- SUI: { type: "0x2::sui::SUI", decimals: 9, symbol: "SUI", tier: 2 },
160
- wBTC: { type: "0x0041f9f9344cac094454cd574e333c4fdb132d7bcc9379bcd4aab485b2a63942::wbtc::WBTC", decimals: 8, symbol: "wBTC", tier: 2 },
161
- ETH: { type: "0xd0e89b2af5e4910726fbcd8b8dd37bb79b29e5f83f7491bca830e94f7f226d29::eth::ETH", decimals: 8, symbol: "ETH", tier: 2 },
162
- GOLD: { type: "0x9d297676e7a4b771ab023291377b2adfaa4938fb9080b8d12430e4b108b836a9::xaum::XAUM", decimals: 9, symbol: "GOLD", tier: 2 },
163
- DEEP: { type: "0xdeeb7a4662eec9f2f3def03fb937a663dddaa2e215b8078a284d026b7946c270::deep::DEEP", decimals: 6, symbol: "DEEP", tier: 2 },
164
- WAL: { type: "0x356a26eb9e012a68958082340d4c4116e7f55615cf27affcff209cf0ae544f59::wal::WAL", decimals: 9, symbol: "WAL", tier: 2 },
165
- NS: { type: "0x5145494a5f5100e645e4b0aa950fa6b68f614e8c59e17bc5ded3495123a79178::ns::NS", decimals: 6, symbol: "NS", tier: 2 },
166
- IKA: { type: "0x7262fb2f7a3a14c888c438a3cd9b912469a58cf60f367352c46584262e8299aa::ika::IKA", decimals: 9, symbol: "IKA", tier: 2 },
167
- CETUS: { type: "0x06864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b::cetus::CETUS", decimals: 9, symbol: "CETUS", tier: 2 },
168
- NAVX: { type: "0xa99b8952d4f7d947ea77fe0ecdcc9e5fc0bcab2841d6e2a5aa00c3044e5544b5::navx::NAVX", decimals: 9, symbol: "NAVX", tier: 2 },
169
- vSUI: { type: "0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT", decimals: 9, symbol: "vSUI", tier: 2 },
170
- haSUI: { type: "0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d::hasui::HASUI", decimals: 9, symbol: "haSUI", tier: 2 },
171
- afSUI: { type: "0xf325ce1300e8dac124071d3152c5c5ee6174914f8bc2161e88329cf579246efc::afsui::AFSUI", decimals: 9, symbol: "afSUI", tier: 2 },
172
- LOFI: { type: "0xf22da9a24ad027cccb5f2d496cbe91de953d363513db08a3a734d361c7c17503::LOFI::LOFI", decimals: 9, symbol: "LOFI", tier: 2 },
173
- MANIFEST: { type: "0xc466c28d87b3d5cd34f3d5c088751532d71a38d93a8aae4551dd56272cfb4355::manifest::MANIFEST", decimals: 9, symbol: "MANIFEST", tier: 2 },
174
- // ── Legacy no tier, kept for display accuracy on existing positions ──
141
+ // ── Settlement stable ─────────────────────────────────────────────────
142
+ USDC: { type: "0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC", decimals: 6, symbol: "USDC" },
143
+ // ── Common swap assets (symbol ergonomics any coin type still swaps)
144
+ SUI: { type: "0x2::sui::SUI", decimals: 9, symbol: "SUI" },
145
+ wBTC: { type: "0x0041f9f9344cac094454cd574e333c4fdb132d7bcc9379bcd4aab485b2a63942::wbtc::WBTC", decimals: 8, symbol: "wBTC" },
146
+ ETH: { type: "0xd0e89b2af5e4910726fbcd8b8dd37bb79b29e5f83f7491bca830e94f7f226d29::eth::ETH", decimals: 8, symbol: "ETH" },
147
+ GOLD: { type: "0x9d297676e7a4b771ab023291377b2adfaa4938fb9080b8d12430e4b108b836a9::xaum::XAUM", decimals: 9, symbol: "GOLD" },
148
+ DEEP: { type: "0xdeeb7a4662eec9f2f3def03fb937a663dddaa2e215b8078a284d026b7946c270::deep::DEEP", decimals: 6, symbol: "DEEP" },
149
+ WAL: { type: "0x356a26eb9e012a68958082340d4c4116e7f55615cf27affcff209cf0ae544f59::wal::WAL", decimals: 9, symbol: "WAL" },
150
+ NS: { type: "0x5145494a5f5100e645e4b0aa950fa6b68f614e8c59e17bc5ded3495123a79178::ns::NS", decimals: 6, symbol: "NS" },
151
+ IKA: { type: "0x7262fb2f7a3a14c888c438a3cd9b912469a58cf60f367352c46584262e8299aa::ika::IKA", decimals: 9, symbol: "IKA" },
152
+ CETUS: { type: "0x06864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b::cetus::CETUS", decimals: 9, symbol: "CETUS" },
153
+ NAVX: { type: "0xa99b8952d4f7d947ea77fe0ecdcc9e5fc0bcab2841d6e2a5aa00c3044e5544b5::navx::NAVX", decimals: 9, symbol: "NAVX" },
154
+ vSUI: { type: "0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT", decimals: 9, symbol: "vSUI" },
155
+ haSUI: { type: "0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d::hasui::HASUI", decimals: 9, symbol: "haSUI" },
156
+ afSUI: { type: "0xf325ce1300e8dac124071d3152c5c5ee6174914f8bc2161e88329cf579246efc::afsui::AFSUI", decimals: 9, symbol: "afSUI" },
157
+ LOFI: { type: "0xf22da9a24ad027cccb5f2d496cbe91de953d363513db08a3a734d361c7c17503::LOFI::LOFI", decimals: 9, symbol: "LOFI" },
158
+ MANIFEST: { type: "0xc466c28d87b3d5cd34f3d5c088751532d71a38d93a8aae4551dd56272cfb4355::manifest::MANIFEST", decimals: 9, symbol: "MANIFEST" },
159
+ // ── Other stables (display / classification) ──────────────────────────
175
160
  USDT: { type: "0x375f70cf2ae4c00bf37117d0c85a2c71545e6ee05c4a5c7d282cd66a4504b068::usdt::USDT", decimals: 6, symbol: "USDT" },
176
161
  USDe: { type: "0x41d587e5336f1c86cad50d38a7136db99333bb9bda91cea4ba69115defeb1402::sui_usde::SUI_USDE", decimals: 6, symbol: "USDe" },
177
162
  USDSUI: { type: "0x44f838219cf67b058f3b37907b655f226153c18e33dfcd0da559a844fea9b1c1::usdsui::USDSUI", decimals: 6, symbol: "USDsui" }
@@ -275,19 +260,21 @@ async function executeTx(client, signer, buildTx, options = {}) {
275
260
  tx.setSender(signer.getAddress());
276
261
  const txBytes = await tx.build({ client: options.buildClient ?? client });
277
262
  const { signature } = await signer.signTransaction(txBytes);
278
- const result = await client.executeTransactionBlock({
279
- transactionBlock: txBytes,
280
- signature,
281
- options: { showEffects: true }
263
+ const result = await client.core.executeTransaction({
264
+ transaction: txBytes,
265
+ signatures: [signature],
266
+ include: { effects: true }
282
267
  });
283
- await client.waitForTransaction({ digest: result.digest });
284
- const gasUsed = result.effects?.gasUsed;
268
+ const txn = result.$kind === "Transaction" ? result.Transaction : result.FailedTransaction;
269
+ await client.core.waitForTransaction({ digest: txn.digest });
270
+ const effects = txn.effects ?? void 0;
271
+ const gasUsed = effects?.gasUsed;
285
272
  let gasCostSui = 0;
286
273
  if (gasUsed) {
287
274
  const total = BigInt(gasUsed.computationCost) + BigInt(gasUsed.storageCost) - BigInt(gasUsed.storageRebate);
288
275
  gasCostSui = Number(total) / 1e9;
289
276
  }
290
- return { digest: result.digest, gasCostSui, effects: result.effects ?? void 0 };
277
+ return { digest: txn.digest, gasCostSui, effects };
291
278
  }
292
279
 
293
280
  // src/wallet/pay.ts
@@ -358,9 +345,6 @@ init_errors();
358
345
  var MIST_PER_SUI = 1000000000n;
359
346
  var SUI_DECIMALS = 9;
360
347
  var USDC_DECIMALS = 6;
361
- var BPS_DENOMINATOR = 10000n;
362
- var SAVE_FEE_BPS = 10n;
363
- var BORROW_FEE_BPS = 5n;
364
348
  var CLOCK_ID = "0x6";
365
349
  var SUPPORTED_ASSETS = {
366
350
  USDC: {
@@ -419,7 +403,6 @@ var SUPPORTED_ASSETS = {
419
403
  }
420
404
  };
421
405
  var STABLE_ASSETS = ["USDC", "USDsui"];
422
- var ALL_NAVI_ASSETS = Object.keys(SUPPORTED_ASSETS);
423
406
  ({
424
407
  USDC: SUPPORTED_ASSETS.USDC.type,
425
408
  USDsui: SUPPORTED_ASSETS.USDsui.type
@@ -583,8 +566,13 @@ function extractAllUserLegs(changes, sender) {
583
566
  }
584
567
  return legs;
585
568
  }
586
-
587
- // src/wallet/history.ts
569
+ function buildRecord(args) {
570
+ const { digest, moveCallTargets, commandTypes, balanceChanges, timestampMs, gasCost, address } = args;
571
+ const legs = extractAllUserLegs(balanceChanges, address);
572
+ const { amount, asset, recipient, direction } = extractTransferDetails(balanceChanges, address);
573
+ const { action, label } = classifyTransaction(moveCallTargets, commandTypes, balanceChanges, address);
574
+ return { digest, action, label, legs, amount, asset, recipient, direction, timestamp: timestampMs, gasCost };
575
+ }
588
576
  function parseSuiRpcTx(tx, address) {
589
577
  return parseTxRecord(tx, address);
590
578
  }
@@ -605,27 +593,15 @@ function parseTxRecord(tx, address) {
605
593
  const gasUsed = tx.effects?.gasUsed;
606
594
  const gasCost = gasUsed ? (Number(gasUsed.computationCost) + Number(gasUsed.storageCost) - Number(gasUsed.storageRebate)) / 1e9 : void 0;
607
595
  const { moveCallTargets, commandTypes } = extractCommands(tx.transaction);
608
- const balanceChanges = tx.balanceChanges ?? [];
609
- const legs = extractAllUserLegs(balanceChanges, address);
610
- const { amount, asset, recipient, direction } = extractTransferDetails(balanceChanges, address);
611
- const { action, label } = classifyTransaction(
596
+ return buildRecord({
597
+ digest: tx.digest,
612
598
  moveCallTargets,
613
599
  commandTypes,
614
- balanceChanges,
600
+ balanceChanges: tx.balanceChanges ?? [],
601
+ timestampMs: Number(tx.timestampMs ?? 0),
602
+ gasCost,
615
603
  address
616
- );
617
- return {
618
- digest: tx.digest,
619
- action,
620
- label,
621
- legs,
622
- amount,
623
- asset,
624
- recipient,
625
- direction,
626
- timestamp: Number(tx.timestampMs ?? 0),
627
- gasCost
628
- };
604
+ });
629
605
  }
630
606
  function extractCommands(txBlock) {
631
607
  const result = { moveCallTargets: [], commandTypes: [] };
@@ -707,37 +683,6 @@ function fromBase64(b64) {
707
683
  return bytes;
708
684
  }
709
685
 
710
- // src/protocols/protocolFee.ts
711
- var FEE_RATES = {
712
- save: SAVE_FEE_BPS,
713
- borrow: BORROW_FEE_BPS,
714
- // Swap uses Cetus's overlay-fee mechanism (taken from output by the aggregator
715
- // and transferred to `overlayFee.receiver`). We list the rate here for display
716
- // / quote calculations only — `addFeeTransfer` is NOT called for swaps.
717
- swap: 10n
718
- // 0.1%
719
- };
720
- function calculateFee(operation, amount) {
721
- const bps = FEE_RATES[operation];
722
- const feeAmount = amount * Number(bps) / Number(BPS_DENOMINATOR);
723
- const rawAmount = stableToRaw(feeAmount, USDC_DECIMALS);
724
- return {
725
- amount: feeAmount,
726
- asset: "USDC",
727
- rate: Number(bps) / Number(BPS_DENOMINATOR),
728
- rawAmount
729
- };
730
- }
731
- function addFeeTransfer(tx, paymentCoin, feeBps, receiver, amount, decimals = USDC_DECIMALS) {
732
- if (feeBps <= 0n) return;
733
- if (amount <= 0) return;
734
- const feeAmount = amount * Number(feeBps) / Number(BPS_DENOMINATOR);
735
- const rawFee = stableToRaw(feeAmount, decimals);
736
- if (rawFee <= 0n) return;
737
- const [feeCoin] = tx.splitCoins(paymentCoin, [tx.pure.u64(rawFee)]);
738
- tx.transferObjects([feeCoin], tx.pure.address(receiver));
739
- }
740
-
741
686
  // src/protocols/cetus-swap.ts
742
687
  init_token_registry();
743
688
  init_token_registry();
@@ -840,10 +785,6 @@ function buildMessage(rule, details) {
840
785
  }
841
786
 
842
787
  // src/safeguards/types.ts
843
- var OUTBOUND_OPS = /* @__PURE__ */ new Set([
844
- "send",
845
- "pay"
846
- ]);
847
788
  var DEFAULT_SAFEGUARD_CONFIG = {
848
789
  locked: false,
849
790
  maxPerTx: 0,
@@ -855,9 +796,6 @@ var DEFAULT_SAFEGUARD_CONFIG = {
855
796
  // src/browser.ts
856
797
  init_token_registry();
857
798
 
858
- exports.ALL_NAVI_ASSETS = ALL_NAVI_ASSETS;
859
- exports.BORROW_FEE_BPS = BORROW_FEE_BPS;
860
- exports.BPS_DENOMINATOR = BPS_DENOMINATOR;
861
799
  exports.CLOCK_ID = CLOCK_ID;
862
800
  exports.DEFAULT_NETWORK = DEFAULT_NETWORK;
863
801
  exports.DEFAULT_SAFEGUARD_CONFIG = DEFAULT_SAFEGUARD_CONFIG;
@@ -866,9 +804,7 @@ exports.KNOWN_TARGETS = KNOWN_TARGETS;
866
804
  exports.KeypairSigner = KeypairSigner;
867
805
  exports.LABEL_PATTERNS = LABEL_PATTERNS;
868
806
  exports.MIST_PER_SUI = MIST_PER_SUI;
869
- exports.OUTBOUND_OPS = OUTBOUND_OPS;
870
807
  exports.OVERLAY_FEE_RATE = OVERLAY_FEE_RATE;
871
- exports.SAVE_FEE_BPS = SAVE_FEE_BPS;
872
808
  exports.STABLE_ASSETS = STABLE_ASSETS;
873
809
  exports.SUI_DECIMALS = SUI_DECIMALS;
874
810
  exports.SUPPORTED_ASSETS = SUPPORTED_ASSETS;
@@ -876,9 +812,7 @@ exports.SafeguardError = SafeguardError;
876
812
  exports.T2000_OVERLAY_FEE_WALLET = T2000_OVERLAY_FEE_WALLET;
877
813
  exports.USDC_DECIMALS = USDC_DECIMALS;
878
814
  exports.ZkLoginSigner = ZkLoginSigner;
879
- exports.addFeeTransfer = addFeeTransfer;
880
815
  exports.buildSwapTx = buildSwapTx;
881
- exports.calculateFee = calculateFee;
882
816
  exports.classifyAction = classifyAction;
883
817
  exports.classifyLabel = classifyLabel;
884
818
  exports.classifyTransaction = classifyTransaction;
@@ -895,10 +829,6 @@ exports.formatUsd = formatUsd;
895
829
  exports.fromBase64 = fromBase64;
896
830
  exports.getDecimals = getDecimals;
897
831
  exports.getDecimalsForCoinType = getDecimalsForCoinType;
898
- exports.getTier = getTier;
899
- exports.isSupported = isSupported;
900
- exports.isTier1 = isTier1;
901
- exports.isTier2 = isTier2;
902
832
  exports.mapMoveAbortCode = mapMoveAbortCode;
903
833
  exports.mapWalletError = mapWalletError;
904
834
  exports.mistToSui = mistToSui;