@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
package/dist/index.d.cts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { EventEmitter } from 'eventemitter3';
|
|
2
2
|
import { SuiGrpcClient } from '@mysten/sui/grpc';
|
|
3
3
|
import { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519';
|
|
4
|
-
import { T as T2000Error,
|
|
5
|
-
export {
|
|
6
|
-
import {
|
|
4
|
+
import { T as T2000Error, aD as T2000Options, Q as TransactionSigner, l as PayOptions, m as PayResult, aE as SwapResult, aF as SwapQuoteResult, w as SupportedAsset, r as SendResult, B as BalanceResponse, J as TransactionRecord, e as DepositInfo, aG as PaymentRequest, $ as ZkLoginProof, aH as SuiCoreClient, j as OverlayFeeConfig, aI as SponsoredCoinMergeCache, x as SwapRouteResult, aJ as SendableAsset } from './send-D2nKpwJN.cjs';
|
|
5
|
+
export { aK as CETUS_USDC_SUI_POOL, C as CLOCK_ID, a as COIN_REGISTRY, b as ClassifyBalanceChange, c as ClassifyResult, d as CoinMeta, aL as CoinPage, aM as DEFAULT_GRPC_URL, D as DEFAULT_NETWORK, E as ETH_TYPE, f as ExtractedTransfer, aN as GASLESS_MIN_STABLE_AMOUNT, aO as GASLESS_STABLE_TYPES, G as GAS_RESERVE_MIN, I as IKA_TYPE, K as KNOWN_TARGETS, g as KeypairSigner, L as LABEL_PATTERNS, h as LOFI_TYPE, M as MANIFEST_TYPE, i as MIST_PER_SUI, N as NAVX_TYPE, aP as OPERATION_ASSETS, O as OVERLAY_FEE_RATE, aQ as Operation, P as PREFLIGHT_MAX_AMOUNT, k as PREFLIGHT_OK, n as PreflightResult, aR as SENDABLE_ASSETS, S as STABLE_ASSETS, o as SUI_DECIMALS, p as SUI_TYPE, q as SUPPORTED_ASSETS, aS as SelectAndSplitResult, aT as SerializedCetusRoute, aU as SerializedCetusRoutePath, aV as SerializedRouterDataV3, s as SimulationResult, t as StableAsset, u as SuiHolding, v as SuiRpcTxBlock, y as T2000ErrorCode, z as T2000ErrorData, A as T2000_OVERLAY_FEE_WALLET, F as TOKEN_MAP, H as TransactionLeg, R as TxDirection, U as USDC_DECIMALS, V as USDC_TYPE, W as USDE_TYPE, X as USDSUI_TYPE, Y as USDT_TYPE, Z as WAL_TYPE, _ as WBTC_TYPE, a0 as ZkLoginSigner, aW as addSendToTx, aX as addSwapToTx, aY as assertAllowedAsset, a1 as buildSendTx, a2 as buildSwapTx, a3 as checkPositiveAmount, a4 as checkSuiAddress, a5 as classifyAction, a6 as classifyLabel, a7 as classifyTransaction, aZ as deserializeCetusRoute, a8 as executeTx, a9 as extractAllUserLegs, aa as extractTransferDetails, ab as extractTxCommands, ac as extractTxSender, ad as fallbackLabel, a_ as fetchAllCoins, ae as findSwapRoute, af as formatAssetAmount, ag as formatSui, ah as formatUsd, a$ as getCoinMeta, ai as getDecimals, aj as getDecimalsForCoinType, b0 as getSuiClient, b1 as getSuiGrpcClient, b2 as isAllowedAsset, b3 as isCetusRouteFresh, b4 as isInRegistry, ak as mapMoveAbortCode, al as mapWalletError, am as mistToSui, b5 as normalizeAsset, b6 as normalizeCoinType, an as parseSuiRpcTx, ao as payWithMpp, ap as preflightFail, aq as preflightPay, ar as preflightSend, as as preflightSwap, b7 as queryHistory, b8 as queryTransaction, at as rawToStable, au as rawToUsdc, av as refineLendingLabel, aw as resolveSymbol, ax as resolveTokenType, b9 as selectAndSplitCoin, ba as selectSuiCoin, bb as serializeCetusRoute, bc as simulateTransaction, ay as stableToRaw, az as suiToMist, bd as throwIfSimulationFailed, aA as truncateAddress, aB as usdcToRaw, aC as validateAddress, be as verifyCetusRouteCoinMatch } from './send-D2nKpwJN.cjs';
|
|
6
|
+
import { TransactionObjectArgument, Transaction } from '@mysten/sui/transactions';
|
|
7
7
|
import { SuinsClient } from '@mysten/suins';
|
|
8
8
|
import '@mysten/sui/client';
|
|
9
9
|
import '@cetusprotocol/aggregator-sdk';
|
|
@@ -376,6 +376,19 @@ declare function normalizeAddressInput(value: string, ctx?: {
|
|
|
376
376
|
signal?: AbortSignal;
|
|
377
377
|
}): Promise<NormalizedAddress>;
|
|
378
378
|
|
|
379
|
+
/**
|
|
380
|
+
* Full wallet balance: **every** held coin, not just the curated stables + SUI.
|
|
381
|
+
*
|
|
382
|
+
* Uses one `listBalances` (paginated) instead of N `getBalance` calls, then
|
|
383
|
+
* partitions: stables → priced $1, SUI → Cetus-oracle priced, **everything else
|
|
384
|
+
* → `tokens[]` amount-only** (`usdValue: null` — no price oracle for arbitrary
|
|
385
|
+
* tokens; we don't guess). Decimals for non-registry tokens are read on-chain
|
|
386
|
+
* (the only added call, and only for tokens you actually hold — necessary for a
|
|
387
|
+
* correct amount). `totalUsd` sums **priced holdings only** so it never
|
|
388
|
+
* overstates; `tokens` surfaces the rest honestly.
|
|
389
|
+
*/
|
|
390
|
+
declare function queryBalance(client: SuiCoreClient, address: string): Promise<BalanceResponse>;
|
|
391
|
+
|
|
379
392
|
declare function generateKeypair(): Ed25519Keypair;
|
|
380
393
|
declare function keypairFromPrivateKey(privateKey: string): Ed25519Keypair;
|
|
381
394
|
/**
|
|
@@ -409,72 +422,6 @@ declare function walletExists(keyPath?: string): Promise<boolean>;
|
|
|
409
422
|
declare function exportPrivateKey(keypair: Ed25519Keypair): string;
|
|
410
423
|
declare function getAddress(keypair: Ed25519Keypair): string;
|
|
411
424
|
|
|
412
|
-
/**
|
|
413
|
-
* Build a PTB that sends `amount` of `asset` from `address` to `to`.
|
|
414
|
-
*
|
|
415
|
-
* [v4.0 Phase A Day 2 — SPEC_AGENT_WALLET_GREENFIELD §A]
|
|
416
|
-
*
|
|
417
|
-
* Asset constraint: `'USDC' | 'USDsui' | 'SUI'` only. Other assets throw
|
|
418
|
-
* `INVALID_ASSET` via `assertAllowedAsset('send', asset)`. The constrained
|
|
419
|
-
* set matches Sui mainnet's gasless allowlist (USDC + USDsui) plus SUI
|
|
420
|
-
* for users who want a gas-native transfer.
|
|
421
|
-
*
|
|
422
|
-
* Build paths:
|
|
423
|
-
* - **USDC / USDsui** — `0x2::balance::send_funds` Move call with a
|
|
424
|
-
* `tx.balance({ type, balance })` input. When built via `SuiGrpcClient`,
|
|
425
|
-
* the gRPC resolver auto-detects gasless eligibility and zeros gas.
|
|
426
|
-
* When built via `SuiJsonRpcClient`, the same PTB still executes but
|
|
427
|
-
* the caller pays normal gas. Minimum 0.01 (protocol allowlist floor).
|
|
428
|
-
* - **SUI** — `tx.splitCoins(tx.gas, [amount]) → tx.transferObjects()`.
|
|
429
|
-
* Standard gas-native transfer. No minimum.
|
|
430
|
-
*
|
|
431
|
-
* Pre-flight balance check stays on JSON-RPC (`client.getBalance`) — it
|
|
432
|
-
* sums coin objects + address balance so the legacy `getCoins` page miss
|
|
433
|
-
* doesn't break for users whose stables landed via gasless deposits.
|
|
434
|
-
*
|
|
435
|
-
* `asset` is REQUIRED (no implicit USDC default — pre-v4 hid LLM intent
|
|
436
|
-
* errors). Callers passing the wrong asset get an explicit error rather
|
|
437
|
-
* than a silent currency substitution.
|
|
438
|
-
*/
|
|
439
|
-
declare function buildSendTx({ client, address, to, amount, asset, }: {
|
|
440
|
-
client: SuiCoreClient;
|
|
441
|
-
address: string;
|
|
442
|
-
to: string;
|
|
443
|
-
amount: number;
|
|
444
|
-
asset: SendableAsset;
|
|
445
|
-
}): Promise<Transaction>;
|
|
446
|
-
/**
|
|
447
|
-
* Fragment-appender for the chain-mode send leg of SPEC 7 multi-write
|
|
448
|
-
* Payment Intents. Consumes a coin reference produced by a previous
|
|
449
|
-
* appender (e.g. `addWithdrawToTx`, `addSwapToTx`) and transfers it to
|
|
450
|
-
* `recipient` within the same Payment Intent — no intermediate wallet
|
|
451
|
-
* materialization.
|
|
452
|
-
*
|
|
453
|
-
* Codifies the hand-built send leg from
|
|
454
|
-
* `scripts/smoke-spec7-withdraw-then-send.ts` (P2.1) into a typed
|
|
455
|
-
* appender. SPEC 7 § "Layer 1" — P2.2b will register this in the
|
|
456
|
-
* `WRITE_APPENDER_REGISTRY` under `send_transfer` for chain-mode
|
|
457
|
-
* dispatch; the registry adapter will handle the wallet-fetch fallback
|
|
458
|
-
* by delegating to `buildSendTx` when no upstream coin is available.
|
|
459
|
-
*
|
|
460
|
-
* For single-step send_transfer flows (no chained predecessor), use
|
|
461
|
-
* `buildSendTx` directly — it builds a complete tx including the
|
|
462
|
-
* wallet-coin selection / merge / split prelude.
|
|
463
|
-
*
|
|
464
|
-
* [v4.0 Phase A Day 2] Stays on the legacy `transferObjects` path
|
|
465
|
-
* because chain-mode bundles are NEVER gasless — by definition they
|
|
466
|
-
* combine multiple Move calls (`withdraw → send`, `swap → send`) which
|
|
467
|
-
* fail the protocol allowlist check (only `balance::send_funds` and
|
|
468
|
-
* a few related helpers are eligible). The bundled flow still works,
|
|
469
|
-
* the user just pays gas (or has it sponsored by audric via Enoki).
|
|
470
|
-
*
|
|
471
|
-
* @returns void — the coin is consumed by `tx.transferObjects`. Callers
|
|
472
|
-
* that need the post-transfer "effective amount" should rely on the
|
|
473
|
-
* upstream appender's `effectiveAmount` (e.g. `addWithdrawToTx`'s
|
|
474
|
-
* return), not on this appender.
|
|
475
|
-
*/
|
|
476
|
-
declare function addSendToTx(tx: Transaction, coin: TransactionObjectArgument, recipient: string): void;
|
|
477
|
-
|
|
478
425
|
/**
|
|
479
426
|
* SPEC 7 v0.4 § Layer 0 — Canonical Write Architecture.
|
|
480
427
|
*
|
|
@@ -981,4 +928,4 @@ declare function fullHandle(label: string): string;
|
|
|
981
928
|
*/
|
|
982
929
|
declare function displayHandle(label: string): string;
|
|
983
930
|
|
|
984
|
-
export { AUDRIC_PARENT_NAME, AUDRIC_PARENT_NFT_ID, type AppenderContext, BalanceResponse, type BuildAddLeafParams, type BuildRevokeLeafParams, type ComposeTxOptions, type ComposeTxResult, type DailySpend, DepositInfo, InvalidAddressError, type LabelValidationResult, type LimitAssertInput, LimitEnforcer, LimitExceededError, type LimitKind, type LimitOperation, type LimitsConfig, type LimitsFile, type NormalizedAddress, OverlayFeeConfig, PayOptions, PayResult, PaymentRequest, SPONSORED_PYTH_DEPENDENT_PROVIDERS, SUINS_NAME_REGEX, SUI_ADDRESS_REGEX, SUI_ADDRESS_STRICT_REGEX, SendResult, type SendTransferInput, SendableAsset, type StepPreview, SuinsNotRegisteredError, SuinsRpcError, SupportedAsset, type SwapExecuteInput, SwapQuoteResult, SwapResult, SwapRouteResult, T2000, T2000Error, T2000Options, TransactionRecord, TransactionSigner, WRITE_APPENDER_REGISTRY, type WriteStep, type WriteToolName, ZkLoginProof,
|
|
931
|
+
export { AUDRIC_PARENT_NAME, AUDRIC_PARENT_NFT_ID, type AppenderContext, BalanceResponse, type BuildAddLeafParams, type BuildRevokeLeafParams, type ComposeTxOptions, type ComposeTxResult, type DailySpend, DepositInfo, InvalidAddressError, type LabelValidationResult, type LimitAssertInput, LimitEnforcer, LimitExceededError, type LimitKind, type LimitOperation, type LimitsConfig, type LimitsFile, type NormalizedAddress, OverlayFeeConfig, PayOptions, PayResult, PaymentRequest, SPONSORED_PYTH_DEPENDENT_PROVIDERS, SUINS_NAME_REGEX, SUI_ADDRESS_REGEX, SUI_ADDRESS_STRICT_REGEX, SendResult, type SendTransferInput, SendableAsset, type StepPreview, SuinsNotRegisteredError, SuinsRpcError, SupportedAsset, type SwapExecuteInput, SwapQuoteResult, SwapResult, SwapRouteResult, T2000, T2000Error, T2000Options, TransactionRecord, TransactionSigner, WRITE_APPENDER_REGISTRY, type WriteStep, type WriteToolName, ZkLoginProof, approxUsdValue, assertLimitConfig, buildAddLeafTx, buildRevokeLeafTx, clearLimits, composeTx, dailySpentToday, deriveAllowedAddressesFromPtb, displayHandle, exportPrivateKey, fullHandle, generateKeypair, getAddress, getLimits, getSponsoredSwapProviders, getSwapQuote, hasLimits, keypairFromPrivateKey, loadKey, looksLikeSuiNs, normalizeAddressInput, queryBalance, readLimitsFile, recordDailySpend, resolveAddressToSuinsViaRpc, resolveSuinsViaRpc, saveBech32, saveKey, setLimits, validateLabel, walletExists, writeLimitsFile };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { EventEmitter } from 'eventemitter3';
|
|
2
2
|
import { SuiGrpcClient } from '@mysten/sui/grpc';
|
|
3
3
|
import { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519';
|
|
4
|
-
import { T as T2000Error,
|
|
5
|
-
export {
|
|
6
|
-
import {
|
|
4
|
+
import { T as T2000Error, aD as T2000Options, Q as TransactionSigner, l as PayOptions, m as PayResult, aE as SwapResult, aF as SwapQuoteResult, w as SupportedAsset, r as SendResult, B as BalanceResponse, J as TransactionRecord, e as DepositInfo, aG as PaymentRequest, $ as ZkLoginProof, aH as SuiCoreClient, j as OverlayFeeConfig, aI as SponsoredCoinMergeCache, x as SwapRouteResult, aJ as SendableAsset } from './send-D2nKpwJN.js';
|
|
5
|
+
export { aK as CETUS_USDC_SUI_POOL, C as CLOCK_ID, a as COIN_REGISTRY, b as ClassifyBalanceChange, c as ClassifyResult, d as CoinMeta, aL as CoinPage, aM as DEFAULT_GRPC_URL, D as DEFAULT_NETWORK, E as ETH_TYPE, f as ExtractedTransfer, aN as GASLESS_MIN_STABLE_AMOUNT, aO as GASLESS_STABLE_TYPES, G as GAS_RESERVE_MIN, I as IKA_TYPE, K as KNOWN_TARGETS, g as KeypairSigner, L as LABEL_PATTERNS, h as LOFI_TYPE, M as MANIFEST_TYPE, i as MIST_PER_SUI, N as NAVX_TYPE, aP as OPERATION_ASSETS, O as OVERLAY_FEE_RATE, aQ as Operation, P as PREFLIGHT_MAX_AMOUNT, k as PREFLIGHT_OK, n as PreflightResult, aR as SENDABLE_ASSETS, S as STABLE_ASSETS, o as SUI_DECIMALS, p as SUI_TYPE, q as SUPPORTED_ASSETS, aS as SelectAndSplitResult, aT as SerializedCetusRoute, aU as SerializedCetusRoutePath, aV as SerializedRouterDataV3, s as SimulationResult, t as StableAsset, u as SuiHolding, v as SuiRpcTxBlock, y as T2000ErrorCode, z as T2000ErrorData, A as T2000_OVERLAY_FEE_WALLET, F as TOKEN_MAP, H as TransactionLeg, R as TxDirection, U as USDC_DECIMALS, V as USDC_TYPE, W as USDE_TYPE, X as USDSUI_TYPE, Y as USDT_TYPE, Z as WAL_TYPE, _ as WBTC_TYPE, a0 as ZkLoginSigner, aW as addSendToTx, aX as addSwapToTx, aY as assertAllowedAsset, a1 as buildSendTx, a2 as buildSwapTx, a3 as checkPositiveAmount, a4 as checkSuiAddress, a5 as classifyAction, a6 as classifyLabel, a7 as classifyTransaction, aZ as deserializeCetusRoute, a8 as executeTx, a9 as extractAllUserLegs, aa as extractTransferDetails, ab as extractTxCommands, ac as extractTxSender, ad as fallbackLabel, a_ as fetchAllCoins, ae as findSwapRoute, af as formatAssetAmount, ag as formatSui, ah as formatUsd, a$ as getCoinMeta, ai as getDecimals, aj as getDecimalsForCoinType, b0 as getSuiClient, b1 as getSuiGrpcClient, b2 as isAllowedAsset, b3 as isCetusRouteFresh, b4 as isInRegistry, ak as mapMoveAbortCode, al as mapWalletError, am as mistToSui, b5 as normalizeAsset, b6 as normalizeCoinType, an as parseSuiRpcTx, ao as payWithMpp, ap as preflightFail, aq as preflightPay, ar as preflightSend, as as preflightSwap, b7 as queryHistory, b8 as queryTransaction, at as rawToStable, au as rawToUsdc, av as refineLendingLabel, aw as resolveSymbol, ax as resolveTokenType, b9 as selectAndSplitCoin, ba as selectSuiCoin, bb as serializeCetusRoute, bc as simulateTransaction, ay as stableToRaw, az as suiToMist, bd as throwIfSimulationFailed, aA as truncateAddress, aB as usdcToRaw, aC as validateAddress, be as verifyCetusRouteCoinMatch } from './send-D2nKpwJN.js';
|
|
6
|
+
import { TransactionObjectArgument, Transaction } from '@mysten/sui/transactions';
|
|
7
7
|
import { SuinsClient } from '@mysten/suins';
|
|
8
8
|
import '@mysten/sui/client';
|
|
9
9
|
import '@cetusprotocol/aggregator-sdk';
|
|
@@ -376,6 +376,19 @@ declare function normalizeAddressInput(value: string, ctx?: {
|
|
|
376
376
|
signal?: AbortSignal;
|
|
377
377
|
}): Promise<NormalizedAddress>;
|
|
378
378
|
|
|
379
|
+
/**
|
|
380
|
+
* Full wallet balance: **every** held coin, not just the curated stables + SUI.
|
|
381
|
+
*
|
|
382
|
+
* Uses one `listBalances` (paginated) instead of N `getBalance` calls, then
|
|
383
|
+
* partitions: stables → priced $1, SUI → Cetus-oracle priced, **everything else
|
|
384
|
+
* → `tokens[]` amount-only** (`usdValue: null` — no price oracle for arbitrary
|
|
385
|
+
* tokens; we don't guess). Decimals for non-registry tokens are read on-chain
|
|
386
|
+
* (the only added call, and only for tokens you actually hold — necessary for a
|
|
387
|
+
* correct amount). `totalUsd` sums **priced holdings only** so it never
|
|
388
|
+
* overstates; `tokens` surfaces the rest honestly.
|
|
389
|
+
*/
|
|
390
|
+
declare function queryBalance(client: SuiCoreClient, address: string): Promise<BalanceResponse>;
|
|
391
|
+
|
|
379
392
|
declare function generateKeypair(): Ed25519Keypair;
|
|
380
393
|
declare function keypairFromPrivateKey(privateKey: string): Ed25519Keypair;
|
|
381
394
|
/**
|
|
@@ -409,72 +422,6 @@ declare function walletExists(keyPath?: string): Promise<boolean>;
|
|
|
409
422
|
declare function exportPrivateKey(keypair: Ed25519Keypair): string;
|
|
410
423
|
declare function getAddress(keypair: Ed25519Keypair): string;
|
|
411
424
|
|
|
412
|
-
/**
|
|
413
|
-
* Build a PTB that sends `amount` of `asset` from `address` to `to`.
|
|
414
|
-
*
|
|
415
|
-
* [v4.0 Phase A Day 2 — SPEC_AGENT_WALLET_GREENFIELD §A]
|
|
416
|
-
*
|
|
417
|
-
* Asset constraint: `'USDC' | 'USDsui' | 'SUI'` only. Other assets throw
|
|
418
|
-
* `INVALID_ASSET` via `assertAllowedAsset('send', asset)`. The constrained
|
|
419
|
-
* set matches Sui mainnet's gasless allowlist (USDC + USDsui) plus SUI
|
|
420
|
-
* for users who want a gas-native transfer.
|
|
421
|
-
*
|
|
422
|
-
* Build paths:
|
|
423
|
-
* - **USDC / USDsui** — `0x2::balance::send_funds` Move call with a
|
|
424
|
-
* `tx.balance({ type, balance })` input. When built via `SuiGrpcClient`,
|
|
425
|
-
* the gRPC resolver auto-detects gasless eligibility and zeros gas.
|
|
426
|
-
* When built via `SuiJsonRpcClient`, the same PTB still executes but
|
|
427
|
-
* the caller pays normal gas. Minimum 0.01 (protocol allowlist floor).
|
|
428
|
-
* - **SUI** — `tx.splitCoins(tx.gas, [amount]) → tx.transferObjects()`.
|
|
429
|
-
* Standard gas-native transfer. No minimum.
|
|
430
|
-
*
|
|
431
|
-
* Pre-flight balance check stays on JSON-RPC (`client.getBalance`) — it
|
|
432
|
-
* sums coin objects + address balance so the legacy `getCoins` page miss
|
|
433
|
-
* doesn't break for users whose stables landed via gasless deposits.
|
|
434
|
-
*
|
|
435
|
-
* `asset` is REQUIRED (no implicit USDC default — pre-v4 hid LLM intent
|
|
436
|
-
* errors). Callers passing the wrong asset get an explicit error rather
|
|
437
|
-
* than a silent currency substitution.
|
|
438
|
-
*/
|
|
439
|
-
declare function buildSendTx({ client, address, to, amount, asset, }: {
|
|
440
|
-
client: SuiCoreClient;
|
|
441
|
-
address: string;
|
|
442
|
-
to: string;
|
|
443
|
-
amount: number;
|
|
444
|
-
asset: SendableAsset;
|
|
445
|
-
}): Promise<Transaction>;
|
|
446
|
-
/**
|
|
447
|
-
* Fragment-appender for the chain-mode send leg of SPEC 7 multi-write
|
|
448
|
-
* Payment Intents. Consumes a coin reference produced by a previous
|
|
449
|
-
* appender (e.g. `addWithdrawToTx`, `addSwapToTx`) and transfers it to
|
|
450
|
-
* `recipient` within the same Payment Intent — no intermediate wallet
|
|
451
|
-
* materialization.
|
|
452
|
-
*
|
|
453
|
-
* Codifies the hand-built send leg from
|
|
454
|
-
* `scripts/smoke-spec7-withdraw-then-send.ts` (P2.1) into a typed
|
|
455
|
-
* appender. SPEC 7 § "Layer 1" — P2.2b will register this in the
|
|
456
|
-
* `WRITE_APPENDER_REGISTRY` under `send_transfer` for chain-mode
|
|
457
|
-
* dispatch; the registry adapter will handle the wallet-fetch fallback
|
|
458
|
-
* by delegating to `buildSendTx` when no upstream coin is available.
|
|
459
|
-
*
|
|
460
|
-
* For single-step send_transfer flows (no chained predecessor), use
|
|
461
|
-
* `buildSendTx` directly — it builds a complete tx including the
|
|
462
|
-
* wallet-coin selection / merge / split prelude.
|
|
463
|
-
*
|
|
464
|
-
* [v4.0 Phase A Day 2] Stays on the legacy `transferObjects` path
|
|
465
|
-
* because chain-mode bundles are NEVER gasless — by definition they
|
|
466
|
-
* combine multiple Move calls (`withdraw → send`, `swap → send`) which
|
|
467
|
-
* fail the protocol allowlist check (only `balance::send_funds` and
|
|
468
|
-
* a few related helpers are eligible). The bundled flow still works,
|
|
469
|
-
* the user just pays gas (or has it sponsored by audric via Enoki).
|
|
470
|
-
*
|
|
471
|
-
* @returns void — the coin is consumed by `tx.transferObjects`. Callers
|
|
472
|
-
* that need the post-transfer "effective amount" should rely on the
|
|
473
|
-
* upstream appender's `effectiveAmount` (e.g. `addWithdrawToTx`'s
|
|
474
|
-
* return), not on this appender.
|
|
475
|
-
*/
|
|
476
|
-
declare function addSendToTx(tx: Transaction, coin: TransactionObjectArgument, recipient: string): void;
|
|
477
|
-
|
|
478
425
|
/**
|
|
479
426
|
* SPEC 7 v0.4 § Layer 0 — Canonical Write Architecture.
|
|
480
427
|
*
|
|
@@ -981,4 +928,4 @@ declare function fullHandle(label: string): string;
|
|
|
981
928
|
*/
|
|
982
929
|
declare function displayHandle(label: string): string;
|
|
983
930
|
|
|
984
|
-
export { AUDRIC_PARENT_NAME, AUDRIC_PARENT_NFT_ID, type AppenderContext, BalanceResponse, type BuildAddLeafParams, type BuildRevokeLeafParams, type ComposeTxOptions, type ComposeTxResult, type DailySpend, DepositInfo, InvalidAddressError, type LabelValidationResult, type LimitAssertInput, LimitEnforcer, LimitExceededError, type LimitKind, type LimitOperation, type LimitsConfig, type LimitsFile, type NormalizedAddress, OverlayFeeConfig, PayOptions, PayResult, PaymentRequest, SPONSORED_PYTH_DEPENDENT_PROVIDERS, SUINS_NAME_REGEX, SUI_ADDRESS_REGEX, SUI_ADDRESS_STRICT_REGEX, SendResult, type SendTransferInput, SendableAsset, type StepPreview, SuinsNotRegisteredError, SuinsRpcError, SupportedAsset, type SwapExecuteInput, SwapQuoteResult, SwapResult, SwapRouteResult, T2000, T2000Error, T2000Options, TransactionRecord, TransactionSigner, WRITE_APPENDER_REGISTRY, type WriteStep, type WriteToolName, ZkLoginProof,
|
|
931
|
+
export { AUDRIC_PARENT_NAME, AUDRIC_PARENT_NFT_ID, type AppenderContext, BalanceResponse, type BuildAddLeafParams, type BuildRevokeLeafParams, type ComposeTxOptions, type ComposeTxResult, type DailySpend, DepositInfo, InvalidAddressError, type LabelValidationResult, type LimitAssertInput, LimitEnforcer, LimitExceededError, type LimitKind, type LimitOperation, type LimitsConfig, type LimitsFile, type NormalizedAddress, OverlayFeeConfig, PayOptions, PayResult, PaymentRequest, SPONSORED_PYTH_DEPENDENT_PROVIDERS, SUINS_NAME_REGEX, SUI_ADDRESS_REGEX, SUI_ADDRESS_STRICT_REGEX, SendResult, type SendTransferInput, SendableAsset, type StepPreview, SuinsNotRegisteredError, SuinsRpcError, SupportedAsset, type SwapExecuteInput, SwapQuoteResult, SwapResult, SwapRouteResult, T2000, T2000Error, T2000Options, TransactionRecord, TransactionSigner, WRITE_APPENDER_REGISTRY, type WriteStep, type WriteToolName, ZkLoginProof, approxUsdValue, assertLimitConfig, buildAddLeafTx, buildRevokeLeafTx, clearLimits, composeTx, dailySpentToday, deriveAllowedAddressesFromPtb, displayHandle, exportPrivateKey, fullHandle, generateKeypair, getAddress, getLimits, getSponsoredSwapProviders, getSwapQuote, hasLimits, keypairFromPrivateKey, loadKey, looksLikeSuiNs, normalizeAddressInput, queryBalance, readLimitsFile, recordDailySpend, resolveAddressToSuinsViaRpc, resolveSuinsViaRpc, saveBech32, saveKey, setLimits, validateLabel, walletExists, writeLimitsFile };
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { normalizeStructTag, isValidSuiAddress, normalizeSuiAddress, fromBase64 } from '@mysten/sui/utils';
|
|
1
2
|
import { coinWithBalance, Transaction } from '@mysten/sui/transactions';
|
|
2
3
|
import { AggregatorClient, Env } from '@cetusprotocol/aggregator-sdk';
|
|
3
4
|
import BN from 'bn.js';
|
|
@@ -5,7 +6,6 @@ import { EventEmitter } from 'eventemitter3';
|
|
|
5
6
|
import { createPaymentTransactionUri } from '@mysten/payment-kit';
|
|
6
7
|
import { SuiGrpcClient } from '@mysten/sui/grpc';
|
|
7
8
|
import { SuiGraphQLClient } from '@mysten/sui/graphql';
|
|
8
|
-
import { normalizeStructTag, normalizeSuiAddress, isValidSuiAddress, fromBase64 } from '@mysten/sui/utils';
|
|
9
9
|
import { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519';
|
|
10
10
|
import { decodeSuiPrivateKey } from '@mysten/sui/cryptography';
|
|
11
11
|
import { access, mkdir, writeFile, readFile } from 'fs/promises';
|
|
@@ -112,6 +112,37 @@ var init_errors = __esm({
|
|
|
112
112
|
};
|
|
113
113
|
}
|
|
114
114
|
});
|
|
115
|
+
function preflightFail(code, error) {
|
|
116
|
+
return { valid: false, code, error };
|
|
117
|
+
}
|
|
118
|
+
function checkPositiveAmount(amount, label = "Amount", max = PREFLIGHT_MAX_AMOUNT) {
|
|
119
|
+
if (typeof amount !== "number" || !Number.isFinite(amount)) {
|
|
120
|
+
return preflightFail("INVALID_AMOUNT", `${label} must be a finite number`);
|
|
121
|
+
}
|
|
122
|
+
if (amount <= 0) {
|
|
123
|
+
return preflightFail("INVALID_AMOUNT", `${label} must be greater than zero`);
|
|
124
|
+
}
|
|
125
|
+
if (amount > max) {
|
|
126
|
+
return preflightFail("INVALID_AMOUNT", `${label} ${amount} exceeds the sane maximum (${max})`);
|
|
127
|
+
}
|
|
128
|
+
return PREFLIGHT_OK;
|
|
129
|
+
}
|
|
130
|
+
function checkSuiAddress(address, label = "recipient") {
|
|
131
|
+
try {
|
|
132
|
+
if (typeof address === "string" && address.trim() !== "" && isValidSuiAddress(normalizeSuiAddress(address))) {
|
|
133
|
+
return PREFLIGHT_OK;
|
|
134
|
+
}
|
|
135
|
+
} catch {
|
|
136
|
+
}
|
|
137
|
+
return preflightFail("INVALID_ADDRESS", `Invalid ${label} address: ${address}`);
|
|
138
|
+
}
|
|
139
|
+
var PREFLIGHT_MAX_AMOUNT, PREFLIGHT_OK;
|
|
140
|
+
var init_preflight = __esm({
|
|
141
|
+
"src/preflight.ts"() {
|
|
142
|
+
PREFLIGHT_MAX_AMOUNT = 1e6;
|
|
143
|
+
PREFLIGHT_OK = { valid: true };
|
|
144
|
+
}
|
|
145
|
+
});
|
|
115
146
|
|
|
116
147
|
// src/token-registry.ts
|
|
117
148
|
var token_registry_exports = {};
|
|
@@ -376,10 +407,28 @@ __export(cetus_swap_exports, {
|
|
|
376
407
|
findSwapRoute: () => findSwapRoute,
|
|
377
408
|
isCetusRouteFresh: () => isCetusRouteFresh,
|
|
378
409
|
isPrecomputedRouteCompatibleWithProviders: () => isPrecomputedRouteCompatibleWithProviders,
|
|
410
|
+
preflightSwap: () => preflightSwap,
|
|
379
411
|
resolveTokenType: () => resolveTokenType,
|
|
380
412
|
serializeCetusRoute: () => serializeCetusRoute,
|
|
381
413
|
verifyCetusRouteCoinMatch: () => verifyCetusRouteCoinMatch
|
|
382
414
|
});
|
|
415
|
+
function preflightSwap(input) {
|
|
416
|
+
if (typeof input.from !== "string" || input.from.trim() === "") {
|
|
417
|
+
return preflightFail("INVALID_ASSET", "A `from` token is required to swap");
|
|
418
|
+
}
|
|
419
|
+
if (typeof input.to !== "string" || input.to.trim() === "") {
|
|
420
|
+
return preflightFail("INVALID_ASSET", "A `to` token is required to swap");
|
|
421
|
+
}
|
|
422
|
+
const amountCheck = checkPositiveAmount(input.amount, "Amount", Number.POSITIVE_INFINITY);
|
|
423
|
+
if (!amountCheck.valid) return amountCheck;
|
|
424
|
+
const resolvedFrom = resolveTokenType(input.from);
|
|
425
|
+
const resolvedTo = resolveTokenType(input.to);
|
|
426
|
+
const sameToken = input.from.trim() === input.to.trim() || resolvedFrom !== null && resolvedFrom === resolvedTo;
|
|
427
|
+
if (sameToken) {
|
|
428
|
+
return preflightFail("INVALID_ASSET", `Cannot swap ${input.from} to itself`);
|
|
429
|
+
}
|
|
430
|
+
return PREFLIGHT_OK;
|
|
431
|
+
}
|
|
383
432
|
function serializeCetusRoute(route, context) {
|
|
384
433
|
return {
|
|
385
434
|
routerData: serializeRouterDataV3(route.routerData),
|
|
@@ -631,6 +680,7 @@ var OVERLAY_FEE_RATE, clientCache;
|
|
|
631
680
|
var init_cetus_swap = __esm({
|
|
632
681
|
"src/protocols/cetus-swap.ts"() {
|
|
633
682
|
init_token_registry();
|
|
683
|
+
init_preflight();
|
|
634
684
|
init_token_registry();
|
|
635
685
|
OVERLAY_FEE_RATE = 1e-3;
|
|
636
686
|
clientCache = /* @__PURE__ */ new Map();
|
|
@@ -1004,8 +1054,33 @@ async function executeTx(client, signer, buildTx, options = {}) {
|
|
|
1004
1054
|
|
|
1005
1055
|
// src/wallet/pay.ts
|
|
1006
1056
|
init_errors();
|
|
1057
|
+
init_preflight();
|
|
1058
|
+
function preflightPay(input) {
|
|
1059
|
+
if (typeof input.url !== "string" || input.url.trim() === "") {
|
|
1060
|
+
return preflightFail("FACILITATOR_REJECTION", "A target URL is required to pay");
|
|
1061
|
+
}
|
|
1062
|
+
let parsed;
|
|
1063
|
+
try {
|
|
1064
|
+
parsed = new URL(input.url);
|
|
1065
|
+
} catch {
|
|
1066
|
+
return preflightFail("FACILITATOR_REJECTION", `Invalid URL: ${input.url}`);
|
|
1067
|
+
}
|
|
1068
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
|
|
1069
|
+
return preflightFail(
|
|
1070
|
+
"FACILITATOR_REJECTION",
|
|
1071
|
+
`URL must be http(s): got ${parsed.protocol}//`
|
|
1072
|
+
);
|
|
1073
|
+
}
|
|
1074
|
+
if (input.maxPrice !== void 0) {
|
|
1075
|
+
const priceCheck = checkPositiveAmount(input.maxPrice, "maxPrice");
|
|
1076
|
+
if (!priceCheck.valid) return priceCheck;
|
|
1077
|
+
}
|
|
1078
|
+
return PREFLIGHT_OK;
|
|
1079
|
+
}
|
|
1007
1080
|
async function payWithMpp(args) {
|
|
1008
1081
|
const { signer, client, options } = args;
|
|
1082
|
+
const pf = preflightPay({ url: options.url, maxPrice: options.maxPrice });
|
|
1083
|
+
if (!pf.valid) throw new T2000Error(pf.code, pf.error);
|
|
1009
1084
|
const method = (options.method ?? "GET").toUpperCase();
|
|
1010
1085
|
const canHaveBody = method !== "GET" && method !== "HEAD";
|
|
1011
1086
|
const reqInit = {
|
|
@@ -1240,6 +1315,25 @@ function normalizeAsset(input) {
|
|
|
1240
1315
|
}
|
|
1241
1316
|
|
|
1242
1317
|
// src/wallet/send.ts
|
|
1318
|
+
init_preflight();
|
|
1319
|
+
function preflightSend(input) {
|
|
1320
|
+
try {
|
|
1321
|
+
assertAllowedAsset("send", input.asset);
|
|
1322
|
+
} catch (e) {
|
|
1323
|
+
return preflightFail("INVALID_ASSET", e.message);
|
|
1324
|
+
}
|
|
1325
|
+
const amountCheck = checkPositiveAmount(input.amount);
|
|
1326
|
+
if (!amountCheck.valid) return amountCheck;
|
|
1327
|
+
if ((input.asset === "USDC" || input.asset === "USDsui") && input.amount < GASLESS_MIN_STABLE_AMOUNT) {
|
|
1328
|
+
return preflightFail(
|
|
1329
|
+
"INVALID_AMOUNT",
|
|
1330
|
+
`Minimum gasless transfer is ${GASLESS_MIN_STABLE_AMOUNT} ${input.asset}. Got ${input.amount}.`
|
|
1331
|
+
);
|
|
1332
|
+
}
|
|
1333
|
+
const addressCheck = checkSuiAddress(input.to);
|
|
1334
|
+
if (!addressCheck.valid) return addressCheck;
|
|
1335
|
+
return PREFLIGHT_OK;
|
|
1336
|
+
}
|
|
1243
1337
|
async function buildSendTx({
|
|
1244
1338
|
client,
|
|
1245
1339
|
address,
|
|
@@ -1247,17 +1341,11 @@ async function buildSendTx({
|
|
|
1247
1341
|
amount,
|
|
1248
1342
|
asset
|
|
1249
1343
|
}) {
|
|
1250
|
-
|
|
1344
|
+
const pf = preflightSend({ to, amount, asset });
|
|
1345
|
+
if (!pf.valid) throw new T2000Error(pf.code, pf.error);
|
|
1251
1346
|
const recipient = validateAddress(to);
|
|
1252
1347
|
const assetInfo = SUPPORTED_ASSETS[asset];
|
|
1253
1348
|
if (!assetInfo) throw new T2000Error("ASSET_NOT_SUPPORTED", `Asset ${asset} is not supported`);
|
|
1254
|
-
if (amount <= 0) throw new T2000Error("INVALID_AMOUNT", "Amount must be greater than zero");
|
|
1255
|
-
if ((asset === "USDC" || asset === "USDsui") && amount < GASLESS_MIN_STABLE_AMOUNT) {
|
|
1256
|
-
throw new T2000Error(
|
|
1257
|
-
"INVALID_AMOUNT",
|
|
1258
|
-
`Minimum gasless transfer is ${GASLESS_MIN_STABLE_AMOUNT} ${asset}. Got ${amount}.`
|
|
1259
|
-
);
|
|
1260
|
-
}
|
|
1261
1349
|
const rawAmount = displayToRaw(amount, assetInfo.decimals);
|
|
1262
1350
|
const tx = new Transaction();
|
|
1263
1351
|
tx.setSender(address);
|
|
@@ -2053,7 +2141,9 @@ var T2000 = class _T2000 extends EventEmitter {
|
|
|
2053
2141
|
amountUsd: approxUsdValue(params.from, params.amount) ?? 0,
|
|
2054
2142
|
force: params.force
|
|
2055
2143
|
});
|
|
2056
|
-
const { findSwapRoute: findSwapRoute2, buildSwapTx: buildSwapTx2, resolveTokenType: resolveTokenType2 } = await Promise.resolve().then(() => (init_cetus_swap(), cetus_swap_exports));
|
|
2144
|
+
const { findSwapRoute: findSwapRoute2, buildSwapTx: buildSwapTx2, resolveTokenType: resolveTokenType2, preflightSwap: preflightSwap2 } = await Promise.resolve().then(() => (init_cetus_swap(), cetus_swap_exports));
|
|
2145
|
+
const pf = preflightSwap2({ from: params.from, to: params.to, amount: params.amount });
|
|
2146
|
+
if (!pf.valid) throw new T2000Error(pf.code, pf.error);
|
|
2057
2147
|
const fromType = resolveTokenType2(params.from);
|
|
2058
2148
|
const toType = resolveTokenType2(params.to);
|
|
2059
2149
|
if (!fromType) throw new T2000Error("ASSET_NOT_SUPPORTED", `Unknown token: ${params.from}. Provide the full coin type.`);
|
|
@@ -2783,6 +2873,9 @@ function displayHandle(label) {
|
|
|
2783
2873
|
return `${label}@${parentDisplay}`;
|
|
2784
2874
|
}
|
|
2785
2875
|
|
|
2786
|
-
|
|
2876
|
+
// src/index.ts
|
|
2877
|
+
init_preflight();
|
|
2878
|
+
|
|
2879
|
+
export { AUDRIC_PARENT_NAME, AUDRIC_PARENT_NFT_ID, CETUS_USDC_SUI_POOL, CLOCK_ID, COIN_REGISTRY, DEFAULT_GRPC_URL, DEFAULT_NETWORK, ETH_TYPE, GASLESS_MIN_STABLE_AMOUNT, GASLESS_STABLE_TYPES, GAS_RESERVE_MIN, IKA_TYPE, InvalidAddressError, KNOWN_TARGETS, KeypairSigner, LABEL_PATTERNS, LOFI_TYPE, LimitEnforcer, LimitExceededError, MANIFEST_TYPE, MIST_PER_SUI, NAVX_TYPE, OPERATION_ASSETS, OVERLAY_FEE_RATE, PREFLIGHT_MAX_AMOUNT, PREFLIGHT_OK, SENDABLE_ASSETS, SPONSORED_PYTH_DEPENDENT_PROVIDERS, STABLE_ASSETS, SUINS_NAME_REGEX, SUI_ADDRESS_REGEX, SUI_ADDRESS_STRICT_REGEX, SUI_DECIMALS, SUI_TYPE, SUPPORTED_ASSETS, SuinsNotRegisteredError, SuinsRpcError, T2000, T2000Error, T2000_OVERLAY_FEE_WALLET, TOKEN_MAP, USDC_DECIMALS, USDC_TYPE, USDE_TYPE, USDSUI_TYPE, USDT_TYPE, WAL_TYPE, WBTC_TYPE, WRITE_APPENDER_REGISTRY, ZkLoginSigner, addSendToTx, addSwapToTx, approxUsdValue, assertAllowedAsset, assertLimitConfig, buildAddLeafTx, buildRevokeLeafTx, buildSendTx, buildSwapTx, checkPositiveAmount, checkSuiAddress, classifyAction, classifyLabel, classifyTransaction, clearLimits, composeTx, dailySpentToday, deriveAllowedAddressesFromPtb, deserializeCetusRoute, displayHandle, executeTx, exportPrivateKey, extractAllUserLegs, extractTransferDetails, extractTxCommands, extractTxSender, fallbackLabel, fetchAllCoins, findSwapRoute, formatAssetAmount, formatSui, formatUsd, fullHandle, generateKeypair, getAddress, getCoinMeta, getDecimals, getDecimalsForCoinType, getLimits, getSponsoredSwapProviders, getSuiClient, getSuiGrpcClient, getSwapQuote, hasLimits, isAllowedAsset, isCetusRouteFresh, isInRegistry, keypairFromPrivateKey, loadKey, looksLikeSuiNs, mapMoveAbortCode, mapWalletError, mistToSui, normalizeAddressInput, normalizeAsset, normalizeCoinType, parseSuiRpcTx, payWithMpp, preflightFail, preflightPay, preflightSend, preflightSwap, queryBalance, queryHistory, queryTransaction, rawToStable, rawToUsdc, readLimitsFile, recordDailySpend, refineLendingLabel, resolveAddressToSuinsViaRpc, resolveSuinsViaRpc, resolveSymbol, resolveTokenType, saveBech32, saveKey, selectAndSplitCoin, selectSuiCoin, serializeCetusRoute, setLimits, simulateTransaction, stableToRaw, suiToMist, throwIfSimulationFailed, truncateAddress, usdcToRaw, validateAddress, validateLabel, verifyCetusRouteCoinMatch, walletExists, writeLimitsFile };
|
|
2787
2880
|
//# sourceMappingURL=index.js.map
|
|
2788
2881
|
//# sourceMappingURL=index.js.map
|