@swapkit/helpers 3.0.0-beta.8 → 4.0.0-beta.24

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.
Files changed (71) hide show
  1. package/dist/api/index.cjs +2 -2
  2. package/dist/api/index.cjs.map +5 -5
  3. package/dist/api/index.js +2 -2
  4. package/dist/api/index.js.map +5 -5
  5. package/dist/{chunk-6vvdbb6s.js → chunk-7shcm26h.js} +3 -3
  6. package/dist/{chunk-6vvdbb6s.js.map → chunk-7shcm26h.js.map} +1 -1
  7. package/dist/chunk-8fdws4se.js +4 -0
  8. package/dist/chunk-8fdws4se.js.map +10 -0
  9. package/dist/{chunk-dbsrwnw2.js → chunk-b8hashv0.js} +3 -3
  10. package/dist/{chunk-dbsrwnw2.js.map → chunk-b8hashv0.js.map} +1 -1
  11. package/dist/{chunk-kdcsgh3q.js → chunk-bf0ph1bk.js} +3 -3
  12. package/dist/{chunk-kdcsgh3q.js.map → chunk-bf0ph1bk.js.map} +1 -1
  13. package/dist/{chunk-mmwvr2y8.js → chunk-bh986mnf.js} +3 -3
  14. package/dist/{chunk-mmwvr2y8.js.map → chunk-bh986mnf.js.map} +1 -1
  15. package/dist/{chunk-ahpfxkx0.js → chunk-dzypg9sp.js} +3 -3
  16. package/dist/{chunk-ahpfxkx0.js.map → chunk-dzypg9sp.js.map} +1 -1
  17. package/dist/{chunk-wmxwvv8c.js → chunk-ghdhtvtt.js} +3 -3
  18. package/dist/{chunk-wmxwvv8c.js.map → chunk-ghdhtvtt.js.map} +1 -1
  19. package/dist/{chunk-fr86y3rx.js → chunk-jhmhh7ax.js} +3 -3
  20. package/dist/{chunk-fr86y3rx.js.map → chunk-jhmhh7ax.js.map} +1 -1
  21. package/dist/{chunk-ekd1k975.js → chunk-nm1av1e6.js} +3 -3
  22. package/dist/{chunk-ekd1k975.js.map → chunk-nm1av1e6.js.map} +1 -1
  23. package/dist/{chunk-wrjh857m.js → chunk-rarep8vg.js} +3 -3
  24. package/dist/{chunk-wrjh857m.js.map → chunk-rarep8vg.js.map} +1 -1
  25. package/dist/{chunk-kr69v1tm.js → chunk-rr043vwc.js} +3 -3
  26. package/dist/{chunk-kr69v1tm.js.map → chunk-rr043vwc.js.map} +1 -1
  27. package/dist/{chunk-3wnfcm30.js → chunk-s82pm7xc.js} +2 -2
  28. package/dist/{chunk-3wnfcm30.js.map → chunk-s82pm7xc.js.map} +1 -1
  29. package/dist/chunk-sb9hymk1.js +3 -0
  30. package/dist/chunk-sb9hymk1.js.map +10 -0
  31. package/dist/{chunk-tq87xn7m.js → chunk-tn4e7zrk.js} +3 -3
  32. package/dist/{chunk-tq87xn7m.js.map → chunk-tn4e7zrk.js.map} +1 -1
  33. package/dist/{chunk-z8emzpyc.js → chunk-vadspc46.js} +3 -3
  34. package/dist/{chunk-z8emzpyc.js.map → chunk-vadspc46.js.map} +1 -1
  35. package/dist/{chunk-xyczdrny.js → chunk-vgg88vt8.js} +3 -3
  36. package/dist/{chunk-xyczdrny.js.map → chunk-vgg88vt8.js.map} +1 -1
  37. package/dist/{chunk-q8xy3739.js → chunk-wssz50sc.js} +3 -3
  38. package/dist/{chunk-q8xy3739.js.map → chunk-wssz50sc.js.map} +1 -1
  39. package/dist/contracts/index.js +1 -1
  40. package/dist/index.cjs +3 -3
  41. package/dist/index.cjs.map +18 -18
  42. package/dist/index.js +3 -3
  43. package/dist/index.js.map +18 -18
  44. package/dist/tokens/index.js +2 -2
  45. package/dist/tokens/index.js.map +2 -2
  46. package/package.json +10 -6
  47. package/src/api/microgard/types.ts +0 -3
  48. package/src/api/midgard/endpoints.ts +1 -65
  49. package/src/api/midgard/types.ts +0 -49
  50. package/src/api/swapkitApi/endpoints.ts +16 -10
  51. package/src/api/swapkitApi/types.ts +1 -1
  52. package/src/index.ts +1 -0
  53. package/src/modules/__tests__/assetValue.test.ts +43 -0
  54. package/src/modules/__tests__/swapKitNumber.test.ts +4 -5
  55. package/src/modules/assetValue.ts +26 -35
  56. package/src/modules/bigIntArithmetics.ts +12 -1
  57. package/src/modules/feeMultiplier.ts +87 -0
  58. package/src/modules/requestClient.ts +43 -23
  59. package/src/modules/swapKitConfig.ts +9 -1
  60. package/src/modules/swapKitError.ts +325 -105
  61. package/src/types/chains.ts +98 -44
  62. package/src/types/derivationPath.ts +2 -0
  63. package/src/types/quotes.ts +1 -2
  64. package/src/types/sdk.ts +0 -2
  65. package/src/types/wallet.ts +5 -0
  66. package/src/utils/__tests__/memo.test.ts +0 -20
  67. package/src/utils/asset.ts +17 -30
  68. package/src/utils/derivationPath.ts +6 -0
  69. package/src/utils/memo.ts +5 -42
  70. package/src/utils/others.ts +1 -2
  71. package/src/utils/wallets.ts +6 -3
