@t2000/sdk 0.38.0 → 0.40.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.cjs CHANGED
@@ -894,7 +894,6 @@ function assertAllowedAsset(op, asset) {
894
894
  }
895
895
  var T2000_PACKAGE_ID = process.env.T2000_PACKAGE_ID ?? "0xd775fcc66eae26797654d435d751dea56b82eeb999de51fd285348e573b968ad";
896
896
  var T2000_CONFIG_ID = process.env.T2000_CONFIG_ID ?? "0x08ba26f0d260b5edf6a19c71492b3eb914906a7419baf2df1426765157e5862a";
897
- var T2000_ADMIN_CAP_ID = "0xa97bfff140f5a2c268a03fe5422d382c228057deb7bcfdaf2967ca18b9bdbbd9";
898
897
  var T2000_TREASURY_ID = process.env.T2000_TREASURY_ID ?? "0xf420ec0dcad44433042fb56e1413fb88d3ff65be94fcf425ef9ff750164590e8";
899
898
  var DEFAULT_NETWORK = "mainnet";
900
899
  var DEFAULT_RPC_URL = "https://fullnode.mainnet.sui.io:443";
@@ -902,17 +901,6 @@ var DEFAULT_KEY_PATH = "~/.t2000/wallet.key";
902
901
  var API_BASE_URL = process.env.T2000_API_URL ?? "https://api.t2000.ai";
903
902
  var CETUS_USDC_SUI_POOL = "0x51e883ba7c0b566a26cbc8a94cd33eb0abd418a77cc1e60ad22fd9b1f29cd2ab";
904
903
  var GAS_RESERVE_MIN = 0.05;
905
- var ALLOWANCE_FEATURES = {
906
- BRIEFING: 0,
907
- YIELD_ALERT: 1,
908
- PAYMENT_ALERT: 2,
909
- ACTION_REMIND: 3,
910
- SESSION: 4,
911
- AUTO_COMPOUND: 5,
912
- DCA: 6,
913
- HF_ALERT: 7
914
- };
915
- var FEATURES_ALL = 255;
916
904
 
917
905
  // src/utils/sui.ts
918
906
  init_errors();
@@ -7171,7 +7159,7 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
7171
7159
  async compoundRewards(options = {}) {
7172
7160
  this.enforcer.assertNotLocked();
7173
7161
  const minValue = options.minValueUsd ?? 0.1;
7174
- const USDC_TYPE3 = SUPPORTED_ASSETS.USDC.type;
7162
+ const USDC_TYPE2 = SUPPORTED_ASSETS.USDC.type;
7175
7163
  const USDC_DEC = SUPPORTED_ASSETS.USDC.decimals;
7176
7164
  const pending = await this.getPendingRewards();
7177
7165
  const nonTrivial = pending.filter((r) => r.amount > 0);
@@ -7198,7 +7186,7 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
7198
7186
  totalGasCost: 0
7199
7187
  };
7200
7188
  }
7201
- const preUsdcCoins = await this._fetchCoins(USDC_TYPE3);
7189
+ const preUsdcCoins = await this._fetchCoins(USDC_TYPE2);
7202
7190
  const preUsdcRaw = preUsdcCoins.reduce((s, c) => s + BigInt(c.balance), 0n);
7203
7191
  const claimResult = await this.claimRewards();
