@t2000/sdk 5.5.1 → 5.6.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/browser.cjs +164 -4
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.d.cts +1 -1
- package/dist/browser.d.ts +1 -1
- package/dist/browser.js +158 -7
- package/dist/browser.js.map +1 -1
- package/dist/index.cjs +110 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +17 -70
- package/dist/index.d.ts +17 -70
- package/dist/index.js +104 -11
- package/dist/index.js.map +1 -1
- package/dist/{simulate-KETPmlDo.d.cts → send-D2nKpwJN.d.cts} +162 -21
- package/dist/{simulate-KETPmlDo.d.ts → send-D2nKpwJN.d.ts} +162 -21
- package/package.json +1 -1
|
@@ -286,6 +286,63 @@ type SponsoredCoinMergeCache = Map<string, {
|
|
|
286
286
|
*/
|
|
287
287
|
declare function selectSuiCoin(tx: Transaction, client: SuiCoreClient, owner: string, amountMist: bigint, sponsoredContext: boolean, mergeCache?: SponsoredCoinMergeCache): Promise<SelectAndSplitResult>;
|
|
288
288
|
|
|
289
|
+
type T2000ErrorCode = 'INSUFFICIENT_BALANCE' | 'ADDRESS_BALANCE_UNSPONSORABLE' | 'INSUFFICIENT_GAS' | 'INVALID_ADDRESS' | 'INVALID_AMOUNT' | 'WALLET_NOT_FOUND' | 'WALLET_LOCKED' | 'WALLET_EXISTS' | 'WALLET_CORRUPT' | 'INVALID_KEY' | 'SIMULATION_FAILED' | 'TRANSACTION_FAILED' | 'ASSET_NOT_SUPPORTED' | 'INVALID_ASSET' | 'PROTOCOL_UNAVAILABLE' | 'RPC_ERROR' | 'RPC_UNREACHABLE' | 'PRICE_EXCEEDS_LIMIT' | 'UNSUPPORTED_NETWORK' | 'PAYMENT_EXPIRED' | 'DUPLICATE_PAYMENT' | 'FACILITATOR_REJECTION' | 'CONTACT_NOT_FOUND' | 'INVALID_CONTACT_NAME' | 'SUINS_NOT_REGISTERED' | 'FACILITATOR_TIMEOUT' | 'SAFEGUARD_BLOCKED' | 'SWAP_NO_ROUTE' | 'SWAP_FAILED' | 'CHAIN_MODE_INVALID' | 'UNKNOWN';
|
|
290
|
+
interface T2000ErrorData {
|
|
291
|
+
reason?: string;
|
|
292
|
+
[key: string]: unknown;
|
|
293
|
+
}
|
|
294
|
+
declare class T2000Error extends Error {
|
|
295
|
+
readonly code: T2000ErrorCode;
|
|
296
|
+
readonly data?: T2000ErrorData;
|
|
297
|
+
readonly retryable: boolean;
|
|
298
|
+
constructor(code: T2000ErrorCode, message: string, data?: T2000ErrorData, retryable?: boolean);
|
|
299
|
+
toJSON(): {
|
|
300
|
+
retryable: boolean;
|
|
301
|
+
data?: T2000ErrorData | undefined;
|
|
302
|
+
error: T2000ErrorCode;
|
|
303
|
+
message: string;
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
declare function mapWalletError(error: unknown): T2000Error;
|
|
307
|
+
declare function mapMoveAbortCode(code: number): string;
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* The result of a synchronous preflight check. `valid: false` carries a
|
|
311
|
+
* `T2000ErrorCode` + human message so the host can surface a precise reason
|
|
312
|
+
* (and the builder can rethrow it as a `T2000Error` verbatim).
|
|
313
|
+
*/
|
|
314
|
+
type PreflightResult = {
|
|
315
|
+
valid: true;
|
|
316
|
+
} | {
|
|
317
|
+
valid: false;
|
|
318
|
+
code: T2000ErrorCode;
|
|
319
|
+
error: string;
|
|
320
|
+
};
|
|
321
|
+
/**
|
|
322
|
+
* Fat-finger / overflow ceiling for an asset amount. NOT a spending policy
|
|
323
|
+
* (that's the `@t2000/sdk/limits` module — USD-denominated, opt-in, stateful);
|
|
324
|
+
* this is the "obviously wrong number" guard the safeguards rule prescribes
|
|
325
|
+
* (`amount > 1_000_000` → unreasonable).
|
|
326
|
+
*/
|
|
327
|
+
declare const PREFLIGHT_MAX_AMOUNT = 1000000;
|
|
328
|
+
declare const PREFLIGHT_OK: PreflightResult;
|
|
329
|
+
declare function preflightFail(code: T2000ErrorCode, error: string): PreflightResult;
|
|
330
|
+
/**
|
|
331
|
+
* Pure positive-finite-amount sanity check (no network). Rejects NaN/Infinity
|
|
332
|
+
* and non-positive values. The absurd-value ceiling defaults to
|
|
333
|
+
* {@link PREFLIGHT_MAX_AMOUNT} but callers can raise it — pass
|
|
334
|
+
* `max: Number.POSITIVE_INFINITY` for swaps of low-unit-value tokens
|
|
335
|
+
* (memecoins legitimately trade in millions/billions of units), where a fixed
|
|
336
|
+
* display-amount ceiling would be a false positive.
|
|
337
|
+
*/
|
|
338
|
+
declare function checkPositiveAmount(amount: number, label?: string, max?: number): PreflightResult;
|
|
339
|
+
/**
|
|
340
|
+
* Pure, synchronous Sui-address validity (no throw, no network) — the
|
|
341
|
+
* non-throwing sibling of `validateAddress`. Use in preflight; use
|
|
342
|
+
* `validateAddress` when you need the normalized form.
|
|
343
|
+
*/
|
|
344
|
+
declare function checkSuiAddress(address: string, label?: string): PreflightResult;
|
|
345
|
+
|
|
289
346
|
/**
|
|
290
347
|
* Unified token registry — single source of truth for coin types, decimals,
|
|
291
348
|
* and symbols. ZERO heavy dependencies; safe to import anywhere (server,
|
|
@@ -373,6 +430,21 @@ declare const MANIFEST_TYPE: string;
|
|
|
373
430
|
* by removing the singleton pattern that hid the misconfig.
|
|
374
431
|
*/
|
|
375
432
|
|
|
433
|
+
/**
|
|
434
|
+
* Synchronous, network-free preflight for `swap`. Validates the from/to token
|
|
435
|
+
* args + amount sanity, and rejects an identity swap — the cheap checks the
|
|
436
|
+
* host runs before routing. Returns a `PreflightResult`; never throws.
|
|
437
|
+
* Route-finding, liquidity, slippage + decimals resolution stay in the async
|
|
438
|
+
* path (`findSwapRoute`/`buildSwapTx`/`getSwapQuote`).
|
|
439
|
+
*
|
|
440
|
+
* v3 drops the swap *tool*, but `swap` survives as an SDK/CLI builder (§8) so
|
|
441
|
+
* it gets the same builder-appropriate preflight as send/pay.
|
|
442
|
+
*/
|
|
443
|
+
declare function preflightSwap(input: {
|
|
444
|
+
from: string;
|
|
445
|
+
to: string;
|
|
446
|
+
amount: number;
|
|
447
|
+
}): PreflightResult;
|
|
376
448
|
interface OverlayFeeConfig {
|
|
377
449
|
/** Fee rate as a fraction (e.g. 0.001 = 0.1%). Pass 0 to disable. */
|
|
378
450
|
rate: number;
|
|
@@ -836,6 +908,17 @@ interface PayResult {
|
|
|
836
908
|
};
|
|
837
909
|
}
|
|
838
910
|
|
|
911
|
+
/**
|
|
912
|
+
* Synchronous, network-free preflight for `pay` (x402 Service call). Validates
|
|
913
|
+
* the target URL shape and the `maxPrice` ceiling when present — the cheap
|
|
914
|
+
* checks the v3 host runs before dispatching the paid tool / showing the
|
|
915
|
+
* tap-to-confirm card. Returns a `PreflightResult`; never throws. The probe +
|
|
916
|
+
* 402 handshake + balance migration stay in `payWithMpp` (network).
|
|
917
|
+
*/
|
|
918
|
+
declare function preflightPay(input: {
|
|
919
|
+
url: string;
|
|
920
|
+
maxPrice?: number;
|
|
921
|
+
}): PreflightResult;
|
|
839
922
|
declare function payWithMpp(args: {
|
|
840
923
|
signer: TransactionSigner;
|
|
841
924
|
client: SuiGrpcClient;
|
|
@@ -852,26 +935,6 @@ declare function executeTx(client: SuiCoreClient, signer: TransactionSigner, bui
|
|
|
852
935
|
effects: SuiTransactionEffects | undefined;
|
|
853
936
|
}>;
|
|
854
937
|
|
|
855
|
-
type T2000ErrorCode = 'INSUFFICIENT_BALANCE' | 'ADDRESS_BALANCE_UNSPONSORABLE' | 'INSUFFICIENT_GAS' | 'INVALID_ADDRESS' | 'INVALID_AMOUNT' | 'WALLET_NOT_FOUND' | 'WALLET_LOCKED' | 'WALLET_EXISTS' | 'WALLET_CORRUPT' | 'INVALID_KEY' | 'SIMULATION_FAILED' | 'TRANSACTION_FAILED' | 'ASSET_NOT_SUPPORTED' | 'INVALID_ASSET' | 'PROTOCOL_UNAVAILABLE' | 'RPC_ERROR' | 'RPC_UNREACHABLE' | 'PRICE_EXCEEDS_LIMIT' | 'UNSUPPORTED_NETWORK' | 'PAYMENT_EXPIRED' | 'DUPLICATE_PAYMENT' | 'FACILITATOR_REJECTION' | 'CONTACT_NOT_FOUND' | 'INVALID_CONTACT_NAME' | 'SUINS_NOT_REGISTERED' | 'FACILITATOR_TIMEOUT' | 'SAFEGUARD_BLOCKED' | 'SWAP_NO_ROUTE' | 'SWAP_FAILED' | 'CHAIN_MODE_INVALID' | 'UNKNOWN';
|
|
856
|
-
interface T2000ErrorData {
|
|
857
|
-
reason?: string;
|
|
858
|
-
[key: string]: unknown;
|
|
859
|
-
}
|
|
860
|
-
declare class T2000Error extends Error {
|
|
861
|
-
readonly code: T2000ErrorCode;
|
|
862
|
-
readonly data?: T2000ErrorData;
|
|
863
|
-
readonly retryable: boolean;
|
|
864
|
-
constructor(code: T2000ErrorCode, message: string, data?: T2000ErrorData, retryable?: boolean);
|
|
865
|
-
toJSON(): {
|
|
866
|
-
retryable: boolean;
|
|
867
|
-
data?: T2000ErrorData | undefined;
|
|
868
|
-
error: T2000ErrorCode;
|
|
869
|
-
message: string;
|
|
870
|
-
};
|
|
871
|
-
}
|
|
872
|
-
declare function mapWalletError(error: unknown): T2000Error;
|
|
873
|
-
declare function mapMoveAbortCode(code: number): string;
|
|
874
|
-
|
|
875
938
|
declare const MIST_PER_SUI = 1000000000n;
|
|
876
939
|
declare const SUI_DECIMALS = 9;
|
|
877
940
|
declare const USDC_DECIMALS = 6;
|
|
@@ -1202,4 +1265,82 @@ interface SimulationResult {
|
|
|
1202
1265
|
declare function simulateTransaction(client: SuiCoreClient, tx: Transaction, sender: string): Promise<SimulationResult>;
|
|
1203
1266
|
declare function throwIfSimulationFailed(sim: SimulationResult): void;
|
|
1204
1267
|
|
|
1205
|
-
|
|
1268
|
+
/**
|
|
1269
|
+
* Synchronous, network-free preflight for `send`. Validates asset membership,
|
|
1270
|
+
* amount sanity, the gasless stable floor, and recipient address shape — the
|
|
1271
|
+
* cheap checks the v3 host runs before the LLM round-trip / tap-to-confirm.
|
|
1272
|
+
* Returns a `PreflightResult`; never throws. `buildSendTx` calls this first,
|
|
1273
|
+
* then layers the network balance read on top.
|
|
1274
|
+
*/
|
|
1275
|
+
declare function preflightSend(input: {
|
|
1276
|
+
to: string;
|
|
1277
|
+
amount: number;
|
|
1278
|
+
asset: string;
|
|
1279
|
+
}): PreflightResult;
|
|
1280
|
+
/**
|
|
1281
|
+
* Build a PTB that sends `amount` of `asset` from `address` to `to`.
|
|
1282
|
+
*
|
|
1283
|
+
* [v4.0 Phase A Day 2 — SPEC_AGENT_WALLET_GREENFIELD §A]
|
|
1284
|
+
*
|
|
1285
|
+
* Asset constraint: `'USDC' | 'USDsui' | 'SUI'` only. Other assets throw
|
|
1286
|
+
* `INVALID_ASSET` via `assertAllowedAsset('send', asset)`. The constrained
|
|
1287
|
+
* set matches Sui mainnet's gasless allowlist (USDC + USDsui) plus SUI
|
|
1288
|
+
* for users who want a gas-native transfer.
|
|
1289
|
+
*
|
|
1290
|
+
* Build paths:
|
|
1291
|
+
* - **USDC / USDsui** — `0x2::balance::send_funds` Move call with a
|
|
1292
|
+
* `tx.balance({ type, balance })` input. When built via `SuiGrpcClient`,
|
|
1293
|
+
* the gRPC resolver auto-detects gasless eligibility and zeros gas.
|
|
1294
|
+
* When built via `SuiJsonRpcClient`, the same PTB still executes but
|
|
1295
|
+
* the caller pays normal gas. Minimum 0.01 (protocol allowlist floor).
|
|
1296
|
+
* - **SUI** — `tx.splitCoins(tx.gas, [amount]) → tx.transferObjects()`.
|
|
1297
|
+
* Standard gas-native transfer. No minimum.
|
|
1298
|
+
*
|
|
1299
|
+
* Pre-flight balance check stays on JSON-RPC (`client.getBalance`) — it
|
|
1300
|
+
* sums coin objects + address balance so the legacy `getCoins` page miss
|
|
1301
|
+
* doesn't break for users whose stables landed via gasless deposits.
|
|
1302
|
+
*
|
|
1303
|
+
* `asset` is REQUIRED (no implicit USDC default — pre-v4 hid LLM intent
|
|
1304
|
+
* errors). Callers passing the wrong asset get an explicit error rather
|
|
1305
|
+
* than a silent currency substitution.
|
|
1306
|
+
*/
|
|
1307
|
+
declare function buildSendTx({ client, address, to, amount, asset, }: {
|
|
1308
|
+
client: SuiCoreClient;
|
|
1309
|
+
address: string;
|
|
1310
|
+
to: string;
|
|
1311
|
+
amount: number;
|
|
1312
|
+
asset: SendableAsset;
|
|
1313
|
+
}): Promise<Transaction>;
|
|
1314
|
+
/**
|
|
1315
|
+
* Fragment-appender for the chain-mode send leg of SPEC 7 multi-write
|
|
1316
|
+
* Payment Intents. Consumes a coin reference produced by a previous
|
|
1317
|
+
* appender (e.g. `addWithdrawToTx`, `addSwapToTx`) and transfers it to
|
|
1318
|
+
* `recipient` within the same Payment Intent — no intermediate wallet
|
|
1319
|
+
* materialization.
|
|
1320
|
+
*
|
|
1321
|
+
* Codifies the hand-built send leg from
|
|
1322
|
+
* `scripts/smoke-spec7-withdraw-then-send.ts` (P2.1) into a typed
|
|
1323
|
+
* appender. SPEC 7 § "Layer 1" — P2.2b will register this in the
|
|
1324
|
+
* `WRITE_APPENDER_REGISTRY` under `send_transfer` for chain-mode
|
|
1325
|
+
* dispatch; the registry adapter will handle the wallet-fetch fallback
|
|
1326
|
+
* by delegating to `buildSendTx` when no upstream coin is available.
|
|
1327
|
+
*
|
|
1328
|
+
* For single-step send_transfer flows (no chained predecessor), use
|
|
1329
|
+
* `buildSendTx` directly — it builds a complete tx including the
|
|
1330
|
+
* wallet-coin selection / merge / split prelude.
|
|
1331
|
+
*
|
|
1332
|
+
* [v4.0 Phase A Day 2] Stays on the legacy `transferObjects` path
|
|
1333
|
+
* because chain-mode bundles are NEVER gasless — by definition they
|
|
1334
|
+
* combine multiple Move calls (`withdraw → send`, `swap → send`) which
|
|
1335
|
+
* fail the protocol allowlist check (only `balance::send_funds` and
|
|
1336
|
+
* a few related helpers are eligible). The bundled flow still works,
|
|
1337
|
+
* the user just pays gas (or has it sponsored by audric via Enoki).
|
|
1338
|
+
*
|
|
1339
|
+
* @returns void — the coin is consumed by `tx.transferObjects`. Callers
|
|
1340
|
+
* that need the post-transfer "effective amount" should rely on the
|
|
1341
|
+
* upstream appender's `effectiveAmount` (e.g. `addWithdrawToTx`'s
|
|
1342
|
+
* return), not on this appender.
|
|
1343
|
+
*/
|
|
1344
|
+
declare function addSendToTx(tx: Transaction, coin: TransactionObjectArgument, recipient: string): void;
|
|
1345
|
+
|
|
1346
|
+
export { type ZkLoginProof as $, T2000_OVERLAY_FEE_WALLET as A, type BalanceResponse as B, CLOCK_ID as C, DEFAULT_NETWORK as D, ETH_TYPE as E, TOKEN_MAP as F, GAS_RESERVE_MIN as G, type TransactionLeg as H, IKA_TYPE as I, type TransactionRecord as J, KNOWN_TARGETS as K, LABEL_PATTERNS as L, MANIFEST_TYPE as M, NAVX_TYPE as N, OVERLAY_FEE_RATE as O, PREFLIGHT_MAX_AMOUNT as P, type TransactionSigner as Q, type TxDirection as R, STABLE_ASSETS as S, T2000Error as T, USDC_DECIMALS as U, USDC_TYPE as V, USDE_TYPE as W, USDSUI_TYPE as X, USDT_TYPE as Y, WAL_TYPE as Z, WBTC_TYPE as _, COIN_REGISTRY as a, getCoinMeta as a$, ZkLoginSigner as a0, buildSendTx as a1, buildSwapTx as a2, checkPositiveAmount as a3, checkSuiAddress as a4, classifyAction as a5, classifyLabel as a6, classifyTransaction as a7, executeTx as a8, extractAllUserLegs as a9, truncateAddress as aA, usdcToRaw as aB, validateAddress as aC, type T2000Options as aD, type SwapResult as aE, type SwapQuoteResult as aF, type PaymentRequest as aG, type SuiCoreClient as aH, type SponsoredCoinMergeCache as aI, type SendableAsset as aJ, CETUS_USDC_SUI_POOL as aK, type CoinPage as aL, DEFAULT_GRPC_URL as aM, GASLESS_MIN_STABLE_AMOUNT as aN, GASLESS_STABLE_TYPES as aO, OPERATION_ASSETS as aP, type Operation as aQ, SENDABLE_ASSETS as aR, type SelectAndSplitResult as aS, type SerializedCetusRoute as aT, type SerializedCetusRoutePath as aU, type SerializedRouterDataV3 as aV, addSendToTx as aW, addSwapToTx as aX, assertAllowedAsset as aY, deserializeCetusRoute as aZ, fetchAllCoins as a_, extractTransferDetails as aa, extractTxCommands as ab, extractTxSender as ac, fallbackLabel as ad, findSwapRoute as ae, formatAssetAmount as af, formatSui as ag, formatUsd as ah, getDecimals as ai, getDecimalsForCoinType as aj, mapMoveAbortCode as ak, mapWalletError as al, mistToSui as am, parseSuiRpcTx as an, payWithMpp as ao, preflightFail as ap, preflightPay as aq, preflightSend as ar, preflightSwap as as, rawToStable as at, rawToUsdc as au, refineLendingLabel as av, resolveSymbol as aw, resolveTokenType as ax, stableToRaw as ay, suiToMist as az, type ClassifyBalanceChange as b, getSuiClient as b0, getSuiGrpcClient as b1, isAllowedAsset as b2, isCetusRouteFresh as b3, isInRegistry as b4, normalizeAsset as b5, normalizeCoinType as b6, queryHistory as b7, queryTransaction as b8, selectAndSplitCoin as b9, selectSuiCoin as ba, serializeCetusRoute as bb, simulateTransaction as bc, throwIfSimulationFailed as bd, verifyCetusRouteCoinMatch as be, type ClassifyResult as c, type CoinMeta as d, type DepositInfo as e, type ExtractedTransfer as f, KeypairSigner as g, LOFI_TYPE as h, MIST_PER_SUI as i, type OverlayFeeConfig as j, PREFLIGHT_OK as k, type PayOptions as l, type PayResult as m, type PreflightResult as n, SUI_DECIMALS as o, SUI_TYPE as p, SUPPORTED_ASSETS as q, type SendResult as r, type SimulationResult as s, type StableAsset as t, type SuiHolding as u, type SuiRpcTxBlock as v, type SupportedAsset as w, type SwapRouteResult as x, type T2000ErrorCode as y, type T2000ErrorData as z };
|
|
@@ -286,6 +286,63 @@ type SponsoredCoinMergeCache = Map<string, {
|
|
|
286
286
|
*/
|
|
287
287
|
declare function selectSuiCoin(tx: Transaction, client: SuiCoreClient, owner: string, amountMist: bigint, sponsoredContext: boolean, mergeCache?: SponsoredCoinMergeCache): Promise<SelectAndSplitResult>;
|
|
288
288
|
|
|
289
|
+
type T2000ErrorCode = 'INSUFFICIENT_BALANCE' | 'ADDRESS_BALANCE_UNSPONSORABLE' | 'INSUFFICIENT_GAS' | 'INVALID_ADDRESS' | 'INVALID_AMOUNT' | 'WALLET_NOT_FOUND' | 'WALLET_LOCKED' | 'WALLET_EXISTS' | 'WALLET_CORRUPT' | 'INVALID_KEY' | 'SIMULATION_FAILED' | 'TRANSACTION_FAILED' | 'ASSET_NOT_SUPPORTED' | 'INVALID_ASSET' | 'PROTOCOL_UNAVAILABLE' | 'RPC_ERROR' | 'RPC_UNREACHABLE' | 'PRICE_EXCEEDS_LIMIT' | 'UNSUPPORTED_NETWORK' | 'PAYMENT_EXPIRED' | 'DUPLICATE_PAYMENT' | 'FACILITATOR_REJECTION' | 'CONTACT_NOT_FOUND' | 'INVALID_CONTACT_NAME' | 'SUINS_NOT_REGISTERED' | 'FACILITATOR_TIMEOUT' | 'SAFEGUARD_BLOCKED' | 'SWAP_NO_ROUTE' | 'SWAP_FAILED' | 'CHAIN_MODE_INVALID' | 'UNKNOWN';
|
|
290
|
+
interface T2000ErrorData {
|
|
291
|
+
reason?: string;
|
|
292
|
+
[key: string]: unknown;
|
|
293
|
+
}
|
|
294
|
+
declare class T2000Error extends Error {
|
|
295
|
+
readonly code: T2000ErrorCode;
|
|
296
|
+
readonly data?: T2000ErrorData;
|
|
297
|
+
readonly retryable: boolean;
|
|
298
|
+
constructor(code: T2000ErrorCode, message: string, data?: T2000ErrorData, retryable?: boolean);
|
|
299
|
+
toJSON(): {
|
|
300
|
+
retryable: boolean;
|
|
301
|
+
data?: T2000ErrorData | undefined;
|
|
302
|
+
error: T2000ErrorCode;
|
|
303
|
+
message: string;
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
declare function mapWalletError(error: unknown): T2000Error;
|
|
307
|
+
declare function mapMoveAbortCode(code: number): string;
|
|
308
|
+
|
|
309
|
+
/**
|
|
310
|
+
* The result of a synchronous preflight check. `valid: false` carries a
|
|
311
|
+
* `T2000ErrorCode` + human message so the host can surface a precise reason
|
|
312
|
+
* (and the builder can rethrow it as a `T2000Error` verbatim).
|
|
313
|
+
*/
|
|
314
|
+
type PreflightResult = {
|
|
315
|
+
valid: true;
|
|
316
|
+
} | {
|
|
317
|
+
valid: false;
|
|
318
|
+
code: T2000ErrorCode;
|
|
319
|
+
error: string;
|
|
320
|
+
};
|
|
321
|
+
/**
|
|
322
|
+
* Fat-finger / overflow ceiling for an asset amount. NOT a spending policy
|
|
323
|
+
* (that's the `@t2000/sdk/limits` module — USD-denominated, opt-in, stateful);
|
|
324
|
+
* this is the "obviously wrong number" guard the safeguards rule prescribes
|
|
325
|
+
* (`amount > 1_000_000` → unreasonable).
|
|
326
|
+
*/
|
|
327
|
+
declare const PREFLIGHT_MAX_AMOUNT = 1000000;
|
|
328
|
+
declare const PREFLIGHT_OK: PreflightResult;
|
|
329
|
+
declare function preflightFail(code: T2000ErrorCode, error: string): PreflightResult;
|
|
330
|
+
/**
|
|
331
|
+
* Pure positive-finite-amount sanity check (no network). Rejects NaN/Infinity
|
|
332
|
+
* and non-positive values. The absurd-value ceiling defaults to
|
|
333
|
+
* {@link PREFLIGHT_MAX_AMOUNT} but callers can raise it — pass
|
|
334
|
+
* `max: Number.POSITIVE_INFINITY` for swaps of low-unit-value tokens
|
|
335
|
+
* (memecoins legitimately trade in millions/billions of units), where a fixed
|
|
336
|
+
* display-amount ceiling would be a false positive.
|
|
337
|
+
*/
|
|
338
|
+
declare function checkPositiveAmount(amount: number, label?: string, max?: number): PreflightResult;
|
|
339
|
+
/**
|
|
340
|
+
* Pure, synchronous Sui-address validity (no throw, no network) — the
|
|
341
|
+
* non-throwing sibling of `validateAddress`. Use in preflight; use
|
|
342
|
+
* `validateAddress` when you need the normalized form.
|
|
343
|
+
*/
|
|
344
|
+
declare function checkSuiAddress(address: string, label?: string): PreflightResult;
|
|
345
|
+
|
|
289
346
|
/**
|
|
290
347
|
* Unified token registry — single source of truth for coin types, decimals,
|
|
291
348
|
* and symbols. ZERO heavy dependencies; safe to import anywhere (server,
|
|
@@ -373,6 +430,21 @@ declare const MANIFEST_TYPE: string;
|
|
|
373
430
|
* by removing the singleton pattern that hid the misconfig.
|
|
374
431
|
*/
|
|
375
432
|
|
|
433
|
+
/**
|
|
434
|
+
* Synchronous, network-free preflight for `swap`. Validates the from/to token
|
|
435
|
+
* args + amount sanity, and rejects an identity swap — the cheap checks the
|
|
436
|
+
* host runs before routing. Returns a `PreflightResult`; never throws.
|
|
437
|
+
* Route-finding, liquidity, slippage + decimals resolution stay in the async
|
|
438
|
+
* path (`findSwapRoute`/`buildSwapTx`/`getSwapQuote`).
|
|
439
|
+
*
|
|
440
|
+
* v3 drops the swap *tool*, but `swap` survives as an SDK/CLI builder (§8) so
|
|
441
|
+
* it gets the same builder-appropriate preflight as send/pay.
|
|
442
|
+
*/
|
|
443
|
+
declare function preflightSwap(input: {
|
|
444
|
+
from: string;
|
|
445
|
+
to: string;
|
|
446
|
+
amount: number;
|
|
447
|
+
}): PreflightResult;
|
|
376
448
|
interface OverlayFeeConfig {
|
|
377
449
|
/** Fee rate as a fraction (e.g. 0.001 = 0.1%). Pass 0 to disable. */
|
|
378
450
|
rate: number;
|
|
@@ -836,6 +908,17 @@ interface PayResult {
|
|
|
836
908
|
};
|
|
837
909
|
}
|
|
838
910
|
|
|
911
|
+
/**
|
|
912
|
+
* Synchronous, network-free preflight for `pay` (x402 Service call). Validates
|
|
913
|
+
* the target URL shape and the `maxPrice` ceiling when present — the cheap
|
|
914
|
+
* checks the v3 host runs before dispatching the paid tool / showing the
|
|
915
|
+
* tap-to-confirm card. Returns a `PreflightResult`; never throws. The probe +
|
|
916
|
+
* 402 handshake + balance migration stay in `payWithMpp` (network).
|
|
917
|
+
*/
|
|
918
|
+
declare function preflightPay(input: {
|
|
919
|
+
url: string;
|
|
920
|
+
maxPrice?: number;
|
|
921
|
+
}): PreflightResult;
|
|
839
922
|
declare function payWithMpp(args: {
|
|
840
923
|
signer: TransactionSigner;
|
|
841
924
|
client: SuiGrpcClient;
|
|
@@ -852,26 +935,6 @@ declare function executeTx(client: SuiCoreClient, signer: TransactionSigner, bui
|
|
|
852
935
|
effects: SuiTransactionEffects | undefined;
|
|
853
936
|
}>;
|
|
854
937
|
|
|
855
|
-
type T2000ErrorCode = 'INSUFFICIENT_BALANCE' | 'ADDRESS_BALANCE_UNSPONSORABLE' | 'INSUFFICIENT_GAS' | 'INVALID_ADDRESS' | 'INVALID_AMOUNT' | 'WALLET_NOT_FOUND' | 'WALLET_LOCKED' | 'WALLET_EXISTS' | 'WALLET_CORRUPT' | 'INVALID_KEY' | 'SIMULATION_FAILED' | 'TRANSACTION_FAILED' | 'ASSET_NOT_SUPPORTED' | 'INVALID_ASSET' | 'PROTOCOL_UNAVAILABLE' | 'RPC_ERROR' | 'RPC_UNREACHABLE' | 'PRICE_EXCEEDS_LIMIT' | 'UNSUPPORTED_NETWORK' | 'PAYMENT_EXPIRED' | 'DUPLICATE_PAYMENT' | 'FACILITATOR_REJECTION' | 'CONTACT_NOT_FOUND' | 'INVALID_CONTACT_NAME' | 'SUINS_NOT_REGISTERED' | 'FACILITATOR_TIMEOUT' | 'SAFEGUARD_BLOCKED' | 'SWAP_NO_ROUTE' | 'SWAP_FAILED' | 'CHAIN_MODE_INVALID' | 'UNKNOWN';
|
|
856
|
-
interface T2000ErrorData {
|
|
857
|
-
reason?: string;
|
|
858
|
-
[key: string]: unknown;
|
|
859
|
-
}
|
|
860
|
-
declare class T2000Error extends Error {
|
|
861
|
-
readonly code: T2000ErrorCode;
|
|
862
|
-
readonly data?: T2000ErrorData;
|
|
863
|
-
readonly retryable: boolean;
|
|
864
|
-
constructor(code: T2000ErrorCode, message: string, data?: T2000ErrorData, retryable?: boolean);
|
|
865
|
-
toJSON(): {
|
|
866
|
-
retryable: boolean;
|
|
867
|
-
data?: T2000ErrorData | undefined;
|
|
868
|
-
error: T2000ErrorCode;
|
|
869
|
-
message: string;
|
|
870
|
-
};
|
|
871
|
-
}
|
|
872
|
-
declare function mapWalletError(error: unknown): T2000Error;
|
|
873
|
-
declare function mapMoveAbortCode(code: number): string;
|
|
874
|
-
|
|
875
938
|
declare const MIST_PER_SUI = 1000000000n;
|
|
876
939
|
declare const SUI_DECIMALS = 9;
|
|
877
940
|
declare const USDC_DECIMALS = 6;
|
|
@@ -1202,4 +1265,82 @@ interface SimulationResult {
|
|
|
1202
1265
|
declare function simulateTransaction(client: SuiCoreClient, tx: Transaction, sender: string): Promise<SimulationResult>;
|
|
1203
1266
|
declare function throwIfSimulationFailed(sim: SimulationResult): void;
|
|
1204
1267
|
|
|
1205
|
-
|
|
1268
|
+
/**
|
|
1269
|
+
* Synchronous, network-free preflight for `send`. Validates asset membership,
|
|
1270
|
+
* amount sanity, the gasless stable floor, and recipient address shape — the
|
|
1271
|
+
* cheap checks the v3 host runs before the LLM round-trip / tap-to-confirm.
|
|
1272
|
+
* Returns a `PreflightResult`; never throws. `buildSendTx` calls this first,
|
|
1273
|
+
* then layers the network balance read on top.
|
|
1274
|
+
*/
|
|
1275
|
+
declare function preflightSend(input: {
|
|
1276
|
+
to: string;
|
|
1277
|
+
amount: number;
|
|
1278
|
+
asset: string;
|
|
1279
|
+
}): PreflightResult;
|
|
1280
|
+
/**
|
|
1281
|
+
* Build a PTB that sends `amount` of `asset` from `address` to `to`.
|
|
1282
|
+
*
|
|
1283
|
+
* [v4.0 Phase A Day 2 — SPEC_AGENT_WALLET_GREENFIELD §A]
|
|
1284
|
+
*
|
|
1285
|
+
* Asset constraint: `'USDC' | 'USDsui' | 'SUI'` only. Other assets throw
|
|
1286
|
+
* `INVALID_ASSET` via `assertAllowedAsset('send', asset)`. The constrained
|
|
1287
|
+
* set matches Sui mainnet's gasless allowlist (USDC + USDsui) plus SUI
|
|
1288
|
+
* for users who want a gas-native transfer.
|
|
1289
|
+
*
|
|
1290
|
+
* Build paths:
|
|
1291
|
+
* - **USDC / USDsui** — `0x2::balance::send_funds` Move call with a
|
|
1292
|
+
* `tx.balance({ type, balance })` input. When built via `SuiGrpcClient`,
|
|
1293
|
+
* the gRPC resolver auto-detects gasless eligibility and zeros gas.
|
|
1294
|
+
* When built via `SuiJsonRpcClient`, the same PTB still executes but
|
|
1295
|
+
* the caller pays normal gas. Minimum 0.01 (protocol allowlist floor).
|
|
1296
|
+
* - **SUI** — `tx.splitCoins(tx.gas, [amount]) → tx.transferObjects()`.
|
|
1297
|
+
* Standard gas-native transfer. No minimum.
|
|
1298
|
+
*
|
|
1299
|
+
* Pre-flight balance check stays on JSON-RPC (`client.getBalance`) — it
|
|
1300
|
+
* sums coin objects + address balance so the legacy `getCoins` page miss
|
|
1301
|
+
* doesn't break for users whose stables landed via gasless deposits.
|
|
1302
|
+
*
|
|
1303
|
+
* `asset` is REQUIRED (no implicit USDC default — pre-v4 hid LLM intent
|
|
1304
|
+
* errors). Callers passing the wrong asset get an explicit error rather
|
|
1305
|
+
* than a silent currency substitution.
|
|
1306
|
+
*/
|
|
1307
|
+
declare function buildSendTx({ client, address, to, amount, asset, }: {
|
|
1308
|
+
client: SuiCoreClient;
|
|
1309
|
+
address: string;
|
|
1310
|
+
to: string;
|
|
1311
|
+
amount: number;
|
|
1312
|
+
asset: SendableAsset;
|
|
1313
|
+
}): Promise<Transaction>;
|
|
1314
|
+
/**
|
|
1315
|
+
* Fragment-appender for the chain-mode send leg of SPEC 7 multi-write
|
|
1316
|
+
* Payment Intents. Consumes a coin reference produced by a previous
|
|
1317
|
+
* appender (e.g. `addWithdrawToTx`, `addSwapToTx`) and transfers it to
|
|
1318
|
+
* `recipient` within the same Payment Intent — no intermediate wallet
|
|
1319
|
+
* materialization.
|
|
1320
|
+
*
|
|
1321
|
+
* Codifies the hand-built send leg from
|
|
1322
|
+
* `scripts/smoke-spec7-withdraw-then-send.ts` (P2.1) into a typed
|
|
1323
|
+
* appender. SPEC 7 § "Layer 1" — P2.2b will register this in the
|
|
1324
|
+
* `WRITE_APPENDER_REGISTRY` under `send_transfer` for chain-mode
|
|
1325
|
+
* dispatch; the registry adapter will handle the wallet-fetch fallback
|
|
1326
|
+
* by delegating to `buildSendTx` when no upstream coin is available.
|
|
1327
|
+
*
|
|
1328
|
+
* For single-step send_transfer flows (no chained predecessor), use
|
|
1329
|
+
* `buildSendTx` directly — it builds a complete tx including the
|
|
1330
|
+
* wallet-coin selection / merge / split prelude.
|
|
1331
|
+
*
|
|
1332
|
+
* [v4.0 Phase A Day 2] Stays on the legacy `transferObjects` path
|
|
1333
|
+
* because chain-mode bundles are NEVER gasless — by definition they
|
|
1334
|
+
* combine multiple Move calls (`withdraw → send`, `swap → send`) which
|
|
1335
|
+
* fail the protocol allowlist check (only `balance::send_funds` and
|
|
1336
|
+
* a few related helpers are eligible). The bundled flow still works,
|
|
1337
|
+
* the user just pays gas (or has it sponsored by audric via Enoki).
|
|
1338
|
+
*
|
|
1339
|
+
* @returns void — the coin is consumed by `tx.transferObjects`. Callers
|
|
1340
|
+
* that need the post-transfer "effective amount" should rely on the
|
|
1341
|
+
* upstream appender's `effectiveAmount` (e.g. `addWithdrawToTx`'s
|
|
1342
|
+
* return), not on this appender.
|
|
1343
|
+
*/
|
|
1344
|
+
declare function addSendToTx(tx: Transaction, coin: TransactionObjectArgument, recipient: string): void;
|
|
1345
|
+
|
|
1346
|
+
export { type ZkLoginProof as $, T2000_OVERLAY_FEE_WALLET as A, type BalanceResponse as B, CLOCK_ID as C, DEFAULT_NETWORK as D, ETH_TYPE as E, TOKEN_MAP as F, GAS_RESERVE_MIN as G, type TransactionLeg as H, IKA_TYPE as I, type TransactionRecord as J, KNOWN_TARGETS as K, LABEL_PATTERNS as L, MANIFEST_TYPE as M, NAVX_TYPE as N, OVERLAY_FEE_RATE as O, PREFLIGHT_MAX_AMOUNT as P, type TransactionSigner as Q, type TxDirection as R, STABLE_ASSETS as S, T2000Error as T, USDC_DECIMALS as U, USDC_TYPE as V, USDE_TYPE as W, USDSUI_TYPE as X, USDT_TYPE as Y, WAL_TYPE as Z, WBTC_TYPE as _, COIN_REGISTRY as a, getCoinMeta as a$, ZkLoginSigner as a0, buildSendTx as a1, buildSwapTx as a2, checkPositiveAmount as a3, checkSuiAddress as a4, classifyAction as a5, classifyLabel as a6, classifyTransaction as a7, executeTx as a8, extractAllUserLegs as a9, truncateAddress as aA, usdcToRaw as aB, validateAddress as aC, type T2000Options as aD, type SwapResult as aE, type SwapQuoteResult as aF, type PaymentRequest as aG, type SuiCoreClient as aH, type SponsoredCoinMergeCache as aI, type SendableAsset as aJ, CETUS_USDC_SUI_POOL as aK, type CoinPage as aL, DEFAULT_GRPC_URL as aM, GASLESS_MIN_STABLE_AMOUNT as aN, GASLESS_STABLE_TYPES as aO, OPERATION_ASSETS as aP, type Operation as aQ, SENDABLE_ASSETS as aR, type SelectAndSplitResult as aS, type SerializedCetusRoute as aT, type SerializedCetusRoutePath as aU, type SerializedRouterDataV3 as aV, addSendToTx as aW, addSwapToTx as aX, assertAllowedAsset as aY, deserializeCetusRoute as aZ, fetchAllCoins as a_, extractTransferDetails as aa, extractTxCommands as ab, extractTxSender as ac, fallbackLabel as ad, findSwapRoute as ae, formatAssetAmount as af, formatSui as ag, formatUsd as ah, getDecimals as ai, getDecimalsForCoinType as aj, mapMoveAbortCode as ak, mapWalletError as al, mistToSui as am, parseSuiRpcTx as an, payWithMpp as ao, preflightFail as ap, preflightPay as aq, preflightSend as ar, preflightSwap as as, rawToStable as at, rawToUsdc as au, refineLendingLabel as av, resolveSymbol as aw, resolveTokenType as ax, stableToRaw as ay, suiToMist as az, type ClassifyBalanceChange as b, getSuiClient as b0, getSuiGrpcClient as b1, isAllowedAsset as b2, isCetusRouteFresh as b3, isInRegistry as b4, normalizeAsset as b5, normalizeCoinType as b6, queryHistory as b7, queryTransaction as b8, selectAndSplitCoin as b9, selectSuiCoin as ba, serializeCetusRoute as bb, simulateTransaction as bc, throwIfSimulationFailed as bd, verifyCetusRouteCoinMatch as be, type ClassifyResult as c, type CoinMeta as d, type DepositInfo as e, type ExtractedTransfer as f, KeypairSigner as g, LOFI_TYPE as h, MIST_PER_SUI as i, type OverlayFeeConfig as j, PREFLIGHT_OK as k, type PayOptions as l, type PayResult as m, type PreflightResult as n, SUI_DECIMALS as o, SUI_TYPE as p, SUPPORTED_ASSETS as q, type SendResult as r, type SimulationResult as s, type StableAsset as t, type SuiHolding as u, type SuiRpcTxBlock as v, type SupportedAsset as w, type SwapRouteResult as x, type T2000ErrorCode as y, type T2000ErrorData as z };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@t2000/sdk",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.6.0",
|
|
4
4
|
"description": "TypeScript SDK for Agent Wallets on Sui — gasless USDC + USDsui transfers, Cetus swap routing, NAVI lending (programmatic), MPP paid API access, zkLogin compatible.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|