@t2000/cli 0.26.2 → 0.27.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
@@ -144,6 +144,7 @@ t2000 init
144
144
  | Command | Description |
145
145
  |---------|-------------|
146
146
  | `t2000 send <amount> <asset> [to] <address>` | Send USDC, SUI, or other assets to any Sui address (the `to` keyword is optional) |
147
+ | `t2000 receive` | Generate a payment request with address and QR URI. Options: `--amount`, `--currency`, `--memo`, `--label` |
147
148
 
148
149
  ### Savings & DeFi
149
150
 
@@ -4,8 +4,8 @@ import {
4
4
  offchainLookup,
5
5
  offchainLookupAbiItem,
6
6
  offchainLookupSignature
7
- } from "./chunk-3I6VJOM6.js";
8
- import "./chunk-EI3GHTKX.js";
7
+ } from "./chunk-A5X4KG7U.js";
8
+ import "./chunk-77SWBATH.js";
9
9
  import "./chunk-7LGHVVIJ.js";
10
10
  import "./chunk-YPWSCLE3.js";
11
11
  export {
@@ -14,4 +14,4 @@ export {
14
14
  offchainLookupAbiItem,
15
15
  offchainLookupSignature
16
16
  };
17
- //# sourceMappingURL=ccip-XP27NGI7.js.map
17
+ //# sourceMappingURL=ccip-JEEJV65M.js.map
@@ -64232,15 +64232,27 @@ function assertAllowedAsset(op, asset) {
64232
64232
  );
64233
64233
  }
64234
64234
  }
64235
- var T2000_PACKAGE_ID = process.env.T2000_PACKAGE_ID ?? "0xab92e9f1fe549ad3d6a52924a73181b45791e76120b975138fac9ec9b75db9f3";
64236
- var T2000_CONFIG_ID = process.env.T2000_CONFIG_ID ?? "0x408add9aa9322f93cfd87523d8f603006eb8713894f4c460283c58a6888dae8a";
64237
- var T2000_TREASURY_ID = process.env.T2000_TREASURY_ID ?? "0x3bb501b8300125dca59019247941a42af6b292a150ce3cfcce9449456be2ec91";
64235
+ var T2000_PACKAGE_ID = process.env.T2000_PACKAGE_ID ?? "0xd775fcc66eae26797654d435d751dea56b82eeb999de51fd285348e573b968ad";
64236
+ var T2000_CONFIG_ID = process.env.T2000_CONFIG_ID ?? "0x08ba26f0d260b5edf6a19c71492b3eb914906a7419baf2df1426765157e5862a";
64237
+ var T2000_ADMIN_CAP_ID = "0xa97bfff140f5a2c268a03fe5422d382c228057deb7bcfdaf2967ca18b9bdbbd9";
64238
+ var T2000_TREASURY_ID = process.env.T2000_TREASURY_ID ?? "0xf420ec0dcad44433042fb56e1413fb88d3ff65be94fcf425ef9ff750164590e8";
64238
64239
  var DEFAULT_NETWORK = "mainnet";
64239
64240
  var DEFAULT_RPC_URL = "https://fullnode.mainnet.sui.io:443";
64240
64241
  var DEFAULT_KEY_PATH = "~/.t2000/wallet.key";
64241
64242
  var API_BASE_URL = process.env.T2000_API_URL ?? "https://api.t2000.ai";
64242
64243
  var CETUS_USDC_SUI_POOL = "0x51e883ba7c0b566a26cbc8a94cd33eb0abd418a77cc1e60ad22fd9b1f29cd2ab";
64243
64244
  var GAS_RESERVE_MIN = 0.05;
64245
+ var ALLOWANCE_FEATURES = {
64246
+ BRIEFING: 0,
64247
+ YIELD_ALERT: 1,
64248
+ PAYMENT_ALERT: 2,
64249
+ ACTION_REMIND: 3,
64250
+ SESSION: 4,
64251
+ AUTO_COMPOUND: 5,
64252
+ DCA: 6,
64253
+ HF_ALERT: 7
64254
+ };
64255
+ var FEATURES_ALL = 255;
64244
64256
  init_errors();
64245
64257
  var cachedClient = null;
