@swapkit/helpers 3.0.0-beta.2 → 3.0.0-beta.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api/index.cjs +2 -2
- package/dist/api/index.cjs.map +6 -6
- package/dist/api/index.js +2 -2
- package/dist/api/index.js.map +6 -6
- package/dist/{chunk-6vvdbb6s.js → chunk-7shcm26h.js} +3 -3
- package/dist/{chunk-6vvdbb6s.js.map → chunk-7shcm26h.js.map} +1 -1
- package/dist/chunk-8fdws4se.js +4 -0
- package/dist/chunk-8fdws4se.js.map +10 -0
- package/dist/{chunk-dbsrwnw2.js → chunk-b8hashv0.js} +3 -3
- package/dist/{chunk-dbsrwnw2.js.map → chunk-b8hashv0.js.map} +1 -1
- package/dist/{chunk-kdcsgh3q.js → chunk-bf0ph1bk.js} +3 -3
- package/dist/{chunk-kdcsgh3q.js.map → chunk-bf0ph1bk.js.map} +1 -1
- package/dist/{chunk-mmwvr2y8.js → chunk-bh986mnf.js} +3 -3
- package/dist/{chunk-mmwvr2y8.js.map → chunk-bh986mnf.js.map} +1 -1
- package/dist/{chunk-ahpfxkx0.js → chunk-dzypg9sp.js} +3 -3
- package/dist/{chunk-ahpfxkx0.js.map → chunk-dzypg9sp.js.map} +1 -1
- package/dist/{chunk-wmxwvv8c.js → chunk-ghdhtvtt.js} +3 -3
- package/dist/{chunk-wmxwvv8c.js.map → chunk-ghdhtvtt.js.map} +1 -1
- package/dist/{chunk-fr86y3rx.js → chunk-jhmhh7ax.js} +3 -3
- package/dist/{chunk-fr86y3rx.js.map → chunk-jhmhh7ax.js.map} +1 -1
- package/dist/{chunk-ekd1k975.js → chunk-nm1av1e6.js} +3 -3
- package/dist/{chunk-ekd1k975.js.map → chunk-nm1av1e6.js.map} +1 -1
- package/dist/{chunk-wrjh857m.js → chunk-rarep8vg.js} +3 -3
- package/dist/{chunk-wrjh857m.js.map → chunk-rarep8vg.js.map} +1 -1
- package/dist/{chunk-kr69v1tm.js → chunk-rr043vwc.js} +3 -3
- package/dist/{chunk-kr69v1tm.js.map → chunk-rr043vwc.js.map} +1 -1
- package/dist/{chunk-3wnfcm30.js → chunk-s82pm7xc.js} +2 -2
- package/dist/{chunk-3wnfcm30.js.map → chunk-s82pm7xc.js.map} +1 -1
- package/dist/chunk-sb9hymk1.js +3 -0
- package/dist/chunk-sb9hymk1.js.map +10 -0
- package/dist/{chunk-tq87xn7m.js → chunk-tn4e7zrk.js} +3 -3
- package/dist/{chunk-tq87xn7m.js.map → chunk-tn4e7zrk.js.map} +1 -1
- package/dist/{chunk-z8emzpyc.js → chunk-vadspc46.js} +3 -3
- package/dist/{chunk-z8emzpyc.js.map → chunk-vadspc46.js.map} +1 -1
- package/dist/{chunk-xyczdrny.js → chunk-vgg88vt8.js} +3 -3
- package/dist/{chunk-xyczdrny.js.map → chunk-vgg88vt8.js.map} +1 -1
- package/dist/{chunk-q8xy3739.js → chunk-wssz50sc.js} +3 -3
- package/dist/{chunk-q8xy3739.js.map → chunk-wssz50sc.js.map} +1 -1
- package/dist/contracts/index.js +1 -1
- package/dist/index.cjs +3 -3
- package/dist/index.cjs.map +18 -18
- package/dist/index.js +3 -3
- package/dist/index.js.map +18 -18
- package/dist/tokens/index.js +2 -2
- package/dist/tokens/index.js.map +2 -2
- package/package.json +6 -5
- package/src/api/microgard/types.ts +0 -3
- package/src/api/midgard/endpoints.ts +1 -65
- package/src/api/midgard/types.ts +0 -49
- package/src/api/swapkitApi/endpoints.ts +16 -10
- package/src/api/swapkitApi/types.ts +1 -1
- package/src/api/thornode/endpoints.ts +22 -4
- package/src/api/thornode/types.ts +3 -2
- package/src/index.ts +1 -0
- package/src/modules/__tests__/assetValue.test.ts +66 -23
- package/src/modules/__tests__/swapKitNumber.test.ts +4 -5
- package/src/modules/assetValue.ts +84 -33
- package/src/modules/bigIntArithmetics.ts +12 -1
- package/src/modules/feeMultiplier.ts +87 -0
- package/src/modules/requestClient.ts +34 -23
- package/src/modules/swapKitConfig.ts +9 -1
- package/src/modules/swapKitError.ts +325 -105
- package/src/types/chains.ts +92 -44
- package/src/types/derivationPath.ts +2 -0
- package/src/types/quotes.ts +1 -2
- package/src/types/sdk.ts +0 -2
- package/src/types/wallet.ts +5 -0
- package/src/utils/__tests__/memo.test.ts +0 -20
- package/src/utils/asset.ts +18 -27
- package/src/utils/derivationPath.ts +6 -0
- package/src/utils/memo.ts +5 -42
- package/src/utils/others.ts +1 -2
- package/src/utils/wallets.ts +6 -3
package/src/types/chains.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { match } from "ts-pattern";
|
|
2
|
+
import { SwapKitError } from "../modules/swapKitError";
|
|
3
|
+
|
|
1
4
|
export enum Chain {
|
|
2
5
|
Arbitrum = "ARB",
|
|
3
6
|
Avalanche = "AVAX",
|
|
@@ -22,6 +25,8 @@ export enum Chain {
|
|
|
22
25
|
Ripple = "XRP",
|
|
23
26
|
THORChain = "THOR",
|
|
24
27
|
Solana = "SOL",
|
|
28
|
+
Tron = "TRX",
|
|
29
|
+
Zcash = "ZEC",
|
|
25
30
|
}
|
|
26
31
|
|
|
27
32
|
export enum StagenetChain {
|
|
@@ -62,6 +67,9 @@ export enum ChainId {
|
|
|
62
67
|
THORChain = "thorchain-1",
|
|
63
68
|
THORChainStagenet = "thorchain-stagenet-v2",
|
|
64
69
|
Solana = "solana",
|
|
70
|
+
Tron = "728126428",
|
|
71
|
+
TronHex = "0x2b6653dc",
|
|
72
|
+
Zcash = "zcash",
|
|
65
73
|
}
|
|
66
74
|
|
|
67
75
|
export const ChainIdToChain: Record<ChainId, Chain> = {
|
|
@@ -97,6 +105,9 @@ export const ChainIdToChain: Record<ChainId, Chain> = {
|
|
|
97
105
|
[ChainId.Solana]: Chain.Solana,
|
|
98
106
|
[ChainId.THORChainStagenet]: Chain.THORChain,
|
|
99
107
|
[ChainId.THORChain]: Chain.THORChain,
|
|
108
|
+
[ChainId.Tron]: Chain.Tron,
|
|
109
|
+
[ChainId.TronHex]: Chain.Tron,
|
|
110
|
+
[ChainId.Zcash]: Chain.Zcash,
|
|
100
111
|
};
|
|
101
112
|
|
|
102
113
|
type ChainNameType = keyof typeof Chain;
|
|
@@ -125,8 +136,10 @@ export const BaseDecimal: Record<Chain, number> = {
|
|
|
125
136
|
OP: 18,
|
|
126
137
|
SOL: 9,
|
|
127
138
|
THOR: 8,
|
|
139
|
+
TRX: 6,
|
|
128
140
|
XRD: 18,
|
|
129
141
|
XRP: 6,
|
|
142
|
+
ZEC: 8,
|
|
130
143
|
};
|
|
131
144
|
|
|
132
145
|
export const BlockTimes: Record<Partial<Chain>, number> = {
|
|
@@ -153,6 +166,8 @@ export const BlockTimes: Record<Partial<Chain>, number> = {
|
|
|
153
166
|
[Chain.Ripple]: 5,
|
|
154
167
|
[Chain.Solana]: 0.4,
|
|
155
168
|
[Chain.THORChain]: 6,
|
|
169
|
+
[Chain.Tron]: 3,
|
|
170
|
+
[Chain.Zcash]: 150,
|
|
156
171
|
};
|
|
157
172
|
|
|
158
173
|
export type SubstrateChain = Chain.Polkadot | Chain.Chainflip;
|
|
@@ -182,13 +197,15 @@ export type UTXOChain =
|
|
|
182
197
|
| Chain.BitcoinCash
|
|
183
198
|
| Chain.Dash
|
|
184
199
|
| Chain.Dogecoin
|
|
185
|
-
| Chain.Litecoin
|
|
200
|
+
| Chain.Litecoin
|
|
201
|
+
| Chain.Zcash;
|
|
186
202
|
export const UTXOChains = [
|
|
187
203
|
Chain.Bitcoin,
|
|
188
204
|
Chain.BitcoinCash,
|
|
189
205
|
Chain.Dash,
|
|
190
206
|
Chain.Dogecoin,
|
|
191
207
|
Chain.Litecoin,
|
|
208
|
+
Chain.Zcash,
|
|
192
209
|
] as const;
|
|
193
210
|
|
|
194
211
|
export type CosmosChain = Chain.Cosmos | Chain.THORChain | Chain.Maya | Chain.Kujira;
|
|
@@ -237,7 +254,7 @@ export const RPC_URLS: Record<Chain | StagenetChain, string> = {
|
|
|
237
254
|
[Chain.Kujira]: "https://kujira-rpc.ibs.team",
|
|
238
255
|
[Chain.Litecoin]: "https://node-router.thorswap.net/litecoin",
|
|
239
256
|
[Chain.Maya]: "https://tendermint.mayachain.info",
|
|
240
|
-
[Chain.Near]: "https://rpc.
|
|
257
|
+
[Chain.Near]: "https://rpc.mainnet.near.org",
|
|
241
258
|
[Chain.Optimism]: "https://mainnet.optimism.io",
|
|
242
259
|
[Chain.Polkadot]: "wss://rpc.polkadot.io",
|
|
243
260
|
[Chain.Polygon]: "https://polygon-rpc.com",
|
|
@@ -245,6 +262,8 @@ export const RPC_URLS: Record<Chain | StagenetChain, string> = {
|
|
|
245
262
|
[Chain.Ripple]: "wss://xrpl.ws/",
|
|
246
263
|
[Chain.Solana]: "https://solana-rpc.publicnode.com",
|
|
247
264
|
[Chain.THORChain]: "https://rpc.thorswap.net",
|
|
265
|
+
[Chain.Tron]: "https://tron-rpc.publicnode.com",
|
|
266
|
+
[Chain.Zcash]: "https://api.blockchair.com/zcash",
|
|
248
267
|
[StagenetChain.Maya]: "https://stagenet.tendermint.mayachain.info",
|
|
249
268
|
[StagenetChain.THORChain]: "https://stagenet-rpc.ninerealms.com",
|
|
250
269
|
};
|
|
@@ -279,27 +298,36 @@ export const FALLBACK_URLS: Record<Chain | StagenetChain, string[]> = {
|
|
|
279
298
|
"wss://archive-1.mainnet.chainflip.io",
|
|
280
299
|
"wss://archive-2.mainnet.chainflip.io",
|
|
281
300
|
],
|
|
282
|
-
[Chain.Cosmos]: ["https://cosmos-rpc.
|
|
301
|
+
[Chain.Cosmos]: ["https://cosmos-rpc.publicnode.com"],
|
|
283
302
|
[Chain.Dash]: ["https://dash-rpc.publicnode.com"],
|
|
284
303
|
[Chain.Dogecoin]: ["https://doge.getblock.io/mainnet", "https://dogecoin.publicnode.com"],
|
|
285
|
-
[Chain.Ethereum]: ["https://eth.llamarpc.com", "https://
|
|
304
|
+
[Chain.Ethereum]: ["https://eth.llamarpc.com", "https://cloudflare-eth.com"],
|
|
286
305
|
[Chain.Fiat]: [],
|
|
287
306
|
[Chain.Kujira]: ["https://kujira-rpc.polkachu.com", "https://rpc-kujira.synergynodes.com/"],
|
|
288
307
|
[Chain.Litecoin]: ["https://ltc.getblock.io/mainnet", "https://litecoin.publicnode.com"],
|
|
289
308
|
[Chain.Maya]: ["https://tendermint.mayachain.info", "https://maya-tendermint.publicnode.com"],
|
|
290
309
|
[StagenetChain.Maya]: [],
|
|
291
|
-
[Chain.Near]: [
|
|
310
|
+
[Chain.Near]: [
|
|
311
|
+
"https://1rpc.io/near",
|
|
312
|
+
"https://near.lava.build",
|
|
313
|
+
"https://near-mainnet.infura.io/v3/3cbfcafa5e1e48b7bb0ea41f2fbc4abf",
|
|
314
|
+
],
|
|
292
315
|
[Chain.Optimism]: ["https://optimism.llamarpc.com", "https://1rpc.io/op"],
|
|
293
316
|
[Chain.Polkadot]: [
|
|
294
317
|
"wss://polkadot-rpc.dwellir.com",
|
|
295
318
|
"wss://polkadot.api.onfinality.io/public-ws",
|
|
296
319
|
],
|
|
297
|
-
[Chain.Polygon]: ["https://polygon.llamarpc.com", "https://rpc.
|
|
320
|
+
[Chain.Polygon]: ["https://polygon.llamarpc.com", "https://polygon-bor-rpc.publicnode.com"],
|
|
298
321
|
[Chain.Radix]: ["https://mainnet.radixdlt.com", "https://radix-mainnet.rpc.grove.city/v1"],
|
|
299
322
|
[Chain.Ripple]: ["wss://s1.ripple.com/", "wss://s2.ripple.com/"],
|
|
300
323
|
[Chain.THORChain]: ["https://thornode.ninerealms.com", NODE_URLS[Chain.THORChain]],
|
|
301
324
|
[StagenetChain.THORChain]: [],
|
|
302
|
-
[Chain.Solana]: [
|
|
325
|
+
[Chain.Solana]: [
|
|
326
|
+
"https://api.mainnet-beta.solana.com",
|
|
327
|
+
"https://solana-mainnet.rpc.extrnode.com",
|
|
328
|
+
],
|
|
329
|
+
[Chain.Tron]: ["https://api.tronstack.io", "https://api.tron.network"],
|
|
330
|
+
[Chain.Zcash]: ["https://api.blockchair.com/zcash"],
|
|
303
331
|
};
|
|
304
332
|
|
|
305
333
|
export const EXPLORER_URLS: Record<Chain, string> = {
|
|
@@ -326,51 +354,71 @@ export const EXPLORER_URLS: Record<Chain, string> = {
|
|
|
326
354
|
[Chain.Ripple]: "https://livenet.xrpl.org/",
|
|
327
355
|
[Chain.THORChain]: "https://runescan.io",
|
|
328
356
|
[Chain.Solana]: "https://solscan.io",
|
|
357
|
+
[Chain.Tron]: "https://tronscan.org",
|
|
358
|
+
[Chain.Zcash]: "https://blockchair.com/zcash",
|
|
329
359
|
};
|
|
330
360
|
|
|
331
361
|
let RPCUrlsMerged = RPC_URLS;
|
|
332
362
|
|
|
333
363
|
const getRpcBody = (chain: Chain | StagenetChain) => {
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
364
|
+
return match(chain)
|
|
365
|
+
.with(
|
|
366
|
+
Chain.Arbitrum,
|
|
367
|
+
Chain.Avalanche,
|
|
368
|
+
Chain.Base,
|
|
369
|
+
Chain.BinanceSmartChain,
|
|
370
|
+
Chain.Ethereum,
|
|
371
|
+
Chain.Optimism,
|
|
372
|
+
Chain.Polygon,
|
|
373
|
+
() => ({ id: 1, jsonrpc: "2.0", method: "eth_blockNumber", params: [] }),
|
|
374
|
+
)
|
|
375
|
+
.with(
|
|
376
|
+
Chain.Bitcoin,
|
|
377
|
+
Chain.Dogecoin,
|
|
378
|
+
Chain.BitcoinCash,
|
|
379
|
+
Chain.Dash,
|
|
380
|
+
Chain.Litecoin,
|
|
381
|
+
Chain.Zcash,
|
|
382
|
+
() => ({
|
|
383
|
+
id: "test",
|
|
384
|
+
jsonrpc: "1.0",
|
|
385
|
+
method: "getblockchaininfo",
|
|
386
|
+
params: [],
|
|
387
|
+
}),
|
|
388
|
+
)
|
|
389
|
+
.with(
|
|
390
|
+
Chain.Cosmos,
|
|
391
|
+
Chain.Kujira,
|
|
392
|
+
Chain.Maya,
|
|
393
|
+
Chain.THORChain,
|
|
394
|
+
StagenetChain.Maya,
|
|
395
|
+
StagenetChain.THORChain,
|
|
396
|
+
() => ({ id: 1, jsonrpc: "2.0", method: "status", params: {} }),
|
|
397
|
+
)
|
|
398
|
+
.with(Chain.Polkadot, Chain.Chainflip, () => ({
|
|
399
|
+
id: 1,
|
|
400
|
+
jsonrpc: "2.0",
|
|
401
|
+
method: "system_health",
|
|
402
|
+
params: [],
|
|
403
|
+
}))
|
|
404
|
+
.with(Chain.Solana, () => ({ id: 1, jsonrpc: "2.0", method: "getHealth" }))
|
|
405
|
+
.with(Chain.Tron, Chain.Radix, Chain.Fiat, () => "")
|
|
406
|
+
.with(Chain.Near, () => ({
|
|
407
|
+
jsonrpc: "2.0",
|
|
408
|
+
id: "dontcare",
|
|
409
|
+
method: "status",
|
|
410
|
+
params: [],
|
|
411
|
+
}))
|
|
412
|
+
.otherwise(() => {
|
|
413
|
+
throw new SwapKitError("helpers_chain_not_supported", { chain });
|
|
414
|
+
});
|
|
365
415
|
};
|
|
366
416
|
|
|
367
417
|
function getChainStatusEndpoint(chain: Chain | StagenetChain) {
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
return "";
|
|
373
|
-
}
|
|
418
|
+
return match(chain)
|
|
419
|
+
.with(Chain.Radix, () => "/status/network-configuration")
|
|
420
|
+
.with(Chain.Tron, () => "/wallet/getnowblock")
|
|
421
|
+
.otherwise(() => "");
|
|
374
422
|
}
|
|
375
423
|
|
|
376
424
|
const testRPCConnection = async (chain: Chain | StagenetChain, url: string) => {
|
|
@@ -32,6 +32,8 @@ export const NetworkDerivationPath: Record<Chain, DerivationPathArray> = {
|
|
|
32
32
|
OP: [44, 60, 0, 0, 0],
|
|
33
33
|
SOL: [44, 501, 0, 0, 0],
|
|
34
34
|
THOR: [44, 931, 0, 0, 0],
|
|
35
|
+
TRX: [44, 195, 0, 0, 0],
|
|
36
|
+
ZEC: [44, 133, 0, 0, 0],
|
|
35
37
|
|
|
36
38
|
// Polkadot and related network derivation path is not number based
|
|
37
39
|
DOT: [0, 0, 0, 0, 0],
|
package/src/types/quotes.ts
CHANGED
|
@@ -76,7 +76,6 @@ export enum ErrorCode {
|
|
|
76
76
|
addressScreeningFailed = "addressScreeningFailed",
|
|
77
77
|
noLiquidtyProvidersFound = "noLiquidtyProvidersFound",
|
|
78
78
|
insufficientLiquidity = "insufficientLiquidity",
|
|
79
|
-
noSaversFound = "noSaversFound",
|
|
80
79
|
noInboundDataFound = "noInbounDataFound",
|
|
81
80
|
noInboundAddressesFound = "noInboundAddressesFound",
|
|
82
81
|
noInboundAddressFoundForChain = "noInboundAddressFoundForChain",
|
|
@@ -110,7 +109,6 @@ export enum ErrorCode {
|
|
|
110
109
|
thorchainPoolUnavailable = "thorchainPoolUnavailable",
|
|
111
110
|
noOhlcvDataFound = "noOhlcvDataFound",
|
|
112
111
|
noTradingPairs = "noTradingPairs",
|
|
113
|
-
noLoanPositionFound = "noLoanPositionFound",
|
|
114
112
|
noLendingAvailability = "noLendingAvailability",
|
|
115
113
|
lendingRepayTooSmall = "lendingRepayTooSmall",
|
|
116
114
|
missingState = "missingState",
|
|
@@ -160,6 +158,7 @@ export enum ProviderName {
|
|
|
160
158
|
UNISWAP_V2 = "UNISWAP_V2",
|
|
161
159
|
UNISWAP_V3 = "UNISWAP_V3",
|
|
162
160
|
KADO = "KADO",
|
|
161
|
+
NEAR = "NEAR",
|
|
163
162
|
}
|
|
164
163
|
|
|
165
164
|
export enum FeeTypeEnum {
|
package/src/types/sdk.ts
CHANGED
package/src/types/wallet.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import type { CosmosWallets, ThorchainWallets } from "@swapkit/toolboxes/cosmos";
|
|
2
2
|
import type { EVMToolboxes } from "@swapkit/toolboxes/evm";
|
|
3
|
+
import type { NearWallet } from "@swapkit/toolboxes/near";
|
|
3
4
|
import type { RadixWallet } from "@swapkit/toolboxes/radix";
|
|
4
5
|
import type { RippleWallet } from "@swapkit/toolboxes/ripple";
|
|
5
6
|
import type { SolanaWallet } from "@swapkit/toolboxes/solana";
|
|
6
7
|
import type { SubstrateToolboxes } from "@swapkit/toolboxes/substrate";
|
|
8
|
+
import type { TronWallet } from "@swapkit/toolboxes/tron";
|
|
7
9
|
import type { UTXOToolboxes } from "@swapkit/toolboxes/utxo";
|
|
8
10
|
import type { BrowserProvider } from "ethers";
|
|
9
11
|
import type { Eip1193Provider } from "ethers";
|
|
@@ -53,6 +55,7 @@ export enum WalletOption {
|
|
|
53
55
|
BRAVE = "BRAVE",
|
|
54
56
|
COINBASE_MOBILE = "COINBASE_MOBILE",
|
|
55
57
|
COINBASE_WEB = "COINBASE_WEB",
|
|
58
|
+
COSMOSTATION = "COSMOSTATION",
|
|
56
59
|
CTRL = "CTRL",
|
|
57
60
|
EIP6963 = "EIP6963",
|
|
58
61
|
EXODUS = "EXODUS",
|
|
@@ -107,6 +110,8 @@ export type FullWallet = BaseWallet<
|
|
|
107
110
|
[Chain.Radix]: RadixWallet;
|
|
108
111
|
[Chain.Ripple]: RippleWallet;
|
|
109
112
|
[Chain.Solana]: SolanaWallet;
|
|
113
|
+
[Chain.Tron]: TronWallet;
|
|
114
|
+
[Chain.Near]: NearWallet;
|
|
110
115
|
}
|
|
111
116
|
>;
|
|
112
117
|
|
|
@@ -8,29 +8,9 @@ import {
|
|
|
8
8
|
getMemoForNameRegister,
|
|
9
9
|
getMemoForRunePoolDeposit,
|
|
10
10
|
getMemoForRunePoolWithdraw,
|
|
11
|
-
getMemoForSaverDeposit,
|
|
12
|
-
getMemoForSaverWithdraw,
|
|
13
11
|
getMemoForWithdraw,
|
|
14
12
|
} from "../memo";
|
|
15
13
|
|
|
16
|
-
describe("getMemoForSaverDeposit", () => {
|
|
17
|
-
test("returns correct memo for single side", () => {
|
|
18
|
-
const result = getMemoForSaverDeposit({ chain: Chain.Ethereum, symbol: "ETH" });
|
|
19
|
-
expect(result).toBe("+:ETH/ETH");
|
|
20
|
-
});
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
describe("getMemoForSaverWithdraw", () => {
|
|
24
|
-
test("returns correct memo for single side", () => {
|
|
25
|
-
const result = getMemoForSaverWithdraw({
|
|
26
|
-
basisPoints: 5000,
|
|
27
|
-
chain: Chain.Ethereum,
|
|
28
|
-
symbol: "ETH",
|
|
29
|
-
});
|
|
30
|
-
expect(result).toBe("-:ETH/ETH:5000");
|
|
31
|
-
});
|
|
32
|
-
});
|
|
33
|
-
|
|
34
14
|
describe("getMemoForLeaveAndBond", () => {
|
|
35
15
|
test("returns correct memo for Leave", () => {
|
|
36
16
|
const result = getMemoForLeaveAndBond({ address: "ABC123", type: MemoType.LEAVE });
|
package/src/utils/asset.ts
CHANGED
|
@@ -14,6 +14,7 @@ export type ConditionalAssetValueReturn<T extends boolean> = T extends true
|
|
|
14
14
|
|
|
15
15
|
export const CommonAssetStrings = [
|
|
16
16
|
`${Chain.Maya}.MAYA`,
|
|
17
|
+
`${Chain.Maya}.CACAO`,
|
|
17
18
|
`${Chain.Ethereum}.THOR`,
|
|
18
19
|
`${Chain.Ethereum}.vTHOR`,
|
|
19
20
|
`${Chain.Kujira}.USK`,
|
|
@@ -23,7 +24,6 @@ export const CommonAssetStrings = [
|
|
|
23
24
|
|
|
24
25
|
const ethGasChains = [
|
|
25
26
|
Chain.Arbitrum,
|
|
26
|
-
Chain.Avalanche,
|
|
27
27
|
Chain.Base,
|
|
28
28
|
Chain.Ethereum,
|
|
29
29
|
Chain.Optimism,
|
|
@@ -53,7 +53,7 @@ async function getContractDecimals({ chain, to }: { chain: EVMChain; to: string
|
|
|
53
53
|
|
|
54
54
|
return Number.parseInt(BigInt(result || BaseDecimal[chain]).toString());
|
|
55
55
|
} catch (error) {
|
|
56
|
-
console.error(error);
|
|
56
|
+
console.error(`Failed to fetch contract decimals for ${to} on ${chain}:`, error);
|
|
57
57
|
return BaseDecimal[chain];
|
|
58
58
|
}
|
|
59
59
|
}
|
|
@@ -77,7 +77,7 @@ async function getRadixAssetDecimal(symbol: string) {
|
|
|
77
77
|
|
|
78
78
|
return manager.divisibility.value.divisibility;
|
|
79
79
|
} catch (error) {
|
|
80
|
-
console.error(error);
|
|
80
|
+
console.error(`Failed to fetch Radix asset decimal for ${symbol}:`, error);
|
|
81
81
|
return BaseDecimal[Chain.Radix];
|
|
82
82
|
}
|
|
83
83
|
}
|
|
@@ -113,6 +113,7 @@ export function getGasAsset({ chain }: { chain: Chain }) {
|
|
|
113
113
|
export function isGasAsset({ chain, symbol }: { chain: Chain; symbol: string }) {
|
|
114
114
|
return match(chain)
|
|
115
115
|
.with(...ethGasChains, () => symbol === "ETH")
|
|
116
|
+
.with(Chain.Avalanche, () => symbol === "AVAX")
|
|
116
117
|
.with(Chain.BinanceSmartChain, () => symbol === "BNB")
|
|
117
118
|
.with(Chain.Maya, () => symbol === "CACAO")
|
|
118
119
|
.with(Chain.Cosmos, () => symbol === "ATOM")
|
|
@@ -125,23 +126,12 @@ export const getCommonAssetInfo = (assetString: CommonAssetString) => {
|
|
|
125
126
|
const decimal = BaseDecimal[assetString as Chain];
|
|
126
127
|
|
|
127
128
|
const commonAssetInfo = match(assetString.toUpperCase())
|
|
128
|
-
.with(...ethGasChains, () => ({
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
}))
|
|
132
|
-
.with(Chain.
|
|
133
|
-
|
|
134
|
-
decimal,
|
|
135
|
-
}))
|
|
136
|
-
.with(Chain.Cosmos, () => ({ identifier: `${assetString.toUpperCase()}.ATOM`, decimal }))
|
|
137
|
-
.with(Chain.Maya, () => ({
|
|
138
|
-
identifier: `${assetString.toUpperCase()}.CACAO`,
|
|
139
|
-
decimal: 10,
|
|
140
|
-
}))
|
|
141
|
-
.with(Chain.BinanceSmartChain, () => ({
|
|
142
|
-
identifier: `${assetString.toUpperCase()}.BNB`,
|
|
143
|
-
decimal,
|
|
144
|
-
}))
|
|
129
|
+
.with(...ethGasChains, (asset) => ({ identifier: `${asset}.ETH`, decimal }))
|
|
130
|
+
.with(Chain.THORChain, (asset) => ({ identifier: `${asset}.RUNE`, decimal }))
|
|
131
|
+
.with(Chain.Cosmos, (asset) => ({ identifier: `${asset}.ATOM`, decimal }))
|
|
132
|
+
.with(Chain.Maya, (asset) => ({ identifier: `${asset}.CACAO`, decimal: 10 }))
|
|
133
|
+
.with(Chain.BinanceSmartChain, (asset) => ({ identifier: `${asset}.BNB`, decimal }))
|
|
134
|
+
.with(Chain.Avalanche, (asset) => ({ identifier: `${asset}.AVAX`, decimal }))
|
|
145
135
|
.with(
|
|
146
136
|
...UTXOChains,
|
|
147
137
|
Chain.Solana,
|
|
@@ -149,13 +139,13 @@ export const getCommonAssetInfo = (assetString: CommonAssetString) => {
|
|
|
149
139
|
Chain.Kujira,
|
|
150
140
|
Chain.Ripple,
|
|
151
141
|
Chain.Polkadot,
|
|
152
|
-
|
|
142
|
+
Chain.Tron,
|
|
143
|
+
Chain.Near,
|
|
144
|
+
(asset) => ({ identifier: `${asset}.${asset}`, decimal }),
|
|
153
145
|
)
|
|
154
|
-
.with(Chain.Radix, "XRD.XRD", () => ({
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
}))
|
|
158
|
-
.with("KUJI.USK", () => ({ identifier: assetString.toUpperCase(), decimal: 6 }))
|
|
146
|
+
.with(Chain.Radix, "XRD.XRD", () => ({ identifier: "XRD.XRD", decimal }))
|
|
147
|
+
|
|
148
|
+
.with("KUJI.USK", (asset) => ({ identifier: asset, decimal: 6 }))
|
|
159
149
|
.with("ETH.FLIP", () => ({
|
|
160
150
|
identifier: "ETH.FLIP-0x826180541412D574cf1336d22c0C0a287822678A",
|
|
161
151
|
decimal: BaseDecimal.ETH,
|
|
@@ -168,7 +158,8 @@ export const getCommonAssetInfo = (assetString: CommonAssetString) => {
|
|
|
168
158
|
identifier: "ETH.vTHOR-0x815c23eca83261b6ec689b60cc4a58b54bc24d8d",
|
|
169
159
|
decimal: BaseDecimal.ETH,
|
|
170
160
|
}))
|
|
171
|
-
.with("MAYA.
|
|
161
|
+
.with("MAYA.CACAO", (identifier) => ({ identifier, decimal: 10 }))
|
|
162
|
+
.with("MAYA.MAYA", (identifier) => ({ identifier, decimal: 4 }))
|
|
172
163
|
// Just to be sure that we are not missing any chain
|
|
173
164
|
.otherwise(() => ({ identifier: assetString, decimal }));
|
|
174
165
|
|
|
@@ -36,9 +36,15 @@ export function updateDerivationPath(
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
export function derivationPathToString([network, chainId, account, change, index]:
|
|
39
|
+
| [number, number, number, number?, number?]
|
|
39
40
|
| [number, number, number, number, number?]
|
|
40
41
|
| DerivationPathArray) {
|
|
41
42
|
const shortPath = typeof index !== "number";
|
|
43
|
+
const accountPath = typeof change !== "number";
|
|
44
|
+
|
|
45
|
+
if (accountPath) {
|
|
46
|
+
return `m/${network}'/${chainId}'/${account}'`;
|
|
47
|
+
}
|
|
42
48
|
|
|
43
49
|
return `m/${network}'/${chainId}'/${account}'/${change}${shortPath ? "" : `/${index}`}`;
|
|
44
50
|
}
|
package/src/utils/memo.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { match } from "ts-pattern";
|
|
1
2
|
import { Chain } from "../types/chains";
|
|
2
3
|
import { MemoType } from "../types/sdk";
|
|
3
4
|
|
|
@@ -16,14 +17,6 @@ export function getMemoForRunePoolDeposit(affiliate?: WithAffiliate<{}>) {
|
|
|
16
17
|
return addAffiliate(MemoType.RUNEPOOL_DEPOSIT, affiliate);
|
|
17
18
|
}
|
|
18
19
|
|
|
19
|
-
export function getMemoForSaverDeposit({
|
|
20
|
-
chain,
|
|
21
|
-
symbol,
|
|
22
|
-
...affiliate
|
|
23
|
-
}: WithAffiliate<{ chain: Chain; symbol: string }>) {
|
|
24
|
-
return addAffiliate(`${MemoType.DEPOSIT}:${chain}/${symbol}`, affiliate);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
20
|
export function getMemoForDeposit({
|
|
28
21
|
chain,
|
|
29
22
|
symbol,
|
|
@@ -43,14 +36,6 @@ export function getMemoForDeposit({
|
|
|
43
36
|
/**
|
|
44
37
|
* Withdraw
|
|
45
38
|
*/
|
|
46
|
-
export function getMemoForSaverWithdraw({
|
|
47
|
-
chain,
|
|
48
|
-
symbol,
|
|
49
|
-
basisPoints,
|
|
50
|
-
}: { chain: Chain; symbol: string; basisPoints: number }) {
|
|
51
|
-
return `${MemoType.WITHDRAW}:${chain}/${symbol}:${basisPoints}`;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
39
|
export function getMemoForWithdraw({
|
|
55
40
|
chain,
|
|
56
41
|
symbol,
|
|
@@ -92,21 +77,6 @@ export function getMemoForNamePreferredAssetRegister({
|
|
|
92
77
|
return `${MemoType.NAME_REGISTER}:${name}:${chain}:${payout}:${owner}:${asset}`;
|
|
93
78
|
}
|
|
94
79
|
|
|
95
|
-
export function getMemoForLoan(
|
|
96
|
-
memoType: MemoType.OPEN_LOAN | MemoType.CLOSE_LOAN,
|
|
97
|
-
{
|
|
98
|
-
asset,
|
|
99
|
-
address,
|
|
100
|
-
minAmount,
|
|
101
|
-
...affiliate
|
|
102
|
-
}: WithAffiliate<{ address: string; asset: string; minAmount?: string }>,
|
|
103
|
-
) {
|
|
104
|
-
const baseMemo = `${memoType}:${asset}:${address}`;
|
|
105
|
-
const minAmountPart = minAmount ? `:${minAmount}` : "";
|
|
106
|
-
|
|
107
|
-
return addAffiliate(`${baseMemo}${minAmountPart}`, affiliate);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
80
|
/**
|
|
111
81
|
* Internal helpers
|
|
112
82
|
*/
|
|
@@ -126,17 +96,10 @@ function getPoolIdentifier({
|
|
|
126
96
|
chain: Chain;
|
|
127
97
|
symbol: string;
|
|
128
98
|
}) {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
return chain.slice(0, 1).toLowerCase();
|
|
134
|
-
case Chain.BitcoinCash:
|
|
135
|
-
return "c";
|
|
136
|
-
|
|
137
|
-
default:
|
|
138
|
-
return `${chain}.${symbol}`;
|
|
139
|
-
}
|
|
99
|
+
return match(chain)
|
|
100
|
+
.with(Chain.Bitcoin, Chain.Dogecoin, Chain.Litecoin, () => chain.slice(0, 1).toLowerCase())
|
|
101
|
+
.with(Chain.BitcoinCash, () => "c")
|
|
102
|
+
.otherwise(() => `${chain}.${symbol}`);
|
|
140
103
|
}
|
|
141
104
|
|
|
142
105
|
type WithAffiliate<T extends {}> = T & {
|
package/src/utils/others.ts
CHANGED
|
@@ -34,7 +34,7 @@ export function wrapWithThrow<T>(fn: () => T, errorKey?: ErrorKeys) {
|
|
|
34
34
|
throw new SwapKitError(errorKey, error);
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
return
|
|
37
|
+
return;
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
|
|
@@ -62,7 +62,6 @@ export function warnOnce(condition: boolean, warning: string) {
|
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
warnings.add(warning);
|
|
65
|
-
console.warn(warning);
|
|
66
65
|
}
|
|
67
66
|
}
|
|
68
67
|
|
package/src/utils/wallets.ts
CHANGED
|
@@ -70,7 +70,10 @@ export async function switchEVMWalletNetwork(
|
|
|
70
70
|
});
|
|
71
71
|
} catch (_error) {
|
|
72
72
|
if (!networkParams) {
|
|
73
|
-
throw new
|
|
73
|
+
throw new SwapKitError("helpers_failed_to_switch_network", {
|
|
74
|
+
error: _error,
|
|
75
|
+
reason: "networkParams not provided",
|
|
76
|
+
});
|
|
74
77
|
}
|
|
75
78
|
await addEVMWalletNetwork(provider, networkParams);
|
|
76
79
|
}
|
|
@@ -107,7 +110,7 @@ export function wrapMethodWithNetworkSwitch<T extends (...args: any[]) => any>(
|
|
|
107
110
|
provider: BrowserProvider,
|
|
108
111
|
chain: Chain,
|
|
109
112
|
) {
|
|
110
|
-
(async (...args: any[]) => {
|
|
113
|
+
return (async (...args: any[]) => {
|
|
111
114
|
try {
|
|
112
115
|
await switchEVMWalletNetwork(provider, chain);
|
|
113
116
|
} catch (error) {
|
|
@@ -247,7 +250,7 @@ export function createWallet<
|
|
|
247
250
|
};
|
|
248
251
|
}
|
|
249
252
|
|
|
250
|
-
function providerRequest({
|
|
253
|
+
export function providerRequest({
|
|
251
254
|
provider,
|
|
252
255
|
params,
|
|
253
256
|
method,
|