@swapkit/helpers 2.4.3 → 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 -24
  90. package/src/types/tokens.ts +1 -1
  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 -148
  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
@@ -0,0 +1,131 @@
1
+ import { createStore } from "zustand/vanilla";
2
+ import { type Chain, EXPLORER_URLS, NODE_URLS, RPC_URLS } from "../types";
3
+
4
+ export type SKConfigIntegrations = {
5
+ chainflip?: { useSDKBroker?: boolean; brokerUrl: string };
6
+ coinbase?: {
7
+ appName: string;
8
+ appLogoUrl?: string | null;
9
+ darkMode?: boolean;
10
+ linkAPIUrl?: string;
11
+ overrideIsMetaMask?: boolean;
12
+ overrideIsCoinbaseWallet?: boolean;
13
+ overrideIsCoinbaseBrowser?: boolean;
14
+ headlessMode?: boolean;
15
+ reloadOnDisconnect?: boolean;
16
+ };
17
+ trezor?: { email: string; appUrl: string };
18
+ keepKey?: { name: string; imageUrl: string; basePath: string; url: string };
19
+ radix: {
20
+ dAppDefinitionAddress: string;
21
+ applicationName: string;
22
+ applicationVersion: string;
23
+ network: { networkId: number; networkName: string; dashboardBase: string };
24
+ };
25
+ };
26
+
27
+ const initialState = {
28
+ // TODO: figure out how to type apis without using toolbox directly
29
+ // Maybe move rpc/toolbox apis to helpers?
30
+ apis: {} as { [key in Chain]: any },
31
+ explorerUrls: EXPLORER_URLS,
32
+ nodeUrls: NODE_URLS,
33
+ rpcUrls: RPC_URLS,
34
+
35
+ apiKeys: {
36
+ blockchair: "",
37
+ covalent: "",
38
+ ethplorer: "freekey",
39
+ kado: "",
40
+ keepKey: "",
41
+ swapKit: "",
42
+ walletConnectProjectId: "",
43
+ },
44
+
45
+ envs: {
46
+ apiUrl: "https://api.swapkit.dev",
47
+ devApiUrl: "https://dev-api.swapkit.dev",
48
+ isDev: false,
49
+ isStagenet: false,
50
+ referer: "https://swapkit.dev",
51
+ },
52
+
53
+ integrations: {
54
+ radix: {
55
+ applicationName: "Swapkit Playground",
56
+ applicationVersion: "0.0.1",
57
+ dAppDefinitionAddress: "account_rdx128r289p58222hcvev7frs6kue76pl7pdcnw8725aw658v0zggkh9ws",
58
+ network: {
59
+ dashboardBase: "https://dashboard.radixdlt.com",
60
+ networkId: 1,
61
+ networkName: "mainnet",
62
+ },
63
+ },
64
+ } as SKConfigIntegrations,
65
+ };
66
+ type SKState = typeof initialState;
67
+
68
+ export type SKConfigState = {
69
+ apiKeys?: Partial<SKState["apiKeys"]>;
70
+ envs?: Partial<SKState["envs"]>;
71
+ explorerUrls?: Partial<SKState["explorerUrls"]>;
72
+ integrations?: Partial<SKConfigIntegrations>;
73
+ nodeUrls?: Partial<SKState["nodeUrls"]>;
74
+ rpcUrls?: Partial<SKState["rpcUrls"]>;
75
+ };
76
+
77
+ type SwapKitConfigStore = SKState & {
78
+ setApiKey: (key: keyof SKState["apiKeys"], apiKey: string) => void;
79
+ setConfig: (config: SKConfigState) => void;
80
+ setEnv: <T extends keyof SKState["envs"]>(key: T, value: SKState["envs"][T]) => void;
81
+ setExplorerUrl: (chain: keyof SKState["explorerUrls"], url: string) => void;
82
+ setNodeUrl: (chain: keyof SKState["nodeUrls"], url: string) => void;
83
+ setRpcUrl: (chain: keyof SKState["rpcUrls"], url: string) => void;
84
+ setIntegrationConfig: (
85
+ integration: keyof SKState["integrations"],
86
+ config: SKConfigIntegrations[keyof SKConfigIntegrations],
87
+ ) => void;
88
+ };
89
+
90
+ const swapKitState = createStore<SwapKitConfigStore>((set) => ({
91
+ ...initialState,
92
+
93
+ setApiKey: (key, apiKey) => set((s) => ({ apiKeys: { ...s.apiKeys, [key]: apiKey } })),
94
+ setEnv: (key, value) => set((s) => ({ envs: { ...s.envs, [key]: value } })),
95
+ setExplorerUrl: (chain, url) =>
96
+ set((s) => ({ explorerUrls: { ...s.explorerUrls, [chain]: url } })),
97
+ setNodeUrl: (chain, url) => set((s) => ({ nodeUrls: { ...s.nodeUrls, [chain]: url } })),
98
+ setRpcUrl: (chain, url) => set((s) => ({ rpcUrls: { ...s.rpcUrls, [chain]: url } })),
99
+ setIntegrationConfig: (integration, config) =>
100
+ set((s) => ({ integrations: { ...s.integrations, [integration]: config } })),
101
+ setConfig: (config) =>
102
+ set((s) => ({
103
+ apiKeys: { ...s.apiKeys, ...config.apiKeys },
104
+ envs: { ...s.envs, ...config.envs },
105
+ explorerUrls: { ...s.explorerUrls, ...config.explorerUrls },
106
+ nodeUrls: { ...s.nodeUrls, ...config.nodeUrls },
107
+ rpcUrls: { ...s.rpcUrls, ...config.rpcUrls },
108
+ integrations: { ...s.integrations, ...config.integrations },
109
+ })),
110
+ }));
111
+
112
+ export const SKConfig = {
113
+ getState: swapKitState.getState,
114
+ get: <T extends keyof SKState>(key: T) => swapKitState.getState()[key],
115
+ set: <T extends SKConfigState>(config: T) => swapKitState.getState().setConfig(config),
116
+
117
+ setApiKey: <T extends keyof SKState["apiKeys"]>(key: T, apiKey: string) =>
118
+ swapKitState.getState().setApiKey(key, apiKey),
119
+ setEnv: <T extends keyof SKState["envs"]>(key: T, value: SKState["envs"][T]) =>
120
+ swapKitState.getState().setEnv(key, value),
121
+ setExplorerUrl: <T extends keyof SKState["explorerUrls"]>(chain: T, url: string) =>
122
+ swapKitState.getState().setExplorerUrl(chain, url),
123
+ setNodeUrl: <T extends keyof SKState["nodeUrls"]>(chain: T, url: string) =>
124
+ swapKitState.getState().setNodeUrl(chain, url),
125
+ setRpcUrl: <T extends keyof SKState["rpcUrls"]>(chain: T, url: string) =>
126
+ swapKitState.getState().setRpcUrl(chain, url),
127
+ setIntegrationConfig: <T extends keyof SKState["integrations"]>(
128
+ integration: T,
129
+ config: SKConfigIntegrations[T],
130
+ ) => swapKitState.getState().setIntegrationConfig(integration, config),
131
+ };
@@ -94,6 +94,7 @@ const errorCodes = {
94
94
  wallet_keepkey_contract_address_not_provided: 20902,
95
95
  wallet_keepkey_send_transaction_no_address: 20903,
96
96
  wallet_bitkeep_not_found: 21001,
97
+ wallet_exodus_sign_transaction_error: 21100,
97
98
  /**
98
99
  * Chainflip
99
100
  */
@@ -128,6 +129,7 @@ const errorCodes = {
128
129
  toolbox_cosmos_signer_not_defined: 90101,
129
130
  toolbox_cosmos_no_accounts_found: 90102,
130
131
  toolbox_cosmos_verify_signature_no_pubkey: 90103,
132
+ toolbox_cosmos_validate_address_prefix_not_found: 90104,
131
133
  toolbox_evm_no_abi_fragment: 90201,
132
134
  toolbox_evm_no_signer: 90202,
133
135
  toolbox_evm_no_signer_address: 90203,
@@ -168,8 +170,8 @@ export class SwapKitError extends Error {
168
170
  sourceError?: any,
169
171
  ) {
170
172
  const isErrorString = typeof errorOrErrorKey === "string";
171
-
172
173
  const errorKey = isErrorString ? errorOrErrorKey : errorOrErrorKey.errorKey;
174
+ super(errorKey);
173
175
 
174
176
  if (sourceError) {
175
177
  console.error(sourceError, {
@@ -178,11 +180,9 @@ export class SwapKitError extends Error {
178
180
  });
179
181
  }
180
182
 
181
- super(errorKey, {
182
- cause: {
183
- code: SwapKitError.ErrorCode[errorKey],
184
- message: `${errorKey}${isErrorString ? "" : `: ${JSON.stringify(errorOrErrorKey.info)}`}`,
185
- },
183
+ console.error(errorKey, {
184
+ code: SwapKitError.ErrorCode[errorKey],
185
+ message: `${errorKey}${isErrorString ? "" : `: ${JSON.stringify(errorOrErrorKey.info)}`}`,
186
186
  });
187
187
 
188
188
  Object.setPrototypeOf(this, SwapKitError.prototype);
@@ -0,0 +1,15 @@
1
+ import * as tokenLists from "./lists";
2
+
3
+ export function getTokenIcon(identifier: string): string | undefined {
4
+ // Search through all lists for a matching token
5
+ for (const list of Object.values(tokenLists)) {
6
+ const token = list.tokens.find((token) => token.identifier === identifier);
7
+ if (token?.logoURI) {
8
+ return token.logoURI;
9
+ }
10
+ }
11
+
12
+ return undefined;
13
+ }
14
+
15
+ export { tokenLists };