@@ -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.ankr.com/near",
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.quickapi.com", "https://cosmos-rpc.publicnode.com"],
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://rpc.ankr.com/eth"],
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]: ["https://1rpc.io/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.ankr.com/polygon"],
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]: ["https://api.mainnet-beta.solana.com", "https://rpc.ankr.com/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,77 @@ 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
- switch (chain) {
335
- case Chain.Arbitrum:
336
- case Chain.Avalanche:
337
- case Chain.Base:
338
- case Chain.BinanceSmartChain:
339
- case Chain.Ethereum:
340
- case Chain.Optimism:
341
- case Chain.Polygon:
342
- return { id: 1, jsonrpc: "2.0", method: "eth_blockNumber", params: [] };
343
- case Chain.Bitcoin:
344
- case Chain.Dogecoin:
345
- case Chain.BitcoinCash:
346
- case Chain.Dash:
347
- case Chain.Litecoin:
348
- return { id: "test", jsonrpc: "1.0", method: "getblockchaininfo", params: [] };
349
- case Chain.Cosmos:
350
- case Chain.Kujira:
351
- case Chain.Maya:
352
- case Chain.THORChain:
353
- case StagenetChain.Maya:
354
- case StagenetChain.THORChain:
355
- return { id: 1, jsonrpc: "2.0", method: "status", params: {} };
356
- case Chain.Polkadot:
357
- return { id: 1, jsonrpc: "2.0", method: "system_health", params: [] };
358
- case Chain.Solana:
359
- return { id: 1, jsonrpc: "2.0", method: "getHealth" };
360
- case Chain.Radix:
361
- return "";
362
- default:
363
- throw new Error(`Unsupported chain: ${chain}`);
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
+ .with(Chain.Ripple, () => ({
413
+ method: "ping",
414
+ params: [{}],
415
+ id: 1,
416
+ jsonrpc: "2.0",
417
+ }))
418
+ .otherwise(() => {
419
+ throw new SwapKitError("helpers_chain_not_supported", { chain });
420
+ });
365
421
  };
366
422
 
367
423
  function getChainStatusEndpoint(chain: Chain | StagenetChain) {
368
- switch (chain) {
369
- case Chain.Radix:
370
- return "/status/network-configuration";
371
- default:
372
- return "";
373
- }
424
+ return match(chain)
425
+ .with(Chain.Radix, () => "/status/network-configuration")
426
+ .with(Chain.Tron, () => "/wallet/getnowblock")
427
+ .otherwise(() => "");
374
428
  }
375
429
 
376
430
  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],
