@trustware/sdk-staging 1.1.10-staging.0 → 1.1.11-staging.1
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/constants.cjs +1 -1
- package/dist/constants.mjs +1 -1
- package/dist/{core-BPLiD1UG.d.ts → core-BgYLe9Q7.d.ts} +15 -2
- package/dist/{core-B7Ez-5-r.d.cts → core-fLSt4qD2.d.cts} +15 -2
- package/dist/core.cjs +281 -237
- 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 +281 -237
- package/dist/core.mjs.map +1 -1
- package/dist/index.cjs +269 -116
- 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 +269 -115
- package/dist/index.mjs.map +1 -1
- package/dist/{manager-B6NNV-E_.d.ts → manager-BY3NHAks.d.ts} +50 -2
- package/dist/{manager-BwjyFjjz.d.cts → manager-DT8enQbE.d.cts} +50 -2
- package/dist/{metadata-BiTMMvlY.d.ts → metadata-BPvFYMlc.d.ts} +1 -1
- package/dist/{metadata-HCflXcsF.d.cts → metadata-DyxUcKHk.d.cts} +1 -1
- package/dist/smart-account.cjs +1 -1
- package/dist/smart-account.cjs.map +1 -1
- package/dist/smart-account.d.cts +12 -12
- package/dist/smart-account.d.ts +12 -12
- package/dist/smart-account.mjs +1 -1
- package/dist/smart-account.mjs.map +1 -1
- package/dist/wallet.cjs +15 -1
- 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 +15 -1
- package/dist/wallet.mjs.map +1 -1
- package/dist/widget.cjs +269 -116
- package/dist/widget.cjs.map +1 -1
- package/dist/widget.mjs +269 -115
- package/dist/widget.mjs.map +1 -1
- package/package.json +1 -1
package/dist/constants.cjs
CHANGED
|
@@ -30,7 +30,7 @@ __export(constants_exports, {
|
|
|
30
30
|
});
|
|
31
31
|
module.exports = __toCommonJS(constants_exports);
|
|
32
32
|
var SDK_NAME = "@trustware/sdk";
|
|
33
|
-
var SDK_VERSION = "1.1.
|
|
33
|
+
var SDK_VERSION = "1.1.11-staging.1";
|
|
34
34
|
var API_ROOT = "https://bv-staging-api.trustware.io";
|
|
35
35
|
var GTM_ID = "GTM-TZDGNCXB";
|
|
36
36
|
var API_PREFIX = "/api";
|
package/dist/constants.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as BuildRouteResult, k as Transaction, T as TrustwareConfigOptions, i as WalletInterFaceAPI, z as ResolvedTrustwareConfig, V as TrustwareTheme, a1 as WalletIdentity, w as walletManager, Y as WalletAddressResolution, a8 as buildRoute, a9 as buildDepositAddress, aa as submitReceipt, ab as
|
|
1
|
+
import { n as BuildRouteResult, k as Transaction, T as TrustwareConfigOptions, i as WalletInterFaceAPI, z as ResolvedTrustwareConfig, V as TrustwareTheme, a1 as WalletIdentity, w as walletManager, Y as WalletAddressResolution, a8 as buildRoute, a9 as buildDepositAddress, aa as submitReceipt, ab as submitStepReceipt, ac as getStatus, ad as pollStatus } from './manager-BY3NHAks.js';
|
|
2
2
|
import { C as ChainDef, c as ChainType, G as GetBalancesOptions, B as BalanceRow, a as BalanceStreamOptions, W as WalletAddressBalanceWrapper } from './blockchain-BxAFzp0s.js';
|
|
3
3
|
import { T as Token } from './types-BJY9r-mz.js';
|
|
4
4
|
|
|
@@ -26,7 +26,19 @@ declare function getBalances(chainRef: string | number, address: string, opts?:
|
|
|
26
26
|
declare function getBalancesByAddress(address: string, opts?: BalanceStreamOptions): Promise<WalletAddressBalanceWrapper[]>;
|
|
27
27
|
declare function getBalancesByAddressStream(address: string, opts?: BalanceStreamOptions): AsyncGenerator<WalletAddressBalanceWrapper[], void, void>;
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
type SendRouteTransactionOptions = {
|
|
30
|
+
/**
|
|
31
|
+
* The caller has already run the plan's approval flow (checked allowances,
|
|
32
|
+
* sent any approves, waited for confirmation). Skips the internal
|
|
33
|
+
* ensureApprovals pass entirely — re-reading an allowance immediately
|
|
34
|
+
* after its approve confirms can return pre-block state from a different
|
|
35
|
+
* RPC node, which made the SDK prompt for the same approval twice
|
|
36
|
+
* (BVT-330). Exactly one path must own the approval decision per
|
|
37
|
+
* execution; this flag is how a caller claims that ownership.
|
|
38
|
+
*/
|
|
39
|
+
approvalsEnsured?: boolean;
|
|
40
|
+
};
|
|
41
|
+
declare function sendRouteTransaction(b: BuildRouteResult, fallbackChainId?: number | string, options?: SendRouteTransactionOptions): Promise<string>;
|
|
30
42
|
declare function runTopUp(params: {
|
|
31
43
|
fromChain?: string;
|
|
32
44
|
toChain?: string;
|
|
@@ -127,6 +139,7 @@ declare const Trustware: {
|
|
|
127
139
|
buildRoute: typeof buildRoute;
|
|
128
140
|
buildDepositAddress: typeof buildDepositAddress;
|
|
129
141
|
submitReceipt: typeof submitReceipt;
|
|
142
|
+
submitStepReceipt: typeof submitStepReceipt;
|
|
130
143
|
getStatus: typeof getStatus;
|
|
131
144
|
pollStatus: typeof pollStatus;
|
|
132
145
|
getBalances: typeof getBalances;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { n as BuildRouteResult, k as Transaction, T as TrustwareConfigOptions, i as WalletInterFaceAPI, z as ResolvedTrustwareConfig, V as TrustwareTheme, a1 as WalletIdentity, w as walletManager, Y as WalletAddressResolution, a8 as buildRoute, a9 as buildDepositAddress, aa as submitReceipt, ab as
|
|
1
|
+
import { n as BuildRouteResult, k as Transaction, T as TrustwareConfigOptions, i as WalletInterFaceAPI, z as ResolvedTrustwareConfig, V as TrustwareTheme, a1 as WalletIdentity, w as walletManager, Y as WalletAddressResolution, a8 as buildRoute, a9 as buildDepositAddress, aa as submitReceipt, ab as submitStepReceipt, ac as getStatus, ad as pollStatus } from './manager-DT8enQbE.cjs';
|
|
2
2
|
import { C as ChainDef, c as ChainType, G as GetBalancesOptions, B as BalanceRow, a as BalanceStreamOptions, W as WalletAddressBalanceWrapper } from './blockchain-BxAFzp0s.cjs';
|
|
3
3
|
import { T as Token } from './types-DX3HtFcn.cjs';
|
|
4
4
|
|
|
@@ -26,7 +26,19 @@ declare function getBalances(chainRef: string | number, address: string, opts?:
|
|
|
26
26
|
declare function getBalancesByAddress(address: string, opts?: BalanceStreamOptions): Promise<WalletAddressBalanceWrapper[]>;
|
|
27
27
|
declare function getBalancesByAddressStream(address: string, opts?: BalanceStreamOptions): AsyncGenerator<WalletAddressBalanceWrapper[], void, void>;
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
type SendRouteTransactionOptions = {
|
|
30
|
+
/**
|
|
31
|
+
* The caller has already run the plan's approval flow (checked allowances,
|
|
32
|
+
* sent any approves, waited for confirmation). Skips the internal
|
|
33
|
+
* ensureApprovals pass entirely — re-reading an allowance immediately
|
|
34
|
+
* after its approve confirms can return pre-block state from a different
|
|
35
|
+
* RPC node, which made the SDK prompt for the same approval twice
|
|
36
|
+
* (BVT-330). Exactly one path must own the approval decision per
|
|
37
|
+
* execution; this flag is how a caller claims that ownership.
|
|
38
|
+
*/
|
|
39
|
+
approvalsEnsured?: boolean;
|
|
40
|
+
};
|
|
41
|
+
declare function sendRouteTransaction(b: BuildRouteResult, fallbackChainId?: number | string, options?: SendRouteTransactionOptions): Promise<string>;
|
|
30
42
|
declare function runTopUp(params: {
|
|
31
43
|
fromChain?: string;
|
|
32
44
|
toChain?: string;
|
|
@@ -127,6 +139,7 @@ declare const Trustware: {
|
|
|
127
139
|
buildRoute: typeof buildRoute;
|
|
128
140
|
buildDepositAddress: typeof buildDepositAddress;
|
|
129
141
|
submitReceipt: typeof submitReceipt;
|
|
142
|
+
submitStepReceipt: typeof submitStepReceipt;
|
|
130
143
|
getStatus: typeof getStatus;
|
|
131
144
|
pollStatus: typeof pollStatus;
|
|
132
145
|
getBalances: typeof getBalances;
|
package/dist/core.cjs
CHANGED
|
@@ -75,7 +75,7 @@ var init_constants = __esm({
|
|
|
75
75
|
"src/constants.ts"() {
|
|
76
76
|
"use strict";
|
|
77
77
|
SDK_NAME = "@trustware/sdk";
|
|
78
|
-
SDK_VERSION = "1.1.
|
|
78
|
+
SDK_VERSION = "1.1.11-staging.1";
|
|
79
79
|
API_ROOT = "https://bv-staging-api.trustware.io";
|
|
80
80
|
API_PREFIX = "/api";
|
|
81
81
|
WALLETCONNECT_PROJECT_ID = "72ea74c400f5111d43aea638d7d83a24";
|
|
@@ -2006,6 +2006,20 @@ var init_eipWallets = __esm({
|
|
|
2006
2006
|
"src/wallets/eipWallets.ts"() {
|
|
2007
2007
|
"use strict";
|
|
2008
2008
|
CHAIN_PARAMS = {
|
|
2009
|
+
1: {
|
|
2010
|
+
chainIdHex: "0x1",
|
|
2011
|
+
chainName: "Ethereum",
|
|
2012
|
+
rpcUrls: ["https://eth.llamarpc.com"],
|
|
2013
|
+
nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
|
|
2014
|
+
blockExplorerUrls: ["https://etherscan.io"]
|
|
2015
|
+
},
|
|
2016
|
+
137: {
|
|
2017
|
+
chainIdHex: "0x89",
|
|
2018
|
+
chainName: "Polygon",
|
|
2019
|
+
rpcUrls: ["https://polygon-rpc.com"],
|
|
2020
|
+
nativeCurrency: { name: "POL", symbol: "POL", decimals: 18 },
|
|
2021
|
+
blockExplorerUrls: ["https://polygonscan.com"]
|
|
2022
|
+
},
|
|
2009
2023
|
8453: {
|
|
2010
2024
|
chainIdHex: "0x2105",
|
|
2011
2025
|
chainName: "Base",
|
|
@@ -4079,6 +4093,19 @@ async function submitReceipt(intentId, txHash, sponsorshipRequestId, eoaAddress)
|
|
|
4079
4093
|
const j = await r.json();
|
|
4080
4094
|
return j.data;
|
|
4081
4095
|
}
|
|
4096
|
+
async function submitStepReceipt(intentId, stepIndex, txHash) {
|
|
4097
|
+
const r = await rateLimitedFetch(
|
|
4098
|
+
`${apiBase()}/v1/route-intent/${intentId}/steps/${stepIndex}/receipt`,
|
|
4099
|
+
{
|
|
4100
|
+
method: "POST",
|
|
4101
|
+
headers: jsonHeaders({ "Idempotency-Key": txHash }),
|
|
4102
|
+
body: JSON.stringify({ txHash })
|
|
4103
|
+
}
|
|
4104
|
+
);
|
|
4105
|
+
await assertOK(r);
|
|
4106
|
+
const j = await r.json();
|
|
4107
|
+
return j.data;
|
|
4108
|
+
}
|
|
4082
4109
|
async function getStatus(intentId) {
|
|
4083
4110
|
const r = await rateLimitedFetch(
|
|
4084
4111
|
`${apiBase()}/v1/route-intent/${intentId}/status`,
|
|
@@ -6167,6 +6194,258 @@ var init_TrustwareError = __esm({
|
|
|
6167
6194
|
}
|
|
6168
6195
|
});
|
|
6169
6196
|
|
|
6197
|
+
// src/core/tx.ts
|
|
6198
|
+
function backendChainId(chain, fallback) {
|
|
6199
|
+
const preferred = chain?.networkIdentifier ?? chain?.chainId ?? chain?.id;
|
|
6200
|
+
return String(preferred ?? fallback ?? "");
|
|
6201
|
+
}
|
|
6202
|
+
function sleep2(ms) {
|
|
6203
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
6204
|
+
}
|
|
6205
|
+
async function sendEvmTx(w, tx) {
|
|
6206
|
+
if (w.type === "eip1193") {
|
|
6207
|
+
const from = await w.getAddress();
|
|
6208
|
+
const params = {
|
|
6209
|
+
from,
|
|
6210
|
+
to: tx.to,
|
|
6211
|
+
data: tx.data,
|
|
6212
|
+
value: tx.value ? `0x${tx.value.toString(16)}` : "0x0"
|
|
6213
|
+
};
|
|
6214
|
+
if (tx.chainId !== void 0) {
|
|
6215
|
+
params.chainId = `0x${tx.chainId.toString(16)}`;
|
|
6216
|
+
}
|
|
6217
|
+
const hash = await w.request({
|
|
6218
|
+
method: "eth_sendTransaction",
|
|
6219
|
+
params: [params]
|
|
6220
|
+
});
|
|
6221
|
+
return hash;
|
|
6222
|
+
}
|
|
6223
|
+
const response = await w.sendTransaction({
|
|
6224
|
+
to: tx.to,
|
|
6225
|
+
data: tx.data,
|
|
6226
|
+
value: tx.value,
|
|
6227
|
+
chainId: tx.chainId
|
|
6228
|
+
});
|
|
6229
|
+
return response.hash;
|
|
6230
|
+
}
|
|
6231
|
+
async function waitForTxConfirmation(chainId, txHash) {
|
|
6232
|
+
const timeoutMs = 12e4;
|
|
6233
|
+
const intervalMs = 2e3;
|
|
6234
|
+
const started = Date.now();
|
|
6235
|
+
while (Date.now() - started < timeoutMs) {
|
|
6236
|
+
const status = await getEVMTxStatus({ chainId, txHash });
|
|
6237
|
+
if (status.status === "success") return;
|
|
6238
|
+
if (status.status === "reverted") {
|
|
6239
|
+
throw new Error("Approval transaction reverted");
|
|
6240
|
+
}
|
|
6241
|
+
await sleep2(intervalMs);
|
|
6242
|
+
}
|
|
6243
|
+
throw new Error("Timed out waiting for approval confirmation");
|
|
6244
|
+
}
|
|
6245
|
+
function requiredApprovalAmount(planAmountWei, routeAmountWei) {
|
|
6246
|
+
if (planAmountWei >= UNLIMITED_APPROVAL_FLOOR && routeAmountWei !== void 0 && routeAmountWei > 0n) {
|
|
6247
|
+
return routeAmountWei;
|
|
6248
|
+
}
|
|
6249
|
+
return planAmountWei;
|
|
6250
|
+
}
|
|
6251
|
+
function approvalSatisfied(currentAllowance, requiredWei) {
|
|
6252
|
+
if (requiredWei === 0n) return currentAllowance === 0n;
|
|
6253
|
+
return currentAllowance >= requiredWei;
|
|
6254
|
+
}
|
|
6255
|
+
async function ensureApprovals(w, approvals, fallbackChainId, intentId, routeAmountWei) {
|
|
6256
|
+
if (!approvals || approvals.length === 0) return;
|
|
6257
|
+
const owner = await w.getAddress();
|
|
6258
|
+
for (const [stepIndex, approval] of approvals.entries()) {
|
|
6259
|
+
const spender = approval.spender;
|
|
6260
|
+
const tokenAddress = approval.tokenAddress;
|
|
6261
|
+
const amount = approval.amount;
|
|
6262
|
+
if (!spender || !tokenAddress || !amount) continue;
|
|
6263
|
+
const chainId = approval.chainId || String(fallbackChainId ?? "");
|
|
6264
|
+
if (!chainId) continue;
|
|
6265
|
+
const amountWei = requiredApprovalAmount(BigInt(amount), routeAmountWei);
|
|
6266
|
+
let currentAllowance = 0n;
|
|
6267
|
+
try {
|
|
6268
|
+
const { allowance } = await getEVMAllowance({
|
|
6269
|
+
chainId,
|
|
6270
|
+
tokenAddress,
|
|
6271
|
+
ownerAddress: owner,
|
|
6272
|
+
spenderAddress: spender
|
|
6273
|
+
});
|
|
6274
|
+
currentAllowance = BigInt(allowance || "0");
|
|
6275
|
+
} catch {
|
|
6276
|
+
}
|
|
6277
|
+
if (approvalSatisfied(currentAllowance, amountWei)) continue;
|
|
6278
|
+
const data = (0, import_viem2.encodeFunctionData)({
|
|
6279
|
+
abi: erc20ApproveAbi,
|
|
6280
|
+
functionName: "approve",
|
|
6281
|
+
args: [spender, amountWei]
|
|
6282
|
+
});
|
|
6283
|
+
const hash = await sendEvmTx(w, {
|
|
6284
|
+
to: tokenAddress,
|
|
6285
|
+
data,
|
|
6286
|
+
value: 0n,
|
|
6287
|
+
chainId: Number.isFinite(Number(chainId)) ? Number(chainId) : void 0
|
|
6288
|
+
});
|
|
6289
|
+
if (intentId) {
|
|
6290
|
+
void submitStepReceipt(intentId, stepIndex, hash).catch(() => {
|
|
6291
|
+
});
|
|
6292
|
+
}
|
|
6293
|
+
await waitForTxConfirmation(chainId, hash);
|
|
6294
|
+
}
|
|
6295
|
+
}
|
|
6296
|
+
function isUserRejected(e2) {
|
|
6297
|
+
const code = e2?.code ?? e2?.data?.code;
|
|
6298
|
+
if (code === 4001) return true;
|
|
6299
|
+
const msg = String(e2?.message || e2)?.toLowerCase?.() || "";
|
|
6300
|
+
return msg.includes("user rejected") || msg.includes("user denied");
|
|
6301
|
+
}
|
|
6302
|
+
async function sendRouteTransaction(b, fallbackChainId, options) {
|
|
6303
|
+
const w = walletManager.wallet;
|
|
6304
|
+
if (!w) throw new Error("Trustware.wallet not configured");
|
|
6305
|
+
const txReq = b.txReq;
|
|
6306
|
+
if (isEvmTxRequest(txReq)) {
|
|
6307
|
+
if (w.ecosystem !== "evm") {
|
|
6308
|
+
throw new Error("An EVM wallet is required for this route");
|
|
6309
|
+
}
|
|
6310
|
+
const to = txReq.to ?? txReq.target;
|
|
6311
|
+
const data = txReq.data;
|
|
6312
|
+
const value = txReq.value ? BigInt(txReq.value) : 0n;
|
|
6313
|
+
const target = Number(txReq.chainId ?? fallbackChainId);
|
|
6314
|
+
let validatedSponsorship;
|
|
6315
|
+
if (b.sponsorship) {
|
|
6316
|
+
if ((0, import_viem2.keccak256)(data) === b.sponsorship.callDataHash) {
|
|
6317
|
+
validatedSponsorship = b.sponsorship;
|
|
6318
|
+
}
|
|
6319
|
+
}
|
|
6320
|
+
if (Number.isFinite(target)) {
|
|
6321
|
+
const current = await w.getChainId();
|
|
6322
|
+
if (current !== target) {
|
|
6323
|
+
try {
|
|
6324
|
+
await w.switchChain(target);
|
|
6325
|
+
} catch {
|
|
6326
|
+
}
|
|
6327
|
+
}
|
|
6328
|
+
}
|
|
6329
|
+
if (!validatedSponsorship && !options?.approvalsEnsured) {
|
|
6330
|
+
await ensureApprovals(
|
|
6331
|
+
w,
|
|
6332
|
+
b.route?.execution?.approvals,
|
|
6333
|
+
Number.isFinite(target) ? target : void 0,
|
|
6334
|
+
b.intentId,
|
|
6335
|
+
BigInt(b.route?.estimate?.fromAmount ?? "0")
|
|
6336
|
+
);
|
|
6337
|
+
}
|
|
6338
|
+
if (w.type === "eip1193") {
|
|
6339
|
+
const from = await w.getAddress();
|
|
6340
|
+
const hexValue = value ? `0x${value.toString(16)}` : "0x0";
|
|
6341
|
+
const params = {
|
|
6342
|
+
from,
|
|
6343
|
+
to,
|
|
6344
|
+
data,
|
|
6345
|
+
value: hexValue
|
|
6346
|
+
};
|
|
6347
|
+
if (Number.isFinite(target)) {
|
|
6348
|
+
params.chainId = `0x${target.toString(16)}`;
|
|
6349
|
+
}
|
|
6350
|
+
const hash = await w.request({
|
|
6351
|
+
method: "eth_sendTransaction",
|
|
6352
|
+
params: [params]
|
|
6353
|
+
});
|
|
6354
|
+
return hash;
|
|
6355
|
+
}
|
|
6356
|
+
const response = await w.sendTransaction({
|
|
6357
|
+
to,
|
|
6358
|
+
data,
|
|
6359
|
+
value,
|
|
6360
|
+
chainId: Number.isFinite(target) ? target : void 0,
|
|
6361
|
+
...validatedSponsorship ? {
|
|
6362
|
+
paymasterAndData: validatedSponsorship.paymasterAndData
|
|
6363
|
+
} : {}
|
|
6364
|
+
});
|
|
6365
|
+
return response.hash;
|
|
6366
|
+
}
|
|
6367
|
+
if (isSerializedSolanaTxRequest(txReq)) {
|
|
6368
|
+
if (w.ecosystem !== "solana") {
|
|
6369
|
+
throw new Error("A Solana wallet is required for this route");
|
|
6370
|
+
}
|
|
6371
|
+
const { getSharedRegistry: getSharedRegistry2 } = await Promise.resolve().then(() => (init_registryClient(), registryClient_exports));
|
|
6372
|
+
const registry = getSharedRegistry2();
|
|
6373
|
+
await registry.ensureChainsLoaded();
|
|
6374
|
+
const chain = registry.chain(
|
|
6375
|
+
String(fallbackChainId ?? txReq.chainId ?? "")
|
|
6376
|
+
);
|
|
6377
|
+
return w.sendSerializedTransaction(
|
|
6378
|
+
txReq.data,
|
|
6379
|
+
backendChainId(chain, fallbackChainId ?? txReq.chainId)
|
|
6380
|
+
);
|
|
6381
|
+
}
|
|
6382
|
+
throw new Error("Invalid route transaction payload");
|
|
6383
|
+
}
|
|
6384
|
+
async function runTopUp(params) {
|
|
6385
|
+
const w = walletManager.wallet;
|
|
6386
|
+
if (!w) throw new Error("Trustware.wallet not configured");
|
|
6387
|
+
const { getSharedRegistry: getSharedRegistry2 } = await Promise.resolve().then(() => (init_registryClient(), registryClient_exports));
|
|
6388
|
+
const reg = getSharedRegistry2();
|
|
6389
|
+
await reg.ensureLoaded();
|
|
6390
|
+
const fromAddress = await w.getAddress();
|
|
6391
|
+
const currentChainRef = w.ecosystem === "evm" ? String(await w.getChainId()) : await w.getChainKey?.() ?? "solana-mainnet-beta";
|
|
6392
|
+
const originalChain = w.ecosystem === "evm" ? await w.getChainId() : void 0;
|
|
6393
|
+
const fromChain = params.fromChain ?? currentChainRef;
|
|
6394
|
+
const { TrustwareConfigStore: TrustwareConfigStore2 } = await Promise.resolve().then(() => (init_store(), store_exports));
|
|
6395
|
+
const cfg = TrustwareConfigStore2.get();
|
|
6396
|
+
const toChain = params.toChain ?? String(cfg.routes.toChain);
|
|
6397
|
+
const fromToken = reg.resolveToken(
|
|
6398
|
+
fromChain,
|
|
6399
|
+
params.fromToken ?? cfg.routes.fromToken ?? void 0
|
|
6400
|
+
) ?? params.fromToken;
|
|
6401
|
+
const toToken = reg.resolveToken(
|
|
6402
|
+
toChain,
|
|
6403
|
+
params.toToken ?? cfg.routes.toToken ?? void 0
|
|
6404
|
+
) ?? params.toToken;
|
|
6405
|
+
if (!fromToken || !toToken) {
|
|
6406
|
+
throw new Error("Unable to resolve route tokens");
|
|
6407
|
+
}
|
|
6408
|
+
try {
|
|
6409
|
+
const build = await buildRoute({
|
|
6410
|
+
fromChain,
|
|
6411
|
+
toChain,
|
|
6412
|
+
fromToken,
|
|
6413
|
+
toToken,
|
|
6414
|
+
fromAmount: String(params.fromAmount),
|
|
6415
|
+
fromAddress,
|
|
6416
|
+
toAddress: params.toAddress ?? cfg.routes.toAddress ?? cfg.routes.fromAddress ?? fromAddress,
|
|
6417
|
+
slippage: cfg.routes.defaultSlippage
|
|
6418
|
+
});
|
|
6419
|
+
const hash = await sendRouteTransaction(build, fromChain);
|
|
6420
|
+
await submitReceipt(build.intentId, hash);
|
|
6421
|
+
return await pollStatus(build.intentId);
|
|
6422
|
+
} catch (e2) {
|
|
6423
|
+
if (isUserRejected(e2)) throw new Error("Transaction cancelled by user");
|
|
6424
|
+
throw e2;
|
|
6425
|
+
} finally {
|
|
6426
|
+
try {
|
|
6427
|
+
if (w.ecosystem === "evm" && originalChain && originalChain !== Number(fromChain)) {
|
|
6428
|
+
await w.switchChain(originalChain);
|
|
6429
|
+
}
|
|
6430
|
+
} catch {
|
|
6431
|
+
}
|
|
6432
|
+
}
|
|
6433
|
+
}
|
|
6434
|
+
var import_viem2, erc20ApproveAbi, UNLIMITED_APPROVAL_FLOOR;
|
|
6435
|
+
var init_tx = __esm({
|
|
6436
|
+
"src/core/tx.ts"() {
|
|
6437
|
+
"use strict";
|
|
6438
|
+
init_wallets();
|
|
6439
|
+
init_routes();
|
|
6440
|
+
init_sdkRpc();
|
|
6441
|
+
import_viem2 = require("viem");
|
|
6442
|
+
erc20ApproveAbi = (0, import_viem2.parseAbi)([
|
|
6443
|
+
"function approve(address spender, uint256 amount) returns (bool)"
|
|
6444
|
+
]);
|
|
6445
|
+
UNLIMITED_APPROVAL_FLOOR = 1n << 255n;
|
|
6446
|
+
}
|
|
6447
|
+
});
|
|
6448
|
+
|
|
6170
6449
|
// src/types/routes.ts
|
|
6171
6450
|
var init_routes2 = __esm({
|
|
6172
6451
|
"src/types/routes.ts"() {
|
|
@@ -6452,242 +6731,6 @@ var init_store = __esm({
|
|
|
6452
6731
|
}
|
|
6453
6732
|
});
|
|
6454
6733
|
|
|
6455
|
-
// src/core/tx.ts
|
|
6456
|
-
function backendChainId(chain, fallback) {
|
|
6457
|
-
const preferred = chain?.networkIdentifier ?? chain?.chainId ?? chain?.id;
|
|
6458
|
-
return String(preferred ?? fallback ?? "");
|
|
6459
|
-
}
|
|
6460
|
-
function sleep2(ms) {
|
|
6461
|
-
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
6462
|
-
}
|
|
6463
|
-
async function sendEvmTx(w, tx) {
|
|
6464
|
-
if (w.type === "eip1193") {
|
|
6465
|
-
const from = await w.getAddress();
|
|
6466
|
-
const params = {
|
|
6467
|
-
from,
|
|
6468
|
-
to: tx.to,
|
|
6469
|
-
data: tx.data,
|
|
6470
|
-
value: tx.value ? `0x${tx.value.toString(16)}` : "0x0"
|
|
6471
|
-
};
|
|
6472
|
-
if (tx.chainId !== void 0) {
|
|
6473
|
-
params.chainId = `0x${tx.chainId.toString(16)}`;
|
|
6474
|
-
}
|
|
6475
|
-
const hash = await w.request({
|
|
6476
|
-
method: "eth_sendTransaction",
|
|
6477
|
-
params: [params]
|
|
6478
|
-
});
|
|
6479
|
-
return hash;
|
|
6480
|
-
}
|
|
6481
|
-
const response = await w.sendTransaction({
|
|
6482
|
-
to: tx.to,
|
|
6483
|
-
data: tx.data,
|
|
6484
|
-
value: tx.value,
|
|
6485
|
-
chainId: tx.chainId
|
|
6486
|
-
});
|
|
6487
|
-
return response.hash;
|
|
6488
|
-
}
|
|
6489
|
-
async function waitForTxConfirmation(chainId, txHash) {
|
|
6490
|
-
const timeoutMs = 12e4;
|
|
6491
|
-
const intervalMs = 2e3;
|
|
6492
|
-
const started = Date.now();
|
|
6493
|
-
while (Date.now() - started < timeoutMs) {
|
|
6494
|
-
const status = await getEVMTxStatus({ chainId, txHash });
|
|
6495
|
-
if (status.status === "success") return;
|
|
6496
|
-
if (status.status === "reverted") {
|
|
6497
|
-
throw new Error("Approval transaction reverted");
|
|
6498
|
-
}
|
|
6499
|
-
await sleep2(intervalMs);
|
|
6500
|
-
}
|
|
6501
|
-
throw new Error("Timed out waiting for approval confirmation");
|
|
6502
|
-
}
|
|
6503
|
-
async function ensureApprovals(w, approvals, fallbackChainId) {
|
|
6504
|
-
if (!approvals || approvals.length === 0) return;
|
|
6505
|
-
const owner = await w.getAddress();
|
|
6506
|
-
for (const approval of approvals) {
|
|
6507
|
-
const spender = approval.spender;
|
|
6508
|
-
const tokenAddress = approval.tokenAddress;
|
|
6509
|
-
const amount = approval.amount;
|
|
6510
|
-
if (!spender || !tokenAddress || !amount) continue;
|
|
6511
|
-
const chainId = approval.chainId || String(fallbackChainId ?? "");
|
|
6512
|
-
if (!chainId) continue;
|
|
6513
|
-
const amountWei = BigInt(amount);
|
|
6514
|
-
if (amountWei === 0n) continue;
|
|
6515
|
-
let currentAllowance = 0n;
|
|
6516
|
-
try {
|
|
6517
|
-
const { allowance } = await getEVMAllowance({
|
|
6518
|
-
chainId,
|
|
6519
|
-
tokenAddress,
|
|
6520
|
-
ownerAddress: owner,
|
|
6521
|
-
spenderAddress: spender
|
|
6522
|
-
});
|
|
6523
|
-
currentAllowance = BigInt(allowance || "0");
|
|
6524
|
-
} catch {
|
|
6525
|
-
}
|
|
6526
|
-
if (currentAllowance >= amountWei) continue;
|
|
6527
|
-
const data = (0, import_viem2.encodeFunctionData)({
|
|
6528
|
-
abi: erc20ApproveAbi,
|
|
6529
|
-
functionName: "approve",
|
|
6530
|
-
args: [spender, amountWei]
|
|
6531
|
-
});
|
|
6532
|
-
const hash = await sendEvmTx(w, {
|
|
6533
|
-
to: tokenAddress,
|
|
6534
|
-
data,
|
|
6535
|
-
value: 0n,
|
|
6536
|
-
chainId: Number.isFinite(Number(chainId)) ? Number(chainId) : void 0
|
|
6537
|
-
});
|
|
6538
|
-
await waitForTxConfirmation(chainId, hash);
|
|
6539
|
-
}
|
|
6540
|
-
}
|
|
6541
|
-
function isUserRejected(e2) {
|
|
6542
|
-
const code = e2?.code ?? e2?.data?.code;
|
|
6543
|
-
if (code === 4001) return true;
|
|
6544
|
-
const msg = String(e2?.message || e2)?.toLowerCase?.() || "";
|
|
6545
|
-
return msg.includes("user rejected") || msg.includes("user denied");
|
|
6546
|
-
}
|
|
6547
|
-
async function sendRouteTransaction(b, fallbackChainId) {
|
|
6548
|
-
const w = walletManager.wallet;
|
|
6549
|
-
if (!w) throw new Error("Trustware.wallet not configured");
|
|
6550
|
-
const txReq = b.txReq;
|
|
6551
|
-
if (isEvmTxRequest(txReq)) {
|
|
6552
|
-
if (w.ecosystem !== "evm") {
|
|
6553
|
-
throw new Error("An EVM wallet is required for this route");
|
|
6554
|
-
}
|
|
6555
|
-
const to = txReq.to ?? txReq.target;
|
|
6556
|
-
const data = txReq.data;
|
|
6557
|
-
const value = txReq.value ? BigInt(txReq.value) : 0n;
|
|
6558
|
-
const target = Number(txReq.chainId ?? fallbackChainId);
|
|
6559
|
-
let validatedSponsorship;
|
|
6560
|
-
if (b.sponsorship) {
|
|
6561
|
-
if ((0, import_viem2.keccak256)(data) === b.sponsorship.callDataHash) {
|
|
6562
|
-
validatedSponsorship = b.sponsorship;
|
|
6563
|
-
}
|
|
6564
|
-
}
|
|
6565
|
-
if (Number.isFinite(target)) {
|
|
6566
|
-
const current = await w.getChainId();
|
|
6567
|
-
if (current !== target) {
|
|
6568
|
-
try {
|
|
6569
|
-
await w.switchChain(target);
|
|
6570
|
-
} catch {
|
|
6571
|
-
}
|
|
6572
|
-
}
|
|
6573
|
-
}
|
|
6574
|
-
if (!validatedSponsorship) {
|
|
6575
|
-
await ensureApprovals(
|
|
6576
|
-
w,
|
|
6577
|
-
b.route?.execution?.approvals,
|
|
6578
|
-
Number.isFinite(target) ? target : void 0
|
|
6579
|
-
);
|
|
6580
|
-
}
|
|
6581
|
-
if (w.type === "eip1193") {
|
|
6582
|
-
const from = await w.getAddress();
|
|
6583
|
-
const hexValue = value ? `0x${value.toString(16)}` : "0x0";
|
|
6584
|
-
const params = {
|
|
6585
|
-
from,
|
|
6586
|
-
to,
|
|
6587
|
-
data,
|
|
6588
|
-
value: hexValue
|
|
6589
|
-
};
|
|
6590
|
-
if (Number.isFinite(target)) {
|
|
6591
|
-
params.chainId = `0x${target.toString(16)}`;
|
|
6592
|
-
}
|
|
6593
|
-
const hash = await w.request({
|
|
6594
|
-
method: "eth_sendTransaction",
|
|
6595
|
-
params: [params]
|
|
6596
|
-
});
|
|
6597
|
-
return hash;
|
|
6598
|
-
}
|
|
6599
|
-
const response = await w.sendTransaction({
|
|
6600
|
-
to,
|
|
6601
|
-
data,
|
|
6602
|
-
value,
|
|
6603
|
-
chainId: Number.isFinite(target) ? target : void 0,
|
|
6604
|
-
...validatedSponsorship ? {
|
|
6605
|
-
paymasterAndData: validatedSponsorship.paymasterAndData
|
|
6606
|
-
} : {}
|
|
6607
|
-
});
|
|
6608
|
-
return response.hash;
|
|
6609
|
-
}
|
|
6610
|
-
if (isSerializedSolanaTxRequest(txReq)) {
|
|
6611
|
-
if (w.ecosystem !== "solana") {
|
|
6612
|
-
throw new Error("A Solana wallet is required for this route");
|
|
6613
|
-
}
|
|
6614
|
-
const { getSharedRegistry: getSharedRegistry2 } = await Promise.resolve().then(() => (init_registryClient(), registryClient_exports));
|
|
6615
|
-
const registry = getSharedRegistry2();
|
|
6616
|
-
await registry.ensureChainsLoaded();
|
|
6617
|
-
const chain = registry.chain(
|
|
6618
|
-
String(fallbackChainId ?? txReq.chainId ?? "")
|
|
6619
|
-
);
|
|
6620
|
-
return w.sendSerializedTransaction(
|
|
6621
|
-
txReq.data,
|
|
6622
|
-
backendChainId(chain, fallbackChainId ?? txReq.chainId)
|
|
6623
|
-
);
|
|
6624
|
-
}
|
|
6625
|
-
throw new Error("Invalid route transaction payload");
|
|
6626
|
-
}
|
|
6627
|
-
async function runTopUp(params) {
|
|
6628
|
-
const w = walletManager.wallet;
|
|
6629
|
-
if (!w) throw new Error("Trustware.wallet not configured");
|
|
6630
|
-
const { getSharedRegistry: getSharedRegistry2 } = await Promise.resolve().then(() => (init_registryClient(), registryClient_exports));
|
|
6631
|
-
const reg = getSharedRegistry2();
|
|
6632
|
-
await reg.ensureLoaded();
|
|
6633
|
-
const fromAddress = await w.getAddress();
|
|
6634
|
-
const currentChainRef = w.ecosystem === "evm" ? String(await w.getChainId()) : await w.getChainKey?.() ?? "solana-mainnet-beta";
|
|
6635
|
-
const originalChain = w.ecosystem === "evm" ? await w.getChainId() : void 0;
|
|
6636
|
-
const fromChain = params.fromChain ?? currentChainRef;
|
|
6637
|
-
const { TrustwareConfigStore: TrustwareConfigStore2 } = await Promise.resolve().then(() => (init_store(), store_exports));
|
|
6638
|
-
const cfg = TrustwareConfigStore2.get();
|
|
6639
|
-
const toChain = params.toChain ?? String(cfg.routes.toChain);
|
|
6640
|
-
const fromToken = reg.resolveToken(
|
|
6641
|
-
fromChain,
|
|
6642
|
-
params.fromToken ?? cfg.routes.fromToken ?? void 0
|
|
6643
|
-
) ?? params.fromToken;
|
|
6644
|
-
const toToken = reg.resolveToken(
|
|
6645
|
-
toChain,
|
|
6646
|
-
params.toToken ?? cfg.routes.toToken ?? void 0
|
|
6647
|
-
) ?? params.toToken;
|
|
6648
|
-
if (!fromToken || !toToken) {
|
|
6649
|
-
throw new Error("Unable to resolve route tokens");
|
|
6650
|
-
}
|
|
6651
|
-
try {
|
|
6652
|
-
const build = await buildRoute({
|
|
6653
|
-
fromChain,
|
|
6654
|
-
toChain,
|
|
6655
|
-
fromToken,
|
|
6656
|
-
toToken,
|
|
6657
|
-
fromAmount: String(params.fromAmount),
|
|
6658
|
-
fromAddress,
|
|
6659
|
-
toAddress: params.toAddress ?? cfg.routes.toAddress ?? cfg.routes.fromAddress ?? fromAddress,
|
|
6660
|
-
slippage: cfg.routes.defaultSlippage
|
|
6661
|
-
});
|
|
6662
|
-
const hash = await sendRouteTransaction(build, fromChain);
|
|
6663
|
-
await submitReceipt(build.intentId, hash);
|
|
6664
|
-
return await pollStatus(build.intentId);
|
|
6665
|
-
} catch (e2) {
|
|
6666
|
-
if (isUserRejected(e2)) throw new Error("Transaction cancelled by user");
|
|
6667
|
-
throw e2;
|
|
6668
|
-
} finally {
|
|
6669
|
-
try {
|
|
6670
|
-
if (w.ecosystem === "evm" && originalChain && originalChain !== Number(fromChain)) {
|
|
6671
|
-
await w.switchChain(originalChain);
|
|
6672
|
-
}
|
|
6673
|
-
} catch {
|
|
6674
|
-
}
|
|
6675
|
-
}
|
|
6676
|
-
}
|
|
6677
|
-
var import_viem2, erc20ApproveAbi;
|
|
6678
|
-
var init_tx = __esm({
|
|
6679
|
-
"src/core/tx.ts"() {
|
|
6680
|
-
"use strict";
|
|
6681
|
-
init_wallets();
|
|
6682
|
-
init_routes();
|
|
6683
|
-
init_sdkRpc();
|
|
6684
|
-
import_viem2 = require("viem");
|
|
6685
|
-
erc20ApproveAbi = (0, import_viem2.parseAbi)([
|
|
6686
|
-
"function approve(address spender, uint256 amount) returns (bool)"
|
|
6687
|
-
]);
|
|
6688
|
-
}
|
|
6689
|
-
});
|
|
6690
|
-
|
|
6691
6734
|
// src/core/index.ts
|
|
6692
6735
|
var _lastValidatedKey, Trustware;
|
|
6693
6736
|
var init_core = __esm({
|
|
@@ -6830,6 +6873,7 @@ var init_core = __esm({
|
|
|
6830
6873
|
buildRoute,
|
|
6831
6874
|
buildDepositAddress,
|
|
6832
6875
|
submitReceipt,
|
|
6876
|
+
submitStepReceipt,
|
|
6833
6877
|
getStatus,
|
|
6834
6878
|
pollStatus,
|
|
6835
6879
|
getBalances,
|