@trustware/sdk-staging 1.1.9-staging.6 → 1.1.10-staging.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/LICENSE +5 -4
- package/README.md +32 -1
- package/THIRD_PARTY_NOTICES.md +118 -0
- package/dist/constants.cjs +1 -1
- package/dist/constants.mjs +1 -1
- package/dist/{core-BTPkApRH.d.cts → core-B7Ez-5-r.d.cts} +3 -2
- package/dist/{core-2oZuxC1J.d.ts → core-BPLiD1UG.d.ts} +3 -2
- package/dist/core.cjs +246 -48
- 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 +247 -48
- package/dist/core.mjs.map +1 -1
- package/dist/index.cjs +300 -76
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.mjs +325 -103
- package/dist/index.mjs.map +1 -1
- package/dist/{manager-BMO1O-cW.d.ts → manager-B6NNV-E_.d.ts} +129 -18
- package/dist/{manager-BZwbtOyf.d.cts → manager-BwjyFjjz.d.cts} +129 -18
- package/dist/{detect-B8xXLwHK.d.ts → metadata-BiTMMvlY.d.ts} +5 -2
- package/dist/{detect-C8xpZRrL.d.cts → metadata-HCflXcsF.d.cts} +5 -2
- package/dist/smart-account.cjs +117 -39
- package/dist/smart-account.cjs.map +1 -1
- package/dist/smart-account.d.cts +235 -222
- package/dist/smart-account.d.ts +235 -222
- package/dist/smart-account.mjs +117 -39
- package/dist/smart-account.mjs.map +1 -1
- package/dist/wallet.cjs +113 -36
- package/dist/wallet.cjs.map +1 -1
- package/dist/wallet.d.cts +4 -7
- package/dist/wallet.d.ts +4 -7
- package/dist/wallet.mjs +113 -36
- package/dist/wallet.mjs.map +1 -1
- package/dist/widget.cjs +239 -54
- package/dist/widget.cjs.map +1 -1
- package/dist/widget.mjs +267 -81
- package/dist/widget.mjs.map +1 -1
- package/package.json +3 -2
package/dist/index.cjs
CHANGED
|
@@ -71,6 +71,31 @@ var init_config = __esm({
|
|
|
71
71
|
}
|
|
72
72
|
});
|
|
73
73
|
|
|
74
|
+
// src/errors/TrustwareError.ts
|
|
75
|
+
var TrustwareError;
|
|
76
|
+
var init_TrustwareError = __esm({
|
|
77
|
+
"src/errors/TrustwareError.ts"() {
|
|
78
|
+
"use strict";
|
|
79
|
+
TrustwareError = class extends Error {
|
|
80
|
+
constructor(params) {
|
|
81
|
+
super(params.message);
|
|
82
|
+
this.name = "TrustwareError";
|
|
83
|
+
this.code = params.code;
|
|
84
|
+
this.userMessage = params.userMessage;
|
|
85
|
+
this.cause = params.cause;
|
|
86
|
+
}
|
|
87
|
+
toJSON() {
|
|
88
|
+
return {
|
|
89
|
+
name: this.name,
|
|
90
|
+
code: this.code,
|
|
91
|
+
message: this.message,
|
|
92
|
+
userMessage: this.userMessage
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
|
|
74
99
|
// src/config/merge.ts
|
|
75
100
|
function deepMerge(base2, patch) {
|
|
76
101
|
if (!patch) return { ...base2 };
|
|
@@ -91,46 +116,80 @@ function normalizeSlippage(v) {
|
|
|
91
116
|
if (n > 5) return 5;
|
|
92
117
|
return n;
|
|
93
118
|
}
|
|
119
|
+
function warnDeprecatedSwapModeFlag() {
|
|
120
|
+
if (hasWarnedDeprecatedSwapModeFlag) return;
|
|
121
|
+
hasWarnedDeprecatedSwapModeFlag = true;
|
|
122
|
+
console.warn(
|
|
123
|
+
'[Trustware SDK] `features.swapMode` is deprecated \u2014 use `mode: "swap"` on the top-level config instead.'
|
|
124
|
+
);
|
|
125
|
+
}
|
|
126
|
+
function resolveMode(input) {
|
|
127
|
+
if (input.mode === "swap") return "swap";
|
|
128
|
+
if (input.mode === "deposit") return "deposit";
|
|
129
|
+
if (input.features?.swapMode) {
|
|
130
|
+
warnDeprecatedSwapModeFlag();
|
|
131
|
+
return "swap";
|
|
132
|
+
}
|
|
133
|
+
return "deposit";
|
|
134
|
+
}
|
|
94
135
|
function resolveConfig(input) {
|
|
95
136
|
if (!input?.apiKey) {
|
|
96
|
-
throw new
|
|
137
|
+
throw new TrustwareError({
|
|
138
|
+
code: "INVALID_CONFIG" /* INVALID_CONFIG */,
|
|
139
|
+
message: "TrustwareConfig: 'apiKey' is required.",
|
|
140
|
+
userMessage: "Missing required API key configuration."
|
|
141
|
+
});
|
|
97
142
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
143
|
+
const mode = resolveMode(input);
|
|
144
|
+
if (mode === "deposit" && (!input.routes?.toChain || !input.routes?.toToken)) {
|
|
145
|
+
throw new TrustwareError({
|
|
146
|
+
code: "INVALID_CONFIG" /* INVALID_CONFIG */,
|
|
147
|
+
message: "TrustwareConfig: 'routes.toChain' and 'routes.toToken' are required in deposit mode.",
|
|
148
|
+
userMessage: "Missing required destination chain/token configuration."
|
|
149
|
+
});
|
|
102
150
|
}
|
|
103
|
-
const toChain = input.routes
|
|
104
|
-
if (input.routes
|
|
151
|
+
const toChain = input.routes?.toChain;
|
|
152
|
+
if (input.routes?.toAddress && toChain) {
|
|
105
153
|
const result = validateAddressForChain(input.routes.toAddress, toChain);
|
|
106
154
|
if (!result.isValid) {
|
|
107
155
|
console.error(`[Trustware SDK] Invalid toAddress: ${result.error}`);
|
|
108
|
-
throw new
|
|
156
|
+
throw new TrustwareError({
|
|
157
|
+
code: "INVALID_CONFIG" /* INVALID_CONFIG */,
|
|
158
|
+
message: `Invalid toAddress: ${result.error}`,
|
|
159
|
+
userMessage: "The configured destination address is invalid."
|
|
160
|
+
});
|
|
109
161
|
}
|
|
110
162
|
}
|
|
111
|
-
if (input.routes
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
163
|
+
if (input.routes?.fromAddress) {
|
|
164
|
+
const fromChain = input.routes.fromChain ?? toChain;
|
|
165
|
+
if (fromChain) {
|
|
166
|
+
const result = validateAddressForChain(
|
|
167
|
+
input.routes.fromAddress,
|
|
168
|
+
fromChain
|
|
169
|
+
);
|
|
170
|
+
if (!result.isValid) {
|
|
171
|
+
console.error(`[Trustware SDK] Invalid fromAddress: ${result.error}`);
|
|
172
|
+
throw new TrustwareError({
|
|
173
|
+
code: "INVALID_CONFIG" /* INVALID_CONFIG */,
|
|
174
|
+
message: `Invalid fromAddress: ${result.error}`,
|
|
175
|
+
userMessage: "The configured source address is invalid."
|
|
176
|
+
});
|
|
177
|
+
}
|
|
119
178
|
}
|
|
120
179
|
}
|
|
121
180
|
const autoDetectProvider = typeof input.autoDetectProvider === "boolean" ? input.autoDetectProvider : DEFAULT_AUTO_DETECT_PROVIDER;
|
|
122
181
|
const routes = {
|
|
123
|
-
toChain: input.routes
|
|
124
|
-
toToken: input.routes
|
|
125
|
-
fromToken: input.routes
|
|
126
|
-
fromAddress: input.routes
|
|
127
|
-
fromChain: input.routes
|
|
128
|
-
toAddress: input.routes
|
|
182
|
+
toChain: input.routes?.toChain ?? "",
|
|
183
|
+
toToken: input.routes?.toToken ?? "",
|
|
184
|
+
fromToken: input.routes?.fromToken,
|
|
185
|
+
fromAddress: input.routes?.fromAddress,
|
|
186
|
+
fromChain: input.routes?.fromChain,
|
|
187
|
+
toAddress: input.routes?.toAddress,
|
|
129
188
|
defaultSlippage: normalizeSlippage(
|
|
130
|
-
input.routes
|
|
189
|
+
input.routes?.defaultSlippage ?? DEFAULT_SLIPPAGE
|
|
131
190
|
),
|
|
132
191
|
options: {
|
|
133
|
-
...input.routes
|
|
192
|
+
...input.routes?.options
|
|
134
193
|
}
|
|
135
194
|
};
|
|
136
195
|
const theme = input.theme ?? "system";
|
|
@@ -149,13 +208,16 @@ function resolveConfig(input) {
|
|
|
149
208
|
tokensPagination: input.features?.tokensPagination ?? DEFAULT_FEATURE_FLAGS.tokensPagination,
|
|
150
209
|
balanceStreaming: input.features?.balanceStreaming ?? DEFAULT_FEATURE_FLAGS.balanceStreaming,
|
|
151
210
|
shouldAllowGA4: input.features?.shouldAllowGA4 ?? DEFAULT_FEATURE_FLAGS.shouldAllowGA4,
|
|
152
|
-
|
|
211
|
+
// Always mirrors the canonical `mode`, however the caller set it (new `mode` field
|
|
212
|
+
// or the deprecated `features.swapMode` flag).
|
|
213
|
+
swapMode: mode === "swap",
|
|
153
214
|
swapDefaultDestToken: input.features?.swapDefaultDestToken ?? DEFAULT_FEATURE_FLAGS.swapDefaultDestToken,
|
|
154
215
|
swapLockDestToken: input.features?.swapLockDestToken ?? DEFAULT_FEATURE_FLAGS.swapLockDestToken,
|
|
155
216
|
swapAllowedDestTokens: input.features?.swapAllowedDestTokens ?? DEFAULT_FEATURE_FLAGS.swapAllowedDestTokens
|
|
156
217
|
};
|
|
157
218
|
return {
|
|
158
219
|
apiKey: input.apiKey,
|
|
220
|
+
mode,
|
|
159
221
|
routes,
|
|
160
222
|
autoDetectProvider,
|
|
161
223
|
theme,
|
|
@@ -168,12 +230,15 @@ function resolveConfig(input) {
|
|
|
168
230
|
onEvent: input.onEvent
|
|
169
231
|
};
|
|
170
232
|
}
|
|
233
|
+
var hasWarnedDeprecatedSwapModeFlag;
|
|
171
234
|
var init_merge = __esm({
|
|
172
235
|
"src/config/merge.ts"() {
|
|
173
236
|
"use strict";
|
|
174
237
|
init_defaults();
|
|
175
238
|
init_config();
|
|
176
239
|
init_index();
|
|
240
|
+
init_TrustwareError();
|
|
241
|
+
hasWarnedDeprecatedSwapModeFlag = false;
|
|
177
242
|
}
|
|
178
243
|
});
|
|
179
244
|
|
|
@@ -430,7 +495,7 @@ var init_constants = __esm({
|
|
|
430
495
|
"src/constants.ts"() {
|
|
431
496
|
"use strict";
|
|
432
497
|
SDK_NAME = "@trustware/sdk";
|
|
433
|
-
SDK_VERSION = "1.1.
|
|
498
|
+
SDK_VERSION = "1.1.10-staging.0";
|
|
434
499
|
API_ROOT = "https://bv-staging-api.trustware.io";
|
|
435
500
|
GTM_ID = "GTM-TZDGNCXB";
|
|
436
501
|
API_PREFIX = "/api";
|
|
@@ -1071,12 +1136,33 @@ var init_deepLink = __esm({
|
|
|
1071
1136
|
});
|
|
1072
1137
|
|
|
1073
1138
|
// src/wallets/metadata.ts
|
|
1074
|
-
var WALLETS;
|
|
1139
|
+
var POPULAR_ORDER, WALLETS;
|
|
1075
1140
|
var init_metadata = __esm({
|
|
1076
1141
|
"src/wallets/metadata.ts"() {
|
|
1077
1142
|
"use strict";
|
|
1078
1143
|
init_deepLink();
|
|
1079
1144
|
init_constants();
|
|
1145
|
+
POPULAR_ORDER = [
|
|
1146
|
+
"rabby",
|
|
1147
|
+
"metamask",
|
|
1148
|
+
"walletconnect",
|
|
1149
|
+
"rainbow",
|
|
1150
|
+
"phantom-evm",
|
|
1151
|
+
"phantom-solana",
|
|
1152
|
+
"metamask-solana",
|
|
1153
|
+
"solflare",
|
|
1154
|
+
"okx",
|
|
1155
|
+
"brave",
|
|
1156
|
+
"coinbase",
|
|
1157
|
+
"zerion",
|
|
1158
|
+
"taho",
|
|
1159
|
+
"trust",
|
|
1160
|
+
"bitget",
|
|
1161
|
+
"backpack",
|
|
1162
|
+
"imtoken",
|
|
1163
|
+
"safe",
|
|
1164
|
+
"kucoin"
|
|
1165
|
+
];
|
|
1080
1166
|
WALLETS = [
|
|
1081
1167
|
{
|
|
1082
1168
|
id: "metamask",
|
|
@@ -2414,7 +2500,9 @@ var init_chains = __esm({
|
|
|
2414
2500
|
btc: "bitcoin",
|
|
2415
2501
|
bitcoin: "bitcoin",
|
|
2416
2502
|
sei: "cosmos",
|
|
2417
|
-
"pacific-1": "cosmos"
|
|
2503
|
+
"pacific-1": "cosmos",
|
|
2504
|
+
nibiru: "cosmos",
|
|
2505
|
+
"cataclysm-1": "cosmos"
|
|
2418
2506
|
};
|
|
2419
2507
|
}
|
|
2420
2508
|
});
|
|
@@ -2469,6 +2557,25 @@ function validateSeiAddress(address) {
|
|
|
2469
2557
|
error: "SEI addresses must be 0x-prefixed EVM or sei1 bech32 strings."
|
|
2470
2558
|
};
|
|
2471
2559
|
}
|
|
2560
|
+
function resolveCosmosBech32Prefix(chain) {
|
|
2561
|
+
const chainDef = typeof chain === "object" && chain ? chain : void 0;
|
|
2562
|
+
const identifier = chainDef?.networkIdentifier ?? chainDef?.chainId ?? chainDef?.id ?? (typeof chain === "string" ? chain : void 0);
|
|
2563
|
+
const normalized = String(identifier ?? "").trim().toLowerCase();
|
|
2564
|
+
return COSMOS_BECH32_PREFIX_BY_CHAIN_ID[normalized] ?? "sei";
|
|
2565
|
+
}
|
|
2566
|
+
function validateCosmosAddress(address, chain) {
|
|
2567
|
+
const trimmed = address.trim();
|
|
2568
|
+
const prefix = resolveCosmosBech32Prefix(chain);
|
|
2569
|
+
if (prefix === "sei" && (0, import_viem.isAddress)(trimmed)) {
|
|
2570
|
+
return { isValid: true };
|
|
2571
|
+
}
|
|
2572
|
+
const result = validateBech32LikeAddress(trimmed, prefix);
|
|
2573
|
+
if (result.isValid) return result;
|
|
2574
|
+
return {
|
|
2575
|
+
isValid: false,
|
|
2576
|
+
error: prefix === "sei" ? "SEI addresses must be 0x-prefixed EVM or sei1 bech32 strings." : `Address must be a valid ${prefix}1 bech32 string.`
|
|
2577
|
+
};
|
|
2578
|
+
}
|
|
2472
2579
|
function validateSolanaAddress(address) {
|
|
2473
2580
|
const trimmed = address.trim();
|
|
2474
2581
|
if (trimmed.startsWith("0x") || (0, import_viem.isAddress)(trimmed)) {
|
|
@@ -2516,15 +2623,12 @@ function validateAddressForChain(address, chain) {
|
|
|
2516
2623
|
case "bitcoin":
|
|
2517
2624
|
return validateBtcAddress(trimmed);
|
|
2518
2625
|
case "cosmos":
|
|
2519
|
-
|
|
2520
|
-
return validateSeiAddress(trimmed);
|
|
2521
|
-
}
|
|
2522
|
-
return validateBech32LikeAddress(trimmed, "sei");
|
|
2626
|
+
return validateCosmosAddress(trimmed, chainDef ?? chain);
|
|
2523
2627
|
default:
|
|
2524
2628
|
return { isValid: false, error: "Unsupported or unknown chain type." };
|
|
2525
2629
|
}
|
|
2526
2630
|
}
|
|
2527
|
-
function validateAddressForRouteChain(address, chainType) {
|
|
2631
|
+
function validateAddressForRouteChain(address, chainType, chainRef) {
|
|
2528
2632
|
switch (normalizeChainType(chainType)) {
|
|
2529
2633
|
case "evm":
|
|
2530
2634
|
return validateEvmAddress(address);
|
|
@@ -2533,7 +2637,7 @@ function validateAddressForRouteChain(address, chainType) {
|
|
|
2533
2637
|
case "bitcoin":
|
|
2534
2638
|
return validateBtcAddress(address);
|
|
2535
2639
|
case "cosmos":
|
|
2536
|
-
return
|
|
2640
|
+
return validateCosmosAddress(address, chainRef ?? chainType);
|
|
2537
2641
|
default:
|
|
2538
2642
|
return { isValid: false, error: "Unsupported chain type." };
|
|
2539
2643
|
}
|
|
@@ -2555,14 +2659,18 @@ function validateRouteAddresses(params) {
|
|
|
2555
2659
|
const normalizedDirection = params.direction?.trim().toLowerCase();
|
|
2556
2660
|
const isDepositFlow = normalizedDirection === "deposit" || (toType === "evm" || toType === "cosmos") && (fromType === "bitcoin" || fromType === "solana");
|
|
2557
2661
|
if (isDepositFlow) {
|
|
2558
|
-
const fromResult2 = validateAddressForRouteChain(
|
|
2662
|
+
const fromResult2 = validateAddressForRouteChain(
|
|
2663
|
+
fromAddress,
|
|
2664
|
+
fromType,
|
|
2665
|
+
params.fromChain
|
|
2666
|
+
);
|
|
2559
2667
|
if (!fromResult2.isValid) {
|
|
2560
2668
|
return {
|
|
2561
2669
|
isValid: false,
|
|
2562
2670
|
error: `From address: ${fromResult2.error ?? "Invalid address."}`
|
|
2563
2671
|
};
|
|
2564
2672
|
}
|
|
2565
|
-
const toResult2 = toType === "cosmos" ?
|
|
2673
|
+
const toResult2 = toType === "cosmos" ? validateCosmosAddress(toAddress, params.toChain) : validateEvmAddress(toAddress);
|
|
2566
2674
|
if (!toResult2.isValid) {
|
|
2567
2675
|
return {
|
|
2568
2676
|
isValid: false,
|
|
@@ -2587,14 +2695,22 @@ function validateRouteAddresses(params) {
|
|
|
2587
2695
|
}
|
|
2588
2696
|
return { isValid: true };
|
|
2589
2697
|
}
|
|
2590
|
-
const fromResult = validateAddressForRouteChain(
|
|
2698
|
+
const fromResult = validateAddressForRouteChain(
|
|
2699
|
+
fromAddress,
|
|
2700
|
+
fromType,
|
|
2701
|
+
params.fromChain
|
|
2702
|
+
);
|
|
2591
2703
|
if (!fromResult.isValid) {
|
|
2592
2704
|
return {
|
|
2593
2705
|
isValid: false,
|
|
2594
2706
|
error: `From address: ${fromResult.error ?? "Invalid address."}`
|
|
2595
2707
|
};
|
|
2596
2708
|
}
|
|
2597
|
-
const toResult = validateAddressForRouteChain(
|
|
2709
|
+
const toResult = validateAddressForRouteChain(
|
|
2710
|
+
toAddress,
|
|
2711
|
+
toType,
|
|
2712
|
+
params.toChain
|
|
2713
|
+
);
|
|
2598
2714
|
if (!toResult.isValid) {
|
|
2599
2715
|
return {
|
|
2600
2716
|
isValid: false,
|
|
@@ -2603,7 +2719,7 @@ function validateRouteAddresses(params) {
|
|
|
2603
2719
|
}
|
|
2604
2720
|
return { isValid: true };
|
|
2605
2721
|
}
|
|
2606
|
-
var import_viem, BECH32_CHARSET;
|
|
2722
|
+
var import_viem, BECH32_CHARSET, COSMOS_BECH32_PREFIX_BY_CHAIN_ID;
|
|
2607
2723
|
var init_address = __esm({
|
|
2608
2724
|
"src/validation/address.ts"() {
|
|
2609
2725
|
"use strict";
|
|
@@ -2611,6 +2727,12 @@ var init_address = __esm({
|
|
|
2611
2727
|
init_index_node4();
|
|
2612
2728
|
init_chains();
|
|
2613
2729
|
BECH32_CHARSET = /^[023456789acdefghjklmnpqrstuvwxyz]+$/i;
|
|
2730
|
+
COSMOS_BECH32_PREFIX_BY_CHAIN_ID = {
|
|
2731
|
+
"pacific-1": "sei",
|
|
2732
|
+
sei: "sei",
|
|
2733
|
+
"cataclysm-1": "nibi",
|
|
2734
|
+
nibiru: "nibi"
|
|
2735
|
+
};
|
|
2614
2736
|
}
|
|
2615
2737
|
});
|
|
2616
2738
|
|
|
@@ -4277,6 +4399,27 @@ var init_wallets = __esm({
|
|
|
4277
4399
|
});
|
|
4278
4400
|
|
|
4279
4401
|
// src/core/routes.ts
|
|
4402
|
+
function assertValidPostHook(hooks) {
|
|
4403
|
+
const postHook = hooks?.postHook;
|
|
4404
|
+
if (!postHook) return;
|
|
4405
|
+
if (!postHook.target?.trim()) {
|
|
4406
|
+
throw new Error("hooks.postHook.target is required.");
|
|
4407
|
+
}
|
|
4408
|
+
if (!postHook.callData?.trim()) {
|
|
4409
|
+
throw new Error("hooks.postHook.callData is required.");
|
|
4410
|
+
}
|
|
4411
|
+
if (postHook.fullAmount) {
|
|
4412
|
+
if (postHook.amountInputPos === void 0) {
|
|
4413
|
+
throw new Error(
|
|
4414
|
+
"hooks.postHook.amountInputPos is required when fullAmount is true."
|
|
4415
|
+
);
|
|
4416
|
+
}
|
|
4417
|
+
} else if (!postHook.fundAmount?.trim()) {
|
|
4418
|
+
throw new Error(
|
|
4419
|
+
"hooks.postHook.fundAmount is required unless fullAmount is set."
|
|
4420
|
+
);
|
|
4421
|
+
}
|
|
4422
|
+
}
|
|
4280
4423
|
function isEvmTxRequest(txReq) {
|
|
4281
4424
|
return Boolean(txReq?.data && (txReq.to || txReq.target));
|
|
4282
4425
|
}
|
|
@@ -4295,6 +4438,7 @@ async function buildRoute(body, signal) {
|
|
|
4295
4438
|
if (!addressValidation.isValid) {
|
|
4296
4439
|
throw new Error(addressValidation.error || "Invalid route addresses.");
|
|
4297
4440
|
}
|
|
4441
|
+
assertValidPostHook(body.hooks);
|
|
4298
4442
|
const cfg = TrustwareConfigStore.get();
|
|
4299
4443
|
const url = `${apiBase()}/v1/routes/route`;
|
|
4300
4444
|
const payload = {
|
|
@@ -4333,6 +4477,7 @@ async function buildRoute(body, signal) {
|
|
|
4333
4477
|
return { intentId, txReq, actions, finalExchangeRate, route, sponsorship };
|
|
4334
4478
|
}
|
|
4335
4479
|
async function buildDepositAddress(body, signal) {
|
|
4480
|
+
assertValidPostHook(body.hooks);
|
|
4336
4481
|
const cfg = TrustwareConfigStore.get();
|
|
4337
4482
|
const url = `${apiBase()}/v1/routes/deposit-address`;
|
|
4338
4483
|
const payload = {
|
|
@@ -4374,7 +4519,7 @@ async function buildDepositAddress(body, signal) {
|
|
|
4374
4519
|
route
|
|
4375
4520
|
};
|
|
4376
4521
|
}
|
|
4377
|
-
async function submitReceipt(intentId, txHash, sponsorshipRequestId) {
|
|
4522
|
+
async function submitReceipt(intentId, txHash, sponsorshipRequestId, eoaAddress) {
|
|
4378
4523
|
const r = await rateLimitedFetch(
|
|
4379
4524
|
`${apiBase()}/v1/route-intent/${intentId}/receipt`,
|
|
4380
4525
|
{
|
|
@@ -4382,7 +4527,8 @@ async function submitReceipt(intentId, txHash, sponsorshipRequestId) {
|
|
|
4382
4527
|
headers: jsonHeaders({ "Idempotency-Key": txHash }),
|
|
4383
4528
|
body: JSON.stringify({
|
|
4384
4529
|
txHash,
|
|
4385
|
-
...sponsorshipRequestId ? { sponsorshipRequestId } : {}
|
|
4530
|
+
...sponsorshipRequestId ? { sponsorshipRequestId } : {},
|
|
4531
|
+
...eoaAddress ? { eoaAddress } : {}
|
|
4386
4532
|
})
|
|
4387
4533
|
}
|
|
4388
4534
|
);
|
|
@@ -5084,6 +5230,87 @@ function backendChainId(chain, fallback) {
|
|
|
5084
5230
|
const preferred = chain?.networkIdentifier ?? chain?.chainId ?? chain?.id;
|
|
5085
5231
|
return String(preferred ?? fallback ?? "");
|
|
5086
5232
|
}
|
|
5233
|
+
function sleep2(ms) {
|
|
5234
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
5235
|
+
}
|
|
5236
|
+
async function sendEvmTx(w, tx) {
|
|
5237
|
+
if (w.type === "eip1193") {
|
|
5238
|
+
const from = await w.getAddress();
|
|
5239
|
+
const params = {
|
|
5240
|
+
from,
|
|
5241
|
+
to: tx.to,
|
|
5242
|
+
data: tx.data,
|
|
5243
|
+
value: tx.value ? `0x${tx.value.toString(16)}` : "0x0"
|
|
5244
|
+
};
|
|
5245
|
+
if (tx.chainId !== void 0) {
|
|
5246
|
+
params.chainId = `0x${tx.chainId.toString(16)}`;
|
|
5247
|
+
}
|
|
5248
|
+
const hash = await w.request({
|
|
5249
|
+
method: "eth_sendTransaction",
|
|
5250
|
+
params: [params]
|
|
5251
|
+
});
|
|
5252
|
+
return hash;
|
|
5253
|
+
}
|
|
5254
|
+
const response = await w.sendTransaction({
|
|
5255
|
+
to: tx.to,
|
|
5256
|
+
data: tx.data,
|
|
5257
|
+
value: tx.value,
|
|
5258
|
+
chainId: tx.chainId
|
|
5259
|
+
});
|
|
5260
|
+
return response.hash;
|
|
5261
|
+
}
|
|
5262
|
+
async function waitForTxConfirmation(chainId, txHash) {
|
|
5263
|
+
const timeoutMs = 12e4;
|
|
5264
|
+
const intervalMs = 2e3;
|
|
5265
|
+
const started = Date.now();
|
|
5266
|
+
while (Date.now() - started < timeoutMs) {
|
|
5267
|
+
const status = await getEVMTxStatus({ chainId, txHash });
|
|
5268
|
+
if (status.status === "success") return;
|
|
5269
|
+
if (status.status === "reverted") {
|
|
5270
|
+
throw new Error("Approval transaction reverted");
|
|
5271
|
+
}
|
|
5272
|
+
await sleep2(intervalMs);
|
|
5273
|
+
}
|
|
5274
|
+
throw new Error("Timed out waiting for approval confirmation");
|
|
5275
|
+
}
|
|
5276
|
+
async function ensureApprovals(w, approvals, fallbackChainId) {
|
|
5277
|
+
if (!approvals || approvals.length === 0) return;
|
|
5278
|
+
const owner = await w.getAddress();
|
|
5279
|
+
for (const approval of approvals) {
|
|
5280
|
+
const spender = approval.spender;
|
|
5281
|
+
const tokenAddress = approval.tokenAddress;
|
|
5282
|
+
const amount = approval.amount;
|
|
5283
|
+
if (!spender || !tokenAddress || !amount) continue;
|
|
5284
|
+
const chainId = approval.chainId || String(fallbackChainId ?? "");
|
|
5285
|
+
if (!chainId) continue;
|
|
5286
|
+
const amountWei = BigInt(amount);
|
|
5287
|
+
if (amountWei === 0n) continue;
|
|
5288
|
+
let currentAllowance = 0n;
|
|
5289
|
+
try {
|
|
5290
|
+
const { allowance } = await getEVMAllowance({
|
|
5291
|
+
chainId,
|
|
5292
|
+
tokenAddress,
|
|
5293
|
+
ownerAddress: owner,
|
|
5294
|
+
spenderAddress: spender
|
|
5295
|
+
});
|
|
5296
|
+
currentAllowance = BigInt(allowance || "0");
|
|
5297
|
+
} catch {
|
|
5298
|
+
}
|
|
5299
|
+
if (currentAllowance >= amountWei) continue;
|
|
5300
|
+
const data = (0, import_viem2.encodeFunctionData)({
|
|
5301
|
+
abi: erc20ApproveAbi,
|
|
5302
|
+
functionName: "approve",
|
|
5303
|
+
args: [spender, amountWei]
|
|
5304
|
+
});
|
|
5305
|
+
const hash = await sendEvmTx(w, {
|
|
5306
|
+
to: tokenAddress,
|
|
5307
|
+
data,
|
|
5308
|
+
value: 0n,
|
|
5309
|
+
chainId: Number.isFinite(Number(chainId)) ? Number(chainId) : void 0
|
|
5310
|
+
});
|
|
5311
|
+
await waitForTxConfirmation(chainId, hash);
|
|
5312
|
+
}
|
|
5313
|
+
}
|
|
5087
5314
|
function isUserRejected(e2) {
|
|
5088
5315
|
const code = e2?.code ?? e2?.data?.code;
|
|
5089
5316
|
if (code === 4001) return true;
|
|
@@ -5117,6 +5344,13 @@ async function sendRouteTransaction(b, fallbackChainId) {
|
|
|
5117
5344
|
}
|
|
5118
5345
|
}
|
|
5119
5346
|
}
|
|
5347
|
+
if (!validatedSponsorship) {
|
|
5348
|
+
await ensureApprovals(
|
|
5349
|
+
w,
|
|
5350
|
+
b.route?.execution?.approvals,
|
|
5351
|
+
Number.isFinite(target) ? target : void 0
|
|
5352
|
+
);
|
|
5353
|
+
}
|
|
5120
5354
|
if (w.type === "eip1193") {
|
|
5121
5355
|
const from = await w.getAddress();
|
|
5122
5356
|
const hexValue = value ? `0x${value.toString(16)}` : "0x0";
|
|
@@ -5213,13 +5447,17 @@ async function runTopUp(params) {
|
|
|
5213
5447
|
}
|
|
5214
5448
|
}
|
|
5215
5449
|
}
|
|
5216
|
-
var import_viem2;
|
|
5450
|
+
var import_viem2, erc20ApproveAbi;
|
|
5217
5451
|
var init_tx = __esm({
|
|
5218
5452
|
"src/core/tx.ts"() {
|
|
5219
5453
|
"use strict";
|
|
5220
5454
|
init_wallets();
|
|
5221
5455
|
init_routes();
|
|
5456
|
+
init_sdkRpc();
|
|
5222
5457
|
import_viem2 = require("viem");
|
|
5458
|
+
erc20ApproveAbi = (0, import_viem2.parseAbi)([
|
|
5459
|
+
"function approve(address spender, uint256 amount) returns (bool)"
|
|
5460
|
+
]);
|
|
5223
5461
|
}
|
|
5224
5462
|
});
|
|
5225
5463
|
|
|
@@ -5341,7 +5579,9 @@ var init_chainHelpers = __esm({
|
|
|
5341
5579
|
btc: "bitcoin",
|
|
5342
5580
|
bitcoin: "bitcoin",
|
|
5343
5581
|
sei: "cosmos",
|
|
5344
|
-
"pacific-1": "cosmos"
|
|
5582
|
+
"pacific-1": "cosmos",
|
|
5583
|
+
nibiru: "cosmos",
|
|
5584
|
+
"cataclysm-1": "cosmos"
|
|
5345
5585
|
};
|
|
5346
5586
|
SEI_EVM_CHAIN_ID = "1329";
|
|
5347
5587
|
SEI_COSMOS_CHAIN_ID = "pacific-1";
|
|
@@ -5556,7 +5796,8 @@ function filterSupportedChains(chains) {
|
|
|
5556
5796
|
}
|
|
5557
5797
|
if (chainType === "cosmos") {
|
|
5558
5798
|
const seiKey = canonicalSeiChainKey(chain.chainId ?? chain.id);
|
|
5559
|
-
|
|
5799
|
+
const isNibiru = normalizeChainKey2(chain.chainId ?? chain.id) === NIBIRU_COSMOS_CHAIN_ID;
|
|
5800
|
+
if (seiKey !== "sei" && !isNibiru) {
|
|
5560
5801
|
return false;
|
|
5561
5802
|
}
|
|
5562
5803
|
}
|
|
@@ -5656,7 +5897,7 @@ function useChains() {
|
|
|
5656
5897
|
error
|
|
5657
5898
|
};
|
|
5658
5899
|
}
|
|
5659
|
-
var import_react3, POPULAR_CHAINS_BY_TVL, POPULAR_LIMIT;
|
|
5900
|
+
var import_react3, POPULAR_CHAINS_BY_TVL, POPULAR_LIMIT, NIBIRU_COSMOS_CHAIN_ID;
|
|
5660
5901
|
var init_useChains = __esm({
|
|
5661
5902
|
"src/core/useChains.ts"() {
|
|
5662
5903
|
"use strict";
|
|
@@ -5667,6 +5908,7 @@ var init_useChains = __esm({
|
|
|
5667
5908
|
init_popularChains();
|
|
5668
5909
|
POPULAR_CHAINS_BY_TVL = popularChains_default.byTvl;
|
|
5669
5910
|
POPULAR_LIMIT = popularChains_default.popularLimit;
|
|
5911
|
+
NIBIRU_COSMOS_CHAIN_ID = "cataclysm-1";
|
|
5670
5912
|
}
|
|
5671
5913
|
});
|
|
5672
5914
|
|
|
@@ -7347,31 +7589,6 @@ var init_useTokens = __esm({
|
|
|
7347
7589
|
}
|
|
7348
7590
|
});
|
|
7349
7591
|
|
|
7350
|
-
// src/errors/TrustwareError.ts
|
|
7351
|
-
var TrustwareError;
|
|
7352
|
-
var init_TrustwareError = __esm({
|
|
7353
|
-
"src/errors/TrustwareError.ts"() {
|
|
7354
|
-
"use strict";
|
|
7355
|
-
TrustwareError = class extends Error {
|
|
7356
|
-
constructor(params) {
|
|
7357
|
-
super(params.message);
|
|
7358
|
-
this.name = "TrustwareError";
|
|
7359
|
-
this.code = params.code;
|
|
7360
|
-
this.userMessage = params.userMessage;
|
|
7361
|
-
this.cause = params.cause;
|
|
7362
|
-
}
|
|
7363
|
-
toJSON() {
|
|
7364
|
-
return {
|
|
7365
|
-
name: this.name,
|
|
7366
|
-
code: this.code,
|
|
7367
|
-
message: this.message,
|
|
7368
|
-
userMessage: this.userMessage
|
|
7369
|
-
};
|
|
7370
|
-
}
|
|
7371
|
-
};
|
|
7372
|
-
}
|
|
7373
|
-
});
|
|
7374
|
-
|
|
7375
7592
|
// src/core/index.ts
|
|
7376
7593
|
var _lastValidatedKey, Trustware;
|
|
7377
7594
|
var init_core = __esm({
|
|
@@ -7967,6 +8184,7 @@ function useTrustwareConfig() {
|
|
|
7967
8184
|
} catch {
|
|
7968
8185
|
return {
|
|
7969
8186
|
apiKey: "",
|
|
8187
|
+
mode: "deposit",
|
|
7970
8188
|
routes: {
|
|
7971
8189
|
toChain: "",
|
|
7972
8190
|
toToken: "",
|
|
@@ -31525,7 +31743,7 @@ async function sendRouteAsUserOperation(params) {
|
|
|
31525
31743
|
);
|
|
31526
31744
|
}
|
|
31527
31745
|
console.debug("[send] UserOp included", { userOpHash, txHash });
|
|
31528
|
-
await submitReceipt(intentId, txHash, getSponsorshipRequestId());
|
|
31746
|
+
await submitReceipt(intentId, txHash, getSponsorshipRequestId(), eoaAddress);
|
|
31529
31747
|
return { userOpHash, txHash, intentId };
|
|
31530
31748
|
}
|
|
31531
31749
|
var NATIVE_ADDRS;
|
|
@@ -31576,7 +31794,7 @@ function normalizeTokenAddressForCompare(chain, addr) {
|
|
|
31576
31794
|
if (chainType === "solana") return value;
|
|
31577
31795
|
return value.toLowerCase();
|
|
31578
31796
|
}
|
|
31579
|
-
function
|
|
31797
|
+
function sleep3(ms) {
|
|
31580
31798
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
31581
31799
|
}
|
|
31582
31800
|
function useTransactionActionModel({
|
|
@@ -31694,7 +31912,7 @@ function useTransactionActionModel({
|
|
|
31694
31912
|
if (status.status === "reverted") {
|
|
31695
31913
|
throw new Error("Approval transaction reverted");
|
|
31696
31914
|
}
|
|
31697
|
-
await
|
|
31915
|
+
await sleep3(intervalMs);
|
|
31698
31916
|
}
|
|
31699
31917
|
throw new Error("Timed out waiting for approval confirmation");
|
|
31700
31918
|
},
|
|
@@ -33359,7 +33577,7 @@ function normalizeTx(raw) {
|
|
|
33359
33577
|
toChainTxUrl: r.toChainTxUrl || r.to_chain_tx_url || void 0
|
|
33360
33578
|
};
|
|
33361
33579
|
}
|
|
33362
|
-
function
|
|
33580
|
+
function sleep4(ms) {
|
|
33363
33581
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
33364
33582
|
}
|
|
33365
33583
|
function isUserRejection(err) {
|
|
@@ -33377,7 +33595,7 @@ async function waitForApprovalConfirmation(chainId, txHash) {
|
|
|
33377
33595
|
if (status.status === "success") return;
|
|
33378
33596
|
if (status.status === "reverted")
|
|
33379
33597
|
throw new Error("Approval transaction reverted");
|
|
33380
|
-
await
|
|
33598
|
+
await sleep4(2e3);
|
|
33381
33599
|
}
|
|
33382
33600
|
throw new Error("Timed out waiting for approval confirmation");
|
|
33383
33601
|
}
|
|
@@ -39805,7 +40023,7 @@ var init_TrustwareWidgetV2 = __esm({
|
|
|
39805
40023
|
if (!isOpen) {
|
|
39806
40024
|
return null;
|
|
39807
40025
|
}
|
|
39808
|
-
if (config.
|
|
40026
|
+
if (config.mode === "swap") {
|
|
39809
40027
|
return /* @__PURE__ */ (0, import_jsx_runtime60.jsx)(SwapMode, { theme, style });
|
|
39810
40028
|
}
|
|
39811
40029
|
return /* @__PURE__ */ (0, import_jsx_runtime60.jsx)(DepositProvider, { initialStep: effectiveInitialStep, children: /* @__PURE__ */ (0, import_jsx_runtime60.jsx)(
|
|
@@ -39896,6 +40114,7 @@ __export(index_exports, {
|
|
|
39896
40114
|
DEFAULT_SLIPPAGE: () => DEFAULT_SLIPPAGE2,
|
|
39897
40115
|
GTM_ID: () => GTM_ID,
|
|
39898
40116
|
IdentityStore: () => IdentityStore,
|
|
40117
|
+
POPULAR_ORDER: () => POPULAR_ORDER,
|
|
39899
40118
|
RateLimitError: () => RateLimitError,
|
|
39900
40119
|
SDK_NAME: () => SDK_NAME,
|
|
39901
40120
|
SDK_VERSION: () => SDK_VERSION,
|
|
@@ -39904,6 +40123,7 @@ __export(index_exports, {
|
|
|
39904
40123
|
TrustwareProvider: () => TrustwareProvider,
|
|
39905
40124
|
TrustwareWidget: () => TrustwareWidgetV2,
|
|
39906
40125
|
WALLETCONNECT_PROJECT_ID: () => WALLETCONNECT_PROJECT_ID,
|
|
40126
|
+
WALLETS: () => WALLETS,
|
|
39907
40127
|
buildWalletIdentityAddress: () => buildWalletIdentityAddress,
|
|
39908
40128
|
connectDetectedWallet: () => connectDetectedWallet,
|
|
39909
40129
|
createWalletIdentity: () => createWalletIdentity,
|
|
@@ -39920,6 +40140,7 @@ __export(index_exports, {
|
|
|
39920
40140
|
useWireDetectionIntoManager: () => useWireDetectionIntoManager,
|
|
39921
40141
|
validateAddressForChain: () => validateAddressForChain,
|
|
39922
40142
|
validateBtcAddress: () => validateBtcAddress,
|
|
40143
|
+
validateCosmosAddress: () => validateCosmosAddress,
|
|
39923
40144
|
validateEvmAddress: () => validateEvmAddress,
|
|
39924
40145
|
validateRouteAddresses: () => validateRouteAddresses,
|
|
39925
40146
|
validateSeiAddress: () => validateSeiAddress,
|
|
@@ -39955,6 +40176,7 @@ init_index();
|
|
|
39955
40176
|
DEFAULT_SLIPPAGE,
|
|
39956
40177
|
GTM_ID,
|
|
39957
40178
|
IdentityStore,
|
|
40179
|
+
POPULAR_ORDER,
|
|
39958
40180
|
RateLimitError,
|
|
39959
40181
|
SDK_NAME,
|
|
39960
40182
|
SDK_VERSION,
|
|
@@ -39963,6 +40185,7 @@ init_index();
|
|
|
39963
40185
|
TrustwareProvider,
|
|
39964
40186
|
TrustwareWidget,
|
|
39965
40187
|
WALLETCONNECT_PROJECT_ID,
|
|
40188
|
+
WALLETS,
|
|
39966
40189
|
buildWalletIdentityAddress,
|
|
39967
40190
|
connectDetectedWallet,
|
|
39968
40191
|
createWalletIdentity,
|
|
@@ -39979,6 +40202,7 @@ init_index();
|
|
|
39979
40202
|
useWireDetectionIntoManager,
|
|
39980
40203
|
validateAddressForChain,
|
|
39981
40204
|
validateBtcAddress,
|
|
40205
|
+
validateCosmosAddress,
|
|
39982
40206
|
validateEvmAddress,
|
|
39983
40207
|
validateRouteAddresses,
|
|
39984
40208
|
validateSeiAddress,
|