@swapkit/helpers 2.5.0 → 3.0.0-beta.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (106) hide show
  1. package/dist/api/index.cjs +3 -0
  2. package/dist/api/index.cjs.map +16 -0
  3. package/dist/api/index.js +3 -0
  4. package/dist/api/index.js.map +16 -0
  5. package/dist/chunk-fazw0jvt.js +3 -0
  6. package/dist/chunk-fazw0jvt.js.map +9 -0
  7. package/dist/chunk-nm00d52v.js +4 -0
  8. package/dist/chunk-nm00d52v.js.map +9 -0
  9. package/dist/contracts/index.cjs +3 -0
  10. package/dist/contracts/index.cjs.map +38 -0
  11. package/dist/contracts/index.js +3 -0
  12. package/dist/contracts/index.js.map +38 -0
  13. package/dist/index.cjs +6 -0
  14. package/dist/index.cjs.map +29 -0
  15. package/dist/index.js +3 -3
  16. package/dist/index.js.map +19 -20
  17. package/dist/tokens/index.cjs +3 -0
  18. package/dist/tokens/index.cjs.map +23 -0
  19. package/dist/tokens/index.js +3 -0
  20. package/dist/tokens/index.js.map +23 -0
  21. package/package.json +31 -15
  22. package/src/api/index.ts +19 -0
  23. package/src/api/microgard/endpoints.ts +83 -0
  24. package/src/api/microgard/types.ts +60 -0
  25. package/src/api/midgard/endpoints.ts +166 -0
  26. package/src/api/midgard/types.ts +155 -0
  27. package/src/api/swapkitApi/endpoints.ts +266 -0
  28. package/src/api/swapkitApi/types.ts +772 -0
  29. package/src/api/thornode/endpoints.ts +78 -0
  30. package/src/api/thornode/types.ts +241 -0
  31. package/src/api/thorswapStatic/endpoints.ts +30 -0
  32. package/src/api/thorswapStatic/types.ts +18 -0
  33. package/src/contracts/abis/avaxGeneric.ts +92 -0
  34. package/src/contracts/abis/avaxWoofi.ts +145 -0
  35. package/src/contracts/abis/bscGeneric.ts +106 -0
  36. package/src/contracts/abis/chainflipGateway.ts +330 -0
  37. package/src/contracts/abis/erc20.ts +99 -0
  38. package/src/contracts/abis/ethGeneric.ts +92 -0
  39. package/src/contracts/abis/mayaEvmVaults.ts +331 -0
  40. package/src/contracts/abis/pancakeV2.ts +145 -0
  41. package/src/contracts/abis/pangolin.ts +120 -0
  42. package/src/contracts/abis/sushiswap.ts +120 -0
  43. package/src/contracts/abis/tcEthVault.ts +650 -0
  44. package/src/contracts/abis/traderJoe.ts +120 -0
  45. package/src/contracts/abis/uniswapV2.ts +120 -0
  46. package/src/contracts/abis/uniswapV2Leg.ts +128 -0
  47. package/src/contracts/abis/uniswapV3_100.ts +128 -0
  48. package/src/contracts/abis/uniswapV3_10000.ts +128 -0
  49. package/src/contracts/abis/uniswapV3_3000.ts +128 -0
  50. package/src/contracts/abis/uniswapV3_500.ts +128 -0
  51. package/src/contracts/index.ts +95 -0
  52. package/src/contracts/routers/index.ts +58 -0
  53. package/src/contracts/routers/kyber.ts +402 -0
  54. package/src/contracts/routers/oneinch.ts +2188 -0
  55. package/src/contracts/routers/pancakeswap.ts +340 -0
  56. package/src/contracts/routers/pangolin.ts +340 -0
  57. package/src/contracts/routers/sushiswap.ts +340 -0
  58. package/src/contracts/routers/traderJoe.ts +340 -0
  59. package/src/contracts/routers/uniswapv2.ts +340 -0
  60. package/src/contracts/routers/uniswapv3.ts +254 -0
  61. package/src/contracts/routers/woofi.ts +171 -0
  62. package/src/index.ts +11 -12
  63. package/src/modules/__tests__/assetValue.test.ts +0 -2
  64. package/src/modules/__tests__/swapKitConfig.test.ts +37 -0
  65. package/src/modules/assetValue.ts +26 -92
  66. package/src/modules/bigIntArithmetics.ts +6 -2
  67. package/src/modules/requestClient.ts +26 -35
  68. package/src/modules/swapKitConfig.ts +131 -0
  69. package/src/modules/swapKitError.ts +6 -6
  70. package/src/tokens/index.ts +15 -0
  71. package/src/tokens/lists/camelot_v3.ts +15920 -0
  72. package/src/tokens/lists/caviar_v1.ts +1694 -0
  73. package/src/tokens/lists/chainflip.ts +104 -0
  74. package/src/tokens/lists/index.ts +13 -0
  75. package/src/tokens/lists/jupiter.ts +29606 -0
  76. package/src/tokens/lists/mayachain.ts +513 -0
  77. package/src/tokens/lists/oneinch.ts +14238 -0
  78. package/src/tokens/lists/openocean_v2.ts +11514 -0
  79. package/src/tokens/lists/pancakeswap.ts +4296 -0
  80. package/src/tokens/lists/pangolin_v1.ts +175 -0
  81. package/src/tokens/lists/sushiswap_v2.ts +965 -0
  82. package/src/tokens/lists/thorchain.ts +669 -0
  83. package/src/tokens/lists/traderjoe_v2.ts +1384 -0
  84. package/src/tokens/lists/uniswap_v2.ts +5596 -0
  85. package/src/tokens/lists/uniswap_v3.ts +5946 -0
  86. package/src/types/chains.ts +26 -46
  87. package/src/types/commonTypes.ts +3 -90
  88. package/src/types/index.ts +3 -4
  89. package/src/types/sdk.ts +0 -30
  90. package/src/types/tokens.ts +2 -2
  91. package/src/types/wallet.ts +37 -21
  92. package/src/{helpers → utils}/asset.ts +49 -19
  93. package/src/{helpers → utils}/derivationPath.ts +7 -2
  94. package/src/{helpers → utils}/memo.ts +0 -65
  95. package/src/{helpers → utils}/others.ts +12 -5
  96. package/src/utils/plugin.ts +13 -0
  97. package/src/{helpers/web3wallets.ts → utils/wallets.ts} +175 -139
  98. package/src/modules/walletUtils.ts +0 -30
  99. package/src/types/network.ts +0 -49
  100. /package/src/{helpers → utils}/__tests__/asset.test.ts +0 -0
  101. /package/src/{helpers/__tests__/derivationPath.ts → utils/__tests__/derivationPath.test.ts} +0 -0
  102. /package/src/{helpers → utils}/__tests__/memo.test.ts +0 -0
  103. /package/src/{helpers → utils}/__tests__/others.test.ts +0 -0
  104. /package/src/{helpers → utils}/__tests__/validators.test.ts +0 -0
  105. /package/src/{helpers → utils}/liquidity.ts +0 -0
  106. /package/src/{helpers → utils}/validators.ts +0 -0
