@trustware/sdk-staging 1.1.9-staging.7 → 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-DzqVEWwP.d.ts → core-BgYLe9Q7.d.ts} +15 -2
- package/dist/{core-gNyi5xsp.d.cts → core-fLSt4qD2.d.cts} +15 -2
- package/dist/core.cjs +318 -145
- 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 +318 -144
- package/dist/core.mjs.map +1 -1
- package/dist/index.cjs +407 -114
- 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 +433 -140
- package/dist/index.mjs.map +1 -1
- package/dist/{manager-Dn4muk74.d.ts → manager-BY3NHAks.d.ts} +138 -2
- package/dist/{manager-DWFNyouP.d.cts → manager-DT8enQbE.d.cts} +138 -2
- package/dist/{detect-Cprq6X9o.d.ts → metadata-BPvFYMlc.d.ts} +5 -2
- package/dist/{detect-DWL4uExV.d.cts → metadata-DyxUcKHk.d.cts} +5 -2
- package/dist/smart-account.cjs +1 -1
- package/dist/smart-account.cjs.map +1 -1
- package/dist/smart-account.d.cts +247 -234
- package/dist/smart-account.d.ts +247 -234
- 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 +4 -7
- package/dist/wallet.d.ts +4 -7
- package/dist/wallet.mjs +15 -1
- package/dist/wallet.mjs.map +1 -1
- package/dist/widget.cjs +381 -113
- package/dist/widget.cjs.map +1 -1
- package/dist/widget.mjs +409 -139
- package/dist/widget.mjs.map +1 -1
- package/package.json +1 -1
package/dist/core.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { T as Trustware, a as TrustwareCore } from './core-
|
|
2
|
-
import './manager-
|
|
1
|
+
export { T as Trustware, a as TrustwareCore } from './core-fLSt4qD2.cjs';
|
|
2
|
+
import './manager-DT8enQbE.cjs';
|
|
3
3
|
import './blockchain-BxAFzp0s.cjs';
|
|
4
4
|
import './types-DX3HtFcn.cjs';
|
package/dist/core.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { T as Trustware, a as TrustwareCore } from './core-
|
|
2
|
-
import './manager-
|
|
1
|
+
export { T as Trustware, a as TrustwareCore } from './core-BgYLe9Q7.js';
|
|
2
|
+
import './manager-BY3NHAks.js';
|
|
3
3
|
import './blockchain-BxAFzp0s.js';
|
|
4
4
|
import './types-BJY9r-mz.js';
|
package/dist/core.mjs
CHANGED
|
@@ -53,7 +53,7 @@ var init_constants = __esm({
|
|
|
53
53
|
"src/constants.ts"() {
|
|
54
54
|
"use strict";
|
|
55
55
|
SDK_NAME = "@trustware/sdk";
|
|
56
|
-
SDK_VERSION = "1.1.
|
|
56
|
+
SDK_VERSION = "1.1.11-staging.1";
|
|
57
57
|
API_ROOT = "https://bv-staging-api.trustware.io";
|
|
58
58
|
API_PREFIX = "/api";
|
|
59
59
|
WALLETCONNECT_PROJECT_ID = "72ea74c400f5111d43aea638d7d83a24";
|
|
@@ -1984,6 +1984,20 @@ var init_eipWallets = __esm({
|
|
|
1984
1984
|
"src/wallets/eipWallets.ts"() {
|
|
1985
1985
|
"use strict";
|
|
1986
1986
|
CHAIN_PARAMS = {
|
|
1987
|
+
1: {
|
|
1988
|
+
chainIdHex: "0x1",
|
|
1989
|
+
chainName: "Ethereum",
|
|
1990
|
+
rpcUrls: ["https://eth.llamarpc.com"],
|
|
1991
|
+
nativeCurrency: { name: "Ether", symbol: "ETH", decimals: 18 },
|
|
1992
|
+
blockExplorerUrls: ["https://etherscan.io"]
|
|
1993
|
+
},
|
|
1994
|
+
137: {
|
|
1995
|
+
chainIdHex: "0x89",
|
|
1996
|
+
chainName: "Polygon",
|
|
1997
|
+
rpcUrls: ["https://polygon-rpc.com"],
|
|
1998
|
+
nativeCurrency: { name: "POL", symbol: "POL", decimals: 18 },
|
|
1999
|
+
blockExplorerUrls: ["https://polygonscan.com"]
|
|
2000
|
+
},
|
|
1987
2001
|
8453: {
|
|
1988
2002
|
chainIdHex: "0x2105",
|
|
1989
2003
|
chainName: "Base",
|
|
@@ -2033,6 +2047,20 @@ async function requestSDKRPC(path, init = {}) {
|
|
|
2033
2047
|
}
|
|
2034
2048
|
);
|
|
2035
2049
|
}
|
|
2050
|
+
async function getEVMAllowance(params) {
|
|
2051
|
+
const search = new URLSearchParams(params);
|
|
2052
|
+
return requestSDKRPC(
|
|
2053
|
+
`/evm/allowance?${search.toString()}`,
|
|
2054
|
+
{ method: "GET" }
|
|
2055
|
+
);
|
|
2056
|
+
}
|
|
2057
|
+
async function getEVMTxStatus(params) {
|
|
2058
|
+
const search = new URLSearchParams(params);
|
|
2059
|
+
return requestSDKRPC(
|
|
2060
|
+
`/evm/tx-status?${search.toString()}`,
|
|
2061
|
+
{ method: "GET" }
|
|
2062
|
+
);
|
|
2063
|
+
}
|
|
2036
2064
|
async function sendSolanaSerialized(body) {
|
|
2037
2065
|
return requestSDKRPC(
|
|
2038
2066
|
"/solana/send-serialized",
|
|
@@ -3906,6 +3934,27 @@ var init_wallets = __esm({
|
|
|
3906
3934
|
});
|
|
3907
3935
|
|
|
3908
3936
|
// src/core/routes.ts
|
|
3937
|
+
function assertValidPostHook(hooks) {
|
|
3938
|
+
const postHook = hooks?.postHook;
|
|
3939
|
+
if (!postHook) return;
|
|
3940
|
+
if (!postHook.target?.trim()) {
|
|
3941
|
+
throw new Error("hooks.postHook.target is required.");
|
|
3942
|
+
}
|
|
3943
|
+
if (!postHook.callData?.trim()) {
|
|
3944
|
+
throw new Error("hooks.postHook.callData is required.");
|
|
3945
|
+
}
|
|
3946
|
+
if (postHook.fullAmount) {
|
|
3947
|
+
if (postHook.amountInputPos === void 0) {
|
|
3948
|
+
throw new Error(
|
|
3949
|
+
"hooks.postHook.amountInputPos is required when fullAmount is true."
|
|
3950
|
+
);
|
|
3951
|
+
}
|
|
3952
|
+
} else if (!postHook.fundAmount?.trim()) {
|
|
3953
|
+
throw new Error(
|
|
3954
|
+
"hooks.postHook.fundAmount is required unless fullAmount is set."
|
|
3955
|
+
);
|
|
3956
|
+
}
|
|
3957
|
+
}
|
|
3909
3958
|
function isEvmTxRequest(txReq) {
|
|
3910
3959
|
return Boolean(txReq?.data && (txReq.to || txReq.target));
|
|
3911
3960
|
}
|
|
@@ -3924,6 +3973,7 @@ async function buildRoute(body, signal) {
|
|
|
3924
3973
|
if (!addressValidation.isValid) {
|
|
3925
3974
|
throw new Error(addressValidation.error || "Invalid route addresses.");
|
|
3926
3975
|
}
|
|
3976
|
+
assertValidPostHook(body.hooks);
|
|
3927
3977
|
const cfg = TrustwareConfigStore.get();
|
|
3928
3978
|
const url = `${apiBase()}/v1/routes/route`;
|
|
3929
3979
|
const payload = {
|
|
@@ -3962,6 +4012,7 @@ async function buildRoute(body, signal) {
|
|
|
3962
4012
|
return { intentId, txReq, actions, finalExchangeRate, route, sponsorship };
|
|
3963
4013
|
}
|
|
3964
4014
|
async function buildDepositAddress(body, signal) {
|
|
4015
|
+
assertValidPostHook(body.hooks);
|
|
3965
4016
|
const cfg = TrustwareConfigStore.get();
|
|
3966
4017
|
const url = `${apiBase()}/v1/routes/deposit-address`;
|
|
3967
4018
|
const payload = {
|
|
@@ -4020,6 +4071,19 @@ async function submitReceipt(intentId, txHash, sponsorshipRequestId, eoaAddress)
|
|
|
4020
4071
|
const j = await r.json();
|
|
4021
4072
|
return j.data;
|
|
4022
4073
|
}
|
|
4074
|
+
async function submitStepReceipt(intentId, stepIndex, txHash) {
|
|
4075
|
+
const r = await rateLimitedFetch(
|
|
4076
|
+
`${apiBase()}/v1/route-intent/${intentId}/steps/${stepIndex}/receipt`,
|
|
4077
|
+
{
|
|
4078
|
+
method: "POST",
|
|
4079
|
+
headers: jsonHeaders({ "Idempotency-Key": txHash }),
|
|
4080
|
+
body: JSON.stringify({ txHash })
|
|
4081
|
+
}
|
|
4082
|
+
);
|
|
4083
|
+
await assertOK(r);
|
|
4084
|
+
const j = await r.json();
|
|
4085
|
+
return j.data;
|
|
4086
|
+
}
|
|
4023
4087
|
async function getStatus(intentId) {
|
|
4024
4088
|
const r = await rateLimitedFetch(
|
|
4025
4089
|
`${apiBase()}/v1/route-intent/${intentId}/status`,
|
|
@@ -6108,6 +6172,258 @@ var init_TrustwareError = __esm({
|
|
|
6108
6172
|
}
|
|
6109
6173
|
});
|
|
6110
6174
|
|
|
6175
|
+
// src/core/tx.ts
|
|
6176
|
+
import { keccak256, encodeFunctionData, parseAbi } from "viem";
|
|
6177
|
+
function backendChainId(chain, fallback) {
|
|
6178
|
+
const preferred = chain?.networkIdentifier ?? chain?.chainId ?? chain?.id;
|
|
6179
|
+
return String(preferred ?? fallback ?? "");
|
|
6180
|
+
}
|
|
6181
|
+
function sleep2(ms) {
|
|
6182
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
6183
|
+
}
|
|
6184
|
+
async function sendEvmTx(w, tx) {
|
|
6185
|
+
if (w.type === "eip1193") {
|
|
6186
|
+
const from = await w.getAddress();
|
|
6187
|
+
const params = {
|
|
6188
|
+
from,
|
|
6189
|
+
to: tx.to,
|
|
6190
|
+
data: tx.data,
|
|
6191
|
+
value: tx.value ? `0x${tx.value.toString(16)}` : "0x0"
|
|
6192
|
+
};
|
|
6193
|
+
if (tx.chainId !== void 0) {
|
|
6194
|
+
params.chainId = `0x${tx.chainId.toString(16)}`;
|
|
6195
|
+
}
|
|
6196
|
+
const hash = await w.request({
|
|
6197
|
+
method: "eth_sendTransaction",
|
|
6198
|
+
params: [params]
|
|
6199
|
+
});
|
|
6200
|
+
return hash;
|
|
6201
|
+
}
|
|
6202
|
+
const response = await w.sendTransaction({
|
|
6203
|
+
to: tx.to,
|
|
6204
|
+
data: tx.data,
|
|
6205
|
+
value: tx.value,
|
|
6206
|
+
chainId: tx.chainId
|
|
6207
|
+
});
|
|
6208
|
+
return response.hash;
|
|
6209
|
+
}
|
|
6210
|
+
async function waitForTxConfirmation(chainId, txHash) {
|
|
6211
|
+
const timeoutMs = 12e4;
|
|
6212
|
+
const intervalMs = 2e3;
|
|
6213
|
+
const started = Date.now();
|
|
6214
|
+
while (Date.now() - started < timeoutMs) {
|
|
6215
|
+
const status = await getEVMTxStatus({ chainId, txHash });
|
|
6216
|
+
if (status.status === "success") return;
|
|
6217
|
+
if (status.status === "reverted") {
|
|
6218
|
+
throw new Error("Approval transaction reverted");
|
|
6219
|
+
}
|
|
6220
|
+
await sleep2(intervalMs);
|
|
6221
|
+
}
|
|
6222
|
+
throw new Error("Timed out waiting for approval confirmation");
|
|
6223
|
+
}
|
|
6224
|
+
function requiredApprovalAmount(planAmountWei, routeAmountWei) {
|
|
6225
|
+
if (planAmountWei >= UNLIMITED_APPROVAL_FLOOR && routeAmountWei !== void 0 && routeAmountWei > 0n) {
|
|
6226
|
+
return routeAmountWei;
|
|
6227
|
+
}
|
|
6228
|
+
return planAmountWei;
|
|
6229
|
+
}
|
|
6230
|
+
function approvalSatisfied(currentAllowance, requiredWei) {
|
|
6231
|
+
if (requiredWei === 0n) return currentAllowance === 0n;
|
|
6232
|
+
return currentAllowance >= requiredWei;
|
|
6233
|
+
}
|
|
6234
|
+
async function ensureApprovals(w, approvals, fallbackChainId, intentId, routeAmountWei) {
|
|
6235
|
+
if (!approvals || approvals.length === 0) return;
|
|
6236
|
+
const owner = await w.getAddress();
|
|
6237
|
+
for (const [stepIndex, approval] of approvals.entries()) {
|
|
6238
|
+
const spender = approval.spender;
|
|
6239
|
+
const tokenAddress = approval.tokenAddress;
|
|
6240
|
+
const amount = approval.amount;
|
|
6241
|
+
if (!spender || !tokenAddress || !amount) continue;
|
|
6242
|
+
const chainId = approval.chainId || String(fallbackChainId ?? "");
|
|
6243
|
+
if (!chainId) continue;
|
|
6244
|
+
const amountWei = requiredApprovalAmount(BigInt(amount), routeAmountWei);
|
|
6245
|
+
let currentAllowance = 0n;
|
|
6246
|
+
try {
|
|
6247
|
+
const { allowance } = await getEVMAllowance({
|
|
6248
|
+
chainId,
|
|
6249
|
+
tokenAddress,
|
|
6250
|
+
ownerAddress: owner,
|
|
6251
|
+
spenderAddress: spender
|
|
6252
|
+
});
|
|
6253
|
+
currentAllowance = BigInt(allowance || "0");
|
|
6254
|
+
} catch {
|
|
6255
|
+
}
|
|
6256
|
+
if (approvalSatisfied(currentAllowance, amountWei)) continue;
|
|
6257
|
+
const data = encodeFunctionData({
|
|
6258
|
+
abi: erc20ApproveAbi,
|
|
6259
|
+
functionName: "approve",
|
|
6260
|
+
args: [spender, amountWei]
|
|
6261
|
+
});
|
|
6262
|
+
const hash = await sendEvmTx(w, {
|
|
6263
|
+
to: tokenAddress,
|
|
6264
|
+
data,
|
|
6265
|
+
value: 0n,
|
|
6266
|
+
chainId: Number.isFinite(Number(chainId)) ? Number(chainId) : void 0
|
|
6267
|
+
});
|
|
6268
|
+
if (intentId) {
|
|
6269
|
+
void submitStepReceipt(intentId, stepIndex, hash).catch(() => {
|
|
6270
|
+
});
|
|
6271
|
+
}
|
|
6272
|
+
await waitForTxConfirmation(chainId, hash);
|
|
6273
|
+
}
|
|
6274
|
+
}
|
|
6275
|
+
function isUserRejected(e2) {
|
|
6276
|
+
const code = e2?.code ?? e2?.data?.code;
|
|
6277
|
+
if (code === 4001) return true;
|
|
6278
|
+
const msg = String(e2?.message || e2)?.toLowerCase?.() || "";
|
|
6279
|
+
return msg.includes("user rejected") || msg.includes("user denied");
|
|
6280
|
+
}
|
|
6281
|
+
async function sendRouteTransaction(b, fallbackChainId, options) {
|
|
6282
|
+
const w = walletManager.wallet;
|
|
6283
|
+
if (!w) throw new Error("Trustware.wallet not configured");
|
|
6284
|
+
const txReq = b.txReq;
|
|
6285
|
+
if (isEvmTxRequest(txReq)) {
|
|
6286
|
+
if (w.ecosystem !== "evm") {
|
|
6287
|
+
throw new Error("An EVM wallet is required for this route");
|
|
6288
|
+
}
|
|
6289
|
+
const to = txReq.to ?? txReq.target;
|
|
6290
|
+
const data = txReq.data;
|
|
6291
|
+
const value = txReq.value ? BigInt(txReq.value) : 0n;
|
|
6292
|
+
const target = Number(txReq.chainId ?? fallbackChainId);
|
|
6293
|
+
let validatedSponsorship;
|
|
6294
|
+
if (b.sponsorship) {
|
|
6295
|
+
if (keccak256(data) === b.sponsorship.callDataHash) {
|
|
6296
|
+
validatedSponsorship = b.sponsorship;
|
|
6297
|
+
}
|
|
6298
|
+
}
|
|
6299
|
+
if (Number.isFinite(target)) {
|
|
6300
|
+
const current = await w.getChainId();
|
|
6301
|
+
if (current !== target) {
|
|
6302
|
+
try {
|
|
6303
|
+
await w.switchChain(target);
|
|
6304
|
+
} catch {
|
|
6305
|
+
}
|
|
6306
|
+
}
|
|
6307
|
+
}
|
|
6308
|
+
if (!validatedSponsorship && !options?.approvalsEnsured) {
|
|
6309
|
+
await ensureApprovals(
|
|
6310
|
+
w,
|
|
6311
|
+
b.route?.execution?.approvals,
|
|
6312
|
+
Number.isFinite(target) ? target : void 0,
|
|
6313
|
+
b.intentId,
|
|
6314
|
+
BigInt(b.route?.estimate?.fromAmount ?? "0")
|
|
6315
|
+
);
|
|
6316
|
+
}
|
|
6317
|
+
if (w.type === "eip1193") {
|
|
6318
|
+
const from = await w.getAddress();
|
|
6319
|
+
const hexValue = value ? `0x${value.toString(16)}` : "0x0";
|
|
6320
|
+
const params = {
|
|
6321
|
+
from,
|
|
6322
|
+
to,
|
|
6323
|
+
data,
|
|
6324
|
+
value: hexValue
|
|
6325
|
+
};
|
|
6326
|
+
if (Number.isFinite(target)) {
|
|
6327
|
+
params.chainId = `0x${target.toString(16)}`;
|
|
6328
|
+
}
|
|
6329
|
+
const hash = await w.request({
|
|
6330
|
+
method: "eth_sendTransaction",
|
|
6331
|
+
params: [params]
|
|
6332
|
+
});
|
|
6333
|
+
return hash;
|
|
6334
|
+
}
|
|
6335
|
+
const response = await w.sendTransaction({
|
|
6336
|
+
to,
|
|
6337
|
+
data,
|
|
6338
|
+
value,
|
|
6339
|
+
chainId: Number.isFinite(target) ? target : void 0,
|
|
6340
|
+
...validatedSponsorship ? {
|
|
6341
|
+
paymasterAndData: validatedSponsorship.paymasterAndData
|
|
6342
|
+
} : {}
|
|
6343
|
+
});
|
|
6344
|
+
return response.hash;
|
|
6345
|
+
}
|
|
6346
|
+
if (isSerializedSolanaTxRequest(txReq)) {
|
|
6347
|
+
if (w.ecosystem !== "solana") {
|
|
6348
|
+
throw new Error("A Solana wallet is required for this route");
|
|
6349
|
+
}
|
|
6350
|
+
const { getSharedRegistry: getSharedRegistry2 } = await Promise.resolve().then(() => (init_registryClient(), registryClient_exports));
|
|
6351
|
+
const registry = getSharedRegistry2();
|
|
6352
|
+
await registry.ensureChainsLoaded();
|
|
6353
|
+
const chain = registry.chain(
|
|
6354
|
+
String(fallbackChainId ?? txReq.chainId ?? "")
|
|
6355
|
+
);
|
|
6356
|
+
return w.sendSerializedTransaction(
|
|
6357
|
+
txReq.data,
|
|
6358
|
+
backendChainId(chain, fallbackChainId ?? txReq.chainId)
|
|
6359
|
+
);
|
|
6360
|
+
}
|
|
6361
|
+
throw new Error("Invalid route transaction payload");
|
|
6362
|
+
}
|
|
6363
|
+
async function runTopUp(params) {
|
|
6364
|
+
const w = walletManager.wallet;
|
|
6365
|
+
if (!w) throw new Error("Trustware.wallet not configured");
|
|
6366
|
+
const { getSharedRegistry: getSharedRegistry2 } = await Promise.resolve().then(() => (init_registryClient(), registryClient_exports));
|
|
6367
|
+
const reg = getSharedRegistry2();
|
|
6368
|
+
await reg.ensureLoaded();
|
|
6369
|
+
const fromAddress = await w.getAddress();
|
|
6370
|
+
const currentChainRef = w.ecosystem === "evm" ? String(await w.getChainId()) : await w.getChainKey?.() ?? "solana-mainnet-beta";
|
|
6371
|
+
const originalChain = w.ecosystem === "evm" ? await w.getChainId() : void 0;
|
|
6372
|
+
const fromChain = params.fromChain ?? currentChainRef;
|
|
6373
|
+
const { TrustwareConfigStore: TrustwareConfigStore2 } = await Promise.resolve().then(() => (init_store(), store_exports));
|
|
6374
|
+
const cfg = TrustwareConfigStore2.get();
|
|
6375
|
+
const toChain = params.toChain ?? String(cfg.routes.toChain);
|
|
6376
|
+
const fromToken = reg.resolveToken(
|
|
6377
|
+
fromChain,
|
|
6378
|
+
params.fromToken ?? cfg.routes.fromToken ?? void 0
|
|
6379
|
+
) ?? params.fromToken;
|
|
6380
|
+
const toToken = reg.resolveToken(
|
|
6381
|
+
toChain,
|
|
6382
|
+
params.toToken ?? cfg.routes.toToken ?? void 0
|
|
6383
|
+
) ?? params.toToken;
|
|
6384
|
+
if (!fromToken || !toToken) {
|
|
6385
|
+
throw new Error("Unable to resolve route tokens");
|
|
6386
|
+
}
|
|
6387
|
+
try {
|
|
6388
|
+
const build = await buildRoute({
|
|
6389
|
+
fromChain,
|
|
6390
|
+
toChain,
|
|
6391
|
+
fromToken,
|
|
6392
|
+
toToken,
|
|
6393
|
+
fromAmount: String(params.fromAmount),
|
|
6394
|
+
fromAddress,
|
|
6395
|
+
toAddress: params.toAddress ?? cfg.routes.toAddress ?? cfg.routes.fromAddress ?? fromAddress,
|
|
6396
|
+
slippage: cfg.routes.defaultSlippage
|
|
6397
|
+
});
|
|
6398
|
+
const hash = await sendRouteTransaction(build, fromChain);
|
|
6399
|
+
await submitReceipt(build.intentId, hash);
|
|
6400
|
+
return await pollStatus(build.intentId);
|
|
6401
|
+
} catch (e2) {
|
|
6402
|
+
if (isUserRejected(e2)) throw new Error("Transaction cancelled by user");
|
|
6403
|
+
throw e2;
|
|
6404
|
+
} finally {
|
|
6405
|
+
try {
|
|
6406
|
+
if (w.ecosystem === "evm" && originalChain && originalChain !== Number(fromChain)) {
|
|
6407
|
+
await w.switchChain(originalChain);
|
|
6408
|
+
}
|
|
6409
|
+
} catch {
|
|
6410
|
+
}
|
|
6411
|
+
}
|
|
6412
|
+
}
|
|
6413
|
+
var erc20ApproveAbi, UNLIMITED_APPROVAL_FLOOR;
|
|
6414
|
+
var init_tx = __esm({
|
|
6415
|
+
"src/core/tx.ts"() {
|
|
6416
|
+
"use strict";
|
|
6417
|
+
init_wallets();
|
|
6418
|
+
init_routes();
|
|
6419
|
+
init_sdkRpc();
|
|
6420
|
+
erc20ApproveAbi = parseAbi([
|
|
6421
|
+
"function approve(address spender, uint256 amount) returns (bool)"
|
|
6422
|
+
]);
|
|
6423
|
+
UNLIMITED_APPROVAL_FLOOR = 1n << 255n;
|
|
6424
|
+
}
|
|
6425
|
+
});
|
|
6426
|
+
|
|
6111
6427
|
// src/types/routes.ts
|
|
6112
6428
|
var init_routes2 = __esm({
|
|
6113
6429
|
"src/types/routes.ts"() {
|
|
@@ -6393,149 +6709,6 @@ var init_store = __esm({
|
|
|
6393
6709
|
}
|
|
6394
6710
|
});
|
|
6395
6711
|
|
|
6396
|
-
// src/core/tx.ts
|
|
6397
|
-
import { keccak256 } from "viem";
|
|
6398
|
-
function backendChainId(chain, fallback) {
|
|
6399
|
-
const preferred = chain?.networkIdentifier ?? chain?.chainId ?? chain?.id;
|
|
6400
|
-
return String(preferred ?? fallback ?? "");
|
|
6401
|
-
}
|
|
6402
|
-
function isUserRejected(e2) {
|
|
6403
|
-
const code = e2?.code ?? e2?.data?.code;
|
|
6404
|
-
if (code === 4001) return true;
|
|
6405
|
-
const msg = String(e2?.message || e2)?.toLowerCase?.() || "";
|
|
6406
|
-
return msg.includes("user rejected") || msg.includes("user denied");
|
|
6407
|
-
}
|
|
6408
|
-
async function sendRouteTransaction(b, fallbackChainId) {
|
|
6409
|
-
const w = walletManager.wallet;
|
|
6410
|
-
if (!w) throw new Error("Trustware.wallet not configured");
|
|
6411
|
-
const txReq = b.txReq;
|
|
6412
|
-
if (isEvmTxRequest(txReq)) {
|
|
6413
|
-
if (w.ecosystem !== "evm") {
|
|
6414
|
-
throw new Error("An EVM wallet is required for this route");
|
|
6415
|
-
}
|
|
6416
|
-
const to = txReq.to ?? txReq.target;
|
|
6417
|
-
const data = txReq.data;
|
|
6418
|
-
const value = txReq.value ? BigInt(txReq.value) : 0n;
|
|
6419
|
-
const target = Number(txReq.chainId ?? fallbackChainId);
|
|
6420
|
-
let validatedSponsorship;
|
|
6421
|
-
if (b.sponsorship) {
|
|
6422
|
-
if (keccak256(data) === b.sponsorship.callDataHash) {
|
|
6423
|
-
validatedSponsorship = b.sponsorship;
|
|
6424
|
-
}
|
|
6425
|
-
}
|
|
6426
|
-
if (Number.isFinite(target)) {
|
|
6427
|
-
const current = await w.getChainId();
|
|
6428
|
-
if (current !== target) {
|
|
6429
|
-
try {
|
|
6430
|
-
await w.switchChain(target);
|
|
6431
|
-
} catch {
|
|
6432
|
-
}
|
|
6433
|
-
}
|
|
6434
|
-
}
|
|
6435
|
-
if (w.type === "eip1193") {
|
|
6436
|
-
const from = await w.getAddress();
|
|
6437
|
-
const hexValue = value ? `0x${value.toString(16)}` : "0x0";
|
|
6438
|
-
const params = {
|
|
6439
|
-
from,
|
|
6440
|
-
to,
|
|
6441
|
-
data,
|
|
6442
|
-
value: hexValue
|
|
6443
|
-
};
|
|
6444
|
-
if (Number.isFinite(target)) {
|
|
6445
|
-
params.chainId = `0x${target.toString(16)}`;
|
|
6446
|
-
}
|
|
6447
|
-
const hash = await w.request({
|
|
6448
|
-
method: "eth_sendTransaction",
|
|
6449
|
-
params: [params]
|
|
6450
|
-
});
|
|
6451
|
-
return hash;
|
|
6452
|
-
}
|
|
6453
|
-
const response = await w.sendTransaction({
|
|
6454
|
-
to,
|
|
6455
|
-
data,
|
|
6456
|
-
value,
|
|
6457
|
-
chainId: Number.isFinite(target) ? target : void 0,
|
|
6458
|
-
...validatedSponsorship ? {
|
|
6459
|
-
paymasterAndData: validatedSponsorship.paymasterAndData
|
|
6460
|
-
} : {}
|
|
6461
|
-
});
|
|
6462
|
-
return response.hash;
|
|
6463
|
-
}
|
|
6464
|
-
if (isSerializedSolanaTxRequest(txReq)) {
|
|
6465
|
-
if (w.ecosystem !== "solana") {
|
|
6466
|
-
throw new Error("A Solana wallet is required for this route");
|
|
6467
|
-
}
|
|
6468
|
-
const { getSharedRegistry: getSharedRegistry2 } = await Promise.resolve().then(() => (init_registryClient(), registryClient_exports));
|
|
6469
|
-
const registry = getSharedRegistry2();
|
|
6470
|
-
await registry.ensureChainsLoaded();
|
|
6471
|
-
const chain = registry.chain(
|
|
6472
|
-
String(fallbackChainId ?? txReq.chainId ?? "")
|
|
6473
|
-
);
|
|
6474
|
-
return w.sendSerializedTransaction(
|
|
6475
|
-
txReq.data,
|
|
6476
|
-
backendChainId(chain, fallbackChainId ?? txReq.chainId)
|
|
6477
|
-
);
|
|
6478
|
-
}
|
|
6479
|
-
throw new Error("Invalid route transaction payload");
|
|
6480
|
-
}
|
|
6481
|
-
async function runTopUp(params) {
|
|
6482
|
-
const w = walletManager.wallet;
|
|
6483
|
-
if (!w) throw new Error("Trustware.wallet not configured");
|
|
6484
|
-
const { getSharedRegistry: getSharedRegistry2 } = await Promise.resolve().then(() => (init_registryClient(), registryClient_exports));
|
|
6485
|
-
const reg = getSharedRegistry2();
|
|
6486
|
-
await reg.ensureLoaded();
|
|
6487
|
-
const fromAddress = await w.getAddress();
|
|
6488
|
-
const currentChainRef = w.ecosystem === "evm" ? String(await w.getChainId()) : await w.getChainKey?.() ?? "solana-mainnet-beta";
|
|
6489
|
-
const originalChain = w.ecosystem === "evm" ? await w.getChainId() : void 0;
|
|
6490
|
-
const fromChain = params.fromChain ?? currentChainRef;
|
|
6491
|
-
const { TrustwareConfigStore: TrustwareConfigStore2 } = await Promise.resolve().then(() => (init_store(), store_exports));
|
|
6492
|
-
const cfg = TrustwareConfigStore2.get();
|
|
6493
|
-
const toChain = params.toChain ?? String(cfg.routes.toChain);
|
|
6494
|
-
const fromToken = reg.resolveToken(
|
|
6495
|
-
fromChain,
|
|
6496
|
-
params.fromToken ?? cfg.routes.fromToken ?? void 0
|
|
6497
|
-
) ?? params.fromToken;
|
|
6498
|
-
const toToken = reg.resolveToken(
|
|
6499
|
-
toChain,
|
|
6500
|
-
params.toToken ?? cfg.routes.toToken ?? void 0
|
|
6501
|
-
) ?? params.toToken;
|
|
6502
|
-
if (!fromToken || !toToken) {
|
|
6503
|
-
throw new Error("Unable to resolve route tokens");
|
|
6504
|
-
}
|
|
6505
|
-
try {
|
|
6506
|
-
const build = await buildRoute({
|
|
6507
|
-
fromChain,
|
|
6508
|
-
toChain,
|
|
6509
|
-
fromToken,
|
|
6510
|
-
toToken,
|
|
6511
|
-
fromAmount: String(params.fromAmount),
|
|
6512
|
-
fromAddress,
|
|
6513
|
-
toAddress: params.toAddress ?? cfg.routes.toAddress ?? cfg.routes.fromAddress ?? fromAddress,
|
|
6514
|
-
slippage: cfg.routes.defaultSlippage
|
|
6515
|
-
});
|
|
6516
|
-
const hash = await sendRouteTransaction(build, fromChain);
|
|
6517
|
-
await submitReceipt(build.intentId, hash);
|
|
6518
|
-
return await pollStatus(build.intentId);
|
|
6519
|
-
} catch (e2) {
|
|
6520
|
-
if (isUserRejected(e2)) throw new Error("Transaction cancelled by user");
|
|
6521
|
-
throw e2;
|
|
6522
|
-
} finally {
|
|
6523
|
-
try {
|
|
6524
|
-
if (w.ecosystem === "evm" && originalChain && originalChain !== Number(fromChain)) {
|
|
6525
|
-
await w.switchChain(originalChain);
|
|
6526
|
-
}
|
|
6527
|
-
} catch {
|
|
6528
|
-
}
|
|
6529
|
-
}
|
|
6530
|
-
}
|
|
6531
|
-
var init_tx = __esm({
|
|
6532
|
-
"src/core/tx.ts"() {
|
|
6533
|
-
"use strict";
|
|
6534
|
-
init_wallets();
|
|
6535
|
-
init_routes();
|
|
6536
|
-
}
|
|
6537
|
-
});
|
|
6538
|
-
|
|
6539
6712
|
// src/core/index.ts
|
|
6540
6713
|
var _lastValidatedKey, Trustware;
|
|
6541
6714
|
var init_core = __esm({
|
|
@@ -6678,6 +6851,7 @@ var init_core = __esm({
|
|
|
6678
6851
|
buildRoute,
|
|
6679
6852
|
buildDepositAddress,
|
|
6680
6853
|
submitReceipt,
|
|
6854
|
+
submitStepReceipt,
|
|
6681
6855
|
getStatus,
|
|
6682
6856
|
pollStatus,
|
|
6683
6857
|
getBalances,
|