@@ -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
@@ -34,8 +34,6 @@ export enum MemoType {
34
34
  LEAVE = "LEAVE",
35
35
  UNBOND = "UNBOND",
36
36
  WITHDRAW = "-",
37
- OPEN_LOAN = "$+",
38
- CLOSE_LOAN = "$-",
39
37
  RUNEPOOL_DEPOSIT = "POOL+",
40
38
  RUNEPOOL_WITHDRAW = "POOL-",
41
39
  }
@@ -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 });
@@ -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`,
@@ -52,7 +53,7 @@ async function getContractDecimals({ chain, to }: { chain: EVMChain; to: string
52
53
 
53
54
  return Number.parseInt(BigInt(result || BaseDecimal[chain]).toString());
54
55
  } catch (error) {
55
- console.error(error);
56
+ console.error(`Failed to fetch contract decimals for ${to} on ${chain}:`, error);
56
57
  return BaseDecimal[chain];
57
58
  }
58
59
  }
@@ -76,7 +77,7 @@ async function getRadixAssetDecimal(symbol: string) {
76
77
 
77
78
  return manager.divisibility.value.divisibility;
78
79
  } catch (error) {
79
- console.error(error);
80
+ console.error(`Failed to fetch Radix asset decimal for ${symbol}:`, error);
80
81
  return BaseDecimal[Chain.Radix];
81
82
  }
82
83
  }
@@ -125,27 +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
- identifier: `${assetString.toUpperCase()}.ETH`,
130
- decimal,
131
- }))
132
- .with(Chain.THORChain, () => ({
133
- identifier: `${assetString.toUpperCase()}.RUNE`,
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
- }))
145
- .with(Chain.Avalanche, () => ({
146
- identifier: `${assetString.toUpperCase()}.AVAX`,
147
- decimal,
148
- }))
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 }))
149
135
  .with(
150
136
  ...UTXOChains,
151
137
  Chain.Solana,
@@ -153,13 +139,13 @@ export const getCommonAssetInfo = (assetString: CommonAssetString) => {
153
139
  Chain.Kujira,
154
140
  Chain.Ripple,
155
141
  Chain.Polkadot,
156
- () => ({ identifier: `${assetString.toUpperCase()}.${assetString.toUpperCase()}`, decimal }),
142
+ Chain.Tron,
143
+ Chain.Near,
144
+ (asset) => ({ identifier: `${asset}.${asset}`, decimal }),
157
145
  )
158
- .with(Chain.Radix, "XRD.XRD", () => ({
159
- identifier: "XRD.XRD",
160
- decimal,
161
- }))
162
- .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 }))
163
149
  .with("ETH.FLIP", () => ({
164
150
  identifier: "ETH.FLIP-0x826180541412D574cf1336d22c0C0a287822678A",
165
151
  decimal: BaseDecimal.ETH,
@@ -172,7 +158,8 @@ export const getCommonAssetInfo = (assetString: CommonAssetString) => {
172
158
  identifier: "ETH.vTHOR-0x815c23eca83261b6ec689b60cc4a58b54bc24d8d",
173
159
  decimal: BaseDecimal.ETH,
174
160
  }))
175
- .with("MAYA.MAYA", () => ({ identifier: assetString.toUpperCase(), decimal: 4 }))
161
+ .with("MAYA.CACAO", (identifier) => ({ identifier, decimal: 10 }))
162
+ .with("MAYA.MAYA", (identifier) => ({ identifier, decimal: 4 }))
176
163
  // Just to be sure that we are not missing any chain
177
164
  .otherwise(() => ({ identifier: assetString, decimal }));
178
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
- switch (chain) {
130
- case Chain.Bitcoin:
131
- case Chain.Dogecoin:
132
- case Chain.Litecoin:
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 & {
@@ -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 console.error(error);
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
 
@@ -70,7 +70,10 @@ export async function switchEVMWalletNetwork(
70
70
  });
71
71
  } catch (_error) {
72
72
  if (!networkParams) {
73
- throw new Error("Failed to switch network, networkParams not provided");
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,