@@ -182,6 +182,12 @@ export const UTXOChains = [
182
182
 
183
183
  export type CosmosChain = Chain.Cosmos | Chain.THORChain | Chain.Maya | Chain.Kujira;
184
184
  export const CosmosChains = [Chain.Cosmos, Chain.THORChain, Chain.Maya, Chain.Kujira] as const;
185
+ export const CosmosChainPrefixes = {
186
+ [Chain.Cosmos]: "cosmos",
187
+ [Chain.THORChain]: "thor",
188
+ [Chain.Maya]: "maya",
189
+ [Chain.Kujira]: "kujira",
190
+ } as Record<CosmosChain, string>;
185
191
 
186
192
  export const TCSupportedChains = [
187
193
  Chain.Avalanche,
@@ -209,8 +215,8 @@ export const RPC_URLS: Record<Chain | StagenetChain, string> = {
209
215
  [Chain.Avalanche]: "https://avalanche-c-chain-rpc.publicnode.com",
210
216
  [Chain.Base]: "https://base-rpc.publicnode.com",
211
217
  [Chain.BinanceSmartChain]: "https://bsc-dataseed.binance.org",
212
- [Chain.Bitcoin]: "https://bitcoin-rpc.publicnode.com",
213
218
  [Chain.BitcoinCash]: "https://node-router.thorswap.net/bitcoin-cash",
219
+ [Chain.Bitcoin]: "https://bitcoin-rpc.publicnode.com",
214
220
  [Chain.Chainflip]: "wss://mainnet-archive.chainflip.io",
215
221
  [Chain.Cosmos]: "https://node-router.thorswap.net/cosmos/rpc",
216
222
  [Chain.Dash]: "https://dash-rpc.publicnode.com",
@@ -224,10 +230,20 @@ export const RPC_URLS: Record<Chain | StagenetChain, string> = {
224
230
  [Chain.Polkadot]: "wss://rpc.polkadot.io",
225
231
  [Chain.Polygon]: "https://polygon-rpc.com",
226
232
  [Chain.Radix]: "https://radix-mainnet.rpc.grove.city/v1/326002fc/core",
233
+ [Chain.Solana]: "https://solana-rpc.publicnode.com",
227
234
  [Chain.THORChain]: "https://rpc.thorswap.net",
228
- [StagenetChain.THORChain]: "https://stagenet-rpc.ninerealms.com",
229
235
  [StagenetChain.Maya]: "https://stagenet.tendermint.mayachain.info",
230
- [Chain.Solana]: "https://solana-rpc.publicnode.com",
236
+ [StagenetChain.THORChain]: "https://stagenet-rpc.ninerealms.com",
237
+ };
238
+
239
+ export const NODE_URLS: Record<
240
+ Chain.THORChain | Chain.Maya | StagenetChain.THORChain | StagenetChain.Maya,
241
+ string
242
+ > = {
243
+ [Chain.THORChain]: "https://thornode.thorswap.net",
244
+ [Chain.Maya]: "https://mayanode.mayachain.info",
245
+ [StagenetChain.THORChain]: "https://stagenet-thornode.ninerealms.com",
246
+ [StagenetChain.Maya]: "https://stagenet.mayanode.mayachain.info",
231
247
  };
232
248
 
233
249
  export const FALLBACK_URLS: Record<Chain | StagenetChain, string[]> = {
@@ -266,7 +282,7 @@ export const FALLBACK_URLS: Record<Chain | StagenetChain, string[]> = {
266
282
  ],
267
283
  [Chain.Polygon]: ["https://polygon.llamarpc.com", "https://rpc.ankr.com/polygon"],
268
284
  [Chain.Radix]: ["https://mainnet.radixdlt.com", "https://radix-mainnet.rpc.grove.city/v1"],
269
- [Chain.THORChain]: ["https://thornode.ninerealms.com", "https://thornode.thorswap.net"],
285
+ [Chain.THORChain]: ["https://thornode.ninerealms.com", NODE_URLS[Chain.THORChain]],
270
286
  [StagenetChain.THORChain]: [],
271
287
  [Chain.Solana]: ["https://api.mainnet-beta.solana.com", "https://rpc.ankr.com/solana"],
272
288
  };
@@ -297,10 +313,6 @@ export const EXPLORER_URLS: Record<Chain, string> = {
297
313
 
298
314
  let RPCUrlsMerged = RPC_URLS;
299
315
 
300
- export const getRPCUrl = (chain: Chain | StagenetChain) => {
301
- return RPCUrlsMerged[chain];
302
- };
303
-
304
316
  const getRpcBody = (chain: Chain | StagenetChain) => {
305
317
  switch (chain) {
306
318
  case Chain.Arbitrum:
@@ -310,50 +322,26 @@ const getRpcBody = (chain: Chain | StagenetChain) => {
310
322
  case Chain.Ethereum:
311
323
  case Chain.Optimism:
312
324
  case Chain.Polygon:
313
- return {
314
- jsonrpc: "2.0",
315
- method: "eth_blockNumber",
316
- params: [],
317
- id: 1,
318
- };
325
+ return { id: 1, jsonrpc: "2.0", method: "eth_blockNumber", params: [] };
319
326
  case Chain.Bitcoin:
320
327
  case Chain.Dogecoin:
321
328
  case Chain.BitcoinCash:
322
329
  case Chain.Dash:
323
330
  case Chain.Litecoin:
324
- return {
325
- jsonrpc: "1.0",
326
- id: "test",
327
- method: "getblockchaininfo",
328
- params: [],
329
- };
331
+ return { id: "test", jsonrpc: "1.0", method: "getblockchaininfo", params: [] };
330
332
  case Chain.Cosmos:
331
333
  case Chain.Kujira:
332
334
  case Chain.Maya:
333
335
  case Chain.THORChain:
334
336
  case StagenetChain.Maya:
335
337
  case StagenetChain.THORChain:
336
- return {
337
- id: 1,
338
- jsonrpc: "2.0",
339
- method: "status",
340
- params: {},
341
- };
338
+ return { id: 1, jsonrpc: "2.0", method: "status", params: {} };
342
339
  case Chain.Polkadot:
343
- return {
344
- jsonrpc: "2.0",
345
- id: 1,
346
- method: "system_health",
347
- params: [],
348
- };
340
+ return { id: 1, jsonrpc: "2.0", method: "system_health", params: [] };
341
+ case Chain.Solana:
342
+ return { id: 1, jsonrpc: "2.0", method: "getHealth" };
349
343
  case Chain.Radix:
350
344
  return "";
351
- case Chain.Solana:
352
- return {
353
- jsonrpc: "2.0",
354
- id: 1,
355
- method: "getHealth",
356
- };
357
345
  default:
358
346
  throw new Error(`Unsupported chain: ${chain}`);
359
347
  }
@@ -437,14 +425,6 @@ export const ChainToChainId = chains.reduce(
437
425
  {} as { [key in Chain]: ChainId },
438
426
  );
439
427
 
440
- export const ChainToRPC = chains.reduce(
441
- (acc, chain) => {
442
- acc[chain] = getRPCUrl(chain);
443
- return acc;
444
- },
445
- {} as { [key in Chain]: string },
446
- );
447
-
448
428
  export const ChainToHexChainId = chains.reduce(
449
429
  (acc, chain) => {
450
430
  const chainString = `${ChainToChainName[chain]}Hex` as keyof typeof ChainId;
@@ -1,96 +1,9 @@
1
- import type { RadixNetwork } from "@swapkit/toolbox-radix";
2
1
  import type { Chain } from "./chains";
3
- import type { ChainApis } from "./sdk";
4
2
  import type { ChainWallet, CryptoChain } from "./wallet";
5
3
 
6
- /**
7
- * @optional for swapkit API access
8
- */
9
- export type SwapkitConfig = {
10
- swapkitConfig?: {
11
- isDev?: boolean;
12
- swapkitApiKey?: string;
13
- useHashedApiKey?: boolean;
14
- referer?: string;
15
- };
16
- swapkitApiKey?: string;
17
- };
18
-
19
- export type ConnectConfig = SwapkitConfig & {
20
- stagenet?: boolean;
21
- /**
22
- * @required
23
- */
24
- thorswapApiKey?: string;
25
- /**
26
- * @optional for non ETH EVM chains - if not set you must use alchemyApi
27
- */
28
- covalentApiKey?: string;
29
- /**
30
- * @required for ETH
31
- */
32
- ethplorerApiKey?: string;
33
- /**
34
- * @required for BTC, BCH, LTC, DOGE
35
- */
36
- blockchairApiKey?: string;
37
- /**
38
- * @required for Walletconnect
39
- */
40
- walletConnectProjectId?: string;
41
- /**
42
- * @optional for Trezor config
43
- */
44
- trezorManifest?: {
45
- email: string;
46
- appUrl: string;
47
- };
48
- /**
49
- * @optional for KeepKey config
50
- */
51
- keepkeyConfig?: {
52
- apiKey: string;
53
- pairingInfo: {
54
- name: string;
55
- imageUrl: string;
56
- basePath: string;
57
- url: string;
58
- };
59
- };
60
- /**
61
- * @deprecated use chainflipBrokerConfig
62
- * @optional for setting the chainflip broker url
63
- */
64
- chainflipBrokerUrl?: string;
65
- /**
66
- * @optional for setting the chainflip broker url
67
- */
68
- chainflipBrokerConfig?: {
69
- useChainflipSDKBroker?: boolean;
70
- chainflipBrokerUrl: string;
71
- };
72
- /**
73
- * @optional for setting the radix wallet
74
- */
75
- radixDappConfig?: {
76
- dAppDefinitionAddress: string;
77
- applicationName: string;
78
- applicationVersion: string;
79
- network: RadixNetwork;
80
- };
81
-
82
- /**
83
- * @optional for setting the kado api key
84
- */
85
- kadoApiKey?: string;
86
- };
87
-
88
- export type ConnectWalletParams<M = { [key in string]: any }> = {
89
- addChain: <T extends CryptoChain>(params: ChainWallet<T> & M) => void;
90
- apis: ChainApis;
91
- config: ConnectConfig;
92
- rpcUrls: { [chain in CryptoChain]?: string };
93
- };
4
+ export type AddChainType<M = { [key in string]: any }> = <T extends CryptoChain>(
5
+ params: ChainWallet<T> & M,
6
+ ) => void;
94
7
 
95
8
  export type Witness = {
96
9
  value: number;
@@ -1,9 +1,8 @@
1
1
  export * from "./chains";
2
2
  export * from "./commonTypes";
3
3
  export * from "./derivationPath";
4
- export * from "./network";
5
- export * from "./tokens";
6
- export * from "./wallet";
7
- export * from "./sdk";
8
4
  export * from "./quotes";
9
5
  export * from "./radix";
6
+ export * from "./sdk";
7
+ export * from "./tokens";
8
+ export * from "./wallet";
package/src/types/sdk.ts CHANGED
@@ -1,34 +1,4 @@
1
- import type { CovalentApiType, EthplorerApiType } from "@swapkit/toolbox-evm";
2
- import type { BlockchairApiType } from "@swapkit/toolbox-utxo";
3
-
4
- import type { AlchemyApiType } from "@swapkit/toolbox-evm/src/api/alchemyApi";
5
1
  import type { AssetValue } from "../modules/assetValue";
6
- import type { Chain, CosmosChain, UTXOChain } from "./chains";
7
-
8
- type NonEthEvmChains =
9
- | Chain.Base
10
- | Chain.BinanceSmartChain
11
- | Chain.Polygon
12
- | Chain.Avalanche
13
- | Chain.Arbitrum
14
- | Chain.Optimism;
15
-
16
- export type ChainApis = { [key in NonEthEvmChains]?: CovalentApiType | AlchemyApiType } & {
17
- [key in Chain.Ethereum]?: EthplorerApiType;
18
- } & {
19
- [key in UTXOChain]?: BlockchairApiType;
20
- } & {
21
- [key in CosmosChain | Chain.Solana | Chain.Radix | Chain.Polkadot | Chain.Chainflip]?: string;
22
- } & {
23
- [key in Chain.Fiat]?: undefined;
24
- };
25
-
26
- export type ChainApi =
27
- | EthplorerApiType
28
- | CovalentApiType
29
- | AlchemyApiType
30
- | BlockchairApiType
31
- | string;
32
2
 
33
3
  export type GenericSwapParams<T = unknown> = {
34
4
  buyAsset?: AssetValue;
@@ -1,4 +1,4 @@
1
- import type { tokenLists } from "@swapkit/tokens";
1
+ import type { tokenLists } from "@swapkit/helpers/tokens";
2
2
 
3
3
  export type TokenTax = { buy: number; sell: number };
4
4
 
@@ -6,7 +6,7 @@ export type TokenNames =
6
6
  | (typeof tokenLists)["CaviarV1List"]["tokens"][number]["identifier"]
7
7
  | (typeof tokenLists)["ChainflipList"]["tokens"][number]["identifier"]
8
8
  | (typeof tokenLists)["JupiterList"]["tokens"][number]["identifier"]
9
- | (typeof tokenLists)["KadoList"]["tokens"][number]["identifier"]
9
+ // | (typeof tokenLists)["KadoList"]["tokens"][number]["identifier"]
10
10
  | (typeof tokenLists)["MayaList"]["tokens"][number]["identifier"]
11
11
  // | (typeof tokenLists)['OciswapV1List']["tokens"][number]["identifier"]
12
12
  | (typeof tokenLists)["OneInchList"]["tokens"][number]["identifier"]
@@ -1,14 +1,14 @@
1
- import type { CosmosWallets, ThorchainWallets } from "@swapkit/toolbox-cosmos";
2
- import type { EVMWallets } from "@swapkit/toolbox-evm";
3
- import type { RadixWallets } from "@swapkit/toolbox-radix";
4
- import type { SolanaWallets } from "@swapkit/toolbox-solana";
5
- import type { SubstrateWallets } from "@swapkit/toolbox-substrate";
6
- import type { UTXOWallets } from "@swapkit/toolbox-utxo";
1
+ import type { CosmosWallets, ThorchainWallets } from "@swapkit/toolboxes/cosmos";
2
+ import type { EVMWallets } from "@swapkit/toolboxes/evm";
3
+ import type { RadixWallets } from "@swapkit/toolboxes/radix";
4
+ import type { SolanaWallets } from "@swapkit/toolboxes/solana";
5
+ import type { SubstrateWallets } from "@swapkit/toolboxes/substrate";
6
+ import type { UTXOWallets } from "@swapkit/toolboxes/utxo";
7
+ import type { BrowserProvider } from "ethers";
7
8
  import type { Eip1193Provider } from "ethers";
8
9
 
9
10
  import type { AssetValue } from "../modules/assetValue";
10
- import type { Chain } from "./chains";
11
- import type { ConnectWalletParams } from "./commonTypes";
11
+ import type { Chain, ChainId } from "./chains";
12
12
 
13
13
  declare global {
14
14
  interface WindowEventMap {
@@ -16,6 +16,33 @@ declare global {
16
16
  }
17
17
  }
18
18
 
19
+ export type EthereumWindowProvider = BrowserProvider & {
20
+ __XDEFI?: boolean;
21
+ isBraveWallet?: boolean;
22
+ isCoinbaseWallet?: boolean;
23
+ isMetaMask?: boolean;
24
+ isOkxWallet?: boolean;
25
+ isKeepKeyWallet?: boolean;
26
+ isTrust?: boolean;
27
+ isTalisman?: boolean;
28
+ on: (event: string, callback?: () => void) => void;
29
+ overrideIsMetaMask?: boolean;
30
+ request: <T = unknown>(args: { method: string; params?: unknown[] }) => Promise<T>;
31
+ selectedProvider?: EthereumWindowProvider;
32
+ };
33
+
34
+ export type NetworkParams = {
35
+ chainId: ChainId;
36
+ chainName: string;
37
+ nativeCurrency: {
38
+ name: string;
39
+ symbol: string;
40
+ decimals: number;
41
+ };
42
+ rpcUrls: string[];
43
+ blockExplorerUrls: string[];
44
+ };
45
+
19
46
  export type {
20
47
  CosmosWallets,
21
48
  ThorchainWallets,
@@ -64,7 +91,7 @@ export type ChainWallet<T extends Chain> = {
64
91
  chain: T;
65
92
  address: string;
66
93
  balance: AssetValue[];
67
- walletType: WalletOption;
94
+ walletType: WalletOption | string;
68
95
  disconnect?: () => void;
69
96
  signMessage?: (message: string) => Promise<string>;
70
97
  };
@@ -84,19 +111,8 @@ export type FullWallet = BaseWallet<
84
111
  RadixWallets
85
112
  >;
86
113
 
87
- /**
88
- * @deprecated use FullWallet instead
89
- */
90
- export type Wallet = FullWallet;
91
-
92
- export type SwapKitWallet<ConnectParams extends any[]> = (
93
- params: ConnectWalletParams,
94
- ) => (...connectParams: ConnectParams) => boolean | Promise<boolean>;
95
-
96
- export type SwapKitPluginParams<Config = {}> = {
114
+ export type SwapKitPluginParams = {
97
115
  getWallet: <T extends CryptoChain>(chain: T) => FullWallet[T];
98
- stagenet?: boolean;
99
- config: Config;
100
116
  };
101
117
 
102
118
  export type EIP6963ProviderInfo = {
@@ -1,6 +1,7 @@
1
1
  import { AssetValue } from "../modules/assetValue";
2
2
  import { RequestClient } from "../modules/requestClient";
3
- import { BaseDecimal, Chain, ChainToRPC, type EVMChain, EVMChains } from "../types/chains";
3
+ import { SKConfig } from "../modules/swapKitConfig";
4
+ import { BaseDecimal, Chain, type EVMChain, EVMChains } from "../types/chains";
4
5
  import type { RadixCoreStateResourceDTO } from "../types/radix";
5
6
  import type { TokenNames } from "../types/tokens";
6
7
 
@@ -17,23 +18,28 @@ export const CommonAssetStrings = [
17
18
  `${Chain.Ethereum}.THOR`,
18
19
  `${Chain.Ethereum}.vTHOR`,
19
20
  `${Chain.Kujira}.USK`,
21
+ `${Chain.Ethereum}.FLIP`,
22
+ `${Chain.Radix}.XRD`,
20
23
  ] as const;
21
24
 
22
25
  const getContractDecimals = async ({ chain, to }: { chain: EVMChain; to: string }) => {
23
26
  try {
24
- const { result } = await RequestClient.post<{ result: string }>(ChainToRPC[chain], {
25
- headers: {
26
- accept: "*/*",
27
- "content-type": "application/json",
28
- "cache-control": "no-cache",
27
+ const { result } = await RequestClient.post<{ result: string }>(
28
+ SKConfig.get("rpcUrls")[chain],
29
+ {
30
+ headers: {
31
+ accept: "*/*",
32
+ "content-type": "application/json",
33
+ "cache-control": "no-cache",
34
+ },
35
+ body: JSON.stringify({
36
+ id: 44,
37
+ jsonrpc: "2.0",
38
+ method: "eth_call",
39
+ params: [{ to: to.toLowerCase(), data: getDecimalMethodHex }, "latest"],
40
+ }),
29
41
  },
30
- body: JSON.stringify({
31
- id: 44,
32
- jsonrpc: "2.0",
33
- method: "eth_call",
34
- params: [{ to: to.toLowerCase(), data: getDecimalMethodHex }, "latest"],
35
- }),
36
- });
42
+ );
37
43
 
38
44
  return Number.parseInt(BigInt(result || BaseDecimal[chain]).toString());
39
45
  } catch (error) {
@@ -47,7 +53,7 @@ const getRadixResourceDecimals = async ({ symbol }: { symbol: string }) => {
47
53
  const resourceAddress = symbol.split("-")[1]?.toLowerCase();
48
54
 
49
55
  const { manager } = await RequestClient.post<RadixCoreStateResourceDTO>(
50
- `${ChainToRPC[Chain.Radix]}/state/resource`,
56
+ `${SKConfig.get("rpcUrls").XRD}/state/resource`,
51
57
  {
52
58
  headers: {
53
59
  Accept: "*/*",
@@ -148,6 +154,8 @@ export const isGasAsset = ({ chain, symbol }: { chain: Chain; symbol: string })
148
154
  return symbol === "BNB";
149
155
  case Chain.THORChain:
150
156
  return symbol === "RUNE";
157
+ case Chain.Radix:
158
+ return `${chain}.${symbol}` === getCommonAssetInfo(chain).identifier;
151
159
 
152
160
  default:
153
161
  return symbol === chain;
@@ -161,10 +169,29 @@ export const getCommonAssetInfo = (assetString: CommonAssetString) => {
161
169
  case Chain.Optimism:
162
170
  return { identifier: `${assetString}.ETH`, decimal: BaseDecimal[assetString] };
163
171
 
172
+ case `${Chain.Radix}.XRD`:
173
+ case Chain.Radix:
174
+ return {
175
+ identifier: "XRD.XRD-resource_rdx1tknxxxxxxxxxradxrdxxxxxxxxx009923554798xxxxxxxxxradxrd",
176
+ decimal: BaseDecimal.XRD,
177
+ };
178
+
179
+ case `${Chain.Ethereum}.FLIP`:
180
+ return {
181
+ identifier: "ETH.FLIP-0x826180541412D574cf1336d22c0C0a287822678A",
182
+ decimal: BaseDecimal.ETH,
183
+ };
164
184
  case `${Chain.Ethereum}.THOR`:
165
- return { identifier: "ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044", decimal: 18 };
185
+ return {
186
+ identifier: "ETH.THOR-0xa5f2211b9b8170f694421f2046281775e8468044",
187
+ decimal: BaseDecimal.ETH,
188
+ };
166
189
  case `${Chain.Ethereum}.vTHOR`:
167
- return { identifier: "ETH.vTHOR-0x815c23eca83261b6ec689b60cc4a58b54bc24d8d", decimal: 18 };
190
+ return {
191
+ identifier: "ETH.vTHOR-0x815c23eca83261b6ec689b60cc4a58b54bc24d8d",
192
+ decimal: BaseDecimal.ETH,
193
+ };
194
+
168
195
  case Chain.Cosmos:
169
196
  return { identifier: `${assetString}.ATOM`, decimal: BaseDecimal[assetString] };
170
197
  case Chain.THORChain:
@@ -173,8 +200,6 @@ export const getCommonAssetInfo = (assetString: CommonAssetString) => {
173
200
  return { identifier: `${assetString}.BNB`, decimal: BaseDecimal[assetString] };
174
201
  case Chain.Maya:
175
202
  return { identifier: `${assetString}.CACAO`, decimal: 10 };
176
- case Chain.Radix:
177
- return { identifier: `${Chain.Radix}.XRD`, decimal: BaseDecimal[assetString] };
178
203
 
179
204
  case `${Chain.Maya}.MAYA`:
180
205
  return { identifier: assetString, decimal: 4 };
@@ -190,6 +215,11 @@ export const getAssetType = ({ chain, symbol }: { chain: Chain; symbol: string }
190
215
  if (symbol.includes("/")) return "Synth";
191
216
 
192
217
  switch (chain) {
218
+ case Chain.Radix:
219
+ return symbol === Chain.Radix || `${chain}.${symbol}` === getCommonAssetInfo(chain).identifier
220
+ ? "Native"
221
+ : chain;
222
+
193
223
  case Chain.Arbitrum:
194
224
  case Chain.Optimism:
195
225
  case Chain.Base:
@@ -258,7 +288,7 @@ export async function findAssetBy(
258
288
  | { chain: EVMChain | Chain.Radix | Chain.Solana; contract: string }
259
289
  | { identifier: `${Chain}.${string}` },
260
290
  ) {
261
- const { tokenLists } = await import("@swapkit/tokens");
291
+ const { tokenLists } = await import("@swapkit/helpers/tokens");
262
292
 
263
293
  for (const tokenList of Object.values(tokenLists)) {
264
294
  for (const { identifier, chain: tokenChain, ...rest } of tokenList.tokens) {
@@ -29,9 +29,14 @@ export function derivationPathToString([network, chainId, account, change, index
29
29
  // TODO @towan - sort this out and make it more readable
30
30
  export function getDerivationPathFor({ chain, index, addressIndex = 0, type }: Params) {
31
31
  if (EVMChains.includes(chain as EVMChain)) {
32
- if (type && ["legacy", "account"].includes(type))
32
+ if (type && ["legacy", "account"].includes(type)) {
33
33
  return [44, 60, 0, index] as DerivationPathArray;
34
- if (type === "ledgerLive") return [44, 60, index, 0, addressIndex] as DerivationPathArray;
34
+ }
35
+
36
+ if (type === "ledgerLive") {
37
+ return [44, 60, index, 0, addressIndex] as DerivationPathArray;
38
+ }
39
+
35
40
  return updatedLastIndex(NetworkDerivationPath[chain], index);
36
41
  }
37
42
 
@@ -1,4 +1,3 @@
1
- import { SwapKitError } from "../modules/swapKitError";
2
1
  import { Chain } from "../types/chains";
3
2
  import { MemoType } from "../types/sdk";
4
3
 
@@ -162,67 +161,3 @@ type WithdrawParams = {
162
161
  basisPoints: number;
163
162
  targetAsset?: string;
164
163
  };
165
-
166
- /**
167
- * @deprecated - Use separate functions per each memo type like getMemoForDeposit, getMemoForWithdraw, etc.
168
- */
169
- export const getMemoFor = <T extends MemoType>(memoType: T, options: any) => {
170
- switch (memoType) {
171
- case MemoType.LEAVE:
172
- case MemoType.BOND: {
173
- return getMemoForLeaveAndBond({ type: memoType, address: options?.address });
174
- }
175
-
176
- case MemoType.UNBOND: {
177
- return getMemoForUnbond({ address: options?.address, unbondAmount: options?.unbondAmount });
178
- }
179
-
180
- case MemoType.NAME_REGISTER: {
181
- return getMemoForNameRegister(options);
182
- }
183
-
184
- case MemoType.OPEN_LOAN:
185
- case MemoType.CLOSE_LOAN: {
186
- return getMemoForLoan(memoType, options);
187
- }
188
-
189
- case MemoType.DEPOSIT: {
190
- const { chain, symbol, address, singleSide } = options;
191
-
192
- if (singleSide) {
193
- return getMemoForSaverDeposit({ chain, symbol });
194
- }
195
-
196
- return getMemoForDeposit({ chain, symbol, address });
197
- }
198
-
199
- case MemoType.WITHDRAW: {
200
- const {
201
- chain,
202
- ticker,
203
- symbol,
204
- basisPoints,
205
- targetAssetString: targetAsset,
206
- singleSide,
207
- } = options;
208
-
209
- if (singleSide) {
210
- return getMemoForSaverWithdraw({ chain, symbol, basisPoints });
211
- }
212
-
213
- return getMemoForWithdraw({
214
- chain,
215
- ticker,
216
- symbol,
217
- basisPoints,
218
- targetAsset,
219
- });
220
- }
221
-
222
- default:
223
- throw new SwapKitError({
224
- errorKey: "helpers_invalid_memo_type",
225
- info: { memoType },
226
- });
227
- }
228
- };
@@ -1,6 +1,7 @@
1
1
  import { RequestClient } from "../modules/requestClient";
2
+ import { SKConfig } from "../modules/swapKitConfig";
2
3
  import { type ErrorKeys, SwapKitError } from "../modules/swapKitError";
3
- import { Chain, ChainId, StagenetChain, getRPCUrl } from "../types";
4
+ import { Chain, ChainId, StagenetChain } from "../types";
4
5
 
5
6
  // 10 rune for register, 1 rune per year
6
7
  // MINIMUM_REGISTRATION_FEE = 11
@@ -53,10 +54,9 @@ export function getChainIdentifier<T extends Chain>(chain: T) {
53
54
  }
54
55
  }
55
56
 
56
- const skipWarnings = ["production", "test"].includes(process.env.NODE_ENV || "");
57
57
  const warnings = new Set();
58
58
  export function warnOnce(condition: boolean, warning: string) {
59
- if (!skipWarnings && condition) {
59
+ if (condition) {
60
60
  if (warnings.has(warning)) {
61
61
  return;
62
62
  }
@@ -67,11 +67,18 @@ export function warnOnce(condition: boolean, warning: string) {
67
67
  }
68
68
 
69
69
  export async function getDynamicChainId(chainId: ChainId = ChainId.THORChain) {
70
- if (![ChainId.THORChainStagenet, ChainId.THORChain, "thorchain-mainnet-v1"].includes(chainId))
70
+ if (![ChainId.THORChainStagenet, ChainId.THORChain, "thorchain-mainnet-v1"].includes(chainId)) {
71
71
  return chainId;
72
+ }
73
+
72
74
  try {
75
+ const rpcUrl =
76
+ SKConfig.get("rpcUrls")[
77
+ chainId !== ChainId.THORChain ? StagenetChain.THORChain : Chain.THORChain
78
+ ];
79
+
73
80
  const response = await RequestClient.get<{ result: { node_info: { network: string } } }>(
74
- `${chainId !== ChainId.THORChain ? getRPCUrl(StagenetChain.THORChain) : getRPCUrl(Chain.THORChain)}/status`,
81
+ `${rpcUrl}/status`,
75
82
  );
76
83
  return response.result.node_info.network as ChainId;
77
84
  } catch (_error) {
@@ -0,0 +1,13 @@
1
+ import type { ProviderName, SwapKitPluginParams } from "../types";
2
+
3
+ export function createPlugin<
4
+ const Name extends string,
5
+ T extends (params: SwapKitPluginParams) => Record<string, unknown>,
6
+ K extends { supportedSwapkitProviders?: ProviderName[] },
7
+ >({ name, properties, methods }: { name: Name; properties?: K; methods: T }) {
8
+ function plugin(pluginParams: SwapKitPluginParams) {
9
+ return { ...methods(pluginParams), ...properties } as K & ReturnType<T>;
10
+ }
11
+
12
+ return { [name]: plugin } as { [key in Name]: typeof plugin };
13
+ }