@t2000/sdk 1.24.2 → 1.24.5

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 CHANGED
@@ -590,7 +590,7 @@ var FEE_RATES = {
590
590
  function calculateFee(operation, amount) {
591
591
  const bps = FEE_RATES[operation];
592
592
  const feeAmount = amount * Number(bps) / Number(BPS_DENOMINATOR);
593
- const rawAmount = usdcToRaw(feeAmount);
593
+ const rawAmount = stableToRaw(feeAmount, USDC_DECIMALS);
594
594
  return {
595
595
  amount: feeAmount,
596
596
  asset: "USDC",
@@ -598,11 +598,11 @@ function calculateFee(operation, amount) {
598
598
  rawAmount
599
599
  };
600
600
  }
601
- function addFeeTransfer(tx, paymentCoin, feeBps, receiver, amount) {
601
+ function addFeeTransfer(tx, paymentCoin, feeBps, receiver, amount, decimals = USDC_DECIMALS) {
602
602
  if (feeBps <= 0n) return;
603
603
  if (amount <= 0) return;
604
604
  const feeAmount = amount * Number(feeBps) / Number(BPS_DENOMINATOR);
605
- const rawFee = usdcToRaw(feeAmount);
605
+ const rawFee = stableToRaw(feeAmount, decimals);
606
606
  if (rawFee <= 0n) return;
607
607
  const [feeCoin] = tx.splitCoins(paymentCoin, [tx.pure.u64(rawFee)]);
608
608
  tx.transferObjects([feeCoin], tx.pure.address(receiver));
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/errors.ts","../src/token-registry.ts","../src/wallet/keypairSigner.ts","../src/wallet/zkLoginSigner.ts","../src/browser.ts","../src/constants.ts","../src/utils/sui.ts","../src/wallet/classify.ts","../src/wallet/history.ts","../src/utils/format.ts","../src/utils/base64.ts","../src/protocols/protocolFee.ts","../src/protocols/cetus-swap.ts","../src/safeguards/errors.ts","../src/safeguards/types.ts"],"names":["T2000Error","TOKEN_MAP","COIN_REGISTRY","SUI_TYPE","USDC_TYPE","USDT_TYPE","USDSUI_TYPE","USDE_TYPE","ETH_TYPE","WBTC_TYPE","WAL_TYPE","NAVX_T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,GAAA,CAA6B;AAAA,EAC3D,MAAA;AAAA,EACA;AACF,CAAC;AAEM,IAAM,wBAAA,GAA4C;AAAA,EACvD,MAAA,EAAQ,KAAA;AAAA,EACR,QAAA,EAAU,CAAA;AAAA,EACV,YAAA,EAAc,CAAA;AAAA,EACd,SAAA,EAAW,CAAA;AAAA,EACX,cAAA,EAAgB;AAClB;;;AVmGA,mBAAA,EAAA","file":"browser.cjs","sourcesContent":["export type T2000ErrorCode =\n | 'INSUFFICIENT_BALANCE'\n | 'INSUFFICIENT_GAS'\n | 'INVALID_ADDRESS'\n | 'INVALID_AMOUNT'\n | 'WALLET_NOT_FOUND'\n | 'WALLET_LOCKED'\n | 'WALLET_EXISTS'\n | 'SIMULATION_FAILED'\n | 'TRANSACTION_FAILED'\n | 'ASSET_NOT_SUPPORTED'\n | 'INVALID_ASSET'\n | 'HEALTH_FACTOR_TOO_LOW'\n | 'WITHDRAW_WOULD_LIQUIDATE'\n | 'WITHDRAW_FAILED'\n | 'NO_COLLATERAL'\n | 'PROTOCOL_PAUSED'\n | 'PROTOCOL_UNAVAILABLE'\n | 'RPC_ERROR'\n | 'RPC_UNREACHABLE'\n | 'PRICE_EXCEEDS_LIMIT'\n | 'UNSUPPORTED_NETWORK'\n | 'PAYMENT_EXPIRED'\n | 'DUPLICATE_PAYMENT'\n | 'FACILITATOR_REJECTION'\n | 'CONTACT_NOT_FOUND'\n | 'INVALID_CONTACT_NAME'\n | 'FACILITATOR_TIMEOUT'\n | 'SAFEGUARD_BLOCKED'\n | 'SWAP_NO_ROUTE'\n | 'SWAP_FAILED'\n | 'CHAIN_MODE_INVALID'\n | 'UNKNOWN';\n\nexport interface T2000ErrorData {\n reason?: string;\n [key: string]: unknown;\n}\n\nexport class T2000Error extends Error {\n readonly code: T2000ErrorCode;\n readonly data?: T2000ErrorData;\n readonly retryable: boolean;\n\n constructor(code: T2000ErrorCode, message: string, data?: T2000ErrorData, retryable = false) {\n super(message);\n this.name = 'T2000Error';\n this.code = code;\n this.data = data;\n this.retryable = retryable;\n }\n\n toJSON() {\n return {\n error: this.code,\n message: this.message,\n ...(this.data && { data: this.data }),\n retryable: this.retryable,\n };\n }\n}\n\nexport function mapWalletError(error: unknown): T2000Error {\n const msg = error instanceof Error ? error.message : String(error);\n\n if (msg.includes('rejected') || msg.includes('cancelled')) {\n return new T2000Error('TRANSACTION_FAILED', 'Transaction cancelled');\n }\n if (msg.includes('Insufficient') || msg.includes('insufficient')) {\n return new T2000Error('INSUFFICIENT_BALANCE', 'Insufficient balance');\n }\n\n return new T2000Error('UNKNOWN', msg, undefined, true);\n}\n\nexport function mapMoveAbortCode(code: number): string {\n const abortMessages: Record<number, string> = {\n 1: 'Protocol is temporarily paused',\n 2: 'Amount must be greater than zero',\n 3: 'Invalid operation type',\n 4: 'Fee rate exceeds maximum',\n 5: 'Insufficient treasury balance',\n 6: 'Not authorized',\n 7: 'Package version mismatch — upgrade required',\n 8: 'Timelock is active — wait for expiry',\n 9: 'No pending change to execute',\n 10: 'Already at current version',\n // NAVI Protocol abort codes\n 1502: 'Oracle price is stale — try again in a moment',\n 1503: 'Withdrawal amount is invalid (zero or dust) — try a specific amount instead of \"all\"',\n 1600: 'Health factor too low — withdrawal would risk liquidation',\n 1605: 'Asset borrowing is disabled or at capacity on this protocol',\n // NAVI utils abort codes\n 46000: 'Insufficient balance to repay — withdraw some savings first to get cash',\n };\n return abortMessages[code] ?? `Move abort code: ${code}`;\n}\n\n/**\n * Check if an error message contains a MoveAbort — these are on-chain\n * failures that will fail no matter how many times you retry.\n */\nexport function isMoveAbort(msg: string): boolean {\n return msg.includes('MoveAbort') || msg.includes('MovePrimitiveRuntimeError');\n}\n\nexport function parseMoveAbortMessage(msg: string): string {\n const abortMatch = msg.match(/abort code:\\s*(\\d+)/i) ?? msg.match(/MoveAbort[^,]*,\\s*(\\d+)/);\n if (abortMatch) {\n const code = parseInt(abortMatch[1], 10);\n\n const moduleMatch = msg.match(/Identifier\\(\"([^\"]+)\"\\)/) ?? msg.match(/in '([^']+)'/);\n const fnMatch = msg.match(/function_name:\\s*Some\\(\"([^\"]+)\"\\)/);\n const context = `${moduleMatch?.[1] ?? ''}${fnMatch ? `::${fnMatch[1]}` : ''}`.toLowerCase();\n const suffix = moduleMatch\n ? ` [${moduleMatch[1]}${fnMatch ? `::${fnMatch[1]}` : ''}]`\n : '';\n\n if (context.includes('slippage')) {\n return `Slippage too high — price moved during execution${suffix}`;\n }\n if (context.includes('balance::split') || context.includes('balance::ENotEnough')) {\n return `Insufficient on-chain balance${suffix}`;\n }\n\n const mapped = mapMoveAbortCode(code);\n return `${mapped}${suffix}`;\n }\n return msg;\n}\n","/**\n * Unified token registry — single source of truth for coin types, decimals, symbols, and tiers.\n *\n * ZERO heavy dependencies. Safe to import from any context (server, browser, Edge).\n *\n * Tier 1: USDC — the financial layer (save, borrow, receive, yield, allowances, marketplace, MPP).\n * Tier 2: 15 curated swap assets — hold, trade, and send only.\n * No tier: Legacy tokens kept for display accuracy (existing NAVI positions). No new operations.\n *\n * To add a new token: add ONE entry to COIN_REGISTRY below. Everything else derives from it.\n * Gate for Tier 2 addition: confirmed deep Cetus liquidity + clear user need.\n */\n\nexport interface CoinMeta {\n type: string;\n decimals: number;\n symbol: string;\n tier?: 1 | 2;\n}\n\n/**\n * Canonical coin registry.\n * Key = user-friendly name (used in swap_execute, CLI, prompts).\n */\nexport const COIN_REGISTRY: Record<string, CoinMeta> = {\n // ── Tier 1 — Financial layer ──────────────────────────────────────────\n USDC: { type: '0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC', decimals: 6, symbol: 'USDC', tier: 1 },\n\n // ── Tier 2 — Swap assets (15 tokens) ──────────────────────────────────\n SUI: { type: '0x2::sui::SUI', decimals: 9, symbol: 'SUI', tier: 2 },\n wBTC: { type: '0x0041f9f9344cac094454cd574e333c4fdb132d7bcc9379bcd4aab485b2a63942::wbtc::WBTC', decimals: 8, symbol: 'wBTC', tier: 2 },\n ETH: { type: '0xd0e89b2af5e4910726fbcd8b8dd37bb79b29e5f83f7491bca830e94f7f226d29::eth::ETH', decimals: 8, symbol: 'ETH', tier: 2 },\n GOLD: { type: '0x9d297676e7a4b771ab023291377b2adfaa4938fb9080b8d12430e4b108b836a9::xaum::XAUM', decimals: 9, symbol: 'GOLD', tier: 2 },\n DEEP: { type: '0xdeeb7a4662eec9f2f3def03fb937a663dddaa2e215b8078a284d026b7946c270::deep::DEEP', decimals: 6, symbol: 'DEEP', tier: 2 },\n WAL: { type: '0x356a26eb9e012a68958082340d4c4116e7f55615cf27affcff209cf0ae544f59::wal::WAL', decimals: 9, symbol: 'WAL', tier: 2 },\n NS: { type: '0x5145494a5f5100e645e4b0aa950fa6b68f614e8c59e17bc5ded3495123a79178::ns::NS', decimals: 6, symbol: 'NS', tier: 2 },\n IKA: { type: '0x7262fb2f7a3a14c888c438a3cd9b912469a58cf60f367352c46584262e8299aa::ika::IKA', decimals: 9, symbol: 'IKA', tier: 2 },\n CETUS: { type: '0x06864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b::cetus::CETUS', decimals: 9, symbol: 'CETUS', tier: 2 },\n NAVX: { type: '0xa99b8952d4f7d947ea77fe0ecdcc9e5fc0bcab2841d6e2a5aa00c3044e5544b5::navx::NAVX', decimals: 9, symbol: 'NAVX', tier: 2 },\n vSUI: { type: '0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT', decimals: 9, symbol: 'vSUI', tier: 2 },\n haSUI: { type: '0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d::hasui::HASUI', decimals: 9, symbol: 'haSUI', tier: 2 },\n afSUI: { type: '0xf325ce1300e8dac124071d3152c5c5ee6174914f8bc2161e88329cf579246efc::afsui::AFSUI', decimals: 9, symbol: 'afSUI', tier: 2 },\n LOFI: { type: '0xf22da9a24ad027cccb5f2d496cbe91de953d363513db08a3a734d361c7c17503::LOFI::LOFI', decimals: 9, symbol: 'LOFI', tier: 2 },\n MANIFEST: { type: '0xc466c28d87b3d5cd34f3d5c088751532d71a38d93a8aae4551dd56272cfb4355::manifest::MANIFEST', decimals: 9, symbol: 'MANIFEST', tier: 2 },\n\n // ── Legacy — no tier, kept for display accuracy on existing positions ──\n USDT: { type: '0x375f70cf2ae4c00bf37117d0c85a2c71545e6ee05c4a5c7d282cd66a4504b068::usdt::USDT', decimals: 6, symbol: 'USDT' },\n USDe: { type: '0x41d587e5336f1c86cad50d38a7136db99333bb9bda91cea4ba69115defeb1402::sui_usde::SUI_USDE', decimals: 6, symbol: 'USDe' },\n USDSUI: { type: '0x44f838219cf67b058f3b37907b655f226153c18e33dfcd0da559a844fea9b1c1::usdsui::USDSUI', decimals: 6, symbol: 'USDsui' },\n};\n\n/** Reverse lookup: coin type → CoinMeta. Built once at import time. */\nconst BY_TYPE = new Map<string, CoinMeta>();\nfor (const meta of Object.values(COIN_REGISTRY)) {\n BY_TYPE.set(meta.type, meta);\n}\n\n// ── Lookup helpers ───────────────────────────────────────────────────────\n\n/**\n * Returns the registry metadata for a coin type, or `undefined` if the coin\n * is not in the registry. Use this when you need to distinguish \"known coin\"\n * from \"supported coin\" — `isSupported` only flags tiered (active) coins,\n * but legacy coins like USDsui / USDe / USDT are in the registry without a\n * tier and still need canonical-symbol resolution.\n */\nexport function getCoinMeta(coinType: string): CoinMeta | undefined {\n return BY_TYPE.get(coinType);\n}\n\n/**\n * Returns true if the coin type appears anywhere in COIN_REGISTRY (tier 1, 2,\n * OR legacy/no-tier). Different from `isSupported`, which excludes legacy\n * entries. The blockvision-prices canonical-symbol gate uses this looser\n * check so that USDsui (legacy/no-tier today, but with a registry-canonical\n * mixed-case symbol) still wins over BlockVision's uppercase 'USDSUI'.\n */\nexport function isInRegistry(coinType: string): boolean {\n return BY_TYPE.has(coinType);\n}\n\n// ── Tier helpers ─────────────────────────────────────────────────────────\n\n/** Returns true if the coin type is Tier 1 (USDC — the financial layer). */\nexport function isTier1(coinType: string): boolean {\n const meta = BY_TYPE.get(coinType);\n return meta?.tier === 1;\n}\n\n/** Returns true if the coin type is Tier 2 (curated swap asset). */\nexport function isTier2(coinType: string): boolean {\n const meta = BY_TYPE.get(coinType);\n return meta?.tier === 2;\n}\n\n/** Returns true if the coin type is actively supported (Tier 1 or Tier 2). */\nexport function isSupported(coinType: string): boolean {\n const meta = BY_TYPE.get(coinType);\n return meta?.tier !== undefined;\n}\n\n/** Returns the tier for a coin type, or undefined if legacy/unknown. */\nexport function getTier(coinType: string): 1 | 2 | undefined {\n return BY_TYPE.get(coinType)?.tier;\n}\n\n// ── Lookup helpers ───────────────────────────────────────────────────────\n\n/**\n * Get decimals for any coin type. Checks full type match, then suffix match, then defaults to 9.\n * Works for both tiered and legacy tokens.\n */\nexport function getDecimalsForCoinType(coinType: string): number {\n const direct = BY_TYPE.get(coinType);\n if (direct) return direct.decimals;\n\n const suffix = coinType.split('::').slice(1).join('::').toUpperCase();\n if (suffix) {\n for (const meta of BY_TYPE.values()) {\n const metaSuffix = meta.type.split('::').slice(1).join('::').toUpperCase();\n if (metaSuffix === suffix) return meta.decimals;\n }\n }\n\n return 9;\n}\n\n/**\n * Resolve a full coin type to a user-friendly symbol.\n * Returns the last `::` segment if not in the registry.\n */\nexport function resolveSymbol(coinType: string): string {\n const direct = BY_TYPE.get(coinType);\n if (direct) return direct.symbol;\n\n const suffix = coinType.split('::').slice(1).join('::').toUpperCase();\n if (suffix) {\n for (const meta of BY_TYPE.values()) {\n const metaSuffix = meta.type.split('::').slice(1).join('::').toUpperCase();\n if (metaSuffix === suffix) return meta.symbol;\n }\n }\n\n return coinType.split('::').pop() ?? coinType;\n}\n\n/**\n * Name → type map for swap resolution. Derived from COIN_REGISTRY.\n * Contains BOTH original-case and UPPERCASE keys for case-insensitive lookup.\n */\nexport const TOKEN_MAP: Record<string, string> = (() => {\n const map: Record<string, string> = {};\n for (const [name, meta] of Object.entries(COIN_REGISTRY)) {\n map[name] = meta.type;\n map[name.toUpperCase()] = meta.type;\n }\n return map;\n})();\n\n/**\n * Resolve a user-friendly token name to its full coin type.\n * Returns the input unchanged if already a full coin type (contains \"::\").\n * Case-insensitive: 'usde', 'USDe', 'USDE' all resolve correctly.\n */\nexport function resolveTokenType(nameOrType: string): string | null {\n if (nameOrType.includes('::')) return nameOrType;\n return TOKEN_MAP[nameOrType] ?? TOKEN_MAP[nameOrType.toUpperCase()] ?? null;\n}\n\n/** Common type constants for direct import. */\nexport const SUI_TYPE = COIN_REGISTRY.SUI.type;\nexport const USDC_TYPE = COIN_REGISTRY.USDC.type;\nexport const USDT_TYPE = COIN_REGISTRY.USDT.type;\nexport const USDSUI_TYPE = COIN_REGISTRY.USDSUI.type;\nexport const USDE_TYPE = COIN_REGISTRY.USDe.type;\nexport const ETH_TYPE = COIN_REGISTRY.ETH.type;\nexport const WBTC_TYPE = COIN_REGISTRY.wBTC.type;\nexport const WAL_TYPE = COIN_REGISTRY.WAL.type;\nexport const NAVX_TYPE = COIN_REGISTRY.NAVX.type;\nexport const IKA_TYPE = COIN_REGISTRY.IKA.type;\nexport const LOFI_TYPE = COIN_REGISTRY.LOFI.type;\nexport const MANIFEST_TYPE = COIN_REGISTRY.MANIFEST.type;\n","import type { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519';\nimport type { TransactionSigner } from '../signer.js';\n\nexport class KeypairSigner implements TransactionSigner {\n constructor(private readonly keypair: Ed25519Keypair) {}\n\n getAddress(): string {\n return this.keypair.getPublicKey().toSuiAddress();\n }\n\n async signTransaction(txBytes: Uint8Array): Promise<{ signature: string }> {\n return this.keypair.signTransaction(txBytes);\n }\n\n /** Access the underlying keypair for APIs that still require it directly. */\n getKeypair(): Ed25519Keypair {\n return this.keypair;\n }\n}\n","import type { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519';\nimport type { TransactionSigner } from '../signer.js';\n\nexport interface ZkLoginProof {\n proofPoints: {\n a: string[];\n b: string[][];\n c: string[];\n };\n issBase64Details: {\n indexMod4: number;\n value: string;\n };\n headerBase64: string;\n addressSeed: string;\n}\n\nexport class ZkLoginSigner implements TransactionSigner {\n constructor(\n private readonly ephemeralKeypair: Ed25519Keypair,\n private readonly zkProof: ZkLoginProof,\n private readonly userAddress: string,\n private readonly maxEpoch: number,\n ) {}\n\n getAddress(): string {\n return this.userAddress;\n }\n\n async signTransaction(txBytes: Uint8Array): Promise<{ signature: string }> {\n const { getZkLoginSignature } = await import('@mysten/zklogin');\n const ephSig = await this.ephemeralKeypair.signTransaction(txBytes);\n return {\n signature: getZkLoginSignature({\n inputs: this.zkProof,\n maxEpoch: this.maxEpoch,\n userSignature: ephSig.signature,\n }),\n };\n }\n\n isExpired(currentEpoch: number): boolean {\n return currentEpoch >= this.maxEpoch;\n }\n}\n","/**\n * Browser-safe entry point for @t2000/sdk.\n *\n * Exports everything the web app needs WITHOUT Node-only modules:\n * - keyManager (fs-based wallet encryption)\n * - ContactManager (file-based contacts)\n *\n * Protocol adapters are NOT statically exported here — import them\n * via dynamic import() in the web app to keep the initial bundle small.\n */\n\n// Signer abstraction\nexport type { TransactionSigner } from './signer.js';\nexport { KeypairSigner } from './wallet/keypairSigner.js';\nexport { ZkLoginSigner, type ZkLoginProof } from './wallet/zkLoginSigner.js';\n\n// Error handling\nexport { T2000Error, mapWalletError, mapMoveAbortCode } from './errors.js';\nexport type { T2000ErrorCode, T2000ErrorData } from './errors.js';\n\n// Constants\nexport {\n MIST_PER_SUI,\n SUI_DECIMALS,\n USDC_DECIMALS,\n BPS_DENOMINATOR,\n SAVE_FEE_BPS,\n BORROW_FEE_BPS,\n T2000_OVERLAY_FEE_WALLET,\n SUPPORTED_ASSETS,\n CLOCK_ID,\n DEFAULT_NETWORK,\n} from './constants.js';\nexport type { SupportedAsset, StableAsset } from './constants.js';\nexport {\n STABLE_ASSETS,\n ALL_NAVI_ASSETS,\n GAS_RESERVE_MIN,\n} from './constants.js';\n\n// Utilities\nexport { validateAddress, truncateAddress } from './utils/sui.js';\nexport {\n KNOWN_TARGETS,\n LABEL_PATTERNS,\n classifyAction,\n classifyLabel,\n fallbackLabel,\n refineLendingLabel,\n classifyTransaction,\n extractTransferDetails,\n} from './wallet/classify.js';\nexport type {\n ClassifyBalanceChange,\n ClassifyResult,\n ExtractedTransfer,\n TxDirection,\n} from './wallet/classify.js';\n/**\n * RPC tx parsing helpers. Safe in the browser — they only do shape\n * inspection / classification and do not import any Node-only modules.\n * `queryHistory` and `queryTransaction` are not re-exported here\n * because they take a Node `SuiJsonRpcClient`; consumers can build\n * the same flow with `parseSuiRpcTx` + their own RPC fetch.\n */\nexport {\n parseSuiRpcTx,\n extractTxSender,\n extractTxCommands,\n} from './wallet/history.js';\nexport type { SuiRpcTxBlock } from './wallet/history.js';\nexport {\n mistToSui,\n suiToMist,\n usdcToRaw,\n rawToUsdc,\n stableToRaw,\n rawToStable,\n getDecimals,\n formatUsd,\n formatSui,\n formatAssetAmount,\n} from './utils/format.js';\nexport { toBase64, fromBase64 } from './utils/base64.js';\n\n// Simulation — use dynamic import() to avoid Buffer dependency in browser bundles\n// import { simulateTransaction } from '@t2000/sdk' (main entry) for Node usage\nexport type { SimulationResult } from './utils/simulate.js';\n\n// Protocol fee\nexport { calculateFee, addFeeTransfer } from './protocols/protocolFee.js';\nexport type { ProtocolFeeInfo, FeeOperation } from './protocols/protocolFee.js';\n\n// Cetus aggregator helpers — Audric prepare/route.ts uses these directly to\n// build swap PTBs with overlay fees (per-call, not module-global).\nexport { findSwapRoute, buildSwapTx, OVERLAY_FEE_RATE } from './protocols/cetus-swap.js';\nexport type { SwapRouteResult, OverlayFeeConfig } from './protocols/cetus-swap.js';\n\n// Safeguards — only browser-safe exports (SafeguardEnforcer uses node:fs)\nexport { SafeguardError } from './safeguards/errors.js';\nexport type { SafeguardRule, SafeguardErrorDetails } from './safeguards/errors.js';\nexport type { SafeguardConfig, TxMetadata } from './safeguards/types.js';\nexport { OUTBOUND_OPS, DEFAULT_SAFEGUARD_CONFIG } from './safeguards/types.js';\n\n// Types\nexport type {\n BalanceResponse,\n GasReserve,\n SendResult,\n SaveResult,\n WithdrawResult,\n BorrowResult,\n RepayResult,\n HealthFactorResult,\n MaxWithdrawResult,\n MaxBorrowResult,\n AssetRates,\n RatesResult,\n PositionEntry,\n PositionsResult,\n EarningsResult,\n FundStatusResult,\n DepositInfo,\n TransactionRecord,\n ClaimRewardsResult,\n PendingReward,\n PayOptions,\n PayResult,\n} from './types.js';\n\n// Token registry — zero Node.js deps, safe for client-side use\nexport {\n COIN_REGISTRY,\n TOKEN_MAP,\n resolveTokenType,\n resolveSymbol,\n getDecimalsForCoinType,\n isTier1,\n isTier2,\n isSupported,\n getTier,\n SUI_TYPE,\n USDC_TYPE,\n USDT_TYPE,\n USDSUI_TYPE,\n USDE_TYPE,\n ETH_TYPE,\n WBTC_TYPE,\n WAL_TYPE,\n NAVX_TYPE,\n IKA_TYPE,\n LOFI_TYPE,\n MANIFEST_TYPE,\n} from './token-registry.js';\nexport type { CoinMeta } from './token-registry.js';\n","import { T2000Error } from './errors.js';\n\nexport const MIST_PER_SUI = 1_000_000_000n;\nexport const SUI_DECIMALS = 9;\nexport const USDC_DECIMALS = 6;\n\nexport const BPS_DENOMINATOR = 10_000n;\nexport const PRECISION = 1_000_000_000_000_000_000n;\n\nexport const MIN_DEPOSIT = 1_000_000n; // 1 USDC (6 decimals)\n\nexport const SAVE_FEE_BPS = 10n; // 0.1%\nexport const BORROW_FEE_BPS = 5n; // 0.05%\n\nexport const CLOCK_ID = '0x6';\n\nexport const SUPPORTED_ASSETS = {\n USDC: {\n type: '0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC',\n decimals: 6,\n symbol: 'USDC',\n displayName: 'USDC',\n },\n USDT: {\n type: '0x375f70cf2ae4c00bf37117d0c85a2c71545e6ee05c4a5c7d282cd66a4504b068::usdt::USDT',\n decimals: 6,\n symbol: 'USDT',\n displayName: 'suiUSDT',\n },\n USDe: {\n type: '0x41d587e5336f1c86cad50d38a7136db99333bb9bda91cea4ba69115defeb1402::sui_usde::SUI_USDE',\n decimals: 6,\n symbol: 'USDe',\n displayName: 'suiUSDe',\n },\n USDsui: {\n type: '0x44f838219cf67b058f3b37907b655f226153c18e33dfcd0da559a844fea9b1c1::usdsui::USDSUI',\n decimals: 6,\n symbol: 'USDsui',\n displayName: 'USDsui',\n },\n SUI: {\n type: '0x2::sui::SUI',\n decimals: 9,\n symbol: 'SUI',\n displayName: 'SUI',\n },\n WAL: {\n type: '0x356a26eb9e012a68958082340d4c4116e7f55615cf27affcff209cf0ae544f59::wal::WAL',\n decimals: 9,\n symbol: 'WAL',\n displayName: 'WAL',\n },\n ETH: {\n type: '0xd0e89b2af5e4910726fbcd8b8dd37bb79b29e5f83f7491bca830e94f7f226d29::eth::ETH',\n decimals: 8,\n symbol: 'ETH',\n displayName: 'suiETH',\n },\n NAVX: {\n type: '0xa99b8952d4f7d947ea77fe0ecdcc9e5fc0bcab2841d6e2a5aa00c3044e5544b5::navx::NAVX',\n decimals: 9,\n symbol: 'NAVX',\n displayName: 'NAVX',\n },\n GOLD: {\n type: '0x9d297676e7a4b771ab023291377b2adfaa4938fb9080b8d12430e4b108b836a9::xaum::XAUM',\n decimals: 6,\n symbol: 'GOLD',\n displayName: 'XAUM',\n },\n} as const;\n\nexport type SupportedAsset = keyof typeof SUPPORTED_ASSETS;\nexport type StableAsset = 'USDC';\nexport const STABLE_ASSETS: readonly StableAsset[] = ['USDC'] as const;\nexport const ALL_NAVI_ASSETS: readonly SupportedAsset[] = Object.keys(SUPPORTED_ASSETS) as SupportedAsset[];\n\n// ---------------------------------------------------------------------------\n// Operation → allowed asset rules (single source of truth)\n// ---------------------------------------------------------------------------\n\n// [v0.51.0] Saveable/borrowable set: USDC + USDsui.\n// USDC is the canonical default; USDsui is a strategic exception backed by an\n// existing NAVI pool. See `.cursor/rules/savings-usdc-only.mdc` for the\n// rationale and the rule that gates additional stables (don't add more here\n// without updating that file).\nexport const OPERATION_ASSETS = {\n save: ['USDC', 'USDsui'],\n borrow: ['USDC', 'USDsui'],\n withdraw: '*',\n repay: '*',\n send: '*',\n swap: '*',\n} as const;\n\nexport type Operation = keyof typeof OPERATION_ASSETS;\n\nexport function isAllowedAsset(op: Operation, asset: string): boolean {\n const allowed = OPERATION_ASSETS[op];\n if (allowed === '*') return true;\n // [v0.51.0] Mixed-case canonical keys (USDsui, suiUSDT) need case-insensitive\n // membership. Pre-v0.51 we only had USDC ↔ USDC (uppercase identity), so\n // a one-sided uppercase compare looked correct. Now that USDsui is in the\n // set, normalize both sides.\n const target = asset.toLowerCase();\n return (allowed as readonly string[]).some((a) => a.toLowerCase() === target);\n}\n\n/**\n * Throws if the asset is not permitted for the given operation.\n * Passing `undefined` (omitted) is always valid — defaults to USDC.\n */\nexport function assertAllowedAsset(op: Operation, asset: string | undefined): void {\n if (!asset) return;\n if (!isAllowedAsset(op, asset)) {\n const allowed = OPERATION_ASSETS[op];\n const list = Array.isArray(allowed) ? allowed.join(', ') : 'any';\n throw new T2000Error(\n 'INVALID_ASSET',\n `${op} only supports ${list}. Cannot use ${asset}.${op === 'save' ? ' Swap to USDC or USDsui first.' : ''}`,\n );\n }\n}\n\n// All protocol fees route here as a regular USDC wallet transfer. Audric's\n// prepare/route.ts adds `addFeeTransfer(...)` inline for save/borrow and passes\n// `overlayFee.receiver = T2000_OVERLAY_FEE_WALLET` for swaps. The CLI/SDK never\n// charge fees — this constant is exported for consumer apps only.\n//\n// Address corresponds to the treasury admin wallet. Override via env for local dev /\n// testnet only — production must use the canonical mainnet address below.\nexport const T2000_OVERLAY_FEE_WALLET = process.env.T2000_OVERLAY_FEE_WALLET\n ?? '0x5366efbf2b4fe5767fe2e78eb197aa5f5d138d88ac3333fbf3f80a1927da473a';\n\nexport const DEFAULT_NETWORK = 'mainnet' as const;\nexport const DEFAULT_RPC_URL = 'https://fullnode.mainnet.sui.io:443';\nexport const DEFAULT_KEY_PATH = '~/.t2000/wallet.key';\nexport const DEFAULT_CONFIG_PATH = '~/.t2000/config.json';\n\nexport const API_BASE_URL = process.env.T2000_API_URL ?? 'https://api.t2000.ai';\n\n// Cetus USDC/SUI pool — read-only for SUI price oracle (no SDK dependency)\nexport const CETUS_USDC_SUI_POOL = '0x51e883ba7c0b566a26cbc8a94cd33eb0abd418a77cc1e60ad22fd9b1f29cd2ab';\n\nexport const GAS_RESERVE_MIN = 0.05; // minimum SUI to keep for gas\n","import { SuiJsonRpcClient, getJsonRpcFullnodeUrl } from '@mysten/sui/jsonRpc';\nimport { isValidSuiAddress, normalizeSuiAddress } from '@mysten/sui/utils';\nimport { DEFAULT_RPC_URL } from '../constants.js';\nimport { T2000Error } from '../errors.js';\n\nlet cachedClient: SuiJsonRpcClient | null = null;\n\nexport function getSuiClient(rpcUrl?: string): SuiJsonRpcClient {\n const url = rpcUrl ?? DEFAULT_RPC_URL;\n if (cachedClient) return cachedClient;\n cachedClient = new SuiJsonRpcClient({ url, network: 'mainnet' });\n return cachedClient;\n}\n\nexport function createSuiClient(network: 'mainnet' | 'testnet' = 'mainnet'): SuiJsonRpcClient {\n return new SuiJsonRpcClient({ url: getJsonRpcFullnodeUrl(network), network });\n}\n\nexport function validateAddress(address: string): string {\n const normalized = normalizeSuiAddress(address);\n if (!isValidSuiAddress(normalized)) {\n throw new T2000Error('INVALID_ADDRESS', `Invalid Sui address: ${address}`);\n }\n return normalized;\n}\n\nexport function truncateAddress(address: string): string {\n if (address.length <= 10) return address;\n return `${address.slice(0, 6)}...${address.slice(-4)}`;\n}\n\n/**\n * Normalize a Sui coin type to its canonical long-form 64-hex address.\n * `0x2::sui::SUI` → `0x0000…0002::sui::SUI`. Idempotent on already-long\n * forms. Returns the input unchanged if it doesn't look like a coin type\n * (`<address>::<module>::<name>`) so callers can pass arbitrary strings\n * without crashing.\n *\n * Why this exists: BlockVision's `/v2/sui/coin/price/list` endpoint\n * silently returns an empty `prices` map for short-form coin types\n * (notably `0x2::sui::SUI` — the native gas coin). Internal callers must\n * pass the long form, but external callers (LLM tool args, cached\n * coin-type strings, audit logs) commonly use the short form. Normalize\n * before the network call, denormalize back to the caller's input shape\n * after, and short/long become interchangeable.\n */\nexport function normalizeCoinType(coinType: string): string {\n const parts = coinType.split('::');\n if (parts.length !== 3) return coinType;\n const [addr, mod, name] = parts;\n if (!addr.startsWith('0x')) return coinType;\n return `${normalizeSuiAddress(addr)}::${mod}::${name}`;\n}\n","/**\n * Shared transaction classifier.\n *\n * Consumed by both the SDK's `parseTxRecord` (production agent path) and\n * the engine's `transaction_history` tool (cold-start RPC path). Keeping\n * a single source of truth here prevents the two paths from drifting —\n * see v1.5.3 regression where the SDK path was emitting `action:\n * 'transaction'` (rendered as \"On-chain\") while the engine path was\n * already producing fine-grained labels.\n */\n\nimport { getDecimalsForCoinType, resolveSymbol, SUI_TYPE } from '../token-registry.js';\n\n/**\n * Coarse action bucket — one of `'send' | 'lending' | 'swap' |\n * 'transaction'`. Used by the ACI `action` filter on the\n * `transaction_history` tool. STABLE: downstream queries depend on\n * exactly these values.\n *\n * Order matters: more specific buckets first. Lending patterns precede\n * swap patterns so a NAVI `::swap` helper (if one ever existed) would\n * still bucket as lending.\n */\nexport const KNOWN_TARGETS: readonly [RegExp, string][] = [\n [/::suilend|::obligation/, 'lending'],\n [/::navi|::lending_core|::incentive_v\\d+|::oracle_pro/, 'lending'],\n /**\n * DEX modules — both direct calls and aggregator legs. The Cetus\n * aggregator dispatches through a per-DEX module (e.g.\n * `cetus::swap`, `flowx_amm::swap`, `aftermath::swap`, …) plus\n * router glue functions. We list every DEX module the aggregator\n * supports today so a single-DEX call still classifies cleanly.\n */\n [/::cetus(?:_dlmm)?::|::pool::|::deepbook|::flowx_(?:amm|clmm)::|::kriya_(?:amm|clmm)::|::turbos::|::aftermath::|::afsui::|::bluefin::|::bluemove::|::ferra_(?:clmm|dlmm)::|::haedal_hmm::|::hasui::|::hawal::|::magma::|::momentum::|::obric::|::springsui::|::steamm_cpmm::|::fullsail::|::alphafi::|::volo_swap::/, 'swap'],\n /**\n * Cetus aggregator router glue. These are the swap-context and\n * balance-handling helpers the aggregator emits around per-DEX\n * legs. Without this entry a tx that ONLY had router calls\n * (theoretically possible for setup/cleanup) would slip through;\n * in practice these always coexist with a DEX leg, but the entry\n * is cheap insurance.\n */\n [/::router::(?:new_swap_context(?:_v)?|confirm_swap|transfer_balance|take_balance|transfer_or_destroy_coin)/, 'swap'],\n [/::transfer::public_transfer/, 'send'],\n];\n\n/**\n * Finer-grained display labels — derived from MoveCall function names.\n * The card renders `label ?? action`, so when this map matches we get\n * \"Deposit\" / \"Withdraw\" / \"Borrow\" / \"Repay\" / \"Payment link\" instead\n * of the generic \"Lending\" or \"Transaction\".\n *\n * Order matters: more specific patterns first. Each entry is\n * (regex, label) where the regex is matched against the\n * fully-qualified MoveCall target `pkg::module::function`.\n */\nexport const LABEL_PATTERNS: readonly [RegExp, string][] = [\n [/::pay(?:ment_kit|_kit)?::|::create_payment_link|::pay_link/, 'payment_link'],\n [/::create_invoice|::invoice::/, 'invoice'],\n [/::deposit|::supply|::mint_ctokens/, 'deposit'],\n [/::withdraw|::redeem|::redeem_ctokens/, 'withdraw'],\n [/::borrow/, 'borrow'],\n [/::repay/, 'repay'],\n [/::claim_reward|::claim::|::claim_incentive/, 'claim'],\n [/::stake/, 'stake'],\n [/::unstake|::burn::/, 'unstake'],\n [/::liquidate/, 'liquidate'],\n];\n\nexport interface ClassifyBalanceChange {\n owner: { AddressOwner?: string } | string;\n coinType: string;\n amount: string;\n}\n\nfunction resolveOwner(owner: ClassifyBalanceChange['owner']): string | null {\n if (typeof owner === 'object' && owner.AddressOwner) return owner.AddressOwner;\n if (typeof owner === 'string') return owner;\n return null;\n}\n\nexport function classifyAction(targets: string[], commandTypes: string[]): string {\n for (const target of targets) {\n for (const [pattern, label] of KNOWN_TARGETS) {\n if (pattern.test(target)) return label;\n }\n }\n if (commandTypes.includes('TransferObjects') && !commandTypes.includes('MoveCall')) return 'send';\n return 'transaction';\n}\n\n/**\n * Last-resort fallback when neither `LABEL_PATTERNS` nor the action\n * bucket produces something useful.\n *\n * Returns the first MoveCall's *module* name (e.g. \"navi\", \"spam\") so\n * the card shows something better than the literal word \"transaction\".\n * When no MoveCall exists, returns 'on-chain'.\n *\n * Note: callers should prefer `classifyLabel` which now layers\n * pattern-match → coarse action → module name (see commentary there).\n */\nexport function fallbackLabel(targets: string[]): string {\n if (!targets.length) return 'on-chain';\n const first = targets[0];\n const parts = first.split('::');\n if (parts.length >= 2 && parts[1]) return parts[1].toLowerCase();\n return 'on-chain';\n}\n\n/**\n * Three-tier label resolution for the transaction history card:\n * 1. Specific keyword match in `LABEL_PATTERNS` (\"deposit\",\n * \"payment_link\", …).\n * 2. Coarse action bucket from `classifyAction` (\"swap\", \"send\",\n * \"lending\") — prevents leaking opaque internal module names like\n * \"router\" (Cetus aggregator) or \"cross_swap\" (third-party DEX\n * aggregators) for txs that we already classified as a swap.\n * 3. Module name from the first MoveCall (`fallbackLabel`) — only\n * used when the action bucket itself is the generic \"transaction\".\n *\n * Pre-v0.46.2 we skipped tier 2, so swaps showed labels like \"router\",\n * \"cross_swap\", \"scallop_router\", etc. instead of the clean \"swap\".\n */\nexport function classifyLabel(targets: string[], commandTypes: string[]): string {\n for (const target of targets) {\n for (const [pattern, label] of LABEL_PATTERNS) {\n if (pattern.test(target)) return label;\n }\n }\n if (commandTypes.includes('TransferObjects') && !commandTypes.includes('MoveCall')) return 'send';\n const action = classifyAction(targets, commandTypes);\n if (action !== 'transaction') return action;\n return fallbackLabel(targets);\n}\n\n/**\n * Balance-direction tiebreaker for ambiguous lending calls.\n *\n * Many lending modules expose generic entry points (NAVI's bundled\n * flash actions, `lending_core::*::entry_*`, etc.) that don't carry\n * a `deposit`/`withdraw`/`borrow`/`repay` keyword in the function\n * name. When `classifyLabel` falls back to a bare module name like\n * `\"lending\"` for a known lending tx, infer direction from the user's\n * non-SUI balance change:\n * - net outflow of the supplied asset → deposit (also covers repay,\n * but repay-without-keyword is essentially never emitted).\n * - net inflow of the supplied asset → withdraw (also covers borrow).\n * SUI is excluded so gas-only transactions don't get mislabeled.\n *\n * If `LABEL_PATTERNS` matched a specific keyword, the existing label is\n * returned unchanged.\n */\nexport function refineLendingLabel(\n currentAction: string,\n currentLabel: string,\n moveCallTargets: string[],\n changes: ClassifyBalanceChange[],\n address: string,\n): string {\n if (currentAction !== 'lending') return currentLabel;\n const labelMatchedSpecific = LABEL_PATTERNS.some(([p]) =>\n moveCallTargets.some((t) => p.test(t)),\n );\n if (labelMatchedSpecific) return currentLabel;\n\n const userNonSuiOutflow = changes.find(\n (c) => resolveOwner(c.owner) === address && c.coinType !== SUI_TYPE && BigInt(c.amount) < 0n,\n );\n if (userNonSuiOutflow) return 'deposit';\n\n const userNonSuiInflow = changes.find(\n (c) => resolveOwner(c.owner) === address && c.coinType !== SUI_TYPE && BigInt(c.amount) > 0n,\n );\n if (userNonSuiInflow) return 'withdraw';\n\n return currentLabel;\n}\n\nexport interface ClassifyResult {\n action: string;\n label: string;\n}\n\nexport function classifyTransaction(\n moveCallTargets: string[],\n commandTypes: string[],\n balanceChanges: ClassifyBalanceChange[],\n address: string,\n): ClassifyResult {\n const action = classifyAction(moveCallTargets, commandTypes);\n const baseLabel = classifyLabel(moveCallTargets, commandTypes);\n const label = refineLendingLabel(action, baseLabel, moveCallTargets, balanceChanges, address);\n return { action, label };\n}\n\n/**\n * Direction of the user's net non-gas movement for this transaction.\n *\n * - `'out'` — the user spent the asset (sends, deposits, repays,\n * swap-in, payment-link payouts).\n * - `'in'` — the user received the asset (withdraws, borrows,\n * swap-out, claims, deposits credited from another wallet).\n *\n * Used by the `TransactionHistoryCard` to choose the `+`/`−` sign and\n * color. Direction is computed from the actual on-chain balance change\n * — never from the textual label — so opaque action types (`'router'`,\n * `'cross_swap'`, …) still render the correct sign.\n */\nexport type TxDirection = 'in' | 'out';\n\nexport interface ExtractedTransfer {\n amount?: number;\n asset?: string;\n recipient?: string;\n direction?: TxDirection;\n}\n\n/**\n * Extracts the principal amount/asset/direction for a transaction\n * from its `balanceChanges`.\n *\n * Algorithm:\n * 1. Restrict to the user's *own* balance changes.\n * 2. Prefer non-SUI changes (gas-only SUI deltas are noise).\n * 3. Pick the change with the largest absolute value — the \"principal\".\n * 4. If no non-SUI change exists, fall back to the largest SUI change\n * so pure-SUI transfers (stake/unstake/native send) still render.\n * 5. Direction follows the sign of the principal.\n * 6. Recipient is set only on outflows, by finding a matching inflow\n * on a *non-user* address with the same coinType.\n *\n * Pre-v0.46.2 this function only inspected outflows, so withdraws,\n * borrows, claims, swap-receives and payment-link receives all\n * rendered with no amount on the rich card (and with a wrong sign,\n * because the card guessed direction from the label string).\n */\nexport function extractTransferDetails(\n changes: ClassifyBalanceChange[] | undefined,\n sender: string,\n): ExtractedTransfer {\n if (!changes || changes.length === 0) return {};\n\n const userChanges = changes.filter((c) => resolveOwner(c.owner) === sender);\n if (userChanges.length === 0) return {};\n\n const userNonSui = userChanges.filter((c) => c.coinType !== SUI_TYPE);\n const pool = userNonSui.length > 0 ? userNonSui : userChanges;\n\n let primary = pool[0];\n let primaryAbs = bigintAbs(BigInt(primary.amount));\n for (let i = 1; i < pool.length; i++) {\n const abs = bigintAbs(BigInt(pool[i].amount));\n if (abs > primaryAbs) {\n primary = pool[i];\n primaryAbs = abs;\n }\n }\n\n const raw = BigInt(primary.amount);\n if (raw === 0n) return {};\n\n const decimals = getDecimalsForCoinType(primary.coinType);\n const amount = Number(primaryAbs) / 10 ** decimals;\n const asset = resolveSymbol(primary.coinType);\n const direction: TxDirection = raw < 0n ? 'out' : 'in';\n\n let recipient: string | undefined;\n if (direction === 'out') {\n const recipientChange = changes.find(\n (c) =>\n resolveOwner(c.owner) !== sender &&\n c.coinType === primary.coinType &&\n BigInt(c.amount) > 0n,\n );\n recipient = recipientChange ? resolveOwner(recipientChange.owner) ?? undefined : undefined;\n }\n\n return { amount, asset, recipient, direction };\n}\n\nfunction bigintAbs(n: bigint): bigint {\n return n < 0n ? -n : n;\n}\n","import type { SuiJsonRpcClient } from '@mysten/sui/jsonRpc';\nimport type { TransactionRecord } from '../types.js';\nimport {\n classifyTransaction,\n extractTransferDetails,\n type ClassifyBalanceChange,\n} from './classify.js';\n\nexport async function queryHistory(\n client: SuiJsonRpcClient,\n address: string,\n limit = 20,\n): Promise<TransactionRecord[]> {\n const txns = await client.queryTransactionBlocks({\n filter: { FromAddress: address },\n options: { showEffects: true, showInput: true, showBalanceChanges: true },\n limit,\n order: 'descending',\n });\n\n return txns.data.map((tx) => parseTxRecord(tx as unknown as SuiRpcTxBlock, address));\n}\n\nexport async function queryTransaction(\n client: SuiJsonRpcClient,\n digest: string,\n senderAddress: string,\n): Promise<TransactionRecord | null> {\n try {\n const tx = await client.getTransactionBlock({\n digest,\n options: { showEffects: true, showInput: true, showBalanceChanges: true },\n });\n return parseTxRecord(tx as unknown as SuiRpcTxBlock, senderAddress);\n } catch {\n return null;\n }\n}\n\n/**\n * Shape of a transaction block as returned by `suix_queryTransactionBlocks`\n * with `showEffects | showInput | showBalanceChanges` enabled. Exported so\n * downstream consumers (audric dashboard `/api/history`, `/api/activity`,\n * etc.) can type their RPC calls without redeclaring the structure.\n */\nexport interface SuiRpcTxBlock {\n digest: string;\n timestampMs?: string;\n transaction?: unknown;\n effects?: { gasUsed?: { computationCost: string; storageCost: string; storageRebate: string } };\n balanceChanges?: ClassifyBalanceChange[];\n}\n\n/**\n * Convert a single Sui RPC transaction block to a {@link TransactionRecord}\n * using the canonical (shared) classifier and balance-change extractor.\n *\n * This is the single source of truth for transaction parsing across the\n * agent-tool path AND the dashboard-API path. Use it instead of writing\n * a bespoke parser per surface.\n *\n * @param tx Raw RPC tx block (must include `effects`, `input`, `balanceChanges`).\n * @param address Wallet address whose perspective we're parsing from.\n */\nexport function parseSuiRpcTx(tx: SuiRpcTxBlock, address: string): TransactionRecord {\n return parseTxRecord(tx, address);\n}\n\n/**\n * Extract the sender (signer) address from a raw RPC tx block.\n * Returns `null` if the block shape is unexpected.\n */\nexport function extractTxSender(txBlock: unknown): string | null {\n try {\n if (!txBlock || typeof txBlock !== 'object') return null;\n const data = 'data' in txBlock ? (txBlock as Record<string, unknown>).data : undefined;\n if (!data || typeof data !== 'object') return null;\n return ((data as Record<string, unknown>).sender as string) ?? null;\n } catch {\n return null;\n }\n}\n\n/**\n * Extract MoveCall targets (`<pkg>::<module>::<function>`) and the\n * sequence of programmable-transaction command types (e.g. `MoveCall`,\n * `TransferObjects`) from a raw RPC tx block. Tolerates both the\n * legacy `inner.transactions` field and the newer `inner.commands`\n * field.\n */\nexport function extractTxCommands(txBlock: unknown): {\n moveCallTargets: string[];\n commandTypes: string[];\n} {\n return extractCommands(txBlock);\n}\n\nfunction parseTxRecord(tx: SuiRpcTxBlock, address: string): TransactionRecord {\n const gasUsed = tx.effects?.gasUsed;\n const gasCost = gasUsed\n ? (Number(gasUsed.computationCost) +\n Number(gasUsed.storageCost) -\n Number(gasUsed.storageRebate)) /\n 1e9\n : undefined;\n\n const { moveCallTargets, commandTypes } = extractCommands(tx.transaction);\n const balanceChanges = tx.balanceChanges ?? [];\n const { amount, asset, recipient, direction } = extractTransferDetails(balanceChanges, address);\n const { action, label } = classifyTransaction(\n moveCallTargets,\n commandTypes,\n balanceChanges,\n address,\n );\n\n return {\n digest: tx.digest,\n action,\n label,\n amount,\n asset,\n recipient,\n direction,\n timestamp: Number(tx.timestampMs ?? 0),\n gasCost,\n };\n}\n\ninterface CommandInfo {\n moveCallTargets: string[];\n commandTypes: string[];\n}\n\nfunction extractCommands(txBlock: unknown): CommandInfo {\n const result: CommandInfo = { moveCallTargets: [], commandTypes: [] };\n try {\n if (!txBlock || typeof txBlock !== 'object') return result;\n const data = 'data' in txBlock ? (txBlock as Record<string, unknown>).data : undefined;\n if (!data || typeof data !== 'object') return result;\n const inner = 'transaction' in (data as Record<string, unknown>)\n ? (data as Record<string, unknown>).transaction\n : undefined;\n if (!inner || typeof inner !== 'object') return result;\n const commands = 'commands' in (inner as Record<string, unknown>)\n ? (inner as Record<string, unknown>).commands\n : 'transactions' in (inner as Record<string, unknown>)\n ? (inner as Record<string, unknown>).transactions\n : undefined;\n if (!Array.isArray(commands)) return result;\n\n for (const cmd of commands as Record<string, unknown>[]) {\n if (cmd.MoveCall) {\n const mc = cmd.MoveCall as { package: string; module: string; function: string };\n result.moveCallTargets.push(`${mc.package}::${mc.module}::${mc.function}`);\n result.commandTypes.push('MoveCall');\n } else if (cmd.TransferObjects) {\n result.commandTypes.push('TransferObjects');\n }\n }\n } catch { /* best effort */ }\n return result;\n}\n","import { MIST_PER_SUI, BPS_DENOMINATOR, USDC_DECIMALS, SUPPORTED_ASSETS } from '../constants.js';\nimport type { SupportedAsset } from '../constants.js';\n\nexport function mistToSui(mist: bigint): number {\n return Number(mist) / Number(MIST_PER_SUI);\n}\n\nexport function suiToMist(sui: number): bigint {\n return BigInt(Math.round(sui * Number(MIST_PER_SUI)));\n}\n\nexport function usdcToRaw(amount: number): bigint {\n return BigInt(Math.round(amount * 10 ** USDC_DECIMALS));\n}\n\nexport function rawToUsdc(raw: bigint): number {\n return Number(raw) / 10 ** USDC_DECIMALS;\n}\n\nexport function stableToRaw(amount: number, decimals: number): bigint {\n return BigInt(Math.round(amount * 10 ** decimals));\n}\n\nexport function rawToStable(raw: bigint, decimals: number): number {\n return Number(raw) / 10 ** decimals;\n}\n\nexport function getDecimals(asset: SupportedAsset): number {\n return SUPPORTED_ASSETS[asset].decimals;\n}\n\nexport function rawToDisplay(raw: bigint, decimals: number): number {\n return Number(raw) / 10 ** decimals;\n}\n\nexport function displayToRaw(amount: number, decimals: number): bigint {\n return BigInt(Math.round(amount * 10 ** decimals));\n}\n\nexport function bpsToPercent(bps: bigint): number {\n return Number(bps) / Number(BPS_DENOMINATOR) * 100;\n}\n\nexport function formatUsd(amount: number): string {\n return `$${amount.toFixed(2)}`;\n}\n\nexport function formatSui(amount: number): string {\n if (amount < 0.001) return `${amount.toFixed(6)} SUI`;\n return `${amount.toFixed(3)} SUI`;\n}\n\nexport function formatLargeNumber(n: number): string {\n if (n >= 1_000_000) return `${(n / 1_000_000).toFixed(1)}M`;\n if (n >= 1_000) return `${(n / 1_000).toFixed(1)}K`;\n return n.toFixed(2);\n}\n\nexport function formatAssetAmount(amount: number, asset: string): string {\n if (asset === 'BTC') return amount.toFixed(8);\n if (asset === 'GOLD') return amount.toFixed(6);\n if (asset === 'ETH') return amount.toFixed(6);\n return amount.toFixed(4);\n}\n\nconst ASSET_LOOKUP: Map<string, string> = new Map();\nfor (const [key, info] of Object.entries(SUPPORTED_ASSETS)) {\n ASSET_LOOKUP.set(key.toUpperCase(), key);\n if (info.displayName && info.displayName.toUpperCase() !== key.toUpperCase()) {\n ASSET_LOOKUP.set(info.displayName.toUpperCase(), key);\n }\n}\n\n/**\n * Case-insensitive lookup against SUPPORTED_ASSETS keys AND display names.\n * 'usde' → 'USDe', 'suiusde' → 'USDe', 'suiusdt' → 'USDT', 'usdsui' → 'USDsui'.\n * Returns the original input if not found so downstream validation can reject it.\n */\nexport function normalizeAsset(input: string): string {\n return ASSET_LOOKUP.get(input.toUpperCase()) ?? input;\n}\n","/** Cross-platform (Node + browser) base64 helpers. */\n\nexport function toBase64(bytes: Uint8Array): string {\n let binary = '';\n for (const byte of bytes) binary += String.fromCharCode(byte);\n return btoa(binary);\n}\n\nexport function fromBase64(b64: string): Uint8Array {\n const binary = atob(b64);\n const bytes = new Uint8Array(binary.length);\n for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);\n return bytes;\n}\n","/**\n * Protocol fee primitives — wallet-direct transfer model.\n *\n * Fees are collected by splitting from the payment coin and transferring directly\n * to the treasury wallet inside the same PTB. Atomic with the operation (PTB\n * semantics); the wallet IS the ledger; the server-side indexer reads\n * `balanceChanges` and writes a `ProtocolFeeLedger` row tagged with the operation\n * classified from the tx's moveCall targets.\n *\n * The SDK / CLI never call this helper — they're fee-free by design (t2000 = infra\n * brand, no opinion on fees). Audric's `prepare/route.ts` is the canonical caller.\n */\nimport { Transaction, type TransactionObjectArgument } from '@mysten/sui/transactions';\nimport {\n SAVE_FEE_BPS,\n BORROW_FEE_BPS,\n BPS_DENOMINATOR,\n} from '../constants.js';\nimport { usdcToRaw } from '../utils/format.js';\n\nexport type FeeOperation = 'save' | 'borrow' | 'swap';\n\nexport interface ProtocolFeeInfo {\n amount: number;\n asset: string;\n rate: number;\n rawAmount: bigint;\n}\n\nconst FEE_RATES: Record<FeeOperation, bigint> = {\n save: SAVE_FEE_BPS,\n borrow: BORROW_FEE_BPS,\n // Swap uses Cetus's overlay-fee mechanism (taken from output by the aggregator\n // and transferred to `overlayFee.receiver`). We list the rate here for display\n // / quote calculations only — `addFeeTransfer` is NOT called for swaps.\n swap: 10n, // 0.1%\n};\n\n/**\n * Compute the fee amount for a given operation against a USD-denominated input.\n * Used pre-tx for receipt display + quote math. Does not modify any tx.\n */\nexport function calculateFee(operation: FeeOperation, amount: number): ProtocolFeeInfo {\n const bps = FEE_RATES[operation];\n const feeAmount = amount * Number(bps) / Number(BPS_DENOMINATOR);\n const rawAmount = usdcToRaw(feeAmount);\n\n return {\n amount: feeAmount,\n asset: 'USDC',\n rate: Number(bps) / Number(BPS_DENOMINATOR),\n rawAmount,\n };\n}\n\n/**\n * Split a fee from `paymentCoin` and transfer it to `receiver` inside the given PTB.\n *\n * **Order is load-bearing.** Call this BEFORE the protocol operation that consumes\n * `paymentCoin` (e.g. NAVI deposit). `splitCoins` mutates the source coin in place,\n * leaving the remainder for the protocol step. If you split AFTER the deposit,\n * the deposit will have consumed the coin and the split will fail.\n *\n * Atomicity: `splitCoins` + `transferObjects` are PTB ops; if anything later in\n * the PTB reverts, the fee transfer reverts too.\n *\n * @param tx Active PTB\n * @param paymentCoin Coin to split the fee from (mutated in place)\n * @param feeBps Fee rate in basis points (e.g. `SAVE_FEE_BPS = 10n` = 0.1%)\n * @param receiver Treasury wallet address (typically `T2000_OVERLAY_FEE_WALLET`)\n * @param amount USD-denominated input amount (matches what was passed to the\n * protocol operation; used to compute the raw fee amount)\n */\nexport function addFeeTransfer(\n tx: Transaction,\n paymentCoin: TransactionObjectArgument,\n feeBps: bigint,\n receiver: string,\n amount: number,\n): void {\n if (feeBps <= 0n) return;\n if (amount <= 0) return;\n\n const feeAmount = amount * Number(feeBps) / Number(BPS_DENOMINATOR);\n const rawFee = usdcToRaw(feeAmount);\n if (rawFee <= 0n) return;\n\n const [feeCoin] = tx.splitCoins(paymentCoin, [tx.pure.u64(rawFee)]);\n tx.transferObjects([feeCoin], tx.pure.address(receiver));\n}\n","/**\n * Cetus Aggregator V3 SDK wrapper — the ONLY file that imports @cetusprotocol/aggregator-sdk.\n * Documented CLAUDE.md exception: multi-DEX routing cannot be feasibly replaced by thin tx builders.\n *\n * [B5 v2 / @t2000/sdk@1.1.0 / 2026-04-30]\n * Overlay fee config is now per-call instead of a module-level singleton. CLI / direct\n * SDK callers (`T2000.swap()`) DON'T pass `overlayFee` → fee-free swap. Audric's\n * prepare/route.ts ALWAYS passes `overlayFee = { rate: OVERLAY_FEE_RATE, receiver:\n * T2000_OVERLAY_FEE_WALLET }` → fee charged. Structural inclusion (Audric's code can't\n * forget to pass it because it IS the code), not a toggle that defaults to safe.\n *\n * Pre-1.1.0: a module-level `OVERLAY_FEE_RECEIVER` constant defaulted to a Move object\n * ID. USDC sent there became OwnedObjects keyed to the object and was inaccessible.\n * Fixed by making the receiver a regular wallet address (T2000_OVERLAY_FEE_WALLET) AND\n * by removing the singleton pattern that hid the misconfig.\n */\nimport { AggregatorClient, Env, type FindRouterParams, type RouterDataV3 } from '@cetusprotocol/aggregator-sdk';\nimport { Transaction, type TransactionObjectArgument } from '@mysten/sui/transactions';\nimport type { SuiJsonRpcClient } from '@mysten/sui/jsonRpc';\nimport { resolveTokenType, getDecimalsForCoinType } from '../token-registry.js';\n\nexport interface OverlayFeeConfig {\n /** Fee rate as a fraction (e.g. 0.001 = 0.1%). Pass 0 to disable. */\n rate: number;\n /** Wallet address that receives the overlay fee. */\n receiver: string;\n}\n\nexport interface SwapRouteResult {\n routerData: RouterDataV3;\n amountIn: string;\n amountOut: string;\n byAmountIn: boolean;\n priceImpact: number;\n insufficientLiquidity: boolean;\n}\n\n/**\n * Default Audric swap overlay fee — 0.1%. Exported for consumers that want to use\n * the canonical Audric rate (the Audric prepare-route does this). Changing this\n * rate requires a coordinated SDK + audric release.\n */\nexport const OVERLAY_FEE_RATE = 0.001;\n\n/**\n * Cache `AggregatorClient` instances by `(signer + overlay rate + overlay receiver)`.\n * Per-call instantiation is cheap (the client is mostly config), but caching avoids\n * pointless re-allocation when the same caller swaps multiple times in a loop.\n */\nconst clientCache = new Map<string, AggregatorClient>();\n\nfunction getClient(walletAddress: string, overlayFee?: OverlayFeeConfig): AggregatorClient {\n const rate = overlayFee?.rate ?? 0;\n const receiver = overlayFee?.receiver ?? '';\n const key = `${walletAddress}|${rate}|${receiver}`;\n\n const cached = clientCache.get(key);\n if (cached) return cached;\n\n const client = new AggregatorClient({\n signer: walletAddress,\n env: Env.Mainnet,\n ...(rate > 0 && receiver\n ? { overlayFeeRate: rate, overlayFeeReceiver: receiver }\n : {}),\n });\n clientCache.set(key, client);\n return client;\n}\n\n/**\n * Find the optimal swap route via Cetus Aggregator REST API.\n *\n * Pass `overlayFee` to charge an overlay fee on the output (Audric's pattern).\n * Omit it for a fee-free swap (CLI / direct SDK pattern).\n */\nexport async function findSwapRoute(params: {\n walletAddress: string;\n from: string;\n to: string;\n amount: bigint;\n byAmountIn: boolean;\n overlayFee?: OverlayFeeConfig;\n /**\n * Optional Cetus provider allow-list. When omitted, all 30+ DEXes\n * are eligible. Sponsored flows (Enoki) MUST pass an exclusion list\n * computed via `getProvidersExcluding([...])` from the Cetus SDK to\n * remove Pyth-dependent providers (HAEDALPMM, METASTABLE, OBRIC,\n * STEAMM_OMM, STEAMM_OMM_V2, SEVENK, HAEDALHMMV2) — those reference\n * `tx.gas` for oracle fees, which Enoki rejects in sponsored txs.\n * Non-sponsored callers (CLI, direct SDK) leave this undefined.\n */\n providers?: string[];\n}): Promise<SwapRouteResult | null> {\n const client = getClient(params.walletAddress, params.overlayFee);\n\n const findParams: FindRouterParams = {\n from: params.from,\n target: params.to,\n amount: params.amount.toString(),\n byAmountIn: params.byAmountIn,\n ...(params.providers ? { providers: params.providers } : {}),\n };\n\n const routerData = await client.findRouters(findParams);\n if (!routerData) return null;\n\n if (routerData.insufficientLiquidity) {\n return {\n routerData,\n amountIn: routerData.amountIn.toString(),\n amountOut: routerData.amountOut.toString(),\n byAmountIn: params.byAmountIn,\n priceImpact: normalizePriceImpact(routerData.deviationRatio),\n insufficientLiquidity: true,\n };\n }\n\n if (routerData.error) {\n const { T2000Error } = await import('../errors.js');\n throw new T2000Error('SWAP_FAILED', `Cetus routing error: ${routerData.error.msg} (code ${routerData.error.code})`);\n }\n\n return {\n routerData,\n amountIn: routerData.amountIn.toString(),\n amountOut: routerData.amountOut.toString(),\n byAmountIn: params.byAmountIn,\n priceImpact: normalizePriceImpact(routerData.deviationRatio),\n insufficientLiquidity: false,\n };\n}\n\n/**\n * Cetus' aggregator types `deviationRatio` as `number`, but in some routes\n * the router actually returns a string (\"0.001234\"). The SDK type lies, so we\n * always coerce to a finite number here (NaN/null/undefined → 0). Without\n * this every downstream consumer that calls `priceImpact.toFixed(...)` will\n * crash at runtime — including the Audric SwapQuoteCard, which takes the\n * whole chat UI down through its error boundary.\n */\nfunction normalizePriceImpact(value: unknown): number {\n const n = typeof value === 'number' ? value : Number(value);\n return Number.isFinite(n) ? n : 0;\n}\n\n/**\n * Build a swap PTB from a route result. The caller must provide an input coin\n * obtained by splitting/merging wallet coins.\n *\n * **Important:** Cetus's `routerSwap` reads the overlay-fee config from the\n * AggregatorClient instance. The `overlayFee` param here MUST match the one\n * passed to `findSwapRoute` for the same swap (otherwise you'll hit the cache\n * boundary and get a different client with different overlay config).\n */\nexport async function buildSwapTx(params: {\n walletAddress: string;\n route: SwapRouteResult;\n tx: Transaction;\n inputCoin: TransactionObjectArgument;\n slippage: number;\n overlayFee?: OverlayFeeConfig;\n}): Promise<TransactionObjectArgument> {\n const client = getClient(params.walletAddress, params.overlayFee);\n const clampedSlippage = Math.max(0.001, Math.min(params.slippage, 0.05));\n\n const outputCoin = await client.routerSwap({\n router: params.route.routerData,\n inputCoin: params.inputCoin,\n slippage: clampedSlippage,\n txb: params.tx,\n });\n\n return outputCoin;\n}\n\n/**\n * Append a swap fragment to an existing PTB. SPEC 7 § \"Layer 1\" Cetus\n * appender. Two modes, dispatched by the presence of `input.inputCoin`:\n *\n * - **Wallet mode** (`inputCoin` omitted) — fetches `from`-asset coins\n * from the sender's wallet (paginated), merges/splits to the\n * requested amount, runs the swap. Mirrors the audric host's\n * `transactions/prepare/route.ts` swap branch (P2.2c will retire that\n * branch in favor of this appender via `composeTx`).\n *\n * - **Chain mode** (`inputCoin` provided) — consumes the passed-in coin\n * reference (typically produced by an upstream appender like\n * `addWithdrawToTx`) directly, no wallet fetch / no merge / no\n * split. This is the SPEC 7 multi-write enabler (\"withdraw → swap →\n * save\" without intermediate wallet materialization).\n *\n * **SUI in wallet mode:** uses `client.getCoins` like every other\n * token. This works for sponsored flows (Enoki — `tx.gas` belongs to\n * the sponsor, swap input comes from the user's separate SUI coin\n * objects). For non-sponsored flows where `tx.gas` IS the user's SUI,\n * the caller should pre-build the inputCoin via\n * `tx.splitCoins(tx.gas, [rawAmount])[0]` and pass it via chain mode\n * instead. (`T2000.swap()` already handles this internally — direct SDK\n * users go through the high-level class, not through this appender.)\n *\n * **`swapAll` semantics (wallet mode):** if the requested raw amount\n * is >= the wallet's total `from` balance, the appender consumes the\n * entire merged primary coin (not a split), matching audric's host\n * route's `swapAll` clipping. The returned `effectiveAmountIn` reflects\n * the actual consumed amount in display units.\n *\n * **Slippage:** clamped to [0.001, 0.05] (0.1% – 5%). Defaults to 0.01.\n *\n * @returns\n * - `coin` — output coin reference, ready for downstream consumption\n * (e.g. `addSaveToTx`) or wallet transfer (`tx.transferObjects`).\n * - `effectiveAmountIn` — display-units input amount the swap actually\n * consumes (handles `swapAll` clipping in wallet mode; in chain mode\n * echoes the requested `input.amount`).\n * - `expectedAmountOut` — display-units output amount per the route\n * quote. Actual on-chain output may differ within slippage.\n * - `route` — raw `SwapRouteResult` for downstream telemetry / logging.\n */\nexport async function addSwapToTx(\n tx: Transaction,\n client: SuiJsonRpcClient,\n address: string,\n input: {\n from: string;\n to: string;\n amount: number;\n slippage?: number;\n byAmountIn?: boolean;\n overlayFee?: OverlayFeeConfig;\n inputCoin?: TransactionObjectArgument;\n /**\n * Optional Cetus provider allow-list. Forwarded to `findSwapRoute`.\n * Sponsored flows (Enoki) MUST pass `getProvidersExcluding([...])`\n * to remove Pyth-dependent providers — see `findSwapRoute`'s JSDoc\n * for the exclusion list. Non-sponsored callers omit this.\n */\n providers?: string[];\n },\n): Promise<{\n coin: TransactionObjectArgument;\n effectiveAmountIn: number;\n expectedAmountOut: number;\n route: SwapRouteResult;\n}> {\n const { T2000Error } = await import('../errors.js');\n\n const fromType = resolveTokenType(input.from);\n const toType = resolveTokenType(input.to);\n if (!fromType) throw new T2000Error('ASSET_NOT_SUPPORTED', `Unknown token: ${input.from}. Provide the symbol (USDC, SUI, ...) or full coin type.`);\n if (!toType) throw new T2000Error('ASSET_NOT_SUPPORTED', `Unknown token: ${input.to}. Provide the symbol (USDC, SUI, ...) or full coin type.`);\n if (fromType === toType) throw new T2000Error('SWAP_FAILED', 'Cannot swap a token to itself');\n if (!Number.isFinite(input.amount) || input.amount <= 0) {\n throw new T2000Error('INVALID_AMOUNT', 'Amount must be greater than zero');\n }\n\n const fromDecimals = getDecimalsForCoinType(fromType);\n const toDecimals = getDecimalsForCoinType(toType);\n const requestedRaw = BigInt(Math.floor(input.amount * 10 ** fromDecimals));\n\n const slippage = Math.max(0.001, Math.min(input.slippage ?? 0.01, 0.05));\n const byAmountIn = input.byAmountIn ?? true;\n\n let inputCoin: TransactionObjectArgument;\n let effectiveRaw: bigint;\n\n if (input.inputCoin) {\n inputCoin = input.inputCoin;\n effectiveRaw = requestedRaw;\n } else {\n // Delegate to the canonical wallet-mode prelude. Critically, this path\n // shares a per-PTB merge cache with every other appender via\n // `selectAndSplitCoin` — when a multi-write bundle includes\n // `swap_execute` alongside `save_deposit`/`send_transfer` of the same\n // input asset (e.g. swap+save+send all from USDC), the second/third\n // appender hits the cache and splits from the already-merged primary\n // instead of re-emitting `mergeCoins` on consumed input slots. That's\n // the P2.7 multi-write bundle fix landed 2026-05-02.\n const { selectAndSplitCoin } = await import('../wallet/coinSelection.js');\n const result = await selectAndSplitCoin(tx, client, address, fromType, requestedRaw);\n inputCoin = result.coin;\n effectiveRaw = result.effectiveAmount;\n }\n\n const route = await findSwapRoute({\n walletAddress: address,\n from: fromType,\n to: toType,\n amount: effectiveRaw,\n byAmountIn,\n overlayFee: input.overlayFee,\n providers: input.providers,\n });\n\n if (!route) {\n throw new T2000Error('SWAP_NO_ROUTE', `No swap route found for ${input.from} → ${input.to}`);\n }\n if (route.insufficientLiquidity) {\n throw new T2000Error('SWAP_NO_ROUTE', `Insufficient liquidity for ${input.from} → ${input.to}`);\n }\n\n const outputCoin = await buildSwapTx({\n walletAddress: address,\n route,\n tx,\n inputCoin,\n slippage,\n overlayFee: input.overlayFee,\n });\n\n return {\n coin: outputCoin,\n effectiveAmountIn: Number(effectiveRaw) / 10 ** fromDecimals,\n expectedAmountOut: Number(route.amountOut) / 10 ** toDecimals,\n route,\n };\n}\n\n/**\n * Simulate a swap transaction without executing it.\n */\nexport async function simulateSwap(params: {\n walletAddress: string;\n tx: Transaction;\n overlayFee?: OverlayFeeConfig;\n}): Promise<{ success: boolean; error?: string }> {\n const client = getClient(params.walletAddress, params.overlayFee);\n try {\n await client.devInspectTransactionBlock(params.tx);\n return { success: true };\n } catch (err) {\n return { success: false, error: err instanceof Error ? err.message : String(err) };\n }\n}\n\n// Re-export from the canonical token registry for backward-compat.\nexport { TOKEN_MAP, resolveTokenType } from '../token-registry.js';\n","import { T2000Error } from '../errors.js';\n\nexport type SafeguardRule = 'locked' | 'maxPerTx' | 'maxDailySend';\n\nexport interface SafeguardErrorDetails {\n attempted?: number;\n limit?: number;\n current?: number;\n}\n\nexport class SafeguardError extends T2000Error {\n readonly rule: SafeguardRule;\n readonly details: SafeguardErrorDetails;\n\n constructor(rule: SafeguardRule, details: SafeguardErrorDetails, message?: string) {\n const msg = message ?? buildMessage(rule, details);\n super('SAFEGUARD_BLOCKED' as any, msg, { rule, ...details });\n this.name = 'SafeguardError';\n this.rule = rule;\n this.details = details;\n }\n\n override toJSON() {\n return {\n error: 'SAFEGUARD_BLOCKED' as const,\n message: this.message,\n retryable: this.retryable,\n data: { rule: this.rule, ...this.details },\n };\n }\n}\n\nfunction buildMessage(rule: SafeguardRule, details: SafeguardErrorDetails): string {\n switch (rule) {\n case 'locked':\n return 'Agent is locked. All operations are frozen.';\n case 'maxPerTx':\n return `Amount $${(details.attempted ?? 0).toFixed(2)} exceeds per-transaction limit ($${(details.limit ?? 0).toFixed(2)})`;\n case 'maxDailySend':\n return `Daily send limit reached ($${(details.current ?? 0).toFixed(2)}/$${(details.limit ?? 0).toFixed(2)} used today)`;\n }\n}\n","export interface SafeguardConfig {\n locked: boolean;\n maxPerTx: number;\n maxDailySend: number;\n dailyUsed: number;\n dailyResetDate: string;\n maxLeverage?: number;\n maxPositionSize?: number;\n}\n\nexport interface TxMetadata {\n operation:\n | 'send'\n | 'save'\n | 'withdraw'\n | 'borrow'\n | 'repay'\n | 'pay';\n amount?: number;\n}\n\nexport const OUTBOUND_OPS = new Set<TxMetadata['operation']>([\n 'send',\n 'pay',\n]);\n\nexport const DEFAULT_SAFEGUARD_CONFIG: SafeguardConfig = {\n locked: false,\n maxPerTx: 0,\n maxDailySend: 0,\n dailyUsed: 0,\n dailyResetDate: '',\n};\n"]}
1
+ {"version":3,"sources":["../src/errors.ts","../src/token-registry.ts","../src/wallet/keypairSigner.ts","../src/wallet/zkLoginSigner.ts","../src/browser.ts","../src/constants.ts","../src/utils/sui.ts","../src/wallet/classify.ts","../src/wallet/history.ts","../src/utils/format.ts","../src/utils/base64.ts","../src/protocols/protocolFee.ts","../src/protocols/cetus-swap.ts","../src/safeguards/errors.ts","../src/safeguards/types.ts"],"names":["T2000Error","TOKEN_MAP","COIN_REGISTRY","SUI_TYPE","USDC_TYPE","USDT_TYPE","USDSUI_TYPE","USDE_TYPE","ETH_TYPE","WBTC_TYPE","WAL_TYPE","NAVX_TYPE","IKA_TYPE","LOFI_TYPE","MANIFEST_TYPE","normalizeSuiAddress","isValidSuiAddress","AggregatorClient","Env"],"mappings":";;;;;;;;;;;;;;;;;AAAA,IAAA,cAAA,GAAA,EAAA;AAAA,QAAA,CAAA,cAAA,EAAA;AAAA,EAAA,UAAA,EAAA,MAAAA,kBAAA;AAAA,EAAA,WAAA,EAAA,MAAA,WAAA;AAAA,EAAA,gBAAA,EAAA,MAAA,gBAAA;AAAA,EAAA,cAAA,EAAA,MAAA,cAAA;AAAA,EAAA,qBAAA,EAAA,MAAA;AAAA,CAAA,CAAA;AA8DO,SAAS,eAAe,KAAA,EAA4B;AACzD,EAAA,MAAM,MAAM,KAAA,YAAiB,KAAA,GAAQ,KAAA,CAAM,OAAA,GAAU,OAAO,KAAK,CAAA;AAEjE,EAAA,IAAI,IAAI,QAAA,CAAS,UAAU,KAAK,GAAA,CAAI,QAAA,CAAS,WAAW,CAAA,EAAG;AACzD,IAAA,OAAO,IAAIA,kBAAA,CAAW,oBAAA,EAAsB,uBAAuB,CAAA;AAAA,EACrE;AACA,EAAA,IAAI,IAAI,QAAA,CAAS,cAAc,KAAK,GAAA,CAAI,QAAA,CAAS,cAAc,CAAA,EAAG;AAChE,IAAA,OAAO,IAAIA,kBAAA,CAAW,sBAAA,EAAwB,sBAAsB,CAAA;AAAA,EACtE;AAEA,EAAA,OAAO,IAAIA,kBAAA,CAAW,SAAA,EAAW,GAAA,EAAK,QAAW,IAAI,CAAA;AACvD;AAEO,SAAS,iBAAiB,IAAA,EAAsB;AACrD,EAAA,MAAM,aAAA,GAAwC;AAAA,IAC5C,CAAA,EAAG,gCA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IAC1H,KAAK,cAAA;AACH,MAAA,OAAO,CAAA,2BAAA,EAAA,CAA+B,OAAA,CAAQ,OAAA,IAAW,CAAA,EAAG,OAAA,CAAQ,CAAC,CAAC,CAAA,EAAA,EAAA,CAAM,OAAA,CAAQ,KAAA,IAAS,CAAA,EAAG,OAAA,CAAQ,CAAC,CAAC,CAAA,YAAA,CAAA;AAAA;AAEhH;;;ACpBO,IAAM,YAAA,uBAAmB,GAAA,CAA6B;AAAA,EAC3D,MAAA;AAAA,EACA;AACF,CAAC;AAEM,IAAM,wBAAA,GAA4C;AAAA,EACvD,MAAA,EAAQ,KAAA;AAAA,EACR,QAAA,EAAU,CAAA;AAAA,EACV,YAAA,EAAc,CAAA;AAAA,EACd,SAAA,EAAW,CAAA;AAAA,EACX,cAAA,EAAgB;AAClB;;;AVmGA,mBAAA,EAAA","file":"browser.cjs","sourcesContent":["export type T2000ErrorCode =\n | 'INSUFFICIENT_BALANCE'\n | 'INSUFFICIENT_GAS'\n | 'INVALID_ADDRESS'\n | 'INVALID_AMOUNT'\n | 'WALLET_NOT_FOUND'\n | 'WALLET_LOCKED'\n | 'WALLET_EXISTS'\n | 'SIMULATION_FAILED'\n | 'TRANSACTION_FAILED'\n | 'ASSET_NOT_SUPPORTED'\n | 'INVALID_ASSET'\n | 'HEALTH_FACTOR_TOO_LOW'\n | 'WITHDRAW_WOULD_LIQUIDATE'\n | 'WITHDRAW_FAILED'\n | 'NO_COLLATERAL'\n | 'PROTOCOL_PAUSED'\n | 'PROTOCOL_UNAVAILABLE'\n | 'RPC_ERROR'\n | 'RPC_UNREACHABLE'\n | 'PRICE_EXCEEDS_LIMIT'\n | 'UNSUPPORTED_NETWORK'\n | 'PAYMENT_EXPIRED'\n | 'DUPLICATE_PAYMENT'\n | 'FACILITATOR_REJECTION'\n | 'CONTACT_NOT_FOUND'\n | 'INVALID_CONTACT_NAME'\n | 'FACILITATOR_TIMEOUT'\n | 'SAFEGUARD_BLOCKED'\n | 'SWAP_NO_ROUTE'\n | 'SWAP_FAILED'\n | 'CHAIN_MODE_INVALID'\n | 'UNKNOWN';\n\nexport interface T2000ErrorData {\n reason?: string;\n [key: string]: unknown;\n}\n\nexport class T2000Error extends Error {\n readonly code: T2000ErrorCode;\n readonly data?: T2000ErrorData;\n readonly retryable: boolean;\n\n constructor(code: T2000ErrorCode, message: string, data?: T2000ErrorData, retryable = false) {\n super(message);\n this.name = 'T2000Error';\n this.code = code;\n this.data = data;\n this.retryable = retryable;\n }\n\n toJSON() {\n return {\n error: this.code,\n message: this.message,\n ...(this.data && { data: this.data }),\n retryable: this.retryable,\n };\n }\n}\n\nexport function mapWalletError(error: unknown): T2000Error {\n const msg = error instanceof Error ? error.message : String(error);\n\n if (msg.includes('rejected') || msg.includes('cancelled')) {\n return new T2000Error('TRANSACTION_FAILED', 'Transaction cancelled');\n }\n if (msg.includes('Insufficient') || msg.includes('insufficient')) {\n return new T2000Error('INSUFFICIENT_BALANCE', 'Insufficient balance');\n }\n\n return new T2000Error('UNKNOWN', msg, undefined, true);\n}\n\nexport function mapMoveAbortCode(code: number): string {\n const abortMessages: Record<number, string> = {\n 1: 'Protocol is temporarily paused',\n 2: 'Amount must be greater than zero',\n 3: 'Invalid operation type',\n 4: 'Fee rate exceeds maximum',\n 5: 'Insufficient treasury balance',\n 6: 'Not authorized',\n 7: 'Package version mismatch — upgrade required',\n 8: 'Timelock is active — wait for expiry',\n 9: 'No pending change to execute',\n 10: 'Already at current version',\n // NAVI Protocol abort codes\n 1502: 'Oracle price is stale — try again in a moment',\n 1503: 'Withdrawal amount is invalid (zero or dust) — try a specific amount instead of \"all\"',\n 1600: 'Health factor too low — withdrawal would risk liquidation',\n 1605: 'Asset borrowing is disabled or at capacity on this protocol',\n // NAVI utils abort codes\n 46000: 'Insufficient balance to repay — withdraw some savings first to get cash',\n };\n return abortMessages[code] ?? `Move abort code: ${code}`;\n}\n\n/**\n * Check if an error message contains a MoveAbort — these are on-chain\n * failures that will fail no matter how many times you retry.\n */\nexport function isMoveAbort(msg: string): boolean {\n return msg.includes('MoveAbort') || msg.includes('MovePrimitiveRuntimeError');\n}\n\nexport function parseMoveAbortMessage(msg: string): string {\n const abortMatch = msg.match(/abort code:\\s*(\\d+)/i) ?? msg.match(/MoveAbort[^,]*,\\s*(\\d+)/);\n if (abortMatch) {\n const code = parseInt(abortMatch[1], 10);\n\n const moduleMatch = msg.match(/Identifier\\(\"([^\"]+)\"\\)/) ?? msg.match(/in '([^']+)'/);\n const fnMatch = msg.match(/function_name:\\s*Some\\(\"([^\"]+)\"\\)/);\n const context = `${moduleMatch?.[1] ?? ''}${fnMatch ? `::${fnMatch[1]}` : ''}`.toLowerCase();\n const suffix = moduleMatch\n ? ` [${moduleMatch[1]}${fnMatch ? `::${fnMatch[1]}` : ''}]`\n : '';\n\n if (context.includes('slippage')) {\n return `Slippage too high — price moved during execution${suffix}`;\n }\n if (context.includes('balance::split') || context.includes('balance::ENotEnough')) {\n return `Insufficient on-chain balance${suffix}`;\n }\n\n const mapped = mapMoveAbortCode(code);\n return `${mapped}${suffix}`;\n }\n return msg;\n}\n","/**\n * Unified token registry — single source of truth for coin types, decimals, symbols, and tiers.\n *\n * ZERO heavy dependencies. Safe to import from any context (server, browser, Edge).\n *\n * Tier 1: USDC — the financial layer (save, borrow, receive, yield, allowances, marketplace, MPP).\n * Tier 2: 15 curated swap assets — hold, trade, and send only.\n * No tier: Legacy tokens kept for display accuracy (existing NAVI positions). No new operations.\n *\n * To add a new token: add ONE entry to COIN_REGISTRY below. Everything else derives from it.\n * Gate for Tier 2 addition: confirmed deep Cetus liquidity + clear user need.\n */\n\nexport interface CoinMeta {\n type: string;\n decimals: number;\n symbol: string;\n tier?: 1 | 2;\n}\n\n/**\n * Canonical coin registry.\n * Key = user-friendly name (used in swap_execute, CLI, prompts).\n */\nexport const COIN_REGISTRY: Record<string, CoinMeta> = {\n // ── Tier 1 — Financial layer ──────────────────────────────────────────\n USDC: { type: '0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC', decimals: 6, symbol: 'USDC', tier: 1 },\n\n // ── Tier 2 — Swap assets (15 tokens) ──────────────────────────────────\n SUI: { type: '0x2::sui::SUI', decimals: 9, symbol: 'SUI', tier: 2 },\n wBTC: { type: '0x0041f9f9344cac094454cd574e333c4fdb132d7bcc9379bcd4aab485b2a63942::wbtc::WBTC', decimals: 8, symbol: 'wBTC', tier: 2 },\n ETH: { type: '0xd0e89b2af5e4910726fbcd8b8dd37bb79b29e5f83f7491bca830e94f7f226d29::eth::ETH', decimals: 8, symbol: 'ETH', tier: 2 },\n GOLD: { type: '0x9d297676e7a4b771ab023291377b2adfaa4938fb9080b8d12430e4b108b836a9::xaum::XAUM', decimals: 9, symbol: 'GOLD', tier: 2 },\n DEEP: { type: '0xdeeb7a4662eec9f2f3def03fb937a663dddaa2e215b8078a284d026b7946c270::deep::DEEP', decimals: 6, symbol: 'DEEP', tier: 2 },\n WAL: { type: '0x356a26eb9e012a68958082340d4c4116e7f55615cf27affcff209cf0ae544f59::wal::WAL', decimals: 9, symbol: 'WAL', tier: 2 },\n NS: { type: '0x5145494a5f5100e645e4b0aa950fa6b68f614e8c59e17bc5ded3495123a79178::ns::NS', decimals: 6, symbol: 'NS', tier: 2 },\n IKA: { type: '0x7262fb2f7a3a14c888c438a3cd9b912469a58cf60f367352c46584262e8299aa::ika::IKA', decimals: 9, symbol: 'IKA', tier: 2 },\n CETUS: { type: '0x06864a6f921804860930db6ddbe2e16acdf8504495ea7481637a1c8b9a8fe54b::cetus::CETUS', decimals: 9, symbol: 'CETUS', tier: 2 },\n NAVX: { type: '0xa99b8952d4f7d947ea77fe0ecdcc9e5fc0bcab2841d6e2a5aa00c3044e5544b5::navx::NAVX', decimals: 9, symbol: 'NAVX', tier: 2 },\n vSUI: { type: '0x549e8b69270defbfafd4f94e17ec44cdbdd99820b33bda2278dea3b9a32d3f55::cert::CERT', decimals: 9, symbol: 'vSUI', tier: 2 },\n haSUI: { type: '0xbde4ba4c2e274a60ce15c1cfff9e5c42e41654ac8b6d906a57efa4bd3c29f47d::hasui::HASUI', decimals: 9, symbol: 'haSUI', tier: 2 },\n afSUI: { type: '0xf325ce1300e8dac124071d3152c5c5ee6174914f8bc2161e88329cf579246efc::afsui::AFSUI', decimals: 9, symbol: 'afSUI', tier: 2 },\n LOFI: { type: '0xf22da9a24ad027cccb5f2d496cbe91de953d363513db08a3a734d361c7c17503::LOFI::LOFI', decimals: 9, symbol: 'LOFI', tier: 2 },\n MANIFEST: { type: '0xc466c28d87b3d5cd34f3d5c088751532d71a38d93a8aae4551dd56272cfb4355::manifest::MANIFEST', decimals: 9, symbol: 'MANIFEST', tier: 2 },\n\n // ── Legacy — no tier, kept for display accuracy on existing positions ──\n USDT: { type: '0x375f70cf2ae4c00bf37117d0c85a2c71545e6ee05c4a5c7d282cd66a4504b068::usdt::USDT', decimals: 6, symbol: 'USDT' },\n USDe: { type: '0x41d587e5336f1c86cad50d38a7136db99333bb9bda91cea4ba69115defeb1402::sui_usde::SUI_USDE', decimals: 6, symbol: 'USDe' },\n USDSUI: { type: '0x44f838219cf67b058f3b37907b655f226153c18e33dfcd0da559a844fea9b1c1::usdsui::USDSUI', decimals: 6, symbol: 'USDsui' },\n};\n\n/** Reverse lookup: coin type → CoinMeta. Built once at import time. */\nconst BY_TYPE = new Map<string, CoinMeta>();\nfor (const meta of Object.values(COIN_REGISTRY)) {\n BY_TYPE.set(meta.type, meta);\n}\n\n// ── Lookup helpers ───────────────────────────────────────────────────────\n\n/**\n * Returns the registry metadata for a coin type, or `undefined` if the coin\n * is not in the registry. Use this when you need to distinguish \"known coin\"\n * from \"supported coin\" — `isSupported` only flags tiered (active) coins,\n * but legacy coins like USDsui / USDe / USDT are in the registry without a\n * tier and still need canonical-symbol resolution.\n */\nexport function getCoinMeta(coinType: string): CoinMeta | undefined {\n return BY_TYPE.get(coinType);\n}\n\n/**\n * Returns true if the coin type appears anywhere in COIN_REGISTRY (tier 1, 2,\n * OR legacy/no-tier). Different from `isSupported`, which excludes legacy\n * entries. The blockvision-prices canonical-symbol gate uses this looser\n * check so that USDsui (legacy/no-tier today, but with a registry-canonical\n * mixed-case symbol) still wins over BlockVision's uppercase 'USDSUI'.\n */\nexport function isInRegistry(coinType: string): boolean {\n return BY_TYPE.has(coinType);\n}\n\n// ── Tier helpers ─────────────────────────────────────────────────────────\n\n/** Returns true if the coin type is Tier 1 (USDC — the financial layer). */\nexport function isTier1(coinType: string): boolean {\n const meta = BY_TYPE.get(coinType);\n return meta?.tier === 1;\n}\n\n/** Returns true if the coin type is Tier 2 (curated swap asset). */\nexport function isTier2(coinType: string): boolean {\n const meta = BY_TYPE.get(coinType);\n return meta?.tier === 2;\n}\n\n/** Returns true if the coin type is actively supported (Tier 1 or Tier 2). */\nexport function isSupported(coinType: string): boolean {\n const meta = BY_TYPE.get(coinType);\n return meta?.tier !== undefined;\n}\n\n/** Returns the tier for a coin type, or undefined if legacy/unknown. */\nexport function getTier(coinType: string): 1 | 2 | undefined {\n return BY_TYPE.get(coinType)?.tier;\n}\n\n// ── Lookup helpers ───────────────────────────────────────────────────────\n\n/**\n * Get decimals for any coin type. Checks full type match, then suffix match, then defaults to 9.\n * Works for both tiered and legacy tokens.\n */\nexport function getDecimalsForCoinType(coinType: string): number {\n const direct = BY_TYPE.get(coinType);\n if (direct) return direct.decimals;\n\n const suffix = coinType.split('::').slice(1).join('::').toUpperCase();\n if (suffix) {\n for (const meta of BY_TYPE.values()) {\n const metaSuffix = meta.type.split('::').slice(1).join('::').toUpperCase();\n if (metaSuffix === suffix) return meta.decimals;\n }\n }\n\n return 9;\n}\n\n/**\n * Resolve a full coin type to a user-friendly symbol.\n * Returns the last `::` segment if not in the registry.\n */\nexport function resolveSymbol(coinType: string): string {\n const direct = BY_TYPE.get(coinType);\n if (direct) return direct.symbol;\n\n const suffix = coinType.split('::').slice(1).join('::').toUpperCase();\n if (suffix) {\n for (const meta of BY_TYPE.values()) {\n const metaSuffix = meta.type.split('::').slice(1).join('::').toUpperCase();\n if (metaSuffix === suffix) return meta.symbol;\n }\n }\n\n return coinType.split('::').pop() ?? coinType;\n}\n\n/**\n * Name → type map for swap resolution. Derived from COIN_REGISTRY.\n * Contains BOTH original-case and UPPERCASE keys for case-insensitive lookup.\n */\nexport const TOKEN_MAP: Record<string, string> = (() => {\n const map: Record<string, string> = {};\n for (const [name, meta] of Object.entries(COIN_REGISTRY)) {\n map[name] = meta.type;\n map[name.toUpperCase()] = meta.type;\n }\n return map;\n})();\n\n/**\n * Resolve a user-friendly token name to its full coin type.\n * Returns the input unchanged if already a full coin type (contains \"::\").\n * Case-insensitive: 'usde', 'USDe', 'USDE' all resolve correctly.\n */\nexport function resolveTokenType(nameOrType: string): string | null {\n if (nameOrType.includes('::')) return nameOrType;\n return TOKEN_MAP[nameOrType] ?? TOKEN_MAP[nameOrType.toUpperCase()] ?? null;\n}\n\n/** Common type constants for direct import. */\nexport const SUI_TYPE = COIN_REGISTRY.SUI.type;\nexport const USDC_TYPE = COIN_REGISTRY.USDC.type;\nexport const USDT_TYPE = COIN_REGISTRY.USDT.type;\nexport const USDSUI_TYPE = COIN_REGISTRY.USDSUI.type;\nexport const USDE_TYPE = COIN_REGISTRY.USDe.type;\nexport const ETH_TYPE = COIN_REGISTRY.ETH.type;\nexport const WBTC_TYPE = COIN_REGISTRY.wBTC.type;\nexport const WAL_TYPE = COIN_REGISTRY.WAL.type;\nexport const NAVX_TYPE = COIN_REGISTRY.NAVX.type;\nexport const IKA_TYPE = COIN_REGISTRY.IKA.type;\nexport const LOFI_TYPE = COIN_REGISTRY.LOFI.type;\nexport const MANIFEST_TYPE = COIN_REGISTRY.MANIFEST.type;\n","import type { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519';\nimport type { TransactionSigner } from '../signer.js';\n\nexport class KeypairSigner implements TransactionSigner {\n constructor(private readonly keypair: Ed25519Keypair) {}\n\n getAddress(): string {\n return this.keypair.getPublicKey().toSuiAddress();\n }\n\n async signTransaction(txBytes: Uint8Array): Promise<{ signature: string }> {\n return this.keypair.signTransaction(txBytes);\n }\n\n /** Access the underlying keypair for APIs that still require it directly. */\n getKeypair(): Ed25519Keypair {\n return this.keypair;\n }\n}\n","import type { Ed25519Keypair } from '@mysten/sui/keypairs/ed25519';\nimport type { TransactionSigner } from '../signer.js';\n\nexport interface ZkLoginProof {\n proofPoints: {\n a: string[];\n b: string[][];\n c: string[];\n };\n issBase64Details: {\n indexMod4: number;\n value: string;\n };\n headerBase64: string;\n addressSeed: string;\n}\n\nexport class ZkLoginSigner implements TransactionSigner {\n constructor(\n private readonly ephemeralKeypair: Ed25519Keypair,\n private readonly zkProof: ZkLoginProof,\n private readonly userAddress: string,\n private readonly maxEpoch: number,\n ) {}\n\n getAddress(): string {\n return this.userAddress;\n }\n\n async signTransaction(txBytes: Uint8Array): Promise<{ signature: string }> {\n const { getZkLoginSignature } = await import('@mysten/zklogin');\n const ephSig = await this.ephemeralKeypair.signTransaction(txBytes);\n return {\n signature: getZkLoginSignature({\n inputs: this.zkProof,\n maxEpoch: this.maxEpoch,\n userSignature: ephSig.signature,\n }),\n };\n }\n\n isExpired(currentEpoch: number): boolean {\n return currentEpoch >= this.maxEpoch;\n }\n}\n","/**\n * Browser-safe entry point for @t2000/sdk.\n *\n * Exports everything the web app needs WITHOUT Node-only modules:\n * - keyManager (fs-based wallet encryption)\n * - ContactManager (file-based contacts)\n *\n * Protocol adapters are NOT statically exported here — import them\n * via dynamic import() in the web app to keep the initial bundle small.\n */\n\n// Signer abstraction\nexport type { TransactionSigner } from './signer.js';\nexport { KeypairSigner } from './wallet/keypairSigner.js';\nexport { ZkLoginSigner, type ZkLoginProof } from './wallet/zkLoginSigner.js';\n\n// Error handling\nexport { T2000Error, mapWalletError, mapMoveAbortCode } from './errors.js';\nexport type { T2000ErrorCode, T2000ErrorData } from './errors.js';\n\n// Constants\nexport {\n MIST_PER_SUI,\n SUI_DECIMALS,\n USDC_DECIMALS,\n BPS_DENOMINATOR,\n SAVE_FEE_BPS,\n BORROW_FEE_BPS,\n T2000_OVERLAY_FEE_WALLET,\n SUPPORTED_ASSETS,\n CLOCK_ID,\n DEFAULT_NETWORK,\n} from './constants.js';\nexport type { SupportedAsset, StableAsset } from './constants.js';\nexport {\n STABLE_ASSETS,\n ALL_NAVI_ASSETS,\n GAS_RESERVE_MIN,\n} from './constants.js';\n\n// Utilities\nexport { validateAddress, truncateAddress } from './utils/sui.js';\nexport {\n KNOWN_TARGETS,\n LABEL_PATTERNS,\n classifyAction,\n classifyLabel,\n fallbackLabel,\n refineLendingLabel,\n classifyTransaction,\n extractTransferDetails,\n} from './wallet/classify.js';\nexport type {\n ClassifyBalanceChange,\n ClassifyResult,\n ExtractedTransfer,\n TxDirection,\n} from './wallet/classify.js';\n/**\n * RPC tx parsing helpers. Safe in the browser — they only do shape\n * inspection / classification and do not import any Node-only modules.\n * `queryHistory` and `queryTransaction` are not re-exported here\n * because they take a Node `SuiJsonRpcClient`; consumers can build\n * the same flow with `parseSuiRpcTx` + their own RPC fetch.\n */\nexport {\n parseSuiRpcTx,\n extractTxSender,\n extractTxCommands,\n} from './wallet/history.js';\nexport type { SuiRpcTxBlock } from './wallet/history.js';\nexport {\n mistToSui,\n suiToMist,\n usdcToRaw,\n rawToUsdc,\n stableToRaw,\n rawToStable,\n getDecimals,\n formatUsd,\n formatSui,\n formatAssetAmount,\n} from './utils/format.js';\nexport { toBase64, fromBase64 } from './utils/base64.js';\n\n// Simulation — use dynamic import() to avoid Buffer dependency in browser bundles\n// import { simulateTransaction } from '@t2000/sdk' (main entry) for Node usage\nexport type { SimulationResult } from './utils/simulate.js';\n\n// Protocol fee\nexport { calculateFee, addFeeTransfer } from './protocols/protocolFee.js';\nexport type { ProtocolFeeInfo, FeeOperation } from './protocols/protocolFee.js';\n\n// Cetus aggregator helpers — Audric prepare/route.ts uses these directly to\n// build swap PTBs with overlay fees (per-call, not module-global).\nexport { findSwapRoute, buildSwapTx, OVERLAY_FEE_RATE } from './protocols/cetus-swap.js';\nexport type { SwapRouteResult, OverlayFeeConfig } from './protocols/cetus-swap.js';\n\n// Safeguards — only browser-safe exports (SafeguardEnforcer uses node:fs)\nexport { SafeguardError } from './safeguards/errors.js';\nexport type { SafeguardRule, SafeguardErrorDetails } from './safeguards/errors.js';\nexport type { SafeguardConfig, TxMetadata } from './safeguards/types.js';\nexport { OUTBOUND_OPS, DEFAULT_SAFEGUARD_CONFIG } from './safeguards/types.js';\n\n// Types\nexport type {\n BalanceResponse,\n GasReserve,\n SendResult,\n SaveResult,\n WithdrawResult,\n BorrowResult,\n RepayResult,\n HealthFactorResult,\n MaxWithdrawResult,\n MaxBorrowResult,\n AssetRates,\n RatesResult,\n PositionEntry,\n PositionsResult,\n EarningsResult,\n FundStatusResult,\n DepositInfo,\n TransactionRecord,\n ClaimRewardsResult,\n PendingReward,\n PayOptions,\n PayResult,\n} from './types.js';\n\n// Token registry — zero Node.js deps, safe for client-side use\nexport {\n COIN_REGISTRY,\n TOKEN_MAP,\n resolveTokenType,\n resolveSymbol,\n getDecimalsForCoinType,\n isTier1,\n isTier2,\n isSupported,\n getTier,\n SUI_TYPE,\n USDC_TYPE,\n USDT_TYPE,\n USDSUI_TYPE,\n USDE_TYPE,\n ETH_TYPE,\n WBTC_TYPE,\n WAL_TYPE,\n NAVX_TYPE,\n IKA_TYPE,\n LOFI_TYPE,\n MANIFEST_TYPE,\n} from './token-registry.js';\nexport type { CoinMeta } from './token-registry.js';\n","import { T2000Error } from './errors.js';\n\nexport const MIST_PER_SUI = 1_000_000_000n;\nexport const SUI_DECIMALS = 9;\nexport const USDC_DECIMALS = 6;\n\nexport const BPS_DENOMINATOR = 10_000n;\nexport const PRECISION = 1_000_000_000_000_000_000n;\n\nexport const MIN_DEPOSIT = 1_000_000n; // 1 USDC (6 decimals)\n\nexport const SAVE_FEE_BPS = 10n; // 0.1%\nexport const BORROW_FEE_BPS = 5n; // 0.05%\n\nexport const CLOCK_ID = '0x6';\n\nexport const SUPPORTED_ASSETS = {\n USDC: {\n type: '0xdba34672e30cb065b1f93e3ab55318768fd6fef66c15942c9f7cb846e2f900e7::usdc::USDC',\n decimals: 6,\n symbol: 'USDC',\n displayName: 'USDC',\n },\n USDT: {\n type: '0x375f70cf2ae4c00bf37117d0c85a2c71545e6ee05c4a5c7d282cd66a4504b068::usdt::USDT',\n decimals: 6,\n symbol: 'USDT',\n displayName: 'suiUSDT',\n },\n USDe: {\n type: '0x41d587e5336f1c86cad50d38a7136db99333bb9bda91cea4ba69115defeb1402::sui_usde::SUI_USDE',\n decimals: 6,\n symbol: 'USDe',\n displayName: 'suiUSDe',\n },\n USDsui: {\n type: '0x44f838219cf67b058f3b37907b655f226153c18e33dfcd0da559a844fea9b1c1::usdsui::USDSUI',\n decimals: 6,\n symbol: 'USDsui',\n displayName: 'USDsui',\n },\n SUI: {\n type: '0x2::sui::SUI',\n decimals: 9,\n symbol: 'SUI',\n displayName: 'SUI',\n },\n WAL: {\n type: '0x356a26eb9e012a68958082340d4c4116e7f55615cf27affcff209cf0ae544f59::wal::WAL',\n decimals: 9,\n symbol: 'WAL',\n displayName: 'WAL',\n },\n ETH: {\n type: '0xd0e89b2af5e4910726fbcd8b8dd37bb79b29e5f83f7491bca830e94f7f226d29::eth::ETH',\n decimals: 8,\n symbol: 'ETH',\n displayName: 'suiETH',\n },\n NAVX: {\n type: '0xa99b8952d4f7d947ea77fe0ecdcc9e5fc0bcab2841d6e2a5aa00c3044e5544b5::navx::NAVX',\n decimals: 9,\n symbol: 'NAVX',\n displayName: 'NAVX',\n },\n GOLD: {\n type: '0x9d297676e7a4b771ab023291377b2adfaa4938fb9080b8d12430e4b108b836a9::xaum::XAUM',\n decimals: 6,\n symbol: 'GOLD',\n displayName: 'XAUM',\n },\n} as const;\n\nexport type SupportedAsset = keyof typeof SUPPORTED_ASSETS;\nexport type StableAsset = 'USDC';\nexport const STABLE_ASSETS: readonly StableAsset[] = ['USDC'] as const;\nexport const ALL_NAVI_ASSETS: readonly SupportedAsset[] = Object.keys(SUPPORTED_ASSETS) as SupportedAsset[];\n\n// ---------------------------------------------------------------------------\n// Operation → allowed asset rules (single source of truth)\n// ---------------------------------------------------------------------------\n\n// [v0.51.0] Saveable/borrowable set: USDC + USDsui.\n// USDC is the canonical default; USDsui is a strategic exception backed by an\n// existing NAVI pool. See `.cursor/rules/savings-usdc-only.mdc` for the\n// rationale and the rule that gates additional stables (don't add more here\n// without updating that file).\nexport const OPERATION_ASSETS = {\n save: ['USDC', 'USDsui'],\n borrow: ['USDC', 'USDsui'],\n withdraw: '*',\n repay: '*',\n send: '*',\n swap: '*',\n} as const;\n\nexport type Operation = keyof typeof OPERATION_ASSETS;\n\nexport function isAllowedAsset(op: Operation, asset: string): boolean {\n const allowed = OPERATION_ASSETS[op];\n if (allowed === '*') return true;\n // [v0.51.0] Mixed-case canonical keys (USDsui, suiUSDT) need case-insensitive\n // membership. Pre-v0.51 we only had USDC ↔ USDC (uppercase identity), so\n // a one-sided uppercase compare looked correct. Now that USDsui is in the\n // set, normalize both sides.\n const target = asset.toLowerCase();\n return (allowed as readonly string[]).some((a) => a.toLowerCase() === target);\n}\n\n/**\n * Throws if the asset is not permitted for the given operation.\n * Passing `undefined` (omitted) is always valid — defaults to USDC.\n */\nexport function assertAllowedAsset(op: Operation, asset: string | undefined): void {\n if (!asset) return;\n if (!isAllowedAsset(op, asset)) {\n const allowed = OPERATION_ASSETS[op];\n const list = Array.isArray(allowed) ? allowed.join(', ') : 'any';\n throw new T2000Error(\n 'INVALID_ASSET',\n `${op} only supports ${list}. Cannot use ${asset}.${op === 'save' ? ' Swap to USDC or USDsui first.' : ''}`,\n );\n }\n}\n\n// All protocol fees route here as a regular USDC wallet transfer. Audric's\n// prepare/route.ts adds `addFeeTransfer(...)` inline for save/borrow and passes\n// `overlayFee.receiver = T2000_OVERLAY_FEE_WALLET` for swaps. The CLI/SDK never\n// charge fees — this constant is exported for consumer apps only.\n//\n// Address corresponds to the treasury admin wallet. Override via env for local dev /\n// testnet only — production must use the canonical mainnet address below.\nexport const T2000_OVERLAY_FEE_WALLET = process.env.T2000_OVERLAY_FEE_WALLET\n ?? '0x5366efbf2b4fe5767fe2e78eb197aa5f5d138d88ac3333fbf3f80a1927da473a';\n\nexport const DEFAULT_NETWORK = 'mainnet' as const;\nexport const DEFAULT_RPC_URL = 'https://fullnode.mainnet.sui.io:443';\nexport const DEFAULT_KEY_PATH = '~/.t2000/wallet.key';\nexport const DEFAULT_CONFIG_PATH = '~/.t2000/config.json';\n\nexport const API_BASE_URL = process.env.T2000_API_URL ?? 'https://api.t2000.ai';\n\n// Cetus USDC/SUI pool — read-only for SUI price oracle (no SDK dependency)\nexport const CETUS_USDC_SUI_POOL = '0x51e883ba7c0b566a26cbc8a94cd33eb0abd418a77cc1e60ad22fd9b1f29cd2ab';\n\nexport const GAS_RESERVE_MIN = 0.05; // minimum SUI to keep for gas\n","import { SuiJsonRpcClient, getJsonRpcFullnodeUrl } from '@mysten/sui/jsonRpc';\nimport { isValidSuiAddress, normalizeSuiAddress } from '@mysten/sui/utils';\nimport { DEFAULT_RPC_URL } from '../constants.js';\nimport { T2000Error } from '../errors.js';\n\nlet cachedClient: SuiJsonRpcClient | null = null;\n\nexport function getSuiClient(rpcUrl?: string): SuiJsonRpcClient {\n const url = rpcUrl ?? DEFAULT_RPC_URL;\n if (cachedClient) return cachedClient;\n cachedClient = new SuiJsonRpcClient({ url, network: 'mainnet' });\n return cachedClient;\n}\n\nexport function createSuiClient(network: 'mainnet' | 'testnet' = 'mainnet'): SuiJsonRpcClient {\n return new SuiJsonRpcClient({ url: getJsonRpcFullnodeUrl(network), network });\n}\n\nexport function validateAddress(address: string): string {\n const normalized = normalizeSuiAddress(address);\n if (!isValidSuiAddress(normalized)) {\n throw new T2000Error('INVALID_ADDRESS', `Invalid Sui address: ${address}`);\n }\n return normalized;\n}\n\nexport function truncateAddress(address: string): string {\n if (address.length <= 10) return address;\n return `${address.slice(0, 6)}...${address.slice(-4)}`;\n}\n\n/**\n * Normalize a Sui coin type to its canonical long-form 64-hex address.\n * `0x2::sui::SUI` → `0x0000…0002::sui::SUI`. Idempotent on already-long\n * forms. Returns the input unchanged if it doesn't look like a coin type\n * (`<address>::<module>::<name>`) so callers can pass arbitrary strings\n * without crashing.\n *\n * Why this exists: BlockVision's `/v2/sui/coin/price/list` endpoint\n * silently returns an empty `prices` map for short-form coin types\n * (notably `0x2::sui::SUI` — the native gas coin). Internal callers must\n * pass the long form, but external callers (LLM tool args, cached\n * coin-type strings, audit logs) commonly use the short form. Normalize\n * before the network call, denormalize back to the caller's input shape\n * after, and short/long become interchangeable.\n */\nexport function normalizeCoinType(coinType: string): string {\n const parts = coinType.split('::');\n if (parts.length !== 3) return coinType;\n const [addr, mod, name] = parts;\n if (!addr.startsWith('0x')) return coinType;\n return `${normalizeSuiAddress(addr)}::${mod}::${name}`;\n}\n","/**\n * Shared transaction classifier.\n *\n * Consumed by both the SDK's `parseTxRecord` (production agent path) and\n * the engine's `transaction_history` tool (cold-start RPC path). Keeping\n * a single source of truth here prevents the two paths from drifting —\n * see v1.5.3 regression where the SDK path was emitting `action:\n * 'transaction'` (rendered as \"On-chain\") while the engine path was\n * already producing fine-grained labels.\n */\n\nimport { getDecimalsForCoinType, resolveSymbol, SUI_TYPE } from '../token-registry.js';\n\n/**\n * Coarse action bucket — one of `'send' | 'lending' | 'swap' |\n * 'transaction'`. Used by the ACI `action` filter on the\n * `transaction_history` tool. STABLE: downstream queries depend on\n * exactly these values.\n *\n * Order matters: more specific buckets first. Lending patterns precede\n * swap patterns so a NAVI `::swap` helper (if one ever existed) would\n * still bucket as lending.\n */\nexport const KNOWN_TARGETS: readonly [RegExp, string][] = [\n [/::suilend|::obligation/, 'lending'],\n [/::navi|::lending_core|::incentive_v\\d+|::oracle_pro/, 'lending'],\n /**\n * DEX modules — both direct calls and aggregator legs. The Cetus\n * aggregator dispatches through a per-DEX module (e.g.\n * `cetus::swap`, `flowx_amm::swap`, `aftermath::swap`, …) plus\n * router glue functions. We list every DEX module the aggregator\n * supports today so a single-DEX call still classifies cleanly.\n */\n [/::cetus(?:_dlmm)?::|::pool::|::deepbook|::flowx_(?:amm|clmm)::|::kriya_(?:amm|clmm)::|::turbos::|::aftermath::|::afsui::|::bluefin::|::bluemove::|::ferra_(?:clmm|dlmm)::|::haedal_hmm::|::hasui::|::hawal::|::magma::|::momentum::|::obric::|::springsui::|::steamm_cpmm::|::fullsail::|::alphafi::|::volo_swap::/, 'swap'],\n /**\n * Cetus aggregator router glue. These are the swap-context and\n * balance-handling helpers the aggregator emits around per-DEX\n * legs. Without this entry a tx that ONLY had router calls\n * (theoretically possible for setup/cleanup) would slip through;\n * in practice these always coexist with a DEX leg, but the entry\n * is cheap insurance.\n */\n [/::router::(?:new_swap_context(?:_v)?|confirm_swap|transfer_balance|take_balance|transfer_or_destroy_coin)/, 'swap'],\n [/::transfer::public_transfer/, 'send'],\n];\n\n/**\n * Finer-grained display labels — derived from MoveCall function names.\n * The card renders `label ?? action`, so when this map matches we get\n * \"Deposit\" / \"Withdraw\" / \"Borrow\" / \"Repay\" / \"Payment link\" instead\n * of the generic \"Lending\" or \"Transaction\".\n *\n * Order matters: more specific patterns first. Each entry is\n * (regex, label) where the regex is matched against the\n * fully-qualified MoveCall target `pkg::module::function`.\n */\nexport const LABEL_PATTERNS: readonly [RegExp, string][] = [\n [/::pay(?:ment_kit|_kit)?::|::create_payment_link|::pay_link/, 'payment_link'],\n [/::create_invoice|::invoice::/, 'invoice'],\n [/::deposit|::supply|::mint_ctokens/, 'deposit'],\n [/::withdraw|::redeem|::redeem_ctokens/, 'withdraw'],\n [/::borrow/, 'borrow'],\n [/::repay/, 'repay'],\n [/::claim_reward|::claim::|::claim_incentive/, 'claim'],\n [/::stake/, 'stake'],\n [/::unstake|::burn::/, 'unstake'],\n [/::liquidate/, 'liquidate'],\n];\n\nexport interface ClassifyBalanceChange {\n owner: { AddressOwner?: string } | string;\n coinType: string;\n amount: string;\n}\n\nfunction resolveOwner(owner: ClassifyBalanceChange['owner']): string | null {\n if (typeof owner === 'object' && owner.AddressOwner) return owner.AddressOwner;\n if (typeof owner === 'string') return owner;\n return null;\n}\n\nexport function classifyAction(targets: string[], commandTypes: string[]): string {\n for (const target of targets) {\n for (const [pattern, label] of KNOWN_TARGETS) {\n if (pattern.test(target)) return label;\n }\n }\n if (commandTypes.includes('TransferObjects') && !commandTypes.includes('MoveCall')) return 'send';\n return 'transaction';\n}\n\n/**\n * Last-resort fallback when neither `LABEL_PATTERNS` nor the action\n * bucket produces something useful.\n *\n * Returns the first MoveCall's *module* name (e.g. \"navi\", \"spam\") so\n * the card shows something better than the literal word \"transaction\".\n * When no MoveCall exists, returns 'on-chain'.\n *\n * Note: callers should prefer `classifyLabel` which now layers\n * pattern-match → coarse action → module name (see commentary there).\n */\nexport function fallbackLabel(targets: string[]): string {\n if (!targets.length) return 'on-chain';\n const first = targets[0];\n const parts = first.split('::');\n if (parts.length >= 2 && parts[1]) return parts[1].toLowerCase();\n return 'on-chain';\n}\n\n/**\n * Three-tier label resolution for the transaction history card:\n * 1. Specific keyword match in `LABEL_PATTERNS` (\"deposit\",\n * \"payment_link\", …).\n * 2. Coarse action bucket from `classifyAction` (\"swap\", \"send\",\n * \"lending\") — prevents leaking opaque internal module names like\n * \"router\" (Cetus aggregator) or \"cross_swap\" (third-party DEX\n * aggregators) for txs that we already classified as a swap.\n * 3. Module name from the first MoveCall (`fallbackLabel`) — only\n * used when the action bucket itself is the generic \"transaction\".\n *\n * Pre-v0.46.2 we skipped tier 2, so swaps showed labels like \"router\",\n * \"cross_swap\", \"scallop_router\", etc. instead of the clean \"swap\".\n */\nexport function classifyLabel(targets: string[], commandTypes: string[]): string {\n for (const target of targets) {\n for (const [pattern, label] of LABEL_PATTERNS) {\n if (pattern.test(target)) return label;\n }\n }\n if (commandTypes.includes('TransferObjects') && !commandTypes.includes('MoveCall')) return 'send';\n const action = classifyAction(targets, commandTypes);\n if (action !== 'transaction') return action;\n return fallbackLabel(targets);\n}\n\n/**\n * Balance-direction tiebreaker for ambiguous lending calls.\n *\n * Many lending modules expose generic entry points (NAVI's bundled\n * flash actions, `lending_core::*::entry_*`, etc.) that don't carry\n * a `deposit`/`withdraw`/`borrow`/`repay` keyword in the function\n * name. When `classifyLabel` falls back to a bare module name like\n * `\"lending\"` for a known lending tx, infer direction from the user's\n * non-SUI balance change:\n * - net outflow of the supplied asset → deposit (also covers repay,\n * but repay-without-keyword is essentially never emitted).\n * - net inflow of the supplied asset → withdraw (also covers borrow).\n * SUI is excluded so gas-only transactions don't get mislabeled.\n *\n * If `LABEL_PATTERNS` matched a specific keyword, the existing label is\n * returned unchanged.\n */\nexport function refineLendingLabel(\n currentAction: string,\n currentLabel: string,\n moveCallTargets: string[],\n changes: ClassifyBalanceChange[],\n address: string,\n): string {\n if (currentAction !== 'lending') return currentLabel;\n const labelMatchedSpecific = LABEL_PATTERNS.some(([p]) =>\n moveCallTargets.some((t) => p.test(t)),\n );\n if (labelMatchedSpecific) return currentLabel;\n\n const userNonSuiOutflow = changes.find(\n (c) => resolveOwner(c.owner) === address && c.coinType !== SUI_TYPE && BigInt(c.amount) < 0n,\n );\n if (userNonSuiOutflow) return 'deposit';\n\n const userNonSuiInflow = changes.find(\n (c) => resolveOwner(c.owner) === address && c.coinType !== SUI_TYPE && BigInt(c.amount) > 0n,\n );\n if (userNonSuiInflow) return 'withdraw';\n\n return currentLabel;\n}\n\nexport interface ClassifyResult {\n action: string;\n label: string;\n}\n\nexport function classifyTransaction(\n moveCallTargets: string[],\n commandTypes: string[],\n balanceChanges: ClassifyBalanceChange[],\n address: string,\n): ClassifyResult {\n const action = classifyAction(moveCallTargets, commandTypes);\n const baseLabel = classifyLabel(moveCallTargets, commandTypes);\n const label = refineLendingLabel(action, baseLabel, moveCallTargets, balanceChanges, address);\n return { action, label };\n}\n\n/**\n * Direction of the user's net non-gas movement for this transaction.\n *\n * - `'out'` — the user spent the asset (sends, deposits, repays,\n * swap-in, payment-link payouts).\n * - `'in'` — the user received the asset (withdraws, borrows,\n * swap-out, claims, deposits credited from another wallet).\n *\n * Used by the `TransactionHistoryCard` to choose the `+`/`−` sign and\n * color. Direction is computed from the actual on-chain balance change\n * — never from the textual label — so opaque action types (`'router'`,\n * `'cross_swap'`, …) still render the correct sign.\n */\nexport type TxDirection = 'in' | 'out';\n\nexport interface ExtractedTransfer {\n amount?: number;\n asset?: string;\n recipient?: string;\n direction?: TxDirection;\n}\n\n/**\n * Extracts the principal amount/asset/direction for a transaction\n * from its `balanceChanges`.\n *\n * Algorithm:\n * 1. Restrict to the user's *own* balance changes.\n * 2. Prefer non-SUI changes (gas-only SUI deltas are noise).\n * 3. Pick the change with the largest absolute value — the \"principal\".\n * 4. If no non-SUI change exists, fall back to the largest SUI change\n * so pure-SUI transfers (stake/unstake/native send) still render.\n * 5. Direction follows the sign of the principal.\n * 6. Recipient is set only on outflows, by finding a matching inflow\n * on a *non-user* address with the same coinType.\n *\n * Pre-v0.46.2 this function only inspected outflows, so withdraws,\n * borrows, claims, swap-receives and payment-link receives all\n * rendered with no amount on the rich card (and with a wrong sign,\n * because the card guessed direction from the label string).\n */\nexport function extractTransferDetails(\n changes: ClassifyBalanceChange[] | undefined,\n sender: string,\n): ExtractedTransfer {\n if (!changes || changes.length === 0) return {};\n\n const userChanges = changes.filter((c) => resolveOwner(c.owner) === sender);\n if (userChanges.length === 0) return {};\n\n const userNonSui = userChanges.filter((c) => c.coinType !== SUI_TYPE);\n const pool = userNonSui.length > 0 ? userNonSui : userChanges;\n\n let primary = pool[0];\n let primaryAbs = bigintAbs(BigInt(primary.amount));\n for (let i = 1; i < pool.length; i++) {\n const abs = bigintAbs(BigInt(pool[i].amount));\n if (abs > primaryAbs) {\n primary = pool[i];\n primaryAbs = abs;\n }\n }\n\n const raw = BigInt(primary.amount);\n if (raw === 0n) return {};\n\n const decimals = getDecimalsForCoinType(primary.coinType);\n const amount = Number(primaryAbs) / 10 ** decimals;\n const asset = resolveSymbol(primary.coinType);\n const direction: TxDirection = raw < 0n ? 'out' : 'in';\n\n let recipient: string | undefined;\n if (direction === 'out') {\n const recipientChange = changes.find(\n (c) =>\n resolveOwner(c.owner) !== sender &&\n c.coinType === primary.coinType &&\n BigInt(c.amount) > 0n,\n );\n recipient = recipientChange ? resolveOwner(recipientChange.owner) ?? undefined : undefined;\n }\n\n return { amount, asset, recipient, direction };\n}\n\nfunction bigintAbs(n: bigint): bigint {\n return n < 0n ? -n : n;\n}\n","import type { SuiJsonRpcClient } from '@mysten/sui/jsonRpc';\nimport type { TransactionRecord } from '../types.js';\nimport {\n classifyTransaction,\n extractTransferDetails,\n type ClassifyBalanceChange,\n} from './classify.js';\n\nexport async function queryHistory(\n client: SuiJsonRpcClient,\n address: string,\n limit = 20,\n): Promise<TransactionRecord[]> {\n const txns = await client.queryTransactionBlocks({\n filter: { FromAddress: address },\n options: { showEffects: true, showInput: true, showBalanceChanges: true },\n limit,\n order: 'descending',\n });\n\n return txns.data.map((tx) => parseTxRecord(tx as unknown as SuiRpcTxBlock, address));\n}\n\nexport async function queryTransaction(\n client: SuiJsonRpcClient,\n digest: string,\n senderAddress: string,\n): Promise<TransactionRecord | null> {\n try {\n const tx = await client.getTransactionBlock({\n digest,\n options: { showEffects: true, showInput: true, showBalanceChanges: true },\n });\n return parseTxRecord(tx as unknown as SuiRpcTxBlock, senderAddress);\n } catch {\n return null;\n }\n}\n\n/**\n * Shape of a transaction block as returned by `suix_queryTransactionBlocks`\n * with `showEffects | showInput | showBalanceChanges` enabled. Exported so\n * downstream consumers (audric dashboard `/api/history`, `/api/activity`,\n * etc.) can type their RPC calls without redeclaring the structure.\n */\nexport interface SuiRpcTxBlock {\n digest: string;\n timestampMs?: string;\n transaction?: unknown;\n effects?: { gasUsed?: { computationCost: string; storageCost: string; storageRebate: string } };\n balanceChanges?: ClassifyBalanceChange[];\n}\n\n/**\n * Convert a single Sui RPC transaction block to a {@link TransactionRecord}\n * using the canonical (shared) classifier and balance-change extractor.\n *\n * This is the single source of truth for transaction parsing across the\n * agent-tool path AND the dashboard-API path. Use it instead of writing\n * a bespoke parser per surface.\n *\n * @param tx Raw RPC tx block (must include `effects`, `input`, `balanceChanges`).\n * @param address Wallet address whose perspective we're parsing from.\n */\nexport function parseSuiRpcTx(tx: SuiRpcTxBlock, address: string): TransactionRecord {\n return parseTxRecord(tx, address);\n}\n\n/**\n * Extract the sender (signer) address from a raw RPC tx block.\n * Returns `null` if the block shape is unexpected.\n */\nexport function extractTxSender(txBlock: unknown): string | null {\n try {\n if (!txBlock || typeof txBlock !== 'object') return null;\n const data = 'data' in txBlock ? (txBlock as Record<string, unknown>).data : undefined;\n if (!data || typeof data !== 'object') return null;\n return ((data as Record<string, unknown>).sender as string) ?? null;\n } catch {\n return null;\n }\n}\n\n/**\n * Extract MoveCall targets (`<pkg>::<module>::<function>`) and the\n * sequence of programmable-transaction command types (e.g. `MoveCall`,\n * `TransferObjects`) from a raw RPC tx block. Tolerates both the\n * legacy `inner.transactions` field and the newer `inner.commands`\n * field.\n */\nexport function extractTxCommands(txBlock: unknown): {\n moveCallTargets: string[];\n commandTypes: string[];\n} {\n return extractCommands(txBlock);\n}\n\nfunction parseTxRecord(tx: SuiRpcTxBlock, address: string): TransactionRecord {\n const gasUsed = tx.effects?.gasUsed;\n const gasCost = gasUsed\n ? (Number(gasUsed.computationCost) +\n Number(gasUsed.storageCost) -\n Number(gasUsed.storageRebate)) /\n 1e9\n : undefined;\n\n const { moveCallTargets, commandTypes } = extractCommands(tx.transaction);\n const balanceChanges = tx.balanceChanges ?? [];\n const { amount, asset, recipient, direction } = extractTransferDetails(balanceChanges, address);\n const { action, label } = classifyTransaction(\n moveCallTargets,\n commandTypes,\n balanceChanges,\n address,\n );\n\n return {\n digest: tx.digest,\n action,\n label,\n amount,\n asset,\n recipient,\n direction,\n timestamp: Number(tx.timestampMs ?? 0),\n gasCost,\n };\n}\n\ninterface CommandInfo {\n moveCallTargets: string[];\n commandTypes: string[];\n}\n\nfunction extractCommands(txBlock: unknown): CommandInfo {\n const result: CommandInfo = { moveCallTargets: [], commandTypes: [] };\n try {\n if (!txBlock || typeof txBlock !== 'object') return result;\n const data = 'data' in txBlock ? (txBlock as Record<string, unknown>).data : undefined;\n if (!data || typeof data !== 'object') return result;\n const inner = 'transaction' in (data as Record<string, unknown>)\n ? (data as Record<string, unknown>).transaction\n : undefined;\n if (!inner || typeof inner !== 'object') return result;\n const commands = 'commands' in (inner as Record<string, unknown>)\n ? (inner as Record<string, unknown>).commands\n : 'transactions' in (inner as Record<string, unknown>)\n ? (inner as Record<string, unknown>).transactions\n : undefined;\n if (!Array.isArray(commands)) return result;\n\n for (const cmd of commands as Record<string, unknown>[]) {\n if (cmd.MoveCall) {\n const mc = cmd.MoveCall as { package: string; module: string; function: string };\n result.moveCallTargets.push(`${mc.package}::${mc.module}::${mc.function}`);\n result.commandTypes.push('MoveCall');\n } else if (cmd.TransferObjects) {\n result.commandTypes.push('TransferObjects');\n }\n }\n } catch { /* best effort */ }\n return result;\n}\n","import { MIST_PER_SUI, BPS_DENOMINATOR, USDC_DECIMALS, SUPPORTED_ASSETS } from '../constants.js';\nimport type { SupportedAsset } from '../constants.js';\n\nexport function mistToSui(mist: bigint): number {\n return Number(mist) / Number(MIST_PER_SUI);\n}\n\nexport function suiToMist(sui: number): bigint {\n return BigInt(Math.round(sui * Number(MIST_PER_SUI)));\n}\n\nexport function usdcToRaw(amount: number): bigint {\n return BigInt(Math.round(amount * 10 ** USDC_DECIMALS));\n}\n\nexport function rawToUsdc(raw: bigint): number {\n return Number(raw) / 10 ** USDC_DECIMALS;\n}\n\nexport function stableToRaw(amount: number, decimals: number): bigint {\n return BigInt(Math.round(amount * 10 ** decimals));\n}\n\nexport function rawToStable(raw: bigint, decimals: number): number {\n return Number(raw) / 10 ** decimals;\n}\n\nexport function getDecimals(asset: SupportedAsset): number {\n return SUPPORTED_ASSETS[asset].decimals;\n}\n\nexport function rawToDisplay(raw: bigint, decimals: number): number {\n return Number(raw) / 10 ** decimals;\n}\n\nexport function displayToRaw(amount: number, decimals: number): bigint {\n return BigInt(Math.round(amount * 10 ** decimals));\n}\n\nexport function bpsToPercent(bps: bigint): number {\n return Number(bps) / Number(BPS_DENOMINATOR) * 100;\n}\n\nexport function formatUsd(amount: number): string {\n return `$${amount.toFixed(2)}`;\n}\n\nexport function formatSui(amount: number): string {\n if (amount < 0.001) return `${amount.toFixed(6)} SUI`;\n return `${amount.toFixed(3)} SUI`;\n}\n\nexport function formatLargeNumber(n: number): string {\n if (n >= 1_000_000) return `${(n / 1_000_000).toFixed(1)}M`;\n if (n >= 1_000) return `${(n / 1_000).toFixed(1)}K`;\n return n.toFixed(2);\n}\n\nexport function formatAssetAmount(amount: number, asset: string): string {\n if (asset === 'BTC') return amount.toFixed(8);\n if (asset === 'GOLD') return amount.toFixed(6);\n if (asset === 'ETH') return amount.toFixed(6);\n return amount.toFixed(4);\n}\n\nconst ASSET_LOOKUP: Map<string, string> = new Map();\nfor (const [key, info] of Object.entries(SUPPORTED_ASSETS)) {\n ASSET_LOOKUP.set(key.toUpperCase(), key);\n if (info.displayName && info.displayName.toUpperCase() !== key.toUpperCase()) {\n ASSET_LOOKUP.set(info.displayName.toUpperCase(), key);\n }\n}\n\n/**\n * Case-insensitive lookup against SUPPORTED_ASSETS keys AND display names.\n * 'usde' → 'USDe', 'suiusde' → 'USDe', 'suiusdt' → 'USDT', 'usdsui' → 'USDsui'.\n * Returns the original input if not found so downstream validation can reject it.\n */\nexport function normalizeAsset(input: string): string {\n return ASSET_LOOKUP.get(input.toUpperCase()) ?? input;\n}\n","/** Cross-platform (Node + browser) base64 helpers. */\n\nexport function toBase64(bytes: Uint8Array): string {\n let binary = '';\n for (const byte of bytes) binary += String.fromCharCode(byte);\n return btoa(binary);\n}\n\nexport function fromBase64(b64: string): Uint8Array {\n const binary = atob(b64);\n const bytes = new Uint8Array(binary.length);\n for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);\n return bytes;\n}\n","/**\n * Protocol fee primitives — wallet-direct transfer model.\n *\n * Fees are collected by splitting from the payment coin and transferring directly\n * to the treasury wallet inside the same PTB. Atomic with the operation (PTB\n * semantics); the wallet IS the ledger; the server-side indexer reads\n * `balanceChanges` and writes a `ProtocolFeeLedger` row tagged with the operation\n * classified from the tx's moveCall targets.\n *\n * The SDK / CLI never call this helper — they're fee-free by design (t2000 = infra\n * brand, no opinion on fees). Audric's `prepare/route.ts` is the canonical caller.\n */\nimport { Transaction, type TransactionObjectArgument } from '@mysten/sui/transactions';\nimport {\n SAVE_FEE_BPS,\n BORROW_FEE_BPS,\n BPS_DENOMINATOR,\n USDC_DECIMALS,\n} from '../constants.js';\nimport { stableToRaw } from '../utils/format.js';\n\nexport type FeeOperation = 'save' | 'borrow' | 'swap';\n\nexport interface ProtocolFeeInfo {\n amount: number;\n asset: string;\n rate: number;\n rawAmount: bigint;\n}\n\nconst FEE_RATES: Record<FeeOperation, bigint> = {\n save: SAVE_FEE_BPS,\n borrow: BORROW_FEE_BPS,\n // Swap uses Cetus's overlay-fee mechanism (taken from output by the aggregator\n // and transferred to `overlayFee.receiver`). We list the rate here for display\n // / quote calculations only — `addFeeTransfer` is NOT called for swaps.\n swap: 10n, // 0.1%\n};\n\n/**\n * Compute the fee amount for a given operation against a USD-denominated input.\n * Used pre-tx for receipt display + quote math. Does not modify any tx.\n */\nexport function calculateFee(operation: FeeOperation, amount: number): ProtocolFeeInfo {\n const bps = FEE_RATES[operation];\n const feeAmount = amount * Number(bps) / Number(BPS_DENOMINATOR);\n const rawAmount = stableToRaw(feeAmount, USDC_DECIMALS);\n\n return {\n amount: feeAmount,\n asset: 'USDC',\n rate: Number(bps) / Number(BPS_DENOMINATOR),\n rawAmount,\n };\n}\n\n/**\n * Split a fee from `paymentCoin` and transfer it to `receiver` inside the given PTB.\n *\n * **Order is load-bearing.** Call this BEFORE the protocol operation that consumes\n * `paymentCoin` (e.g. NAVI deposit). `splitCoins` mutates the source coin in place,\n * leaving the remainder for the protocol step. If you split AFTER the deposit,\n * the deposit will have consumed the coin and the split will fail.\n *\n * Atomicity: `splitCoins` + `transferObjects` are PTB ops; if anything later in\n * the PTB reverts, the fee transfer reverts too.\n *\n * @param tx Active PTB\n * @param paymentCoin Coin to split the fee from (mutated in place)\n * @param feeBps Fee rate in basis points (e.g. `SAVE_FEE_BPS = 10n` = 0.1%)\n * @param receiver Treasury wallet address (typically `T2000_OVERLAY_FEE_WALLET`)\n * @param amount Display-units input amount (matches what was passed to the\n * protocol operation; used to compute the raw fee amount)\n * @param decimals Coin decimals for raw conversion. Defaults to USDC_DECIMALS\n * (6). Pass the actual coin decimals when skimming a fee\n * from a non-USDC coin (e.g. USDsui = 6, GOLD = 6, ETH = 8,\n * SUI = 9). Backward-compatible: existing USDC callers can\n * omit. Wrong decimals → wrong raw amount → either fee\n * too small (silent loss) or too large (PTB revert from\n * insufficient coin balance).\n */\nexport function addFeeTransfer(\n tx: Transaction,\n paymentCoin: TransactionObjectArgument,\n feeBps: bigint,\n receiver: string,\n amount: number,\n decimals: number = USDC_DECIMALS,\n): void {\n if (feeBps <= 0n) return;\n if (amount <= 0) return;\n\n const feeAmount = amount * Number(feeBps) / Number(BPS_DENOMINATOR);\n const rawFee = stableToRaw(feeAmount, decimals);\n if (rawFee <= 0n) return;\n\n const [feeCoin] = tx.splitCoins(paymentCoin, [tx.pure.u64(rawFee)]);\n tx.transferObjects([feeCoin], tx.pure.address(receiver));\n}\n","/**\n * Cetus Aggregator V3 SDK wrapper — the ONLY file that imports @cetusprotocol/aggregator-sdk.\n * Documented CLAUDE.md exception: multi-DEX routing cannot be feasibly replaced by thin tx builders.\n *\n * [B5 v2 / @t2000/sdk@1.1.0 / 2026-04-30]\n * Overlay fee config is now per-call instead of a module-level singleton. CLI / direct\n * SDK callers (`T2000.swap()`) DON'T pass `overlayFee` → fee-free swap. Audric's\n * prepare/route.ts ALWAYS passes `overlayFee = { rate: OVERLAY_FEE_RATE, receiver:\n * T2000_OVERLAY_FEE_WALLET }` → fee charged. Structural inclusion (Audric's code can't\n * forget to pass it because it IS the code), not a toggle that defaults to safe.\n *\n * Pre-1.1.0: a module-level `OVERLAY_FEE_RECEIVER` constant defaulted to a Move object\n * ID. USDC sent there became OwnedObjects keyed to the object and was inaccessible.\n * Fixed by making the receiver a regular wallet address (T2000_OVERLAY_FEE_WALLET) AND\n * by removing the singleton pattern that hid the misconfig.\n */\nimport { AggregatorClient, Env, type FindRouterParams, type RouterDataV3 } from '@cetusprotocol/aggregator-sdk';\nimport { Transaction, type TransactionObjectArgument } from '@mysten/sui/transactions';\nimport type { SuiJsonRpcClient } from '@mysten/sui/jsonRpc';\nimport { resolveTokenType, getDecimalsForCoinType } from '../token-registry.js';\n\nexport interface OverlayFeeConfig {\n /** Fee rate as a fraction (e.g. 0.001 = 0.1%). Pass 0 to disable. */\n rate: number;\n /** Wallet address that receives the overlay fee. */\n receiver: string;\n}\n\nexport interface SwapRouteResult {\n routerData: RouterDataV3;\n amountIn: string;\n amountOut: string;\n byAmountIn: boolean;\n priceImpact: number;\n insufficientLiquidity: boolean;\n}\n\n/**\n * Default Audric swap overlay fee — 0.1%. Exported for consumers that want to use\n * the canonical Audric rate (the Audric prepare-route does this). Changing this\n * rate requires a coordinated SDK + audric release.\n */\nexport const OVERLAY_FEE_RATE = 0.001;\n\n/**\n * Cache `AggregatorClient` instances by `(signer + overlay rate + overlay receiver)`.\n * Per-call instantiation is cheap (the client is mostly config), but caching avoids\n * pointless re-allocation when the same caller swaps multiple times in a loop.\n */\nconst clientCache = new Map<string, AggregatorClient>();\n\nfunction getClient(walletAddress: string, overlayFee?: OverlayFeeConfig): AggregatorClient {\n const rate = overlayFee?.rate ?? 0;\n const receiver = overlayFee?.receiver ?? '';\n const key = `${walletAddress}|${rate}|${receiver}`;\n\n const cached = clientCache.get(key);\n if (cached) return cached;\n\n const client = new AggregatorClient({\n signer: walletAddress,\n env: Env.Mainnet,\n ...(rate > 0 && receiver\n ? { overlayFeeRate: rate, overlayFeeReceiver: receiver }\n : {}),\n });\n clientCache.set(key, client);\n return client;\n}\n\n/**\n * Find the optimal swap route via Cetus Aggregator REST API.\n *\n * Pass `overlayFee` to charge an overlay fee on the output (Audric's pattern).\n * Omit it for a fee-free swap (CLI / direct SDK pattern).\n */\nexport async function findSwapRoute(params: {\n walletAddress: string;\n from: string;\n to: string;\n amount: bigint;\n byAmountIn: boolean;\n overlayFee?: OverlayFeeConfig;\n /**\n * Optional Cetus provider allow-list. When omitted, all 30+ DEXes\n * are eligible. Sponsored flows (Enoki) MUST pass an exclusion list\n * computed via `getProvidersExcluding([...])` from the Cetus SDK to\n * remove Pyth-dependent providers (HAEDALPMM, METASTABLE, OBRIC,\n * STEAMM_OMM, STEAMM_OMM_V2, SEVENK, HAEDALHMMV2) — those reference\n * `tx.gas` for oracle fees, which Enoki rejects in sponsored txs.\n * Non-sponsored callers (CLI, direct SDK) leave this undefined.\n */\n providers?: string[];\n}): Promise<SwapRouteResult | null> {\n const client = getClient(params.walletAddress, params.overlayFee);\n\n const findParams: FindRouterParams = {\n from: params.from,\n target: params.to,\n amount: params.amount.toString(),\n byAmountIn: params.byAmountIn,\n ...(params.providers ? { providers: params.providers } : {}),\n };\n\n const routerData = await client.findRouters(findParams);\n if (!routerData) return null;\n\n if (routerData.insufficientLiquidity) {\n return {\n routerData,\n amountIn: routerData.amountIn.toString(),\n amountOut: routerData.amountOut.toString(),\n byAmountIn: params.byAmountIn,\n priceImpact: normalizePriceImpact(routerData.deviationRatio),\n insufficientLiquidity: true,\n };\n }\n\n if (routerData.error) {\n const { T2000Error } = await import('../errors.js');\n throw new T2000Error('SWAP_FAILED', `Cetus routing error: ${routerData.error.msg} (code ${routerData.error.code})`);\n }\n\n return {\n routerData,\n amountIn: routerData.amountIn.toString(),\n amountOut: routerData.amountOut.toString(),\n byAmountIn: params.byAmountIn,\n priceImpact: normalizePriceImpact(routerData.deviationRatio),\n insufficientLiquidity: false,\n };\n}\n\n/**\n * Cetus' aggregator types `deviationRatio` as `number`, but in some routes\n * the router actually returns a string (\"0.001234\"). The SDK type lies, so we\n * always coerce to a finite number here (NaN/null/undefined → 0). Without\n * this every downstream consumer that calls `priceImpact.toFixed(...)` will\n * crash at runtime — including the Audric SwapQuoteCard, which takes the\n * whole chat UI down through its error boundary.\n */\nfunction normalizePriceImpact(value: unknown): number {\n const n = typeof value === 'number' ? value : Number(value);\n return Number.isFinite(n) ? n : 0;\n}\n\n/**\n * Build a swap PTB from a route result. The caller must provide an input coin\n * obtained by splitting/merging wallet coins.\n *\n * **Important:** Cetus's `routerSwap` reads the overlay-fee config from the\n * AggregatorClient instance. The `overlayFee` param here MUST match the one\n * passed to `findSwapRoute` for the same swap (otherwise you'll hit the cache\n * boundary and get a different client with different overlay config).\n */\nexport async function buildSwapTx(params: {\n walletAddress: string;\n route: SwapRouteResult;\n tx: Transaction;\n inputCoin: TransactionObjectArgument;\n slippage: number;\n overlayFee?: OverlayFeeConfig;\n}): Promise<TransactionObjectArgument> {\n const client = getClient(params.walletAddress, params.overlayFee);\n const clampedSlippage = Math.max(0.001, Math.min(params.slippage, 0.05));\n\n const outputCoin = await client.routerSwap({\n router: params.route.routerData,\n inputCoin: params.inputCoin,\n slippage: clampedSlippage,\n txb: params.tx,\n });\n\n return outputCoin;\n}\n\n/**\n * Append a swap fragment to an existing PTB. SPEC 7 § \"Layer 1\" Cetus\n * appender. Two modes, dispatched by the presence of `input.inputCoin`:\n *\n * - **Wallet mode** (`inputCoin` omitted) — fetches `from`-asset coins\n * from the sender's wallet (paginated), merges/splits to the\n * requested amount, runs the swap. Mirrors the audric host's\n * `transactions/prepare/route.ts` swap branch (P2.2c will retire that\n * branch in favor of this appender via `composeTx`).\n *\n * - **Chain mode** (`inputCoin` provided) — consumes the passed-in coin\n * reference (typically produced by an upstream appender like\n * `addWithdrawToTx`) directly, no wallet fetch / no merge / no\n * split. This is the SPEC 7 multi-write enabler (\"withdraw → swap →\n * save\" without intermediate wallet materialization).\n *\n * **SUI in wallet mode:** uses `client.getCoins` like every other\n * token. This works for sponsored flows (Enoki — `tx.gas` belongs to\n * the sponsor, swap input comes from the user's separate SUI coin\n * objects). For non-sponsored flows where `tx.gas` IS the user's SUI,\n * the caller should pre-build the inputCoin via\n * `tx.splitCoins(tx.gas, [rawAmount])[0]` and pass it via chain mode\n * instead. (`T2000.swap()` already handles this internally — direct SDK\n * users go through the high-level class, not through this appender.)\n *\n * **`swapAll` semantics (wallet mode):** if the requested raw amount\n * is >= the wallet's total `from` balance, the appender consumes the\n * entire merged primary coin (not a split), matching audric's host\n * route's `swapAll` clipping. The returned `effectiveAmountIn` reflects\n * the actual consumed amount in display units.\n *\n * **Slippage:** clamped to [0.001, 0.05] (0.1% – 5%). Defaults to 0.01.\n *\n * @returns\n * - `coin` — output coin reference, ready for downstream consumption\n * (e.g. `addSaveToTx`) or wallet transfer (`tx.transferObjects`).\n * - `effectiveAmountIn` — display-units input amount the swap actually\n * consumes (handles `swapAll` clipping in wallet mode; in chain mode\n * echoes the requested `input.amount`).\n * - `expectedAmountOut` — display-units output amount per the route\n * quote. Actual on-chain output may differ within slippage.\n * - `route` — raw `SwapRouteResult` for downstream telemetry / logging.\n */\nexport async function addSwapToTx(\n tx: Transaction,\n client: SuiJsonRpcClient,\n address: string,\n input: {\n from: string;\n to: string;\n amount: number;\n slippage?: number;\n byAmountIn?: boolean;\n overlayFee?: OverlayFeeConfig;\n inputCoin?: TransactionObjectArgument;\n /**\n * Optional Cetus provider allow-list. Forwarded to `findSwapRoute`.\n * Sponsored flows (Enoki) MUST pass `getProvidersExcluding([...])`\n * to remove Pyth-dependent providers — see `findSwapRoute`'s JSDoc\n * for the exclusion list. Non-sponsored callers omit this.\n */\n providers?: string[];\n },\n): Promise<{\n coin: TransactionObjectArgument;\n effectiveAmountIn: number;\n expectedAmountOut: number;\n route: SwapRouteResult;\n}> {\n const { T2000Error } = await import('../errors.js');\n\n const fromType = resolveTokenType(input.from);\n const toType = resolveTokenType(input.to);\n if (!fromType) throw new T2000Error('ASSET_NOT_SUPPORTED', `Unknown token: ${input.from}. Provide the symbol (USDC, SUI, ...) or full coin type.`);\n if (!toType) throw new T2000Error('ASSET_NOT_SUPPORTED', `Unknown token: ${input.to}. Provide the symbol (USDC, SUI, ...) or full coin type.`);\n if (fromType === toType) throw new T2000Error('SWAP_FAILED', 'Cannot swap a token to itself');\n if (!Number.isFinite(input.amount) || input.amount <= 0) {\n throw new T2000Error('INVALID_AMOUNT', 'Amount must be greater than zero');\n }\n\n const fromDecimals = getDecimalsForCoinType(fromType);\n const toDecimals = getDecimalsForCoinType(toType);\n const requestedRaw = BigInt(Math.floor(input.amount * 10 ** fromDecimals));\n\n const slippage = Math.max(0.001, Math.min(input.slippage ?? 0.01, 0.05));\n const byAmountIn = input.byAmountIn ?? true;\n\n let inputCoin: TransactionObjectArgument;\n let effectiveRaw: bigint;\n\n if (input.inputCoin) {\n inputCoin = input.inputCoin;\n effectiveRaw = requestedRaw;\n } else {\n // Delegate to the canonical wallet-mode prelude. Critically, this path\n // shares a per-PTB merge cache with every other appender via\n // `selectAndSplitCoin` — when a multi-write bundle includes\n // `swap_execute` alongside `save_deposit`/`send_transfer` of the same\n // input asset (e.g. swap+save+send all from USDC), the second/third\n // appender hits the cache and splits from the already-merged primary\n // instead of re-emitting `mergeCoins` on consumed input slots. That's\n // the P2.7 multi-write bundle fix landed 2026-05-02.\n const { selectAndSplitCoin } = await import('../wallet/coinSelection.js');\n const result = await selectAndSplitCoin(tx, client, address, fromType, requestedRaw);\n inputCoin = result.coin;\n effectiveRaw = result.effectiveAmount;\n }\n\n const route = await findSwapRoute({\n walletAddress: address,\n from: fromType,\n to: toType,\n amount: effectiveRaw,\n byAmountIn,\n overlayFee: input.overlayFee,\n providers: input.providers,\n });\n\n if (!route) {\n throw new T2000Error('SWAP_NO_ROUTE', `No swap route found for ${input.from} → ${input.to}`);\n }\n if (route.insufficientLiquidity) {\n throw new T2000Error('SWAP_NO_ROUTE', `Insufficient liquidity for ${input.from} → ${input.to}`);\n }\n\n const outputCoin = await buildSwapTx({\n walletAddress: address,\n route,\n tx,\n inputCoin,\n slippage,\n overlayFee: input.overlayFee,\n });\n\n return {\n coin: outputCoin,\n effectiveAmountIn: Number(effectiveRaw) / 10 ** fromDecimals,\n expectedAmountOut: Number(route.amountOut) / 10 ** toDecimals,\n route,\n };\n}\n\n/**\n * Simulate a swap transaction without executing it.\n */\nexport async function simulateSwap(params: {\n walletAddress: string;\n tx: Transaction;\n overlayFee?: OverlayFeeConfig;\n}): Promise<{ success: boolean; error?: string }> {\n const client = getClient(params.walletAddress, params.overlayFee);\n try {\n await client.devInspectTransactionBlock(params.tx);\n return { success: true };\n } catch (err) {\n return { success: false, error: err instanceof Error ? err.message : String(err) };\n }\n}\n\n// Re-export from the canonical token registry for backward-compat.\nexport { TOKEN_MAP, resolveTokenType } from '../token-registry.js';\n","import { T2000Error } from '../errors.js';\n\nexport type SafeguardRule = 'locked' | 'maxPerTx' | 'maxDailySend';\n\nexport interface SafeguardErrorDetails {\n attempted?: number;\n limit?: number;\n current?: number;\n}\n\nexport class SafeguardError extends T2000Error {\n readonly rule: SafeguardRule;\n readonly details: SafeguardErrorDetails;\n\n constructor(rule: SafeguardRule, details: SafeguardErrorDetails, message?: string) {\n const msg = message ?? buildMessage(rule, details);\n super('SAFEGUARD_BLOCKED' as any, msg, { rule, ...details });\n this.name = 'SafeguardError';\n this.rule = rule;\n this.details = details;\n }\n\n override toJSON() {\n return {\n error: 'SAFEGUARD_BLOCKED' as const,\n message: this.message,\n retryable: this.retryable,\n data: { rule: this.rule, ...this.details },\n };\n }\n}\n\nfunction buildMessage(rule: SafeguardRule, details: SafeguardErrorDetails): string {\n switch (rule) {\n case 'locked':\n return 'Agent is locked. All operations are frozen.';\n case 'maxPerTx':\n return `Amount $${(details.attempted ?? 0).toFixed(2)} exceeds per-transaction limit ($${(details.limit ?? 0).toFixed(2)})`;\n case 'maxDailySend':\n return `Daily send limit reached ($${(details.current ?? 0).toFixed(2)}/$${(details.limit ?? 0).toFixed(2)} used today)`;\n }\n}\n","export interface SafeguardConfig {\n locked: boolean;\n maxPerTx: number;\n maxDailySend: number;\n dailyUsed: number;\n dailyResetDate: string;\n maxLeverage?: number;\n maxPositionSize?: number;\n}\n\nexport interface TxMetadata {\n operation:\n | 'send'\n | 'save'\n | 'withdraw'\n | 'borrow'\n | 'repay'\n | 'pay';\n amount?: number;\n}\n\nexport const OUTBOUND_OPS = new Set<TxMetadata['operation']>([\n 'send',\n 'pay',\n]);\n\nexport const DEFAULT_SAFEGUARD_CONFIG: SafeguardConfig = {\n locked: false,\n maxPerTx: 0,\n maxDailySend: 0,\n dailyUsed: 0,\n dailyResetDate: '',\n};\n"]}
@@ -1,4 +1,4 @@
1
- export { A as ALL_NAVI_ASSETS, B as BORROW_FEE_BPS, a as BPS_DENOMINATOR, C as CLOCK_ID, b as COIN_REGISTRY, c as ClassifyBalanceChange, d as ClassifyResult, e as CoinMeta, D as DEFAULT_NETWORK, f as DEFAULT_SAFEGUARD_CONFIG, E as ETH_TYPE, g as ExtractedTransfer, F as FeeOperation, G as GAS_RESERVE_MIN, I as IKA_TYPE, K as KNOWN_TARGETS, h as KeypairSigner, L as LABEL_PATTERNS, i as LOFI_TYPE, M as MANIFEST_TYPE, j as MIST_PER_SUI, N as NAVX_TYPE, O as OUTBOUND_OPS, k as OVERLAY_FEE_RATE, l as OverlayFeeConfig, P as ProtocolFeeInfo, S as SAVE_FEE_BPS, m as STABLE_ASSETS, n as SUI_DECIMALS, o as SUI_TYPE, p as SUPPORTED_ASSETS, q as SafeguardConfig, r as SafeguardError, s as SafeguardErrorDetails, t as SafeguardRule, u as SimulationResult, v as StableAsset, w as SuiRpcTxBlock, x as SupportedAsset, y as SwapRouteResult, T as T2000Error, z as T2000ErrorCode, H as T2000ErrorData, J as T2000_OVERLAY_FEE_WALLET, Q as TOKEN_MAP, R as TransactionSigner, U as TxDirection, V as TxMetadata, W as USDC_DECIMALS, X as USDC_TYPE, Y as USDE_TYPE, Z as USDSUI_TYPE, _ as USDT_TYPE, $ as WAL_TYPE, a0 as WBTC_TYPE, a1 as ZkLoginProof, a2 as ZkLoginSigner, a3 as addFeeTransfer, a4 as buildSwapTx, a5 as calculateFee, a6 as classifyAction, a7 as classifyLabel, a8 as classifyTransaction, a9 as extractTransferDetails, aa as extractTxCommands, ab as extractTxSender, ac as fallbackLabel, ad as findSwapRoute, ae as formatAssetAmount, af as formatSui, ag as formatUsd, ah as getDecimals, ai as getDecimalsForCoinType, aj as getTier, ak as isSupported, al as isTier1, am as isTier2, an as mapMoveAbortCode, ao as mapWalletError, ap as mistToSui, aq as parseSuiRpcTx, ar as rawToStable, as as rawToUsdc, at as refineLendingLabel, au as resolveSymbol, av as resolveTokenType, aw as stableToRaw, ax as suiToMist, ay as truncateAddress, az as usdcToRaw, aA as validateAddress } from './types-D03bON1v.cjs';
1
+ export { A as ALL_NAVI_ASSETS, B as BORROW_FEE_BPS, a as BPS_DENOMINATOR, C as CLOCK_ID, b as COIN_REGISTRY, c as ClassifyBalanceChange, d as ClassifyResult, e as CoinMeta, D as DEFAULT_NETWORK, f as DEFAULT_SAFEGUARD_CONFIG, E as ETH_TYPE, g as ExtractedTransfer, F as FeeOperation, G as GAS_RESERVE_MIN, I as IKA_TYPE, K as KNOWN_TARGETS, h as KeypairSigner, L as LABEL_PATTERNS, i as LOFI_TYPE, M as MANIFEST_TYPE, j as MIST_PER_SUI, N as NAVX_TYPE, O as OUTBOUND_OPS, k as OVERLAY_FEE_RATE, l as OverlayFeeConfig, P as ProtocolFeeInfo, S as SAVE_FEE_BPS, m as STABLE_ASSETS, n as SUI_DECIMALS, o as SUI_TYPE, p as SUPPORTED_ASSETS, q as SafeguardConfig, r as SafeguardError, s as SafeguardErrorDetails, t as SafeguardRule, u as SimulationResult, v as StableAsset, w as SuiRpcTxBlock, x as SupportedAsset, y as SwapRouteResult, T as T2000Error, z as T2000ErrorCode, H as T2000ErrorData, J as T2000_OVERLAY_FEE_WALLET, Q as TOKEN_MAP, R as TransactionSigner, U as TxDirection, V as TxMetadata, W as USDC_DECIMALS, X as USDC_TYPE, Y as USDE_TYPE, Z as USDSUI_TYPE, _ as USDT_TYPE, $ as WAL_TYPE, a0 as WBTC_TYPE, a1 as ZkLoginProof, a2 as ZkLoginSigner, a3 as addFeeTransfer, a4 as buildSwapTx, a5 as calculateFee, a6 as classifyAction, a7 as classifyLabel, a8 as classifyTransaction, a9 as extractTransferDetails, aa as extractTxCommands, ab as extractTxSender, ac as fallbackLabel, ad as findSwapRoute, ae as formatAssetAmount, af as formatSui, ag as formatUsd, ah as getDecimals, ai as getDecimalsForCoinType, aj as getTier, ak as isSupported, al as isTier1, am as isTier2, an as mapMoveAbortCode, ao as mapWalletError, ap as mistToSui, aq as parseSuiRpcTx, ar as rawToStable, as as rawToUsdc, at as refineLendingLabel, au as resolveSymbol, av as resolveTokenType, aw as stableToRaw, ax as suiToMist, ay as truncateAddress, az as usdcToRaw, aA as validateAddress } from './types-DvNhsBbN.cjs';
2
2
  export { A as AssetRates, B as BalanceResponse, a as BorrowResult, C as ClaimRewardsResult, D as DepositInfo, E as EarningsResult, F as FundStatusResult, G as GasReserve, H as HealthFactorResult, M as MaxBorrowResult, b as MaxWithdrawResult, P as PayOptions, c as PayResult, d as PendingReward, e as PositionEntry, f as PositionsResult, R as RatesResult, g as RepayResult, S as SaveResult, h as SendResult, T as TransactionRecord, W as WithdrawResult } from './types-jAD-e7Pq.cjs';
3
3
  import '@mysten/sui/keypairs/ed25519';
4
4
  import '@mysten/sui/jsonRpc';
package/dist/browser.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { A as ALL_NAVI_ASSETS, B as BORROW_FEE_BPS, a as BPS_DENOMINATOR, C as CLOCK_ID, b as COIN_REGISTRY, c as ClassifyBalanceChange, d as ClassifyResult, e as CoinMeta, D as DEFAULT_NETWORK, f as DEFAULT_SAFEGUARD_CONFIG, E as ETH_TYPE, g as ExtractedTransfer, F as FeeOperation, G as GAS_RESERVE_MIN, I as IKA_TYPE, K as KNOWN_TARGETS, h as KeypairSigner, L as LABEL_PATTERNS, i as LOFI_TYPE, M as MANIFEST_TYPE, j as MIST_PER_SUI, N as NAVX_TYPE, O as OUTBOUND_OPS, k as OVERLAY_FEE_RATE, l as OverlayFeeConfig, P as ProtocolFeeInfo, S as SAVE_FEE_BPS, m as STABLE_ASSETS, n as SUI_DECIMALS, o as SUI_TYPE, p as SUPPORTED_ASSETS, q as SafeguardConfig, r as SafeguardError, s as SafeguardErrorDetails, t as SafeguardRule, u as SimulationResult, v as StableAsset, w as SuiRpcTxBlock, x as SupportedAsset, y as SwapRouteResult, T as T2000Error, z as T2000ErrorCode, H as T2000ErrorData, J as T2000_OVERLAY_FEE_WALLET, Q as TOKEN_MAP, R as TransactionSigner, U as TxDirection, V as TxMetadata, W as USDC_DECIMALS, X as USDC_TYPE, Y as USDE_TYPE, Z as USDSUI_TYPE, _ as USDT_TYPE, $ as WAL_TYPE, a0 as WBTC_TYPE, a1 as ZkLoginProof, a2 as ZkLoginSigner, a3 as addFeeTransfer, a4 as buildSwapTx, a5 as calculateFee, a6 as classifyAction, a7 as classifyLabel, a8 as classifyTransaction, a9 as extractTransferDetails, aa as extractTxCommands, ab as extractTxSender, ac as fallbackLabel, ad as findSwapRoute, ae as formatAssetAmount, af as formatSui, ag as formatUsd, ah as getDecimals, ai as getDecimalsForCoinType, aj as getTier, ak as isSupported, al as isTier1, am as isTier2, an as mapMoveAbortCode, ao as mapWalletError, ap as mistToSui, aq as parseSuiRpcTx, ar as rawToStable, as as rawToUsdc, at as refineLendingLabel, au as resolveSymbol, av as resolveTokenType, aw as stableToRaw, ax as suiToMist, ay as truncateAddress, az as usdcToRaw, aA as validateAddress } from './types-DCb8Xt_q.js';
1
+ export { A as ALL_NAVI_ASSETS, B as BORROW_FEE_BPS, a as BPS_DENOMINATOR, C as CLOCK_ID, b as COIN_REGISTRY, c as ClassifyBalanceChange, d as ClassifyResult, e as CoinMeta, D as DEFAULT_NETWORK, f as DEFAULT_SAFEGUARD_CONFIG, E as ETH_TYPE, g as ExtractedTransfer, F as FeeOperation, G as GAS_RESERVE_MIN, I as IKA_TYPE, K as KNOWN_TARGETS, h as KeypairSigner, L as LABEL_PATTERNS, i as LOFI_TYPE, M as MANIFEST_TYPE, j as MIST_PER_SUI, N as NAVX_TYPE, O as OUTBOUND_OPS, k as OVERLAY_FEE_RATE, l as OverlayFeeConfig, P as ProtocolFeeInfo, S as SAVE_FEE_BPS, m as STABLE_ASSETS, n as SUI_DECIMALS, o as SUI_TYPE, p as SUPPORTED_ASSETS, q as SafeguardConfig, r as SafeguardError, s as SafeguardErrorDetails, t as SafeguardRule, u as SimulationResult, v as StableAsset, w as SuiRpcTxBlock, x as SupportedAsset, y as SwapRouteResult, T as T2000Error, z as T2000ErrorCode, H as T2000ErrorData, J as T2000_OVERLAY_FEE_WALLET, Q as TOKEN_MAP, R as TransactionSigner, U as TxDirection, V as TxMetadata, W as USDC_DECIMALS, X as USDC_TYPE, Y as USDE_TYPE, Z as USDSUI_TYPE, _ as USDT_TYPE, $ as WAL_TYPE, a0 as WBTC_TYPE, a1 as ZkLoginProof, a2 as ZkLoginSigner, a3 as addFeeTransfer, a4 as buildSwapTx, a5 as calculateFee, a6 as classifyAction, a7 as classifyLabel, a8 as classifyTransaction, a9 as extractTransferDetails, aa as extractTxCommands, ab as extractTxSender, ac as fallbackLabel, ad as findSwapRoute, ae as formatAssetAmount, af as formatSui, ag as formatUsd, ah as getDecimals, ai as getDecimalsForCoinType, aj as getTier, ak as isSupported, al as isTier1, am as isTier2, an as mapMoveAbortCode, ao as mapWalletError, ap as mistToSui, aq as parseSuiRpcTx, ar as rawToStable, as as rawToUsdc, at as refineLendingLabel, au as resolveSymbol, av as resolveTokenType, aw as stableToRaw, ax as suiToMist, ay as truncateAddress, az as usdcToRaw, aA as validateAddress } from './types-D1-rO-J4.js';
2
2
  export { A as AssetRates, B as BalanceResponse, a as BorrowResult, C as ClaimRewardsResult, D as DepositInfo, E as EarningsResult, F as FundStatusResult, G as GasReserve, H as HealthFactorResult, M as MaxBorrowResult, b as MaxWithdrawResult, P as PayOptions, c as PayResult, d as PendingReward, e as PositionEntry, f as PositionsResult, R as RatesResult, g as RepayResult, S as SaveResult, h as SendResult, T as TransactionRecord, W as WithdrawResult } from './types-jAD-e7Pq.js';
3
3
  import '@mysten/sui/keypairs/ed25519';
4
4
  import '@mysten/sui/jsonRpc';
package/dist/browser.js CHANGED
@@ -588,7 +588,7 @@ var FEE_RATES = {
588
588
  function calculateFee(operation, amount) {
589
589
  const bps = FEE_RATES[operation];
590
590
  const feeAmount = amount * Number(bps) / Number(BPS_DENOMINATOR);
591
- const rawAmount = usdcToRaw(feeAmount);
591
+ const rawAmount = stableToRaw(feeAmount, USDC_DECIMALS);
592
592
  return {
593
593
  amount: feeAmount,
594
594
  asset: "USDC",
@@ -596,11 +596,11 @@ function calculateFee(operation, amount) {
596
596
  rawAmount
597
597
  };
598
598
  }
599
- function addFeeTransfer(tx, paymentCoin, feeBps, receiver, amount) {
599
+ function addFeeTransfer(tx, paymentCoin, feeBps, receiver, amount, decimals = USDC_DECIMALS) {
600
600
  if (feeBps <= 0n) return;
601
601
  if (amount <= 0) return;
602
602
  const feeAmount = amount * Number(feeBps) / Number(BPS_DENOMINATOR);
603
- const rawFee = usdcToRaw(feeAmount);
603
+ const rawFee = stableToRaw(feeAmount, decimals);
604
604
  if (rawFee <= 0n) return;
605
605
  const [feeCoin] = tx.splitCoins(paymentCoin, [tx.pure.u64(rawFee)]);
606
606
  tx.transferObjects([feeCoin], tx.pure.address(receiver));