@t2000/sdk 5.5.1 → 5.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser.cjs +164 -4
- package/dist/browser.cjs.map +1 -1
- package/dist/browser.d.cts +1 -1
- package/dist/browser.d.ts +1 -1
- package/dist/browser.js +158 -7
- package/dist/browser.js.map +1 -1
- package/dist/index.cjs +110 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +17 -70
- package/dist/index.d.ts +17 -70
- package/dist/index.js +104 -11
- package/dist/index.js.map +1 -1
- package/dist/{simulate-KETPmlDo.d.cts → send-D2nKpwJN.d.cts} +162 -21
- package/dist/{simulate-KETPmlDo.d.ts → send-D2nKpwJN.d.ts} +162 -21
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var utils = require('@mysten/sui/utils');
|
|
3
4
|
var transactions = require('@mysten/sui/transactions');
|
|
4
5
|
var aggregatorSdk = require('@cetusprotocol/aggregator-sdk');
|
|
5
6
|
var BN = require('bn.js');
|
|
@@ -7,7 +8,6 @@ var eventemitter3 = require('eventemitter3');
|
|
|
7
8
|
var paymentKit = require('@mysten/payment-kit');
|
|
8
9
|
var grpc = require('@mysten/sui/grpc');
|
|
9
10
|
var graphql = require('@mysten/sui/graphql');
|
|
10
|
-
var utils = require('@mysten/sui/utils');
|
|
11
11
|
var ed25519 = require('@mysten/sui/keypairs/ed25519');
|
|
12
12
|
var cryptography = require('@mysten/sui/cryptography');
|
|
13
13
|
var promises = require('fs/promises');
|
|
@@ -118,6 +118,37 @@ var init_errors = __esm({
|
|
|
118
118
|
};
|
|
119
119
|
}
|
|
120
120
|
});
|
|
121
|
+
function preflightFail(code, error) {
|
|
122
|
+
return { valid: false, code, error };
|
|
123
|
+
}
|
|
124
|
+
function checkPositiveAmount(amount, label = "Amount", max = exports.PREFLIGHT_MAX_AMOUNT) {
|
|
125
|
+
if (typeof amount !== "number" || !Number.isFinite(amount)) {
|
|
126
|
+
return preflightFail("INVALID_AMOUNT", `${label} must be a finite number`);
|
|
127
|
+
}
|
|
128
|
+
if (amount <= 0) {
|
|
129
|
+
return preflightFail("INVALID_AMOUNT", `${label} must be greater than zero`);
|
|
130
|
+
}
|
|
131
|
+
if (amount > max) {
|
|
132
|
+
return preflightFail("INVALID_AMOUNT", `${label} ${amount} exceeds the sane maximum (${max})`);
|
|
133
|
+
}
|
|
134
|
+
return exports.PREFLIGHT_OK;
|
|
135
|
+
}
|
|
136
|
+
function checkSuiAddress(address, label = "recipient") {
|
|
137
|
+
try {
|
|
138
|
+
if (typeof address === "string" && address.trim() !== "" && utils.isValidSuiAddress(utils.normalizeSuiAddress(address))) {
|
|
139
|
+
return exports.PREFLIGHT_OK;
|
|
140
|
+
}
|
|
141
|
+
} catch {
|
|
142
|
+
}
|
|
143
|
+
return preflightFail("INVALID_ADDRESS", `Invalid ${label} address: ${address}`);
|
|
144
|
+
}
|
|
145
|
+
exports.PREFLIGHT_MAX_AMOUNT = void 0; exports.PREFLIGHT_OK = void 0;
|
|
146
|
+
var init_preflight = __esm({
|
|
147
|
+
"src/preflight.ts"() {
|
|
148
|
+
exports.PREFLIGHT_MAX_AMOUNT = 1e6;
|
|
149
|
+
exports.PREFLIGHT_OK = { valid: true };
|
|
150
|
+
}
|
|
151
|
+
});
|
|
121
152
|
|
|
122
153
|
// src/token-registry.ts
|
|
123
154
|
var token_registry_exports = {};
|
|
@@ -382,10 +413,28 @@ __export(cetus_swap_exports, {
|
|
|
382
413
|
findSwapRoute: () => findSwapRoute,
|
|
383
414
|
isCetusRouteFresh: () => isCetusRouteFresh,
|
|
384
415
|
isPrecomputedRouteCompatibleWithProviders: () => isPrecomputedRouteCompatibleWithProviders,
|
|
416
|
+
preflightSwap: () => preflightSwap,
|
|
385
417
|
resolveTokenType: () => resolveTokenType,
|
|
386
418
|
serializeCetusRoute: () => serializeCetusRoute,
|
|
387
419
|
verifyCetusRouteCoinMatch: () => verifyCetusRouteCoinMatch
|
|
388
420
|
});
|
|
421
|
+
function preflightSwap(input) {
|
|
422
|
+
if (typeof input.from !== "string" || input.from.trim() === "") {
|
|
423
|
+
return preflightFail("INVALID_ASSET", "A `from` token is required to swap");
|
|
424
|
+
}
|
|
425
|
+
if (typeof input.to !== "string" || input.to.trim() === "") {
|
|
426
|
+
return preflightFail("INVALID_ASSET", "A `to` token is required to swap");
|
|
427
|
+
}
|
|
428
|
+
const amountCheck = checkPositiveAmount(input.amount, "Amount", Number.POSITIVE_INFINITY);
|
|
429
|
+
if (!amountCheck.valid) return amountCheck;
|
|
430
|
+
const resolvedFrom = resolveTokenType(input.from);
|
|
431
|
+
const resolvedTo = resolveTokenType(input.to);
|
|
432
|
+
const sameToken = input.from.trim() === input.to.trim() || resolvedFrom !== null && resolvedFrom === resolvedTo;
|
|
433
|
+
if (sameToken) {
|
|
434
|
+
return preflightFail("INVALID_ASSET", `Cannot swap ${input.from} to itself`);
|
|
435
|
+
}
|
|
436
|
+
return exports.PREFLIGHT_OK;
|
|
437
|
+
}
|
|
389
438
|
function serializeCetusRoute(route, context) {
|
|
390
439
|
return {
|
|
391
440
|
routerData: serializeRouterDataV3(route.routerData),
|
|
@@ -637,6 +686,7 @@ exports.OVERLAY_FEE_RATE = void 0; var clientCache;
|
|
|
637
686
|
var init_cetus_swap = __esm({
|
|
638
687
|
"src/protocols/cetus-swap.ts"() {
|
|
639
688
|
init_token_registry();
|
|
689
|
+
init_preflight();
|
|
640
690
|
init_token_registry();
|
|
641
691
|
exports.OVERLAY_FEE_RATE = 1e-3;
|
|
642
692
|
clientCache = /* @__PURE__ */ new Map();
|
|
@@ -1010,8 +1060,33 @@ async function executeTx(client, signer, buildTx, options = {}) {
|
|
|
1010
1060
|
|
|
1011
1061
|
// src/wallet/pay.ts
|
|
1012
1062
|
init_errors();
|
|
1063
|
+
init_preflight();
|
|
1064
|
+
function preflightPay(input) {
|
|
1065
|
+
if (typeof input.url !== "string" || input.url.trim() === "") {
|
|
1066
|
+
return preflightFail("FACILITATOR_REJECTION", "A target URL is required to pay");
|
|
1067
|
+
}
|
|
1068
|
+
let parsed;
|
|
1069
|
+
try {
|
|
1070
|
+
parsed = new URL(input.url);
|
|
1071
|
+
} catch {
|
|
1072
|
+
return preflightFail("FACILITATOR_REJECTION", `Invalid URL: ${input.url}`);
|
|
1073
|
+
}
|
|
1074
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") {
|
|
1075
|
+
return preflightFail(
|
|
1076
|
+
"FACILITATOR_REJECTION",
|
|
1077
|
+
`URL must be http(s): got ${parsed.protocol}//`
|
|
1078
|
+
);
|
|
1079
|
+
}
|
|
1080
|
+
if (input.maxPrice !== void 0) {
|
|
1081
|
+
const priceCheck = checkPositiveAmount(input.maxPrice, "maxPrice");
|
|
1082
|
+
if (!priceCheck.valid) return priceCheck;
|
|
1083
|
+
}
|
|
1084
|
+
return exports.PREFLIGHT_OK;
|
|
1085
|
+
}
|
|
1013
1086
|
async function payWithMpp(args) {
|
|
1014
1087
|
const { signer, client, options } = args;
|
|
1088
|
+
const pf = preflightPay({ url: options.url, maxPrice: options.maxPrice });
|
|
1089
|
+
if (!pf.valid) throw new exports.T2000Error(pf.code, pf.error);
|
|
1015
1090
|
const method = (options.method ?? "GET").toUpperCase();
|
|
1016
1091
|
const canHaveBody = method !== "GET" && method !== "HEAD";
|
|
1017
1092
|
const reqInit = {
|
|
@@ -1246,6 +1321,25 @@ function normalizeAsset(input) {
|
|
|
1246
1321
|
}
|
|
1247
1322
|
|
|
1248
1323
|
// src/wallet/send.ts
|
|
1324
|
+
init_preflight();
|
|
1325
|
+
function preflightSend(input) {
|
|
1326
|
+
try {
|
|
1327
|
+
assertAllowedAsset("send", input.asset);
|
|
1328
|
+
} catch (e) {
|
|
1329
|
+
return preflightFail("INVALID_ASSET", e.message);
|
|
1330
|
+
}
|
|
1331
|
+
const amountCheck = checkPositiveAmount(input.amount);
|
|
1332
|
+
if (!amountCheck.valid) return amountCheck;
|
|
1333
|
+
if ((input.asset === "USDC" || input.asset === "USDsui") && input.amount < GASLESS_MIN_STABLE_AMOUNT) {
|
|
1334
|
+
return preflightFail(
|
|
1335
|
+
"INVALID_AMOUNT",
|
|
1336
|
+
`Minimum gasless transfer is ${GASLESS_MIN_STABLE_AMOUNT} ${input.asset}. Got ${input.amount}.`
|
|
1337
|
+
);
|
|
1338
|
+
}
|
|
1339
|
+
const addressCheck = checkSuiAddress(input.to);
|
|
1340
|
+
if (!addressCheck.valid) return addressCheck;
|
|
1341
|
+
return exports.PREFLIGHT_OK;
|
|
1342
|
+
}
|
|
1249
1343
|
async function buildSendTx({
|
|
1250
1344
|
client,
|
|
1251
1345
|
address,
|
|
@@ -1253,17 +1347,11 @@ async function buildSendTx({
|
|
|
1253
1347
|
amount,
|
|
1254
1348
|
asset
|
|
1255
1349
|
}) {
|
|
1256
|
-
|
|
1350
|
+
const pf = preflightSend({ to, amount, asset });
|
|
1351
|
+
if (!pf.valid) throw new exports.T2000Error(pf.code, pf.error);
|
|
1257
1352
|
const recipient = validateAddress(to);
|
|
1258
1353
|
const assetInfo = SUPPORTED_ASSETS[asset];
|
|
1259
1354
|
if (!assetInfo) throw new exports.T2000Error("ASSET_NOT_SUPPORTED", `Asset ${asset} is not supported`);
|
|
1260
|
-
if (amount <= 0) throw new exports.T2000Error("INVALID_AMOUNT", "Amount must be greater than zero");
|
|
1261
|
-
if ((asset === "USDC" || asset === "USDsui") && amount < GASLESS_MIN_STABLE_AMOUNT) {
|
|
1262
|
-
throw new exports.T2000Error(
|
|
1263
|
-
"INVALID_AMOUNT",
|
|
1264
|
-
`Minimum gasless transfer is ${GASLESS_MIN_STABLE_AMOUNT} ${asset}. Got ${amount}.`
|
|
1265
|
-
);
|
|
1266
|
-
}
|
|
1267
1355
|
const rawAmount = displayToRaw(amount, assetInfo.decimals);
|
|
1268
1356
|
const tx = new transactions.Transaction();
|
|
1269
1357
|
tx.setSender(address);
|
|
@@ -2059,7 +2147,9 @@ var T2000 = class _T2000 extends eventemitter3.EventEmitter {
|
|
|
2059
2147
|
amountUsd: approxUsdValue(params.from, params.amount) ?? 0,
|
|
2060
2148
|
force: params.force
|
|
2061
2149
|
});
|
|
2062
|
-
const { findSwapRoute: findSwapRoute2, buildSwapTx: buildSwapTx2, resolveTokenType: resolveTokenType2 } = await Promise.resolve().then(() => (init_cetus_swap(), cetus_swap_exports));
|
|
2150
|
+
const { findSwapRoute: findSwapRoute2, buildSwapTx: buildSwapTx2, resolveTokenType: resolveTokenType2, preflightSwap: preflightSwap2 } = await Promise.resolve().then(() => (init_cetus_swap(), cetus_swap_exports));
|
|
2151
|
+
const pf = preflightSwap2({ from: params.from, to: params.to, amount: params.amount });
|
|
2152
|
+
if (!pf.valid) throw new exports.T2000Error(pf.code, pf.error);
|
|
2063
2153
|
const fromType = resolveTokenType2(params.from);
|
|
2064
2154
|
const toType = resolveTokenType2(params.to);
|
|
2065
2155
|
if (!fromType) throw new exports.T2000Error("ASSET_NOT_SUPPORTED", `Unknown token: ${params.from}. Provide the full coin type.`);
|
|
@@ -2789,6 +2879,9 @@ function displayHandle(label) {
|
|
|
2789
2879
|
return `${label}@${parentDisplay}`;
|
|
2790
2880
|
}
|
|
2791
2881
|
|
|
2882
|
+
// src/index.ts
|
|
2883
|
+
init_preflight();
|
|
2884
|
+
|
|
2792
2885
|
exports.AUDRIC_PARENT_NAME = AUDRIC_PARENT_NAME;
|
|
2793
2886
|
exports.AUDRIC_PARENT_NFT_ID = AUDRIC_PARENT_NFT_ID;
|
|
2794
2887
|
exports.CETUS_USDC_SUI_POOL = CETUS_USDC_SUI_POOL;
|
|
@@ -2830,6 +2923,8 @@ exports.buildAddLeafTx = buildAddLeafTx;
|
|
|
2830
2923
|
exports.buildRevokeLeafTx = buildRevokeLeafTx;
|
|
2831
2924
|
exports.buildSendTx = buildSendTx;
|
|
2832
2925
|
exports.buildSwapTx = buildSwapTx;
|
|
2926
|
+
exports.checkPositiveAmount = checkPositiveAmount;
|
|
2927
|
+
exports.checkSuiAddress = checkSuiAddress;
|
|
2833
2928
|
exports.classifyAction = classifyAction;
|
|
2834
2929
|
exports.classifyLabel = classifyLabel;
|
|
2835
2930
|
exports.classifyTransaction = classifyTransaction;
|
|
@@ -2877,6 +2972,11 @@ exports.normalizeAsset = normalizeAsset;
|
|
|
2877
2972
|
exports.normalizeCoinType = normalizeCoinType;
|
|
2878
2973
|
exports.parseSuiRpcTx = parseSuiRpcTx;
|
|
2879
2974
|
exports.payWithMpp = payWithMpp;
|
|
2975
|
+
exports.preflightFail = preflightFail;
|
|
2976
|
+
exports.preflightPay = preflightPay;
|
|
2977
|
+
exports.preflightSend = preflightSend;
|
|
2978
|
+
exports.preflightSwap = preflightSwap;
|
|
2979
|
+
exports.queryBalance = queryBalance;
|
|
2880
2980
|
exports.queryHistory = queryHistory;
|
|
2881
2981
|
exports.queryTransaction = queryTransaction;
|
|
2882
2982
|
exports.rawToStable = rawToStable;
|