@t2000/sdk 0.22.3 → 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 +1 -0
- package/dist/adapters/index.cjs +3 -3
- package/dist/adapters/index.cjs.map +1 -1
- package/dist/adapters/index.d.cts +1 -1
- package/dist/adapters/index.d.ts +1 -1
- package/dist/adapters/index.js +3 -3
- package/dist/adapters/index.js.map +1 -1
- package/dist/browser.cjs +3 -3
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.d.cts +2 -2
- package/dist/browser.d.ts +2 -2
- package/dist/browser.js +3 -3
- package/dist/browser.js.map +1 -1
- package/dist/index.cjs +300 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +117 -6
- package/dist/index.d.ts +117 -6
- package/dist/index.js +280 -6
- package/dist/index.js.map +1 -1
- package/dist/{token-registry-bf_caDsv.d.cts → token-registry-BYEXDwjs.d.cts} +13 -2
- package/dist/{token-registry-DLEKjV8I.d.ts → token-registry-CX_RDDO_.d.ts} +13 -2
- package/dist/{types-XWEUAS-X.d.cts → types-D9NstGUu.d.cts} +75 -1
- package/dist/{types-XWEUAS-X.d.ts → types-D9NstGUu.d.ts} +75 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { EventEmitter } from 'eventemitter3';
|
|
2
2
|
import { SuiJsonRpcClient } from '@mysten/sui/jsonRpc';
|
|
3
3
|
import { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519';
|
|
4
|
-
import { T as T2000Error, am as SafeguardEnforcer, w as TransactionSigner, Z as ZkLoginProof, s as SupportedAsset } from './token-registry-
|
|
5
|
-
export { A as ALL_NAVI_ASSETS, a as AutoTopUpResult, B as BPS_DENOMINATOR,
|
|
4
|
+
import { T as T2000Error, am as SafeguardEnforcer, w as TransactionSigner, Z as ZkLoginProof, s as SupportedAsset, an as AllowanceFeature } from './token-registry-BYEXDwjs.cjs';
|
|
5
|
+
export { ao as ALLOWANCE_FEATURES, A as ALL_NAVI_ASSETS, a as AutoTopUpResult, B as BPS_DENOMINATOR, ap as CETUS_USDC_SUI_POOL, C as CLOCK_ID, b as COIN_REGISTRY, c as CoinMeta, D as DEFAULT_NETWORK, d as DEFAULT_SAFEGUARD_CONFIG, E as ETH_TYPE, F as FeeOperation, G as GAS_RESERVE_MIN, e as GasExecutionResult, f as GasRequestType, g as GasSponsorResponse, h as GasStatusResponse, I as IKA_TYPE, K as KeypairSigner, L as LOFI_TYPE, M as MANIFEST_TYPE, i as MIST_PER_SUI, N as NAVX_TYPE, aq as OPERATION_ASSETS, O as OUTBOUND_OPS, ar as Operation, P as ProtocolFeeInfo, S as STABLE_ASSETS, j as SUI_DECIMALS, k as SUI_TYPE, l as SUPPORTED_ASSETS, m as SafeguardConfig, n as SafeguardError, o as SafeguardErrorDetails, p as SafeguardRule, q as SimulationResult, r as StableAsset, t as T2000ErrorCode, u as T2000ErrorData, v as TOKEN_MAP, x as TxMetadata, U as USDC_DECIMALS, y as USDC_TYPE, z as USDE_TYPE, H as USDSUI_TYPE, J as USDT_TYPE, W as WAL_TYPE, Q as WBTC_TYPE, R as ZkLoginSigner, V as addCollectFeeToTx, as as assertAllowedAsset, X as calculateFee, Y as executeAutoTopUp, _ as executeWithGas, $ as formatAssetAmount, a0 as formatSui, a1 as formatUsd, a2 as getDecimals, a3 as getDecimalsForCoinType, a4 as getGasStatus, a5 as getTier, at as isAllowedAsset, a6 as isSupported, a7 as isTier1, a8 as isTier2, a9 as mapMoveAbortCode, aa as mapWalletError, ab as mistToSui, ac as rawToStable, ad as rawToUsdc, ae as resolveSymbol, af as resolveTokenType, ag as shouldAutoTopUp, au as simulateTransaction, ah as stableToRaw, ai as suiToMist, av as throwIfSimulationFailed, aj as truncateAddress, ak as usdcToRaw, al as validateAddress } from './token-registry-BYEXDwjs.cjs';
|
|
6
6
|
import { L as LendingAdapter, a as LendingRates } from './descriptors-Be4FAgN5.cjs';
|
|
7
7
|
export { A as AdapterCapability, b as AdapterPositions, c as AdapterTxResult, H as HealthInfo, P as ProtocolDescriptor, d as allDescriptors, n as naviDescriptor } from './descriptors-Be4FAgN5.cjs';
|
|
8
|
-
import { j as T2000Options, P as PayOptions, d as PayResult, k as StakeVSuiResult, U as UnstakeVSuiResult, l as SwapResult, m as SwapQuoteResult, i as SendResult, B as BalanceResponse, T as TransactionRecord, D as DepositInfo, S as SaveResult, W as WithdrawResult, c as MaxWithdrawResult, a as BorrowResult, h as RepayResult, M as MaxBorrowResult, H as HealthFactorResult, e as PendingReward, C as ClaimRewardsResult, g as PositionsResult, R as RatesResult, E as EarningsResult, F as FundStatusResult } from './types-
|
|
9
|
-
export { A as AssetRates, G as GasMethod, b as GasReserve, f as PositionEntry } from './types-
|
|
10
|
-
import { RouterDataV3 } from '@cetusprotocol/aggregator-sdk';
|
|
8
|
+
import { j as T2000Options, P as PayOptions, d as PayResult, k as StakeVSuiResult, U as UnstakeVSuiResult, l as SwapResult, m as SwapQuoteResult, i as SendResult, B as BalanceResponse, T as TransactionRecord, D as DepositInfo, n as PaymentRequest, S as SaveResult, W as WithdrawResult, c as MaxWithdrawResult, a as BorrowResult, h as RepayResult, M as MaxBorrowResult, H as HealthFactorResult, e as PendingReward, C as ClaimRewardsResult, g as PositionsResult, R as RatesResult, E as EarningsResult, F as FundStatusResult, o as AllowanceInfo, p as FinancialSummary } from './types-D9NstGUu.cjs';
|
|
9
|
+
export { q as AllowanceCreateResult, r as AllowanceDeductResult, s as AllowanceDepositResult, t as AllowanceWithdrawResult, A as AssetRates, G as GasMethod, b as GasReserve, u as HFAlertLevel, f as PositionEntry } from './types-D9NstGUu.cjs';
|
|
11
10
|
import { Transaction, TransactionObjectArgument } from '@mysten/sui/transactions';
|
|
11
|
+
import { RouterDataV3 } from '@cetusprotocol/aggregator-sdk';
|
|
12
12
|
export { NaviAdapter, ProtocolRegistry } from './adapters/index.cjs';
|
|
13
13
|
|
|
14
14
|
interface Contact {
|
|
@@ -136,6 +136,12 @@ declare class T2000 extends EventEmitter<T2000Events> {
|
|
|
136
136
|
}): Promise<TransactionRecord[]>;
|
|
137
137
|
transactionDetail(digest: string): Promise<TransactionRecord | null>;
|
|
138
138
|
deposit(): Promise<DepositInfo>;
|
|
139
|
+
receive(params?: {
|
|
140
|
+
amount?: number;
|
|
141
|
+
currency?: string;
|
|
142
|
+
memo?: string;
|
|
143
|
+
label?: string;
|
|
144
|
+
}): PaymentRequest;
|
|
139
145
|
exportKey(): string;
|
|
140
146
|
static fromZkLogin(opts: {
|
|
141
147
|
ephemeralKeypair: Ed25519Keypair;
|
|
@@ -203,6 +209,67 @@ declare function getAddress(keypair: Ed25519Keypair): string;
|
|
|
203
209
|
|
|
204
210
|
declare function solveHashcash(challenge: string): string;
|
|
205
211
|
|
|
212
|
+
interface CreateAllowanceOptions {
|
|
213
|
+
permittedFeatures?: bigint;
|
|
214
|
+
expiresAt?: bigint;
|
|
215
|
+
dailyLimit?: bigint;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Build a PTB that creates a new shared Allowance<USDC> for the signer.
|
|
219
|
+
*/
|
|
220
|
+
declare function buildCreateAllowanceTx(options?: CreateAllowanceOptions): Transaction;
|
|
221
|
+
/**
|
|
222
|
+
* Add an owner deposit call to an existing PTB.
|
|
223
|
+
* The caller must provide a coin reference (e.g. from `tx.splitCoins`).
|
|
224
|
+
*/
|
|
225
|
+
declare function addDepositAllowanceTx(tx: Transaction, allowanceId: string, paymentCoin: TransactionObjectArgument): void;
|
|
226
|
+
/**
|
|
227
|
+
* Build a standalone deposit PTB that splits `amount` (raw USDC) from
|
|
228
|
+
* the given USDC coin and deposits into the allowance.
|
|
229
|
+
*/
|
|
230
|
+
declare function buildDepositAllowanceTx(allowanceId: string, usdcCoin: string, amount: bigint): Transaction;
|
|
231
|
+
/**
|
|
232
|
+
* Build an admin-sponsored deposit PTB. Requires AdminCap in the signer's wallet.
|
|
233
|
+
*/
|
|
234
|
+
declare function buildAdminDepositAllowanceTx(allowanceId: string, usdcCoin: string, amount: bigint): Transaction;
|
|
235
|
+
/**
|
|
236
|
+
* Build a deduct PTB. Only callable by the AdminCap holder (server/cron).
|
|
237
|
+
* Enforces on-chain: feature permission, expiry, daily limit.
|
|
238
|
+
*/
|
|
239
|
+
declare function buildDeductAllowanceTx(allowanceId: string, amount: bigint, feature: AllowanceFeature): Transaction;
|
|
240
|
+
/**
|
|
241
|
+
* Build a full-withdrawal PTB. Returns entire remaining balance to the owner.
|
|
242
|
+
*/
|
|
243
|
+
declare function buildWithdrawAllowanceTx(allowanceId: string): Transaction;
|
|
244
|
+
/**
|
|
245
|
+
* Build a partial-withdrawal PTB. Returns `amount` (raw USDC) to the owner.
|
|
246
|
+
*/
|
|
247
|
+
declare function buildWithdrawAmountAllowanceTx(allowanceId: string, amount: bigint): Transaction;
|
|
248
|
+
/**
|
|
249
|
+
* Fetch the full allowance state from an on-chain Allowance<T> shared object.
|
|
250
|
+
*/
|
|
251
|
+
declare function getAllowance(client: SuiJsonRpcClient, allowanceId: string): Promise<AllowanceInfo>;
|
|
252
|
+
/**
|
|
253
|
+
* Shorthand: get just the USDC balance of an allowance.
|
|
254
|
+
*/
|
|
255
|
+
declare function getAllowanceBalance(client: SuiJsonRpcClient, allowanceId: string): Promise<bigint>;
|
|
256
|
+
|
|
257
|
+
declare const HF_WARN_THRESHOLD = 1.8;
|
|
258
|
+
declare const HF_CRITICAL_THRESHOLD = 1.3;
|
|
259
|
+
interface FinancialSummaryOptions {
|
|
260
|
+
allowanceId?: string;
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Fetch a complete financial snapshot for one wallet in parallel.
|
|
264
|
+
* Designed for the notification cron — one call returns everything
|
|
265
|
+
* a briefing, HF alert, or rate alert needs.
|
|
266
|
+
*
|
|
267
|
+
* Every sub-call has a fallback so a single RPC failure doesn't
|
|
268
|
+
* crash the entire batch. Callers can check individual zero values
|
|
269
|
+
* to detect degraded data.
|
|
270
|
+
*/
|
|
271
|
+
declare function getFinancialSummary(client: SuiJsonRpcClient, walletAddress: string, options?: FinancialSummaryOptions): Promise<FinancialSummary>;
|
|
272
|
+
|
|
206
273
|
declare function getRates(client: SuiJsonRpcClient): Promise<RatesResult>;
|
|
207
274
|
|
|
208
275
|
declare function getSwapQuote(params: {
|
|
@@ -275,4 +342,48 @@ declare function buildStakeVSuiTx(_client: SuiJsonRpcClient, address: string, am
|
|
|
275
342
|
*/
|
|
276
343
|
declare function buildUnstakeVSuiTx(client: SuiJsonRpcClient, address: string, amountMist: bigint | 'all'): Promise<Transaction>;
|
|
277
344
|
|
|
278
|
-
|
|
345
|
+
/**
|
|
346
|
+
* Short-lived signed authorization for a single autonomous cron execution.
|
|
347
|
+
* Built off-chain, verified off-chain before any on-chain PTB is constructed.
|
|
348
|
+
*
|
|
349
|
+
* Security properties:
|
|
350
|
+
* - 60s TTL (configurable) — expired intents rejected before execution
|
|
351
|
+
* - Single-use nonce — stored in IntentLog, duplicate rejected immediately
|
|
352
|
+
* - Ed25519 signature by admin key — tamper-proof envelope
|
|
353
|
+
* - maxAmount ceiling — PTB builder must not exceed this
|
|
354
|
+
*/
|
|
355
|
+
interface ScopedIntent {
|
|
356
|
+
version: 1;
|
|
357
|
+
userId: string;
|
|
358
|
+
walletAddress: string;
|
|
359
|
+
allowanceObjectId: string;
|
|
360
|
+
featureCode: AllowanceFeature;
|
|
361
|
+
maxAmount: number;
|
|
362
|
+
issuedAt: number;
|
|
363
|
+
expiresAt: number;
|
|
364
|
+
nonce: string;
|
|
365
|
+
signature: string;
|
|
366
|
+
}
|
|
367
|
+
type ScopedIntentPayload = Omit<ScopedIntent, 'signature'>;
|
|
368
|
+
|
|
369
|
+
interface BuildIntentParams {
|
|
370
|
+
userId: string;
|
|
371
|
+
walletAddress: string;
|
|
372
|
+
allowanceObjectId: string;
|
|
373
|
+
featureCode: AllowanceFeature;
|
|
374
|
+
maxAmount: number;
|
|
375
|
+
ttlMs?: number;
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* Build a ScopedIntent signed by the admin keypair.
|
|
379
|
+
* Generates a cryptographically random 32-byte nonce and signs the canonical payload.
|
|
380
|
+
*/
|
|
381
|
+
declare function buildScopedIntent(adminKeypair: Ed25519Keypair, params: BuildIntentParams): Promise<ScopedIntent>;
|
|
382
|
+
/**
|
|
383
|
+
* Verify a ScopedIntent:
|
|
384
|
+
* 1. Check TTL — reject expired intents immediately (fast path)
|
|
385
|
+
* 2. Verify Ed25519 signature over canonical payload
|
|
386
|
+
*/
|
|
387
|
+
declare function verifyScopedIntent(intent: ScopedIntent, adminPublicKeyBytes: Uint8Array): Promise<boolean>;
|
|
388
|
+
|
|
389
|
+
export { AllowanceFeature, AllowanceInfo, BalanceResponse, BorrowResult, type BuildIntentParams, ClaimRewardsResult, ContactManager, DepositInfo, EarningsResult, FinancialSummary, type FinancialSummaryOptions, FundStatusResult, HF_CRITICAL_THRESHOLD, HF_WARN_THRESHOLD, HealthFactorResult, LendingAdapter, LendingRates, MaxBorrowResult, MaxWithdrawResult, PayOptions, PayResult, PaymentRequest, PendingReward, PositionsResult, RatesResult, RepayResult, SafeguardEnforcer, SaveResult, type ScopedIntent, type ScopedIntentPayload, SendResult, StakeVSuiResult, SupportedAsset, SwapQuoteResult, SwapResult, type SwapRouteResult, T2000, T2000Error, T2000Options, TransactionRecord, TransactionSigner, UnstakeVSuiResult, VOLO_METADATA, VOLO_PKG, VOLO_POOL, VSUI_TYPE, type VoloStats, WithdrawResult, ZkLoginProof, addDepositAllowanceTx, buildAdminDepositAllowanceTx, buildCreateAllowanceTx, buildDeductAllowanceTx, buildDepositAllowanceTx, buildScopedIntent, buildStakeVSuiTx, buildSwapTx, buildUnstakeVSuiTx, buildWithdrawAllowanceTx, buildWithdrawAmountAllowanceTx, exportPrivateKey, findSwapRoute, generateKeypair, getAddress, getAllowance, getAllowanceBalance, getFinancialSummary, getRates, getSwapQuote, getVoloStats, keypairFromPrivateKey, loadKey, saveKey, solveHashcash, verifyScopedIntent, walletExists };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { EventEmitter } from 'eventemitter3';
|
|
2
2
|
import { SuiJsonRpcClient } from '@mysten/sui/jsonRpc';
|
|
3
3
|
import { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519';
|
|
4
|
-
import { T as T2000Error, am as SafeguardEnforcer, w as TransactionSigner, Z as ZkLoginProof, s as SupportedAsset } from './token-registry-
|
|
5
|
-
export { A as ALL_NAVI_ASSETS, a as AutoTopUpResult, B as BPS_DENOMINATOR,
|
|
4
|
+
import { T as T2000Error, am as SafeguardEnforcer, w as TransactionSigner, Z as ZkLoginProof, s as SupportedAsset, an as AllowanceFeature } from './token-registry-CX_RDDO_.js';
|
|
5
|
+
export { ao as ALLOWANCE_FEATURES, A as ALL_NAVI_ASSETS, a as AutoTopUpResult, B as BPS_DENOMINATOR, ap as CETUS_USDC_SUI_POOL, C as CLOCK_ID, b as COIN_REGISTRY, c as CoinMeta, D as DEFAULT_NETWORK, d as DEFAULT_SAFEGUARD_CONFIG, E as ETH_TYPE, F as FeeOperation, G as GAS_RESERVE_MIN, e as GasExecutionResult, f as GasRequestType, g as GasSponsorResponse, h as GasStatusResponse, I as IKA_TYPE, K as KeypairSigner, L as LOFI_TYPE, M as MANIFEST_TYPE, i as MIST_PER_SUI, N as NAVX_TYPE, aq as OPERATION_ASSETS, O as OUTBOUND_OPS, ar as Operation, P as ProtocolFeeInfo, S as STABLE_ASSETS, j as SUI_DECIMALS, k as SUI_TYPE, l as SUPPORTED_ASSETS, m as SafeguardConfig, n as SafeguardError, o as SafeguardErrorDetails, p as SafeguardRule, q as SimulationResult, r as StableAsset, t as T2000ErrorCode, u as T2000ErrorData, v as TOKEN_MAP, x as TxMetadata, U as USDC_DECIMALS, y as USDC_TYPE, z as USDE_TYPE, H as USDSUI_TYPE, J as USDT_TYPE, W as WAL_TYPE, Q as WBTC_TYPE, R as ZkLoginSigner, V as addCollectFeeToTx, as as assertAllowedAsset, X as calculateFee, Y as executeAutoTopUp, _ as executeWithGas, $ as formatAssetAmount, a0 as formatSui, a1 as formatUsd, a2 as getDecimals, a3 as getDecimalsForCoinType, a4 as getGasStatus, a5 as getTier, at as isAllowedAsset, a6 as isSupported, a7 as isTier1, a8 as isTier2, a9 as mapMoveAbortCode, aa as mapWalletError, ab as mistToSui, ac as rawToStable, ad as rawToUsdc, ae as resolveSymbol, af as resolveTokenType, ag as shouldAutoTopUp, au as simulateTransaction, ah as stableToRaw, ai as suiToMist, av as throwIfSimulationFailed, aj as truncateAddress, ak as usdcToRaw, al as validateAddress } from './token-registry-CX_RDDO_.js';
|
|
6
6
|
import { L as LendingAdapter, a as LendingRates } from './descriptors-Be4FAgN5.js';
|
|
7
7
|
export { A as AdapterCapability, b as AdapterPositions, c as AdapterTxResult, H as HealthInfo, P as ProtocolDescriptor, d as allDescriptors, n as naviDescriptor } from './descriptors-Be4FAgN5.js';
|
|
8
|
-
import { j as T2000Options, P as PayOptions, d as PayResult, k as StakeVSuiResult, U as UnstakeVSuiResult, l as SwapResult, m as SwapQuoteResult, i as SendResult, B as BalanceResponse, T as TransactionRecord, D as DepositInfo, S as SaveResult, W as WithdrawResult, c as MaxWithdrawResult, a as BorrowResult, h as RepayResult, M as MaxBorrowResult, H as HealthFactorResult, e as PendingReward, C as ClaimRewardsResult, g as PositionsResult, R as RatesResult, E as EarningsResult, F as FundStatusResult } from './types-
|
|
9
|
-
export { A as AssetRates, G as GasMethod, b as GasReserve, f as PositionEntry } from './types-
|
|
10
|
-
import { RouterDataV3 } from '@cetusprotocol/aggregator-sdk';
|
|
8
|
+
import { j as T2000Options, P as PayOptions, d as PayResult, k as StakeVSuiResult, U as UnstakeVSuiResult, l as SwapResult, m as SwapQuoteResult, i as SendResult, B as BalanceResponse, T as TransactionRecord, D as DepositInfo, n as PaymentRequest, S as SaveResult, W as WithdrawResult, c as MaxWithdrawResult, a as BorrowResult, h as RepayResult, M as MaxBorrowResult, H as HealthFactorResult, e as PendingReward, C as ClaimRewardsResult, g as PositionsResult, R as RatesResult, E as EarningsResult, F as FundStatusResult, o as AllowanceInfo, p as FinancialSummary } from './types-D9NstGUu.js';
|
|
9
|
+
export { q as AllowanceCreateResult, r as AllowanceDeductResult, s as AllowanceDepositResult, t as AllowanceWithdrawResult, A as AssetRates, G as GasMethod, b as GasReserve, u as HFAlertLevel, f as PositionEntry } from './types-D9NstGUu.js';
|
|
11
10
|
import { Transaction, TransactionObjectArgument } from '@mysten/sui/transactions';
|
|
11
|
+
import { RouterDataV3 } from '@cetusprotocol/aggregator-sdk';
|
|
12
12
|
export { NaviAdapter, ProtocolRegistry } from './adapters/index.js';
|
|
13
13
|
|
|
14
14
|
interface Contact {
|
|
@@ -136,6 +136,12 @@ declare class T2000 extends EventEmitter<T2000Events> {
|
|
|
136
136
|
}): Promise<TransactionRecord[]>;
|
|
137
137
|
transactionDetail(digest: string): Promise<TransactionRecord | null>;
|
|
138
138
|
deposit(): Promise<DepositInfo>;
|
|
139
|
+
receive(params?: {
|
|
140
|
+
amount?: number;
|
|
141
|
+
currency?: string;
|
|
142
|
+
memo?: string;
|
|
143
|
+
label?: string;
|
|
144
|
+
}): PaymentRequest;
|
|
139
145
|
exportKey(): string;
|
|
140
146
|
static fromZkLogin(opts: {
|
|
141
147
|
ephemeralKeypair: Ed25519Keypair;
|
|
@@ -203,6 +209,67 @@ declare function getAddress(keypair: Ed25519Keypair): string;
|
|
|
203
209
|
|
|
204
210
|
declare function solveHashcash(challenge: string): string;
|
|
205
211
|
|
|
212
|
+
interface CreateAllowanceOptions {
|
|
213
|
+
permittedFeatures?: bigint;
|
|
214
|
+
expiresAt?: bigint;
|
|
215
|
+
dailyLimit?: bigint;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Build a PTB that creates a new shared Allowance<USDC> for the signer.
|
|
219
|
+
*/
|
|
220
|
+
declare function buildCreateAllowanceTx(options?: CreateAllowanceOptions): Transaction;
|
|
221
|
+
/**
|
|
222
|
+
* Add an owner deposit call to an existing PTB.
|
|
223
|
+
* The caller must provide a coin reference (e.g. from `tx.splitCoins`).
|
|
224
|
+
*/
|
|
225
|
+
declare function addDepositAllowanceTx(tx: Transaction, allowanceId: string, paymentCoin: TransactionObjectArgument): void;
|
|
226
|
+
/**
|
|
227
|
+
* Build a standalone deposit PTB that splits `amount` (raw USDC) from
|
|
228
|
+
* the given USDC coin and deposits into the allowance.
|
|
229
|
+
*/
|
|
230
|
+
declare function buildDepositAllowanceTx(allowanceId: string, usdcCoin: string, amount: bigint): Transaction;
|
|
231
|
+
/**
|
|
232
|
+
* Build an admin-sponsored deposit PTB. Requires AdminCap in the signer's wallet.
|
|
233
|
+
*/
|
|
234
|
+
declare function buildAdminDepositAllowanceTx(allowanceId: string, usdcCoin: string, amount: bigint): Transaction;
|
|
235
|
+
/**
|
|
236
|
+
* Build a deduct PTB. Only callable by the AdminCap holder (server/cron).
|
|
237
|
+
* Enforces on-chain: feature permission, expiry, daily limit.
|
|
238
|
+
*/
|
|
239
|
+
declare function buildDeductAllowanceTx(allowanceId: string, amount: bigint, feature: AllowanceFeature): Transaction;
|
|
240
|
+
/**
|
|
241
|
+
* Build a full-withdrawal PTB. Returns entire remaining balance to the owner.
|
|
242
|
+
*/
|
|
243
|
+
declare function buildWithdrawAllowanceTx(allowanceId: string): Transaction;
|
|
244
|
+
/**
|
|
245
|
+
* Build a partial-withdrawal PTB. Returns `amount` (raw USDC) to the owner.
|
|
246
|
+
*/
|
|
247
|
+
declare function buildWithdrawAmountAllowanceTx(allowanceId: string, amount: bigint): Transaction;
|
|
248
|
+
/**
|
|
249
|
+
* Fetch the full allowance state from an on-chain Allowance<T> shared object.
|
|
250
|
+
*/
|
|
251
|
+
declare function getAllowance(client: SuiJsonRpcClient, allowanceId: string): Promise<AllowanceInfo>;
|
|
252
|
+
/**
|
|
253
|
+
* Shorthand: get just the USDC balance of an allowance.
|
|
254
|
+
*/
|
|
255
|
+
declare function getAllowanceBalance(client: SuiJsonRpcClient, allowanceId: string): Promise<bigint>;
|
|
256
|
+
|
|
257
|
+
declare const HF_WARN_THRESHOLD = 1.8;
|
|
258
|
+
declare const HF_CRITICAL_THRESHOLD = 1.3;
|
|
259
|
+
interface FinancialSummaryOptions {
|
|
260
|
+
allowanceId?: string;
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Fetch a complete financial snapshot for one wallet in parallel.
|
|
264
|
+
* Designed for the notification cron — one call returns everything
|
|
265
|
+
* a briefing, HF alert, or rate alert needs.
|
|
266
|
+
*
|
|
267
|
+
* Every sub-call has a fallback so a single RPC failure doesn't
|
|
268
|
+
* crash the entire batch. Callers can check individual zero values
|
|
269
|
+
* to detect degraded data.
|
|
270
|
+
*/
|
|
271
|
+
declare function getFinancialSummary(client: SuiJsonRpcClient, walletAddress: string, options?: FinancialSummaryOptions): Promise<FinancialSummary>;
|
|
272
|
+
|
|
206
273
|
declare function getRates(client: SuiJsonRpcClient): Promise<RatesResult>;
|
|
207
274
|
|
|
208
275
|
declare function getSwapQuote(params: {
|
|
@@ -275,4 +342,48 @@ declare function buildStakeVSuiTx(_client: SuiJsonRpcClient, address: string, am
|
|
|
275
342
|
*/
|
|
276
343
|
declare function buildUnstakeVSuiTx(client: SuiJsonRpcClient, address: string, amountMist: bigint | 'all'): Promise<Transaction>;
|
|
277
344
|
|
|
278
|
-
|
|
345
|
+
/**
|
|
346
|
+
* Short-lived signed authorization for a single autonomous cron execution.
|
|
347
|
+
* Built off-chain, verified off-chain before any on-chain PTB is constructed.
|
|
348
|
+
*
|
|
349
|
+
* Security properties:
|
|
350
|
+
* - 60s TTL (configurable) — expired intents rejected before execution
|
|
351
|
+
* - Single-use nonce — stored in IntentLog, duplicate rejected immediately
|
|
352
|
+
* - Ed25519 signature by admin key — tamper-proof envelope
|
|
353
|
+
* - maxAmount ceiling — PTB builder must not exceed this
|
|
354
|
+
*/
|
|
355
|
+
interface ScopedIntent {
|
|
356
|
+
version: 1;
|
|
357
|
+
userId: string;
|
|
358
|
+
walletAddress: string;
|
|
359
|
+
allowanceObjectId: string;
|
|
360
|
+
featureCode: AllowanceFeature;
|
|
361
|
+
maxAmount: number;
|
|
362
|
+
issuedAt: number;
|
|
363
|
+
expiresAt: number;
|
|
364
|
+
nonce: string;
|
|
365
|
+
signature: string;
|
|
366
|
+
}
|
|
367
|
+
type ScopedIntentPayload = Omit<ScopedIntent, 'signature'>;
|
|
368
|
+
|
|
369
|
+
interface BuildIntentParams {
|
|
370
|
+
userId: string;
|
|
371
|
+
walletAddress: string;
|
|
372
|
+
allowanceObjectId: string;
|
|
373
|
+
featureCode: AllowanceFeature;
|
|
374
|
+
maxAmount: number;
|
|
375
|
+
ttlMs?: number;
|
|
376
|
+
}
|
|
377
|
+
/**
|
|
378
|
+
* Build a ScopedIntent signed by the admin keypair.
|
|
379
|
+
* Generates a cryptographically random 32-byte nonce and signs the canonical payload.
|
|
380
|
+
*/
|
|
381
|
+
declare function buildScopedIntent(adminKeypair: Ed25519Keypair, params: BuildIntentParams): Promise<ScopedIntent>;
|
|
382
|
+
/**
|
|
383
|
+
* Verify a ScopedIntent:
|
|
384
|
+
* 1. Check TTL — reject expired intents immediately (fast path)
|
|
385
|
+
* 2. Verify Ed25519 signature over canonical payload
|
|
386
|
+
*/
|
|
387
|
+
declare function verifyScopedIntent(intent: ScopedIntent, adminPublicKeyBytes: Uint8Array): Promise<boolean>;
|
|
388
|
+
|
|
389
|
+
export { AllowanceFeature, AllowanceInfo, BalanceResponse, BorrowResult, type BuildIntentParams, ClaimRewardsResult, ContactManager, DepositInfo, EarningsResult, FinancialSummary, type FinancialSummaryOptions, FundStatusResult, HF_CRITICAL_THRESHOLD, HF_WARN_THRESHOLD, HealthFactorResult, LendingAdapter, LendingRates, MaxBorrowResult, MaxWithdrawResult, PayOptions, PayResult, PaymentRequest, PendingReward, PositionsResult, RatesResult, RepayResult, SafeguardEnforcer, SaveResult, type ScopedIntent, type ScopedIntentPayload, SendResult, StakeVSuiResult, SupportedAsset, SwapQuoteResult, SwapResult, type SwapRouteResult, T2000, T2000Error, T2000Options, TransactionRecord, TransactionSigner, UnstakeVSuiResult, VOLO_METADATA, VOLO_PKG, VOLO_POOL, VSUI_TYPE, type VoloStats, WithdrawResult, ZkLoginProof, addDepositAllowanceTx, buildAdminDepositAllowanceTx, buildCreateAllowanceTx, buildDeductAllowanceTx, buildDepositAllowanceTx, buildScopedIntent, buildStakeVSuiTx, buildSwapTx, buildUnstakeVSuiTx, buildWithdrawAllowanceTx, buildWithdrawAmountAllowanceTx, exportPrivateKey, findSwapRoute, generateKeypair, getAddress, getAllowance, getAllowanceBalance, getFinancialSummary, getRates, getSwapQuote, getVoloStats, keypairFromPrivateKey, loadKey, saveKey, solveHashcash, verifyScopedIntent, walletExists };
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@ import { AggregatorClient, Env } from '@cetusprotocol/aggregator-sdk';
|
|
|
3
3
|
import { EventEmitter } from 'eventemitter3';
|
|
4
4
|
import { SuiJsonRpcClient } from '@mysten/sui/jsonRpc';
|
|
5
5
|
import { normalizeSuiAddress, isValidSuiAddress } from '@mysten/sui/utils';
|
|
6
|
-
import { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519';
|
|
6
|
+
import { Ed25519Keypair, Ed25519PublicKey } from '@mysten/sui/keypairs/ed25519';
|
|
7
7
|
import { decodeSuiPrivateKey } from '@mysten/sui/cryptography';
|
|
8
8
|
import { createHash, randomBytes, createCipheriv, createDecipheriv, scryptSync } from 'crypto';
|
|
9
9
|
import { access, mkdir, writeFile, readFile } from 'fs/promises';
|
|
@@ -488,15 +488,27 @@ function assertAllowedAsset(op, asset) {
|
|
|
488
488
|
);
|
|
489
489
|
}
|
|
490
490
|
}
|
|
491
|
-
var T2000_PACKAGE_ID = process.env.T2000_PACKAGE_ID ?? "
|
|
492
|
-
var T2000_CONFIG_ID = process.env.T2000_CONFIG_ID ?? "
|
|
493
|
-
var
|
|
491
|
+
var T2000_PACKAGE_ID = process.env.T2000_PACKAGE_ID ?? "0xd775fcc66eae26797654d435d751dea56b82eeb999de51fd285348e573b968ad";
|
|
492
|
+
var T2000_CONFIG_ID = process.env.T2000_CONFIG_ID ?? "0x08ba26f0d260b5edf6a19c71492b3eb914906a7419baf2df1426765157e5862a";
|
|
493
|
+
var T2000_ADMIN_CAP_ID = "0xa97bfff140f5a2c268a03fe5422d382c228057deb7bcfdaf2967ca18b9bdbbd9";
|
|
494
|
+
var T2000_TREASURY_ID = process.env.T2000_TREASURY_ID ?? "0xf420ec0dcad44433042fb56e1413fb88d3ff65be94fcf425ef9ff750164590e8";
|
|
494
495
|
var DEFAULT_NETWORK = "mainnet";
|
|
495
496
|
var DEFAULT_RPC_URL = "https://fullnode.mainnet.sui.io:443";
|
|
496
497
|
var DEFAULT_KEY_PATH = "~/.t2000/wallet.key";
|
|
497
498
|
var API_BASE_URL = process.env.T2000_API_URL ?? "https://api.t2000.ai";
|
|
498
499
|
var CETUS_USDC_SUI_POOL = "0x51e883ba7c0b566a26cbc8a94cd33eb0abd418a77cc1e60ad22fd9b1f29cd2ab";
|
|
499
500
|
var GAS_RESERVE_MIN = 0.05;
|
|
501
|
+
var ALLOWANCE_FEATURES = {
|
|
502
|
+
BRIEFING: 0,
|
|
503
|
+
YIELD_ALERT: 1,
|
|
504
|
+
PAYMENT_ALERT: 2,
|
|
505
|
+
ACTION_REMIND: 3,
|
|
506
|
+
SESSION: 4,
|
|
507
|
+
AUTO_COMPOUND: 5,
|
|
508
|
+
DCA: 6,
|
|
509
|
+
HF_ALERT: 7
|
|
510
|
+
};
|
|
511
|
+
var FEATURES_ALL = 255;
|
|
500
512
|
|
|
501
513
|
// src/utils/sui.ts
|
|
502
514
|
init_errors();
|
|
@@ -889,7 +901,7 @@ function extractCommands(txBlock) {
|
|
|
889
901
|
if (!data || typeof data !== "object") return result;
|
|
890
902
|
const inner = "transaction" in data ? data.transaction : void 0;
|
|
891
903
|
if (!inner || typeof inner !== "object") return result;
|
|
892
|
-
const commands = "commands" in inner ? inner.commands : void 0;
|
|
904
|
+
const commands = "commands" in inner ? inner.commands : "transactions" in inner ? inner.transactions : void 0;
|
|
893
905
|
if (!Array.isArray(commands)) return result;
|
|
894
906
|
for (const cmd of commands) {
|
|
895
907
|
if (cmd.MoveCall) {
|
|
@@ -2615,6 +2627,32 @@ var T2000 = class _T2000 extends EventEmitter {
|
|
|
2615
2627
|
].join("\n")
|
|
2616
2628
|
};
|
|
2617
2629
|
}
|
|
2630
|
+
receive(params) {
|
|
2631
|
+
const amount = params?.amount ?? null;
|
|
2632
|
+
const currency = params?.currency ?? "USDC";
|
|
2633
|
+
const memo = params?.memo ?? null;
|
|
2634
|
+
const label = params?.label ?? null;
|
|
2635
|
+
const qrParts = [`sui:${this._address}`];
|
|
2636
|
+
const queryParams = [];
|
|
2637
|
+
if (amount != null) queryParams.push(`amount=${amount}`);
|
|
2638
|
+
if (currency !== "SUI") queryParams.push(`currency=${currency}`);
|
|
2639
|
+
if (memo) queryParams.push(`memo=${encodeURIComponent(memo)}`);
|
|
2640
|
+
if (label) queryParams.push(`label=${encodeURIComponent(label)}`);
|
|
2641
|
+
const qrUri = queryParams.length > 0 ? `${qrParts[0]}?${queryParams.join("&")}` : qrParts[0];
|
|
2642
|
+
const amountStr = amount != null ? `$${amount.toFixed(2)} ` : "";
|
|
2643
|
+
const displayParts = [`Send ${amountStr}${currency} to ${truncateAddress(this._address)}`];
|
|
2644
|
+
if (memo) displayParts.push(`Memo: ${memo}`);
|
|
2645
|
+
return {
|
|
2646
|
+
address: this._address,
|
|
2647
|
+
network: "mainnet",
|
|
2648
|
+
amount,
|
|
2649
|
+
currency,
|
|
2650
|
+
memo,
|
|
2651
|
+
label,
|
|
2652
|
+
qrUri,
|
|
2653
|
+
displayText: displayParts.join("\n")
|
|
2654
|
+
};
|
|
2655
|
+
}
|
|
2618
2656
|
exportKey() {
|
|
2619
2657
|
return exportPrivateKey(this.keypair);
|
|
2620
2658
|
}
|
|
@@ -3261,6 +3299,190 @@ async function callUsdcSponsorApi(address) {
|
|
|
3261
3299
|
|
|
3262
3300
|
// src/index.ts
|
|
3263
3301
|
init_errors();
|
|
3302
|
+
var USDC_TYPE2 = SUPPORTED_ASSETS.USDC.type;
|
|
3303
|
+
function buildCreateAllowanceTx(options = {}) {
|
|
3304
|
+
const tx = new Transaction();
|
|
3305
|
+
tx.moveCall({
|
|
3306
|
+
target: `${T2000_PACKAGE_ID}::allowance::create`,
|
|
3307
|
+
typeArguments: [USDC_TYPE2],
|
|
3308
|
+
arguments: [
|
|
3309
|
+
tx.pure.u64(options.permittedFeatures ?? BigInt(FEATURES_ALL)),
|
|
3310
|
+
tx.pure.u64(options.expiresAt ?? 0n),
|
|
3311
|
+
tx.pure.u64(options.dailyLimit ?? 0n),
|
|
3312
|
+
tx.object(CLOCK_ID)
|
|
3313
|
+
]
|
|
3314
|
+
});
|
|
3315
|
+
return tx;
|
|
3316
|
+
}
|
|
3317
|
+
function addDepositAllowanceTx(tx, allowanceId, paymentCoin) {
|
|
3318
|
+
tx.moveCall({
|
|
3319
|
+
target: `${T2000_PACKAGE_ID}::allowance::deposit`,
|
|
3320
|
+
typeArguments: [USDC_TYPE2],
|
|
3321
|
+
arguments: [tx.object(allowanceId), paymentCoin]
|
|
3322
|
+
});
|
|
3323
|
+
}
|
|
3324
|
+
function buildDepositAllowanceTx(allowanceId, usdcCoin, amount) {
|
|
3325
|
+
const tx = new Transaction();
|
|
3326
|
+
const [split] = tx.splitCoins(tx.object(usdcCoin), [tx.pure.u64(amount)]);
|
|
3327
|
+
addDepositAllowanceTx(tx, allowanceId, split);
|
|
3328
|
+
return tx;
|
|
3329
|
+
}
|
|
3330
|
+
function buildAdminDepositAllowanceTx(allowanceId, usdcCoin, amount) {
|
|
3331
|
+
const tx = new Transaction();
|
|
3332
|
+
const [split] = tx.splitCoins(tx.object(usdcCoin), [tx.pure.u64(amount)]);
|
|
3333
|
+
tx.moveCall({
|
|
3334
|
+
target: `${T2000_PACKAGE_ID}::allowance::admin_deposit`,
|
|
3335
|
+
typeArguments: [USDC_TYPE2],
|
|
3336
|
+
arguments: [
|
|
3337
|
+
tx.object(allowanceId),
|
|
3338
|
+
tx.object(T2000_ADMIN_CAP_ID),
|
|
3339
|
+
split
|
|
3340
|
+
]
|
|
3341
|
+
});
|
|
3342
|
+
return tx;
|
|
3343
|
+
}
|
|
3344
|
+
function buildDeductAllowanceTx(allowanceId, amount, feature) {
|
|
3345
|
+
const tx = new Transaction();
|
|
3346
|
+
tx.moveCall({
|
|
3347
|
+
target: `${T2000_PACKAGE_ID}::allowance::deduct`,
|
|
3348
|
+
typeArguments: [USDC_TYPE2],
|
|
3349
|
+
arguments: [
|
|
3350
|
+
tx.object(allowanceId),
|
|
3351
|
+
tx.object(T2000_CONFIG_ID),
|
|
3352
|
+
tx.object(T2000_ADMIN_CAP_ID),
|
|
3353
|
+
tx.pure.u64(amount),
|
|
3354
|
+
tx.pure.u8(feature),
|
|
3355
|
+
tx.object(CLOCK_ID)
|
|
3356
|
+
]
|
|
3357
|
+
});
|
|
3358
|
+
return tx;
|
|
3359
|
+
}
|
|
3360
|
+
function buildWithdrawAllowanceTx(allowanceId) {
|
|
3361
|
+
const tx = new Transaction();
|
|
3362
|
+
tx.moveCall({
|
|
3363
|
+
target: `${T2000_PACKAGE_ID}::allowance::withdraw`,
|
|
3364
|
+
typeArguments: [USDC_TYPE2],
|
|
3365
|
+
arguments: [tx.object(allowanceId)]
|
|
3366
|
+
});
|
|
3367
|
+
return tx;
|
|
3368
|
+
}
|
|
3369
|
+
function buildWithdrawAmountAllowanceTx(allowanceId, amount) {
|
|
3370
|
+
const tx = new Transaction();
|
|
3371
|
+
tx.moveCall({
|
|
3372
|
+
target: `${T2000_PACKAGE_ID}::allowance::withdraw_amount`,
|
|
3373
|
+
typeArguments: [USDC_TYPE2],
|
|
3374
|
+
arguments: [tx.object(allowanceId), tx.pure.u64(amount)]
|
|
3375
|
+
});
|
|
3376
|
+
return tx;
|
|
3377
|
+
}
|
|
3378
|
+
async function getAllowance(client, allowanceId) {
|
|
3379
|
+
const obj = await client.getObject({
|
|
3380
|
+
id: allowanceId,
|
|
3381
|
+
options: { showContent: true, showType: true }
|
|
3382
|
+
});
|
|
3383
|
+
if (!obj.data?.content || obj.data.content.dataType !== "moveObject") {
|
|
3384
|
+
throw new Error(`Allowance ${allowanceId} not found or is not a Move object`);
|
|
3385
|
+
}
|
|
3386
|
+
const fields = obj.data.content.fields;
|
|
3387
|
+
const coinType = extractCoinType(obj.data.content.type);
|
|
3388
|
+
return {
|
|
3389
|
+
id: allowanceId,
|
|
3390
|
+
owner: fields.owner,
|
|
3391
|
+
balance: parseU64Field(fields.balance),
|
|
3392
|
+
totalDeposited: parseU64Field(fields.total_deposited),
|
|
3393
|
+
totalSpent: parseU64Field(fields.total_spent),
|
|
3394
|
+
createdAt: Number(fields.created_at),
|
|
3395
|
+
coinType,
|
|
3396
|
+
permittedFeatures: parseU64Field(fields.permitted_features),
|
|
3397
|
+
expiresAt: Number(fields.expires_at),
|
|
3398
|
+
dailyLimit: parseU64Field(fields.daily_limit),
|
|
3399
|
+
dailySpent: parseU64Field(fields.daily_spent),
|
|
3400
|
+
windowStart: Number(fields.window_start)
|
|
3401
|
+
};
|
|
3402
|
+
}
|
|
3403
|
+
async function getAllowanceBalance(client, allowanceId) {
|
|
3404
|
+
const info = await getAllowance(client, allowanceId);
|
|
3405
|
+
return info.balance;
|
|
3406
|
+
}
|
|
3407
|
+
function parseU64Field(raw) {
|
|
3408
|
+
if (typeof raw === "string" || typeof raw === "number") return BigInt(raw);
|
|
3409
|
+
if (typeof raw === "object" && raw !== null && "value" in raw) {
|
|
3410
|
+
return BigInt(raw.value);
|
|
3411
|
+
}
|
|
3412
|
+
return 0n;
|
|
3413
|
+
}
|
|
3414
|
+
function extractCoinType(objectType) {
|
|
3415
|
+
const match = objectType.match(/<(.+)>/);
|
|
3416
|
+
return match ? match[1] : "unknown";
|
|
3417
|
+
}
|
|
3418
|
+
|
|
3419
|
+
// src/protocols/financialSummary.ts
|
|
3420
|
+
var HF_WARN_THRESHOLD = 1.8;
|
|
3421
|
+
var HF_CRITICAL_THRESHOLD = 1.3;
|
|
3422
|
+
var HF_FALLBACK = {
|
|
3423
|
+
healthFactor: Infinity,
|
|
3424
|
+
supplied: 0,
|
|
3425
|
+
borrowed: 0,
|
|
3426
|
+
maxBorrow: 0,
|
|
3427
|
+
liquidationThreshold: 0.75
|
|
3428
|
+
};
|
|
3429
|
+
function classifyHF(hf, hasBorrow) {
|
|
3430
|
+
if (!hasBorrow || !Number.isFinite(hf)) return "none";
|
|
3431
|
+
if (hf <= HF_CRITICAL_THRESHOLD) return "critical";
|
|
3432
|
+
if (hf <= HF_WARN_THRESHOLD) return "warn";
|
|
3433
|
+
return "none";
|
|
3434
|
+
}
|
|
3435
|
+
async function fetchSuiPriceUsd(client) {
|
|
3436
|
+
try {
|
|
3437
|
+
const pool = await client.getObject({
|
|
3438
|
+
id: CETUS_USDC_SUI_POOL,
|
|
3439
|
+
options: { showContent: true }
|
|
3440
|
+
});
|
|
3441
|
+
if (pool.data?.content?.dataType === "moveObject") {
|
|
3442
|
+
const fields = pool.data.content.fields;
|
|
3443
|
+
const sqrtPrice = BigInt(String(fields.current_sqrt_price ?? "0"));
|
|
3444
|
+
if (sqrtPrice > 0n) {
|
|
3445
|
+
const Q64 = 2n ** 64n;
|
|
3446
|
+
const sqrtFloat = Number(sqrtPrice) / Number(Q64);
|
|
3447
|
+
const price = 1e3 / (sqrtFloat * sqrtFloat);
|
|
3448
|
+
if (price > 0.01 && price < 1e3) return price;
|
|
3449
|
+
}
|
|
3450
|
+
}
|
|
3451
|
+
} catch {
|
|
3452
|
+
}
|
|
3453
|
+
return 1;
|
|
3454
|
+
}
|
|
3455
|
+
async function getFinancialSummary(client, walletAddress, options = {}) {
|
|
3456
|
+
const [usdcBal, suiBal, hf, rates, suiPrice, allowance] = await Promise.all([
|
|
3457
|
+
client.getBalance({ owner: walletAddress, coinType: SUPPORTED_ASSETS.USDC.type }).catch(() => ({ totalBalance: "0" })),
|
|
3458
|
+
client.getBalance({ owner: walletAddress, coinType: SUPPORTED_ASSETS.SUI.type }).catch(() => ({ totalBalance: "0" })),
|
|
3459
|
+
getHealthFactor(client, walletAddress).catch(() => HF_FALLBACK),
|
|
3460
|
+
getRates(client),
|
|
3461
|
+
fetchSuiPriceUsd(client),
|
|
3462
|
+
options.allowanceId ? getAllowanceBalance(client, options.allowanceId).catch(() => null) : Promise.resolve(null)
|
|
3463
|
+
]);
|
|
3464
|
+
const usdcAvailable = Number(usdcBal.totalBalance) / 10 ** SUPPORTED_ASSETS.USDC.decimals;
|
|
3465
|
+
const gasReserveSui = Number(suiBal.totalBalance) / Number(MIST_PER_SUI);
|
|
3466
|
+
const saveApy = rates.USDC?.saveApy ?? 0;
|
|
3467
|
+
const borrowApy = rates.USDC?.borrowApy ?? 0;
|
|
3468
|
+
const dailyYield = hf.supplied * (saveApy / 365);
|
|
3469
|
+
return {
|
|
3470
|
+
walletAddress,
|
|
3471
|
+
usdcAvailable,
|
|
3472
|
+
savingsBalance: hf.supplied,
|
|
3473
|
+
debtBalance: hf.borrowed,
|
|
3474
|
+
idleUsdc: Math.max(0, usdcAvailable),
|
|
3475
|
+
healthFactor: hf.healthFactor,
|
|
3476
|
+
hfAlertLevel: classifyHF(hf.healthFactor, hf.borrowed > 0),
|
|
3477
|
+
saveApy,
|
|
3478
|
+
borrowApy,
|
|
3479
|
+
dailyYield,
|
|
3480
|
+
gasReserveSui,
|
|
3481
|
+
gasReserveUsd: gasReserveSui * suiPrice,
|
|
3482
|
+
allowanceBalance: allowance,
|
|
3483
|
+
fetchedAt: Date.now()
|
|
3484
|
+
};
|
|
3485
|
+
}
|
|
3264
3486
|
|
|
3265
3487
|
// src/utils/simulate.ts
|
|
3266
3488
|
init_errors();
|
|
@@ -3372,7 +3594,59 @@ async function getSwapQuote(params) {
|
|
|
3372
3594
|
init_cetus_swap();
|
|
3373
3595
|
init_token_registry();
|
|
3374
3596
|
init_volo();
|
|
3597
|
+
var DEFAULT_TTL_MS = 6e4;
|
|
3598
|
+
async function buildScopedIntent(adminKeypair, params) {
|
|
3599
|
+
const now = Date.now();
|
|
3600
|
+
const nonceBytes = new Uint8Array(32);
|
|
3601
|
+
crypto.getRandomValues(nonceBytes);
|
|
3602
|
+
const nonce = Buffer.from(nonceBytes).toString("hex");
|
|
3603
|
+
const payload = {
|
|
3604
|
+
version: 1,
|
|
3605
|
+
userId: params.userId,
|
|
3606
|
+
walletAddress: params.walletAddress,
|
|
3607
|
+
allowanceObjectId: params.allowanceObjectId,
|
|
3608
|
+
featureCode: params.featureCode,
|
|
3609
|
+
maxAmount: params.maxAmount,
|
|
3610
|
+
issuedAt: now,
|
|
3611
|
+
expiresAt: now + (params.ttlMs ?? DEFAULT_TTL_MS),
|
|
3612
|
+
nonce
|
|
3613
|
+
};
|
|
3614
|
+
const message = canonicalIntentBytes(payload);
|
|
3615
|
+
const signature = await adminKeypair.sign(message);
|
|
3616
|
+
return {
|
|
3617
|
+
...payload,
|
|
3618
|
+
signature: Buffer.from(signature).toString("hex")
|
|
3619
|
+
};
|
|
3620
|
+
}
|
|
3621
|
+
async function verifyScopedIntent(intent, adminPublicKeyBytes) {
|
|
3622
|
+
if (Date.now() > intent.expiresAt) return false;
|
|
3623
|
+
const payload = {
|
|
3624
|
+
version: intent.version,
|
|
3625
|
+
userId: intent.userId,
|
|
3626
|
+
walletAddress: intent.walletAddress,
|
|
3627
|
+
allowanceObjectId: intent.allowanceObjectId,
|
|
3628
|
+
featureCode: intent.featureCode,
|
|
3629
|
+
maxAmount: intent.maxAmount,
|
|
3630
|
+
issuedAt: intent.issuedAt,
|
|
3631
|
+
expiresAt: intent.expiresAt,
|
|
3632
|
+
nonce: intent.nonce
|
|
3633
|
+
};
|
|
3634
|
+
const message = canonicalIntentBytes(payload);
|
|
3635
|
+
const signatureBytes = Buffer.from(intent.signature, "hex");
|
|
3636
|
+
try {
|
|
3637
|
+
const publicKey = new Ed25519PublicKey(adminPublicKeyBytes);
|
|
3638
|
+
return await publicKey.verify(message, signatureBytes);
|
|
3639
|
+
} catch {
|
|
3640
|
+
return false;
|
|
3641
|
+
}
|
|
3642
|
+
}
|
|
3643
|
+
function canonicalIntentBytes(payload) {
|
|
3644
|
+
const sorted = Object.fromEntries(
|
|
3645
|
+
Object.entries(payload).sort(([a], [b]) => a.localeCompare(b))
|
|
3646
|
+
);
|
|
3647
|
+
return new TextEncoder().encode(JSON.stringify(sorted));
|
|
3648
|
+
}
|
|
3375
3649
|
|
|
3376
|
-
export { ALL_NAVI_ASSETS, BPS_DENOMINATOR, CETUS_USDC_SUI_POOL, CLOCK_ID, COIN_REGISTRY, ContactManager, DEFAULT_NETWORK, DEFAULT_SAFEGUARD_CONFIG, ETH_TYPE, GAS_RESERVE_MIN, IKA_TYPE, KeypairSigner, LOFI_TYPE, MANIFEST_TYPE, MIST_PER_SUI, NAVX_TYPE, NaviAdapter, OPERATION_ASSETS, OUTBOUND_OPS, ProtocolRegistry, STABLE_ASSETS, SUI_DECIMALS, SUI_TYPE, SUPPORTED_ASSETS, SafeguardEnforcer, SafeguardError, T2000, T2000Error, TOKEN_MAP, USDC_DECIMALS, USDC_TYPE, USDE_TYPE, USDSUI_TYPE, USDT_TYPE, VOLO_METADATA, VOLO_PKG, VOLO_POOL, VSUI_TYPE, WAL_TYPE, WBTC_TYPE, ZkLoginSigner, addCollectFeeToTx, allDescriptors, assertAllowedAsset, buildStakeVSuiTx, buildSwapTx, buildUnstakeVSuiTx, calculateFee, executeAutoTopUp, executeWithGas, exportPrivateKey, findSwapRoute, formatAssetAmount, formatSui, formatUsd, generateKeypair, getAddress, getDecimals, getDecimalsForCoinType, getGasStatus, getRates, getSwapQuote, getTier, getVoloStats, isAllowedAsset, isSupported, isTier1, isTier2, keypairFromPrivateKey, loadKey, mapMoveAbortCode, mapWalletError, mistToSui, naviDescriptor, rawToStable, rawToUsdc, resolveSymbol, resolveTokenType, saveKey, shouldAutoTopUp, simulateTransaction, solveHashcash, stableToRaw, suiToMist, throwIfSimulationFailed, truncateAddress, usdcToRaw, validateAddress, walletExists };
|
|
3650
|
+
export { ALLOWANCE_FEATURES, ALL_NAVI_ASSETS, BPS_DENOMINATOR, CETUS_USDC_SUI_POOL, CLOCK_ID, COIN_REGISTRY, ContactManager, DEFAULT_NETWORK, DEFAULT_SAFEGUARD_CONFIG, ETH_TYPE, GAS_RESERVE_MIN, HF_CRITICAL_THRESHOLD, HF_WARN_THRESHOLD, IKA_TYPE, KeypairSigner, LOFI_TYPE, MANIFEST_TYPE, MIST_PER_SUI, NAVX_TYPE, NaviAdapter, OPERATION_ASSETS, OUTBOUND_OPS, ProtocolRegistry, STABLE_ASSETS, SUI_DECIMALS, SUI_TYPE, SUPPORTED_ASSETS, SafeguardEnforcer, SafeguardError, T2000, T2000Error, TOKEN_MAP, USDC_DECIMALS, USDC_TYPE, USDE_TYPE, USDSUI_TYPE, USDT_TYPE, VOLO_METADATA, VOLO_PKG, VOLO_POOL, VSUI_TYPE, WAL_TYPE, WBTC_TYPE, ZkLoginSigner, addCollectFeeToTx, addDepositAllowanceTx, allDescriptors, assertAllowedAsset, buildAdminDepositAllowanceTx, buildCreateAllowanceTx, buildDeductAllowanceTx, buildDepositAllowanceTx, buildScopedIntent, buildStakeVSuiTx, buildSwapTx, buildUnstakeVSuiTx, buildWithdrawAllowanceTx, buildWithdrawAmountAllowanceTx, calculateFee, executeAutoTopUp, executeWithGas, exportPrivateKey, findSwapRoute, formatAssetAmount, formatSui, formatUsd, generateKeypair, getAddress, getAllowance, getAllowanceBalance, getDecimals, getDecimalsForCoinType, getFinancialSummary, getGasStatus, getRates, getSwapQuote, getTier, getVoloStats, isAllowedAsset, isSupported, isTier1, isTier2, keypairFromPrivateKey, loadKey, mapMoveAbortCode, mapWalletError, mistToSui, naviDescriptor, rawToStable, rawToUsdc, resolveSymbol, resolveTokenType, saveKey, shouldAutoTopUp, simulateTransaction, solveHashcash, stableToRaw, suiToMist, throwIfSimulationFailed, truncateAddress, usdcToRaw, validateAddress, verifyScopedIntent, walletExists };
|
|
3377
3651
|
//# sourceMappingURL=index.js.map
|
|
3378
3652
|
//# sourceMappingURL=index.js.map
|