64246
64258
  function getSuiClient(rpcUrl) {
@@ -64617,7 +64629,7 @@ function extractCommands(txBlock) {
64617
64629
  if (!data || typeof data !== "object") return result;
64618
64630
  const inner = "transaction" in data ? data.transaction : void 0;
64619
64631
  if (!inner || typeof inner !== "object") return result;
64620
- const commands = "commands" in inner ? inner.commands : void 0;
64632
+ const commands = "commands" in inner ? inner.commands : "transactions" in inner ? inner.transactions : void 0;
64621
64633
  if (!Array.isArray(commands)) return result;
64622
64634
  for (const cmd of commands) {
64623
64635
  if (cmd.MoveCall) {
@@ -66005,8 +66017,8 @@ var T2000 = class _T2000 extends import_index.default {
66005
66017
  async pay(options) {
66006
66018
  this.enforcer.assertNotLocked();
66007
66019
  this.enforcer.check({ operation: "pay", amount: options.maxPrice ?? 1 });
66008
- const { Mppx } = await import("./client-IXUBQ3HM.js");
66009
- const { sui } = await import("./client-YNWQPUC5.js");
66020
+ const { Mppx } = await import("./client-KQCHOXLV.js");
66021
+ const { sui } = await import("./client-2MUO6VAJ.js");
66010
66022
  const client = this.client;
66011
66023
  const signer = this._signer;
66012
66024
  const signerAddress = signer.getAddress();
@@ -66309,6 +66321,32 @@ var T2000 = class _T2000 extends import_index.default {
66309
66321
  ].join("\n")
66310
66322
  };
66311
66323
  }
66324
+ receive(params) {
66325
+ const amount = params?.amount ?? null;
66326
+ const currency = params?.currency ?? "USDC";
66327
+ const memo = params?.memo ?? null;
66328
+ const label = params?.label ?? null;
66329
+ const qrParts = [`sui:${this._address}`];
66330
+ const queryParams = [];
66331
+ if (amount != null) queryParams.push(`amount=${amount}`);
66332
+ if (currency !== "SUI") queryParams.push(`currency=${currency}`);
66333
+ if (memo) queryParams.push(`memo=${encodeURIComponent(memo)}`);
66334
+ if (label) queryParams.push(`label=${encodeURIComponent(label)}`);
66335
+ const qrUri = queryParams.length > 0 ? `${qrParts[0]}?${queryParams.join("&")}` : qrParts[0];
66336
+ const amountStr = amount != null ? `$${amount.toFixed(2)} ` : "";
66337
+ const displayParts = [`Send ${amountStr}${currency} to ${truncateAddress(this._address)}`];
66338
+ if (memo) displayParts.push(`Memo: ${memo}`);
66339
+ return {
66340
+ address: this._address,
66341
+ network: "mainnet",
66342
+ amount,
66343
+ currency,
66344
+ memo,
66345
+ label,
66346
+ qrUri,
66347
+ displayText: displayParts.join("\n")
66348
+ };
66349
+ }
66312
66350
  exportKey() {
66313
66351
  return exportPrivateKey(this.keypair);
66314
66352
  }
@@ -66953,6 +66991,188 @@ async function callUsdcSponsorApi(address) {
66953
66991
  }
66954
66992
  }
66955
66993
  init_errors();
66994
+ var USDC_TYPE2 = SUPPORTED_ASSETS.USDC.type;
66995
+ function buildCreateAllowanceTx(options = {}) {
66996
+ const tx = new Transaction();
66997
+ tx.moveCall({
66998
+ target: `${T2000_PACKAGE_ID}::allowance::create`,
66999
+ typeArguments: [USDC_TYPE2],
67000
+ arguments: [
67001
+ tx.pure.u64(options.permittedFeatures ?? BigInt(FEATURES_ALL)),
67002
+ tx.pure.u64(options.expiresAt ?? 0n),
67003
+ tx.pure.u64(options.dailyLimit ?? 0n),
67004
+ tx.object(CLOCK_ID)
67005
+ ]
67006
+ });
67007
+ return tx;
67008
+ }
67009
+ function addDepositAllowanceTx(tx, allowanceId, paymentCoin) {
67010
+ tx.moveCall({
67011
+ target: `${T2000_PACKAGE_ID}::allowance::deposit`,
67012
+ typeArguments: [USDC_TYPE2],
67013
+ arguments: [tx.object(allowanceId), paymentCoin]
67014
+ });
67015
+ }
67016
+ function buildDepositAllowanceTx(allowanceId, usdcCoin, amount) {
67017
+ const tx = new Transaction();
67018
+ const [split2] = tx.splitCoins(tx.object(usdcCoin), [tx.pure.u64(amount)]);
67019
+ addDepositAllowanceTx(tx, allowanceId, split2);
67020
+ return tx;
67021
+ }
67022
+ function buildAdminDepositAllowanceTx(allowanceId, usdcCoin, amount) {
67023
+ const tx = new Transaction();
67024
+ const [split2] = tx.splitCoins(tx.object(usdcCoin), [tx.pure.u64(amount)]);
67025
+ tx.moveCall({
67026
+ target: `${T2000_PACKAGE_ID}::allowance::admin_deposit`,
67027
+ typeArguments: [USDC_TYPE2],
67028
+ arguments: [
67029
+ tx.object(allowanceId),
67030
+ tx.object(T2000_ADMIN_CAP_ID),
67031
+ split2
67032
+ ]
67033
+ });
67034
+ return tx;
67035
+ }
67036
+ function buildDeductAllowanceTx(allowanceId, amount, feature) {
67037
+ const tx = new Transaction();
67038
+ tx.moveCall({
67039
+ target: `${T2000_PACKAGE_ID}::allowance::deduct`,
67040
+ typeArguments: [USDC_TYPE2],
67041
+ arguments: [
67042
+ tx.object(allowanceId),
67043
+ tx.object(T2000_CONFIG_ID),
67044
+ tx.object(T2000_ADMIN_CAP_ID),
67045
+ tx.pure.u64(amount),
67046
+ tx.pure.u8(feature),
67047
+ tx.object(CLOCK_ID)
67048
+ ]
67049
+ });
67050
+ return tx;
67051
+ }
67052
+ function buildWithdrawAllowanceTx(allowanceId) {
67053
+ const tx = new Transaction();
67054
+ tx.moveCall({
67055
+ target: `${T2000_PACKAGE_ID}::allowance::withdraw`,
67056
+ typeArguments: [USDC_TYPE2],
67057
+ arguments: [tx.object(allowanceId)]
67058
+ });
67059
+ return tx;
67060
+ }
67061
+ function buildWithdrawAmountAllowanceTx(allowanceId, amount) {
67062
+ const tx = new Transaction();
67063
+ tx.moveCall({
67064
+ target: `${T2000_PACKAGE_ID}::allowance::withdraw_amount`,
67065
+ typeArguments: [USDC_TYPE2],
67066
+ arguments: [tx.object(allowanceId), tx.pure.u64(amount)]
67067
+ });
67068
+ return tx;
67069
+ }
67070
+ async function getAllowance(client, allowanceId) {
67071
+ const obj = await client.getObject({
67072
+ id: allowanceId,
67073
+ options: { showContent: true, showType: true }
67074
+ });
67075
+ if (!obj.data?.content || obj.data.content.dataType !== "moveObject") {
67076
+ throw new Error(`Allowance ${allowanceId} not found or is not a Move object`);
67077
+ }
67078
+ const fields = obj.data.content.fields;
67079
+ const coinType = extractCoinType(obj.data.content.type);
67080
+ return {
67081
+ id: allowanceId,
67082
+ owner: fields.owner,
67083
+ balance: parseU64Field(fields.balance),
67084
+ totalDeposited: parseU64Field(fields.total_deposited),
67085
+ totalSpent: parseU64Field(fields.total_spent),
67086
+ createdAt: Number(fields.created_at),
67087
+ coinType,
67088
+ permittedFeatures: parseU64Field(fields.permitted_features),
67089
+ expiresAt: Number(fields.expires_at),
67090
+ dailyLimit: parseU64Field(fields.daily_limit),
67091
+ dailySpent: parseU64Field(fields.daily_spent),
67092
+ windowStart: Number(fields.window_start)
67093
+ };
67094
+ }
67095
+ async function getAllowanceBalance(client, allowanceId) {
67096
+ const info = await getAllowance(client, allowanceId);
67097
+ return info.balance;
67098
+ }
67099
+ function parseU64Field(raw) {
67100
+ if (typeof raw === "string" || typeof raw === "number") return BigInt(raw);
67101
+ if (typeof raw === "object" && raw !== null && "value" in raw) {
67102
+ return BigInt(raw.value);
67103
+ }
67104
+ return 0n;
67105
+ }
67106
+ function extractCoinType(objectType2) {
67107
+ const match = objectType2.match(/<(.+)>/);
67108
+ return match ? match[1] : "unknown";
67109
+ }
67110
+ var HF_WARN_THRESHOLD = 1.8;
67111
+ var HF_CRITICAL_THRESHOLD = 1.3;
67112
+ var HF_FALLBACK = {
67113
+ healthFactor: Infinity,
67114
+ supplied: 0,
67115
+ borrowed: 0,
67116
+ maxBorrow: 0,
67117
+ liquidationThreshold: 0.75
67118
+ };
67119
+ function classifyHF(hf, hasBorrow) {
67120
+ if (!hasBorrow || !Number.isFinite(hf)) return "none";
67121
+ if (hf <= HF_CRITICAL_THRESHOLD) return "critical";
67122
+ if (hf <= HF_WARN_THRESHOLD) return "warn";
67123
+ return "none";
67124
+ }
67125
+ async function fetchSuiPriceUsd(client) {
67126
+ try {
67127
+ const pool = await client.getObject({
67128
+ id: CETUS_USDC_SUI_POOL,
67129
+ options: { showContent: true }
67130
+ });
67131
+ if (pool.data?.content?.dataType === "moveObject") {
67132
+ const fields = pool.data.content.fields;
67133
+ const sqrtPrice = BigInt(String(fields.current_sqrt_price ?? "0"));
67134
+ if (sqrtPrice > 0n) {
67135
+ const Q64 = 2n ** 64n;
67136
+ const sqrtFloat = Number(sqrtPrice) / Number(Q64);
67137
+ const price = 1e3 / (sqrtFloat * sqrtFloat);
67138
+ if (price > 0.01 && price < 1e3) return price;
67139
+ }
67140
+ }
67141
+ } catch {
67142
+ }
67143
+ return 1;
67144
+ }
67145
+ async function getFinancialSummary(client, walletAddress, options = {}) {
67146
+ const [usdcBal, suiBal, hf, rates, suiPrice, allowance] = await Promise.all([
67147
+ client.getBalance({ owner: walletAddress, coinType: SUPPORTED_ASSETS.USDC.type }).catch(() => ({ totalBalance: "0" })),
67148
+ client.getBalance({ owner: walletAddress, coinType: SUPPORTED_ASSETS.SUI.type }).catch(() => ({ totalBalance: "0" })),
67149
+ getHealthFactor(client, walletAddress).catch(() => HF_FALLBACK),
67150
+ getRates(client),
67151
+ fetchSuiPriceUsd(client),
67152
+ options.allowanceId ? getAllowanceBalance(client, options.allowanceId).catch(() => null) : Promise.resolve(null)
67153
+ ]);
67154
+ const usdcAvailable = Number(usdcBal.totalBalance) / 10 ** SUPPORTED_ASSETS.USDC.decimals;
67155
+ const gasReserveSui = Number(suiBal.totalBalance) / Number(MIST_PER_SUI2);
67156
+ const saveApy = rates.USDC?.saveApy ?? 0;
67157
+ const borrowApy = rates.USDC?.borrowApy ?? 0;
67158
+ const dailyYield = hf.supplied * (saveApy / 365);
67159
+ return {
67160
+ walletAddress,
67161
+ usdcAvailable,
67162
+ savingsBalance: hf.supplied,
67163
+ debtBalance: hf.borrowed,
67164
+ idleUsdc: Math.max(0, usdcAvailable),
67165
+ healthFactor: hf.healthFactor,
67166
+ hfAlertLevel: classifyHF(hf.healthFactor, hf.borrowed > 0),
67167
+ saveApy,
67168
+ borrowApy,
67169
+ dailyYield,
67170
+ gasReserveSui,
67171
+ gasReserveUsd: gasReserveSui * suiPrice,
67172
+ allowanceBalance: allowance,
67173
+ fetchedAt: Date.now()
67174
+ };
67175
+ }
66956
67176
  init_errors();
66957
67177
  init_errors();
66958
67178
  async function simulateTransaction(client, tx, sender) {
@@ -67058,6 +67278,58 @@ async function getSwapQuote(params) {
67058
67278
  init_cetus_swap();
67059
67279
  init_token_registry();
67060
67280
  init_volo();
67281
+ var DEFAULT_TTL_MS = 6e4;
67282
+ async function buildScopedIntent(adminKeypair, params) {
67283
+ const now = Date.now();
67284
+ const nonceBytes = new Uint8Array(32);
67285
+ crypto.getRandomValues(nonceBytes);
67286
+ const nonce = Buffer.from(nonceBytes).toString("hex");
67287
+ const payload = {
67288
+ version: 1,
67289
+ userId: params.userId,
67290
+ walletAddress: params.walletAddress,
67291
+ allowanceObjectId: params.allowanceObjectId,
67292
+ featureCode: params.featureCode,
67293
+ maxAmount: params.maxAmount,
67294
+ issuedAt: now,
67295
+ expiresAt: now + (params.ttlMs ?? DEFAULT_TTL_MS),
67296
+ nonce
67297
+ };
67298
+ const message = canonicalIntentBytes(payload);
67299
+ const signature = await adminKeypair.sign(message);
67300
+ return {
67301
+ ...payload,
67302
+ signature: Buffer.from(signature).toString("hex")
67303
+ };
67304
+ }
67305
+ async function verifyScopedIntent(intent, adminPublicKeyBytes) {
67306
+ if (Date.now() > intent.expiresAt) return false;
67307
+ const payload = {
67308
+ version: intent.version,
67309
+ userId: intent.userId,
67310
+ walletAddress: intent.walletAddress,
67311
+ allowanceObjectId: intent.allowanceObjectId,
67312
+ featureCode: intent.featureCode,
67313
+ maxAmount: intent.maxAmount,
67314
+ issuedAt: intent.issuedAt,
67315
+ expiresAt: intent.expiresAt,
67316
+ nonce: intent.nonce
67317
+ };
67318
+ const message = canonicalIntentBytes(payload);
67319
+ const signatureBytes = Buffer.from(intent.signature, "hex");
67320
+ try {
67321
+ const publicKey = new Ed25519PublicKey(adminPublicKeyBytes);
67322
+ return await publicKey.verify(message, signatureBytes);
67323
+ } catch {
67324
+ return false;
67325
+ }
67326
+ }
67327
+ function canonicalIntentBytes(payload) {
67328
+ const sorted = Object.fromEntries(
67329
+ Object.entries(payload).sort(([a], [b2]) => a.localeCompare(b2))
67330
+ );
67331
+ return new TextEncoder().encode(JSON.stringify(sorted));
67332
+ }
67061
67333
 
67062
67334
  export {
67063
67335
  ZodOptional,
@@ -67111,6 +67383,7 @@ export {
67111
67383
  DEFAULT_NETWORK,
67112
67384
  CETUS_USDC_SUI_POOL,
67113
67385
  GAS_RESERVE_MIN,
67386
+ ALLOWANCE_FEATURES,
67114
67387
  validateAddress,
67115
67388
  truncateAddress,
67116
67389
  generateKeypair,
@@ -67150,9 +67423,23 @@ export {
67150
67423
  SafeguardEnforcer,
67151
67424
  ContactManager,
67152
67425
  T2000,
67426
+ buildCreateAllowanceTx,
67427
+ addDepositAllowanceTx,
67428
+ buildDepositAllowanceTx,
67429
+ buildAdminDepositAllowanceTx,
67430
+ buildDeductAllowanceTx,
67431
+ buildWithdrawAllowanceTx,
67432
+ buildWithdrawAmountAllowanceTx,
67433
+ getAllowance,
67434
+ getAllowanceBalance,
67435
+ HF_WARN_THRESHOLD,
67436
+ HF_CRITICAL_THRESHOLD,
67437
+ getFinancialSummary,
67153
67438
  simulateTransaction,
67154
67439
  throwIfSimulationFailed,
67155
- getSwapQuote
67440
+ getSwapQuote,
67441
+ buildScopedIntent,
67442
+ verifyScopedIntent
67156
67443
  };
67157
67444
  /*! Bundled license information:
67158
67445
 
@@ -67201,4 +67488,4 @@ axios/dist/node/axios.cjs:
67201
67488
  @scure/bip39/index.js:
67202
67489
  (*! scure-bip39 - MIT License (c) 2022 Patricio Palladino, Paul Miller (paulmillr.com) *)
67203
67490
  */
67204
- //# sourceMappingURL=chunk-KLHAR3XK.js.map
67491
+ //# sourceMappingURL=chunk-2JUMTEBB.js.map