@swapkit/core 1.0.0-rc.119 → 1.0.0-rc.120

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.
@@ -1,206 +1,205 @@
1
- var re = Object.defineProperty;
2
- var ye = (r, e, t) => e in r ? re(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
3
- var y = (r, e, t) => (ye(r, typeof e != "symbol" ? e + "" : e, t), t), ue = (r, e, t) => {
4
- if (!e.has(r))
5
- throw TypeError("Cannot " + t);
6
- };
7
- var M = (r, e, t) => (ue(r, e, "read from private field"), t ? t.call(r) : e.get(r)), F = (r, e, t) => {
8
- if (e.has(r))
9
- throw TypeError("Cannot add the same private member more than once");
10
- e instanceof WeakSet ? e.add(r) : e.set(r, t);
11
- };
12
- import { AssetValue as L, SwapKitError as s, RequestClient as N, SwapKitNumber as oe, getMemoFor as O, getMinAmountByChain as U, gasFeeMultiplier as de } from "@swapkit/helpers";
13
- export * from "@swapkit/helpers";
14
- import { ChainToExplorerUrl as Y, Chain as a, ApiUrl as B, AGG_SWAP as le, ChainToChainId as me, SWAP_OUT as Te, SWAP_IN as ce, FeeOption as K, TCAvalancheDepositABI as be, TCBscDepositABI as fe, TCEthereumVaultAbi as we, MemoType as v } from "@swapkit/types";
15
- export * from "@swapkit/types";
16
- const ee = ({ chain: r, txHash: e }) => {
17
- const t = Y[r];
18
- switch (r) {
19
- case a.Binance:
20
- case a.Maya:
21
- case a.Kujira:
22
- case a.THORChain:
23
- return `${t}/tx/${e.startsWith("0x") ? e.slice(2) : e}`;
24
- case a.Arbitrum:
25
- case a.Avalanche:
26
- case a.BinanceSmartChain:
27
- case a.Ethereum:
28
- case a.Optimism:
29
- case a.Polkadot:
30
- case a.Polygon:
31
- return `${t}/tx/${e.startsWith("0x") ? e : `0x${e}`}`;
32
- case a.Cosmos:
33
- return `${t}/transactions/${e}`;
34
- case a.Litecoin:
35
- case a.Bitcoin:
36
- case a.BitcoinCash:
37
- case a.Dogecoin:
38
- return `${t}/transaction/${e.toLowerCase()}`;
1
+ var __require = ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
+ }) : x)(function(x) {
4
+ if (typeof require !== "undefined")
5
+ return require.apply(this, arguments);
6
+ throw Error('Dynamic require of "' + x + '" is not supported');
7
+ });
8
+
9
+ // src/client/index.ts
10
+ import {AssetValue, SwapKitError} from "@swapkit/helpers";
11
+ import {Chain as Chain2} from "@swapkit/types";
12
+
13
+ // src/helpers/explorerUrls.ts
14
+ import {Chain, ChainToExplorerUrl} from "@swapkit/types";
15
+ function getExplorerTxUrl({ chain, txHash }) {
16
+ const baseUrl = ChainToExplorerUrl[chain];
17
+ switch (chain) {
18
+ case Chain.Binance:
19
+ case Chain.Maya:
20
+ case Chain.Kujira:
21
+ case Chain.Cosmos:
22
+ case Chain.THORChain:
23
+ return `${baseUrl}/tx/${txHash.startsWith("0x") ? txHash.slice(2) : txHash}`;
24
+ case Chain.Arbitrum:
25
+ case Chain.Avalanche:
26
+ case Chain.BinanceSmartChain:
27
+ case Chain.Ethereum:
28
+ case Chain.Optimism:
29
+ case Chain.Polkadot:
30
+ case Chain.Polygon:
31
+ return `${baseUrl}/tx/${txHash.startsWith("0x") ? txHash : `0x${txHash}`}`;
32
+ case Chain.Litecoin:
33
+ case Chain.Bitcoin:
34
+ case Chain.BitcoinCash:
35
+ case Chain.Dogecoin:
36
+ return `${baseUrl}/transaction/${txHash.toLowerCase()}`;
39
37
  default:
40
- throw new Error(`Unsupported chain: ${r}`);
38
+ throw new Error(`Unsupported chain: ${chain}`);
41
39
  }
42
- }, te = ({ chain: r, address: e }) => {
43
- const t = Y[r];
44
- switch (r) {
45
- case a.Arbitrum:
46
- case a.Avalanche:
47
- case a.Binance:
48
- case a.BinanceSmartChain:
49
- case a.Bitcoin:
50
- case a.BitcoinCash:
51
- case a.Dogecoin:
52
- case a.Ethereum:
53
- case a.Kujira:
54
- case a.Litecoin:
55
- case a.Maya:
56
- case a.Optimism:
57
- case a.Polkadot:
58
- case a.Polygon:
59
- case a.THORChain:
60
- return `${t}/address/${e}`;
61
- case a.Cosmos:
62
- return `${t}/account/${e}`;
63
- default:
64
- throw new Error(`Unsupported chain: ${r}`);
65
- }
66
- };
67
- var Me = /* @__PURE__ */ ((r) => (r.Approve = "approve", r.CheckOnly = "checkOnly", r))(Me || {});
68
- function ze({
69
- stagenet: r,
70
- wallets: e,
71
- plugins: t,
72
- config: n = {},
73
- apis: p,
74
- rpcUrls: i
40
+ }
41
+ function getExplorerAddressUrl({ chain, address }) {
42
+ const baseUrl = ChainToExplorerUrl[chain];
43
+ return `${baseUrl}/address/${address}`;
44
+ }
45
+
46
+ // src/client/index.ts
47
+ function SwapKit({
48
+ stagenet,
49
+ wallets,
50
+ plugins,
51
+ config = {},
52
+ apis,
53
+ rpcUrls
75
54
  }) {
76
- const o = {}, c = {};
77
- for (const u of t) {
78
- const { name: m, methods: _ } = u({ wallets: o, stagenet: r });
79
- c[m] = _;
55
+ const connectedWallets = {};
56
+ const availablePlugins = {};
57
+ for (const plugin of plugins) {
58
+ const { name, methods } = plugin({ wallets: connectedWallets, stagenet });
59
+ availablePlugins[name] = methods;
80
60
  }
81
- const f = e.reduce((u, m) => (u[m.connectMethodName] = m.connect({
82
- addChain: w,
83
- config: n,
84
- apis: p,
85
- rpcUrls: i
86
- }), u), {});
87
- function b(u) {
88
- const m = c[u] || Object.values(c)[0];
89
- if (!m)
90
- throw new s("core_plugin_not_found", "Could not find the requested plugin");
91
- return m;
61
+ const connectWalletMethods = wallets.reduce((acc, wallet) => {
62
+ acc[wallet.connectMethodName] = wallet.connect({
63
+ addChain,
64
+ config,
65
+ apis,
66
+ rpcUrls
67
+ });
68
+ return acc;
69
+ }, {});
70
+ function getSwapKitPlugin(pluginName) {
71
+ const plugin = availablePlugins[pluginName] || Object.values(availablePlugins)[0];
72
+ if (!plugin) {
73
+ throw new SwapKitError("core_plugin_not_found", "Could not find the requested plugin");
74
+ }
75
+ return plugin;
92
76
  }
93
- function w(u) {
94
- o[u.chain] = u;
77
+ function addChain(connectWallet) {
78
+ connectedWallets[connectWallet.chain] = connectWallet;
95
79
  }
96
- function T({
97
- assetValue: u,
98
- type: m = "checkOnly",
99
- contractAddress: _
80
+ function approve({
81
+ assetValue,
82
+ type = "checkOnly",
83
+ contractAddress
100
84
  }) {
101
- const { address: x, chain: R, isGasAsset: ie, isSynthetic: pe } = u, G = [a.Ethereum, a.Avalanche, a.BinanceSmartChain].includes(R);
102
- if (G && ie || !G || pe)
103
- return Promise.resolve(m === "checkOnly" ? !0 : "approved");
104
- const C = o[R], Q = m === "checkOnly" ? C == null ? void 0 : C.isApproved : C == null ? void 0 : C.approve;
105
- if (!Q)
106
- throw new s("core_wallet_connection_not_found");
107
- const $ = l(R);
108
- if (!(x && $))
109
- throw new s("core_approve_asset_address_or_from_not_found");
110
- const se = _;
111
- return Q({
112
- amount: u.getBaseValue("bigint"),
113
- assetAddress: x,
114
- from: $,
115
- spenderAddress: se
85
+ const { address, chain, isGasAsset, isSynthetic } = assetValue;
86
+ const isEVMChain = [Chain2.Ethereum, Chain2.Avalanche, Chain2.BinanceSmartChain].includes(chain);
87
+ const isNativeEVM = isEVMChain && isGasAsset;
88
+ if (isNativeEVM || !isEVMChain || isSynthetic) {
89
+ return Promise.resolve(type === "checkOnly" ? true : "approved");
90
+ }
91
+ const walletMethods = connectedWallets[chain];
92
+ const walletAction = type === "checkOnly" ? walletMethods?.isApproved : walletMethods?.approve;
93
+ if (!walletAction)
94
+ throw new SwapKitError("core_wallet_connection_not_found");
95
+ const from = getAddress(chain);
96
+ if (!(address && from))
97
+ throw new SwapKitError("core_approve_asset_address_or_from_not_found");
98
+ const spenderAddress = contractAddress;
99
+ return walletAction({
100
+ amount: assetValue.getBaseValue("bigint"),
101
+ assetAddress: address,
102
+ from,
103
+ spenderAddress
116
104
  });
117
105
  }
118
- function d(u) {
119
- return o[u];
120
- }
121
- function l(u) {
122
- var m;
123
- return ((m = d(u)) == null ? void 0 : m.address) || "";
124
- }
125
- function A(u) {
126
- var m;
127
- return ((m = d(u)) == null ? void 0 : m.balance) || [];
106
+ function getWallet(chain) {
107
+ return connectedWallets[chain];
128
108
  }
129
- function k(u, m) {
130
- return ee({ chain: u, txHash: m });
109
+ function getAddress(chain) {
110
+ return getWallet(chain)?.address || "";
131
111
  }
132
- function h(u, m) {
133
- return te({ chain: u, address: m });
112
+ function getBalance(chain) {
113
+ return getWallet(chain)?.balance || [];
134
114
  }
135
- function g({ address: u, chain: m }) {
136
- var _, x;
137
- return (x = (_ = d(m)) == null ? void 0 : _.validateAddress) == null ? void 0 : x.call(_, u);
115
+ function validateAddress({ address, chain }) {
116
+ return getWallet(chain)?.validateAddress?.(address);
138
117
  }
139
- async function I(u, m) {
140
- const _ = [L.fromChainOrSignature(u)], x = d(u);
141
- try {
142
- if (!x)
143
- throw new s("core_wallet_connection_not_found");
144
- const R = await (x == null ? void 0 : x.getBalance(x.address, m));
145
- return x.balance = R != null && R.length ? R : _, x;
146
- } catch (R) {
147
- throw new s("core_wallet_connection_not_found", R);
118
+ async function getWalletWithBalance(chain, potentialScamFilter) {
119
+ const defaultBalance = [AssetValue.fromChainOrSignature(chain)];
120
+ const wallet = getWallet(chain);
121
+ if (!wallet) {
122
+ throw new SwapKitError("core_wallet_connection_not_found");
148
123
  }
124
+ const balance = await wallet?.getBalance(wallet.address, potentialScamFilter);
125
+ wallet.balance = balance?.length ? balance : defaultBalance;
126
+ return wallet;
149
127
  }
150
- function D(u, m) {
151
- return T({
152
- assetValue: u,
153
- contractAddress: m,
154
- type: "approve"
155
- /* Approve */
156
- });
128
+ function approveAssetValue(assetValue, contractAddress) {
129
+ return approve({ assetValue, contractAddress, type: ApproveMode.Approve });
157
130
  }
158
- function X(u, m) {
159
- return T({
160
- assetValue: u,
161
- contractAddress: m,
162
- type: "checkOnly"
163
- /* CheckOnly */
164
- });
131
+ function isAssetValueApproved(assetValue, contractAddress) {
132
+ return approve({ assetValue, contractAddress, type: ApproveMode.CheckOnly });
165
133
  }
166
- function ae({ provider: u, ...m }) {
167
- return b(u == null ? void 0 : u.name).swap({ provider: u, ...m });
134
+ function swap({ provider, ...rest }) {
135
+ const plugin = getSwapKitPlugin(provider?.name);
136
+ return plugin.swap({ provider, ...rest });
168
137
  }
169
138
  return {
170
- ...c,
171
- ...f,
172
- approveAssetValue: D,
173
- getAddress: l,
174
- getBalance: A,
175
- getExplorerAddressUrl: h,
176
- getExplorerTxUrl: k,
177
- getWallet: d,
178
- getWalletWithBalance: I,
179
- isAssetValueApproved: X,
180
- swap: ae,
181
- validateAddress: g
139
+ ...availablePlugins,
140
+ ...connectWalletMethods,
141
+ getExplorerAddressUrl,
142
+ getExplorerTxUrl,
143
+ approveAssetValue,
144
+ getAddress,
145
+ getBalance,
146
+ getWallet,
147
+ getWalletWithBalance,
148
+ isAssetValueApproved,
149
+ swap,
150
+ validateAddress
182
151
  };
183
152
  }
184
- const Ae = [
153
+ var ApproveMode;
154
+ (function(ApproveMode2) {
155
+ ApproveMode2["Approve"] = "approve";
156
+ ApproveMode2["CheckOnly"] = "checkOnly";
157
+ })(ApproveMode || (ApproveMode = {}));
158
+ // src/client/old.ts
159
+ import {
160
+ AssetValue as AssetValue2,
161
+ SwapKitApi,
162
+ SwapKitError as SwapKitError2,
163
+ SwapKitNumber,
164
+ gasFeeMultiplier,
165
+ getMemoFor,
166
+ getMinAmountByChain,
167
+ wrapWithThrow
168
+ } from "@swapkit/helpers";
169
+ import {
170
+ AGG_SWAP,
171
+ Chain as Chain3,
172
+ ChainToChainId,
173
+ FeeOption,
174
+ MemoType,
175
+ SWAP_IN,
176
+ SWAP_OUT,
177
+ TCAvalancheDepositABI,
178
+ TCBscDepositABI,
179
+ TCEthereumVaultAbi
180
+ } from "@swapkit/types";
181
+
182
+ // src/aggregator/contracts/avaxGeneric.ts
183
+ var avaxGeneric = [
185
184
  {
186
185
  inputs: [{ internalType: "address", name: "_ttp", type: "address" }],
187
186
  stateMutability: "nonpayable",
188
187
  type: "constructor"
189
188
  },
190
189
  {
191
- anonymous: !1,
190
+ anonymous: false,
192
191
  inputs: [
193
- { indexed: !1, internalType: "uint256", name: "fee", type: "uint256" },
194
- { indexed: !1, internalType: "address", name: "feeRecipient", type: "address" }
192
+ { indexed: false, internalType: "uint256", name: "fee", type: "uint256" },
193
+ { indexed: false, internalType: "address", name: "feeRecipient", type: "address" }
195
194
  ],
196
195
  name: "FeeSet",
197
196
  type: "event"
198
197
  },
199
198
  {
200
- anonymous: !1,
199
+ anonymous: false,
201
200
  inputs: [
202
- { indexed: !0, internalType: "address", name: "owner", type: "address" },
203
- { indexed: !1, internalType: "bool", name: "active", type: "bool" }
201
+ { indexed: true, internalType: "address", name: "owner", type: "address" },
202
+ { indexed: false, internalType: "bool", name: "active", type: "bool" }
204
203
  ],
205
204
  name: "OwnerSet",
206
205
  type: "event"
@@ -272,7 +271,10 @@ const Ae = [
272
271
  type: "function"
273
272
  },
274
273
  { stateMutability: "payable", type: "receive" }
275
- ], ve = [
274
+ ];
275
+
276
+ // src/aggregator/contracts/avaxWoofi.ts
277
+ var avaxWoofi = [
276
278
  {
277
279
  inputs: [
278
280
  { internalType: "address", name: "_ttp", type: "address" },
@@ -283,44 +285,44 @@ const Ae = [
283
285
  type: "constructor"
284
286
  },
285
287
  {
286
- anonymous: !1,
288
+ anonymous: false,
287
289
  inputs: [
288
- { indexed: !1, internalType: "uint256", name: "fee", type: "uint256" },
289
- { indexed: !1, internalType: "address", name: "feeRecipient", type: "address" }
290
+ { indexed: false, internalType: "uint256", name: "fee", type: "uint256" },
291
+ { indexed: false, internalType: "address", name: "feeRecipient", type: "address" }
290
292
  ],
291
293
  name: "FeeSet",
292
294
  type: "event"
293
295
  },
294
296
  {
295
- anonymous: !1,
297
+ anonymous: false,
296
298
  inputs: [
297
- { indexed: !0, internalType: "address", name: "owner", type: "address" },
298
- { indexed: !1, internalType: "bool", name: "active", type: "bool" }
299
+ { indexed: true, internalType: "address", name: "owner", type: "address" },
300
+ { indexed: false, internalType: "bool", name: "active", type: "bool" }
299
301
  ],
300
302
  name: "OwnerSet",
301
303
  type: "event"
302
304
  },
303
305
  {
304
- anonymous: !1,
306
+ anonymous: false,
305
307
  inputs: [
306
- { indexed: !1, internalType: "address", name: "from", type: "address" },
307
- { indexed: !1, internalType: "address", name: "token", type: "address" },
308
- { indexed: !1, internalType: "uint256", name: "amount", type: "uint256" },
309
- { indexed: !1, internalType: "uint256", name: "out", type: "uint256" },
310
- { indexed: !1, internalType: "uint256", name: "fee", type: "uint256" },
311
- { indexed: !1, internalType: "address", name: "vault", type: "address" },
312
- { indexed: !1, internalType: "string", name: "memo", type: "string" }
308
+ { indexed: false, internalType: "address", name: "from", type: "address" },
309
+ { indexed: false, internalType: "address", name: "token", type: "address" },
310
+ { indexed: false, internalType: "uint256", name: "amount", type: "uint256" },
311
+ { indexed: false, internalType: "uint256", name: "out", type: "uint256" },
312
+ { indexed: false, internalType: "uint256", name: "fee", type: "uint256" },
313
+ { indexed: false, internalType: "address", name: "vault", type: "address" },
314
+ { indexed: false, internalType: "string", name: "memo", type: "string" }
313
315
  ],
314
316
  name: "SwapIn",
315
317
  type: "event"
316
318
  },
317
319
  {
318
- anonymous: !1,
320
+ anonymous: false,
319
321
  inputs: [
320
- { indexed: !1, internalType: "address", name: "to", type: "address" },
321
- { indexed: !1, internalType: "address", name: "token", type: "address" },
322
- { indexed: !1, internalType: "uint256", name: "amount", type: "uint256" },
323
- { indexed: !1, internalType: "uint256", name: "fee", type: "uint256" }
322
+ { indexed: false, internalType: "address", name: "to", type: "address" },
323
+ { indexed: false, internalType: "address", name: "token", type: "address" },
324
+ { indexed: false, internalType: "uint256", name: "amount", type: "uint256" },
325
+ { indexed: false, internalType: "uint256", name: "fee", type: "uint256" }
324
326
  ],
325
327
  name: "SwapOut",
326
328
  type: "event"
@@ -416,40 +418,43 @@ const Ae = [
416
418
  type: "function"
417
419
  },
418
420
  { stateMutability: "payable", type: "receive" }
419
- ], ke = [
421
+ ];
422
+
423
+ // src/aggregator/contracts/bscGeneric.ts
424
+ var bscGeneric = [
420
425
  {
421
426
  inputs: [{ internalType: "address", name: "_ttp", type: "address" }],
422
427
  stateMutability: "nonpayable",
423
428
  type: "constructor"
424
429
  },
425
430
  {
426
- anonymous: !1,
431
+ anonymous: false,
427
432
  inputs: [
428
- { indexed: !1, internalType: "uint256", name: "fee", type: "uint256" },
429
- { indexed: !1, internalType: "address", name: "feeRecipient", type: "address" }
433
+ { indexed: false, internalType: "uint256", name: "fee", type: "uint256" },
434
+ { indexed: false, internalType: "address", name: "feeRecipient", type: "address" }
430
435
  ],
431
436
  name: "FeeSet",
432
437
  type: "event"
433
438
  },
434
439
  {
435
- anonymous: !1,
440
+ anonymous: false,
436
441
  inputs: [
437
- { indexed: !0, internalType: "address", name: "owner", type: "address" },
438
- { indexed: !1, internalType: "bool", name: "active", type: "bool" }
442
+ { indexed: true, internalType: "address", name: "owner", type: "address" },
443
+ { indexed: false, internalType: "bool", name: "active", type: "bool" }
439
444
  ],
440
445
  name: "OwnerSet",
441
446
  type: "event"
442
447
  },
443
448
  {
444
- anonymous: !1,
449
+ anonymous: false,
445
450
  inputs: [
446
- { indexed: !1, internalType: "address", name: "from", type: "address" },
447
- { indexed: !1, internalType: "address", name: "token", type: "address" },
448
- { indexed: !1, internalType: "uint256", name: "amount", type: "uint256" },
449
- { indexed: !1, internalType: "uint256", name: "out", type: "uint256" },
450
- { indexed: !1, internalType: "uint256", name: "fee", type: "uint256" },
451
- { indexed: !1, internalType: "address", name: "vault", type: "address" },
452
- { indexed: !1, internalType: "string", name: "memo", type: "string" }
451
+ { indexed: false, internalType: "address", name: "from", type: "address" },
452
+ { indexed: false, internalType: "address", name: "token", type: "address" },
453
+ { indexed: false, internalType: "uint256", name: "amount", type: "uint256" },
454
+ { indexed: false, internalType: "uint256", name: "out", type: "uint256" },
455
+ { indexed: false, internalType: "uint256", name: "fee", type: "uint256" },
456
+ { indexed: false, internalType: "address", name: "vault", type: "address" },
457
+ { indexed: false, internalType: "string", name: "memo", type: "string" }
453
458
  ],
454
459
  name: "SwapIn",
455
460
  type: "event"
@@ -521,26 +526,29 @@ const Ae = [
521
526
  type: "function"
522
527
  },
523
528
  { stateMutability: "payable", type: "receive" }
524
- ], he = [
529
+ ];
530
+
531
+ // src/aggregator/contracts/ethGeneric.ts
532
+ var ethGeneric = [
525
533
  {
526
534
  inputs: [{ internalType: "address", name: "_ttp", type: "address" }],
527
535
  stateMutability: "nonpayable",
528
536
  type: "constructor"
529
537
  },
530
538
  {
531
- anonymous: !1,
539
+ anonymous: false,
532
540
  inputs: [
533
- { indexed: !1, internalType: "uint256", name: "fee", type: "uint256" },
534
- { indexed: !1, internalType: "address", name: "feeRecipient", type: "address" }
541
+ { indexed: false, internalType: "uint256", name: "fee", type: "uint256" },
542
+ { indexed: false, internalType: "address", name: "feeRecipient", type: "address" }
535
543
  ],
536
544
  name: "FeeSet",
537
545
  type: "event"
538
546
  },
539
547
  {
540
- anonymous: !1,
548
+ anonymous: false,
541
549
  inputs: [
542
- { indexed: !0, internalType: "address", name: "owner", type: "address" },
543
- { indexed: !1, internalType: "bool", name: "active", type: "bool" }
550
+ { indexed: true, internalType: "address", name: "owner", type: "address" },
551
+ { indexed: false, internalType: "bool", name: "active", type: "bool" }
544
552
  ],
545
553
  name: "OwnerSet",
546
554
  type: "event"
@@ -612,7 +620,10 @@ const Ae = [
612
620
  type: "function"
613
621
  },
614
622
  { stateMutability: "payable", type: "receive" }
615
- ], ge = [
623
+ ];
624
+
625
+ // src/aggregator/contracts/pancakeV2.ts
626
+ var pancakeV2 = [
616
627
  {
617
628
  inputs: [
618
629
  { internalType: "address", name: "_ttp", type: "address" },
@@ -623,44 +634,44 @@ const Ae = [
623
634
  type: "constructor"
624
635
  },
625
636
  {
626
- anonymous: !1,
637
+ anonymous: false,
627
638
  inputs: [
628
- { indexed: !1, internalType: "uint256", name: "fee", type: "uint256" },
629
- { indexed: !1, internalType: "address", name: "feeRecipient", type: "address" }
639
+ { indexed: false, internalType: "uint256", name: "fee", type: "uint256" },
640
+ { indexed: false, internalType: "address", name: "feeRecipient", type: "address" }
630
641
  ],
631
642
  name: "FeeSet",
632
643
  type: "event"
633
644
  },
634
645
  {
635
- anonymous: !1,
646
+ anonymous: false,
636
647
  inputs: [
637
- { indexed: !0, internalType: "address", name: "owner", type: "address" },
638
- { indexed: !1, internalType: "bool", name: "active", type: "bool" }
648
+ { indexed: true, internalType: "address", name: "owner", type: "address" },
649
+ { indexed: false, internalType: "bool", name: "active", type: "bool" }
639
650
  ],
640
651
  name: "OwnerSet",
641
652
  type: "event"
642
653
  },
643
654
  {
644
- anonymous: !1,
655
+ anonymous: false,
645
656
  inputs: [
646
- { indexed: !1, internalType: "address", name: "from", type: "address" },
647
- { indexed: !1, internalType: "address", name: "token", type: "address" },
648
- { indexed: !1, internalType: "uint256", name: "amount", type: "uint256" },
649
- { indexed: !1, internalType: "uint256", name: "out", type: "uint256" },
650
- { indexed: !1, internalType: "uint256", name: "fee", type: "uint256" },
651
- { indexed: !1, internalType: "address", name: "vault", type: "address" },
652
- { indexed: !1, internalType: "string", name: "memo", type: "string" }
657
+ { indexed: false, internalType: "address", name: "from", type: "address" },
658
+ { indexed: false, internalType: "address", name: "token", type: "address" },
659
+ { indexed: false, internalType: "uint256", name: "amount", type: "uint256" },
660
+ { indexed: false, internalType: "uint256", name: "out", type: "uint256" },
661
+ { indexed: false, internalType: "uint256", name: "fee", type: "uint256" },
662
+ { indexed: false, internalType: "address", name: "vault", type: "address" },
663
+ { indexed: false, internalType: "string", name: "memo", type: "string" }
653
664
  ],
654
665
  name: "SwapIn",
655
666
  type: "event"
656
667
  },
657
668
  {
658
- anonymous: !1,
669
+ anonymous: false,
659
670
  inputs: [
660
- { indexed: !1, internalType: "address", name: "to", type: "address" },
661
- { indexed: !1, internalType: "address", name: "token", type: "address" },
662
- { indexed: !1, internalType: "uint256", name: "amount", type: "uint256" },
663
- { indexed: !1, internalType: "uint256", name: "fee", type: "uint256" }
671
+ { indexed: false, internalType: "address", name: "to", type: "address" },
672
+ { indexed: false, internalType: "address", name: "token", type: "address" },
673
+ { indexed: false, internalType: "uint256", name: "amount", type: "uint256" },
674
+ { indexed: false, internalType: "uint256", name: "fee", type: "uint256" }
664
675
  ],
665
676
  name: "SwapOut",
666
677
  type: "event"
@@ -756,7 +767,10 @@ const Ae = [
756
767
  type: "function"
757
768
  },
758
769
  { stateMutability: "payable", type: "receive" }
759
- ], xe = [
770
+ ];
771
+
772
+ // src/aggregator/contracts/pangolin.ts
773
+ var pangolin = [
760
774
  {
761
775
  inputs: [
762
776
  { internalType: "address", name: "_ttp", type: "address" },
@@ -767,19 +781,19 @@ const Ae = [
767
781
  type: "constructor"
768
782
  },
769
783
  {
770
- anonymous: !1,
784
+ anonymous: false,
771
785
  inputs: [
772
- { indexed: !1, internalType: "uint256", name: "fee", type: "uint256" },
773
- { indexed: !1, internalType: "address", name: "feeRecipient", type: "address" }
786
+ { indexed: false, internalType: "uint256", name: "fee", type: "uint256" },
787
+ { indexed: false, internalType: "address", name: "feeRecipient", type: "address" }
774
788
  ],
775
789
  name: "FeeSet",
776
790
  type: "event"
777
791
  },
778
792
  {
779
- anonymous: !1,
793
+ anonymous: false,
780
794
  inputs: [
781
- { indexed: !0, internalType: "address", name: "owner", type: "address" },
782
- { indexed: !1, internalType: "bool", name: "active", type: "bool" }
795
+ { indexed: true, internalType: "address", name: "owner", type: "address" },
796
+ { indexed: false, internalType: "bool", name: "active", type: "bool" }
783
797
  ],
784
798
  name: "OwnerSet",
785
799
  type: "event"
@@ -875,17 +889,20 @@ const Ae = [
875
889
  type: "function"
876
890
  },
877
891
  { stateMutability: "payable", type: "receive" }
878
- ], Z = [
892
+ ];
893
+
894
+ // src/aggregator/contracts/routers/kyber.ts
895
+ var kyberRouter = [
879
896
  {
880
897
  inputs: [{ internalType: "address", name: "_WETH", type: "address" }],
881
898
  stateMutability: "nonpayable",
882
899
  type: "constructor"
883
900
  },
884
901
  {
885
- anonymous: !1,
902
+ anonymous: false,
886
903
  inputs: [
887
904
  {
888
- indexed: !1,
905
+ indexed: false,
889
906
  internalType: "bytes",
890
907
  name: "clientData",
891
908
  type: "bytes"
@@ -895,10 +912,10 @@ const Ae = [
895
912
  type: "event"
896
913
  },
897
914
  {
898
- anonymous: !1,
915
+ anonymous: false,
899
916
  inputs: [
900
917
  {
901
- indexed: !1,
918
+ indexed: false,
902
919
  internalType: "string",
903
920
  name: "reason",
904
921
  type: "string"
@@ -908,22 +925,22 @@ const Ae = [
908
925
  type: "event"
909
926
  },
910
927
  {
911
- anonymous: !1,
928
+ anonymous: false,
912
929
  inputs: [
913
930
  {
914
- indexed: !1,
931
+ indexed: false,
915
932
  internalType: "address",
916
933
  name: "pair",
917
934
  type: "address"
918
935
  },
919
936
  {
920
- indexed: !1,
937
+ indexed: false,
921
938
  internalType: "uint256",
922
939
  name: "amountOut",
923
940
  type: "uint256"
924
941
  },
925
942
  {
926
- indexed: !1,
943
+ indexed: false,
927
944
  internalType: "address",
928
945
  name: "output",
929
946
  type: "address"
@@ -933,54 +950,54 @@ const Ae = [
933
950
  type: "event"
934
951
  },
935
952
  {
936
- anonymous: !1,
953
+ anonymous: false,
937
954
  inputs: [
938
955
  {
939
- indexed: !1,
956
+ indexed: false,
940
957
  internalType: "address",
941
958
  name: "token",
942
959
  type: "address"
943
960
  },
944
961
  {
945
- indexed: !1,
962
+ indexed: false,
946
963
  internalType: "uint256",
947
964
  name: "totalAmount",
948
965
  type: "uint256"
949
966
  },
950
967
  {
951
- indexed: !1,
968
+ indexed: false,
952
969
  internalType: "uint256",
953
970
  name: "totalFee",
954
971
  type: "uint256"
955
972
  },
956
973
  {
957
- indexed: !1,
974
+ indexed: false,
958
975
  internalType: "address[]",
959
976
  name: "recipients",
960
977
  type: "address[]"
961
978
  },
962
979
  {
963
- indexed: !1,
980
+ indexed: false,
964
981
  internalType: "uint256[]",
965
982
  name: "amounts",
966
983
  type: "uint256[]"
967
984
  },
968
- { indexed: !1, internalType: "bool", name: "isBps", type: "bool" }
985
+ { indexed: false, internalType: "bool", name: "isBps", type: "bool" }
969
986
  ],
970
987
  name: "Fee",
971
988
  type: "event"
972
989
  },
973
990
  {
974
- anonymous: !1,
991
+ anonymous: false,
975
992
  inputs: [
976
993
  {
977
- indexed: !0,
994
+ indexed: true,
978
995
  internalType: "address",
979
996
  name: "previousOwner",
980
997
  type: "address"
981
998
  },
982
999
  {
983
- indexed: !0,
1000
+ indexed: true,
984
1001
  internalType: "address",
985
1002
  name: "newOwner",
986
1003
  type: "address"
@@ -990,40 +1007,40 @@ const Ae = [
990
1007
  type: "event"
991
1008
  },
992
1009
  {
993
- anonymous: !1,
1010
+ anonymous: false,
994
1011
  inputs: [
995
1012
  {
996
- indexed: !1,
1013
+ indexed: false,
997
1014
  internalType: "address",
998
1015
  name: "sender",
999
1016
  type: "address"
1000
1017
  },
1001
1018
  {
1002
- indexed: !1,
1019
+ indexed: false,
1003
1020
  internalType: "contract IERC20",
1004
1021
  name: "srcToken",
1005
1022
  type: "address"
1006
1023
  },
1007
1024
  {
1008
- indexed: !1,
1025
+ indexed: false,
1009
1026
  internalType: "contract IERC20",
1010
1027
  name: "dstToken",
1011
1028
  type: "address"
1012
1029
  },
1013
1030
  {
1014
- indexed: !1,
1031
+ indexed: false,
1015
1032
  internalType: "address",
1016
1033
  name: "dstReceiver",
1017
1034
  type: "address"
1018
1035
  },
1019
1036
  {
1020
- indexed: !1,
1037
+ indexed: false,
1021
1038
  internalType: "uint256",
1022
1039
  name: "spentAmount",
1023
1040
  type: "uint256"
1024
1041
  },
1025
1042
  {
1026
- indexed: !1,
1043
+ indexed: false,
1027
1044
  internalType: "uint256",
1028
1045
  name: "returnAmount",
1029
1046
  type: "uint256"
@@ -1276,7 +1293,10 @@ const Ae = [
1276
1293
  type: "function"
1277
1294
  },
1278
1295
  { stateMutability: "payable", type: "receive" }
1279
- ], j = [
1296
+ ];
1297
+
1298
+ // src/aggregator/contracts/routers/oneinch.ts
1299
+ var oneInchRouter = [
1280
1300
  {
1281
1301
  inputs: [
1282
1302
  {
@@ -1545,16 +1565,16 @@ const Ae = [
1545
1565
  type: "error"
1546
1566
  },
1547
1567
  {
1548
- anonymous: !1,
1568
+ anonymous: false,
1549
1569
  inputs: [
1550
1570
  {
1551
- indexed: !0,
1571
+ indexed: true,
1552
1572
  internalType: "address",
1553
1573
  name: "maker",
1554
1574
  type: "address"
1555
1575
  },
1556
1576
  {
1557
- indexed: !1,
1577
+ indexed: false,
1558
1578
  internalType: "uint256",
1559
1579
  name: "newNonce",
1560
1580
  type: "uint256"
@@ -1564,22 +1584,22 @@ const Ae = [
1564
1584
  type: "event"
1565
1585
  },
1566
1586
  {
1567
- anonymous: !1,
1587
+ anonymous: false,
1568
1588
  inputs: [
1569
1589
  {
1570
- indexed: !0,
1590
+ indexed: true,
1571
1591
  internalType: "address",
1572
1592
  name: "maker",
1573
1593
  type: "address"
1574
1594
  },
1575
1595
  {
1576
- indexed: !1,
1596
+ indexed: false,
1577
1597
  internalType: "bytes32",
1578
1598
  name: "orderHash",
1579
1599
  type: "bytes32"
1580
1600
  },
1581
1601
  {
1582
- indexed: !1,
1602
+ indexed: false,
1583
1603
  internalType: "uint256",
1584
1604
  name: "remainingRaw",
1585
1605
  type: "uint256"
@@ -1589,22 +1609,22 @@ const Ae = [
1589
1609
  type: "event"
1590
1610
  },
1591
1611
  {
1592
- anonymous: !1,
1612
+ anonymous: false,
1593
1613
  inputs: [
1594
1614
  {
1595
- indexed: !0,
1615
+ indexed: true,
1596
1616
  internalType: "address",
1597
1617
  name: "maker",
1598
1618
  type: "address"
1599
1619
  },
1600
1620
  {
1601
- indexed: !1,
1621
+ indexed: false,
1602
1622
  internalType: "bytes32",
1603
1623
  name: "orderHash",
1604
1624
  type: "bytes32"
1605
1625
  },
1606
1626
  {
1607
- indexed: !1,
1627
+ indexed: false,
1608
1628
  internalType: "uint256",
1609
1629
  name: "remaining",
1610
1630
  type: "uint256"
@@ -1614,16 +1634,16 @@ const Ae = [
1614
1634
  type: "event"
1615
1635
  },
1616
1636
  {
1617
- anonymous: !1,
1637
+ anonymous: false,
1618
1638
  inputs: [
1619
1639
  {
1620
- indexed: !1,
1640
+ indexed: false,
1621
1641
  internalType: "bytes32",
1622
1642
  name: "orderHash",
1623
1643
  type: "bytes32"
1624
1644
  },
1625
1645
  {
1626
- indexed: !1,
1646
+ indexed: false,
1627
1647
  internalType: "uint256",
1628
1648
  name: "makingAmount",
1629
1649
  type: "uint256"
@@ -1633,16 +1653,16 @@ const Ae = [
1633
1653
  type: "event"
1634
1654
  },
1635
1655
  {
1636
- anonymous: !1,
1656
+ anonymous: false,
1637
1657
  inputs: [
1638
1658
  {
1639
- indexed: !0,
1659
+ indexed: true,
1640
1660
  internalType: "address",
1641
1661
  name: "previousOwner",
1642
1662
  type: "address"
1643
1663
  },
1644
1664
  {
1645
- indexed: !0,
1665
+ indexed: true,
1646
1666
  internalType: "address",
1647
1667
  name: "newOwner",
1648
1668
  type: "address"
@@ -3463,7 +3483,10 @@ const Ae = [
3463
3483
  stateMutability: "payable",
3464
3484
  type: "receive"
3465
3485
  }
3466
- ], z = [
3486
+ ];
3487
+
3488
+ // src/aggregator/contracts/routers/pancakeswap.ts
3489
+ var pancakeSwapRouter = [
3467
3490
  {
3468
3491
  inputs: [
3469
3492
  { internalType: "address", name: "_factory", type: "address" },
@@ -3802,7 +3825,10 @@ const Ae = [
3802
3825
  type: "function"
3803
3826
  },
3804
3827
  { stateMutability: "payable", type: "receive" }
3805
- ], _e = [
3828
+ ];
3829
+
3830
+ // src/aggregator/contracts/routers/pangolin.ts
3831
+ var pangolinRouter = [
3806
3832
  {
3807
3833
  inputs: [
3808
3834
  { internalType: "address", name: "_factory", type: "address" },
@@ -4141,7 +4167,10 @@ const Ae = [
4141
4167
  type: "function"
4142
4168
  },
4143
4169
  { stateMutability: "payable", type: "receive" }
4144
- ], Oe = [
4170
+ ];
4171
+
4172
+ // src/aggregator/contracts/routers/sushiswap.ts
4173
+ var sushiswapRouter = [
4145
4174
  {
4146
4175
  inputs: [
4147
4176
  { internalType: "address", name: "_factory", type: "address" },
@@ -4480,7 +4509,10 @@ const Ae = [
4480
4509
  type: "function"
4481
4510
  },
4482
4511
  { stateMutability: "payable", type: "receive" }
4483
- ], Ee = [
4512
+ ];
4513
+
4514
+ // src/aggregator/contracts/routers/traderJoe.ts
4515
+ var traderJoeRouter = [
4484
4516
  {
4485
4517
  inputs: [
4486
4518
  { internalType: "address", name: "_factory", type: "address" },
@@ -4819,7 +4851,10 @@ const Ae = [
4819
4851
  type: "function"
4820
4852
  },
4821
4853
  { stateMutability: "payable", type: "receive" }
4822
- ], Re = [
4854
+ ];
4855
+
4856
+ // src/aggregator/contracts/routers/uniswapv2.ts
4857
+ var uniswapv2Router = [
4823
4858
  {
4824
4859
  inputs: [
4825
4860
  { internalType: "address", name: "_factory", type: "address" },
@@ -5158,7 +5193,10 @@ const Ae = [
5158
5193
  type: "function"
5159
5194
  },
5160
5195
  { stateMutability: "payable", type: "receive" }
5161
- ], Ie = [
5196
+ ];
5197
+
5198
+ // src/aggregator/contracts/routers/uniswapv3.ts
5199
+ var uniswapv3Router = [
5162
5200
  {
5163
5201
  inputs: [
5164
5202
  { internalType: "address", name: "_factory", type: "address" },
@@ -5411,7 +5449,10 @@ const Ae = [
5411
5449
  type: "function"
5412
5450
  },
5413
5451
  { stateMutability: "payable", type: "receive" }
5414
- ], Fe = [
5452
+ ];
5453
+
5454
+ // src/aggregator/contracts/routers/woofi.ts
5455
+ var woofiRouter = [
5415
5456
  {
5416
5457
  inputs: [
5417
5458
  { internalType: "address", name: "_weth", type: "address" },
@@ -5421,36 +5462,36 @@ const Ae = [
5421
5462
  type: "constructor"
5422
5463
  },
5423
5464
  {
5424
- anonymous: !1,
5465
+ anonymous: false,
5425
5466
  inputs: [
5426
- { indexed: !0, internalType: "address", name: "previousOwner", type: "address" },
5427
- { indexed: !0, internalType: "address", name: "newOwner", type: "address" }
5467
+ { indexed: true, internalType: "address", name: "previousOwner", type: "address" },
5468
+ { indexed: true, internalType: "address", name: "newOwner", type: "address" }
5428
5469
  ],
5429
5470
  name: "OwnershipTransferred",
5430
5471
  type: "event"
5431
5472
  },
5432
5473
  {
5433
- anonymous: !1,
5434
- inputs: [{ indexed: !1, internalType: "address", name: "newPool", type: "address" }],
5474
+ anonymous: false,
5475
+ inputs: [{ indexed: false, internalType: "address", name: "newPool", type: "address" }],
5435
5476
  name: "WooPoolChanged",
5436
5477
  type: "event"
5437
5478
  },
5438
5479
  {
5439
- anonymous: !1,
5480
+ anonymous: false,
5440
5481
  inputs: [
5441
5482
  {
5442
- indexed: !1,
5483
+ indexed: false,
5443
5484
  internalType: "enum IWooRouterV2.SwapType",
5444
5485
  name: "swapType",
5445
5486
  type: "uint8"
5446
5487
  },
5447
- { indexed: !0, internalType: "address", name: "fromToken", type: "address" },
5448
- { indexed: !0, internalType: "address", name: "toToken", type: "address" },
5449
- { indexed: !1, internalType: "uint256", name: "fromAmount", type: "uint256" },
5450
- { indexed: !1, internalType: "uint256", name: "toAmount", type: "uint256" },
5451
- { indexed: !1, internalType: "address", name: "from", type: "address" },
5452
- { indexed: !0, internalType: "address", name: "to", type: "address" },
5453
- { indexed: !1, internalType: "address", name: "rebateTo", type: "address" }
5488
+ { indexed: true, internalType: "address", name: "fromToken", type: "address" },
5489
+ { indexed: true, internalType: "address", name: "toToken", type: "address" },
5490
+ { indexed: false, internalType: "uint256", name: "fromAmount", type: "uint256" },
5491
+ { indexed: false, internalType: "uint256", name: "toAmount", type: "uint256" },
5492
+ { indexed: false, internalType: "address", name: "from", type: "address" },
5493
+ { indexed: true, internalType: "address", name: "to", type: "address" },
5494
+ { indexed: false, internalType: "address", name: "rebateTo", type: "address" }
5454
5495
  ],
5455
5496
  name: "WooRouterSwap",
5456
5497
  type: "event"
@@ -5581,23 +5622,41 @@ const Ae = [
5581
5622
  type: "function"
5582
5623
  },
5583
5624
  { stateMutability: "payable", type: "receive" }
5584
- ], Se = {
5585
- // AVAX
5586
- ["0xE54Ca86531e17Ef3616d22Ca28b0D458b6C89106".toLowerCase()]: _e,
5587
- ["0xC22FBb3133dF781E6C25ea6acebe2D2Bb8CeA2f9".toLowerCase()]: Fe,
5588
- ["0x60aE616a2155Ee3d9A68541Ba4544862310933d4".toLowerCase()]: Ee,
5589
- ["0x1111111254fb6c44bAC0beD2854e76F90643097d".toLowerCase()]: j,
5590
- ["0x6131B5fae19EA4f9D964eAc0408E4408b66337b5".toLowerCase()]: Z,
5591
- // BSC
5592
- ["0x10ED43C718714eb63d5aA57B78B54704E256024E".toLowerCase()]: z,
5593
- // ETH
5594
- ["0x6131B5fae19EA4f9D964eAc0408E4408b66337b5".toLowerCase()]: Z,
5595
- ["0xd9e1ce17f2641f24ae83637ab66a2cca9c378b9f".toLowerCase()]: Oe,
5596
- ["0xEfF92A263d31888d860bD50809A8D171709b7b1c".toLowerCase()]: z,
5597
- ["0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D".toLowerCase()]: Re,
5598
- ["0xE592427A0AEce92De3Edee1F18E0157C05861564".toLowerCase()]: Ie,
5599
- ["0x1111111254fb6c44bac0bed2854e76f90643097d".toLowerCase()]: j
5600
- }, Ce = [
5625
+ ];
5626
+
5627
+ // src/aggregator/contracts/routers/index.ts
5628
+ var DEX_CONTRACT_ADDRESS;
5629
+ (function(DEX_CONTRACT_ADDRESS2) {
5630
+ DEX_CONTRACT_ADDRESS2["TRADERJOE"] = "0x60aE616a2155Ee3d9A68541Ba4544862310933d4";
5631
+ DEX_CONTRACT_ADDRESS2["PANGOLIN"] = "0xE54Ca86531e17Ef3616d22Ca28b0D458b6C89106";
5632
+ DEX_CONTRACT_ADDRESS2["WOOFI"] = "0xC22FBb3133dF781E6C25ea6acebe2D2Bb8CeA2f9";
5633
+ DEX_CONTRACT_ADDRESS2["ONEINCH_AVAX"] = "0x1111111254fb6c44bAC0beD2854e76F90643097d";
5634
+ DEX_CONTRACT_ADDRESS2["KYBER_AVAX"] = "0x6131B5fae19EA4f9D964eAc0408E4408b66337b5";
5635
+ DEX_CONTRACT_ADDRESS2["PANCAKESWAP_BSC"] = "0x10ED43C718714eb63d5aA57B78B54704E256024E";
5636
+ DEX_CONTRACT_ADDRESS2["ONEINCH_ETH"] = "0x1111111254fb6c44bac0bed2854e76f90643097d";
5637
+ DEX_CONTRACT_ADDRESS2["PANCAKESWAP_ETH"] = "0xEfF92A263d31888d860bD50809A8D171709b7b1c";
5638
+ DEX_CONTRACT_ADDRESS2["KYBER_ETH"] = "0x6131B5fae19EA4f9D964eAc0408E4408b66337b5";
5639
+ DEX_CONTRACT_ADDRESS2["SUSHISWAP"] = "0xd9e1ce17f2641f24ae83637ab66a2cca9c378b9f";
5640
+ DEX_CONTRACT_ADDRESS2["UNISWAP_V2"] = "0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D";
5641
+ DEX_CONTRACT_ADDRESS2["UNISWAP_V3"] = "0xE592427A0AEce92De3Edee1F18E0157C05861564";
5642
+ })(DEX_CONTRACT_ADDRESS || (DEX_CONTRACT_ADDRESS = {}));
5643
+ var lowercasedRouterAbiMapping = {
5644
+ [DEX_CONTRACT_ADDRESS.PANGOLIN.toLowerCase()]: pangolinRouter,
5645
+ [DEX_CONTRACT_ADDRESS.WOOFI.toLowerCase()]: woofiRouter,
5646
+ [DEX_CONTRACT_ADDRESS.TRADERJOE.toLowerCase()]: traderJoeRouter,
5647
+ [DEX_CONTRACT_ADDRESS.ONEINCH_AVAX.toLowerCase()]: oneInchRouter,
5648
+ [DEX_CONTRACT_ADDRESS.KYBER_AVAX.toLowerCase()]: kyberRouter,
5649
+ [DEX_CONTRACT_ADDRESS.PANCAKESWAP_BSC.toLowerCase()]: pancakeSwapRouter,
5650
+ [DEX_CONTRACT_ADDRESS.KYBER_ETH.toLowerCase()]: kyberRouter,
5651
+ [DEX_CONTRACT_ADDRESS.SUSHISWAP.toLowerCase()]: sushiswapRouter,
5652
+ [DEX_CONTRACT_ADDRESS.PANCAKESWAP_ETH.toLowerCase()]: pancakeSwapRouter,
5653
+ [DEX_CONTRACT_ADDRESS.UNISWAP_V2.toLowerCase()]: uniswapv2Router,
5654
+ [DEX_CONTRACT_ADDRESS.UNISWAP_V3.toLowerCase()]: uniswapv3Router,
5655
+ [DEX_CONTRACT_ADDRESS.ONEINCH_ETH.toLowerCase()]: oneInchRouter
5656
+ };
5657
+
5658
+ // src/aggregator/contracts/sushiswap.ts
5659
+ var sushiswap2 = [
5601
5660
  {
5602
5661
  inputs: [
5603
5662
  { internalType: "address", name: "_ttp", type: "address" },
@@ -5608,19 +5667,19 @@ const Ae = [
5608
5667
  type: "constructor"
5609
5668
  },
5610
5669
  {
5611
- anonymous: !1,
5670
+ anonymous: false,
5612
5671
  inputs: [
5613
- { indexed: !1, internalType: "uint256", name: "fee", type: "uint256" },
5614
- { indexed: !1, internalType: "address", name: "feeRecipient", type: "address" }
5672
+ { indexed: false, internalType: "uint256", name: "fee", type: "uint256" },
5673
+ { indexed: false, internalType: "address", name: "feeRecipient", type: "address" }
5615
5674
  ],
5616
5675
  name: "FeeSet",
5617
5676
  type: "event"
5618
5677
  },
5619
5678
  {
5620
- anonymous: !1,
5679
+ anonymous: false,
5621
5680
  inputs: [
5622
- { indexed: !0, internalType: "address", name: "owner", type: "address" },
5623
- { indexed: !1, internalType: "bool", name: "active", type: "bool" }
5681
+ { indexed: true, internalType: "address", name: "owner", type: "address" },
5682
+ { indexed: false, internalType: "bool", name: "active", type: "bool" }
5624
5683
  ],
5625
5684
  name: "OwnerSet",
5626
5685
  type: "event"
@@ -5716,7 +5775,10 @@ const Ae = [
5716
5775
  type: "function"
5717
5776
  },
5718
5777
  { stateMutability: "payable", type: "receive" }
5719
- ], Be = [
5778
+ ];
5779
+
5780
+ // src/aggregator/contracts/traderJoe.ts
5781
+ var traderJoe2 = [
5720
5782
  {
5721
5783
  inputs: [
5722
5784
  { internalType: "address", name: "_ttp", type: "address" },
@@ -5727,19 +5789,19 @@ const Ae = [
5727
5789
  type: "constructor"
5728
5790
  },
5729
5791
  {
5730
- anonymous: !1,
5792
+ anonymous: false,
5731
5793
  inputs: [
5732
- { indexed: !1, internalType: "uint256", name: "fee", type: "uint256" },
5733
- { indexed: !1, internalType: "address", name: "feeRecipient", type: "address" }
5794
+ { indexed: false, internalType: "uint256", name: "fee", type: "uint256" },
5795
+ { indexed: false, internalType: "address", name: "feeRecipient", type: "address" }
5734
5796
  ],
5735
5797
  name: "FeeSet",
5736
5798
  type: "event"
5737
5799
  },
5738
5800
  {
5739
- anonymous: !1,
5801
+ anonymous: false,
5740
5802
  inputs: [
5741
- { indexed: !0, internalType: "address", name: "owner", type: "address" },
5742
- { indexed: !1, internalType: "bool", name: "active", type: "bool" }
5803
+ { indexed: true, internalType: "address", name: "owner", type: "address" },
5804
+ { indexed: false, internalType: "bool", name: "active", type: "bool" }
5743
5805
  ],
5744
5806
  name: "OwnerSet",
5745
5807
  type: "event"
@@ -5835,7 +5897,10 @@ const Ae = [
5835
5897
  type: "function"
5836
5898
  },
5837
5899
  { stateMutability: "payable", type: "receive" }
5838
- ], qe = [
5900
+ ];
5901
+
5902
+ // src/aggregator/contracts/uniswapV2.ts
5903
+ var uniswapV2 = [
5839
5904
  {
5840
5905
  inputs: [
5841
5906
  { internalType: "address", name: "_ttp", type: "address" },
@@ -5846,19 +5911,19 @@ const Ae = [
5846
5911
  type: "constructor"
5847
5912
  },
5848
5913
  {
5849
- anonymous: !1,
5914
+ anonymous: false,
5850
5915
  inputs: [
5851
- { indexed: !1, internalType: "uint256", name: "fee", type: "uint256" },
5852
- { indexed: !1, internalType: "address", name: "feeRecipient", type: "address" }
5916
+ { indexed: false, internalType: "uint256", name: "fee", type: "uint256" },
5917
+ { indexed: false, internalType: "address", name: "feeRecipient", type: "address" }
5853
5918
  ],
5854
5919
  name: "FeeSet",
5855
5920
  type: "event"
5856
5921
  },
5857
5922
  {
5858
- anonymous: !1,
5923
+ anonymous: false,
5859
5924
  inputs: [
5860
- { indexed: !0, internalType: "address", name: "owner", type: "address" },
5861
- { indexed: !1, internalType: "bool", name: "active", type: "bool" }
5925
+ { indexed: true, internalType: "address", name: "owner", type: "address" },
5926
+ { indexed: false, internalType: "bool", name: "active", type: "bool" }
5862
5927
  ],
5863
5928
  name: "OwnerSet",
5864
5929
  type: "event"
@@ -5954,7 +6019,10 @@ const Ae = [
5954
6019
  type: "function"
5955
6020
  },
5956
6021
  { stateMutability: "payable", type: "receive" }
5957
- ], He = [
6022
+ ];
6023
+
6024
+ // src/aggregator/contracts/uniswapV2Leg.ts
6025
+ var uniswapV2Leg = [
5958
6026
  {
5959
6027
  inputs: [
5960
6028
  { internalType: "address", name: "_ttp", type: "address" },
@@ -5966,19 +6034,19 @@ const Ae = [
5966
6034
  type: "constructor"
5967
6035
  },
5968
6036
  {
5969
- anonymous: !1,
6037
+ anonymous: false,
5970
6038
  inputs: [
5971
- { indexed: !1, internalType: "uint256", name: "fee", type: "uint256" },
5972
- { indexed: !1, internalType: "address", name: "feeRecipient", type: "address" }
6039
+ { indexed: false, internalType: "uint256", name: "fee", type: "uint256" },
6040
+ { indexed: false, internalType: "address", name: "feeRecipient", type: "address" }
5973
6041
  ],
5974
6042
  name: "FeeSet",
5975
6043
  type: "event"
5976
6044
  },
5977
6045
  {
5978
- anonymous: !1,
6046
+ anonymous: false,
5979
6047
  inputs: [
5980
- { indexed: !0, internalType: "address", name: "owner", type: "address" },
5981
- { indexed: !1, internalType: "bool", name: "active", type: "bool" }
6048
+ { indexed: true, internalType: "address", name: "owner", type: "address" },
6049
+ { indexed: false, internalType: "bool", name: "active", type: "bool" }
5982
6050
  ],
5983
6051
  name: "OwnerSet",
5984
6052
  type: "event"
@@ -6081,7 +6149,10 @@ const Ae = [
6081
6149
  type: "function"
6082
6150
  },
6083
6151
  { stateMutability: "payable", type: "receive" }
6084
- ], Pe = [
6152
+ ];
6153
+
6154
+ // src/aggregator/contracts/uniswapV3_100.ts
6155
+ var uniswapV3_100 = [
6085
6156
  {
6086
6157
  inputs: [
6087
6158
  { internalType: "address", name: "_ttp", type: "address" },
@@ -6093,19 +6164,19 @@ const Ae = [
6093
6164
  type: "constructor"
6094
6165
  },
6095
6166
  {
6096
- anonymous: !1,
6167
+ anonymous: false,
6097
6168
  inputs: [
6098
- { indexed: !1, internalType: "uint256", name: "fee", type: "uint256" },
6099
- { indexed: !1, internalType: "address", name: "feeRecipient", type: "address" }
6169
+ { indexed: false, internalType: "uint256", name: "fee", type: "uint256" },
6170
+ { indexed: false, internalType: "address", name: "feeRecipient", type: "address" }
6100
6171
  ],
6101
6172
  name: "FeeSet",
6102
6173
  type: "event"
6103
6174
  },
6104
6175
  {
6105
- anonymous: !1,
6176
+ anonymous: false,
6106
6177
  inputs: [
6107
- { indexed: !0, internalType: "address", name: "owner", type: "address" },
6108
- { indexed: !1, internalType: "bool", name: "active", type: "bool" }
6178
+ { indexed: true, internalType: "address", name: "owner", type: "address" },
6179
+ { indexed: false, internalType: "bool", name: "active", type: "bool" }
6109
6180
  ],
6110
6181
  name: "OwnerSet",
6111
6182
  type: "event"
@@ -6208,7 +6279,10 @@ const Ae = [
6208
6279
  type: "function"
6209
6280
  },
6210
6281
  { stateMutability: "payable", type: "receive" }
6211
- ], Le = [
6282
+ ];
6283
+
6284
+ // src/aggregator/contracts/uniswapV3_500.ts
6285
+ var uniswapV3_500 = [
6212
6286
  {
6213
6287
  inputs: [
6214
6288
  { internalType: "address", name: "_ttp", type: "address" },
@@ -6220,19 +6294,19 @@ const Ae = [
6220
6294
  type: "constructor"
6221
6295
  },
6222
6296
  {
6223
- anonymous: !1,
6297
+ anonymous: false,
6224
6298
  inputs: [
6225
- { indexed: !1, internalType: "uint256", name: "fee", type: "uint256" },
6226
- { indexed: !1, internalType: "address", name: "feeRecipient", type: "address" }
6299
+ { indexed: false, internalType: "uint256", name: "fee", type: "uint256" },
6300
+ { indexed: false, internalType: "address", name: "feeRecipient", type: "address" }
6227
6301
  ],
6228
6302
  name: "FeeSet",
6229
6303
  type: "event"
6230
6304
  },
6231
6305
  {
6232
- anonymous: !1,
6306
+ anonymous: false,
6233
6307
  inputs: [
6234
- { indexed: !0, internalType: "address", name: "owner", type: "address" },
6235
- { indexed: !1, internalType: "bool", name: "active", type: "bool" }
6308
+ { indexed: true, internalType: "address", name: "owner", type: "address" },
6309
+ { indexed: false, internalType: "bool", name: "active", type: "bool" }
6236
6310
  ],
6237
6311
  name: "OwnerSet",
6238
6312
  type: "event"
@@ -6335,7 +6409,10 @@ const Ae = [
6335
6409
  type: "function"
6336
6410
  },
6337
6411
  { stateMutability: "payable", type: "receive" }
6338
- ], We = [
6412
+ ];
6413
+
6414
+ // src/aggregator/contracts/uniswapV3_3000.ts
6415
+ var uniswapV3_3000 = [
6339
6416
  {
6340
6417
  inputs: [
6341
6418
  { internalType: "address", name: "_ttp", type: "address" },
@@ -6347,19 +6424,19 @@ const Ae = [
6347
6424
  type: "constructor"
6348
6425
  },
6349
6426
  {
6350
- anonymous: !1,
6427
+ anonymous: false,
6351
6428
  inputs: [
6352
- { indexed: !1, internalType: "uint256", name: "fee", type: "uint256" },
6353
- { indexed: !1, internalType: "address", name: "feeRecipient", type: "address" }
6429
+ { indexed: false, internalType: "uint256", name: "fee", type: "uint256" },
6430
+ { indexed: false, internalType: "address", name: "feeRecipient", type: "address" }
6354
6431
  ],
6355
6432
  name: "FeeSet",
6356
6433
  type: "event"
6357
6434
  },
6358
6435
  {
6359
- anonymous: !1,
6436
+ anonymous: false,
6360
6437
  inputs: [
6361
- { indexed: !0, internalType: "address", name: "owner", type: "address" },
6362
- { indexed: !1, internalType: "bool", name: "active", type: "bool" }
6438
+ { indexed: true, internalType: "address", name: "owner", type: "address" },
6439
+ { indexed: false, internalType: "bool", name: "active", type: "bool" }
6363
6440
  ],
6364
6441
  name: "OwnerSet",
6365
6442
  type: "event"
@@ -6462,7 +6539,10 @@ const Ae = [
6462
6539
  type: "function"
6463
6540
  },
6464
6541
  { stateMutability: "payable", type: "receive" }
6465
- ], Ve = [
6542
+ ];
6543
+
6544
+ // src/aggregator/contracts/uniswapV3_10000.ts
6545
+ var uniswapV3_10000 = [
6466
6546
  {
6467
6547
  inputs: [
6468
6548
  { internalType: "address", name: "_ttp", type: "address" },
@@ -6474,19 +6554,19 @@ const Ae = [
6474
6554
  type: "constructor"
6475
6555
  },
6476
6556
  {
6477
- anonymous: !1,
6557
+ anonymous: false,
6478
6558
  inputs: [
6479
- { indexed: !1, internalType: "uint256", name: "fee", type: "uint256" },
6480
- { indexed: !1, internalType: "address", name: "feeRecipient", type: "address" }
6559
+ { indexed: false, internalType: "uint256", name: "fee", type: "uint256" },
6560
+ { indexed: false, internalType: "address", name: "feeRecipient", type: "address" }
6481
6561
  ],
6482
6562
  name: "FeeSet",
6483
6563
  type: "event"
6484
6564
  },
6485
6565
  {
6486
- anonymous: !1,
6566
+ anonymous: false,
6487
6567
  inputs: [
6488
- { indexed: !0, internalType: "address", name: "owner", type: "address" },
6489
- { indexed: !1, internalType: "bool", name: "active", type: "bool" }
6568
+ { indexed: true, internalType: "address", name: "owner", type: "address" },
6569
+ { indexed: false, internalType: "bool", name: "active", type: "bool" }
6490
6570
  ],
6491
6571
  name: "OwnerSet",
6492
6572
  type: "event"
@@ -6589,627 +6669,656 @@ const Ae = [
6589
6669
  type: "function"
6590
6670
  },
6591
6671
  { stateMutability: "payable", type: "receive" }
6592
- ], ne = {
6593
- ["0x7C38b8B2efF28511ECc14a621e263857Fb5771d3".toLowerCase()]: Ae,
6594
- ["0xB6fA6f1DcD686F4A573Fd243a6FABb4ba36Ba98c".toLowerCase()]: ke,
6595
- ["0xd31f7e39afECEc4855fecc51b693F9A0Cec49fd2".toLowerCase()]: he
6596
- }, De = {
6597
- ...Se,
6598
- ...ne,
6599
- // AVAX
6600
- ["0x942c6dA485FD6cEf255853ef83a149d43A73F18a".toLowerCase()]: xe,
6601
- ["0x5505BE604dFA8A1ad402A71f8A357fba47F9bf5a".toLowerCase()]: ve,
6602
- ["0x3b7DbdD635B99cEa39D3d95Dbd0217F05e55B212".toLowerCase()]: Be,
6603
- // BSC
6604
- ["0x30912B38618D3D37De3191A4FFE982C65a9aEC2E".toLowerCase()]: ge,
6605
- // ETH
6606
- ["0xbf365e79aA44A2164DA135100C57FDB6635ae870".toLowerCase()]: Ce,
6607
- ["0x86904Eb2b3c743400D03f929F2246EfA80B91215".toLowerCase()]: qe,
6608
- ["0x3660dE6C56cFD31998397652941ECe42118375DA".toLowerCase()]: He,
6609
- ["0xBd68cBe6c247e2c3a0e36B8F0e24964914f26Ee8".toLowerCase()]: Pe,
6610
- ["0xe4ddca21881bac219af7f217703db0475d2a9f02".toLowerCase()]: Le,
6611
- ["0x11733abf0cdb43298f7e949c930188451a9a9ef2".toLowerCase()]: We,
6612
- ["0xb33874810e5395eb49d8bd7e912631db115d5a03".toLowerCase()]: Ve
6613
- }, Xe = ({
6614
- streamSwap: r,
6615
- contractAddress: e,
6616
- recipient: t,
6617
- toChecksumAddress: n,
6672
+ ];
6673
+
6674
+ // src/aggregator/contracts/index.ts
6675
+ var AGG_CONTRACT_ADDRESS;
6676
+ (function(AGG_CONTRACT_ADDRESS2) {
6677
+ AGG_CONTRACT_ADDRESS2["PANGOLIN"] = "0x942c6dA485FD6cEf255853ef83a149d43A73F18a";
6678
+ AGG_CONTRACT_ADDRESS2["AVAX_GENERIC"] = "0x7C38b8B2efF28511ECc14a621e263857Fb5771d3";
6679
+ AGG_CONTRACT_ADDRESS2["AVAX_WOOFI"] = "0x5505BE604dFA8A1ad402A71f8A357fba47F9bf5a";
6680
+ AGG_CONTRACT_ADDRESS2["AVAX_TRADER_JOE"] = "0x3b7DbdD635B99cEa39D3d95Dbd0217F05e55B212";
6681
+ AGG_CONTRACT_ADDRESS2["BSC_GENERIC"] = "0xB6fA6f1DcD686F4A573Fd243a6FABb4ba36Ba98c";
6682
+ AGG_CONTRACT_ADDRESS2["BSC_PANCAKE_V2"] = "0x30912B38618D3D37De3191A4FFE982C65a9aEC2E";
6683
+ AGG_CONTRACT_ADDRESS2["ETH_GENERIC"] = "0xd31f7e39afECEc4855fecc51b693F9A0Cec49fd2";
6684
+ AGG_CONTRACT_ADDRESS2["UNISWAP_V2"] = "0x86904Eb2b3c743400D03f929F2246EfA80B91215";
6685
+ AGG_CONTRACT_ADDRESS2["SUSHISWAP"] = "0xbf365e79aA44A2164DA135100C57FDB6635ae870";
6686
+ AGG_CONTRACT_ADDRESS2["UNISWAP_V3_100"] = "0xBd68cBe6c247e2c3a0e36B8F0e24964914f26Ee8";
6687
+ AGG_CONTRACT_ADDRESS2["UNISWAP_V3_500"] = "0xe4ddca21881bac219af7f217703db0475d2a9f02";
6688
+ AGG_CONTRACT_ADDRESS2["UNISWAP_V3_3000"] = "0x11733abf0cdb43298f7e949c930188451a9a9ef2";
6689
+ AGG_CONTRACT_ADDRESS2["UNISWAP_V3_10000"] = "0xb33874810e5395eb49d8bd7e912631db115d5a03";
6690
+ AGG_CONTRACT_ADDRESS2["UNISWAP_V2_LEG"] = "0x3660dE6C56cFD31998397652941ECe42118375DA";
6691
+ })(AGG_CONTRACT_ADDRESS || (AGG_CONTRACT_ADDRESS = {}));
6692
+ var lowercasedGenericAbiMappings = {
6693
+ [AGG_CONTRACT_ADDRESS.AVAX_GENERIC.toLowerCase()]: avaxGeneric,
6694
+ [AGG_CONTRACT_ADDRESS.BSC_GENERIC.toLowerCase()]: bscGeneric,
6695
+ [AGG_CONTRACT_ADDRESS.ETH_GENERIC.toLowerCase()]: ethGeneric
6696
+ };
6697
+ var lowercasedContractAbiMapping = {
6698
+ ...lowercasedRouterAbiMapping,
6699
+ ...lowercasedGenericAbiMappings,
6700
+ [AGG_CONTRACT_ADDRESS.PANGOLIN.toLowerCase()]: pangolin,
6701
+ [AGG_CONTRACT_ADDRESS.AVAX_WOOFI.toLowerCase()]: avaxWoofi,
6702
+ [AGG_CONTRACT_ADDRESS.AVAX_TRADER_JOE.toLowerCase()]: traderJoe2,
6703
+ [AGG_CONTRACT_ADDRESS.BSC_PANCAKE_V2.toLowerCase()]: pancakeV2,
6704
+ [AGG_CONTRACT_ADDRESS.SUSHISWAP.toLowerCase()]: sushiswap2,
6705
+ [AGG_CONTRACT_ADDRESS.UNISWAP_V2.toLowerCase()]: uniswapV2,
6706
+ [AGG_CONTRACT_ADDRESS.UNISWAP_V2_LEG.toLowerCase()]: uniswapV2Leg,
6707
+ [AGG_CONTRACT_ADDRESS.UNISWAP_V3_100.toLowerCase()]: uniswapV3_100,
6708
+ [AGG_CONTRACT_ADDRESS.UNISWAP_V3_500.toLowerCase()]: uniswapV3_500,
6709
+ [AGG_CONTRACT_ADDRESS.UNISWAP_V3_3000.toLowerCase()]: uniswapV3_3000,
6710
+ [AGG_CONTRACT_ADDRESS.UNISWAP_V3_10000.toLowerCase()]: uniswapV3_10000
6711
+ };
6712
+
6713
+ // src/aggregator/getSwapParams.ts
6714
+ var getSwapInParams = ({
6715
+ streamSwap,
6716
+ contractAddress,
6717
+ recipient,
6718
+ toChecksumAddress,
6618
6719
  calldata: {
6619
- amount: p,
6620
- amountOutMin: i = "",
6621
- data: o = "",
6622
- deadline: c,
6623
- memo: f,
6624
- router: b,
6625
- memoStreamingSwap: w,
6626
- tcMemo: T,
6627
- tcRouter: d,
6628
- tcVault: l,
6629
- vault: A,
6630
- token: k
6720
+ amount,
6721
+ amountOutMin = "",
6722
+ data = "",
6723
+ deadline,
6724
+ memo,
6725
+ router,
6726
+ memoStreamingSwap,
6727
+ tcMemo,
6728
+ tcRouter,
6729
+ tcVault,
6730
+ vault,
6731
+ token
6631
6732
  }
6632
6733
  }) => {
6633
- const h = !!ne[e.toLowerCase()];
6634
- if (h && !b)
6734
+ const isGeneric = !!lowercasedGenericAbiMappings[contractAddress.toLowerCase()];
6735
+ if (isGeneric && !router) {
6635
6736
  throw new Error("Router is required on calldata for swapIn with GenericContract");
6636
- const g = T || f, I = r && w || g;
6637
- if (!(l || A))
6737
+ }
6738
+ const baseMemo = tcMemo || memo;
6739
+ const transactionMemo = streamSwap ? memoStreamingSwap || baseMemo : baseMemo;
6740
+ if (!(tcVault || vault))
6638
6741
  throw new Error("TC Vault is required on calldata");
6639
- if (!(d || b))
6742
+ if (!(tcRouter || router))
6640
6743
  throw new Error("TC Router is required on calldata");
6641
- if (!I)
6744
+ if (!transactionMemo)
6642
6745
  throw new Error("TC Memo is required on calldata");
6643
- if (!k)
6746
+ if (!token)
6644
6747
  throw new Error("Token is required on calldata");
6645
- const D = [
6646
- // v2 contracts don't have tcVault, tcRouter, tcMemo but vault, router, memo
6647
- n(d || b),
6648
- n(l || A),
6649
- I.replace("{recipientAddress}", t),
6650
- n(k),
6651
- p
6652
- ], X = h ? [n(b), o, c] : [i, c];
6653
- return [...D, ...X];
6654
- }, Ue = (r) => {
6655
- const e = r ? B.MayanodeStagenet : B.MayanodeMainnet;
6656
- return N.get(`${e}/mayachain/mimir`);
6657
- }, Ne = (r) => {
6658
- const e = r ? B.ThornodeStagenet : B.ThornodeMainnet;
6659
- return N.get(`${e}/thorchain/inbound_addresses`);
6660
- }, Ge = (r) => {
6661
- const e = r ? B.ThornodeStagenet : B.ThornodeMainnet;
6662
- return N.get(`${e}/thorchain/mimir`);
6663
- }, J = () => Object.values(a).reduce(
6664
- (r, e) => (r[e] = null, r),
6665
- {}
6666
- ), Qe = ({
6667
- chain: r,
6668
- address: e
6748
+ const baseParams = [
6749
+ toChecksumAddress(tcRouter || router),
6750
+ toChecksumAddress(tcVault || vault),
6751
+ transactionMemo.replace("{recipientAddress}", recipient),
6752
+ toChecksumAddress(token),
6753
+ amount
6754
+ ];
6755
+ const contractParams = isGeneric ? [toChecksumAddress(router), data, deadline] : [amountOutMin, deadline];
6756
+ return [...baseParams, ...contractParams];
6757
+ };
6758
+
6759
+ // src/client/old.ts
6760
+ var getEmptyWalletStructure = () => Object.values(Chain3).reduce((acc, chain) => {
6761
+ acc[chain] = null;
6762
+ return acc;
6763
+ }, {});
6764
+ var validateAddressType = ({
6765
+ chain,
6766
+ address
6669
6767
  }) => {
6670
- if (!e)
6671
- return !1;
6672
- switch (r) {
6673
- case a.Bitcoin:
6674
- return !e.startsWith("bc1p");
6768
+ if (!address)
6769
+ return false;
6770
+ switch (chain) {
6771
+ case Chain3.Bitcoin:
6772
+ return !address.startsWith("bc1p");
6675
6773
  default:
6676
- return !0;
6774
+ return true;
6677
6775
  }
6678
6776
  };
6679
- var S, W, q, E, H, V, P;
6680
- class Je {
6681
- constructor({ stagenet: e } = {}) {
6682
- y(this, "connectedChains", J());
6683
- y(this, "connectedWallets", J());
6684
- y(this, "stagenet", !1);
6685
- y(this, "getAddress", (e) => {
6686
- var t;
6687
- return ((t = this.connectedChains[e]) == null ? void 0 : t.address) || "";
6688
- });
6689
- y(this, "getExplorerTxUrl", (e, t) => ee({ chain: e, txHash: t }));
6690
- y(this, "getWallet", (e) => this.connectedWallets[e]);
6691
- y(this, "getExplorerAddressUrl", (e, t) => te({ chain: e, address: t }));
6692
- y(this, "getBalance", async (e, t) => {
6693
- const n = await this.getWalletByChain(e, t);
6694
- return (n == null ? void 0 : n.balance) || [];
6695
- });
6696
- y(this, "swap", async ({
6697
- streamSwap: e,
6698
- recipient: t,
6699
- route: n,
6700
- feeOptionKey: p = K.Average
6701
- // biome-ignore lint/complexity/noExcessiveCognitiveComplexity: <explanation>
6702
- }) => {
6703
- var c, f;
6777
+
6778
+ class SwapKitCore {
6779
+ connectedChains = getEmptyWalletStructure();
6780
+ connectedWallets = getEmptyWalletStructure();
6781
+ stagenet = false;
6782
+ constructor({ stagenet } = {}) {
6783
+ this.stagenet = !!stagenet;
6784
+ }
6785
+ getAddress = (chain) => this.connectedChains[chain]?.address || "";
6786
+ getExplorerTxUrl = (chain, txHash) => getExplorerTxUrl({ chain, txHash });
6787
+ getWallet = (chain) => this.connectedWallets[chain];
6788
+ getExplorerAddressUrl = (chain, address) => getExplorerAddressUrl({ chain, address });
6789
+ getBalance = async (chain, potentialScamFilter) => {
6790
+ const wallet = await this.getWalletByChain(chain, potentialScamFilter);
6791
+ return wallet?.balance || [];
6792
+ };
6793
+ swap = async ({
6794
+ streamSwap,
6795
+ recipient,
6796
+ route,
6797
+ feeOptionKey = FeeOption.Average
6798
+ }) => {
6799
+ const {
6800
+ meta: { quoteMode }
6801
+ } = route;
6802
+ const evmChain = quoteMode.startsWith("ERC20-") ? Chain3.Ethereum : quoteMode.startsWith("ARC20-") ? Chain3.Avalanche : quoteMode.startsWith("BEP20-") ? Chain3.BinanceSmartChain : undefined;
6803
+ if (!route.complete)
6804
+ throw new SwapKitError2("core_swap_route_not_complete");
6805
+ if (AGG_SWAP.includes(quoteMode) && evmChain) {
6806
+ const walletMethods = this.connectedWallets[evmChain];
6807
+ if (!walletMethods?.sendTransaction) {
6808
+ throw new SwapKitError2("core_wallet_connection_not_found");
6809
+ }
6810
+ const transaction = streamSwap ? route?.streamingSwap?.transaction : route?.transaction;
6811
+ if (!transaction)
6812
+ throw new SwapKitError2("core_swap_route_transaction_not_found");
6813
+ const { data, from, to, value } = route.transaction;
6814
+ const params = {
6815
+ data,
6816
+ from,
6817
+ to: to.toLowerCase(),
6818
+ chainId: BigInt(ChainToChainId[evmChain]),
6819
+ value: value ? BigInt(value) : 0n
6820
+ };
6821
+ return walletMethods.sendTransaction(params, feeOptionKey);
6822
+ }
6823
+ if (SWAP_OUT.includes(quoteMode)) {
6824
+ if (!route.calldata.fromAsset)
6825
+ throw new SwapKitError2("core_swap_asset_not_recognized");
6826
+ const asset = await AssetValue2.fromString(route.calldata.fromAsset);
6827
+ if (!asset)
6828
+ throw new SwapKitError2("core_swap_asset_not_recognized");
6829
+ const { address: recipient2 } = await this.#getInboundDataByChain(asset.chain);
6704
6830
  const {
6705
- meta: { quoteMode: i }
6706
- // evmTransactionDetails: contractCallParams,
6707
- } = n, o = i.startsWith("ERC20-") ? a.Ethereum : i.startsWith("ARC20-") ? a.Avalanche : i.startsWith("BEP20-") ? a.BinanceSmartChain : void 0;
6708
- if (!n.complete)
6709
- throw new s("core_swap_route_not_complete");
6710
- if (le.includes(i) && o) {
6711
- const b = this.connectedWallets[o];
6712
- if (!(b != null && b.sendTransaction))
6713
- throw new s("core_wallet_connection_not_found");
6714
- if (!(e ? (c = n == null ? void 0 : n.streamingSwap) == null ? void 0 : c.transaction : n == null ? void 0 : n.transaction))
6715
- throw new s("core_swap_route_transaction_not_found");
6716
- const { data: T, from: d, to: l, value: A } = n.transaction, k = {
6717
- data: T,
6718
- from: d,
6719
- to: l.toLowerCase(),
6720
- chainId: BigInt(me[o]),
6721
- value: A ? BigInt(A) : 0n
6722
- };
6723
- return b.sendTransaction(k, p);
6831
+ contract: router,
6832
+ calldata: { expiration, amountIn, memo, memoStreamingSwap }
6833
+ } = route;
6834
+ const assetValue = asset.add(SwapKitNumber.fromBigInt(BigInt(amountIn), asset.decimal));
6835
+ const swapMemo = streamSwap ? memoStreamingSwap || memo : memo;
6836
+ return this.deposit({
6837
+ expiration,
6838
+ assetValue,
6839
+ memo: swapMemo,
6840
+ feeOptionKey,
6841
+ router,
6842
+ recipient: recipient2
6843
+ });
6844
+ }
6845
+ if (SWAP_IN.includes(quoteMode) && evmChain) {
6846
+ const { calldata, contract: contractAddress } = route;
6847
+ if (!contractAddress)
6848
+ throw new SwapKitError2("core_swap_contract_not_found");
6849
+ const walletMethods = this.connectedWallets[evmChain];
6850
+ const from = this.getAddress(evmChain);
6851
+ if (!(walletMethods?.sendTransaction && from)) {
6852
+ throw new SwapKitError2("core_wallet_connection_not_found");
6724
6853
  }
6725
- if (Te.includes(i)) {
6726
- if (!n.calldata.fromAsset)
6727
- throw new s("core_swap_asset_not_recognized");
6728
- const b = await L.fromString(n.calldata.fromAsset);
6729
- if (!b)
6730
- throw new s("core_swap_asset_not_recognized");
6731
- const { address: w } = await M(this, S).call(this, b.chain), {
6732
- contract: T,
6733
- calldata: { expiration: d, amountIn: l, memo: A, memoStreamingSwap: k }
6734
- } = n, h = b.add(oe.fromBigInt(BigInt(l), b.decimal)), g = e && k || A;
6735
- return this.deposit({
6736
- expiration: d,
6737
- assetValue: h,
6738
- memo: g,
6739
- feeOptionKey: p,
6740
- router: T,
6741
- recipient: w
6854
+ const { getProvider, toChecksumAddress } = await import("@swapkit/toolbox-evm");
6855
+ const provider = getProvider(evmChain);
6856
+ const abi = lowercasedContractAbiMapping[contractAddress.toLowerCase()];
6857
+ if (!abi)
6858
+ throw new SwapKitError2("core_swap_contract_not_supported", {
6859
+ contractAddress
6742
6860
  });
6743
- }
6744
- if (ce.includes(i) && o) {
6745
- const { calldata: b, contract: w } = n;
6746
- if (!w)
6747
- throw new s("core_swap_contract_not_found");
6748
- const T = this.connectedWallets[o], d = this.getAddress(o);
6749
- if (!(T != null && T.sendTransaction && d))
6750
- throw new s("core_wallet_connection_not_found");
6751
- const { getProvider: l, toChecksumAddress: A } = await import("@swapkit/toolbox-evm"), k = l(o), h = De[w.toLowerCase()];
6752
- if (!h)
6753
- throw new s("core_swap_contract_not_supported", {
6754
- contractAddress: w
6755
- });
6756
- const I = await (await ((f = T.createContract) == null ? void 0 : f.call(T, w, h, k))).getFunction("swapIn").populateTransaction(
6757
- ...Xe({
6758
- streamSwap: e,
6759
- toChecksumAddress: A,
6760
- contractAddress: w,
6761
- recipient: t,
6762
- calldata: b
6763
- }),
6764
- { from: d }
6765
- );
6766
- return T.sendTransaction(I, p);
6767
- }
6768
- throw new s("core_swap_quote_mode_not_supported", { quoteMode: i });
6769
- });
6770
- y(this, "getWalletByChain", async (e, t) => {
6771
- var o, c;
6772
- const n = this.getAddress(e);
6773
- if (!n)
6774
- return null;
6775
- const p = [L.fromChainOrSignature(e)], i = (o = this.connectedChains[e]) == null ? void 0 : o.walletType;
6776
- try {
6777
- const f = await ((c = this.getWallet(e)) == null ? void 0 : c.getBalance(n, t));
6778
- return this.connectedChains[e] = {
6779
- address: n,
6780
- balance: f != null && f.length ? f : p,
6781
- walletType: i
6782
- }, { ...this.connectedChains[e] };
6783
- } catch (f) {
6784
- return console.error(f), { address: n, balance: p, walletType: i };
6785
- }
6786
- });
6787
- y(this, "approveAssetValue", (e, t) => M(this, q).call(this, { assetValue: e, type: "approve", contractAddress: t }));
6788
- y(this, "isAssetValueApproved", (e, t) => M(this, q).call(this, { assetValue: e, contractAddress: t, type: "checkOnly" }));
6789
- y(this, "validateAddress", ({ address: e, chain: t }) => {
6790
- var n, p;
6791
- return (p = (n = this.getWallet(t)) == null ? void 0 : n.validateAddress) == null ? void 0 : p.call(n, e);
6861
+ const contract = await walletMethods.createContract?.(contractAddress, abi, provider);
6862
+ const tx = await contract.getFunction("swapIn").populateTransaction(...getSwapInParams({
6863
+ streamSwap,
6864
+ toChecksumAddress,
6865
+ contractAddress,
6866
+ recipient,
6867
+ calldata
6868
+ }), { from });
6869
+ return walletMethods.sendTransaction(tx, feeOptionKey);
6870
+ }
6871
+ throw new SwapKitError2("core_swap_quote_mode_not_supported", { quoteMode });
6872
+ };
6873
+ getWalletByChain = async (chain, potentialScamFilter) => {
6874
+ const address = this.getAddress(chain);
6875
+ if (!address)
6876
+ return null;
6877
+ const defaultBalance = [AssetValue2.fromChainOrSignature(chain)];
6878
+ const walletType = this.connectedChains[chain]?.walletType;
6879
+ try {
6880
+ const balance = await this.getWallet(chain)?.getBalance(address, potentialScamFilter);
6881
+ this.connectedChains[chain] = {
6882
+ address,
6883
+ balance: balance?.length ? balance : defaultBalance,
6884
+ walletType
6885
+ };
6886
+ return { ...this.connectedChains[chain] };
6887
+ } catch (error) {
6888
+ console.error(error);
6889
+ return { address, balance: defaultBalance, walletType };
6890
+ }
6891
+ };
6892
+ approveAssetValue = (assetValue, contractAddress) => this.#approve({ assetValue, type: "approve", contractAddress });
6893
+ isAssetValueApproved = (assetValue, contractAddress) => this.#approve({ assetValue, contractAddress, type: "checkOnly" });
6894
+ validateAddress = ({ address, chain }) => this.getWallet(chain)?.validateAddress?.(address);
6895
+ transfer = async (params) => {
6896
+ const walletInstance = this.connectedWallets[params.assetValue.chain];
6897
+ if (!walletInstance)
6898
+ throw new SwapKitError2("core_wallet_connection_not_found");
6899
+ try {
6900
+ const tx = await walletInstance.transfer(this.#prepareTxParams(params));
6901
+ return tx;
6902
+ } catch (error) {
6903
+ throw new SwapKitError2("core_swap_transaction_error", error);
6904
+ }
6905
+ };
6906
+ deposit = async ({
6907
+ assetValue,
6908
+ recipient,
6909
+ router,
6910
+ ...rest
6911
+ }) => {
6912
+ const { chain, symbol, ticker } = assetValue;
6913
+ const walletInstance = this.connectedWallets[chain];
6914
+ const connectedWallet = this.connectedChains[chain];
6915
+ const isAddressValidated = await validateAddressType({
6916
+ address: connectedWallet?.address,
6917
+ chain
6792
6918
  });
6793
- y(this, "transfer", async (e) => {
6794
- const t = this.connectedWallets[e.assetValue.chain];
6795
- if (!t)
6796
- throw new s("core_wallet_connection_not_found");
6797
- try {
6798
- return await t.transfer(M(this, P).call(this, e));
6799
- } catch (n) {
6800
- throw new s("core_swap_transaction_error", n);
6801
- }
6919
+ if (!isAddressValidated) {
6920
+ throw new SwapKitError2("core_transaction_invalid_sender_address");
6921
+ }
6922
+ if (!walletInstance) {
6923
+ throw new SwapKitError2("core_wallet_connection_not_found");
6924
+ }
6925
+ const params = this.#prepareTxParams({
6926
+ assetValue,
6927
+ recipient,
6928
+ router,
6929
+ ...rest
6802
6930
  });
6803
- y(this, "deposit", async ({
6804
- assetValue: e,
6805
- recipient: t,
6806
- router: n,
6807
- ...p
6808
- }) => {
6809
- const { chain: i, symbol: o, ticker: c } = e, f = this.connectedWallets[i], b = this.connectedChains[i];
6810
- if (!await Qe({
6811
- address: b == null ? void 0 : b.address,
6812
- chain: i
6813
- }))
6814
- throw new s("core_transaction_invalid_sender_address");
6815
- if (!f)
6816
- throw new s("core_wallet_connection_not_found");
6817
- const T = M(this, P).call(this, {
6818
- assetValue: e,
6819
- recipient: t,
6820
- router: n,
6821
- ...p
6822
- });
6823
- try {
6824
- switch (i) {
6825
- case a.THORChain:
6826
- case a.Maya: {
6827
- const d = f;
6828
- return await (t === "" ? d.deposit(T) : d.transfer(T));
6829
- }
6830
- case a.Ethereum:
6831
- case a.BinanceSmartChain:
6832
- case a.Avalanche: {
6833
- const { getChecksumAddressFromAsset: d } = await import("@swapkit/toolbox-evm"), l = i === a.Avalanche ? be : i === a.BinanceSmartChain ? fe : we;
6834
- return await f.call({
6835
- abi: l,
6836
- contractAddress: n || (await M(this, S).call(this, i)).router,
6837
- funcName: "depositWithExpiry",
6838
- funcParams: [
6839
- t,
6840
- d({ chain: i, symbol: o, ticker: c }, i),
6841
- e.getBaseValue("string"),
6842
- T.memo,
6843
- p.expiration || Number.parseInt(`${((/* @__PURE__ */ new Date()).getTime() + 15 * 60 * 1e3) / 1e3}`)
6844
- ],
6845
- txOverrides: {
6846
- from: T.from,
6847
- value: e.isGasAsset ? e.getBaseValue("bigint") : void 0
6848
- }
6849
- });
6850
- }
6851
- default:
6852
- return await f.transfer(T);
6931
+ try {
6932
+ switch (chain) {
6933
+ case Chain3.THORChain:
6934
+ case Chain3.Maya: {
6935
+ const wallet = walletInstance;
6936
+ const tx = await (recipient === "" ? wallet.deposit(params) : wallet.transfer(params));
6937
+ return tx;
6853
6938
  }
6854
- } catch (d) {
6855
- const l = typeof d == "string" ? d.toLowerCase() : d == null ? void 0 : d.message.toLowerCase(), A = l == null ? void 0 : l.includes("insufficient funds"), k = l == null ? void 0 : l.includes("gas"), h = l == null ? void 0 : l.includes("server"), g = l == null ? void 0 : l.includes("user rejected"), I = A ? "core_transaction_deposit_insufficient_funds_error" : k ? "core_transaction_deposit_gas_error" : h ? "core_transaction_deposit_server_error" : g ? "core_transaction_user_rejected" : "core_transaction_deposit_error";
6856
- throw new s(I, d);
6857
- }
6858
- });
6859
- /**
6860
- * TC related Methods
6861
- */
6862
- y(this, "createLiquidity", async ({
6863
- runeAssetValue: e,
6864
- assetValue: t
6865
- }) => {
6866
- if (e.lte(0) || t.lte(0))
6867
- throw new s("core_transaction_create_liquidity_invalid_params");
6868
- let n = "", p = "";
6869
- try {
6870
- n = await M(this, E).call(this, {
6871
- assetValue: e,
6872
- memo: O(v.DEPOSIT, {
6873
- ...t,
6874
- address: this.getAddress(t.chain)
6875
- })
6876
- });
6877
- } catch (i) {
6878
- throw new s("core_transaction_create_liquidity_rune_error", i);
6879
- }
6880
- try {
6881
- p = await M(this, E).call(this, {
6882
- assetValue: t,
6883
- memo: O(v.DEPOSIT, {
6884
- ...t,
6885
- address: this.getAddress(a.THORChain)
6886
- })
6887
- });
6888
- } catch (i) {
6889
- throw new s("core_transaction_create_liquidity_asset_error", i);
6890
- }
6891
- return { runeTx: n, assetTx: p };
6892
- });
6893
- y(this, "addLiquidity", async ({
6894
- runeAssetValue: e,
6895
- assetValue: t,
6896
- runeAddr: n,
6897
- assetAddr: p,
6898
- isPendingSymmAsset: i,
6899
- mode: o = "sym"
6900
- }) => {
6901
- const { chain: c, symbol: f } = t, b = o === "sym", w = (e == null ? void 0 : e.gt(0)) && (b || o === "rune"), T = (t == null ? void 0 : t.gt(0)) && (b || o === "asset"), d = i || w, l = d ? n || this.getAddress(a.THORChain) : "", A = b || o === "asset" ? p || this.getAddress(c) : "";
6902
- if (!(w || T))
6903
- throw new s("core_transaction_add_liquidity_invalid_params");
6904
- if (d && !l)
6905
- throw new s("core_transaction_add_liquidity_no_rune_address");
6906
- let k, h;
6907
- if (w && e)
6908
- try {
6909
- k = await M(this, E).call(this, {
6910
- assetValue: e,
6911
- memo: O(v.DEPOSIT, {
6912
- chain: c,
6913
- symbol: f,
6914
- address: A
6915
- })
6939
+ case Chain3.Ethereum:
6940
+ case Chain3.BinanceSmartChain:
6941
+ case Chain3.Avalanche: {
6942
+ const { getChecksumAddressFromAsset } = await import("@swapkit/toolbox-evm");
6943
+ const abi = chain === Chain3.Avalanche ? TCAvalancheDepositABI : chain === Chain3.BinanceSmartChain ? TCBscDepositABI : TCEthereumVaultAbi;
6944
+ const wallet = walletInstance;
6945
+ const response = await wallet.call({
6946
+ abi,
6947
+ contractAddress: router || (await this.#getInboundDataByChain(chain)).router,
6948
+ funcName: "depositWithExpiry",
6949
+ funcParams: [
6950
+ recipient,
6951
+ getChecksumAddressFromAsset({ chain, symbol, ticker }, chain),
6952
+ assetValue.getBaseValue("string"),
6953
+ params.memo,
6954
+ rest.expiration || Number.parseInt(`${(new Date().getTime() + 900000) / 1000}`)
6955
+ ],
6956
+ txOverrides: {
6957
+ from: params.from,
6958
+ value: assetValue.isGasAsset ? assetValue.getBaseValue("bigint") : undefined
6959
+ }
6916
6960
  });
6917
- } catch (g) {
6918
- throw new s("core_transaction_add_liquidity_rune_error", g);
6961
+ return response;
6919
6962
  }
6920
- if (T && t)
6921
- try {
6922
- h = await M(this, E).call(this, {
6923
- assetValue: t,
6924
- memo: O(v.DEPOSIT, {
6925
- chain: c,
6926
- symbol: f,
6927
- address: l
6928
- })
6929
- });
6930
- } catch (g) {
6931
- throw new s("core_transaction_add_liquidity_asset_error", g);
6963
+ default: {
6964
+ const tx = await walletInstance.transfer(params);
6965
+ return tx;
6932
6966
  }
6933
- return { runeTx: k, assetTx: h };
6934
- });
6935
- y(this, "addLiquidityPart", ({
6936
- assetValue: e,
6937
- poolAddress: t,
6938
- address: n,
6939
- symmetric: p
6940
- }) => {
6941
- if (p && !n)
6942
- throw new s("core_transaction_add_liquidity_invalid_params");
6943
- const i = O(v.DEPOSIT, {
6944
- chain: t.split(".")[0],
6945
- symbol: t.split(".")[1],
6946
- address: p ? n : ""
6967
+ }
6968
+ } catch (error) {
6969
+ const errorMessage = typeof error === "string" ? error.toLowerCase() : error?.message?.toLowerCase();
6970
+ const isInsufficientFunds = errorMessage?.includes("insufficient funds");
6971
+ const isGas = errorMessage?.includes("gas");
6972
+ const isServer = errorMessage?.includes("server");
6973
+ const isUserRejected = errorMessage?.includes("user rejected");
6974
+ const errorKey = isInsufficientFunds ? "core_transaction_deposit_insufficient_funds_error" : isGas ? "core_transaction_deposit_gas_error" : isServer ? "core_transaction_deposit_server_error" : isUserRejected ? "core_transaction_user_rejected" : "core_transaction_deposit_error";
6975
+ throw new SwapKitError2(errorKey, error);
6976
+ }
6977
+ };
6978
+ createLiquidity = async ({
6979
+ runeAssetValue,
6980
+ assetValue
6981
+ }) => {
6982
+ if (runeAssetValue.lte(0) || assetValue.lte(0)) {
6983
+ throw new SwapKitError2("core_transaction_create_liquidity_invalid_params");
6984
+ }
6985
+ const assetAddress = this.getAddress(assetValue.chain);
6986
+ const runeAddress = this.getAddress(Chain3.THORChain);
6987
+ const runeTx = await wrapWithThrow(() => {
6988
+ return this.#depositToPool({
6989
+ assetValue: runeAssetValue,
6990
+ memo: getMemoFor(MemoType.DEPOSIT, { ...assetValue, address: assetAddress })
6947
6991
  });
6948
- return M(this, E).call(this, { assetValue: e, memo: i });
6949
- });
6950
- y(this, "withdraw", ({
6951
- memo: e,
6952
- assetValue: t,
6953
- percent: n,
6954
- from: p,
6955
- to: i
6956
- }) => {
6957
- const o = i === "rune" && p !== "rune" ? L.fromChainOrSignature(a.THORChain) : p === "sym" && i === "sym" || p === "rune" || p === "asset" ? void 0 : t, c = U(p === "asset" ? t.chain : a.THORChain), f = e || O(v.WITHDRAW, {
6958
- symbol: t.symbol,
6959
- chain: t.chain,
6960
- ticker: t.ticker,
6961
- basisPoints: Math.min(1e4, Math.round(n * 100)),
6962
- targetAssetString: o == null ? void 0 : o.toString(),
6963
- singleSide: !1
6992
+ }, "core_transaction_create_liquidity_rune_error");
6993
+ const assetTx = await wrapWithThrow(() => {
6994
+ return this.#depositToPool({
6995
+ assetValue,
6996
+ memo: getMemoFor(MemoType.DEPOSIT, { ...assetValue, address: runeAddress })
6964
6997
  });
6965
- return M(this, E).call(this, { assetValue: c, memo: f });
6966
- });
6967
- y(this, "savings", ({
6968
- assetValue: e,
6969
- memo: t,
6970
- percent: n,
6971
- type: p
6972
- }) => {
6973
- const i = p === "add" ? v.DEPOSIT : v.WITHDRAW, o = t || O(i, {
6974
- ticker: e.ticker,
6975
- symbol: e.symbol,
6976
- chain: e.chain,
6977
- singleSide: !0,
6978
- basisPoints: n ? Math.min(1e4, Math.round(n * 100)) : void 0
6979
- }), c = i === v.DEPOSIT ? e : U(e.chain);
6980
- return M(this, E).call(this, { memo: o, assetValue: c });
6981
- });
6982
- y(this, "loan", ({
6983
- assetValue: e,
6984
- memo: t,
6985
- minAmount: n,
6986
- type: p
6987
- }) => M(this, E).call(this, {
6988
- assetValue: e,
6989
- memo: t || O(p === "open" ? v.OPEN_LOAN : v.CLOSE_LOAN, {
6990
- asset: e.toString(),
6991
- minAmount: n.toString(),
6992
- address: this.getAddress(e.chain)
6993
- })
6994
- }));
6995
- y(this, "nodeAction", ({
6996
- type: e,
6997
- assetValue: t,
6998
- address: n
6999
- }) => {
7000
- const p = e === "bond" ? v.BOND : e === "unbond" ? v.UNBOND : v.LEAVE, i = O(p, {
7001
- address: n,
7002
- unbondAmount: e === "unbond" ? t.getBaseValue("number") : void 0
6998
+ }, "core_transaction_create_liquidity_asset_error");
6999
+ return { runeTx, assetTx };
7000
+ };
7001
+ addLiquidity = async ({
7002
+ runeAssetValue,
7003
+ assetValue,
7004
+ runeAddr,
7005
+ assetAddr,
7006
+ isPendingSymmAsset,
7007
+ mode = "sym"
7008
+ }) => {
7009
+ const { chain, symbol } = assetValue;
7010
+ const isSym = mode === "sym";
7011
+ const runeTransfer = runeAssetValue?.gt(0) && (isSym || mode === "rune");
7012
+ const assetTransfer = assetValue?.gt(0) && (isSym || mode === "asset");
7013
+ const includeRuneAddress = isPendingSymmAsset || runeTransfer;
7014
+ const runeAddress = includeRuneAddress ? runeAddr || this.getAddress(Chain3.THORChain) : "";
7015
+ const assetAddress = isSym || mode === "asset" ? assetAddr || this.getAddress(chain) : "";
7016
+ if (!(runeTransfer || assetTransfer)) {
7017
+ throw new SwapKitError2("core_transaction_add_liquidity_invalid_params");
7018
+ }
7019
+ if (includeRuneAddress && !runeAddress) {
7020
+ throw new SwapKitError2("core_transaction_add_liquidity_no_rune_address");
7021
+ }
7022
+ const runeTx = await wrapWithThrow(() => {
7023
+ return this.#depositToPool({
7024
+ assetValue: runeAssetValue,
7025
+ memo: getMemoFor(MemoType.DEPOSIT, { chain, symbol, address: assetAddress })
7003
7026
  });
7004
- return M(this, H).call(this, {
7005
- memo: i,
7006
- assetValue: e === "bond" ? t : U(a.THORChain)
7027
+ }, "core_transaction_add_liquidity_rune_error");
7028
+ const assetTx = assetTransfer && assetValue ? wrapWithThrow(() => {
7029
+ return this.#depositToPool({
7030
+ assetValue,
7031
+ memo: getMemoFor(MemoType.DEPOSIT, { chain, symbol, address: runeAddress })
7007
7032
  });
7033
+ }, "core_transaction_add_liquidity_asset_error") : null;
7034
+ return { runeTx, assetTx };
7035
+ };
7036
+ addLiquidityPart = ({
7037
+ assetValue,
7038
+ poolAddress,
7039
+ address,
7040
+ symmetric
7041
+ }) => {
7042
+ if (symmetric && !address) {
7043
+ throw new SwapKitError2("core_transaction_add_liquidity_invalid_params");
7044
+ }
7045
+ const memo = getMemoFor(MemoType.DEPOSIT, {
7046
+ chain: poolAddress.split(".")[0],
7047
+ symbol: poolAddress.split(".")[1],
7048
+ address: symmetric ? address : ""
7008
7049
  });
7009
- y(this, "registerThorname", ({
7010
- assetValue: e,
7011
- ...t
7012
- }) => M(this, H).call(this, {
7013
- assetValue: e,
7014
- memo: O(v.THORNAME_REGISTER, t)
7015
- }));
7016
- y(this, "registerMayaname", ({
7017
- assetValue: e,
7018
- ...t
7019
- }) => M(this, V).call(this, {
7020
- assetValue: e,
7021
- memo: O(v.THORNAME_REGISTER, t)
7022
- }));
7023
- y(this, "extend", ({ wallets: e, config: t, apis: n = {}, rpcUrls: p = {} }) => {
7024
- try {
7025
- for (const i of e)
7026
- this[i.connectMethodName] = i.connect({
7027
- addChain: M(this, W),
7028
- config: t || {},
7029
- apis: n,
7030
- rpcUrls: p
7031
- });
7032
- } catch (i) {
7033
- throw new s("core_extend_error", i);
7034
- }
7035
- });
7036
- y(this, "estimateMaxSendableAmount", async ({
7037
- chain: e,
7038
- params: t
7039
- }) => {
7040
- const n = this.getWallet(e);
7041
- switch (e) {
7042
- case a.Arbitrum:
7043
- case a.Avalanche:
7044
- case a.BinanceSmartChain:
7045
- case a.Ethereum:
7046
- case a.Optimism:
7047
- case a.Polygon: {
7048
- const { estimateMaxSendableAmount: p } = await import("@swapkit/toolbox-evm");
7049
- return p({
7050
- ...t,
7051
- toolbox: n
7052
- });
7053
- }
7054
- case a.Bitcoin:
7055
- case a.BitcoinCash:
7056
- case a.Dogecoin:
7057
- case a.Litecoin:
7058
- return n.estimateMaxSendableAmount(t);
7059
- case a.Binance:
7060
- case a.THORChain:
7061
- case a.Cosmos: {
7062
- const { estimateMaxSendableAmount: p } = await import("@swapkit/toolbox-cosmos");
7063
- return p({
7064
- ...t,
7065
- toolbox: n
7066
- });
7067
- }
7068
- default:
7069
- throw new s("core_estimated_max_spendable_chain_not_supported");
7070
- }
7071
- });
7072
- /**
7073
- * Wallet connection methods
7074
- */
7075
- // biome-ignore lint/suspicious/useAwait: Extended methods
7076
- y(this, "connectXDEFI", async (e) => {
7077
- throw new s("core_wallet_xdefi_not_installed");
7078
- });
7079
- // biome-ignore lint/suspicious/useAwait: Extended methods
7080
- y(this, "connectEVMWallet", async (e, t) => {
7081
- throw new s("core_wallet_evmwallet_not_installed");
7082
- });
7083
- // biome-ignore lint/suspicious/useAwait: Extended methods
7084
- y(this, "connectWalletconnect", async (e, t) => {
7085
- throw new s("core_wallet_walletconnect_not_installed");
7086
- });
7087
- // biome-ignore lint/suspicious/useAwait: Extended methods
7088
- y(this, "connectKeepkey", async (e, t) => {
7089
- throw new s("core_wallet_keepkey_not_installed");
7090
- });
7091
- // biome-ignore lint/suspicious/useAwait: Extended methods
7092
- y(this, "connectKeystore", async (e, t) => {
7093
- throw new s("core_wallet_keystore_not_installed");
7094
- });
7095
- // biome-ignore lint/suspicious/useAwait: Extended methods
7096
- y(this, "connectLedger", async (e, t) => {
7097
- throw new s("core_wallet_ledger_not_installed");
7098
- });
7099
- // biome-ignore lint/suspicious/useAwait: Extended methods
7100
- y(this, "connectTrezor", async (e, t) => {
7101
- throw new s("core_wallet_trezor_not_installed");
7050
+ return this.#depositToPool({ assetValue, memo });
7051
+ };
7052
+ withdraw = ({
7053
+ memo,
7054
+ assetValue,
7055
+ percent,
7056
+ from,
7057
+ to
7058
+ }) => {
7059
+ const targetAsset = to === "rune" && from !== "rune" ? AssetValue2.fromChainOrSignature(Chain3.THORChain) : from === "sym" && to === "sym" || from === "rune" || from === "asset" ? undefined : assetValue;
7060
+ const value = getMinAmountByChain(from === "asset" ? assetValue.chain : Chain3.THORChain);
7061
+ const memoString = memo || getMemoFor(MemoType.WITHDRAW, {
7062
+ symbol: assetValue.symbol,
7063
+ chain: assetValue.chain,
7064
+ ticker: assetValue.ticker,
7065
+ basisPoints: Math.min(1e4, Math.round(percent * 100)),
7066
+ targetAssetString: targetAsset?.toString(),
7067
+ singleSide: false
7102
7068
  });
7103
- // biome-ignore lint/suspicious/useAwait: Extended methods
7104
- y(this, "connectKeplr", async (e) => {
7105
- throw new s("core_wallet_keplr_not_installed");
7069
+ return this.#depositToPool({ assetValue: value, memo: memoString });
7070
+ };
7071
+ savings = ({
7072
+ assetValue,
7073
+ memo,
7074
+ percent,
7075
+ type
7076
+ }) => {
7077
+ const memoType = type === "add" ? MemoType.DEPOSIT : MemoType.WITHDRAW;
7078
+ const memoString = memo || getMemoFor(memoType, {
7079
+ ticker: assetValue.ticker,
7080
+ symbol: assetValue.symbol,
7081
+ chain: assetValue.chain,
7082
+ singleSide: true,
7083
+ basisPoints: percent ? Math.min(1e4, Math.round(percent * 100)) : undefined
7106
7084
  });
7107
- // biome-ignore lint/suspicious/useAwait: Extended methods
7108
- y(this, "connectOkx", async (e) => {
7109
- throw new s("core_wallet_okx_not_installed");
7085
+ const value = memoType === MemoType.DEPOSIT ? assetValue : getMinAmountByChain(assetValue.chain);
7086
+ return this.#depositToPool({ memo: memoString, assetValue: value });
7087
+ };
7088
+ loan = ({
7089
+ assetValue,
7090
+ memo,
7091
+ minAmount,
7092
+ type
7093
+ }) => this.#depositToPool({
7094
+ assetValue,
7095
+ memo: memo || getMemoFor(type === "open" ? MemoType.OPEN_LOAN : MemoType.CLOSE_LOAN, {
7096
+ asset: assetValue.toString(),
7097
+ minAmount: minAmount.toString(),
7098
+ address: this.getAddress(assetValue.chain)
7099
+ })
7100
+ });
7101
+ nodeAction = ({
7102
+ type,
7103
+ assetValue,
7104
+ address
7105
+ }) => {
7106
+ const memoType = type === "bond" ? MemoType.BOND : type === "unbond" ? MemoType.UNBOND : MemoType.LEAVE;
7107
+ const memo = getMemoFor(memoType, {
7108
+ address,
7109
+ unbondAmount: type === "unbond" ? assetValue.getBaseValue("number") : undefined
7110
7110
  });
7111
- y(this, "disconnectChain", (e) => {
7112
- this.connectedChains[e] = null, this.connectedWallets[e] = null;
7111
+ return this.#thorchainTransfer({
7112
+ memo,
7113
+ assetValue: type === "bond" ? assetValue : getMinAmountByChain(Chain3.THORChain)
7113
7114
  });
7114
- F(this, S, async (e) => {
7115
- switch (e) {
7116
- case a.Maya:
7117
- case a.THORChain:
7118
- return { gas_rate: "0", router: "", address: "", halted: !1, chain: e };
7119
- default: {
7120
- const n = (await Ne(this.stagenet)).find((p) => p.chain === e);
7121
- if (!n)
7122
- throw new s("core_inbound_data_not_found");
7123
- if (n != null && n.halted)
7124
- throw new s("core_chain_halted");
7125
- return n;
7126
- }
7115
+ };
7116
+ registerThorname = ({
7117
+ assetValue,
7118
+ ...param
7119
+ }) => this.#thorchainTransfer({
7120
+ assetValue,
7121
+ memo: getMemoFor(MemoType.THORNAME_REGISTER, param)
7122
+ });
7123
+ registerMayaname = ({
7124
+ assetValue,
7125
+ ...param
7126
+ }) => this.#mayachainTransfer({
7127
+ assetValue,
7128
+ memo: getMemoFor(MemoType.THORNAME_REGISTER, param)
7129
+ });
7130
+ extend = ({ wallets, config, apis = {}, rpcUrls = {} }) => {
7131
+ try {
7132
+ for (const wallet of wallets) {
7133
+ this[wallet.connectMethodName] = wallet.connect({
7134
+ addChain: this.#addConnectedChain,
7135
+ config: config || {},
7136
+ apis,
7137
+ rpcUrls
7138
+ });
7127
7139
  }
7140
+ } catch (error) {
7141
+ throw new SwapKitError2("core_extend_error", error);
7142
+ }
7143
+ };
7144
+ estimateMaxSendableAmount = async ({
7145
+ chain,
7146
+ params
7147
+ }) => {
7148
+ const walletMethods = this.getWallet(chain);
7149
+ switch (chain) {
7150
+ case Chain3.Arbitrum:
7151
+ case Chain3.Avalanche:
7152
+ case Chain3.BinanceSmartChain:
7153
+ case Chain3.Ethereum:
7154
+ case Chain3.Optimism:
7155
+ case Chain3.Polygon: {
7156
+ const { estimateMaxSendableAmount } = await import("@swapkit/toolbox-evm");
7157
+ return estimateMaxSendableAmount({
7158
+ ...params,
7159
+ toolbox: walletMethods
7160
+ });
7161
+ }
7162
+ case Chain3.Bitcoin:
7163
+ case Chain3.BitcoinCash:
7164
+ case Chain3.Dogecoin:
7165
+ case Chain3.Litecoin:
7166
+ return walletMethods.estimateMaxSendableAmount(params);
7167
+ case Chain3.Binance:
7168
+ case Chain3.THORChain:
7169
+ case Chain3.Cosmos: {
7170
+ const { estimateMaxSendableAmount } = await import("@swapkit/toolbox-cosmos");
7171
+ return estimateMaxSendableAmount({
7172
+ ...params,
7173
+ toolbox: walletMethods
7174
+ });
7175
+ }
7176
+ default:
7177
+ throw new SwapKitError2("core_estimated_max_spendable_chain_not_supported");
7178
+ }
7179
+ };
7180
+ connectXDEFI = async (_chains) => {
7181
+ throw new SwapKitError2("core_wallet_xdefi_not_installed");
7182
+ };
7183
+ connectEVMWallet = async (_chains, _wallet) => {
7184
+ throw new SwapKitError2("core_wallet_evmwallet_not_installed");
7185
+ };
7186
+ connectWalletconnect = async (_chains, _options) => {
7187
+ throw new SwapKitError2("core_wallet_walletconnect_not_installed");
7188
+ };
7189
+ connectKeepkey = async (_chains, _derivationPath) => {
7190
+ throw new SwapKitError2("core_wallet_keepkey_not_installed");
7191
+ };
7192
+ connectKeystore = async (_chains, _phrase) => {
7193
+ throw new SwapKitError2("core_wallet_keystore_not_installed");
7194
+ };
7195
+ connectLedger = async (_chains, _derivationPath) => {
7196
+ throw new SwapKitError2("core_wallet_ledger_not_installed");
7197
+ };
7198
+ connectTrezor = async (_chains, _derivationPath) => {
7199
+ throw new SwapKitError2("core_wallet_trezor_not_installed");
7200
+ };
7201
+ connectKeplr = async (_chain) => {
7202
+ throw new SwapKitError2("core_wallet_keplr_not_installed");
7203
+ };
7204
+ connectOkx = async (_chains) => {
7205
+ throw new SwapKitError2("core_wallet_okx_not_installed");
7206
+ };
7207
+ disconnectChain = (chain) => {
7208
+ this.connectedChains[chain] = null;
7209
+ this.connectedWallets[chain] = null;
7210
+ };
7211
+ #getInboundDataByChain = async (chain) => {
7212
+ switch (chain) {
7213
+ case Chain3.Maya:
7214
+ case Chain3.THORChain:
7215
+ return { gas_rate: "0", router: "", address: "", halted: false, chain };
7216
+ default: {
7217
+ const inboundData = await SwapKitApi.getInboundAddresses({ stagenet: this.stagenet });
7218
+ const chainAddressData = inboundData.find((item) => item.chain === chain);
7219
+ if (!chainAddressData)
7220
+ throw new SwapKitError2("core_inbound_data_not_found");
7221
+ if (chainAddressData?.halted)
7222
+ throw new SwapKitError2("core_chain_halted");
7223
+ return chainAddressData;
7224
+ }
7225
+ }
7226
+ };
7227
+ #addConnectedChain = ({
7228
+ chain,
7229
+ address,
7230
+ balance,
7231
+ walletType,
7232
+ ...rest
7233
+ }) => {
7234
+ this.connectedChains[chain] = {
7235
+ address: address || "",
7236
+ balance: balance || [],
7237
+ walletType: walletType || "unknown"
7238
+ };
7239
+ this.connectedWallets[chain] = { ...rest };
7240
+ };
7241
+ #approve = async ({
7242
+ assetValue,
7243
+ type = "checkOnly",
7244
+ contractAddress
7245
+ }) => {
7246
+ const { address, chain, isGasAsset, isSynthetic } = assetValue;
7247
+ const isEVMChain = [Chain3.Ethereum, Chain3.Avalanche, Chain3.BinanceSmartChain].includes(chain);
7248
+ const isNativeEVM = isEVMChain && isGasAsset;
7249
+ if (isNativeEVM || !isEVMChain || isSynthetic)
7250
+ return true;
7251
+ const walletMethods = this.connectedWallets[chain];
7252
+ const walletAction = type === "checkOnly" ? walletMethods?.isApproved : walletMethods?.approve;
7253
+ if (!walletAction) {
7254
+ throw new SwapKitError2("core_wallet_connection_not_found");
7255
+ }
7256
+ const from = this.getAddress(chain);
7257
+ if (!(address && from)) {
7258
+ throw new SwapKitError2("core_approve_asset_address_or_from_not_found");
7259
+ }
7260
+ const spenderAddress = contractAddress || (await this.#getInboundDataByChain(chain)).router;
7261
+ return walletAction({
7262
+ amount: assetValue.getBaseValue("bigint"),
7263
+ assetAddress: address,
7264
+ from,
7265
+ spenderAddress
7128
7266
  });
7129
- F(this, W, ({
7130
- chain: e,
7131
- address: t,
7132
- balance: n,
7133
- walletType: p,
7134
- ...i
7135
- }) => {
7136
- this.connectedChains[e] = {
7137
- address: t || "",
7138
- balance: n || [],
7139
- walletType: p || "unknown"
7140
- }, this.connectedWallets[e] = { ...i };
7141
- });
7142
- F(this, q, async ({
7143
- assetValue: e,
7144
- type: t = "checkOnly",
7145
- contractAddress: n
7146
- }) => {
7147
- const { address: p, chain: i, isGasAsset: o, isSynthetic: c } = e, f = [a.Ethereum, a.Avalanche, a.BinanceSmartChain].includes(i);
7148
- if (f && o || !f || c)
7149
- return !0;
7150
- const w = this.connectedWallets[i], T = t === "checkOnly" ? w == null ? void 0 : w.isApproved : w == null ? void 0 : w.approve;
7151
- if (!T)
7152
- throw new s("core_wallet_connection_not_found");
7153
- const d = this.getAddress(i);
7154
- if (!(p && d))
7155
- throw new s("core_approve_asset_address_or_from_not_found");
7156
- const l = n || (await M(this, S).call(this, i)).router;
7157
- return T({
7158
- amount: e.getBaseValue("bigint"),
7159
- assetAddress: p,
7160
- from: d,
7161
- spenderAddress: l
7162
- });
7163
- });
7164
- F(this, E, async ({
7165
- assetValue: e,
7166
- memo: t,
7167
- feeOptionKey: n = K.Fast
7168
- }) => {
7169
- const {
7170
- gas_rate: p,
7171
- router: i,
7172
- address: o
7173
- } = await M(this, S).call(this, e.chain), c = (Number.parseInt(p) || 0) * de[n];
7174
- return this.deposit({
7175
- assetValue: e,
7176
- recipient: o,
7177
- memo: t,
7178
- router: i,
7179
- feeRate: c
7180
- });
7181
- });
7182
- F(this, H, async ({
7183
- memo: e,
7184
- assetValue: t
7185
- }) => {
7186
- const n = await Ge(this.stagenet);
7187
- if (n.HALTCHAINGLOBAL >= 1 || n.HALTTHORCHAIN >= 1)
7188
- throw new s("core_chain_halted");
7189
- return this.deposit({ assetValue: t, recipient: "", memo: e });
7190
- });
7191
- F(this, V, async ({
7192
- memo: e,
7193
- assetValue: t
7194
- }) => {
7195
- const n = await Ue(this.stagenet);
7196
- if (n.HALTCHAINGLOBAL >= 1 || n.HALTTHORCHAIN >= 1)
7197
- throw new s("core_chain_halted");
7198
- return this.deposit({ assetValue: t, recipient: "", memo: e });
7267
+ };
7268
+ #depositToPool = async ({
7269
+ assetValue,
7270
+ memo,
7271
+ feeOptionKey = FeeOption.Fast
7272
+ }) => {
7273
+ const {
7274
+ gas_rate = "0",
7275
+ router,
7276
+ address: poolAddress
7277
+ } = await this.#getInboundDataByChain(assetValue.chain);
7278
+ const feeRate = Number.parseInt(gas_rate) * gasFeeMultiplier[feeOptionKey];
7279
+ return this.deposit({
7280
+ assetValue,
7281
+ recipient: poolAddress,
7282
+ memo,
7283
+ router,
7284
+ feeRate
7199
7285
  });
7200
- F(this, P, ({ assetValue: e, ...t }) => ({
7201
- ...t,
7202
- memo: t.memo || "",
7203
- from: this.getAddress(e.chain),
7204
- assetValue: e
7205
- }));
7206
- this.stagenet = !!e;
7207
- }
7286
+ };
7287
+ #thorchainTransfer = async ({
7288
+ memo,
7289
+ assetValue
7290
+ }) => {
7291
+ const mimir = await SwapKitApi.getMimirInfo({ stagenet: this.stagenet });
7292
+ if (mimir.HALTCHAINGLOBAL >= 1 || mimir.HALTTHORCHAIN >= 1) {
7293
+ throw new SwapKitError2("core_chain_halted");
7294
+ }
7295
+ return this.deposit({ assetValue, recipient: "", memo });
7296
+ };
7297
+ #mayachainTransfer = async ({
7298
+ memo,
7299
+ assetValue
7300
+ }) => {
7301
+ const mimir = await SwapKitApi.getMimirInfo({ type: "mayachain", stagenet: this.stagenet });
7302
+ if (mimir.HALTCHAINGLOBAL >= 1 || mimir.HALTTHORCHAIN >= 1) {
7303
+ throw new SwapKitError2("core_chain_halted");
7304
+ }
7305
+ return this.deposit({ assetValue, recipient: "", memo });
7306
+ };
7307
+ #prepareTxParams = ({ assetValue, ...restTxParams }) => ({
7308
+ ...restTxParams,
7309
+ memo: restTxParams.memo || "",
7310
+ from: this.getAddress(assetValue.chain),
7311
+ assetValue
7312
+ });
7208
7313
  }
7209
- S = new WeakMap(), W = new WeakMap(), q = new WeakMap(), E = new WeakMap(), H = new WeakMap(), V = new WeakMap(), P = new WeakMap();
7314
+
7315
+ // src/index.ts
7316
+ export * from "@swapkit/helpers";
7317
+ export * from "@swapkit/types";
7210
7318
  export {
7211
- Me as ApproveMode,
7212
- ze as SwapKit,
7213
- Je as SwapKitCore
7319
+ SwapKitCore,
7320
+ SwapKit,
7321
+ ApproveMode
7214
7322
  };
7215
- //# sourceMappingURL=index.es.js.map
7323
+
7324
+ //# debugId=7476CD7A24100A4B64756e2164756e21