@t2000/cli 0.38.0 → 0.39.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/{chunk-J7X23P3A.js → chunk-4YV63VD3.js} +11 -205
- package/dist/chunk-4YV63VD3.js.map +1 -0
- package/dist/{dist-CEF2K35K.js → dist-LJKS6IJU.js} +8 -8
- package/dist/{dist-CEF2K35K.js.map → dist-LJKS6IJU.js.map} +1 -1
- package/dist/{dist-4XKBULY7.js → dist-X2WIJABG.js} +2 -26
- package/dist/index.js +3 -3
- package/package.json +3 -3
- package/dist/chunk-J7X23P3A.js.map +0 -1
- /package/dist/{dist-4XKBULY7.js.map → dist-X2WIJABG.js.map} +0 -0
|
@@ -60680,7 +60680,6 @@ function assertAllowedAsset(op, asset) {
|
|
|
60680
60680
|
}
|
|
60681
60681
|
var T2000_PACKAGE_ID = process.env.T2000_PACKAGE_ID ?? "0xd775fcc66eae26797654d435d751dea56b82eeb999de51fd285348e573b968ad";
|
|
60682
60682
|
var T2000_CONFIG_ID = process.env.T2000_CONFIG_ID ?? "0x08ba26f0d260b5edf6a19c71492b3eb914906a7419baf2df1426765157e5862a";
|
|
60683
|
-
var T2000_ADMIN_CAP_ID = "0xa97bfff140f5a2c268a03fe5422d382c228057deb7bcfdaf2967ca18b9bdbbd9";
|
|
60684
60683
|
var T2000_TREASURY_ID = process.env.T2000_TREASURY_ID ?? "0xf420ec0dcad44433042fb56e1413fb88d3ff65be94fcf425ef9ff750164590e8";
|
|
60685
60684
|
var DEFAULT_NETWORK = "mainnet";
|
|
60686
60685
|
var DEFAULT_RPC_URL = "https://fullnode.mainnet.sui.io:443";
|
|
@@ -60688,17 +60687,6 @@ var DEFAULT_KEY_PATH = "~/.t2000/wallet.key";
|
|
|
60688
60687
|
var API_BASE_URL = process.env.T2000_API_URL ?? "https://api.t2000.ai";
|
|
60689
60688
|
var CETUS_USDC_SUI_POOL = "0x51e883ba7c0b566a26cbc8a94cd33eb0abd418a77cc1e60ad22fd9b1f29cd2ab";
|
|
60690
60689
|
var GAS_RESERVE_MIN = 0.05;
|
|
60691
|
-
var ALLOWANCE_FEATURES = {
|
|
60692
|
-
BRIEFING: 0,
|
|
60693
|
-
YIELD_ALERT: 1,
|
|
60694
|
-
PAYMENT_ALERT: 2,
|
|
60695
|
-
ACTION_REMIND: 3,
|
|
60696
|
-
SESSION: 4,
|
|
60697
|
-
AUTO_COMPOUND: 5,
|
|
60698
|
-
DCA: 6,
|
|
60699
|
-
HF_ALERT: 7
|
|
60700
|
-
};
|
|
60701
|
-
var FEATURES_ALL = 255;
|
|
60702
60690
|
init_errors();
|
|
60703
60691
|
var cachedClient = null;
|
|
60704
60692
|
function getSuiClient(rpcUrl) {
|
|
@@ -66881,7 +66869,7 @@ var T2000 = class _T2000 extends import_index.default {
|
|
|
66881
66869
|
async compoundRewards(options = {}) {
|
|
66882
66870
|
this.enforcer.assertNotLocked();
|
|
66883
66871
|
const minValue = options.minValueUsd ?? 0.1;
|
|
66884
|
-
const
|
|
66872
|
+
const USDC_TYPE2 = SUPPORTED_ASSETS.USDC.type;
|
|
66885
66873
|
const USDC_DEC = SUPPORTED_ASSETS.USDC.decimals;
|
|
66886
66874
|
const pending = await this.getPendingRewards();
|
|
66887
66875
|
const nonTrivial = pending.filter((r) => r.amount > 0);
|
|
@@ -66908,7 +66896,7 @@ var T2000 = class _T2000 extends import_index.default {
|
|
|
66908
66896
|
totalGasCost: 0
|
|
66909
66897
|
};
|
|
66910
66898
|
}
|
|
66911
|
-
const preUsdcCoins = await this._fetchCoins(
|
|
66899
|
+
const preUsdcCoins = await this._fetchCoins(USDC_TYPE2);
|
|
66912
66900
|
const preUsdcRaw = preUsdcCoins.reduce((s, c) => s + BigInt(c.balance), 0n);
|
|
66913
66901
|
const claimResult = await this.claimRewards();
|
|
66914
66902
|
if (!claimResult.tx) {
|
|
@@ -66927,7 +66915,7 @@ var T2000 = class _T2000 extends import_index.default {
|
|
|
66927
66915
|
let totalGasCost = claimResult.gasCost;
|
|
66928
66916
|
for (const reward of nonTrivial) {
|
|
66929
66917
|
if (!reward.coinType) continue;
|
|
66930
|
-
if (reward.coinType ===
|
|
66918
|
+
if (reward.coinType === USDC_TYPE2) continue;
|
|
66931
66919
|
try {
|
|
66932
66920
|
const decimals = getDecimalsForCoinType(reward.coinType) ?? 9;
|
|
66933
66921
|
const rawAmount = BigInt(Math.floor(reward.amount * 10 ** decimals));
|
|
@@ -66937,7 +66925,7 @@ var T2000 = class _T2000 extends import_index.default {
|
|
|
66937
66925
|
const route = await findSwapRoute2({
|
|
66938
66926
|
walletAddress: this._address,
|
|
66939
66927
|
from: reward.coinType,
|
|
66940
|
-
to:
|
|
66928
|
+
to: USDC_TYPE2,
|
|
66941
66929
|
amount: rawAmount,
|
|
66942
66930
|
byAmountIn: true
|
|
66943
66931
|
});
|
|
@@ -66965,7 +66953,7 @@ var T2000 = class _T2000 extends import_index.default {
|
|
|
66965
66953
|
console.warn(`[compound] Failed to swap ${reward.symbol}:`, err instanceof Error ? err.message : err);
|
|
66966
66954
|
}
|
|
66967
66955
|
}
|
|
66968
|
-
const postUsdcCoins = await this._fetchCoins(
|
|
66956
|
+
const postUsdcCoins = await this._fetchCoins(USDC_TYPE2);
|
|
66969
66957
|
const postUsdcRaw = postUsdcCoins.reduce((s, c) => s + BigInt(c.balance), 0n);
|
|
66970
66958
|
const gainedRaw = postUsdcRaw > preUsdcRaw ? postUsdcRaw - preUsdcRaw : 0n;
|
|
66971
66959
|
const depositUsdc = Number(gainedRaw) / 10 ** USDC_DEC;
|
|
@@ -66976,7 +66964,7 @@ var T2000 = class _T2000 extends import_index.default {
|
|
|
66976
66964
|
const depositResult = await executeWithGas(this.client, this._signer, async () => {
|
|
66977
66965
|
const tx = new Transaction();
|
|
66978
66966
|
tx.setSender(this._address);
|
|
66979
|
-
const coins = await this._fetchCoins(
|
|
66967
|
+
const coins = await this._fetchCoins(USDC_TYPE2);
|
|
66980
66968
|
if (coins.length === 0) throw new T2000Error("INSUFFICIENT_BALANCE", "No USDC coins after swap");
|
|
66981
66969
|
const merged = this._mergeCoinsInTx(tx, coins);
|
|
66982
66970
|
const [inputCoin] = tx.splitCoins(merged, [gainedRaw]);
|
|
@@ -67128,122 +67116,6 @@ async function callSponsorApi(address, name) {
|
|
|
67128
67116
|
}
|
|
67129
67117
|
}
|
|
67130
67118
|
init_errors();
|
|
67131
|
-
var USDC_TYPE2 = SUPPORTED_ASSETS.USDC.type;
|
|
67132
|
-
function buildCreateAllowanceTx(options = {}) {
|
|
67133
|
-
const tx = new Transaction();
|
|
67134
|
-
tx.moveCall({
|
|
67135
|
-
target: `${T2000_PACKAGE_ID}::allowance::create`,
|
|
67136
|
-
typeArguments: [USDC_TYPE2],
|
|
67137
|
-
arguments: [
|
|
67138
|
-
tx.pure.u64(options.permittedFeatures ?? BigInt(FEATURES_ALL)),
|
|
67139
|
-
tx.pure.u64(options.expiresAt ?? 0n),
|
|
67140
|
-
tx.pure.u64(options.dailyLimit ?? 0n),
|
|
67141
|
-
tx.object(CLOCK_ID)
|
|
67142
|
-
]
|
|
67143
|
-
});
|
|
67144
|
-
return tx;
|
|
67145
|
-
}
|
|
67146
|
-
function addDepositAllowanceTx(tx, allowanceId, paymentCoin) {
|
|
67147
|
-
tx.moveCall({
|
|
67148
|
-
target: `${T2000_PACKAGE_ID}::allowance::deposit`,
|
|
67149
|
-
typeArguments: [USDC_TYPE2],
|
|
67150
|
-
arguments: [tx.object(allowanceId), paymentCoin]
|
|
67151
|
-
});
|
|
67152
|
-
}
|
|
67153
|
-
function buildDepositAllowanceTx(allowanceId, usdcCoin, amount) {
|
|
67154
|
-
const tx = new Transaction();
|
|
67155
|
-
const [split2] = tx.splitCoins(tx.object(usdcCoin), [tx.pure.u64(amount)]);
|
|
67156
|
-
addDepositAllowanceTx(tx, allowanceId, split2);
|
|
67157
|
-
return tx;
|
|
67158
|
-
}
|
|
67159
|
-
function buildAdminDepositAllowanceTx(allowanceId, usdcCoin, amount) {
|
|
67160
|
-
const tx = new Transaction();
|
|
67161
|
-
const [split2] = tx.splitCoins(tx.object(usdcCoin), [tx.pure.u64(amount)]);
|
|
67162
|
-
tx.moveCall({
|
|
67163
|
-
target: `${T2000_PACKAGE_ID}::allowance::admin_deposit`,
|
|
67164
|
-
typeArguments: [USDC_TYPE2],
|
|
67165
|
-
arguments: [
|
|
67166
|
-
tx.object(allowanceId),
|
|
67167
|
-
tx.object(T2000_ADMIN_CAP_ID),
|
|
67168
|
-
split2
|
|
67169
|
-
]
|
|
67170
|
-
});
|
|
67171
|
-
return tx;
|
|
67172
|
-
}
|
|
67173
|
-
function buildDeductAllowanceTx(allowanceId, amount, feature) {
|
|
67174
|
-
const tx = new Transaction();
|
|
67175
|
-
tx.moveCall({
|
|
67176
|
-
target: `${T2000_PACKAGE_ID}::allowance::deduct`,
|
|
67177
|
-
typeArguments: [USDC_TYPE2],
|
|
67178
|
-
arguments: [
|
|
67179
|
-
tx.object(allowanceId),
|
|
67180
|
-
tx.object(T2000_CONFIG_ID),
|
|
67181
|
-
tx.object(T2000_ADMIN_CAP_ID),
|
|
67182
|
-
tx.pure.u64(amount),
|
|
67183
|
-
tx.pure.u8(feature),
|
|
67184
|
-
tx.object(CLOCK_ID)
|
|
67185
|
-
]
|
|
67186
|
-
});
|
|
67187
|
-
return tx;
|
|
67188
|
-
}
|
|
67189
|
-
function buildWithdrawAllowanceTx(allowanceId) {
|
|
67190
|
-
const tx = new Transaction();
|
|
67191
|
-
tx.moveCall({
|
|
67192
|
-
target: `${T2000_PACKAGE_ID}::allowance::withdraw`,
|
|
67193
|
-
typeArguments: [USDC_TYPE2],
|
|
67194
|
-
arguments: [tx.object(allowanceId)]
|
|
67195
|
-
});
|
|
67196
|
-
return tx;
|
|
67197
|
-
}
|
|
67198
|
-
function buildWithdrawAmountAllowanceTx(allowanceId, amount) {
|
|
67199
|
-
const tx = new Transaction();
|
|
67200
|
-
tx.moveCall({
|
|
67201
|
-
target: `${T2000_PACKAGE_ID}::allowance::withdraw_amount`,
|
|
67202
|
-
typeArguments: [USDC_TYPE2],
|
|
67203
|
-
arguments: [tx.object(allowanceId), tx.pure.u64(amount)]
|
|
67204
|
-
});
|
|
67205
|
-
return tx;
|
|
67206
|
-
}
|
|
67207
|
-
async function getAllowance(client, allowanceId) {
|
|
67208
|
-
const obj = await client.getObject({
|
|
67209
|
-
id: allowanceId,
|
|
67210
|
-
options: { showContent: true, showType: true }
|
|
67211
|
-
});
|
|
67212
|
-
if (!obj.data?.content || obj.data.content.dataType !== "moveObject") {
|
|
67213
|
-
throw new Error(`Allowance ${allowanceId} not found or is not a Move object`);
|
|
67214
|
-
}
|
|
67215
|
-
const fields = obj.data.content.fields;
|
|
67216
|
-
const coinType = extractCoinType(obj.data.content.type);
|
|
67217
|
-
return {
|
|
67218
|
-
id: allowanceId,
|
|
67219
|
-
owner: fields.owner,
|
|
67220
|
-
balance: parseU64Field(fields.balance),
|
|
67221
|
-
totalDeposited: parseU64Field(fields.total_deposited),
|
|
67222
|
-
totalSpent: parseU64Field(fields.total_spent),
|
|
67223
|
-
createdAt: Number(fields.created_at),
|
|
67224
|
-
coinType,
|
|
67225
|
-
permittedFeatures: parseU64Field(fields.permitted_features),
|
|
67226
|
-
expiresAt: Number(fields.expires_at),
|
|
67227
|
-
dailyLimit: parseU64Field(fields.daily_limit),
|
|
67228
|
-
dailySpent: parseU64Field(fields.daily_spent),
|
|
67229
|
-
windowStart: Number(fields.window_start)
|
|
67230
|
-
};
|
|
67231
|
-
}
|
|
67232
|
-
async function getAllowanceBalance(client, allowanceId) {
|
|
67233
|
-
const info = await getAllowance(client, allowanceId);
|
|
67234
|
-
return info.balance;
|
|
67235
|
-
}
|
|
67236
|
-
function parseU64Field(raw) {
|
|
67237
|
-
if (typeof raw === "string" || typeof raw === "number") return BigInt(raw);
|
|
67238
|
-
if (typeof raw === "object" && raw !== null && "value" in raw) {
|
|
67239
|
-
return BigInt(raw.value);
|
|
67240
|
-
}
|
|
67241
|
-
return 0n;
|
|
67242
|
-
}
|
|
67243
|
-
function extractCoinType(objectType2) {
|
|
67244
|
-
const match = objectType2.match(/<(.+)>/);
|
|
67245
|
-
return match ? match[1] : "unknown";
|
|
67246
|
-
}
|
|
67247
67119
|
var HF_WARN_THRESHOLD = 1.8;
|
|
67248
67120
|
var HF_CRITICAL_THRESHOLD = 1.3;
|
|
67249
67121
|
var HF_FALLBACK = {
|
|
@@ -67279,14 +67151,13 @@ async function fetchSuiPriceUsd(client) {
|
|
|
67279
67151
|
}
|
|
67280
67152
|
return 1;
|
|
67281
67153
|
}
|
|
67282
|
-
async function getFinancialSummary(client, walletAddress,
|
|
67283
|
-
const [usdcBal, suiBal, hf, rates, suiPrice
|
|
67154
|
+
async function getFinancialSummary(client, walletAddress, _options = {}) {
|
|
67155
|
+
const [usdcBal, suiBal, hf, rates, suiPrice] = await Promise.all([
|
|
67284
67156
|
client.getBalance({ owner: walletAddress, coinType: SUPPORTED_ASSETS.USDC.type }).catch(() => ({ totalBalance: "0" })),
|
|
67285
67157
|
client.getBalance({ owner: walletAddress, coinType: SUPPORTED_ASSETS.SUI.type }).catch(() => ({ totalBalance: "0" })),
|
|
67286
67158
|
getHealthFactor(client, walletAddress).catch(() => HF_FALLBACK),
|
|
67287
67159
|
getRates(client),
|
|
67288
|
-
fetchSuiPriceUsd(client)
|
|
67289
|
-
options.allowanceId ? getAllowanceBalance(client, options.allowanceId).catch(() => null) : Promise.resolve(null)
|
|
67160
|
+
fetchSuiPriceUsd(client)
|
|
67290
67161
|
]);
|
|
67291
67162
|
const usdcAvailable = Number(usdcBal.totalBalance) / 10 ** SUPPORTED_ASSETS.USDC.decimals;
|
|
67292
67163
|
const gasReserveSui = Number(suiBal.totalBalance) / Number(MIST_PER_SUI2);
|
|
@@ -67306,7 +67177,6 @@ async function getFinancialSummary(client, walletAddress, options = {}) {
|
|
|
67306
67177
|
dailyYield,
|
|
67307
67178
|
gasReserveSui,
|
|
67308
67179
|
gasReserveUsd: gasReserveSui * suiPrice,
|
|
67309
|
-
allowanceBalance: allowance,
|
|
67310
67180
|
fetchedAt: Date.now()
|
|
67311
67181
|
};
|
|
67312
67182
|
}
|
|
@@ -67415,58 +67285,6 @@ async function getSwapQuote(params) {
|
|
|
67415
67285
|
init_cetus_swap();
|
|
67416
67286
|
init_token_registry();
|
|
67417
67287
|
init_volo();
|
|
67418
|
-
var DEFAULT_TTL_MS = 6e4;
|
|
67419
|
-
async function buildScopedIntent(adminKeypair, params) {
|
|
67420
|
-
const now = Date.now();
|
|
67421
|
-
const nonceBytes = new Uint8Array(32);
|
|
67422
|
-
crypto.getRandomValues(nonceBytes);
|
|
67423
|
-
const nonce = Buffer.from(nonceBytes).toString("hex");
|
|
67424
|
-
const payload = {
|
|
67425
|
-
version: 1,
|
|
67426
|
-
userId: params.userId,
|
|
67427
|
-
walletAddress: params.walletAddress,
|
|
67428
|
-
allowanceObjectId: params.allowanceObjectId,
|
|
67429
|
-
featureCode: params.featureCode,
|
|
67430
|
-
maxAmount: params.maxAmount,
|
|
67431
|
-
issuedAt: now,
|
|
67432
|
-
expiresAt: now + (params.ttlMs ?? DEFAULT_TTL_MS),
|
|
67433
|
-
nonce
|
|
67434
|
-
};
|
|
67435
|
-
const message = canonicalIntentBytes(payload);
|
|
67436
|
-
const signature = await adminKeypair.sign(message);
|
|
67437
|
-
return {
|
|
67438
|
-
...payload,
|
|
67439
|
-
signature: Buffer.from(signature).toString("hex")
|
|
67440
|
-
};
|
|
67441
|
-
}
|
|
67442
|
-
async function verifyScopedIntent(intent, adminPublicKeyBytes) {
|
|
67443
|
-
if (Date.now() > intent.expiresAt) return false;
|
|
67444
|
-
const payload = {
|
|
67445
|
-
version: intent.version,
|
|
67446
|
-
userId: intent.userId,
|
|
67447
|
-
walletAddress: intent.walletAddress,
|
|
67448
|
-
allowanceObjectId: intent.allowanceObjectId,
|
|
67449
|
-
featureCode: intent.featureCode,
|
|
67450
|
-
maxAmount: intent.maxAmount,
|
|
67451
|
-
issuedAt: intent.issuedAt,
|
|
67452
|
-
expiresAt: intent.expiresAt,
|
|
67453
|
-
nonce: intent.nonce
|
|
67454
|
-
};
|
|
67455
|
-
const message = canonicalIntentBytes(payload);
|
|
67456
|
-
const signatureBytes = Buffer.from(intent.signature, "hex");
|
|
67457
|
-
try {
|
|
67458
|
-
const publicKey = new Ed25519PublicKey(adminPublicKeyBytes);
|
|
67459
|
-
return await publicKey.verify(message, signatureBytes);
|
|
67460
|
-
} catch {
|
|
67461
|
-
return false;
|
|
67462
|
-
}
|
|
67463
|
-
}
|
|
67464
|
-
function canonicalIntentBytes(payload) {
|
|
67465
|
-
const sorted = Object.fromEntries(
|
|
67466
|
-
Object.entries(payload).sort(([a], [b2]) => a.localeCompare(b2))
|
|
67467
|
-
);
|
|
67468
|
-
return new TextEncoder().encode(JSON.stringify(sorted));
|
|
67469
|
-
}
|
|
67470
67288
|
|
|
67471
67289
|
export {
|
|
67472
67290
|
mapWalletError,
|
|
@@ -67516,7 +67334,6 @@ export {
|
|
|
67516
67334
|
DEFAULT_NETWORK,
|
|
67517
67335
|
CETUS_USDC_SUI_POOL,
|
|
67518
67336
|
GAS_RESERVE_MIN,
|
|
67519
|
-
ALLOWANCE_FEATURES,
|
|
67520
67337
|
validateAddress,
|
|
67521
67338
|
truncateAddress,
|
|
67522
67339
|
generateKeypair,
|
|
@@ -67557,23 +67374,12 @@ export {
|
|
|
67557
67374
|
SafeguardEnforcer,
|
|
67558
67375
|
ContactManager,
|
|
67559
67376
|
T2000,
|
|
67560
|
-
buildCreateAllowanceTx,
|
|
67561
|
-
addDepositAllowanceTx,
|
|
67562
|
-
buildDepositAllowanceTx,
|
|
67563
|
-
buildAdminDepositAllowanceTx,
|
|
67564
|
-
buildDeductAllowanceTx,
|
|
67565
|
-
buildWithdrawAllowanceTx,
|
|
67566
|
-
buildWithdrawAmountAllowanceTx,
|
|
67567
|
-
getAllowance,
|
|
67568
|
-
getAllowanceBalance,
|
|
67569
67377
|
HF_WARN_THRESHOLD,
|
|
67570
67378
|
HF_CRITICAL_THRESHOLD,
|
|
67571
67379
|
getFinancialSummary,
|
|
67572
67380
|
simulateTransaction,
|
|
67573
67381
|
throwIfSimulationFailed,
|
|
67574
|
-
getSwapQuote
|
|
67575
|
-
buildScopedIntent,
|
|
67576
|
-
verifyScopedIntent
|
|
67382
|
+
getSwapQuote
|
|
67577
67383
|
};
|
|
67578
67384
|
/*! Bundled license information:
|
|
67579
67385
|
|
|
@@ -67627,4 +67433,4 @@ axios/dist/node/axios.cjs:
|
|
|
67627
67433
|
@scure/bip39/index.js:
|
|
67628
67434
|
(*! scure-bip39 - MIT License (c) 2022 Patricio Palladino, Paul Miller (paulmillr.com) *)
|
|
67629
67435
|
*/
|
|
67630
|
-
//# sourceMappingURL=chunk-
|
|
67436
|
+
//# sourceMappingURL=chunk-4YV63VD3.js.map
|