7204
7192
  if (!claimResult.tx) {
@@ -7217,7 +7205,7 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
7217
7205
  let totalGasCost = claimResult.gasCost;
7218
7206
  for (const reward of nonTrivial) {
7219
7207
  if (!reward.coinType) continue;
7220
- if (reward.coinType === USDC_TYPE3) continue;
7208
+ if (reward.coinType === USDC_TYPE2) continue;
7221
7209
  try {
7222
7210
  const decimals = getDecimalsForCoinType(reward.coinType) ?? 9;
7223
7211
  const rawAmount = BigInt(Math.floor(reward.amount * 10 ** decimals));
@@ -7227,7 +7215,7 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
7227
7215
  const route = await findSwapRoute2({
7228
7216
  walletAddress: this._address,
7229
7217
  from: reward.coinType,
7230
- to: USDC_TYPE3,
7218
+ to: USDC_TYPE2,
7231
7219
  amount: rawAmount,
7232
7220
  byAmountIn: true
7233
7221
  });
@@ -7255,7 +7243,7 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
7255
7243
  console.warn(`[compound] Failed to swap ${reward.symbol}:`, err instanceof Error ? err.message : err);
7256
7244
  }
7257
7245
  }
7258
- const postUsdcCoins = await this._fetchCoins(USDC_TYPE3);
7246
+ const postUsdcCoins = await this._fetchCoins(USDC_TYPE2);
7259
7247
  const postUsdcRaw = postUsdcCoins.reduce((s, c) => s + BigInt(c.balance), 0n);
7260
7248
  const gainedRaw = postUsdcRaw > preUsdcRaw ? postUsdcRaw - preUsdcRaw : 0n;
7261
7249
  const depositUsdc = Number(gainedRaw) / 10 ** USDC_DEC;
@@ -7266,7 +7254,7 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
7266
7254
  const depositResult = await executeWithGas(this.client, this._signer, async () => {
7267
7255
  const tx = new transactions.Transaction();
7268
7256
  tx.setSender(this._address);
7269
- const coins = await this._fetchCoins(USDC_TYPE3);
7257
+ const coins = await this._fetchCoins(USDC_TYPE2);
7270
7258
  if (coins.length === 0) throw new exports.T2000Error("INSUFFICIENT_BALANCE", "No USDC coins after swap");
7271
7259
  const merged = this._mergeCoinsInTx(tx, coins);
7272
7260
  const [inputCoin] = tx.splitCoins(merged, [gainedRaw]);
@@ -7420,122 +7408,6 @@ async function callSponsorApi(address, name) {
7420
7408
 
7421
7409
  // src/index.ts
7422
7410
  init_errors();
7423
- var USDC_TYPE2 = SUPPORTED_ASSETS.USDC.type;
7424
- function buildCreateAllowanceTx(options = {}) {
7425
- const tx = new transactions.Transaction();
7426
- tx.moveCall({
7427
- target: `${T2000_PACKAGE_ID}::allowance::create`,
7428
- typeArguments: [USDC_TYPE2],
7429
- arguments: [
7430
- tx.pure.u64(options.permittedFeatures ?? BigInt(FEATURES_ALL)),
7431
- tx.pure.u64(options.expiresAt ?? 0n),
7432
- tx.pure.u64(options.dailyLimit ?? 0n),
7433
- tx.object(CLOCK_ID)
7434
- ]
7435
- });
7436
- return tx;
7437
- }
7438
- function addDepositAllowanceTx(tx, allowanceId, paymentCoin) {
7439
- tx.moveCall({
7440
- target: `${T2000_PACKAGE_ID}::allowance::deposit`,
7441
- typeArguments: [USDC_TYPE2],
7442
- arguments: [tx.object(allowanceId), paymentCoin]
7443
- });
7444
- }
7445
- function buildDepositAllowanceTx(allowanceId, usdcCoin, amount) {
7446
- const tx = new transactions.Transaction();
7447
- const [split] = tx.splitCoins(tx.object(usdcCoin), [tx.pure.u64(amount)]);
7448
- addDepositAllowanceTx(tx, allowanceId, split);
7449
- return tx;
7450
- }
7451
- function buildAdminDepositAllowanceTx(allowanceId, usdcCoin, amount) {
7452
- const tx = new transactions.Transaction();
7453
- const [split] = tx.splitCoins(tx.object(usdcCoin), [tx.pure.u64(amount)]);
7454
- tx.moveCall({
7455
- target: `${T2000_PACKAGE_ID}::allowance::admin_deposit`,
7456
- typeArguments: [USDC_TYPE2],
7457
- arguments: [
7458
- tx.object(allowanceId),
7459
- tx.object(T2000_ADMIN_CAP_ID),
7460
- split
7461
- ]
7462
- });
7463
- return tx;
7464
- }
7465
- function buildDeductAllowanceTx(allowanceId, amount, feature) {
7466
- const tx = new transactions.Transaction();
7467
- tx.moveCall({
7468
- target: `${T2000_PACKAGE_ID}::allowance::deduct`,
7469
- typeArguments: [USDC_TYPE2],
7470
- arguments: [
7471
- tx.object(allowanceId),
7472
- tx.object(T2000_CONFIG_ID),
7473
- tx.object(T2000_ADMIN_CAP_ID),
7474
- tx.pure.u64(amount),
7475
- tx.pure.u8(feature),
7476
- tx.object(CLOCK_ID)
7477
- ]
7478
- });
7479
- return tx;
7480
- }
7481
- function buildWithdrawAllowanceTx(allowanceId) {
7482
- const tx = new transactions.Transaction();
7483
- tx.moveCall({
7484
- target: `${T2000_PACKAGE_ID}::allowance::withdraw`,
7485
- typeArguments: [USDC_TYPE2],
7486
- arguments: [tx.object(allowanceId)]
7487
- });
7488
- return tx;
7489
- }
7490
- function buildWithdrawAmountAllowanceTx(allowanceId, amount) {
7491
- const tx = new transactions.Transaction();
7492
- tx.moveCall({
7493
- target: `${T2000_PACKAGE_ID}::allowance::withdraw_amount`,
7494
- typeArguments: [USDC_TYPE2],
7495
- arguments: [tx.object(allowanceId), tx.pure.u64(amount)]
7496
- });
7497
- return tx;
7498
- }
7499
- async function getAllowance(client, allowanceId) {
7500
- const obj = await client.getObject({
7501
- id: allowanceId,
7502
- options: { showContent: true, showType: true }
7503
- });
7504
- if (!obj.data?.content || obj.data.content.dataType !== "moveObject") {
7505
- throw new Error(`Allowance ${allowanceId} not found or is not a Move object`);
7506
- }
7507
- const fields = obj.data.content.fields;
7508
- const coinType = extractCoinType(obj.data.content.type);
7509
- return {
7510
- id: allowanceId,
7511
- owner: fields.owner,
7512
- balance: parseU64Field(fields.balance),
7513
- totalDeposited: parseU64Field(fields.total_deposited),
7514
- totalSpent: parseU64Field(fields.total_spent),
7515
- createdAt: Number(fields.created_at),
7516
- coinType,
7517
- permittedFeatures: parseU64Field(fields.permitted_features),
7518
- expiresAt: Number(fields.expires_at),
7519
- dailyLimit: parseU64Field(fields.daily_limit),
7520
- dailySpent: parseU64Field(fields.daily_spent),
7521
- windowStart: Number(fields.window_start)
7522
- };
7523
- }
7524
- async function getAllowanceBalance(client, allowanceId) {
7525
- const info = await getAllowance(client, allowanceId);
7526
- return info.balance;
7527
- }
7528
- function parseU64Field(raw) {
7529
- if (typeof raw === "string" || typeof raw === "number") return BigInt(raw);
7530
- if (typeof raw === "object" && raw !== null && "value" in raw) {
7531
- return BigInt(raw.value);
7532
- }
7533
- return 0n;
7534
- }
7535
- function extractCoinType(objectType) {
7536
- const match = objectType.match(/<(.+)>/);
7537
- return match ? match[1] : "unknown";
7538
- }
7539
7411
 
7540
7412
  // src/protocols/financialSummary.ts
7541
7413
  var HF_WARN_THRESHOLD = 1.8;
@@ -7573,14 +7445,13 @@ async function fetchSuiPriceUsd(client) {
7573
7445
  }
7574
7446
  return 1;
7575
7447
  }
7576
- async function getFinancialSummary(client, walletAddress, options = {}) {
7577
- const [usdcBal, suiBal, hf, rates, suiPrice, allowance] = await Promise.all([
7448
+ async function getFinancialSummary(client, walletAddress, _options = {}) {
7449
+ const [usdcBal, suiBal, hf, rates, suiPrice] = await Promise.all([
7578
7450
  client.getBalance({ owner: walletAddress, coinType: SUPPORTED_ASSETS.USDC.type }).catch(() => ({ totalBalance: "0" })),
7579
7451
  client.getBalance({ owner: walletAddress, coinType: SUPPORTED_ASSETS.SUI.type }).catch(() => ({ totalBalance: "0" })),
7580
7452
  getHealthFactor(client, walletAddress).catch(() => HF_FALLBACK),
7581
7453
  getRates(client),
7582
- fetchSuiPriceUsd(client),
7583
- options.allowanceId ? getAllowanceBalance(client, options.allowanceId).catch(() => null) : Promise.resolve(null)
7454
+ fetchSuiPriceUsd(client)
7584
7455
  ]);
7585
7456
  const usdcAvailable = Number(usdcBal.totalBalance) / 10 ** SUPPORTED_ASSETS.USDC.decimals;
7586
7457
  const gasReserveSui = Number(suiBal.totalBalance) / Number(MIST_PER_SUI);
@@ -7600,7 +7471,6 @@ async function getFinancialSummary(client, walletAddress, options = {}) {
7600
7471
  dailyYield,
7601
7472
  gasReserveSui,
7602
7473
  gasReserveUsd: gasReserveSui * suiPrice,
7603
- allowanceBalance: allowance,
7604
7474
  fetchedAt: Date.now()
7605
7475
  };
7606
7476
  }
@@ -7715,65 +7585,12 @@ async function getSwapQuote(params) {
7715
7585
  init_cetus_swap();
7716
7586
  init_token_registry();
7717
7587
  init_volo();
7718
- var DEFAULT_TTL_MS = 6e4;
7719
- async function buildScopedIntent(adminKeypair, params) {
7720
- const now = Date.now();
7721
- const nonceBytes = new Uint8Array(32);
7722
- crypto.getRandomValues(nonceBytes);
7723
- const nonce = Buffer.from(nonceBytes).toString("hex");
7724
- const payload = {
7725
- version: 1,
7726
- userId: params.userId,
7727
- walletAddress: params.walletAddress,
7728
- allowanceObjectId: params.allowanceObjectId,
7729
- featureCode: params.featureCode,
7730
- maxAmount: params.maxAmount,
7731
- issuedAt: now,
7732
- expiresAt: now + (params.ttlMs ?? DEFAULT_TTL_MS),
7733
- nonce
7734
- };
7735
- const message = canonicalIntentBytes(payload);
7736
- const signature = await adminKeypair.sign(message);
7737
- return {
7738
- ...payload,
7739
- signature: Buffer.from(signature).toString("hex")
7740
- };
7741
- }
7742
- async function verifyScopedIntent(intent, adminPublicKeyBytes) {
7743
- if (Date.now() > intent.expiresAt) return false;
7744
- const payload = {
7745
- version: intent.version,
7746
- userId: intent.userId,
7747
- walletAddress: intent.walletAddress,
7748
- allowanceObjectId: intent.allowanceObjectId,
7749
- featureCode: intent.featureCode,
7750
- maxAmount: intent.maxAmount,
7751
- issuedAt: intent.issuedAt,
7752
- expiresAt: intent.expiresAt,
7753
- nonce: intent.nonce
7754
- };
7755
- const message = canonicalIntentBytes(payload);
7756
- const signatureBytes = Buffer.from(intent.signature, "hex");
7757
- try {
7758
- const publicKey = new ed25519.Ed25519PublicKey(adminPublicKeyBytes);
7759
- return await publicKey.verify(message, signatureBytes);
7760
- } catch {
7761
- return false;
7762
- }
7763
- }
7764
- function canonicalIntentBytes(payload) {
7765
- const sorted = Object.fromEntries(
7766
- Object.entries(payload).sort(([a], [b2]) => a.localeCompare(b2))
7767
- );
7768
- return new TextEncoder().encode(JSON.stringify(sorted));
7769
- }
7770
7588
  /*! Bundled license information:
7771
7589
 
7772
7590
  @scure/base/index.js:
7773
7591
  (*! scure-base - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
7774
7592
  */
7775
7593
 
7776
- exports.ALLOWANCE_FEATURES = ALLOWANCE_FEATURES;
7777
7594
  exports.ALL_NAVI_ASSETS = ALL_NAVI_ASSETS;
7778
7595
  exports.BPS_DENOMINATOR = BPS_DENOMINATOR;
7779
7596
  exports.CETUS_USDC_SUI_POOL = CETUS_USDC_SUI_POOL;
@@ -7799,19 +7616,11 @@ exports.T2000 = T2000;
7799
7616
  exports.USDC_DECIMALS = USDC_DECIMALS;
7800
7617
  exports.ZkLoginSigner = ZkLoginSigner;
7801
7618
  exports.addCollectFeeToTx = addCollectFeeToTx;
7802
- exports.addDepositAllowanceTx = addDepositAllowanceTx;
7803
7619
  exports.allDescriptors = allDescriptors;
7804
7620
  exports.assertAllowedAsset = assertAllowedAsset;
7805
- exports.buildAdminDepositAllowanceTx = buildAdminDepositAllowanceTx;
7806
- exports.buildCreateAllowanceTx = buildCreateAllowanceTx;
7807
- exports.buildDeductAllowanceTx = buildDeductAllowanceTx;
7808
- exports.buildDepositAllowanceTx = buildDepositAllowanceTx;
7809
- exports.buildScopedIntent = buildScopedIntent;
7810
7621
  exports.buildStakeVSuiTx = buildStakeVSuiTx;
7811
7622
  exports.buildSwapTx = buildSwapTx;
7812
7623
  exports.buildUnstakeVSuiTx = buildUnstakeVSuiTx;
7813
- exports.buildWithdrawAllowanceTx = buildWithdrawAllowanceTx;
7814
- exports.buildWithdrawAmountAllowanceTx = buildWithdrawAmountAllowanceTx;
7815
7624
  exports.calculateFee = calculateFee;
7816
7625
  exports.executeAutoTopUp = executeAutoTopUp;
7817
7626
  exports.executeWithGas = executeWithGas;
@@ -7822,8 +7631,6 @@ exports.formatSui = formatSui;
7822
7631
  exports.formatUsd = formatUsd;
7823
7632
  exports.generateKeypair = generateKeypair;
7824
7633
  exports.getAddress = getAddress;
7825
- exports.getAllowance = getAllowance;
7826
- exports.getAllowanceBalance = getAllowanceBalance;
7827
7634
  exports.getDecimals = getDecimals;
7828
7635
  exports.getDecimalsForCoinType = getDecimalsForCoinType;
7829
7636
  exports.getFinancialSummary = getFinancialSummary;
@@ -7857,7 +7664,6 @@ exports.throwIfSimulationFailed = throwIfSimulationFailed;
7857
7664
  exports.truncateAddress = truncateAddress;
7858
7665
  exports.usdcToRaw = usdcToRaw;
7859
7666
  exports.validateAddress = validateAddress;
7860
- exports.verifyScopedIntent = verifyScopedIntent;
7861
7667
  exports.walletExists = walletExists;
7862
7668
  //# sourceMappingURL=index.cjs.map
7863
7669
  //# sourceMappingURL=index.cjs.map