@t2000/sdk 9.1.0 → 9.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser.cjs +106 -7
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.d.cts +1 -1
- package/dist/browser.d.ts +1 -1
- package/dist/browser.js +106 -8
- package/dist/browser.js.map +1 -1
- package/dist/index.cjs +108 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +108 -8
- package/dist/index.js.map +1 -1
- package/dist/{send-CUUOLK_H.d.cts → send-DEK6aOGe.d.cts} +14 -1
- package/dist/{send-CUUOLK_H.d.ts → send-DEK6aOGe.d.ts} +14 -1
- package/package.json +3 -2
package/dist/browser.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { B as BalanceResponse, C as CLOCK_ID, a as COIN_REGISTRY, b as ClassifyBalanceChange, c as ClassifyResult, d as CoinMeta, D as DEFAULT_NETWORK, e as DepositInfo, E as ETH_TYPE, f as ExtractedTransfer, G as GAS_RESERVE_MIN, I as IKA_TYPE, K as KNOWN_TARGETS, g as KeypairSigner, L as LABEL_PATTERNS, h as LOFI_TYPE, M as MANIFEST_TYPE, i as MIST_PER_SUI, N as NAVX_TYPE, O as OVERLAY_FEE_RATE, j as OverlayFeeConfig, P as PREFLIGHT_MAX_AMOUNT, k as PREFLIGHT_OK, l as PayOptions, m as PayResult, n as PreflightResult, S as STABLE_ASSETS, o as SUI_DECIMALS, p as SUI_TYPE, q as SUPPORTED_ASSETS, r as SendResult, s as SimulationResult, t as StableAsset, u as SuiHolding, v as SuiRpcTxBlock, w as SupportedAsset, x as SwapRouteResult, T as T2000Error, y as T2000ErrorCode, z as T2000ErrorData, A as T2000_OVERLAY_FEE_WALLET, F as TOKEN_MAP, H as TransactionLeg, J as TransactionRecord, Q as TransactionSigner, R as TxDirection, U as USDC_DECIMALS, V as USDC_TYPE, W as USDE_TYPE, X as USDSUI_TYPE, Y as USDT_TYPE, Z as WAL_TYPE, _ as WBTC_TYPE, $ as ZkLoginProof, a0 as ZkLoginSigner, a1 as buildSendTx, a2 as buildSwapTx, a3 as checkPositiveAmount, a4 as checkSuiAddress, a5 as classifyAction, a6 as classifyLabel, a7 as classifyTransaction, a8 as executeTx, a9 as extractAllUserLegs, aa as extractTransferDetails, ab as extractTxCommands, ac as extractTxSender, ad as fallbackLabel, ae as findSwapRoute, af as formatAssetAmount, ag as formatSui, ah as formatUsd, ai as getDecimals, aj as getDecimalsForCoinType, ak as mapMoveAbortCode, al as mapWalletError, am as mistToSui, an as
|
|
1
|
+
export { B as BalanceResponse, C as CLOCK_ID, a as COIN_REGISTRY, b as ClassifyBalanceChange, c as ClassifyResult, d as CoinMeta, D as DEFAULT_NETWORK, e as DepositInfo, E as ETH_TYPE, f as ExtractedTransfer, G as GAS_RESERVE_MIN, I as IKA_TYPE, K as KNOWN_TARGETS, g as KeypairSigner, L as LABEL_PATTERNS, h as LOFI_TYPE, M as MANIFEST_TYPE, i as MIST_PER_SUI, N as NAVX_TYPE, O as OVERLAY_FEE_RATE, j as OverlayFeeConfig, P as PREFLIGHT_MAX_AMOUNT, k as PREFLIGHT_OK, l as PayOptions, m as PayResult, n as PreflightResult, S as STABLE_ASSETS, o as SUI_DECIMALS, p as SUI_TYPE, q as SUPPORTED_ASSETS, r as SendResult, s as SimulationResult, t as StableAsset, u as SuiHolding, v as SuiRpcTxBlock, w as SupportedAsset, x as SwapRouteResult, T as T2000Error, y as T2000ErrorCode, z as T2000ErrorData, A as T2000_OVERLAY_FEE_WALLET, F as TOKEN_MAP, H as TransactionLeg, J as TransactionRecord, Q as TransactionSigner, R as TxDirection, U as USDC_DECIMALS, V as USDC_TYPE, W as USDE_TYPE, X as USDSUI_TYPE, Y as USDT_TYPE, Z as WAL_TYPE, _ as WBTC_TYPE, $ as ZkLoginProof, a0 as ZkLoginSigner, a1 as buildSendTx, a2 as buildSwapTx, a3 as checkPositiveAmount, a4 as checkSuiAddress, a5 as classifyAction, a6 as classifyLabel, a7 as classifyTransaction, a8 as executeTx, a9 as extractAllUserLegs, aa as extractTransferDetails, ab as extractTxCommands, ac as extractTxSender, ad as fallbackLabel, ae as findSwapRoute, af as formatAssetAmount, ag as formatSui, ah as formatUsd, ai as getDecimals, aj as getDecimalsForCoinType, ak as mapMoveAbortCode, al as mapWalletError, am as mistToSui, an as parseMppSuiChallenge, ao as parseSuiRpcTx, ap as payWithMpp, aq as preflightFail, ar as preflightPay, as as preflightSend, at as preflightSwap, au as rawToStable, av as rawToUsdc, aw as refineLendingLabel, ax as resolveSymbol, ay as resolveTokenType, az as stableToRaw, aA as suiToMist, aB as truncateAddress, aC as usdcToRaw, aD as validateAddress } from './send-DEK6aOGe.cjs';
|
|
2
2
|
import '@mysten/sui/keypairs/ed25519';
|
|
3
3
|
import '@mysten/sui/grpc';
|
|
4
4
|
import '@mysten/sui/client';
|
package/dist/browser.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { B as BalanceResponse, C as CLOCK_ID, a as COIN_REGISTRY, b as ClassifyBalanceChange, c as ClassifyResult, d as CoinMeta, D as DEFAULT_NETWORK, e as DepositInfo, E as ETH_TYPE, f as ExtractedTransfer, G as GAS_RESERVE_MIN, I as IKA_TYPE, K as KNOWN_TARGETS, g as KeypairSigner, L as LABEL_PATTERNS, h as LOFI_TYPE, M as MANIFEST_TYPE, i as MIST_PER_SUI, N as NAVX_TYPE, O as OVERLAY_FEE_RATE, j as OverlayFeeConfig, P as PREFLIGHT_MAX_AMOUNT, k as PREFLIGHT_OK, l as PayOptions, m as PayResult, n as PreflightResult, S as STABLE_ASSETS, o as SUI_DECIMALS, p as SUI_TYPE, q as SUPPORTED_ASSETS, r as SendResult, s as SimulationResult, t as StableAsset, u as SuiHolding, v as SuiRpcTxBlock, w as SupportedAsset, x as SwapRouteResult, T as T2000Error, y as T2000ErrorCode, z as T2000ErrorData, A as T2000_OVERLAY_FEE_WALLET, F as TOKEN_MAP, H as TransactionLeg, J as TransactionRecord, Q as TransactionSigner, R as TxDirection, U as USDC_DECIMALS, V as USDC_TYPE, W as USDE_TYPE, X as USDSUI_TYPE, Y as USDT_TYPE, Z as WAL_TYPE, _ as WBTC_TYPE, $ as ZkLoginProof, a0 as ZkLoginSigner, a1 as buildSendTx, a2 as buildSwapTx, a3 as checkPositiveAmount, a4 as checkSuiAddress, a5 as classifyAction, a6 as classifyLabel, a7 as classifyTransaction, a8 as executeTx, a9 as extractAllUserLegs, aa as extractTransferDetails, ab as extractTxCommands, ac as extractTxSender, ad as fallbackLabel, ae as findSwapRoute, af as formatAssetAmount, ag as formatSui, ah as formatUsd, ai as getDecimals, aj as getDecimalsForCoinType, ak as mapMoveAbortCode, al as mapWalletError, am as mistToSui, an as
|
|
1
|
+
export { B as BalanceResponse, C as CLOCK_ID, a as COIN_REGISTRY, b as ClassifyBalanceChange, c as ClassifyResult, d as CoinMeta, D as DEFAULT_NETWORK, e as DepositInfo, E as ETH_TYPE, f as ExtractedTransfer, G as GAS_RESERVE_MIN, I as IKA_TYPE, K as KNOWN_TARGETS, g as KeypairSigner, L as LABEL_PATTERNS, h as LOFI_TYPE, M as MANIFEST_TYPE, i as MIST_PER_SUI, N as NAVX_TYPE, O as OVERLAY_FEE_RATE, j as OverlayFeeConfig, P as PREFLIGHT_MAX_AMOUNT, k as PREFLIGHT_OK, l as PayOptions, m as PayResult, n as PreflightResult, S as STABLE_ASSETS, o as SUI_DECIMALS, p as SUI_TYPE, q as SUPPORTED_ASSETS, r as SendResult, s as SimulationResult, t as StableAsset, u as SuiHolding, v as SuiRpcTxBlock, w as SupportedAsset, x as SwapRouteResult, T as T2000Error, y as T2000ErrorCode, z as T2000ErrorData, A as T2000_OVERLAY_FEE_WALLET, F as TOKEN_MAP, H as TransactionLeg, J as TransactionRecord, Q as TransactionSigner, R as TxDirection, U as USDC_DECIMALS, V as USDC_TYPE, W as USDE_TYPE, X as USDSUI_TYPE, Y as USDT_TYPE, Z as WAL_TYPE, _ as WBTC_TYPE, $ as ZkLoginProof, a0 as ZkLoginSigner, a1 as buildSendTx, a2 as buildSwapTx, a3 as checkPositiveAmount, a4 as checkSuiAddress, a5 as classifyAction, a6 as classifyLabel, a7 as classifyTransaction, a8 as executeTx, a9 as extractAllUserLegs, aa as extractTransferDetails, ab as extractTxCommands, ac as extractTxSender, ad as fallbackLabel, ae as findSwapRoute, af as formatAssetAmount, ag as formatSui, ah as formatUsd, ai as getDecimals, aj as getDecimalsForCoinType, ak as mapMoveAbortCode, al as mapWalletError, am as mistToSui, an as parseMppSuiChallenge, ao as parseSuiRpcTx, ap as payWithMpp, aq as preflightFail, ar as preflightPay, as as preflightSend, at as preflightSwap, au as rawToStable, av as rawToUsdc, aw as refineLendingLabel, ax as resolveSymbol, ay as resolveTokenType, az as stableToRaw, aA as suiToMist, aB as truncateAddress, aC as usdcToRaw, aD as validateAddress } from './send-DEK6aOGe.js';
|
|
2
2
|
import '@mysten/sui/keypairs/ed25519';
|
|
3
3
|
import '@mysten/sui/grpc';
|
|
4
4
|
import '@mysten/sui/client';
|
package/dist/browser.js
CHANGED
|
@@ -445,6 +445,13 @@ var ZkLoginSigner = class {
|
|
|
445
445
|
// src/wallet/pay.ts
|
|
446
446
|
init_errors();
|
|
447
447
|
|
|
448
|
+
// src/mpp-cost.ts
|
|
449
|
+
function parseChallengeAmount(challenge) {
|
|
450
|
+
const raw = challenge?.request?.amount;
|
|
451
|
+
const n = typeof raw === "string" ? Number(raw) : typeof raw === "number" ? raw : Number.NaN;
|
|
452
|
+
return Number.isFinite(n) ? n : void 0;
|
|
453
|
+
}
|
|
454
|
+
|
|
448
455
|
// src/wallet/executeTx.ts
|
|
449
456
|
async function executeTx(client, signer, buildTx, options = {}) {
|
|
450
457
|
const tx = await buildTx();
|
|
@@ -457,7 +464,11 @@ async function executeTx(client, signer, buildTx, options = {}) {
|
|
|
457
464
|
include: { effects: true }
|
|
458
465
|
});
|
|
459
466
|
const txn = result.$kind === "Transaction" ? result.Transaction : result.FailedTransaction;
|
|
460
|
-
|
|
467
|
+
try {
|
|
468
|
+
await client.core.waitForTransaction({ digest: txn.digest });
|
|
469
|
+
} catch (err) {
|
|
470
|
+
if (!txn.effects) throw err;
|
|
471
|
+
}
|
|
461
472
|
const effects = txn.effects ?? void 0;
|
|
462
473
|
const gasUsed = effects?.gasUsed;
|
|
463
474
|
let gasCostSui = 0;
|
|
@@ -533,13 +544,35 @@ async function payWithMpp(args) {
|
|
|
533
544
|
return finalize(probe, { paid: false });
|
|
534
545
|
}
|
|
535
546
|
const requirements = await pickSuiExactRequirements(probe, client.network);
|
|
536
|
-
if (
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
547
|
+
if (requirements) {
|
|
548
|
+
return payViaX402({ signer, client, options, reqInit, requirements });
|
|
549
|
+
}
|
|
550
|
+
const headerChallenge = await parseMppSuiChallenge(probe);
|
|
551
|
+
if (headerChallenge) {
|
|
552
|
+
return payViaMppHeader({ signer, client, options });
|
|
553
|
+
}
|
|
554
|
+
throw new T2000Error(
|
|
555
|
+
"FACILITATOR_REJECTION",
|
|
556
|
+
`Endpoint returned 402 without an x402 'exact' / sui:${client.network} requirement in the body or an MPP 'sui' challenge in WWW-Authenticate. Nothing this SDK can pay.`
|
|
557
|
+
);
|
|
558
|
+
}
|
|
559
|
+
async function parseMppSuiChallenge(response) {
|
|
560
|
+
try {
|
|
561
|
+
const { Challenge } = await import('mppx');
|
|
562
|
+
const challenges = Challenge.fromResponseList(response);
|
|
563
|
+
const suiChallenge = challenges.find((c) => c.method === "sui" && c.intent === "charge");
|
|
564
|
+
if (!suiChallenge) return void 0;
|
|
565
|
+
const req = suiChallenge.request;
|
|
566
|
+
if (typeof req?.amount !== "string" || typeof req?.recipient !== "string") return void 0;
|
|
567
|
+
return {
|
|
568
|
+
amount: req.amount,
|
|
569
|
+
currency: typeof req.currency === "string" ? req.currency : "",
|
|
570
|
+
recipient: req.recipient,
|
|
571
|
+
description: suiChallenge.description
|
|
572
|
+
};
|
|
573
|
+
} catch {
|
|
574
|
+
return void 0;
|
|
541
575
|
}
|
|
542
|
-
return payViaX402({ signer, client, options, reqInit, requirements });
|
|
543
576
|
}
|
|
544
577
|
async function pickSuiExactRequirements(response, network) {
|
|
545
578
|
try {
|
|
@@ -554,6 +587,7 @@ async function payViaX402(args) {
|
|
|
554
587
|
const { signer, client, options, reqInit, requirements } = args;
|
|
555
588
|
const { buildX402SignedPayment, X402_PAYMENT_HEADER, X402_PAYMENT_RESPONSE_HEADER } = await import('@suimpp/mpp/x402');
|
|
556
589
|
const amountRaw = BigInt(requirements.maxAmountRequired);
|
|
590
|
+
assertWithinMaxPrice(atomicToHuman(amountRaw, await assetDecimals(requirements.asset)), options.maxPrice);
|
|
557
591
|
const migrationGasSui = await ensureAddressBalanceCovers({
|
|
558
592
|
signer,
|
|
559
593
|
client,
|
|
@@ -589,6 +623,70 @@ async function payViaX402(args) {
|
|
|
589
623
|
receipt: digest ? { reference: digest, timestamp: (/* @__PURE__ */ new Date()).toISOString() } : result.receipt
|
|
590
624
|
};
|
|
591
625
|
}
|
|
626
|
+
async function payViaMppHeader(args) {
|
|
627
|
+
const { signer, client, options } = args;
|
|
628
|
+
const { Mppx } = await import('mppx/client');
|
|
629
|
+
const { sui, USDC, USDC_TESTNET } = await import('@suimpp/mpp/client');
|
|
630
|
+
const signerAddress = signer.getAddress();
|
|
631
|
+
const network = client.network === "testnet" ? "testnet" : "mainnet";
|
|
632
|
+
const grpcClient = await makeGrpcBuildClient(client);
|
|
633
|
+
let paymentDigest;
|
|
634
|
+
let gasCostSui = 0;
|
|
635
|
+
let chargedAmount;
|
|
636
|
+
const mppx = Mppx.create({
|
|
637
|
+
polyfill: false,
|
|
638
|
+
onChallenge: async (challenge) => {
|
|
639
|
+
const parsed = parseChallengeAmount(challenge);
|
|
640
|
+
if (parsed !== void 0) {
|
|
641
|
+
chargedAmount = parsed;
|
|
642
|
+
assertWithinMaxPrice(parsed, options.maxPrice);
|
|
643
|
+
}
|
|
644
|
+
return void 0;
|
|
645
|
+
},
|
|
646
|
+
methods: [
|
|
647
|
+
sui({
|
|
648
|
+
client,
|
|
649
|
+
currency: network === "testnet" ? USDC_TESTNET : USDC,
|
|
650
|
+
signer: {
|
|
651
|
+
toSuiAddress: () => signerAddress,
|
|
652
|
+
signPersonalMessage: (bytes) => signer.signPersonalMessage(bytes)
|
|
653
|
+
},
|
|
654
|
+
execute: async (tx) => {
|
|
655
|
+
const result2 = await executeTx(client, signer, () => tx, { buildClient: grpcClient });
|
|
656
|
+
paymentDigest = result2.digest;
|
|
657
|
+
gasCostSui = result2.gasCostSui;
|
|
658
|
+
return { digest: result2.digest };
|
|
659
|
+
}
|
|
660
|
+
})
|
|
661
|
+
]
|
|
662
|
+
});
|
|
663
|
+
const method = (options.method ?? "GET").toUpperCase();
|
|
664
|
+
const canHaveBody = method !== "GET" && method !== "HEAD";
|
|
665
|
+
const response = await mppx.fetch(options.url, {
|
|
666
|
+
method,
|
|
667
|
+
headers: options.headers,
|
|
668
|
+
body: canHaveBody ? options.body : void 0
|
|
669
|
+
});
|
|
670
|
+
const paid = !!paymentDigest;
|
|
671
|
+
const result = await finalize(response, { paid });
|
|
672
|
+
if (!paid) return { ...result, dialect: "legacy" };
|
|
673
|
+
return {
|
|
674
|
+
...result,
|
|
675
|
+
dialect: "legacy",
|
|
676
|
+
cost: chargedAmount ?? options.maxPrice ?? void 0,
|
|
677
|
+
gasCostSui,
|
|
678
|
+
receipt: paymentDigest ? { reference: paymentDigest, timestamp: (/* @__PURE__ */ new Date()).toISOString() } : void 0
|
|
679
|
+
};
|
|
680
|
+
}
|
|
681
|
+
function assertWithinMaxPrice(price, maxPrice) {
|
|
682
|
+
if (maxPrice !== void 0 && price > maxPrice) {
|
|
683
|
+
throw new T2000Error(
|
|
684
|
+
"PRICE_EXCEEDS_LIMIT",
|
|
685
|
+
`Service price $${price} exceeds maxPrice ceiling $${maxPrice}`,
|
|
686
|
+
{ price, maxPrice }
|
|
687
|
+
);
|
|
688
|
+
}
|
|
689
|
+
}
|
|
592
690
|
async function ensureAddressBalanceCovers(args) {
|
|
593
691
|
const { signer, client, asset, amountRaw } = args;
|
|
594
692
|
const owner = signer.getAddress();
|
|
@@ -1170,6 +1268,6 @@ async function buildSendTx({
|
|
|
1170
1268
|
// src/browser.ts
|
|
1171
1269
|
init_token_registry();
|
|
1172
1270
|
|
|
1173
|
-
export { CLOCK_ID, COIN_REGISTRY, DEFAULT_NETWORK, ETH_TYPE, GAS_RESERVE_MIN, IKA_TYPE, KNOWN_TARGETS, KeypairSigner, LABEL_PATTERNS, LOFI_TYPE, MANIFEST_TYPE, MIST_PER_SUI, NAVX_TYPE, OVERLAY_FEE_RATE, PREFLIGHT_MAX_AMOUNT, PREFLIGHT_OK, STABLE_ASSETS, SUI_DECIMALS, SUI_TYPE, SUPPORTED_ASSETS, T2000Error, T2000_OVERLAY_FEE_WALLET, TOKEN_MAP, USDC_DECIMALS, USDC_TYPE, USDE_TYPE, USDSUI_TYPE, USDT_TYPE, WAL_TYPE, WBTC_TYPE, ZkLoginSigner, buildSendTx, buildSwapTx, checkPositiveAmount, checkSuiAddress, classifyAction, classifyLabel, classifyTransaction, executeTx, extractAllUserLegs, extractTransferDetails, extractTxCommands, extractTxSender, fallbackLabel, findSwapRoute, formatAssetAmount, formatSui, formatUsd, fromBase642 as fromBase64, getDecimals, getDecimalsForCoinType, mapMoveAbortCode, mapWalletError, mistToSui, parseSuiRpcTx, payWithMpp, preflightFail, preflightPay, preflightSend, preflightSwap, rawToStable, rawToUsdc, refineLendingLabel, resolveSymbol, resolveTokenType, stableToRaw, suiToMist, toBase64, truncateAddress, usdcToRaw, validateAddress };
|
|
1271
|
+
export { CLOCK_ID, COIN_REGISTRY, DEFAULT_NETWORK, ETH_TYPE, GAS_RESERVE_MIN, IKA_TYPE, KNOWN_TARGETS, KeypairSigner, LABEL_PATTERNS, LOFI_TYPE, MANIFEST_TYPE, MIST_PER_SUI, NAVX_TYPE, OVERLAY_FEE_RATE, PREFLIGHT_MAX_AMOUNT, PREFLIGHT_OK, STABLE_ASSETS, SUI_DECIMALS, SUI_TYPE, SUPPORTED_ASSETS, T2000Error, T2000_OVERLAY_FEE_WALLET, TOKEN_MAP, USDC_DECIMALS, USDC_TYPE, USDE_TYPE, USDSUI_TYPE, USDT_TYPE, WAL_TYPE, WBTC_TYPE, ZkLoginSigner, buildSendTx, buildSwapTx, checkPositiveAmount, checkSuiAddress, classifyAction, classifyLabel, classifyTransaction, executeTx, extractAllUserLegs, extractTransferDetails, extractTxCommands, extractTxSender, fallbackLabel, findSwapRoute, formatAssetAmount, formatSui, formatUsd, fromBase642 as fromBase64, getDecimals, getDecimalsForCoinType, mapMoveAbortCode, mapWalletError, mistToSui, parseMppSuiChallenge, parseSuiRpcTx, payWithMpp, preflightFail, preflightPay, preflightSend, preflightSwap, rawToStable, rawToUsdc, refineLendingLabel, resolveSymbol, resolveTokenType, stableToRaw, suiToMist, toBase64, truncateAddress, usdcToRaw, validateAddress };
|
|
1174
1272
|
//# sourceMappingURL=browser.js.map
|
|
1175
1273
|
//# sourceMappingURL=browser.js.map
|