@trustware/sdk-staging 1.1.11-staging.1 → 1.1.11-staging.2
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/README.md +54 -21
- package/dist/constants.cjs +1 -1
- package/dist/constants.mjs +1 -1
- package/dist/{core-BgYLe9Q7.d.ts → core-B1WCJfDI.d.ts} +1 -1
- package/dist/{core-fLSt4qD2.d.cts → core-CeNTuqPz.d.cts} +1 -1
- package/dist/core.cjs +85 -43
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.cts +2 -2
- package/dist/core.d.ts +2 -2
- package/dist/core.mjs +83 -42
- package/dist/core.mjs.map +1 -1
- package/dist/index.cjs +107 -55
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +11 -5
- package/dist/index.d.ts +11 -5
- package/dist/index.mjs +105 -55
- package/dist/index.mjs.map +1 -1
- package/dist/{manager-BY3NHAks.d.ts → manager-Bw8b1wSD.d.ts} +89 -22
- package/dist/{manager-DT8enQbE.d.cts → manager-DNGk1YkR.d.cts} +89 -22
- package/dist/{metadata-BPvFYMlc.d.ts → metadata-C__KMeuz.d.ts} +1 -1
- package/dist/{metadata-DyxUcKHk.d.cts → metadata-Dk4R8_-T.d.cts} +1 -1
- package/dist/smart-account.cjs +49 -44
- package/dist/smart-account.cjs.map +1 -1
- package/dist/smart-account.d.cts +5 -0
- package/dist/smart-account.d.ts +5 -0
- package/dist/smart-account.mjs +49 -44
- package/dist/smart-account.mjs.map +1 -1
- package/dist/wallet.cjs +40 -39
- package/dist/wallet.cjs.map +1 -1
- package/dist/wallet.d.cts +3 -3
- package/dist/wallet.d.ts +3 -3
- package/dist/wallet.mjs +40 -39
- package/dist/wallet.mjs.map +1 -1
- package/dist/widget.cjs +101 -55
- package/dist/widget.cjs.map +1 -1
- package/dist/widget.mjs +101 -55
- package/dist/widget.mjs.map +1 -1
- package/package.json +73 -5
package/dist/index.cjs
CHANGED
|
@@ -47,18 +47,16 @@ var init_defaults = __esm({
|
|
|
47
47
|
});
|
|
48
48
|
|
|
49
49
|
// src/types/config.ts
|
|
50
|
-
var DEFAULT_SLIPPAGE2, DEFAULT_AUTO_DETECT_PROVIDER2, DEFAULT_RETRY_CONFIG, DEFAULT_FEATURE_FLAGS;
|
|
50
|
+
var DEFAULT_SLIPPAGE2, DEFAULT_AUTO_DETECT_PROVIDER2, DEFAULT_RETRY_CONFIG, RATE_LIMIT_WAIT_BUDGET_MS, DEFAULT_FEATURE_FLAGS;
|
|
51
51
|
var init_config = __esm({
|
|
52
52
|
"src/types/config.ts"() {
|
|
53
53
|
"use strict";
|
|
54
54
|
DEFAULT_SLIPPAGE2 = 1;
|
|
55
55
|
DEFAULT_AUTO_DETECT_PROVIDER2 = false;
|
|
56
56
|
DEFAULT_RETRY_CONFIG = {
|
|
57
|
-
autoRetry: true,
|
|
58
|
-
maxRetries: 3,
|
|
59
|
-
baseDelayMs: 1e3,
|
|
60
57
|
approachingThreshold: 5
|
|
61
58
|
};
|
|
59
|
+
RATE_LIMIT_WAIT_BUDGET_MS = 1e4;
|
|
62
60
|
DEFAULT_FEATURE_FLAGS = {
|
|
63
61
|
tokensPagination: true,
|
|
64
62
|
balanceStreaming: false,
|
|
@@ -195,9 +193,6 @@ function resolveConfig(input) {
|
|
|
195
193
|
const theme = input.theme ?? "system";
|
|
196
194
|
const messages = deepMerge(DEFAULT_MESSAGES, input.messages);
|
|
197
195
|
const retry = {
|
|
198
|
-
autoRetry: input.retry?.autoRetry ?? DEFAULT_RETRY_CONFIG.autoRetry,
|
|
199
|
-
maxRetries: input.retry?.maxRetries ?? DEFAULT_RETRY_CONFIG.maxRetries,
|
|
200
|
-
baseDelayMs: input.retry?.baseDelayMs ?? DEFAULT_RETRY_CONFIG.baseDelayMs,
|
|
201
196
|
approachingThreshold: input.retry?.approachingThreshold ?? DEFAULT_RETRY_CONFIG.approachingThreshold,
|
|
202
197
|
onRateLimitInfo: input.retry?.onRateLimitInfo,
|
|
203
198
|
onRateLimited: input.retry?.onRateLimited,
|
|
@@ -509,7 +504,7 @@ var init_constants = __esm({
|
|
|
509
504
|
"src/constants.ts"() {
|
|
510
505
|
"use strict";
|
|
511
506
|
SDK_NAME = "@trustware/sdk";
|
|
512
|
-
SDK_VERSION = "1.1.11-staging.
|
|
507
|
+
SDK_VERSION = "1.1.11-staging.2";
|
|
513
508
|
API_ROOT = "https://bv-staging-api.trustware.io";
|
|
514
509
|
GTM_ID = "GTM-TZDGNCXB";
|
|
515
510
|
API_PREFIX = "/api";
|
|
@@ -596,50 +591,54 @@ function notifyRateLimitCallbacks(info, isRateLimited, retryCount) {
|
|
|
596
591
|
retry.onRateLimitApproaching(info, retry.approachingThreshold);
|
|
597
592
|
}
|
|
598
593
|
}
|
|
599
|
-
function
|
|
600
|
-
if (
|
|
601
|
-
|
|
594
|
+
function serverDirectedWaitMs(info) {
|
|
595
|
+
if (!info) return null;
|
|
596
|
+
if (typeof info.retryAfter === "number" && info.retryAfter > 0) {
|
|
597
|
+
return info.retryAfter * 1e3;
|
|
602
598
|
}
|
|
603
|
-
|
|
599
|
+
if (typeof info.reset === "number" && info.reset > 0) {
|
|
600
|
+
const untilReset = info.reset * 1e3 - Date.now();
|
|
601
|
+
if (untilReset > 0) return untilReset;
|
|
602
|
+
}
|
|
603
|
+
return null;
|
|
604
604
|
}
|
|
605
605
|
function sleep(ms) {
|
|
606
606
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
607
607
|
}
|
|
608
|
-
async function
|
|
609
|
-
|
|
610
|
-
const cfg = TrustwareConfigStore.get();
|
|
611
|
-
if (!cfg.retry.autoRetry || skipRateLimit) {
|
|
612
|
-
return fetch(url, fetchOptions);
|
|
613
|
-
}
|
|
614
|
-
const { maxRetries, baseDelayMs } = cfg.retry;
|
|
608
|
+
async function withRateLimitRetry(attempt) {
|
|
609
|
+
let waitedMs = 0;
|
|
615
610
|
let retryCount = 0;
|
|
616
611
|
while (true) {
|
|
617
|
-
const response = await
|
|
612
|
+
const response = await attempt();
|
|
618
613
|
const rateLimitInfo = parseRateLimitHeaders(response);
|
|
619
|
-
if (response.status
|
|
614
|
+
if (response.status !== 429) {
|
|
620
615
|
if (rateLimitInfo) {
|
|
621
|
-
notifyRateLimitCallbacks(rateLimitInfo,
|
|
622
|
-
}
|
|
623
|
-
if (retryCount >= maxRetries) {
|
|
624
|
-
throw new RateLimitError(
|
|
625
|
-
rateLimitInfo || { limit: 0, remaining: 0, reset: 0 },
|
|
626
|
-
true
|
|
627
|
-
);
|
|
616
|
+
notifyRateLimitCallbacks(rateLimitInfo, false, 0);
|
|
628
617
|
}
|
|
629
|
-
|
|
630
|
-
baseDelayMs,
|
|
631
|
-
retryCount,
|
|
632
|
-
rateLimitInfo?.retryAfter
|
|
633
|
-
);
|
|
634
|
-
await sleep(delay);
|
|
635
|
-
retryCount++;
|
|
636
|
-
continue;
|
|
618
|
+
return response;
|
|
637
619
|
}
|
|
638
620
|
if (rateLimitInfo) {
|
|
639
|
-
notifyRateLimitCallbacks(rateLimitInfo,
|
|
621
|
+
notifyRateLimitCallbacks(rateLimitInfo, true, retryCount);
|
|
640
622
|
}
|
|
641
|
-
|
|
623
|
+
const waitMs = serverDirectedWaitMs(rateLimitInfo);
|
|
624
|
+
const info = rateLimitInfo || { limit: 0, remaining: 0, reset: 0 };
|
|
625
|
+
if (waitMs === null) {
|
|
626
|
+
throw new RateLimitError(info, true);
|
|
627
|
+
}
|
|
628
|
+
if (waitedMs + waitMs > RATE_LIMIT_WAIT_BUDGET_MS) {
|
|
629
|
+
throw new RateLimitError(info, false);
|
|
630
|
+
}
|
|
631
|
+
await sleep(waitMs);
|
|
632
|
+
waitedMs += waitMs;
|
|
633
|
+
retryCount++;
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
async function rateLimitedFetch(url, options = {}) {
|
|
637
|
+
const { skipRateLimit, ...fetchOptions } = options;
|
|
638
|
+
if (skipRateLimit) {
|
|
639
|
+
return fetch(url, fetchOptions);
|
|
642
640
|
}
|
|
641
|
+
return withRateLimitRetry(() => fetch(url, fetchOptions));
|
|
643
642
|
}
|
|
644
643
|
var RateLimitError;
|
|
645
644
|
var init_http = __esm({
|
|
@@ -647,9 +646,11 @@ var init_http = __esm({
|
|
|
647
646
|
"use strict";
|
|
648
647
|
init_constants();
|
|
649
648
|
init_config2();
|
|
649
|
+
init_config();
|
|
650
650
|
RateLimitError = class extends Error {
|
|
651
651
|
constructor(info, retriesExhausted) {
|
|
652
|
-
const
|
|
652
|
+
const seconds = info.retryAfter ?? (info.reset > 0 ? Math.max(0, Math.ceil((info.reset * 1e3 - Date.now()) / 1e3)) : null);
|
|
653
|
+
const message = seconds === null ? "Rate limit exceeded. The server did not say when to retry." : `Rate limit exceeded. Try again in ${seconds} seconds.`;
|
|
653
654
|
super(message);
|
|
654
655
|
this.name = "RateLimitError";
|
|
655
656
|
this.rateLimitInfo = info;
|
|
@@ -4575,7 +4576,18 @@ async function getStatus(intentId) {
|
|
|
4575
4576
|
);
|
|
4576
4577
|
await assertOK(r);
|
|
4577
4578
|
const j = await r.json();
|
|
4578
|
-
return j.data;
|
|
4579
|
+
return normalizeStatusPayload(j.data);
|
|
4580
|
+
}
|
|
4581
|
+
function normalizeStatusPayload(raw) {
|
|
4582
|
+
if (!raw || typeof raw !== "object") return raw;
|
|
4583
|
+
const wire = raw;
|
|
4584
|
+
const out = { ...wire };
|
|
4585
|
+
for (const [snake, camel] of Object.entries(STATUS_WIRE_TO_CAMEL)) {
|
|
4586
|
+
if (out[camel] !== void 0) continue;
|
|
4587
|
+
if (!(snake in wire)) continue;
|
|
4588
|
+
out[camel] = wire[snake];
|
|
4589
|
+
}
|
|
4590
|
+
return out;
|
|
4579
4591
|
}
|
|
4580
4592
|
async function pollStatus(intentId, { intervalMs = 2e3, timeoutMs = 5 * 6e4 } = {}) {
|
|
4581
4593
|
const t0 = Date.now();
|
|
@@ -4586,12 +4598,39 @@ async function pollStatus(intentId, { intervalMs = 2e3, timeoutMs = 5 * 6e4 } =
|
|
|
4586
4598
|
await new Promise((r) => setTimeout(r, intervalMs));
|
|
4587
4599
|
}
|
|
4588
4600
|
}
|
|
4601
|
+
var STATUS_WIRE_TO_CAMEL;
|
|
4589
4602
|
var init_routes = __esm({
|
|
4590
4603
|
"src/core/routes.ts"() {
|
|
4591
4604
|
"use strict";
|
|
4592
4605
|
init_http();
|
|
4593
4606
|
init_store();
|
|
4594
4607
|
init_address();
|
|
4608
|
+
STATUS_WIRE_TO_CAMEL = {
|
|
4609
|
+
intent_id: "intentId",
|
|
4610
|
+
from_address: "fromAddress",
|
|
4611
|
+
to_address: "toAddress",
|
|
4612
|
+
from_chain_id: "fromChainId",
|
|
4613
|
+
to_chain_id: "toChainId",
|
|
4614
|
+
source_tx_hash: "sourceTxHash",
|
|
4615
|
+
dest_tx_hash: "destTxHash",
|
|
4616
|
+
request_id: "requestId",
|
|
4617
|
+
provider_request_id: "providerRequestId",
|
|
4618
|
+
transaction_request: "transactionRequest",
|
|
4619
|
+
status_raw: "statusRaw",
|
|
4620
|
+
route_path: "routePath",
|
|
4621
|
+
route_status: "routeStatus",
|
|
4622
|
+
to_amount_wei: "toAmountWei",
|
|
4623
|
+
from_chain_block: "fromChainBlock",
|
|
4624
|
+
to_chain_block: "toChainBlock",
|
|
4625
|
+
from_chain_tx_url: "fromChainTxUrl",
|
|
4626
|
+
to_chain_tx_url: "toChainTxUrl",
|
|
4627
|
+
gas_status: "gasStatus",
|
|
4628
|
+
is_gmp_transaction: "isGMPTransaction",
|
|
4629
|
+
axelar_transaction_url: "axelarTransactionUrl",
|
|
4630
|
+
create_date: "createdDate",
|
|
4631
|
+
update_date: "updatedDate",
|
|
4632
|
+
time_spent_ms: "timeSpentMs"
|
|
4633
|
+
};
|
|
4595
4634
|
}
|
|
4596
4635
|
});
|
|
4597
4636
|
|
|
@@ -5140,7 +5179,7 @@ async function getBalances(chainRef, address, opts) {
|
|
|
5140
5179
|
if (cached) return cached;
|
|
5141
5180
|
}
|
|
5142
5181
|
const url = `${apiBase()}/v1/data/wallets/${encodeURIComponent(chainKey)}/${trimmedAddress}/balances`;
|
|
5143
|
-
const response = await
|
|
5182
|
+
const response = await rateLimitedFetch(url, {
|
|
5144
5183
|
method: "GET",
|
|
5145
5184
|
credentials: "omit",
|
|
5146
5185
|
headers: jsonHeaders()
|
|
@@ -7643,6 +7682,7 @@ var init_core = __esm({
|
|
|
7643
7682
|
init_store();
|
|
7644
7683
|
init_wallets();
|
|
7645
7684
|
init_routes();
|
|
7685
|
+
init_routes();
|
|
7646
7686
|
init_balances();
|
|
7647
7687
|
init_tx();
|
|
7648
7688
|
init_http();
|
|
@@ -8245,12 +8285,9 @@ function useTrustwareConfig() {
|
|
|
8245
8285
|
title: "Trustware SDK",
|
|
8246
8286
|
description: "Seamlessly bridge assets across chains with Trustware."
|
|
8247
8287
|
},
|
|
8248
|
-
|
|
8249
|
-
|
|
8250
|
-
|
|
8251
|
-
baseDelayMs: 1e3,
|
|
8252
|
-
approachingThreshold: 5
|
|
8253
|
-
},
|
|
8288
|
+
// Shared with the resolver rather than restated, so this placeholder
|
|
8289
|
+
// can't drift from the real defaults.
|
|
8290
|
+
retry: { ...DEFAULT_RETRY_CONFIG },
|
|
8254
8291
|
features: {
|
|
8255
8292
|
tokensPagination: true,
|
|
8256
8293
|
balanceStreaming: false,
|
|
@@ -8277,6 +8314,7 @@ var init_useTrustwareConfig = __esm({
|
|
|
8277
8314
|
"use strict";
|
|
8278
8315
|
"use client";
|
|
8279
8316
|
import_react10 = require("react");
|
|
8317
|
+
init_config();
|
|
8280
8318
|
init_store();
|
|
8281
8319
|
}
|
|
8282
8320
|
});
|
|
@@ -30830,7 +30868,7 @@ var init_src = __esm({
|
|
|
30830
30868
|
});
|
|
30831
30869
|
|
|
30832
30870
|
// src/smart-account/client.ts
|
|
30833
|
-
async function
|
|
30871
|
+
async function fetchOnceWithTimeout(url, init) {
|
|
30834
30872
|
const controller = new AbortController();
|
|
30835
30873
|
const timer = setTimeout(() => controller.abort(), FETCH_TIMEOUT_MS);
|
|
30836
30874
|
try {
|
|
@@ -30851,6 +30889,9 @@ async function fetchWithTimeout(url, init) {
|
|
|
30851
30889
|
clearTimeout(timer);
|
|
30852
30890
|
}
|
|
30853
30891
|
}
|
|
30892
|
+
async function fetchWithTimeout(url, init) {
|
|
30893
|
+
return withRateLimitRetry(() => fetchOnceWithTimeout(url, init));
|
|
30894
|
+
}
|
|
30854
30895
|
function extractRevertHex(err) {
|
|
30855
30896
|
if (typeof err.data === "string" && err.data.startsWith("0x"))
|
|
30856
30897
|
return err.data;
|
|
@@ -31343,7 +31384,7 @@ async function estimateRelayFeeInToken(valueWei, fromAmountWei, fromAmountUSD, c
|
|
|
31343
31384
|
tokenUnitsPerDollar = Number(fromAmountWei) / fromUSD;
|
|
31344
31385
|
} else if (fromToken && fromDecimals !== void 0) {
|
|
31345
31386
|
try {
|
|
31346
|
-
const resp = await
|
|
31387
|
+
const resp = await rateLimitedFetch(
|
|
31347
31388
|
`${apiBase()}/v1/price/token?chainId=${cid}&address=${fromToken}`,
|
|
31348
31389
|
{ headers: jsonHeaders() }
|
|
31349
31390
|
);
|
|
@@ -31359,9 +31400,10 @@ async function estimateRelayFeeInToken(valueWei, fromAmountWei, fromAmountUSD, c
|
|
|
31359
31400
|
return 0n;
|
|
31360
31401
|
}
|
|
31361
31402
|
try {
|
|
31362
|
-
const resp = await
|
|
31363
|
-
|
|
31364
|
-
|
|
31403
|
+
const resp = await rateLimitedFetch(
|
|
31404
|
+
`${apiBase()}/v1/price/native?chainId=${cid}`,
|
|
31405
|
+
{ headers: jsonHeaders() }
|
|
31406
|
+
);
|
|
31365
31407
|
if (!resp.ok) throw new Error(`native price HTTP ${resp.status}`);
|
|
31366
31408
|
const json = await resp.json();
|
|
31367
31409
|
const ethPriceUSD = parseFloat(json.data?.priceUSD ?? "0");
|
|
@@ -34106,9 +34148,14 @@ var init_useSwapExecution = __esm({
|
|
|
34106
34148
|
|
|
34107
34149
|
// src/core/forex.ts
|
|
34108
34150
|
async function fetchForexRates(base2 = "USD") {
|
|
34109
|
-
|
|
34110
|
-
|
|
34111
|
-
|
|
34151
|
+
let r;
|
|
34152
|
+
try {
|
|
34153
|
+
r = await rateLimitedFetch(`${apiBase()}/v1/forex?base=${base2}`, {
|
|
34154
|
+
headers: jsonHeaders()
|
|
34155
|
+
});
|
|
34156
|
+
} catch {
|
|
34157
|
+
return {};
|
|
34158
|
+
}
|
|
34112
34159
|
if (!r.ok) return {};
|
|
34113
34160
|
const j = await r.json();
|
|
34114
34161
|
const rates = j?.data?.rates ?? j?.rates ?? j?.data ?? {};
|
|
@@ -40268,6 +40315,7 @@ __export(index_exports, {
|
|
|
40268
40315
|
GTM_ID: () => GTM_ID,
|
|
40269
40316
|
IdentityStore: () => IdentityStore,
|
|
40270
40317
|
POPULAR_ORDER: () => POPULAR_ORDER,
|
|
40318
|
+
RATE_LIMIT_WAIT_BUDGET_MS: () => RATE_LIMIT_WAIT_BUDGET_MS,
|
|
40271
40319
|
RateLimitError: () => RateLimitError,
|
|
40272
40320
|
SDK_NAME: () => SDK_NAME,
|
|
40273
40321
|
SDK_VERSION: () => SDK_VERSION,
|
|
@@ -40277,6 +40325,7 @@ __export(index_exports, {
|
|
|
40277
40325
|
TrustwareWidget: () => TrustwareWidgetV2,
|
|
40278
40326
|
WALLETCONNECT_PROJECT_ID: () => WALLETCONNECT_PROJECT_ID,
|
|
40279
40327
|
WALLETS: () => WALLETS,
|
|
40328
|
+
assertValidPostHook: () => assertValidPostHook,
|
|
40280
40329
|
buildWalletIdentityAddress: () => buildWalletIdentityAddress,
|
|
40281
40330
|
connectDetectedWallet: () => connectDetectedWallet,
|
|
40282
40331
|
createWalletIdentity: () => createWalletIdentity,
|
|
@@ -40305,6 +40354,7 @@ var init_index = __esm({
|
|
|
40305
40354
|
"src/index.ts"() {
|
|
40306
40355
|
init_core2();
|
|
40307
40356
|
init_http();
|
|
40357
|
+
init_core2();
|
|
40308
40358
|
init_useWalletTokenState();
|
|
40309
40359
|
init_wallets();
|
|
40310
40360
|
init_widget();
|
|
@@ -40330,6 +40380,7 @@ init_index();
|
|
|
40330
40380
|
GTM_ID,
|
|
40331
40381
|
IdentityStore,
|
|
40332
40382
|
POPULAR_ORDER,
|
|
40383
|
+
RATE_LIMIT_WAIT_BUDGET_MS,
|
|
40333
40384
|
RateLimitError,
|
|
40334
40385
|
SDK_NAME,
|
|
40335
40386
|
SDK_VERSION,
|
|
@@ -40339,6 +40390,7 @@ init_index();
|
|
|
40339
40390
|
TrustwareWidget,
|
|
40340
40391
|
WALLETCONNECT_PROJECT_ID,
|
|
40341
40392
|
WALLETS,
|
|
40393
|
+
assertValidPostHook,
|
|
40342
40394
|
buildWalletIdentityAddress,
|
|
40343
40395
|
connectDetectedWallet,
|
|
40344
40396
|
createWalletIdentity,
|