0xtrails 0.16.1 → 0.16.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/dist/package.js +1 -1
- package/dist/prepareSend.d.ts.map +1 -1
- package/dist/prepareSend.js +77 -77
- package/dist/umd/trails.min.js +2 -2
- package/package.json +3 -3
package/dist/package.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var t = "0xtrails", e = "0.16.
|
|
1
|
+
var t = "0xtrails", e = "0.16.2", i = "SDK for Trails", s = "module", a = "./dist/index.js", r = "./dist/index.js", d = "./dist/index.d.ts";
|
|
2
2
|
var c = { access: "public" }, o = ["dist"], n = {
|
|
3
3
|
build: "rimraf dist && pnpm run build:css && pnpm run build:vite && pnpm run build:patch && pnpm run build:umd",
|
|
4
4
|
"build:patch": "node scripts/apply-react-patch.cjs",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prepareSend.d.ts","sourceRoot":"","sources":["../src/prepareSend.ts"],"names":[],"mappings":"AAkBA,OAAO,EAEL,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EAIvB,MAAM,8BAA8B,CAAA;AASrC,YAAY,EACV,kBAAkB,EAClB,eAAe,EACf,gBAAgB,EAChB,iBAAiB,EACjB,UAAU,GACX,MAAM,8BAA8B,CAAA;AAGrC,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAA;AAGvE,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAA;AAsB3D,wBAAsB,WAAW,CAC/B,OAAO,EAAE,kBAAkB,GAC1B,OAAO,CAAC,iBAAiB,CAAC,
|
|
1
|
+
{"version":3,"file":"prepareSend.d.ts","sourceRoot":"","sources":["../src/prepareSend.ts"],"names":[],"mappings":"AAkBA,OAAO,EAEL,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EAIvB,MAAM,8BAA8B,CAAA;AASrC,YAAY,EACV,kBAAkB,EAClB,eAAe,EACf,gBAAgB,EAChB,iBAAiB,EACjB,UAAU,GACX,MAAM,8BAA8B,CAAA;AAGrC,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAA;AAGvE,OAAO,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAA;AAsB3D,wBAAsB,WAAW,CAC/B,OAAO,EAAE,kBAAkB,GAC1B,OAAO,CAAC,iBAAiB,CAAC,CAyZ5B;AAGD,YAAY,EACV,aAAa,EACb,SAAS,EACT,OAAO,EACP,KAAK,EACL,cAAc,EACd,UAAU,EACV,iBAAiB,GAClB,MAAM,qBAAqB,CAAA;AAC5B,YAAY,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAA;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAA;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAG7C,OAAO,EACL,iBAAiB,EACjB,8BAA8B,EAC9B,wBAAwB,EACxB,2BAA2B,EAC3B,WAAW,EACX,4BAA4B,EAC5B,wBAAwB,EACxB,SAAS,GACV,MAAM,8BAA8B,CAAA"}
|
package/dist/prepareSend.js
CHANGED
|
@@ -2,38 +2,38 @@ import { logger as p } from "./logger/index.js";
|
|
|
2
2
|
import { getChainInfo as he, getPublicClient as Ce } from "./chains.js";
|
|
3
3
|
import { abortControllerRegistry as Pe } from "./abortController.js";
|
|
4
4
|
import { getIsCustomCalldata as ke } from "./contractUtils.js";
|
|
5
|
-
import { addressEqual as
|
|
6
|
-
import { TRAILS_CONTRACTS as
|
|
5
|
+
import { addressEqual as g, isNativeToken as F, isZeroAccount as $ } from "./utils/address.js";
|
|
6
|
+
import { TRAILS_CONTRACTS as W } from "./contractConstants.js";
|
|
7
7
|
import { getWethAddress as ve } from "./tokenRegistry.js";
|
|
8
8
|
import { trackPaymentError as Se, trackPaymentStarted as we } from "./analytics.js";
|
|
9
9
|
import { getSlippageToleranceValue as Ee } from "./widget/components/SlippageToleranceSettings.js";
|
|
10
10
|
import { getERC20TransferData as Ie } from "./utils.js";
|
|
11
11
|
import { getTokenPrices as Ue } from "./query/price.queries.js";
|
|
12
|
-
import { PlaceholderError as
|
|
12
|
+
import { PlaceholderError as _e, TRAILS_ROUTER_PLACEHOLDER_AMOUNT as be, calldataHasPlaceholder as ye, replacePlaceholderInCalldata as De } from "./placeholder.js";
|
|
13
13
|
import { resolveDefaultIntentProtocol as Oe } from "./intentProtocolResolver.js";
|
|
14
|
-
import { TradeType as
|
|
14
|
+
import { TradeType as u } from "./transactionIntent/types.js";
|
|
15
15
|
import { isSameChain as Re, isSameToken as Fe } from "./transactionIntent/validators.js";
|
|
16
16
|
import "./transactionIntent/quote/feeExtractors.js";
|
|
17
17
|
import "./transactionIntent/quote/normalizeQuote.js";
|
|
18
18
|
import { handleIntent as Ne } from "./transactionIntent/handlers/intentHandler.js";
|
|
19
|
-
import { DestinationEncodingError as
|
|
19
|
+
import { DestinationEncodingError as z, encodeDestinationForIntentProtocol as qe } from "./intentProtocolEncoding.js";
|
|
20
20
|
import "./quoteError.js";
|
|
21
21
|
import "./hooks/useQuote.js";
|
|
22
22
|
import { IntentProtocolVersion as S, RouteProvider as Le, RouteProvider as Tt } from "@0xtrails/api";
|
|
23
23
|
function Me(t) {
|
|
24
|
-
if (t instanceof
|
|
25
|
-
if (t.code === "MULTIPLE_AMOUNT_SLOTS") return new
|
|
26
|
-
if (t.code === "INVALID_AMOUNT_OFFSET") return new
|
|
24
|
+
if (t instanceof _e) {
|
|
25
|
+
if (t.code === "MULTIPLE_AMOUNT_SLOTS") return new z("MULTIPLE_AMOUNT_SLOTS", t.message, t);
|
|
26
|
+
if (t.code === "INVALID_AMOUNT_OFFSET") return new z("UNSAFE_PLACEHOLDER_MATCH", t.message, t);
|
|
27
27
|
}
|
|
28
28
|
return t;
|
|
29
29
|
}
|
|
30
30
|
async function At(t) {
|
|
31
31
|
p.console.log("[trails-sdk] New quote generated - aborting all existing operations"), Pe.abortAll();
|
|
32
|
-
const { account:
|
|
32
|
+
const { account: a, originTokenAddress: i, originChainId: r, originTokenBalance: K, destinationChainId: n, recipient: T, destinationTokenAddress: o, swapAmount: s, tradeType: d = u.EXACT_OUTPUT, originTokenSymbol: N, destinationTokenSymbol: A, client: Q, trailsClient: w, destinationApproveAddress: j, destinationCalldata: h, onTransactionStateChange: B, sourceTokenDecimals: E, destinationTokenDecimals: I, slippageTolerance: q, originNativeTokenPriceUsd: Z, swapProvider: G, bridgeProvider: L, swapProviderFallback: J, bridgeProviderFallback: Y, fundMethod: ee, mode: U, checkoutOnHandlers: _, selectedFeeOption: te, walletId: M, abortSignal: re, commitIntentFn: oe, executeIntentFn: ie, sequenceProjectAccessKey: ne, sequenceIndexerUrl: ae, isSmartWallet: se, isSenderContractOnOrigin: de, trailsApiKey: le, trailsApiUrl: ce, sequenceMetadataUrl: me, onramp: pe, refundAddress: ue, isMultiCallEncoding: C, intentProtocolVersion: b } = t;
|
|
33
33
|
let { sourceTokenPriceUsd: P, destinationTokenPriceUsd: k } = t;
|
|
34
|
-
const y =
|
|
35
|
-
if (!
|
|
36
|
-
if (!
|
|
34
|
+
const y = ee ?? "wallet";
|
|
35
|
+
if (!a?.address || $(a.address)) throw new Error("Account address is required and must not be the zero address");
|
|
36
|
+
if (!s || s === "0") throw new Error("swapAmount is required and must be a positive numeric value");
|
|
37
37
|
if (!r) throw new Error("Origin chain ID is required");
|
|
38
38
|
if (!n) throw new Error("Destination chain ID is required");
|
|
39
39
|
if (t.originPublicClient) {
|
|
@@ -44,160 +44,160 @@ async function At(t) {
|
|
|
44
44
|
const e = t.destinationPublicClient?.chain?.id;
|
|
45
45
|
if (e !== n) throw new Error(`Destination public client chain ID mismatch: expected ${n}, got ${e}`);
|
|
46
46
|
}
|
|
47
|
-
const
|
|
47
|
+
const fe = q !== void 0 ? q : Ee("0.01");
|
|
48
48
|
if (!E) throw new Error("Source token decimals not provided");
|
|
49
49
|
if (!I) throw new Error("Destination token decimals not provided");
|
|
50
50
|
const { intentProtocol: l } = await Oe({
|
|
51
51
|
trailsClient: w,
|
|
52
|
-
override:
|
|
52
|
+
override: b
|
|
53
53
|
});
|
|
54
|
-
let
|
|
55
|
-
if (
|
|
56
|
-
let
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
let
|
|
54
|
+
let c = ke(h);
|
|
55
|
+
if ($(T)) throw new Error("Recipient address cannot be zero address");
|
|
56
|
+
let f = T, v = j, m = h, D = G;
|
|
57
|
+
const x = Re(r, n), ge = Fe(i, o), Te = x && ge, O = ve(r), H = x && !!O && (F(i) && g(o, O) || g(i, O) && F(o)) && g(T, a.address);
|
|
58
|
+
H && (f = a.address, D = Le.WETH, c || (m = void 0, c = !1));
|
|
59
|
+
let V;
|
|
60
60
|
try {
|
|
61
|
-
|
|
61
|
+
V = ye(h);
|
|
62
62
|
} catch (e) {
|
|
63
63
|
throw Me(e);
|
|
64
64
|
}
|
|
65
|
-
if (
|
|
65
|
+
if (c && V && !C && d === u.EXACT_OUTPUT && (m = De(m || "", s), p.console.log("[trails-sdk] Same-chain same-token: Replaced placeholder with actual amount in calldata", { swapAmount: s })), C && c && b && b !== S.v1_5)
|
|
66
66
|
throw new Error("Multicall encoding (to.calls) requires v1.5 protocol. v1 is not supported.");
|
|
67
|
-
if (!
|
|
67
|
+
if (!c && d === u.EXACT_INPUT && !F(o) && !Te && !H && (m = Ie(T, BigInt(be)), f = o, c = !0, p.console.log("[trails-sdk] Setting ERC20 transfer calldata for destination metatxn tracking")), p.console.log("[trails-sdk] [intent-protocol] === Protocol Version Selected ===", {
|
|
68
68
|
intentProtocol: l,
|
|
69
69
|
isV1: l === S.v1,
|
|
70
70
|
isV1_5: l === S.v1_5
|
|
71
|
-
}),
|
|
71
|
+
}), c && d === u.EXACT_INPUT && !C) {
|
|
72
72
|
p.console.log("[trails-sdk] [intent-protocol] Calldata wrapping required for custom calldata", {
|
|
73
73
|
intentProtocol: l,
|
|
74
74
|
wrapperType: l === S.v1 ? "TrailsRouter" : "TrailsUtils (Hydrate)"
|
|
75
75
|
});
|
|
76
76
|
const e = qe({
|
|
77
77
|
intentProtocol: l,
|
|
78
|
-
destinationAddress:
|
|
78
|
+
destinationAddress: f,
|
|
79
79
|
destinationCalldata: m ?? "0x",
|
|
80
80
|
destinationApprovalAddress: v,
|
|
81
|
-
isExactInput:
|
|
82
|
-
hasCustomCalldata:
|
|
83
|
-
swapAmount:
|
|
81
|
+
isExactInput: d === u.EXACT_INPUT,
|
|
82
|
+
hasCustomCalldata: c,
|
|
83
|
+
swapAmount: s,
|
|
84
84
|
originChainId: r,
|
|
85
85
|
destinationChainId: n,
|
|
86
86
|
originTokenAddress: i,
|
|
87
87
|
destinationTokenAddress: o,
|
|
88
|
-
trailsRouterAddress:
|
|
89
|
-
trailsUtilsAddress:
|
|
88
|
+
trailsRouterAddress: W.trailsRouterAddress,
|
|
89
|
+
trailsUtilsAddress: W.trailsUtilsAddress
|
|
90
90
|
});
|
|
91
|
-
|
|
91
|
+
f = e.destinationAddress, m = e.destinationCalldata, e.destinationApprovalAddress && (v = e.destinationApprovalAddress), p.console.log("[trails-sdk] [intent-protocol] Destination encoding", {
|
|
92
92
|
intentProtocol: l,
|
|
93
93
|
strategy: {
|
|
94
94
|
none: "none",
|
|
95
95
|
v1_trails_router: "TrailsRouter",
|
|
96
96
|
v1_5_trails_utils_hydrate: "TrailsUtils (Hydrate)"
|
|
97
97
|
}[e.strategy],
|
|
98
|
-
effectiveDestinationAddress:
|
|
98
|
+
effectiveDestinationAddress: f,
|
|
99
99
|
hasApprovalAddress: !!v
|
|
100
100
|
});
|
|
101
101
|
}
|
|
102
102
|
if (!P || !k) try {
|
|
103
103
|
const e = await Ue(w, [{
|
|
104
|
-
tokenSymbol:
|
|
104
|
+
tokenSymbol: N,
|
|
105
105
|
tokenAddress: i,
|
|
106
106
|
chainId: r
|
|
107
107
|
}, {
|
|
108
|
-
tokenSymbol:
|
|
108
|
+
tokenSymbol: A,
|
|
109
109
|
tokenAddress: o,
|
|
110
110
|
chainId: n
|
|
111
111
|
}]);
|
|
112
|
-
P = e.find((
|
|
112
|
+
P = e.find((R) => g(R.token.tokenAddress, i))?.priceUsd ?? 0, k = e.find((R) => g(R.token.tokenAddress, o))?.priceUsd ?? 0;
|
|
113
113
|
} catch (e) {
|
|
114
114
|
p.console.error("[trails-sdk] Error getting token prices:", e);
|
|
115
115
|
}
|
|
116
116
|
we({
|
|
117
|
-
userAddress:
|
|
117
|
+
userAddress: a.address,
|
|
118
118
|
originChainId: r,
|
|
119
119
|
destinationChainId: n,
|
|
120
120
|
originTokenAddress: i,
|
|
121
|
-
originTokenAmount:
|
|
121
|
+
originTokenAmount: d === u.EXACT_INPUT ? s : void 0,
|
|
122
122
|
originTokenDecimals: E,
|
|
123
123
|
destinationTokenAddress: o,
|
|
124
|
-
destinationTokenSymbol:
|
|
125
|
-
destinationTokenAmount:
|
|
124
|
+
destinationTokenSymbol: A || "",
|
|
125
|
+
destinationTokenAmount: d === u.EXACT_OUTPUT ? s : void 0,
|
|
126
126
|
destinationTokenDecimals: I,
|
|
127
127
|
mode: U,
|
|
128
128
|
fundMethod: y,
|
|
129
129
|
sourceTokenPriceUsd: P?.toString(),
|
|
130
130
|
destinationTokenPriceUsd: k?.toString(),
|
|
131
|
-
tradeType:
|
|
131
|
+
tradeType: d.toString(),
|
|
132
132
|
swapProvider: D || void 0,
|
|
133
|
-
bridgeProvider:
|
|
134
|
-
onramp:
|
|
135
|
-
walletId:
|
|
136
|
-
destinationCalldata:
|
|
133
|
+
bridgeProvider: L || void 0,
|
|
134
|
+
onramp: pe,
|
|
135
|
+
walletId: M,
|
|
136
|
+
destinationCalldata: h
|
|
137
137
|
});
|
|
138
138
|
const X = he(r);
|
|
139
139
|
if (!X)
|
|
140
140
|
throw Se({
|
|
141
141
|
error: `Chain ${r} not found`,
|
|
142
|
-
userAddress:
|
|
142
|
+
userAddress: a.address,
|
|
143
143
|
mode: U,
|
|
144
144
|
fundMethod: y,
|
|
145
145
|
originChainId: r,
|
|
146
146
|
destinationChainId: n,
|
|
147
147
|
originTokenAddress: i,
|
|
148
148
|
destinationTokenAddress: o,
|
|
149
|
-
destinationTokenSymbol:
|
|
149
|
+
destinationTokenSymbol: A
|
|
150
150
|
}), new Error(`Chain ${r} not found`);
|
|
151
151
|
const Ae = t.originPublicClient ?? Ce(r);
|
|
152
|
-
return
|
|
152
|
+
return _?.triggerCheckoutStart && _.triggerCheckoutStart(), Ne({
|
|
153
153
|
queryClient: t.queryClient,
|
|
154
|
-
mainSignerAddress:
|
|
154
|
+
mainSignerAddress: a.address,
|
|
155
155
|
originChainId: r,
|
|
156
156
|
originTokenAddress: i,
|
|
157
|
-
originTokenBalance:
|
|
157
|
+
originTokenBalance: K,
|
|
158
158
|
originTokenDecimals: E,
|
|
159
|
-
originTokenSymbol:
|
|
159
|
+
originTokenSymbol: N,
|
|
160
160
|
destinationChainId: n,
|
|
161
161
|
destinationTokenAddress: o,
|
|
162
|
-
destinationTokenSymbol:
|
|
162
|
+
destinationTokenSymbol: A,
|
|
163
163
|
destinationTokenDecimals: I,
|
|
164
|
-
swapAmount:
|
|
165
|
-
recipient:
|
|
164
|
+
swapAmount: s,
|
|
165
|
+
recipient: f,
|
|
166
166
|
destinationApproveAddress: v,
|
|
167
167
|
destinationCalldata: m,
|
|
168
|
-
walletClient:
|
|
168
|
+
walletClient: Q,
|
|
169
169
|
publicClient: Ae,
|
|
170
|
-
account:
|
|
170
|
+
account: a,
|
|
171
171
|
chain: X,
|
|
172
|
-
onTransactionStateChange:
|
|
172
|
+
onTransactionStateChange: B,
|
|
173
173
|
transactionStates: [],
|
|
174
174
|
trailsClient: w,
|
|
175
175
|
sourceTokenPriceUsd: P,
|
|
176
176
|
destinationTokenPriceUsd: k,
|
|
177
|
-
originNativeTokenPriceUsd:
|
|
178
|
-
slippageTolerance:
|
|
179
|
-
tradeType:
|
|
177
|
+
originNativeTokenPriceUsd: Z,
|
|
178
|
+
slippageTolerance: fe,
|
|
179
|
+
tradeType: d,
|
|
180
180
|
swapProvider: D,
|
|
181
|
-
bridgeProvider:
|
|
182
|
-
swapProviderFallback:
|
|
183
|
-
bridgeProviderFallback:
|
|
181
|
+
bridgeProvider: L,
|
|
182
|
+
swapProviderFallback: J,
|
|
183
|
+
bridgeProviderFallback: Y,
|
|
184
184
|
fundMethod: y,
|
|
185
185
|
mode: U,
|
|
186
|
-
checkoutOnHandlers:
|
|
187
|
-
selectedFeeOption:
|
|
188
|
-
walletId:
|
|
189
|
-
abortSignal:
|
|
190
|
-
commitIntentFn:
|
|
191
|
-
executeIntentFn:
|
|
192
|
-
sequenceProjectAccessKey:
|
|
193
|
-
sequenceIndexerUrl:
|
|
194
|
-
isSmartWallet:
|
|
195
|
-
isSenderContractOnOrigin:
|
|
196
|
-
trailsApiKey:
|
|
197
|
-
trailsApiUrl:
|
|
198
|
-
sequenceMetadataUrl:
|
|
199
|
-
refundAddress:
|
|
200
|
-
isMultiCallEncoding:
|
|
186
|
+
checkoutOnHandlers: _,
|
|
187
|
+
selectedFeeOption: te,
|
|
188
|
+
walletId: M,
|
|
189
|
+
abortSignal: re,
|
|
190
|
+
commitIntentFn: oe,
|
|
191
|
+
executeIntentFn: ie,
|
|
192
|
+
sequenceProjectAccessKey: ne,
|
|
193
|
+
sequenceIndexerUrl: ae,
|
|
194
|
+
isSmartWallet: se,
|
|
195
|
+
isSenderContractOnOrigin: de,
|
|
196
|
+
trailsApiKey: le,
|
|
197
|
+
trailsApiUrl: ce,
|
|
198
|
+
sequenceMetadataUrl: me,
|
|
199
|
+
refundAddress: ue,
|
|
200
|
+
isMultiCallEncoding: C,
|
|
201
201
|
intentProtocolVersion: l
|
|
202
202
|
});
|
|
203
203
|
}
|