@aegis-engine/core 0.1.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 +21 -0
- package/README.md +42 -0
- package/dist/abis.d.ts +205 -0
- package/dist/actions/directPoolSwap.d.ts +39 -0
- package/dist/actions/kyberSwap.d.ts +38 -0
- package/dist/actions/types.d.ts +17 -0
- package/dist/actions/wallet.d.ts +17 -0
- package/dist/address.d.ts +5 -0
- package/dist/aegis-core.js +2043 -0
- package/dist/config.d.ts +119 -0
- package/dist/encoding.d.ts +57 -0
- package/dist/errors.d.ts +3 -0
- package/dist/index.d.ts +28 -0
- package/dist/metadata.d.ts +25 -0
- package/dist/permit.d.ts +70 -0
- package/dist/polling.d.ts +3 -0
- package/dist/quote/aggregatedSwapQuote.d.ts +5 -0
- package/dist/quote.d.ts +59 -0
- package/dist/services/kyberSwap.d.ts +84 -0
- package/dist/swap/authorizePermit.d.ts +29 -0
- package/dist/swap/executeSwapTransaction.d.ts +38 -0
- package/dist/swap/gas.d.ts +8 -0
- package/dist/swap/types.d.ts +28 -0
- package/dist/transactionProgress.d.ts +55 -0
- package/dist/types/aggregatedSwap.d.ts +29 -0
- package/dist/wallet.d.ts +34 -0
- package/package.json +38 -0
|
@@ -0,0 +1,2043 @@
|
|
|
1
|
+
var Me = Object.defineProperty;
|
|
2
|
+
var Ue = (e, t, n) => t in e ? Me(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
|
|
3
|
+
var I = (e, t, n) => Ue(e, typeof t != "symbol" ? t + "" : t, n);
|
|
4
|
+
import { encodeAbiParameters as T, keccak256 as Ne, encodeFunctionData as q, getAddress as m, createWalletClient as P, custom as D, erc20Abi as z, http as Fe, createPublicClient as Be, fallback as We, isAddress as Ge } from "viem";
|
|
5
|
+
import { mainnet as Ke } from "viem/chains";
|
|
6
|
+
function K(e) {
|
|
7
|
+
return (e == null ? void 0 : e.toLowerCase()) ?? "";
|
|
8
|
+
}
|
|
9
|
+
function A(e, t) {
|
|
10
|
+
return e.toLowerCase() === t.toLowerCase();
|
|
11
|
+
}
|
|
12
|
+
function Le(e, t) {
|
|
13
|
+
return e === null || t === null ? e === t : A(e, t);
|
|
14
|
+
}
|
|
15
|
+
function oe(e, t) {
|
|
16
|
+
return e.toLowerCase() === t.toLowerCase();
|
|
17
|
+
}
|
|
18
|
+
const V = [
|
|
19
|
+
{
|
|
20
|
+
type: "function",
|
|
21
|
+
name: "execute",
|
|
22
|
+
stateMutability: "payable",
|
|
23
|
+
inputs: [
|
|
24
|
+
{
|
|
25
|
+
name: "batches",
|
|
26
|
+
type: "tuple[]",
|
|
27
|
+
components: [
|
|
28
|
+
{ name: "requiresV4Unlock", type: "bool" },
|
|
29
|
+
{ name: "actions", type: "bytes" },
|
|
30
|
+
{ name: "params", type: "bytes[]" }
|
|
31
|
+
]
|
|
32
|
+
},
|
|
33
|
+
{ name: "deadline", type: "uint256" }
|
|
34
|
+
],
|
|
35
|
+
outputs: []
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
type: "function",
|
|
39
|
+
name: "multicall",
|
|
40
|
+
stateMutability: "payable",
|
|
41
|
+
inputs: [{ name: "data", type: "bytes[]" }],
|
|
42
|
+
outputs: [{ name: "results", type: "bytes[]" }]
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
type: "function",
|
|
46
|
+
name: "permitBatch",
|
|
47
|
+
stateMutability: "payable",
|
|
48
|
+
inputs: [
|
|
49
|
+
{ name: "owner", type: "address" },
|
|
50
|
+
{
|
|
51
|
+
name: "permitBatch",
|
|
52
|
+
type: "tuple",
|
|
53
|
+
components: [
|
|
54
|
+
{
|
|
55
|
+
name: "details",
|
|
56
|
+
type: "tuple[]",
|
|
57
|
+
components: [
|
|
58
|
+
{ name: "token", type: "address" },
|
|
59
|
+
{ name: "amount", type: "uint160" },
|
|
60
|
+
{ name: "expiration", type: "uint48" },
|
|
61
|
+
{ name: "nonce", type: "uint48" }
|
|
62
|
+
]
|
|
63
|
+
},
|
|
64
|
+
{ name: "spender", type: "address" },
|
|
65
|
+
{ name: "sigDeadline", type: "uint256" }
|
|
66
|
+
]
|
|
67
|
+
},
|
|
68
|
+
{ name: "signature", type: "bytes" }
|
|
69
|
+
],
|
|
70
|
+
outputs: []
|
|
71
|
+
}
|
|
72
|
+
], ae = [
|
|
73
|
+
{
|
|
74
|
+
type: "function",
|
|
75
|
+
name: "approve",
|
|
76
|
+
stateMutability: "nonpayable",
|
|
77
|
+
inputs: [
|
|
78
|
+
{ name: "token", type: "address" },
|
|
79
|
+
{ name: "spender", type: "address" },
|
|
80
|
+
{ name: "amount", type: "uint160" },
|
|
81
|
+
{ name: "expiration", type: "uint48" }
|
|
82
|
+
],
|
|
83
|
+
outputs: []
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
type: "function",
|
|
87
|
+
name: "allowance",
|
|
88
|
+
stateMutability: "view",
|
|
89
|
+
inputs: [
|
|
90
|
+
{ name: "owner", type: "address" },
|
|
91
|
+
{ name: "token", type: "address" },
|
|
92
|
+
{ name: "spender", type: "address" }
|
|
93
|
+
],
|
|
94
|
+
outputs: [
|
|
95
|
+
{ name: "amount", type: "uint160" },
|
|
96
|
+
{ name: "expiration", type: "uint48" },
|
|
97
|
+
{ name: "nonce", type: "uint48" }
|
|
98
|
+
]
|
|
99
|
+
}
|
|
100
|
+
], Z = [
|
|
101
|
+
{
|
|
102
|
+
type: "function",
|
|
103
|
+
name: "quoteExactInputSingle",
|
|
104
|
+
stateMutability: "nonpayable",
|
|
105
|
+
inputs: [
|
|
106
|
+
{
|
|
107
|
+
name: "params",
|
|
108
|
+
type: "tuple",
|
|
109
|
+
components: [
|
|
110
|
+
{
|
|
111
|
+
name: "poolKey",
|
|
112
|
+
type: "tuple",
|
|
113
|
+
components: [
|
|
114
|
+
{ name: "currency0", type: "address" },
|
|
115
|
+
{ name: "currency1", type: "address" },
|
|
116
|
+
{ name: "fee", type: "uint24" },
|
|
117
|
+
{ name: "tickSpacing", type: "int24" },
|
|
118
|
+
{ name: "hooks", type: "address" }
|
|
119
|
+
]
|
|
120
|
+
},
|
|
121
|
+
{ name: "zeroForOne", type: "bool" },
|
|
122
|
+
{ name: "exactAmount", type: "uint128" },
|
|
123
|
+
{ name: "hookData", type: "bytes" }
|
|
124
|
+
]
|
|
125
|
+
}
|
|
126
|
+
],
|
|
127
|
+
outputs: [
|
|
128
|
+
{ name: "amountOut", type: "uint256" },
|
|
129
|
+
{ name: "gasEstimate", type: "uint256" }
|
|
130
|
+
]
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
type: "function",
|
|
134
|
+
name: "quoteExactOutputSingle",
|
|
135
|
+
stateMutability: "nonpayable",
|
|
136
|
+
inputs: [
|
|
137
|
+
{
|
|
138
|
+
name: "params",
|
|
139
|
+
type: "tuple",
|
|
140
|
+
components: [
|
|
141
|
+
{
|
|
142
|
+
name: "poolKey",
|
|
143
|
+
type: "tuple",
|
|
144
|
+
components: [
|
|
145
|
+
{ name: "currency0", type: "address" },
|
|
146
|
+
{ name: "currency1", type: "address" },
|
|
147
|
+
{ name: "fee", type: "uint24" },
|
|
148
|
+
{ name: "tickSpacing", type: "int24" },
|
|
149
|
+
{ name: "hooks", type: "address" }
|
|
150
|
+
]
|
|
151
|
+
},
|
|
152
|
+
{ name: "zeroForOne", type: "bool" },
|
|
153
|
+
{ name: "exactAmount", type: "uint128" },
|
|
154
|
+
{ name: "hookData", type: "bytes" }
|
|
155
|
+
]
|
|
156
|
+
}
|
|
157
|
+
],
|
|
158
|
+
outputs: [
|
|
159
|
+
{ name: "amountIn", type: "uint256" },
|
|
160
|
+
{ name: "gasEstimate", type: "uint256" }
|
|
161
|
+
]
|
|
162
|
+
}
|
|
163
|
+
], ie = 0n, $e = 2n ** 128n - 1n, O = {
|
|
164
|
+
SWAP_EXACT_IN_SINGLE: 6,
|
|
165
|
+
SWAP_EXACT_OUT_SINGLE: 8,
|
|
166
|
+
SETTLE: 11,
|
|
167
|
+
TAKE: 14,
|
|
168
|
+
TAKE_PORTION: 16
|
|
169
|
+
}, re = {
|
|
170
|
+
name: "poolKey",
|
|
171
|
+
type: "tuple",
|
|
172
|
+
components: [
|
|
173
|
+
{ name: "currency0", type: "address" },
|
|
174
|
+
{ name: "currency1", type: "address" },
|
|
175
|
+
{ name: "fee", type: "uint24" },
|
|
176
|
+
{ name: "tickSpacing", type: "int24" },
|
|
177
|
+
{ name: "hooks", type: "address" }
|
|
178
|
+
]
|
|
179
|
+
}, qe = [
|
|
180
|
+
{
|
|
181
|
+
name: "params",
|
|
182
|
+
type: "tuple",
|
|
183
|
+
components: [
|
|
184
|
+
re,
|
|
185
|
+
{ name: "zeroForOne", type: "bool" },
|
|
186
|
+
{ name: "amountIn", type: "uint128" },
|
|
187
|
+
{ name: "amountOutMinimum", type: "uint128" },
|
|
188
|
+
{ name: "hookData", type: "bytes" }
|
|
189
|
+
]
|
|
190
|
+
}
|
|
191
|
+
], ze = [
|
|
192
|
+
{
|
|
193
|
+
name: "params",
|
|
194
|
+
type: "tuple",
|
|
195
|
+
components: [
|
|
196
|
+
re,
|
|
197
|
+
{ name: "zeroForOne", type: "bool" },
|
|
198
|
+
{ name: "amountOut", type: "uint128" },
|
|
199
|
+
{ name: "amountInMaximum", type: "uint128" },
|
|
200
|
+
{ name: "hookData", type: "bytes" }
|
|
201
|
+
]
|
|
202
|
+
}
|
|
203
|
+
], Ve = [
|
|
204
|
+
{ name: "currency", type: "address" },
|
|
205
|
+
{ name: "amount", type: "uint256" },
|
|
206
|
+
{ name: "payerIsUser", type: "bool" }
|
|
207
|
+
], ce = [
|
|
208
|
+
{ name: "currency", type: "address" },
|
|
209
|
+
{ name: "recipient", type: "address" },
|
|
210
|
+
{ name: "amount", type: "uint256" }
|
|
211
|
+
], He = [
|
|
212
|
+
{ name: "currency", type: "address" },
|
|
213
|
+
{ name: "recipient", type: "address" },
|
|
214
|
+
{ name: "bips", type: "uint256" }
|
|
215
|
+
];
|
|
216
|
+
function je(e) {
|
|
217
|
+
return `0x${e.map((t) => t.toString(16).padStart(2, "0")).join("")}`;
|
|
218
|
+
}
|
|
219
|
+
function Xe(e, t) {
|
|
220
|
+
return {
|
|
221
|
+
requiresV4Unlock: !0,
|
|
222
|
+
actions: je(e),
|
|
223
|
+
params: t
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
function Qe(e, t) {
|
|
227
|
+
return q({
|
|
228
|
+
abi: V,
|
|
229
|
+
functionName: "execute",
|
|
230
|
+
args: [e, t]
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
function Ye(e) {
|
|
234
|
+
return q({
|
|
235
|
+
abi: V,
|
|
236
|
+
functionName: "permitBatch",
|
|
237
|
+
args: [e.owner, e.permitBatch, e.signature]
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
function Je(e) {
|
|
241
|
+
return q({
|
|
242
|
+
abi: V,
|
|
243
|
+
functionName: "multicall",
|
|
244
|
+
args: [e]
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
function Ze(e) {
|
|
248
|
+
if (!e) return !1;
|
|
249
|
+
if ("bips" in e) {
|
|
250
|
+
if (!Number.isInteger(e.bips) || e.bips < 0 || e.bips > 1e4)
|
|
251
|
+
throw new Error("Fee portion must be an integer between 0 and 10000 bips.");
|
|
252
|
+
return e.bips > 0;
|
|
253
|
+
}
|
|
254
|
+
return e.amount > 0n;
|
|
255
|
+
}
|
|
256
|
+
function ge(e, t) {
|
|
257
|
+
return "bips" in e ? {
|
|
258
|
+
action: O.TAKE_PORTION,
|
|
259
|
+
params: T(He, [t, e.recipient, BigInt(e.bips)])
|
|
260
|
+
} : {
|
|
261
|
+
action: O.TAKE,
|
|
262
|
+
params: T(ce, [t, e.recipient, e.amount])
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
function k(e, t = "Amount") {
|
|
266
|
+
if (e < 0n || e > $e)
|
|
267
|
+
throw new Error(`${t} is too large for a single V4 swap.`);
|
|
268
|
+
}
|
|
269
|
+
function et(e, t) {
|
|
270
|
+
return t ? Je([Ye(t), e]) : e;
|
|
271
|
+
}
|
|
272
|
+
function ue(e) {
|
|
273
|
+
return Ne(
|
|
274
|
+
T(
|
|
275
|
+
[
|
|
276
|
+
{ name: "currency0", type: "address" },
|
|
277
|
+
{ name: "currency1", type: "address" },
|
|
278
|
+
{ name: "fee", type: "uint24" },
|
|
279
|
+
{ name: "tickSpacing", type: "int24" },
|
|
280
|
+
{ name: "hooks", type: "address" }
|
|
281
|
+
],
|
|
282
|
+
[
|
|
283
|
+
e.currency0,
|
|
284
|
+
e.currency1,
|
|
285
|
+
e.fee,
|
|
286
|
+
e.tickSpacing,
|
|
287
|
+
e.hooks
|
|
288
|
+
]
|
|
289
|
+
)
|
|
290
|
+
);
|
|
291
|
+
}
|
|
292
|
+
function le(e) {
|
|
293
|
+
const t = e.zeroForOne ? e.poolKey.currency0 : e.poolKey.currency1, n = e.zeroForOne ? e.poolKey.currency1 : e.poolKey.currency0, o = Ze(e.fee) ? e.fee : null, a = o ? ge(o, n) : null, i = Xe(
|
|
294
|
+
[
|
|
295
|
+
e.swapAction,
|
|
296
|
+
O.SETTLE,
|
|
297
|
+
...a ? [a.action] : [],
|
|
298
|
+
O.TAKE
|
|
299
|
+
],
|
|
300
|
+
[
|
|
301
|
+
e.encodedSwapParams,
|
|
302
|
+
T(Ve, [t, e.settleAmount, !0]),
|
|
303
|
+
...a ? [a.params] : [],
|
|
304
|
+
T(ce, [n, e.recipient, ie])
|
|
305
|
+
]
|
|
306
|
+
);
|
|
307
|
+
return {
|
|
308
|
+
calldata: et(Qe([i], e.deadline), e.permit),
|
|
309
|
+
value: 0n
|
|
310
|
+
};
|
|
311
|
+
}
|
|
312
|
+
function tt(e) {
|
|
313
|
+
return k(e.amountIn, "Swap input amount"), k(e.amountOutMinimum, "Swap minimum output"), le({
|
|
314
|
+
swapAction: O.SWAP_EXACT_IN_SINGLE,
|
|
315
|
+
encodedSwapParams: T(qe, [
|
|
316
|
+
{
|
|
317
|
+
poolKey: e.poolKey,
|
|
318
|
+
zeroForOne: e.zeroForOne,
|
|
319
|
+
amountIn: e.amountIn,
|
|
320
|
+
amountOutMinimum: e.amountOutMinimum,
|
|
321
|
+
hookData: "0x"
|
|
322
|
+
}
|
|
323
|
+
]),
|
|
324
|
+
poolKey: e.poolKey,
|
|
325
|
+
zeroForOne: e.zeroForOne,
|
|
326
|
+
settleAmount: e.amountIn,
|
|
327
|
+
recipient: e.recipient,
|
|
328
|
+
deadline: e.deadline,
|
|
329
|
+
permit: e.permit,
|
|
330
|
+
fee: e.fee
|
|
331
|
+
});
|
|
332
|
+
}
|
|
333
|
+
function nt(e) {
|
|
334
|
+
return k(e.amountOut, "Swap output amount"), k(e.amountInMaximum, "Swap maximum input"), le({
|
|
335
|
+
swapAction: O.SWAP_EXACT_OUT_SINGLE,
|
|
336
|
+
encodedSwapParams: T(ze, [
|
|
337
|
+
{
|
|
338
|
+
poolKey: e.poolKey,
|
|
339
|
+
zeroForOne: e.zeroForOne,
|
|
340
|
+
amountOut: e.amountOut,
|
|
341
|
+
amountInMaximum: e.amountInMaximum,
|
|
342
|
+
hookData: "0x"
|
|
343
|
+
}
|
|
344
|
+
]),
|
|
345
|
+
poolKey: e.poolKey,
|
|
346
|
+
zeroForOne: e.zeroForOne,
|
|
347
|
+
settleAmount: ie,
|
|
348
|
+
recipient: e.recipient,
|
|
349
|
+
deadline: e.deadline,
|
|
350
|
+
permit: e.permit,
|
|
351
|
+
fee: e.fee
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
function se(e, t) {
|
|
355
|
+
var n;
|
|
356
|
+
return ((n = t.explorerTxUrl) == null ? void 0 : n.call(t, e)) ?? "#";
|
|
357
|
+
}
|
|
358
|
+
const E = 1, me = m("0x00581261a1200956ea05d1810fF28ffd66D8E254"), ot = m("0x8f29BD5c8429730fA4C46e6295c4e679eDEdd0cC"), at = 8388608, it = 50, pe = m(
|
|
359
|
+
"0x8ea2C7de60ef1Cd4dcE64ea2DDDe2f99F0127eFC"
|
|
360
|
+
);
|
|
361
|
+
function x(e) {
|
|
362
|
+
return e ? m(e) : void 0;
|
|
363
|
+
}
|
|
364
|
+
function C(e) {
|
|
365
|
+
if (!e.permit2 || !e.quoter)
|
|
366
|
+
throw new Error("Missing Permit2 or V4 Quoter contract address.");
|
|
367
|
+
return {
|
|
368
|
+
permit2: m(e.permit2),
|
|
369
|
+
quoter: m(e.quoter),
|
|
370
|
+
poolManager: x(e.poolManager),
|
|
371
|
+
positionDescriptor: x(e.positionDescriptor),
|
|
372
|
+
positionManager: x(e.positionManager),
|
|
373
|
+
stateView: x(e.stateView),
|
|
374
|
+
universalRouter: x(e.universalRouter),
|
|
375
|
+
universalRouterV2_1_1: x(e.universalRouterV2_1_1)
|
|
376
|
+
};
|
|
377
|
+
}
|
|
378
|
+
const de = {
|
|
379
|
+
1: C({
|
|
380
|
+
poolManager: "0x000000000004444c5dc75cB358380D2e3dE08A90",
|
|
381
|
+
positionDescriptor: "0xd1428ba554f4c8450b763a0b2040a4935c63f06c",
|
|
382
|
+
positionManager: "0xbd216513d74c8cf14cf4747e6aaa6420ff64ee9e",
|
|
383
|
+
quoter: "0x52f0e24d1c21c8a0cb1e5a5dd6198556bd9e1203",
|
|
384
|
+
stateView: "0x7ffe42c4a5deea5b0fec41c94c136cf115597227",
|
|
385
|
+
universalRouter: "0x66a9893cc07d91d95644aedd05d03f95e1dba8af",
|
|
386
|
+
universalRouterV2_1_1: "0x4c82d1fbfe28c977cbb58d8c7ff8fcf9f70a2cca",
|
|
387
|
+
permit2: "0x000000000022D473030F116dDEE9F6B43aC78BA3"
|
|
388
|
+
}),
|
|
389
|
+
10: C({
|
|
390
|
+
poolManager: "0x9a13f98cb987694c9f086b1f5eb990eea8264ec3",
|
|
391
|
+
positionDescriptor: "0xedd81496169c46df161b8513a52ffecaaaa66743",
|
|
392
|
+
positionManager: "0x3c3ea4b57a46241e54610e5f022e5c45859a1017",
|
|
393
|
+
quoter: "0x1f3131a13296fb91c90870043742c3cdbff1a8d7",
|
|
394
|
+
stateView: "0xc18a3169788f4f75a170290584eca6395c75ecdb",
|
|
395
|
+
universalRouter: "0x851116d9223fabed8e56c0e6b8ad0c31d98b3507",
|
|
396
|
+
universalRouterV2_1_1: "0x8b844f885672f333bc0042cb669255f93a4c1e6b",
|
|
397
|
+
permit2: "0x000000000022D473030F116dDEE9F6B43aC78BA3"
|
|
398
|
+
}),
|
|
399
|
+
130: C({
|
|
400
|
+
poolManager: "0x1f98400000000000000000000000000000000004",
|
|
401
|
+
positionDescriptor: "0x9fb28449a191cd8c03a1b7abfb0f5996ecf7f722",
|
|
402
|
+
positionManager: "0x4529a01c7a0410167c5740c487a8de60232617bf",
|
|
403
|
+
quoter: "0x333e3c607b141b18ff6de9f258db6e77fe7491e0",
|
|
404
|
+
stateView: "0x86e8631a016f9068c3f085faf484ee3f5fdee8f2",
|
|
405
|
+
universalRouter: "0xef740bf23acae26f6492b10de645d6b98dc8eaf3",
|
|
406
|
+
universalRouterV2_1_1: "0xfdf682f51fe81aa4898f0ae2163d8a55c127fbc7",
|
|
407
|
+
permit2: "0x000000000022D473030F116dDEE9F6B43aC78BA3"
|
|
408
|
+
}),
|
|
409
|
+
137: C({
|
|
410
|
+
poolManager: "0x67366782805870060151383f4bbff9dab53e5cd6",
|
|
411
|
+
positionDescriptor: "0x0892771f0c1b78ad6013d6e5536007e1c16e6794",
|
|
412
|
+
positionManager: "0x1ec2ebf4f37e7363fdfe3551602425af0b3ceef9",
|
|
413
|
+
quoter: "0xb3d5c3dfc3a7aebff71895a7191796bffc2c81b9",
|
|
414
|
+
stateView: "0x5ea1bd7974c8a611cbab0bdcafcb1d9cc9b3ba5a",
|
|
415
|
+
universalRouter: "0x1095692a6237d83c6a72f3f5efedb9a670c49223",
|
|
416
|
+
universalRouterV2_1_1: "0x8b844f885672f333bc0042cb669255f93a4c1e6b",
|
|
417
|
+
permit2: "0x000000000022D473030F116dDEE9F6B43aC78BA3"
|
|
418
|
+
}),
|
|
419
|
+
8453: C({
|
|
420
|
+
poolManager: "0x498581ff718922c3f8e6a244956af099b2652b2b",
|
|
421
|
+
positionDescriptor: "0x25d093633990dc94bedeed76c8f3cdaa75f3e7d5",
|
|
422
|
+
positionManager: "0x7c5f5a4bbd8fd63184577525326123b519429bdc",
|
|
423
|
+
quoter: "0x0d5e0f971ed27fbff6c2837bf31316121532048d",
|
|
424
|
+
stateView: "0xa3c0c9b65bad0b08107aa264b0f3db444b867a71",
|
|
425
|
+
universalRouter: "0x6ff5693b99212da76ad316178a184ab56d299b43",
|
|
426
|
+
universalRouterV2_1_1: "0xfdf682f51fe81aa4898f0ae2163d8a55c127fbc7",
|
|
427
|
+
permit2: "0x000000000022D473030F116dDEE9F6B43aC78BA3"
|
|
428
|
+
}),
|
|
429
|
+
42161: C({
|
|
430
|
+
poolManager: "0x360e68faccca8ca495c1b759fd9eee466db9fb32",
|
|
431
|
+
positionDescriptor: "0xe2023f3fa515cf070e07fd9d51c1d236e07843f4",
|
|
432
|
+
positionManager: "0xd88f38f930b7952f2db2432cb002e7abbf3dd869",
|
|
433
|
+
quoter: "0x3972c00f7ed4885e145823eb7c655375d275a1c5",
|
|
434
|
+
stateView: "0x76fd297e2d437cd7f76d50f01afe6160f86e9990",
|
|
435
|
+
universalRouter: "0xa51afafe0263b40edaef0df8781ea9aa03e381a3",
|
|
436
|
+
universalRouterV2_1_1: "0x8b844f885672f333bc0042cb669255f93a4c1e6b",
|
|
437
|
+
permit2: "0x000000000022D473030F116dDEE9F6B43aC78BA3"
|
|
438
|
+
})
|
|
439
|
+
}, H = de[E], fe = H.permit2, he = H.quoter, rt = [
|
|
440
|
+
"https://eth.drpc.org",
|
|
441
|
+
"https://ethereum-rpc.publicnode.com",
|
|
442
|
+
"https://cloudflare-eth.com"
|
|
443
|
+
], ct = "https://aegis.markets/graphql/meta", ut = {
|
|
444
|
+
chainId: E,
|
|
445
|
+
chain: Ke,
|
|
446
|
+
name: "Ethereum",
|
|
447
|
+
router: me,
|
|
448
|
+
permit2: fe,
|
|
449
|
+
quoter: he,
|
|
450
|
+
v4Contracts: H,
|
|
451
|
+
rpcUrls: rt,
|
|
452
|
+
explorerTxUrl: (e) => `https://etherscan.io/tx/${e}`,
|
|
453
|
+
poolExplorerUrl: (e) => `https://app.uniswap.org/explore/pools/ethereum/${e}`,
|
|
454
|
+
metadataEndpoint: ct,
|
|
455
|
+
fee: {
|
|
456
|
+
bps: it,
|
|
457
|
+
recipient: pe
|
|
458
|
+
}
|
|
459
|
+
}, j = {
|
|
460
|
+
[E]: ut
|
|
461
|
+
}, y = {
|
|
462
|
+
USDC: {
|
|
463
|
+
chainId: E,
|
|
464
|
+
address: m("0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48"),
|
|
465
|
+
name: "USD Coin",
|
|
466
|
+
symbol: "USDC",
|
|
467
|
+
decimals: 6
|
|
468
|
+
},
|
|
469
|
+
WATER: {
|
|
470
|
+
chainId: E,
|
|
471
|
+
address: m("0x828B22c9ea1c20B551EeFC6198174C4bb7a8CBF6"),
|
|
472
|
+
name: "WATER",
|
|
473
|
+
symbol: "WATER",
|
|
474
|
+
decimals: 18
|
|
475
|
+
},
|
|
476
|
+
WOOD: {
|
|
477
|
+
chainId: E,
|
|
478
|
+
address: m("0x670AfdD7226e73d3CC55B5cd83933E46aF22DECd"),
|
|
479
|
+
name: "WOOD",
|
|
480
|
+
symbol: "WOOD",
|
|
481
|
+
decimals: 18
|
|
482
|
+
},
|
|
483
|
+
GRASS: {
|
|
484
|
+
chainId: E,
|
|
485
|
+
address: m("0xF06Ad052b0d8D511D0B6f00100b8e402639209EF"),
|
|
486
|
+
name: "GRASS",
|
|
487
|
+
symbol: "GRASS",
|
|
488
|
+
decimals: 18
|
|
489
|
+
},
|
|
490
|
+
STONE: {
|
|
491
|
+
chainId: E,
|
|
492
|
+
address: m("0xCabcc33D9Ff7e24F413d939773D232C0d50dCc7f"),
|
|
493
|
+
name: "STONE",
|
|
494
|
+
symbol: "STONE",
|
|
495
|
+
decimals: 18,
|
|
496
|
+
// STONE's ichi asset is logo_256_stone_2.svg, not the symbol-derived
|
|
497
|
+
// logo_256_stone.svg that getIchiIconGuess('STONE') produces. Pin it so the
|
|
498
|
+
// mark stays correct even when the metadata service is unreachable.
|
|
499
|
+
iconUrl: "https://ichi-images.s3.us-east-1.amazonaws.com/tokens/logo_256_stone_2.svg"
|
|
500
|
+
}
|
|
501
|
+
};
|
|
502
|
+
function B(e, t, n, o, a, i) {
|
|
503
|
+
return {
|
|
504
|
+
id: e,
|
|
505
|
+
chainId: E,
|
|
506
|
+
symbol: t,
|
|
507
|
+
poolId: n,
|
|
508
|
+
poolKey: {
|
|
509
|
+
currency0: o,
|
|
510
|
+
currency1: a,
|
|
511
|
+
fee: at,
|
|
512
|
+
tickSpacing: i,
|
|
513
|
+
hooks: ot
|
|
514
|
+
},
|
|
515
|
+
token: y[t],
|
|
516
|
+
counterToken: y.USDC,
|
|
517
|
+
router: me,
|
|
518
|
+
permit2: fe,
|
|
519
|
+
quoter: he,
|
|
520
|
+
label: `${y.USDC.symbol} / ${t}`
|
|
521
|
+
};
|
|
522
|
+
}
|
|
523
|
+
const lt = B(
|
|
524
|
+
"WATER_USDC",
|
|
525
|
+
"WATER",
|
|
526
|
+
"0x01409fc6f1bf49e20bf05df5d4dcb96ed3977ea717bc4a135e9deacd92ebc0af",
|
|
527
|
+
y.WATER.address,
|
|
528
|
+
y.USDC.address,
|
|
529
|
+
60
|
|
530
|
+
), st = B(
|
|
531
|
+
"WOOD_USDC",
|
|
532
|
+
"WOOD",
|
|
533
|
+
"0x0f8a98e3fdb7ea4438a3f7342f040cbc9d1eced1b90a876d38f3453100243356",
|
|
534
|
+
y.WOOD.address,
|
|
535
|
+
y.USDC.address,
|
|
536
|
+
60
|
|
537
|
+
), mt = B(
|
|
538
|
+
"GRASS_USDC",
|
|
539
|
+
"GRASS",
|
|
540
|
+
"0xd0194ad1f57730361b93ecf8da86e18590bd5e1f64e4a35f3a5b5bd666e48ae1",
|
|
541
|
+
y.USDC.address,
|
|
542
|
+
y.GRASS.address,
|
|
543
|
+
60
|
|
544
|
+
), pt = B(
|
|
545
|
+
"STONE_USDC",
|
|
546
|
+
"STONE",
|
|
547
|
+
"0x3fa06e44e4bee9539887681eab6b608b646784e2027ea6292198cde0690aff54",
|
|
548
|
+
y.USDC.address,
|
|
549
|
+
y.STONE.address,
|
|
550
|
+
60
|
|
551
|
+
), Un = {
|
|
552
|
+
WATER_USDC: lt,
|
|
553
|
+
WOOD_USDC: st,
|
|
554
|
+
GRASS_USDC: mt,
|
|
555
|
+
STONE_USDC: pt
|
|
556
|
+
}, Nn = [
|
|
557
|
+
"WATER_USDC",
|
|
558
|
+
"WOOD_USDC",
|
|
559
|
+
"GRASS_USDC",
|
|
560
|
+
"STONE_USDC"
|
|
561
|
+
], we = 50, ye = pe, X = {
|
|
562
|
+
USDC: y.USDC,
|
|
563
|
+
USDT: {
|
|
564
|
+
chainId: E,
|
|
565
|
+
address: m("0xdAC17F958D2ee523a2206206994597C13D831ec7"),
|
|
566
|
+
name: "Tether USD",
|
|
567
|
+
symbol: "USDT",
|
|
568
|
+
decimals: 6
|
|
569
|
+
},
|
|
570
|
+
WETH: {
|
|
571
|
+
chainId: E,
|
|
572
|
+
address: m("0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2"),
|
|
573
|
+
name: "Wrapped Ether",
|
|
574
|
+
symbol: "WETH",
|
|
575
|
+
decimals: 18
|
|
576
|
+
},
|
|
577
|
+
ETH: {
|
|
578
|
+
chainId: E,
|
|
579
|
+
address: m("0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE"),
|
|
580
|
+
name: "Ether",
|
|
581
|
+
symbol: "ETH",
|
|
582
|
+
decimals: 18
|
|
583
|
+
},
|
|
584
|
+
WBTC: {
|
|
585
|
+
chainId: E,
|
|
586
|
+
address: m("0x2260FAC5E5542a773Aa44fBCfeDf7C193bc2C599"),
|
|
587
|
+
name: "Wrapped Bitcoin",
|
|
588
|
+
symbol: "WBTC",
|
|
589
|
+
decimals: 8
|
|
590
|
+
},
|
|
591
|
+
STETH: {
|
|
592
|
+
chainId: E,
|
|
593
|
+
address: m("0xae7ab96520DE3A18E5e111B5EaAb095312D7fE84"),
|
|
594
|
+
name: "Lido Staked Ether",
|
|
595
|
+
symbol: "stETH",
|
|
596
|
+
decimals: 18
|
|
597
|
+
}
|
|
598
|
+
}, dt = {
|
|
599
|
+
USDC: y.USDC,
|
|
600
|
+
ETH: X.ETH,
|
|
601
|
+
WATER: y.WATER,
|
|
602
|
+
WOOD: y.WOOD,
|
|
603
|
+
GRASS: y.GRASS,
|
|
604
|
+
STONE: y.STONE
|
|
605
|
+
}, ft = Object.values(
|
|
606
|
+
X
|
|
607
|
+
), ht = Object.values(
|
|
608
|
+
dt
|
|
609
|
+
), Fn = {
|
|
610
|
+
default: ft,
|
|
611
|
+
wolfgame: ht
|
|
612
|
+
}, Bn = X;
|
|
613
|
+
function g(e) {
|
|
614
|
+
return {
|
|
615
|
+
...e,
|
|
616
|
+
address: m(e.address)
|
|
617
|
+
};
|
|
618
|
+
}
|
|
619
|
+
function wt(e) {
|
|
620
|
+
const t = m(e.currency0), n = m(e.currency1);
|
|
621
|
+
if (t.toLowerCase() >= n.toLowerCase())
|
|
622
|
+
throw new Error(
|
|
623
|
+
"Invalid pool key: currency0 must sort below currency1 (Uniswap v4 canonical ordering)."
|
|
624
|
+
);
|
|
625
|
+
return {
|
|
626
|
+
currency0: t,
|
|
627
|
+
currency1: n,
|
|
628
|
+
fee: e.fee,
|
|
629
|
+
tickSpacing: e.tickSpacing,
|
|
630
|
+
hooks: m(e.hooks)
|
|
631
|
+
};
|
|
632
|
+
}
|
|
633
|
+
function yt(e, t) {
|
|
634
|
+
var o, a;
|
|
635
|
+
const n = de[e.chainId];
|
|
636
|
+
return {
|
|
637
|
+
...n,
|
|
638
|
+
...t == null ? void 0 : t.v4Contracts,
|
|
639
|
+
...e.v4Contracts,
|
|
640
|
+
permit2: ((o = e.v4Contracts) == null ? void 0 : o.permit2) ?? e.permit2 ?? (t == null ? void 0 : t.permit2) ?? (n == null ? void 0 : n.permit2),
|
|
641
|
+
quoter: ((a = e.v4Contracts) == null ? void 0 : a.quoter) ?? e.quoter ?? (t == null ? void 0 : t.quoter) ?? (n == null ? void 0 : n.quoter)
|
|
642
|
+
};
|
|
643
|
+
}
|
|
644
|
+
function Et(e, t) {
|
|
645
|
+
var a;
|
|
646
|
+
const n = yt(e, t);
|
|
647
|
+
if (!t && (!e.chain || !e.router || !((a = e.rpcUrls) != null && a.length)))
|
|
648
|
+
throw new Error(
|
|
649
|
+
`Missing viem chain, Aegis router, or RPC URLs for chain ${e.chainId}.`
|
|
650
|
+
);
|
|
651
|
+
const o = C(n);
|
|
652
|
+
return {
|
|
653
|
+
chainId: e.chainId,
|
|
654
|
+
chain: e.chain ?? t.chain,
|
|
655
|
+
name: e.name ?? (t == null ? void 0 : t.name) ?? `Chain ${e.chainId}`,
|
|
656
|
+
router: m(e.router ?? t.router),
|
|
657
|
+
permit2: o.permit2,
|
|
658
|
+
quoter: o.quoter,
|
|
659
|
+
v4Contracts: o,
|
|
660
|
+
rpcUrls: e.rpcUrls ?? t.rpcUrls,
|
|
661
|
+
explorerTxUrl: e.explorerTxUrl ?? (t == null ? void 0 : t.explorerTxUrl),
|
|
662
|
+
poolExplorerUrl: e.poolExplorerUrl ?? (t == null ? void 0 : t.poolExplorerUrl),
|
|
663
|
+
metadataEndpoint: e.metadataEndpoint ?? (t == null ? void 0 : t.metadataEndpoint),
|
|
664
|
+
// Fee stays internal: it is never read from host input, only inherited from
|
|
665
|
+
// the bundled base chain config (e.g. mainnet keeps its 50 bps fee).
|
|
666
|
+
fee: t == null ? void 0 : t.fee
|
|
667
|
+
};
|
|
668
|
+
}
|
|
669
|
+
function Wn(e) {
|
|
670
|
+
const t = { ...j };
|
|
671
|
+
if (!e) return t;
|
|
672
|
+
for (const [n, o] of Object.entries(e)) {
|
|
673
|
+
if (!o) continue;
|
|
674
|
+
const a = o.chainId ?? Number(n);
|
|
675
|
+
t[a] = Et(
|
|
676
|
+
{ ...o, chainId: a },
|
|
677
|
+
t[a]
|
|
678
|
+
);
|
|
679
|
+
}
|
|
680
|
+
return t;
|
|
681
|
+
}
|
|
682
|
+
function bt(e, t = j) {
|
|
683
|
+
const n = g(e.token), o = g(e.counterToken), a = e.chainId ?? n.chainId ?? o.chainId ?? E, i = t[a];
|
|
684
|
+
if (!i) throw new Error(`No Aegis swap chain config found for chain ${a}.`);
|
|
685
|
+
if (n.chainId !== a || o.chainId !== a)
|
|
686
|
+
throw new Error(`Pool token chain ids must match chain ${a}.`);
|
|
687
|
+
const c = wt(e.poolKey), r = ue(c);
|
|
688
|
+
if (e.poolId && !oe(e.poolId, r))
|
|
689
|
+
throw new Error("Configured pool id does not match the pool key.");
|
|
690
|
+
return {
|
|
691
|
+
id: e.id,
|
|
692
|
+
chainId: a,
|
|
693
|
+
symbol: e.symbol ?? n.symbol,
|
|
694
|
+
poolId: e.poolId ?? r,
|
|
695
|
+
poolKey: c,
|
|
696
|
+
token: n,
|
|
697
|
+
counterToken: o,
|
|
698
|
+
router: m(e.router ?? i.router),
|
|
699
|
+
permit2: m(e.permit2 ?? i.permit2),
|
|
700
|
+
quoter: m(e.quoter ?? i.quoter),
|
|
701
|
+
label: e.label ?? `${o.symbol} / ${n.symbol}`
|
|
702
|
+
};
|
|
703
|
+
}
|
|
704
|
+
function Gn(e, t = j) {
|
|
705
|
+
return e != null && e.length ? Object.fromEntries(
|
|
706
|
+
e.map((n) => {
|
|
707
|
+
const o = bt(n, t);
|
|
708
|
+
return [o.id, o];
|
|
709
|
+
})
|
|
710
|
+
) : {};
|
|
711
|
+
}
|
|
712
|
+
function Ee(e) {
|
|
713
|
+
if (!Number.isFinite(e) || e < 0 || e > 2e3)
|
|
714
|
+
throw new Error("Slippage must be between 0% and 20%.");
|
|
715
|
+
}
|
|
716
|
+
function At(e, t) {
|
|
717
|
+
return Ee(t), e * BigInt(1e4 - Math.round(t)) / 10000n;
|
|
718
|
+
}
|
|
719
|
+
function St(e, t) {
|
|
720
|
+
return Ee(t), (e * BigInt(1e4 + Math.round(t)) + 9999n) / 10000n;
|
|
721
|
+
}
|
|
722
|
+
function It(e, t) {
|
|
723
|
+
return t <= 0 ? 0n : e * BigInt(t) / 10000n;
|
|
724
|
+
}
|
|
725
|
+
function Ct(e, t) {
|
|
726
|
+
return t <= 0 ? e : (e * 10000n + BigInt(1e4 - t - 1)) / BigInt(1e4 - t);
|
|
727
|
+
}
|
|
728
|
+
function Tt(e, t) {
|
|
729
|
+
if (t <= 0) return e;
|
|
730
|
+
const n = BigInt(1e4 - t);
|
|
731
|
+
return (e * 10000n + n - 1n) / n;
|
|
732
|
+
}
|
|
733
|
+
function M(e) {
|
|
734
|
+
return k(e), e;
|
|
735
|
+
}
|
|
736
|
+
function _t(e, t) {
|
|
737
|
+
if (A(t.address, e.currency0)) return !0;
|
|
738
|
+
if (A(t.address, e.currency1)) return !1;
|
|
739
|
+
throw new Error("Input token is not part of this pool.");
|
|
740
|
+
}
|
|
741
|
+
function vt(e, t, n) {
|
|
742
|
+
const o = ue(e.poolKey);
|
|
743
|
+
if (!oe(o, e.poolId))
|
|
744
|
+
throw new Error("Configured pool id does not match the pool key.");
|
|
745
|
+
const a = A(t.address, e.poolKey.currency0) || A(t.address, e.poolKey.currency1), i = A(n.address, e.poolKey.currency0) || A(n.address, e.poolKey.currency1);
|
|
746
|
+
if (!a || !i || A(t.address, n.address))
|
|
747
|
+
throw new Error("Selected tokens do not match this direct pool.");
|
|
748
|
+
}
|
|
749
|
+
function xt(e, t) {
|
|
750
|
+
if (Array.isArray(e)) {
|
|
751
|
+
const a = e[0], i = e[1];
|
|
752
|
+
if (typeof a == "bigint" && typeof i == "bigint")
|
|
753
|
+
return { amount: a, gasEstimate: i };
|
|
754
|
+
throw new Error("Unexpected V4 Quoter response.");
|
|
755
|
+
}
|
|
756
|
+
const n = e, o = n[t];
|
|
757
|
+
if (typeof o == "bigint" && typeof n.gasEstimate == "bigint")
|
|
758
|
+
return { amount: o, gasEstimate: n.gasEstimate };
|
|
759
|
+
throw new Error("Unexpected V4 Quoter response.");
|
|
760
|
+
}
|
|
761
|
+
async function Ot(e) {
|
|
762
|
+
var d, f, w, S;
|
|
763
|
+
if ((d = e.signal) != null && d.aborted) throw new DOMException("Quote request aborted", "AbortError");
|
|
764
|
+
if (e.amount <= 0n) throw new Error("Enter an amount to swap.");
|
|
765
|
+
M(e.amount), vt(e.market, e.tokenIn, e.tokenOut);
|
|
766
|
+
const t = e.market.poolKey, n = _t(t, e.tokenIn), o = ((f = e.fee) == null ? void 0 : f.bps) ?? 0;
|
|
767
|
+
if (!Number.isInteger(o) || o < 0 || o >= 1e4)
|
|
768
|
+
throw new Error("Fee must be an integer between 0 and 9999 bps.");
|
|
769
|
+
const a = e.mode === "exactOut" ? M(Ct(e.amount, o)) : e.amount, i = e.mode === "exactOut" ? await e.publicClient.simulateContract({
|
|
770
|
+
address: e.market.quoter,
|
|
771
|
+
abi: Z,
|
|
772
|
+
functionName: "quoteExactOutputSingle",
|
|
773
|
+
args: [{ poolKey: t, zeroForOne: n, exactAmount: a, hookData: "0x" }],
|
|
774
|
+
account: e.account
|
|
775
|
+
}) : await e.publicClient.simulateContract({
|
|
776
|
+
address: e.market.quoter,
|
|
777
|
+
abi: Z,
|
|
778
|
+
functionName: "quoteExactInputSingle",
|
|
779
|
+
args: [{ poolKey: t, zeroForOne: n, exactAmount: e.amount, hookData: "0x" }],
|
|
780
|
+
account: e.account
|
|
781
|
+
});
|
|
782
|
+
if ((w = e.signal) != null && w.aborted) throw new DOMException("Quote request aborted", "AbortError");
|
|
783
|
+
const c = xt(
|
|
784
|
+
i.result,
|
|
785
|
+
e.mode === "exactOut" ? "amountIn" : "amountOut"
|
|
786
|
+
), r = e.mode === "exactOut" ? c.amount : e.amount, u = e.mode === "exactOut" ? a : c.amount, l = e.mode === "exactOut" ? u - e.amount : It(u, o), s = u - l, p = e.mode === "exactOut" ? s : At(s, e.slippageBps);
|
|
787
|
+
return {
|
|
788
|
+
mode: e.mode,
|
|
789
|
+
poolKey: t,
|
|
790
|
+
zeroForOne: n,
|
|
791
|
+
amountIn: r,
|
|
792
|
+
amountOut: s,
|
|
793
|
+
grossAmountOut: u,
|
|
794
|
+
amountOutMinimum: e.mode === "exactOut" ? u : M(Tt(p, o)),
|
|
795
|
+
amountInMaximum: e.mode === "exactOut" ? M(St(r, e.slippageBps)) : r,
|
|
796
|
+
userAmountOutMinimum: p,
|
|
797
|
+
feeAmount: l,
|
|
798
|
+
feeBps: o,
|
|
799
|
+
feeRecipient: o > 0 ? ((S = e.fee) == null ? void 0 : S.recipient) ?? null : null,
|
|
800
|
+
gasEstimate: c.gasEstimate
|
|
801
|
+
};
|
|
802
|
+
}
|
|
803
|
+
function be(e, t) {
|
|
804
|
+
return e.mode === t.mode && e.zeroForOne === t.zeroForOne && A(e.poolKey.currency0, t.poolKey.currency0) && A(e.poolKey.currency1, t.poolKey.currency1) && e.poolKey.fee === t.poolKey.fee && e.poolKey.tickSpacing === t.poolKey.tickSpacing && A(e.poolKey.hooks, t.poolKey.hooks) && e.feeBps === t.feeBps && Le(e.feeRecipient, t.feeRecipient);
|
|
805
|
+
}
|
|
806
|
+
function Kn(e, t) {
|
|
807
|
+
return be(e, t) && e.amountIn === t.amountIn && e.amountOut === t.amountOut && e.grossAmountOut === t.grossAmountOut && e.amountOutMinimum === t.amountOutMinimum && e.amountInMaximum === t.amountInMaximum && e.userAmountOutMinimum === t.userAmountOutMinimum && e.feeAmount === t.feeAmount;
|
|
808
|
+
}
|
|
809
|
+
function Pt(e, t) {
|
|
810
|
+
return !e || !be(e, t) ? { quote: t, priceMovedBeyondTolerance: !1 } : t.mode === "exactIn" ? t.amountOut < e.userAmountOutMinimum ? { quote: t, priceMovedBeyondTolerance: !0 } : {
|
|
811
|
+
quote: {
|
|
812
|
+
...t,
|
|
813
|
+
amountOutMinimum: t.amountOutMinimum > e.amountOutMinimum ? t.amountOutMinimum : e.amountOutMinimum,
|
|
814
|
+
userAmountOutMinimum: t.userAmountOutMinimum > e.userAmountOutMinimum ? t.userAmountOutMinimum : e.userAmountOutMinimum
|
|
815
|
+
},
|
|
816
|
+
priceMovedBeyondTolerance: !1
|
|
817
|
+
} : t.amountIn > e.amountInMaximum ? { quote: t, priceMovedBeyondTolerance: !0 } : {
|
|
818
|
+
quote: {
|
|
819
|
+
...t,
|
|
820
|
+
amountInMaximum: t.amountInMaximum < e.amountInMaximum ? t.amountInMaximum : e.amountInMaximum
|
|
821
|
+
},
|
|
822
|
+
priceMovedBeyondTolerance: !1
|
|
823
|
+
};
|
|
824
|
+
}
|
|
825
|
+
function Dt(e) {
|
|
826
|
+
return e.mode === "exactOut" ? e.amountInMaximum : e.amountIn;
|
|
827
|
+
}
|
|
828
|
+
function kt(e) {
|
|
829
|
+
return e.feeRecipient ? e.mode === "exactIn" ? e.feeBps > 0 ? { recipient: e.feeRecipient, bips: e.feeBps } : null : e.feeAmount > 0n ? { recipient: e.feeRecipient, amount: e.feeAmount } : null : null;
|
|
830
|
+
}
|
|
831
|
+
function Ae(e) {
|
|
832
|
+
for (let n = e; n && typeof n == "object"; n = n.cause)
|
|
833
|
+
if (n.code === 4001) return !0;
|
|
834
|
+
const t = e instanceof Error ? e.message.toLowerCase() : "";
|
|
835
|
+
return t.includes("user rejected") || t.includes("user denied") || t.includes("rejected the request") || t.includes("request rejected");
|
|
836
|
+
}
|
|
837
|
+
const Rt = "Request rejected.";
|
|
838
|
+
function Mt(e, t) {
|
|
839
|
+
if (Ae(e))
|
|
840
|
+
return Rt;
|
|
841
|
+
const n = e instanceof Error ? e.message : "";
|
|
842
|
+
if (!n) return t;
|
|
843
|
+
const o = n.toLowerCase();
|
|
844
|
+
return o.includes("wallet_switchethereumchain") || o.includes("wallet_addethereumchain") ? "Network switch failed." : o.includes("insufficient funds") ? "Insufficient funds for gas." : o.includes("execution reverted") || o.includes("swap reverted") ? "Swap reverted on-chain." : o.includes("token not found") ? "Token is not supported by KyberSwap." : o.includes("kyberswap api error") ? "KyberSwap could not build this route. Try again." : t;
|
|
845
|
+
}
|
|
846
|
+
class Se extends Error {
|
|
847
|
+
constructor({
|
|
848
|
+
status: n,
|
|
849
|
+
statusText: o,
|
|
850
|
+
code: a,
|
|
851
|
+
message: i,
|
|
852
|
+
body: c
|
|
853
|
+
}) {
|
|
854
|
+
super(i);
|
|
855
|
+
I(this, "status");
|
|
856
|
+
I(this, "statusText");
|
|
857
|
+
I(this, "code");
|
|
858
|
+
I(this, "body");
|
|
859
|
+
this.name = "KyberSwapApiError", this.status = n, this.statusText = o, this.code = a, this.body = c;
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
const Ie = "https://aggregator-api.kyberswap.com", L = "Aegis", Ut = {
|
|
863
|
+
1: "ethereum",
|
|
864
|
+
10: "optimism",
|
|
865
|
+
56: "bsc",
|
|
866
|
+
130: "unichain",
|
|
867
|
+
137: "polygon",
|
|
868
|
+
143: "monad",
|
|
869
|
+
146: "sonic",
|
|
870
|
+
250: "fantom",
|
|
871
|
+
999: "hyperevm",
|
|
872
|
+
2020: "ronin",
|
|
873
|
+
4326: "megaeth",
|
|
874
|
+
5e3: "mantle",
|
|
875
|
+
8453: "base",
|
|
876
|
+
9745: "plasma",
|
|
877
|
+
42161: "arbitrum",
|
|
878
|
+
42793: "etherlink",
|
|
879
|
+
43114: "avalanche",
|
|
880
|
+
59144: "linea",
|
|
881
|
+
80094: "berachain"
|
|
882
|
+
};
|
|
883
|
+
function Ce(e) {
|
|
884
|
+
const t = Ut[e];
|
|
885
|
+
if (!t)
|
|
886
|
+
throw new Error(`KyberSwap does not support chain ${e}.`);
|
|
887
|
+
return t;
|
|
888
|
+
}
|
|
889
|
+
async function Te(e) {
|
|
890
|
+
const t = e.clone();
|
|
891
|
+
let n, o, a;
|
|
892
|
+
try {
|
|
893
|
+
const u = await e.json();
|
|
894
|
+
n = u, o = u.code, a = u.message;
|
|
895
|
+
} catch {
|
|
896
|
+
try {
|
|
897
|
+
const u = await t.text();
|
|
898
|
+
n = u, a = u;
|
|
899
|
+
} catch {
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
const i = a ? `: ${a.slice(0, 300)}` : "", c = o !== void 0 ? ` ${o}` : "", r = e.statusText || "Request failed";
|
|
903
|
+
return new Se({
|
|
904
|
+
status: e.status,
|
|
905
|
+
statusText: r,
|
|
906
|
+
code: o,
|
|
907
|
+
message: `KyberSwap API error${c}${i || `: ${r}`}`,
|
|
908
|
+
body: n
|
|
909
|
+
});
|
|
910
|
+
}
|
|
911
|
+
function _e(e) {
|
|
912
|
+
return e instanceof Se && (e.status === 429 || e.status >= 500);
|
|
913
|
+
}
|
|
914
|
+
function Nt(e) {
|
|
915
|
+
if (!(e != null && e.routeSummary) || !(e != null && e.routerAddress))
|
|
916
|
+
throw new Error("Invalid response from KyberSwap API");
|
|
917
|
+
return {
|
|
918
|
+
...e,
|
|
919
|
+
routerAddress: m(e.routerAddress),
|
|
920
|
+
// Kyber requires route/build to receive routeSummary exactly as returned
|
|
921
|
+
// from /routes. Do not checksum addresses or strip empty nested fields here.
|
|
922
|
+
routeSummary: e.routeSummary
|
|
923
|
+
};
|
|
924
|
+
}
|
|
925
|
+
function Ft(e) {
|
|
926
|
+
if (!(e != null && e.data) || !(e != null && e.routerAddress))
|
|
927
|
+
throw new Error("Invalid encoded route from KyberSwap API");
|
|
928
|
+
return {
|
|
929
|
+
...e,
|
|
930
|
+
data: e.data,
|
|
931
|
+
routerAddress: m(e.routerAddress)
|
|
932
|
+
};
|
|
933
|
+
}
|
|
934
|
+
async function Bt({
|
|
935
|
+
tokenIn: e,
|
|
936
|
+
tokenOut: t,
|
|
937
|
+
amountIn: n,
|
|
938
|
+
chainId: o = 1,
|
|
939
|
+
origin: a,
|
|
940
|
+
fee: i,
|
|
941
|
+
signal: c
|
|
942
|
+
}) {
|
|
943
|
+
const r = new URLSearchParams({
|
|
944
|
+
tokenIn: e,
|
|
945
|
+
tokenOut: t,
|
|
946
|
+
amountIn: n,
|
|
947
|
+
gasInclude: "true"
|
|
948
|
+
});
|
|
949
|
+
a && r.set("origin", a), i && (r.set("feeAmount", i.feeAmount), r.set("chargeFeeBy", i.chargeFeeBy), r.set("isInBps", String(i.isInBps)), r.set("feeReceiver", i.feeReceiver));
|
|
950
|
+
const u = await fetch(
|
|
951
|
+
`${Ie}/${Ce(o)}/api/v1/routes?${r}`,
|
|
952
|
+
{
|
|
953
|
+
method: "GET",
|
|
954
|
+
headers: {
|
|
955
|
+
Accept: "application/json",
|
|
956
|
+
"X-Client-Id": L
|
|
957
|
+
},
|
|
958
|
+
signal: c
|
|
959
|
+
}
|
|
960
|
+
);
|
|
961
|
+
if (!u.ok) throw await Te(u);
|
|
962
|
+
const l = await u.json();
|
|
963
|
+
return Nt(l.data);
|
|
964
|
+
}
|
|
965
|
+
async function Wt({
|
|
966
|
+
routeSummary: e,
|
|
967
|
+
sender: t,
|
|
968
|
+
recipient: n,
|
|
969
|
+
slippageBps: o,
|
|
970
|
+
chainId: a = 1,
|
|
971
|
+
signal: i
|
|
972
|
+
}) {
|
|
973
|
+
const c = await fetch(
|
|
974
|
+
`${Ie}/${Ce(a)}/api/v1/route/build`,
|
|
975
|
+
{
|
|
976
|
+
method: "POST",
|
|
977
|
+
headers: {
|
|
978
|
+
Accept: "application/json",
|
|
979
|
+
"Content-Type": "application/json",
|
|
980
|
+
"X-Client-Id": L
|
|
981
|
+
},
|
|
982
|
+
body: JSON.stringify({
|
|
983
|
+
routeSummary: e,
|
|
984
|
+
sender: t,
|
|
985
|
+
origin: t,
|
|
986
|
+
recipient: n,
|
|
987
|
+
slippageTolerance: o,
|
|
988
|
+
deadline: Math.floor(Date.now() / 1e3 + 600),
|
|
989
|
+
enableGasEstimation: !1,
|
|
990
|
+
source: L
|
|
991
|
+
}),
|
|
992
|
+
signal: i
|
|
993
|
+
}
|
|
994
|
+
);
|
|
995
|
+
if (!c.ok) throw await Te(c);
|
|
996
|
+
const r = await c.json();
|
|
997
|
+
return Ft(r.data);
|
|
998
|
+
}
|
|
999
|
+
const Gt = 2, Kt = "Route temporarily unavailable. Refresh the quote and try again.";
|
|
1000
|
+
function Ln(e, t) {
|
|
1001
|
+
return _e(e) ? Kt : Mt(e, t);
|
|
1002
|
+
}
|
|
1003
|
+
function Lt(e, t) {
|
|
1004
|
+
if (!Number.isFinite(t) || t < 0 || t > 2e3)
|
|
1005
|
+
throw new Error("Slippage must be between 0% and 20%.");
|
|
1006
|
+
return e * BigInt(1e4 - Math.round(t)) / 10000n;
|
|
1007
|
+
}
|
|
1008
|
+
function $t(e, t) {
|
|
1009
|
+
if (t <= 0) return 0n;
|
|
1010
|
+
const n = BigInt(1e4 - t);
|
|
1011
|
+
return (e * 10000n + n - 1n) / n - e;
|
|
1012
|
+
}
|
|
1013
|
+
function qt(e) {
|
|
1014
|
+
return e !== E ? null : {
|
|
1015
|
+
feeAmount: String(we),
|
|
1016
|
+
chargeFeeBy: "currency_out",
|
|
1017
|
+
isInBps: !0,
|
|
1018
|
+
feeReceiver: ye
|
|
1019
|
+
};
|
|
1020
|
+
}
|
|
1021
|
+
function zt(e) {
|
|
1022
|
+
const t = e.routeSummary.gasEstimate ?? e.routeSummary.gas ?? "0";
|
|
1023
|
+
try {
|
|
1024
|
+
return BigInt(t);
|
|
1025
|
+
} catch {
|
|
1026
|
+
return 0n;
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
function Vt(e) {
|
|
1030
|
+
var t;
|
|
1031
|
+
return ((t = e.routeSummary.route) == null ? void 0 : t.flat()) ?? [];
|
|
1032
|
+
}
|
|
1033
|
+
function Ht(e, t, n) {
|
|
1034
|
+
const o = Vt(e);
|
|
1035
|
+
return o.length ? o.map((a) => ({
|
|
1036
|
+
dex: a.exchange || a.poolType || "Unknown",
|
|
1037
|
+
inputToken: t,
|
|
1038
|
+
outputToken: n,
|
|
1039
|
+
part: 0
|
|
1040
|
+
})) : (e.routeSummary.routeComposition || []).map((a) => ({
|
|
1041
|
+
dex: a.name || "Unknown",
|
|
1042
|
+
inputToken: t,
|
|
1043
|
+
outputToken: n,
|
|
1044
|
+
part: a.part || 0
|
|
1045
|
+
}));
|
|
1046
|
+
}
|
|
1047
|
+
async function ee(e, t, n, o, a = "exactIn", i, c, r) {
|
|
1048
|
+
if (a === "exactOut")
|
|
1049
|
+
throw new Error("Exact output is not supported for aggregated routes.");
|
|
1050
|
+
if (e.chainId !== t.chainId)
|
|
1051
|
+
throw new Error("Input and output tokens must be on the same chain.");
|
|
1052
|
+
if (n <= 0n)
|
|
1053
|
+
throw new Error("Enter an amount to swap.");
|
|
1054
|
+
const u = qt(e.chainId), l = i ? Gt : 1;
|
|
1055
|
+
let s;
|
|
1056
|
+
for (let p = 0; p < l; p += 1) {
|
|
1057
|
+
const d = await Bt({
|
|
1058
|
+
tokenIn: e.address,
|
|
1059
|
+
tokenOut: t.address,
|
|
1060
|
+
amountIn: n.toString(),
|
|
1061
|
+
chainId: e.chainId,
|
|
1062
|
+
origin: i,
|
|
1063
|
+
fee: u,
|
|
1064
|
+
signal: c
|
|
1065
|
+
}), f = BigInt(d.routeSummary.amountOut), w = u ? we : 0, S = $t(f, w), b = Lt(f, o);
|
|
1066
|
+
let h = null;
|
|
1067
|
+
try {
|
|
1068
|
+
h = i ? await Wt({
|
|
1069
|
+
routeSummary: d.routeSummary,
|
|
1070
|
+
sender: i,
|
|
1071
|
+
recipient: i,
|
|
1072
|
+
slippageBps: o,
|
|
1073
|
+
chainId: e.chainId,
|
|
1074
|
+
signal: c
|
|
1075
|
+
}) : null;
|
|
1076
|
+
} catch (_) {
|
|
1077
|
+
if (s = _, i && p < l - 1 && _e(_))
|
|
1078
|
+
continue;
|
|
1079
|
+
throw _;
|
|
1080
|
+
}
|
|
1081
|
+
return {
|
|
1082
|
+
inputToken: e,
|
|
1083
|
+
outputToken: t,
|
|
1084
|
+
amountIn: n,
|
|
1085
|
+
amountOut: f,
|
|
1086
|
+
gasEstimate: h != null && h.gas ? BigInt(h.gas) : zt(d),
|
|
1087
|
+
hops: Ht(d, e, t),
|
|
1088
|
+
routerAddress: (h == null ? void 0 : h.routerAddress) ?? d.routerAddress,
|
|
1089
|
+
calldata: (h == null ? void 0 : h.data) ?? null,
|
|
1090
|
+
transactionValue: h != null && h.transactionValue ? BigInt(h.transactionValue) : 0n,
|
|
1091
|
+
priceImpact: d.routeSummary.priceImpact ?? 0,
|
|
1092
|
+
feeAmount: S,
|
|
1093
|
+
feeBps: w,
|
|
1094
|
+
feeRecipient: u ? ye : null,
|
|
1095
|
+
userAmountOutMinimum: b,
|
|
1096
|
+
amountOutMinimum: b
|
|
1097
|
+
};
|
|
1098
|
+
}
|
|
1099
|
+
throw s instanceof Error ? s : new Error("Swap route could not be encoded. Try again.");
|
|
1100
|
+
}
|
|
1101
|
+
const N = 2n ** 160n - 1n, ve = 2n ** 256n - 1n, xe = 600, jt = 1800, Oe = 1800, Xt = xe, Qt = 2 ** 48 - 1, Yt = {
|
|
1102
|
+
PermitBatch: [
|
|
1103
|
+
{ name: "details", type: "PermitDetails[]" },
|
|
1104
|
+
{ name: "spender", type: "address" },
|
|
1105
|
+
{ name: "sigDeadline", type: "uint256" }
|
|
1106
|
+
],
|
|
1107
|
+
PermitDetails: [
|
|
1108
|
+
{ name: "token", type: "address" },
|
|
1109
|
+
{ name: "amount", type: "uint160" },
|
|
1110
|
+
{ name: "expiration", type: "uint48" },
|
|
1111
|
+
{ name: "nonce", type: "uint48" }
|
|
1112
|
+
]
|
|
1113
|
+
};
|
|
1114
|
+
async function Jt(e) {
|
|
1115
|
+
const t = e.amount ?? ve, n = P({
|
|
1116
|
+
account: e.account,
|
|
1117
|
+
chain: e.chain,
|
|
1118
|
+
transport: D(e.provider)
|
|
1119
|
+
}), { request: o } = await e.publicClient.simulateContract({
|
|
1120
|
+
address: e.token,
|
|
1121
|
+
abi: z,
|
|
1122
|
+
functionName: "approve",
|
|
1123
|
+
args: [e.permit2, t],
|
|
1124
|
+
account: e.account
|
|
1125
|
+
}), a = await n.writeContract({
|
|
1126
|
+
...o,
|
|
1127
|
+
chain: e.chain
|
|
1128
|
+
});
|
|
1129
|
+
if ((await e.publicClient.waitForTransactionReceipt({ hash: a })).status === "reverted") throw new Error("Token approval reverted.");
|
|
1130
|
+
return a;
|
|
1131
|
+
}
|
|
1132
|
+
function F(e) {
|
|
1133
|
+
return e.publicClient.readContract({
|
|
1134
|
+
address: e.token,
|
|
1135
|
+
abi: z,
|
|
1136
|
+
functionName: "allowance",
|
|
1137
|
+
args: [e.owner, e.spender]
|
|
1138
|
+
});
|
|
1139
|
+
}
|
|
1140
|
+
async function te(e) {
|
|
1141
|
+
const t = e.amount ?? ve, o = await P({
|
|
1142
|
+
account: e.account,
|
|
1143
|
+
chain: e.chain,
|
|
1144
|
+
transport: D(e.provider)
|
|
1145
|
+
}).writeContract({
|
|
1146
|
+
address: e.token,
|
|
1147
|
+
abi: z,
|
|
1148
|
+
functionName: "approve",
|
|
1149
|
+
args: [e.spender, t],
|
|
1150
|
+
account: e.account,
|
|
1151
|
+
chain: e.chain
|
|
1152
|
+
});
|
|
1153
|
+
if ((await e.publicClient.waitForTransactionReceipt({ hash: o })).status === "reverted") throw new Error("Token approval reverted.");
|
|
1154
|
+
return o;
|
|
1155
|
+
}
|
|
1156
|
+
async function Zt(e) {
|
|
1157
|
+
const t = e.amount && e.amount < N ? e.amount : N, n = e.expiration ?? Qt, o = P({
|
|
1158
|
+
account: e.account,
|
|
1159
|
+
chain: e.chain,
|
|
1160
|
+
transport: D(e.provider)
|
|
1161
|
+
}), { request: a } = await e.publicClient.simulateContract({
|
|
1162
|
+
address: e.permit2,
|
|
1163
|
+
abi: ae,
|
|
1164
|
+
functionName: "approve",
|
|
1165
|
+
args: [e.token, e.router, t, n],
|
|
1166
|
+
account: e.account
|
|
1167
|
+
}), i = await o.writeContract({
|
|
1168
|
+
...a,
|
|
1169
|
+
chain: e.chain
|
|
1170
|
+
});
|
|
1171
|
+
if ((await e.publicClient.waitForTransactionReceipt({ hash: i })).status === "reverted") throw new Error("Permit2 approval reverted.");
|
|
1172
|
+
return i;
|
|
1173
|
+
}
|
|
1174
|
+
function Pe(e) {
|
|
1175
|
+
return e.publicClient.readContract({
|
|
1176
|
+
address: e.permit2,
|
|
1177
|
+
abi: ae,
|
|
1178
|
+
functionName: "allowance",
|
|
1179
|
+
args: [e.account, e.token, e.router]
|
|
1180
|
+
});
|
|
1181
|
+
}
|
|
1182
|
+
async function gt(e) {
|
|
1183
|
+
const [t, n, o] = await (e.allowanceRead ?? Pe(e)), a = Math.floor(Date.now() / 1e3);
|
|
1184
|
+
if (t >= e.amount && Number(n) > a + Xt)
|
|
1185
|
+
return null;
|
|
1186
|
+
const i = {
|
|
1187
|
+
details: [
|
|
1188
|
+
{
|
|
1189
|
+
token: e.token,
|
|
1190
|
+
amount: e.sizing === "max" || e.amount > N ? N : e.amount,
|
|
1191
|
+
expiration: a + Oe,
|
|
1192
|
+
nonce: Number(o)
|
|
1193
|
+
}
|
|
1194
|
+
],
|
|
1195
|
+
spender: e.router,
|
|
1196
|
+
sigDeadline: BigInt(a + jt)
|
|
1197
|
+
}, r = await P({
|
|
1198
|
+
account: e.account,
|
|
1199
|
+
chain: e.chain,
|
|
1200
|
+
transport: D(e.provider)
|
|
1201
|
+
}).signTypedData({
|
|
1202
|
+
account: e.account,
|
|
1203
|
+
domain: {
|
|
1204
|
+
name: "Permit2",
|
|
1205
|
+
chainId: e.chainId,
|
|
1206
|
+
verifyingContract: e.permit2
|
|
1207
|
+
},
|
|
1208
|
+
types: Yt,
|
|
1209
|
+
primaryType: "PermitBatch",
|
|
1210
|
+
message: i
|
|
1211
|
+
});
|
|
1212
|
+
return {
|
|
1213
|
+
owner: e.account,
|
|
1214
|
+
permitBatch: i,
|
|
1215
|
+
signature: r
|
|
1216
|
+
};
|
|
1217
|
+
}
|
|
1218
|
+
const en = "https://ichi-images.s3.us-east-1.amazonaws.com/tokens", G = /* @__PURE__ */ new Map();
|
|
1219
|
+
function ne(e, t, n) {
|
|
1220
|
+
return `${e}|evm_${t}_${n.toLowerCase()}`;
|
|
1221
|
+
}
|
|
1222
|
+
function tn(e, t) {
|
|
1223
|
+
return `evm_${e}_${t.toLowerCase()}`;
|
|
1224
|
+
}
|
|
1225
|
+
function nn(e) {
|
|
1226
|
+
const t = e == null ? void 0 : e.trim();
|
|
1227
|
+
if (!t) return null;
|
|
1228
|
+
const n = t.split("-"), a = (n.length > 1 ? n[n.length - 1] : t).trim().toLowerCase();
|
|
1229
|
+
return !a || !/^[a-z0-9]+$/.test(a) ? null : a;
|
|
1230
|
+
}
|
|
1231
|
+
function on(e) {
|
|
1232
|
+
const t = nn(e);
|
|
1233
|
+
return t ? `${en}/logo_256_${t}.svg` : null;
|
|
1234
|
+
}
|
|
1235
|
+
function $n(e, t) {
|
|
1236
|
+
var n, o;
|
|
1237
|
+
return ((n = e.iconUrl) != null && n.trim() ? e.iconUrl : null) ?? ((o = t[K(e.address)]) == null ? void 0 : o.iconURL) ?? on(e.symbol);
|
|
1238
|
+
}
|
|
1239
|
+
function an(e, t) {
|
|
1240
|
+
return `query AegisSwapWidgetTokenMetadata { ${t.map((o, a) => `t${a}: getGlobalToken(id: ${JSON.stringify(tn(e, o))}) { chainId address symbol displayName fullName decimals iconURL }`).join(" ")} }`;
|
|
1241
|
+
}
|
|
1242
|
+
async function qn(e) {
|
|
1243
|
+
var r, u;
|
|
1244
|
+
const t = e.endpoint.trim(), n = [
|
|
1245
|
+
...new Map(
|
|
1246
|
+
e.addresses.map((l) => {
|
|
1247
|
+
const s = m(l);
|
|
1248
|
+
return [s.toLowerCase(), s];
|
|
1249
|
+
})
|
|
1250
|
+
).values()
|
|
1251
|
+
], o = /* @__PURE__ */ new Map(), a = n.filter((l) => {
|
|
1252
|
+
const s = ne(t, e.chainId, l);
|
|
1253
|
+
if (!G.has(s)) return !0;
|
|
1254
|
+
const p = G.get(s);
|
|
1255
|
+
return p && o.set(K(l), p), !1;
|
|
1256
|
+
});
|
|
1257
|
+
if (!a.length || typeof fetch != "function") return o;
|
|
1258
|
+
const i = await fetch(t, {
|
|
1259
|
+
method: "POST",
|
|
1260
|
+
headers: { "Content-Type": "application/json" },
|
|
1261
|
+
body: JSON.stringify({
|
|
1262
|
+
query: an(e.chainId, a)
|
|
1263
|
+
}),
|
|
1264
|
+
signal: e.signal
|
|
1265
|
+
});
|
|
1266
|
+
if (!i.ok)
|
|
1267
|
+
throw new Error(`Token metadata request failed with HTTP ${i.status}.`);
|
|
1268
|
+
const c = await i.json();
|
|
1269
|
+
if ((r = c.errors) != null && r.length)
|
|
1270
|
+
throw new Error(((u = c.errors[0]) == null ? void 0 : u.message) ?? "Token metadata request failed.");
|
|
1271
|
+
return a.forEach((l, s) => {
|
|
1272
|
+
var d;
|
|
1273
|
+
const p = ((d = c.data) == null ? void 0 : d[`t${s}`]) ?? null;
|
|
1274
|
+
G.set(ne(t, e.chainId, l), p), p && o.set(K(l), p);
|
|
1275
|
+
}), o;
|
|
1276
|
+
}
|
|
1277
|
+
function rn() {
|
|
1278
|
+
return typeof window > "u" ? null : window.ethereum ?? null;
|
|
1279
|
+
}
|
|
1280
|
+
function W(e) {
|
|
1281
|
+
return typeof e != "string" || !Ge(e) ? null : m(e);
|
|
1282
|
+
}
|
|
1283
|
+
function cn(e) {
|
|
1284
|
+
return !!(e && typeof e == "object" && typeof e.request == "function");
|
|
1285
|
+
}
|
|
1286
|
+
function un(e) {
|
|
1287
|
+
return cn(e) ? { provider: e, account: null } : !e || typeof e != "object" ? { provider: null, account: null } : {
|
|
1288
|
+
provider: e.provider ?? null,
|
|
1289
|
+
account: W(e.account)
|
|
1290
|
+
};
|
|
1291
|
+
}
|
|
1292
|
+
async function ln(e) {
|
|
1293
|
+
const t = await e.request({ method: "eth_accounts" });
|
|
1294
|
+
return W(t == null ? void 0 : t[0]);
|
|
1295
|
+
}
|
|
1296
|
+
async function sn(e) {
|
|
1297
|
+
const t = await e.request({ method: "eth_requestAccounts" });
|
|
1298
|
+
return W(t == null ? void 0 : t[0]);
|
|
1299
|
+
}
|
|
1300
|
+
async function $(e) {
|
|
1301
|
+
const t = await e.request({ method: "eth_chainId" });
|
|
1302
|
+
if (typeof t != "string" || !/^0x[0-9a-f]+$/i.test(t)) return null;
|
|
1303
|
+
const n = Number.parseInt(t, 16);
|
|
1304
|
+
return Number.isSafeInteger(n) ? n : null;
|
|
1305
|
+
}
|
|
1306
|
+
function mn(e) {
|
|
1307
|
+
return `0x${e.toString(16)}`;
|
|
1308
|
+
}
|
|
1309
|
+
function pn(e) {
|
|
1310
|
+
const t = e, n = [t.message, t.shortMessage, t.details].filter((o) => typeof o == "string").join(" ").toLowerCase();
|
|
1311
|
+
return t.code === 4902 || n.includes("unrecognized chain") || n.includes("unknown chain") || n.includes("chain has not been added") || n.includes("not added to wallet");
|
|
1312
|
+
}
|
|
1313
|
+
function dn(e) {
|
|
1314
|
+
return typeof e == "number" ? { chainId: e } : e;
|
|
1315
|
+
}
|
|
1316
|
+
function fn(e) {
|
|
1317
|
+
var t, n;
|
|
1318
|
+
return (t = e.rpcUrls) != null && t.length ? e.rpcUrls : ((n = e.chain) == null ? void 0 : n.rpcUrls.default.http) ?? [];
|
|
1319
|
+
}
|
|
1320
|
+
function hn(e) {
|
|
1321
|
+
var n, o;
|
|
1322
|
+
const t = (o = (n = e.chain) == null ? void 0 : n.blockExplorers) == null ? void 0 : o.default.url;
|
|
1323
|
+
return t ? [t] : [];
|
|
1324
|
+
}
|
|
1325
|
+
async function wn(e, t) {
|
|
1326
|
+
var i, c;
|
|
1327
|
+
const n = dn(t), o = mn(n.chainId), a = {
|
|
1328
|
+
method: "wallet_switchEthereumChain",
|
|
1329
|
+
params: [{ chainId: o }]
|
|
1330
|
+
};
|
|
1331
|
+
try {
|
|
1332
|
+
await e.request(a);
|
|
1333
|
+
return;
|
|
1334
|
+
} catch (r) {
|
|
1335
|
+
if (!pn(r)) throw r;
|
|
1336
|
+
const u = fn(n);
|
|
1337
|
+
if (u.length === 0) throw r;
|
|
1338
|
+
const l = hn(n);
|
|
1339
|
+
await e.request({
|
|
1340
|
+
method: "wallet_addEthereumChain",
|
|
1341
|
+
params: [
|
|
1342
|
+
{
|
|
1343
|
+
chainId: o,
|
|
1344
|
+
chainName: n.name ?? ((i = n.chain) == null ? void 0 : i.name) ?? `Chain ${n.chainId}`,
|
|
1345
|
+
nativeCurrency: ((c = n.chain) == null ? void 0 : c.nativeCurrency) ?? {
|
|
1346
|
+
name: "Ether",
|
|
1347
|
+
symbol: "ETH",
|
|
1348
|
+
decimals: 18
|
|
1349
|
+
},
|
|
1350
|
+
rpcUrls: u,
|
|
1351
|
+
...l.length ? { blockExplorerUrls: l } : {}
|
|
1352
|
+
}
|
|
1353
|
+
]
|
|
1354
|
+
});
|
|
1355
|
+
}
|
|
1356
|
+
await e.request({
|
|
1357
|
+
method: "wallet_switchEthereumChain",
|
|
1358
|
+
params: [{ chainId: o }]
|
|
1359
|
+
});
|
|
1360
|
+
}
|
|
1361
|
+
function zn(e, t) {
|
|
1362
|
+
const n = t.map(
|
|
1363
|
+
(o) => Fe(o, {
|
|
1364
|
+
batch: !0,
|
|
1365
|
+
retryCount: 2,
|
|
1366
|
+
retryDelay: 150,
|
|
1367
|
+
timeout: 1e4
|
|
1368
|
+
})
|
|
1369
|
+
);
|
|
1370
|
+
return Be({
|
|
1371
|
+
chain: e,
|
|
1372
|
+
transport: n.length === 1 ? n[0] : We(n)
|
|
1373
|
+
});
|
|
1374
|
+
}
|
|
1375
|
+
function Vn(e, t) {
|
|
1376
|
+
const n = e;
|
|
1377
|
+
if (!n.on || !n.removeListener) return () => {
|
|
1378
|
+
};
|
|
1379
|
+
const o = () => {
|
|
1380
|
+
var i;
|
|
1381
|
+
return (i = t.onAccountsChanged) == null ? void 0 : i.call(t);
|
|
1382
|
+
}, a = () => {
|
|
1383
|
+
var i;
|
|
1384
|
+
return (i = t.onChainChanged) == null ? void 0 : i.call(t);
|
|
1385
|
+
};
|
|
1386
|
+
return n.on("accountsChanged", o), n.on("chainChanged", a), () => {
|
|
1387
|
+
var i, c;
|
|
1388
|
+
(i = n.removeListener) == null || i.call(n, "accountsChanged", o), (c = n.removeListener) == null || c.call(n, "chainChanged", a);
|
|
1389
|
+
};
|
|
1390
|
+
}
|
|
1391
|
+
async function yn({
|
|
1392
|
+
wallet: e,
|
|
1393
|
+
publicClient: t,
|
|
1394
|
+
activeChain: n,
|
|
1395
|
+
market: o,
|
|
1396
|
+
inputToken: a,
|
|
1397
|
+
outputToken: i,
|
|
1398
|
+
swapQuote: c,
|
|
1399
|
+
permit: r,
|
|
1400
|
+
setStatus: u,
|
|
1401
|
+
setTxHash: l,
|
|
1402
|
+
onSubmitted: s
|
|
1403
|
+
}) {
|
|
1404
|
+
const p = BigInt(Math.floor(Date.now() / 1e3) + xe), d = kt(c), f = c.mode === "exactOut" ? nt({
|
|
1405
|
+
poolKey: c.poolKey,
|
|
1406
|
+
zeroForOne: c.zeroForOne,
|
|
1407
|
+
amountOut: c.grossAmountOut,
|
|
1408
|
+
amountInMaximum: c.amountInMaximum,
|
|
1409
|
+
recipient: e.account,
|
|
1410
|
+
deadline: p,
|
|
1411
|
+
permit: r,
|
|
1412
|
+
fee: d
|
|
1413
|
+
}) : tt({
|
|
1414
|
+
poolKey: c.poolKey,
|
|
1415
|
+
zeroForOne: c.zeroForOne,
|
|
1416
|
+
amountIn: c.amountIn,
|
|
1417
|
+
amountOutMinimum: c.amountOutMinimum,
|
|
1418
|
+
recipient: e.account,
|
|
1419
|
+
deadline: p,
|
|
1420
|
+
permit: r,
|
|
1421
|
+
fee: d
|
|
1422
|
+
});
|
|
1423
|
+
u("submitting");
|
|
1424
|
+
const w = P({
|
|
1425
|
+
account: e.account,
|
|
1426
|
+
chain: n.chain,
|
|
1427
|
+
transport: D(e.provider)
|
|
1428
|
+
}), S = await t.estimateGas({
|
|
1429
|
+
account: e.account,
|
|
1430
|
+
to: o.router,
|
|
1431
|
+
data: f.calldata,
|
|
1432
|
+
value: f.value
|
|
1433
|
+
}), b = await w.sendTransaction({
|
|
1434
|
+
to: o.router,
|
|
1435
|
+
data: f.calldata,
|
|
1436
|
+
value: f.value,
|
|
1437
|
+
gas: S * 12n / 10n
|
|
1438
|
+
}), h = {
|
|
1439
|
+
mode: c.mode,
|
|
1440
|
+
inputSymbol: a.symbol,
|
|
1441
|
+
outputSymbol: i.symbol,
|
|
1442
|
+
amountIn: c.amountIn,
|
|
1443
|
+
amountOut: c.amountOut,
|
|
1444
|
+
feeAmount: c.feeAmount,
|
|
1445
|
+
feeBps: c.feeBps
|
|
1446
|
+
};
|
|
1447
|
+
l(b);
|
|
1448
|
+
try {
|
|
1449
|
+
s == null || s(b, h);
|
|
1450
|
+
} catch (R) {
|
|
1451
|
+
console.warn("[AegisSwapWidget] onSubmitted callback failed", R);
|
|
1452
|
+
}
|
|
1453
|
+
let _ = null;
|
|
1454
|
+
const v = await t.waitForTransactionReceipt({
|
|
1455
|
+
hash: b,
|
|
1456
|
+
onReplaced: (R) => {
|
|
1457
|
+
_ = R.reason, l(R.transaction.hash);
|
|
1458
|
+
}
|
|
1459
|
+
});
|
|
1460
|
+
if (_ === "cancelled") throw new Error("Swap was cancelled in the wallet.");
|
|
1461
|
+
if (v.status === "reverted") throw new Error("Swap reverted on-chain.");
|
|
1462
|
+
const Y = v.gasUsed ?? 0n, J = v.effectiveGasPrice ?? 0n, Re = {
|
|
1463
|
+
transactionHash: v.transactionHash,
|
|
1464
|
+
blockNumber: v.blockNumber ?? 0n,
|
|
1465
|
+
gasUsed: Y,
|
|
1466
|
+
effectiveGasPrice: J,
|
|
1467
|
+
feeWei: Y * J
|
|
1468
|
+
};
|
|
1469
|
+
return { receipt: v, summary: Re, swapDetails: h };
|
|
1470
|
+
}
|
|
1471
|
+
async function En({
|
|
1472
|
+
wallet: e,
|
|
1473
|
+
publicClient: t,
|
|
1474
|
+
activeChain: n,
|
|
1475
|
+
permit2: o,
|
|
1476
|
+
router: a,
|
|
1477
|
+
token: i,
|
|
1478
|
+
amount: c,
|
|
1479
|
+
approvalMode: r,
|
|
1480
|
+
allowanceRead: u,
|
|
1481
|
+
setStatus: l
|
|
1482
|
+
}) {
|
|
1483
|
+
try {
|
|
1484
|
+
return await gt({
|
|
1485
|
+
provider: e.provider,
|
|
1486
|
+
publicClient: t,
|
|
1487
|
+
account: e.account,
|
|
1488
|
+
chainId: n.chainId,
|
|
1489
|
+
chain: n.chain,
|
|
1490
|
+
permit2: o,
|
|
1491
|
+
router: a,
|
|
1492
|
+
token: i,
|
|
1493
|
+
amount: c,
|
|
1494
|
+
sizing: r,
|
|
1495
|
+
allowanceRead: u
|
|
1496
|
+
});
|
|
1497
|
+
} catch (s) {
|
|
1498
|
+
if (Ae(s)) throw s;
|
|
1499
|
+
return l("approving"), await Zt({
|
|
1500
|
+
provider: e.provider,
|
|
1501
|
+
publicClient: t,
|
|
1502
|
+
account: e.account,
|
|
1503
|
+
chain: n.chain,
|
|
1504
|
+
token: i,
|
|
1505
|
+
permit2: o,
|
|
1506
|
+
router: a,
|
|
1507
|
+
// undefined -> MAX_UINT160, mirroring the 'max' permit sizing above.
|
|
1508
|
+
amount: r === "max" ? void 0 : c,
|
|
1509
|
+
expiration: Math.floor(Date.now() / 1e3) + Oe
|
|
1510
|
+
}), null;
|
|
1511
|
+
}
|
|
1512
|
+
}
|
|
1513
|
+
function Hn() {
|
|
1514
|
+
return typeof document > "u" ? !0 : document.visibilityState !== "hidden";
|
|
1515
|
+
}
|
|
1516
|
+
async function jn(e, t, n, o) {
|
|
1517
|
+
let a;
|
|
1518
|
+
for (let i = 0; i < t; i += 1) {
|
|
1519
|
+
i > 0 && await new Promise((c) => setTimeout(c, n));
|
|
1520
|
+
try {
|
|
1521
|
+
return await e();
|
|
1522
|
+
} catch (c) {
|
|
1523
|
+
if (a = c, o != null && o()) break;
|
|
1524
|
+
}
|
|
1525
|
+
}
|
|
1526
|
+
throw a ?? new Error("retryOnError was called with attempts < 1.");
|
|
1527
|
+
}
|
|
1528
|
+
async function Q(e, t, n, o) {
|
|
1529
|
+
let a = await e();
|
|
1530
|
+
for (let i = 1; i < n && !t(a); i += 1)
|
|
1531
|
+
await new Promise((c) => setTimeout(c, o)), a = await e();
|
|
1532
|
+
return a;
|
|
1533
|
+
}
|
|
1534
|
+
async function bn(e, t, n = 12, o = 250) {
|
|
1535
|
+
return await Q(
|
|
1536
|
+
() => $(e),
|
|
1537
|
+
(i) => i === t,
|
|
1538
|
+
n,
|
|
1539
|
+
o
|
|
1540
|
+
) === t;
|
|
1541
|
+
}
|
|
1542
|
+
async function De(e) {
|
|
1543
|
+
var a, i;
|
|
1544
|
+
const t = await $(e.provider);
|
|
1545
|
+
if ((a = e.onChainId) == null || a.call(e, t), t === e.chain.chainId) return;
|
|
1546
|
+
await wn(e.provider, e.chain);
|
|
1547
|
+
const n = await bn(e.provider, e.chain.chainId), o = n ? e.chain.chainId : await $(e.provider);
|
|
1548
|
+
if ((i = e.onChainId) == null || i.call(e, o), !n)
|
|
1549
|
+
throw new Error("Network switch did not complete. Switch to the correct network and try again.");
|
|
1550
|
+
}
|
|
1551
|
+
async function Xn(e = {}) {
|
|
1552
|
+
var o;
|
|
1553
|
+
let t = e.provider ?? await ((o = e.getProvider) == null ? void 0 : o.call(e)) ?? rn(), n = W(e.account);
|
|
1554
|
+
if ((!t || !n) && e.connectWallet) {
|
|
1555
|
+
const a = un(await e.connectWallet());
|
|
1556
|
+
t = a.provider ?? t, n = n ?? a.account;
|
|
1557
|
+
}
|
|
1558
|
+
if (!t) throw new Error("No wallet provider found.");
|
|
1559
|
+
if (n || (n = e.requestAccount === !1 ? await ln(t) : await sn(t)), !n) throw new Error("Wallet connection was not completed.");
|
|
1560
|
+
return { provider: t, account: n };
|
|
1561
|
+
}
|
|
1562
|
+
class An extends Error {
|
|
1563
|
+
constructor(n) {
|
|
1564
|
+
super("Price moved beyond your slippage tolerance. Review the updated quote and try again.");
|
|
1565
|
+
I(this, "quote");
|
|
1566
|
+
this.name = "DirectPoolSwapPriceMovedError", this.quote = n;
|
|
1567
|
+
}
|
|
1568
|
+
}
|
|
1569
|
+
async function Sn(e, t) {
|
|
1570
|
+
return Q(e, (n) => n >= t, 5, 300);
|
|
1571
|
+
}
|
|
1572
|
+
async function In(e) {
|
|
1573
|
+
var a;
|
|
1574
|
+
const t = () => F({
|
|
1575
|
+
publicClient: e.publicClient,
|
|
1576
|
+
token: e.token.address,
|
|
1577
|
+
owner: e.wallet.account,
|
|
1578
|
+
spender: e.permit2
|
|
1579
|
+
});
|
|
1580
|
+
let n = await t();
|
|
1581
|
+
if (n >= e.amount) return { approvalHash: null, allowance: n };
|
|
1582
|
+
(a = e.onStatus) == null || a.call(e, "approving");
|
|
1583
|
+
const o = await Jt({
|
|
1584
|
+
provider: e.wallet.provider,
|
|
1585
|
+
publicClient: e.publicClient,
|
|
1586
|
+
account: e.wallet.account,
|
|
1587
|
+
chain: e.activeChain.chain,
|
|
1588
|
+
token: e.token.address,
|
|
1589
|
+
permit2: e.permit2,
|
|
1590
|
+
amount: e.approvalMode === "exact" ? e.amount : void 0
|
|
1591
|
+
});
|
|
1592
|
+
if (n = await Sn(t, e.amount), n < e.amount)
|
|
1593
|
+
throw new Error("Approval confirmed, but allowance is still below this quote. Try again.");
|
|
1594
|
+
return { approvalHash: o, allowance: n };
|
|
1595
|
+
}
|
|
1596
|
+
async function Qn(e) {
|
|
1597
|
+
var s, p, d;
|
|
1598
|
+
await De({
|
|
1599
|
+
provider: e.wallet.provider,
|
|
1600
|
+
chain: e.activeChain,
|
|
1601
|
+
onChainId: e.onWalletChainId
|
|
1602
|
+
});
|
|
1603
|
+
const t = F({
|
|
1604
|
+
publicClient: e.publicClient,
|
|
1605
|
+
token: e.inputToken.address,
|
|
1606
|
+
owner: e.wallet.account,
|
|
1607
|
+
spender: e.market.permit2
|
|
1608
|
+
}).catch(() => null), n = Pe({
|
|
1609
|
+
publicClient: e.publicClient,
|
|
1610
|
+
permit2: e.market.permit2,
|
|
1611
|
+
account: e.wallet.account,
|
|
1612
|
+
token: e.inputToken.address,
|
|
1613
|
+
router: e.market.router
|
|
1614
|
+
});
|
|
1615
|
+
n.catch(() => {
|
|
1616
|
+
});
|
|
1617
|
+
const o = await Ot({
|
|
1618
|
+
publicClient: e.publicClient,
|
|
1619
|
+
account: e.wallet.account,
|
|
1620
|
+
market: e.market,
|
|
1621
|
+
tokenIn: e.inputToken,
|
|
1622
|
+
tokenOut: e.outputToken,
|
|
1623
|
+
mode: e.mode,
|
|
1624
|
+
amount: e.amount,
|
|
1625
|
+
slippageBps: e.slippageBps,
|
|
1626
|
+
fee: e.fee ?? e.activeChain.fee ?? null,
|
|
1627
|
+
signal: e.signal
|
|
1628
|
+
}), a = Pt(e.displayedQuote ?? null, o);
|
|
1629
|
+
if (a.priceMovedBeyondTolerance)
|
|
1630
|
+
throw (s = e.onStatus) == null || s.call(e, "idle"), new An(o);
|
|
1631
|
+
const i = a.quote, c = Dt(i);
|
|
1632
|
+
if (c <= 0n) throw new Error("Quote returned an empty amount. Try again.");
|
|
1633
|
+
let r = await t ?? await F({
|
|
1634
|
+
publicClient: e.publicClient,
|
|
1635
|
+
token: e.inputToken.address,
|
|
1636
|
+
owner: e.wallet.account,
|
|
1637
|
+
spender: e.market.permit2
|
|
1638
|
+
});
|
|
1639
|
+
if (r < c && (r = (await In({
|
|
1640
|
+
wallet: e.wallet,
|
|
1641
|
+
publicClient: e.publicClient,
|
|
1642
|
+
activeChain: e.activeChain,
|
|
1643
|
+
token: e.inputToken,
|
|
1644
|
+
permit2: e.market.permit2,
|
|
1645
|
+
amount: c,
|
|
1646
|
+
approvalMode: e.approvalMode ?? "exact",
|
|
1647
|
+
onStatus: e.onStatus
|
|
1648
|
+
})).allowance), r < c)
|
|
1649
|
+
throw new Error(`Approve ${e.inputToken.symbol} before swapping.`);
|
|
1650
|
+
(p = e.onStatus) == null || p.call(e, "signing");
|
|
1651
|
+
const u = await En({
|
|
1652
|
+
wallet: e.wallet,
|
|
1653
|
+
publicClient: e.publicClient,
|
|
1654
|
+
activeChain: e.activeChain,
|
|
1655
|
+
permit2: e.market.permit2,
|
|
1656
|
+
router: e.market.router,
|
|
1657
|
+
token: e.inputToken.address,
|
|
1658
|
+
amount: c,
|
|
1659
|
+
approvalMode: e.approvalMode ?? "exact",
|
|
1660
|
+
allowanceRead: n,
|
|
1661
|
+
setStatus: (f) => {
|
|
1662
|
+
var w;
|
|
1663
|
+
return (w = e.onStatus) == null ? void 0 : w.call(e, f);
|
|
1664
|
+
}
|
|
1665
|
+
}), l = await yn({
|
|
1666
|
+
wallet: e.wallet,
|
|
1667
|
+
publicClient: e.publicClient,
|
|
1668
|
+
activeChain: e.activeChain,
|
|
1669
|
+
market: e.market,
|
|
1670
|
+
inputToken: e.inputToken,
|
|
1671
|
+
outputToken: e.outputToken,
|
|
1672
|
+
swapQuote: i,
|
|
1673
|
+
permit: u,
|
|
1674
|
+
setStatus: (f) => {
|
|
1675
|
+
var w;
|
|
1676
|
+
return (w = e.onStatus) == null ? void 0 : w.call(e, f);
|
|
1677
|
+
},
|
|
1678
|
+
setTxHash: (f) => {
|
|
1679
|
+
var w;
|
|
1680
|
+
return (w = e.onTxHash) == null ? void 0 : w.call(e, f);
|
|
1681
|
+
},
|
|
1682
|
+
onSubmitted: e.onSubmitted
|
|
1683
|
+
});
|
|
1684
|
+
return (d = e.onStatus) == null || d.call(e, "success"), {
|
|
1685
|
+
hash: l.receipt.transactionHash,
|
|
1686
|
+
explorerUrl: se(l.receipt.transactionHash, e.activeChain),
|
|
1687
|
+
quote: i,
|
|
1688
|
+
receiptSummary: l.summary,
|
|
1689
|
+
swap: l.swapDetails
|
|
1690
|
+
};
|
|
1691
|
+
}
|
|
1692
|
+
async function Cn(e, t) {
|
|
1693
|
+
try {
|
|
1694
|
+
return await e.estimateGas(t) * 12n / 10n;
|
|
1695
|
+
} catch {
|
|
1696
|
+
return;
|
|
1697
|
+
}
|
|
1698
|
+
}
|
|
1699
|
+
const Tn = "0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE";
|
|
1700
|
+
function ke(e) {
|
|
1701
|
+
return e.address.toLowerCase() === Tn.toLowerCase();
|
|
1702
|
+
}
|
|
1703
|
+
class _n extends Error {
|
|
1704
|
+
constructor(n) {
|
|
1705
|
+
super("Price moved beyond your slippage tolerance. Review the updated quote and try again.");
|
|
1706
|
+
I(this, "quote");
|
|
1707
|
+
this.name = "KyberSwapPriceMovedError", this.quote = n;
|
|
1708
|
+
}
|
|
1709
|
+
}
|
|
1710
|
+
async function vn(e) {
|
|
1711
|
+
var a;
|
|
1712
|
+
if (ke(e.inputToken)) return { approvalHashes: [], allowance: e.amount };
|
|
1713
|
+
const t = () => F({
|
|
1714
|
+
publicClient: e.publicClient,
|
|
1715
|
+
token: e.inputToken.address,
|
|
1716
|
+
owner: e.wallet.account,
|
|
1717
|
+
spender: e.spender
|
|
1718
|
+
});
|
|
1719
|
+
let n = await t();
|
|
1720
|
+
if (n >= e.amount) return { approvalHashes: [], allowance: n };
|
|
1721
|
+
(a = e.onStatus) == null || a.call(e, "approving");
|
|
1722
|
+
const o = [];
|
|
1723
|
+
if (n > 0n && o.push(
|
|
1724
|
+
await te({
|
|
1725
|
+
provider: e.wallet.provider,
|
|
1726
|
+
publicClient: e.publicClient,
|
|
1727
|
+
account: e.wallet.account,
|
|
1728
|
+
chain: e.activeChain.chain,
|
|
1729
|
+
token: e.inputToken.address,
|
|
1730
|
+
spender: e.spender,
|
|
1731
|
+
amount: 0n
|
|
1732
|
+
})
|
|
1733
|
+
), o.push(
|
|
1734
|
+
await te({
|
|
1735
|
+
provider: e.wallet.provider,
|
|
1736
|
+
publicClient: e.publicClient,
|
|
1737
|
+
account: e.wallet.account,
|
|
1738
|
+
chain: e.activeChain.chain,
|
|
1739
|
+
token: e.inputToken.address,
|
|
1740
|
+
spender: e.spender,
|
|
1741
|
+
amount: e.approvalMode === "max" ? void 0 : e.amount
|
|
1742
|
+
})
|
|
1743
|
+
), n = await Q(t, (i) => i >= e.amount, 5, 300), n < e.amount)
|
|
1744
|
+
throw new Error("Approval confirmed, but allowance is still below this quote. Try again.");
|
|
1745
|
+
return { approvalHashes: o, allowance: n };
|
|
1746
|
+
}
|
|
1747
|
+
function xn(e) {
|
|
1748
|
+
return {
|
|
1749
|
+
mode: "exactIn",
|
|
1750
|
+
inputSymbol: e.inputToken.symbol,
|
|
1751
|
+
outputSymbol: e.outputToken.symbol,
|
|
1752
|
+
amountIn: e.amountIn,
|
|
1753
|
+
amountOut: e.amountOut,
|
|
1754
|
+
feeAmount: e.feeAmount,
|
|
1755
|
+
feeBps: e.feeBps
|
|
1756
|
+
};
|
|
1757
|
+
}
|
|
1758
|
+
function On(e) {
|
|
1759
|
+
const t = e.gasUsed ?? 0n, n = e.effectiveGasPrice ?? 0n;
|
|
1760
|
+
return {
|
|
1761
|
+
transactionHash: e.transactionHash,
|
|
1762
|
+
blockNumber: e.blockNumber ?? 0n,
|
|
1763
|
+
gasUsed: t,
|
|
1764
|
+
effectiveGasPrice: n,
|
|
1765
|
+
feeWei: t * n
|
|
1766
|
+
};
|
|
1767
|
+
}
|
|
1768
|
+
async function Yn(e) {
|
|
1769
|
+
var p, d, f, w, S;
|
|
1770
|
+
await De({
|
|
1771
|
+
provider: e.wallet.provider,
|
|
1772
|
+
chain: e.activeChain,
|
|
1773
|
+
onChainId: e.onWalletChainId
|
|
1774
|
+
});
|
|
1775
|
+
const t = e.displayedQuote ?? await ee(
|
|
1776
|
+
e.inputToken,
|
|
1777
|
+
e.outputToken,
|
|
1778
|
+
e.amount,
|
|
1779
|
+
e.slippageBps,
|
|
1780
|
+
"exactIn",
|
|
1781
|
+
null,
|
|
1782
|
+
e.signal
|
|
1783
|
+
);
|
|
1784
|
+
await vn({
|
|
1785
|
+
wallet: e.wallet,
|
|
1786
|
+
publicClient: e.publicClient,
|
|
1787
|
+
activeChain: e.activeChain,
|
|
1788
|
+
inputToken: e.inputToken,
|
|
1789
|
+
spender: t.routerAddress,
|
|
1790
|
+
amount: t.amountIn,
|
|
1791
|
+
approvalMode: e.approvalMode ?? "exact",
|
|
1792
|
+
onStatus: e.onStatus
|
|
1793
|
+
}), (p = e.onStatus) == null || p.call(e, "submitting");
|
|
1794
|
+
const n = await ee(
|
|
1795
|
+
e.inputToken,
|
|
1796
|
+
e.outputToken,
|
|
1797
|
+
e.amount,
|
|
1798
|
+
e.slippageBps,
|
|
1799
|
+
"exactIn",
|
|
1800
|
+
e.wallet.account,
|
|
1801
|
+
e.signal
|
|
1802
|
+
);
|
|
1803
|
+
if (e.displayedQuote && n.amountOut < e.displayedQuote.userAmountOutMinimum)
|
|
1804
|
+
throw (d = e.onStatus) == null || d.call(e, "idle"), new _n(n);
|
|
1805
|
+
if (!n.calldata) throw new Error("Swap route could not be encoded. Try again.");
|
|
1806
|
+
const o = n.transactionValue || (ke(e.inputToken) ? n.amountIn : 0n), a = P({
|
|
1807
|
+
account: e.wallet.account,
|
|
1808
|
+
chain: e.activeChain.chain,
|
|
1809
|
+
transport: D(e.wallet.provider)
|
|
1810
|
+
}), i = await Cn(e.publicClient, {
|
|
1811
|
+
account: e.wallet.account,
|
|
1812
|
+
to: n.routerAddress,
|
|
1813
|
+
data: n.calldata,
|
|
1814
|
+
value: o
|
|
1815
|
+
}), c = await a.sendTransaction({
|
|
1816
|
+
to: n.routerAddress,
|
|
1817
|
+
data: n.calldata,
|
|
1818
|
+
value: o,
|
|
1819
|
+
...i ? { gas: i } : {}
|
|
1820
|
+
});
|
|
1821
|
+
(f = e.onTxHash) == null || f.call(e, c);
|
|
1822
|
+
const r = xn(n);
|
|
1823
|
+
try {
|
|
1824
|
+
(w = e.onSubmitted) == null || w.call(e, c, r);
|
|
1825
|
+
} catch (b) {
|
|
1826
|
+
console.warn("[AegisCore] onSubmitted callback failed", b);
|
|
1827
|
+
}
|
|
1828
|
+
let u = null;
|
|
1829
|
+
const l = await e.publicClient.waitForTransactionReceipt({
|
|
1830
|
+
hash: c,
|
|
1831
|
+
onReplaced: (b) => {
|
|
1832
|
+
var h;
|
|
1833
|
+
u = b.reason, (h = e.onTxHash) == null || h.call(e, b.transaction.hash);
|
|
1834
|
+
}
|
|
1835
|
+
});
|
|
1836
|
+
if (u === "cancelled") throw new Error("Swap was cancelled in the wallet.");
|
|
1837
|
+
if (l.status === "reverted") throw new Error("Swap reverted on-chain.");
|
|
1838
|
+
const s = On(l);
|
|
1839
|
+
return (S = e.onStatus) == null || S.call(e, "success"), {
|
|
1840
|
+
hash: l.transactionHash,
|
|
1841
|
+
explorerUrl: se(l.transactionHash, e.activeChain),
|
|
1842
|
+
quote: n,
|
|
1843
|
+
receiptSummary: s,
|
|
1844
|
+
swap: r
|
|
1845
|
+
};
|
|
1846
|
+
}
|
|
1847
|
+
function Jn(e) {
|
|
1848
|
+
return e === "approving" || e === "signing" || e === "submitting";
|
|
1849
|
+
}
|
|
1850
|
+
const Pn = {
|
|
1851
|
+
total: 0,
|
|
1852
|
+
completed: 0,
|
|
1853
|
+
active: null
|
|
1854
|
+
};
|
|
1855
|
+
function U({ total: e, completed: t }) {
|
|
1856
|
+
return e <= 0 ? 0 : t / e * 100;
|
|
1857
|
+
}
|
|
1858
|
+
function Dn({
|
|
1859
|
+
status: e,
|
|
1860
|
+
txHash: t,
|
|
1861
|
+
approvalRequired: n,
|
|
1862
|
+
approvalDone: o,
|
|
1863
|
+
authorizationRequired: a
|
|
1864
|
+
}) {
|
|
1865
|
+
const i = n || o, c = a, r = e === "idle" && !o ? 0 : 1 + (i ? 1 : 0) + (c ? 1 : 0);
|
|
1866
|
+
if (r === 0) return Pn;
|
|
1867
|
+
if (e === "success") return { total: r, completed: r, active: null };
|
|
1868
|
+
if (e === "idle")
|
|
1869
|
+
return {
|
|
1870
|
+
total: r,
|
|
1871
|
+
completed: o && i ? 1 : 0,
|
|
1872
|
+
active: null
|
|
1873
|
+
};
|
|
1874
|
+
if (e === "approving") {
|
|
1875
|
+
if (o && c) {
|
|
1876
|
+
const s = i ? 1 : 0;
|
|
1877
|
+
return { total: r, completed: s, active: s + 1 };
|
|
1878
|
+
}
|
|
1879
|
+
return {
|
|
1880
|
+
total: r,
|
|
1881
|
+
completed: 0,
|
|
1882
|
+
active: i || c ? 1 : null
|
|
1883
|
+
};
|
|
1884
|
+
}
|
|
1885
|
+
const u = i ? 1 : 0;
|
|
1886
|
+
if (e === "signing")
|
|
1887
|
+
return {
|
|
1888
|
+
total: r,
|
|
1889
|
+
completed: u,
|
|
1890
|
+
active: c ? u + 1 : null
|
|
1891
|
+
};
|
|
1892
|
+
const l = r - 1;
|
|
1893
|
+
return {
|
|
1894
|
+
total: r,
|
|
1895
|
+
completed: t ? r : l,
|
|
1896
|
+
active: t ? null : r
|
|
1897
|
+
};
|
|
1898
|
+
}
|
|
1899
|
+
function Zn({
|
|
1900
|
+
status: e,
|
|
1901
|
+
inputSymbol: t,
|
|
1902
|
+
txHash: n,
|
|
1903
|
+
actionError: o,
|
|
1904
|
+
approvalRequired: a,
|
|
1905
|
+
approvalDone: i,
|
|
1906
|
+
authorizationRequired: c
|
|
1907
|
+
}) {
|
|
1908
|
+
const r = Dn({
|
|
1909
|
+
status: e,
|
|
1910
|
+
txHash: n,
|
|
1911
|
+
approvalRequired: a,
|
|
1912
|
+
approvalDone: i,
|
|
1913
|
+
authorizationRequired: c
|
|
1914
|
+
});
|
|
1915
|
+
return o ? {
|
|
1916
|
+
state: "error",
|
|
1917
|
+
label: o,
|
|
1918
|
+
walletPrompts: r,
|
|
1919
|
+
completePct: 100,
|
|
1920
|
+
activeWidthPct: 0
|
|
1921
|
+
} : e === "success" ? {
|
|
1922
|
+
state: "success",
|
|
1923
|
+
label: "Swap confirmed",
|
|
1924
|
+
walletPrompts: r,
|
|
1925
|
+
completePct: 100,
|
|
1926
|
+
activeWidthPct: 0
|
|
1927
|
+
} : e === "idle" ? i ? {
|
|
1928
|
+
state: "pending",
|
|
1929
|
+
label: `ERC20 approval complete · ready to swap · ${r.completed} of ${r.total} prompts done`,
|
|
1930
|
+
walletPrompts: r,
|
|
1931
|
+
completePct: U(r),
|
|
1932
|
+
activeWidthPct: 0
|
|
1933
|
+
} : null : e === "approving" ? {
|
|
1934
|
+
state: "pending",
|
|
1935
|
+
label: i && c ? `Approving Permit2 router · wallet prompt ${r.active ?? 1} of ${r.total}` : `Approving ${t} for Permit2 · wallet prompt ${r.active ?? 1} of ${r.total}`,
|
|
1936
|
+
walletPrompts: r,
|
|
1937
|
+
completePct: U(r),
|
|
1938
|
+
activeWidthPct: 100
|
|
1939
|
+
} : a || i ? {
|
|
1940
|
+
state: e === "submitting" && n ? "mining" : "pending",
|
|
1941
|
+
label: e === "signing" ? `ERC20 approval complete · sign Permit2 permit · wallet prompt ${r.active ?? 2} of ${r.total}` : n ? `Confirming swap · ${r.completed} of ${r.total} wallet prompts complete` : `Approve complete · submitting swap · wallet prompt ${r.active ?? r.total} of ${r.total}`,
|
|
1942
|
+
walletPrompts: r,
|
|
1943
|
+
completePct: U(r),
|
|
1944
|
+
activeWidthPct: 100
|
|
1945
|
+
} : {
|
|
1946
|
+
state: e === "submitting" && n ? "mining" : "pending",
|
|
1947
|
+
label: e === "signing" ? c ? `Signing Permit2 spending permit · wallet prompt ${r.active ?? 1} of ${r.total}` : "Preparing swap" : n ? `Confirming swap on-chain · ${r.completed} of ${r.total} wallet prompts complete` : `Submitting swap · wallet prompt ${r.active ?? r.total} of ${r.total}`,
|
|
1948
|
+
walletPrompts: r,
|
|
1949
|
+
completePct: U(r),
|
|
1950
|
+
activeWidthPct: 100
|
|
1951
|
+
};
|
|
1952
|
+
}
|
|
1953
|
+
export {
|
|
1954
|
+
at as AEGIS_DYNAMIC_FEE_FLAG,
|
|
1955
|
+
j as AEGIS_SWAP_CHAINS,
|
|
1956
|
+
E as AEGIS_SWAP_CHAIN_ID,
|
|
1957
|
+
it as AEGIS_SWAP_DEFAULT_FEE_BPS,
|
|
1958
|
+
pe as AEGIS_SWAP_DEFAULT_FEE_RECIPIENT,
|
|
1959
|
+
ct as AEGIS_SWAP_DEFAULT_METADATA_ENDPOINT,
|
|
1960
|
+
Nn as AEGIS_SWAP_DEFAULT_POOL_IDS,
|
|
1961
|
+
rt as AEGIS_SWAP_DEFAULT_RPC_URLS,
|
|
1962
|
+
ot as AEGIS_SWAP_HOOK,
|
|
1963
|
+
ut as AEGIS_SWAP_MAINNET_CHAIN,
|
|
1964
|
+
H as AEGIS_SWAP_MAINNET_UNISWAP_V4_CONTRACTS,
|
|
1965
|
+
Un as AEGIS_SWAP_MARKETS,
|
|
1966
|
+
fe as AEGIS_SWAP_PERMIT2,
|
|
1967
|
+
me as AEGIS_SWAP_ROUTER,
|
|
1968
|
+
y as AEGIS_SWAP_TOKENS,
|
|
1969
|
+
he as AEGIS_SWAP_V4_QUOTER,
|
|
1970
|
+
Bn as AGGREGATED_SWAP_CURATED_TOKENS,
|
|
1971
|
+
X as AGGREGATED_SWAP_DEFAULT_TOKENS,
|
|
1972
|
+
ft as AGGREGATED_SWAP_DEFAULT_TOKEN_LIST,
|
|
1973
|
+
Fn as AGGREGATED_SWAP_TOKEN_PRESETS,
|
|
1974
|
+
dt as AGGREGATED_SWAP_WOLFGAME_TOKENS,
|
|
1975
|
+
ht as AGGREGATED_SWAP_WOLFGAME_TOKEN_LIST,
|
|
1976
|
+
Oe as DEFAULT_PERMIT_EXPIRATION_SECONDS,
|
|
1977
|
+
An as DirectPoolSwapPriceMovedError,
|
|
1978
|
+
Se as KyberSwapApiError,
|
|
1979
|
+
_n as KyberSwapPriceMovedError,
|
|
1980
|
+
$e as MAX_UINT128,
|
|
1981
|
+
N as MAX_UINT160,
|
|
1982
|
+
ve as MAX_UINT256,
|
|
1983
|
+
Tn as NATIVE_TOKEN_ADDRESS,
|
|
1984
|
+
Qt as PERMIT2_FAR_FUTURE_EXPIRATION,
|
|
1985
|
+
xe as SWAP_TX_DEADLINE_SECONDS,
|
|
1986
|
+
de as UNISWAP_V4_CONTRACTS_BY_CHAIN,
|
|
1987
|
+
Ln as aggregatedSwapErrorMessage,
|
|
1988
|
+
In as approveDirectPoolSwapInput,
|
|
1989
|
+
te as approveErc20Spender,
|
|
1990
|
+
Jt as approveErc20ToPermit2,
|
|
1991
|
+
vn as approveKyberSwapInput,
|
|
1992
|
+
Zt as approvePermit2ToRouter,
|
|
1993
|
+
k as assertUint128,
|
|
1994
|
+
tt as buildExactInSwapTransaction,
|
|
1995
|
+
nt as buildExactOutSwapTransaction,
|
|
1996
|
+
Wt as buildKyberSwapRoute,
|
|
1997
|
+
gt as buildSignedPermitBatch,
|
|
1998
|
+
ue as computePoolId,
|
|
1999
|
+
Et as createAegisSwapChainConfig,
|
|
2000
|
+
Wn as createAegisSwapChains,
|
|
2001
|
+
Gn as createAegisSwapMarketsFromPools,
|
|
2002
|
+
bt as createAegisSwapPoolMarket,
|
|
2003
|
+
C as createAegisSwapUniswapV4Contracts,
|
|
2004
|
+
zn as createSwapPublicClient,
|
|
2005
|
+
De as ensureWalletChain,
|
|
2006
|
+
Mt as errorMessage,
|
|
2007
|
+
Cn as estimateSwapGasWithBuffer,
|
|
2008
|
+
Qn as executeDirectPoolSwap,
|
|
2009
|
+
Yn as executeKyberSwap,
|
|
2010
|
+
ee as fetchAggregatedSwapQuote,
|
|
2011
|
+
Ot as fetchDirectSwapQuote,
|
|
2012
|
+
qn as fetchGlobalTokenMetadata,
|
|
2013
|
+
Bt as fetchKyberSwapRoute,
|
|
2014
|
+
se as getExplorerUrl,
|
|
2015
|
+
on as getIchiIconGuess,
|
|
2016
|
+
rn as getInjectedProvider,
|
|
2017
|
+
ln as getProviderAccount,
|
|
2018
|
+
$ as getProviderChainId,
|
|
2019
|
+
_t as getZeroForOne,
|
|
2020
|
+
Jn as isBusy,
|
|
2021
|
+
Hn as isDocumentVisible,
|
|
2022
|
+
cn as isEip1193Provider,
|
|
2023
|
+
ke as isNativeToken,
|
|
2024
|
+
_e as isRetryableKyberSwapError,
|
|
2025
|
+
Ae as isUserRejectedError,
|
|
2026
|
+
W as normalizeAccount,
|
|
2027
|
+
un as normalizeWalletConnection,
|
|
2028
|
+
kt as outputFeeForQuote,
|
|
2029
|
+
Q as pollUntil,
|
|
2030
|
+
Dt as quoteSpendAmount,
|
|
2031
|
+
F as readErc20Allowance,
|
|
2032
|
+
Pe as readPermit2RouterAllowance,
|
|
2033
|
+
Pt as reconcileSubmitQuote,
|
|
2034
|
+
sn as requestProviderAccount,
|
|
2035
|
+
$n as resolveTokenIconUrl,
|
|
2036
|
+
Xn as resolveWalletSession,
|
|
2037
|
+
jn as retryOnError,
|
|
2038
|
+
Kn as sameQuote,
|
|
2039
|
+
Vn as subscribeProvider,
|
|
2040
|
+
wn as switchProviderChain,
|
|
2041
|
+
Zn as transactionProgressView,
|
|
2042
|
+
bn as waitForProviderChain
|
|
2043
|
+
};
|