@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.
- package/dist/api/index.cjs +3 -0
- package/dist/api/index.cjs.map +16 -0
- package/dist/api/index.js +3 -0
- package/dist/api/index.js.map +16 -0
- package/dist/chunk-fazw0jvt.js +3 -0
- package/dist/chunk-fazw0jvt.js.map +9 -0
- package/dist/chunk-nm00d52v.js +4 -0
- package/dist/chunk-nm00d52v.js.map +9 -0
- package/dist/contracts/index.cjs +3 -0
- package/dist/contracts/index.cjs.map +38 -0
- package/dist/contracts/index.js +3 -0
- package/dist/contracts/index.js.map +38 -0
- package/dist/index.cjs +6 -0
- package/dist/index.cjs.map +29 -0
- package/dist/index.js +3 -3
- package/dist/index.js.map +19 -20
- package/dist/tokens/index.cjs +3 -0
- package/dist/tokens/index.cjs.map +23 -0
- package/dist/tokens/index.js +3 -0
- package/dist/tokens/index.js.map +23 -0
- package/package.json +31 -15
- package/src/api/index.ts +19 -0
- package/src/api/microgard/endpoints.ts +83 -0
- package/src/api/microgard/types.ts +60 -0
- package/src/api/midgard/endpoints.ts +166 -0
- package/src/api/midgard/types.ts +155 -0
- package/src/api/swapkitApi/endpoints.ts +266 -0
- package/src/api/swapkitApi/types.ts +772 -0
- package/src/api/thornode/endpoints.ts +78 -0
- package/src/api/thornode/types.ts +241 -0
- package/src/api/thorswapStatic/endpoints.ts +30 -0
- package/src/api/thorswapStatic/types.ts +18 -0
- package/src/contracts/abis/avaxGeneric.ts +92 -0
- package/src/contracts/abis/avaxWoofi.ts +145 -0
- package/src/contracts/abis/bscGeneric.ts +106 -0
- package/src/contracts/abis/chainflipGateway.ts +330 -0
- package/src/contracts/abis/erc20.ts +99 -0
- package/src/contracts/abis/ethGeneric.ts +92 -0
- package/src/contracts/abis/mayaEvmVaults.ts +331 -0
- package/src/contracts/abis/pancakeV2.ts +145 -0
- package/src/contracts/abis/pangolin.ts +120 -0
- package/src/contracts/abis/sushiswap.ts +120 -0
- package/src/contracts/abis/tcEthVault.ts +650 -0
- package/src/contracts/abis/traderJoe.ts +120 -0
- package/src/contracts/abis/uniswapV2.ts +120 -0
- package/src/contracts/abis/uniswapV2Leg.ts +128 -0
- package/src/contracts/abis/uniswapV3_100.ts +128 -0
- package/src/contracts/abis/uniswapV3_10000.ts +128 -0
- package/src/contracts/abis/uniswapV3_3000.ts +128 -0
- package/src/contracts/abis/uniswapV3_500.ts +128 -0
- package/src/contracts/index.ts +95 -0
- package/src/contracts/routers/index.ts +58 -0
- package/src/contracts/routers/kyber.ts +402 -0
- package/src/contracts/routers/oneinch.ts +2188 -0
- package/src/contracts/routers/pancakeswap.ts +340 -0
- package/src/contracts/routers/pangolin.ts +340 -0
- package/src/contracts/routers/sushiswap.ts +340 -0
- package/src/contracts/routers/traderJoe.ts +340 -0
- package/src/contracts/routers/uniswapv2.ts +340 -0
- package/src/contracts/routers/uniswapv3.ts +254 -0
- package/src/contracts/routers/woofi.ts +171 -0
- package/src/index.ts +11 -12
- package/src/modules/__tests__/assetValue.test.ts +0 -2
- package/src/modules/__tests__/swapKitConfig.test.ts +37 -0
- package/src/modules/assetValue.ts +26 -92
- package/src/modules/bigIntArithmetics.ts +6 -2
- package/src/modules/requestClient.ts +26 -35
- package/src/modules/swapKitConfig.ts +131 -0
- package/src/modules/swapKitError.ts +6 -6
- package/src/tokens/index.ts +15 -0
- package/src/tokens/lists/camelot_v3.ts +15920 -0
- package/src/tokens/lists/caviar_v1.ts +1694 -0
- package/src/tokens/lists/chainflip.ts +104 -0
- package/src/tokens/lists/index.ts +13 -0
- package/src/tokens/lists/jupiter.ts +29606 -0
- package/src/tokens/lists/mayachain.ts +513 -0
- package/src/tokens/lists/oneinch.ts +14238 -0
- package/src/tokens/lists/openocean_v2.ts +11514 -0
- package/src/tokens/lists/pancakeswap.ts +4296 -0
- package/src/tokens/lists/pangolin_v1.ts +175 -0
- package/src/tokens/lists/sushiswap_v2.ts +965 -0
- package/src/tokens/lists/thorchain.ts +669 -0
- package/src/tokens/lists/traderjoe_v2.ts +1384 -0
- package/src/tokens/lists/uniswap_v2.ts +5596 -0
- package/src/tokens/lists/uniswap_v3.ts +5946 -0
- package/src/types/chains.ts +26 -46
- package/src/types/commonTypes.ts +3 -90
- package/src/types/index.ts +3 -4
- package/src/types/sdk.ts +0 -30
- package/src/types/tokens.ts +2 -2
- package/src/types/wallet.ts +37 -21
- package/src/{helpers → utils}/asset.ts +49 -19
- package/src/{helpers → utils}/derivationPath.ts +7 -2
- package/src/{helpers → utils}/memo.ts +0 -65
- package/src/{helpers → utils}/others.ts +12 -5
- package/src/utils/plugin.ts +13 -0
- package/src/{helpers/web3wallets.ts → utils/wallets.ts} +175 -139
- package/src/modules/walletUtils.ts +0 -30
- package/src/types/network.ts +0 -49
- /package/src/{helpers → utils}/__tests__/asset.test.ts +0 -0
- /package/src/{helpers/__tests__/derivationPath.ts → utils/__tests__/derivationPath.test.ts} +0 -0
- /package/src/{helpers → utils}/__tests__/memo.test.ts +0 -0
- /package/src/{helpers → utils}/__tests__/others.test.ts +0 -0
- /package/src/{helpers → utils}/__tests__/validators.test.ts +0 -0
- /package/src/{helpers → utils}/liquidity.ts +0 -0
- /package/src/{helpers → utils}/validators.ts +0 -0
|
@@ -1,27 +1,16 @@
|
|
|
1
1
|
import type { BrowserProvider } from "ethers";
|
|
2
2
|
import { SwapKitError } from "../modules/swapKitError";
|
|
3
3
|
import {
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
type AddChainType,
|
|
5
|
+
type Chain,
|
|
6
|
+
ChainToHexChainId,
|
|
6
7
|
type EIP6963AnnounceProviderEvent,
|
|
7
8
|
type EIP6963Provider,
|
|
9
|
+
type EthereumWindowProvider,
|
|
10
|
+
type NetworkParams,
|
|
8
11
|
WalletOption,
|
|
9
12
|
} from "../types";
|
|
10
|
-
|
|
11
|
-
export type EthereumWindowProvider = BrowserProvider & {
|
|
12
|
-
__XDEFI?: boolean;
|
|
13
|
-
isBraveWallet?: boolean;
|
|
14
|
-
isCoinbaseWallet?: boolean;
|
|
15
|
-
isMetaMask?: boolean;
|
|
16
|
-
isOkxWallet?: boolean;
|
|
17
|
-
isKeepKeyWallet?: boolean;
|
|
18
|
-
isTrust?: boolean;
|
|
19
|
-
isTalisman?: boolean;
|
|
20
|
-
on: (event: string, callback?: () => void) => void;
|
|
21
|
-
overrideIsMetaMask?: boolean;
|
|
22
|
-
request: <T = unknown>(args: { method: string; params?: unknown[] }) => Promise<T>;
|
|
23
|
-
selectedProvider?: EthereumWindowProvider;
|
|
24
|
-
};
|
|
13
|
+
import { warnOnce } from "./others";
|
|
25
14
|
|
|
26
15
|
declare const window: {
|
|
27
16
|
ethereum: EthereumWindowProvider;
|
|
@@ -32,54 +21,91 @@ declare const window: {
|
|
|
32
21
|
xfi?: { ethereum: EthereumWindowProvider };
|
|
33
22
|
} & Window;
|
|
34
23
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
nativeCurrency: {
|
|
39
|
-
name: string;
|
|
40
|
-
symbol: string;
|
|
41
|
-
decimals: number;
|
|
42
|
-
};
|
|
43
|
-
rpcUrls: string[];
|
|
44
|
-
blockExplorerUrls: string[];
|
|
45
|
-
};
|
|
24
|
+
export function isWeb3Detected() {
|
|
25
|
+
return typeof window.ethereum !== "undefined";
|
|
26
|
+
}
|
|
46
27
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
export
|
|
28
|
+
export function isDetected(walletOption: WalletOption) {
|
|
29
|
+
return listWeb3EVMWallets().includes(walletOption);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function listWeb3EVMWallets() {
|
|
33
|
+
const metamaskEnabled = window?.ethereum && !window.ethereum?.isBraveWallet;
|
|
34
|
+
// @ts-ignore that should be implemented in ctrl and hooked up via swapkit core
|
|
35
|
+
const ctrlEnabled = window?.xfi || window?.ethereum?.__XDEFI;
|
|
36
|
+
const braveEnabled = window?.ethereum?.isBraveWallet;
|
|
37
|
+
const trustEnabled = window?.ethereum?.isTrust || window?.trustwallet;
|
|
38
|
+
const coinbaseEnabled =
|
|
39
|
+
(window?.ethereum?.overrideIsMetaMask &&
|
|
40
|
+
window?.ethereum?.selectedProvider?.isCoinbaseWallet) ||
|
|
41
|
+
window?.coinbaseWalletExtension;
|
|
42
|
+
const bitgetEnabled = window?.bitkeep?.ethereum;
|
|
43
|
+
|
|
44
|
+
const wallets = [];
|
|
45
|
+
if (metamaskEnabled) wallets.push(WalletOption.METAMASK);
|
|
46
|
+
if (ctrlEnabled) wallets.push(WalletOption.CTRL);
|
|
47
|
+
if (braveEnabled) wallets.push(WalletOption.BRAVE);
|
|
48
|
+
if (trustEnabled) wallets.push(WalletOption.TRUSTWALLET_WEB);
|
|
49
|
+
if (coinbaseEnabled) wallets.push(WalletOption.COINBASE_WEB);
|
|
50
|
+
if (okxMobileEnabled()) wallets.push(WalletOption.OKX_MOBILE);
|
|
51
|
+
if (bitgetEnabled) wallets.push(WalletOption.BITGET);
|
|
52
|
+
|
|
53
|
+
return wallets;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export async function switchEVMWalletNetwork(
|
|
57
|
+
provider: BrowserProvider,
|
|
58
|
+
chain: Chain,
|
|
59
|
+
networkParams?: NetworkParams,
|
|
60
|
+
) {
|
|
61
|
+
try {
|
|
62
|
+
await providerRequest({
|
|
63
|
+
provider,
|
|
64
|
+
method: "wallet_switchEthereumChain",
|
|
65
|
+
params: [{ chainId: ChainToHexChainId[chain] }],
|
|
66
|
+
});
|
|
67
|
+
} catch (_error) {
|
|
68
|
+
if (!networkParams) {
|
|
69
|
+
throw new Error("Failed to switch network, networkParams not provided");
|
|
70
|
+
}
|
|
71
|
+
await addEVMWalletNetwork(provider, networkParams);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export function filterSupportedChains<T extends string[]>({
|
|
76
|
+
chains,
|
|
77
|
+
supportedChains,
|
|
78
|
+
walletType,
|
|
79
|
+
}: { chains: Chain[]; supportedChains: T; walletType?: WalletOption }) {
|
|
80
|
+
const supported = chains.filter((chain) => supportedChains.includes(chain));
|
|
81
|
+
|
|
82
|
+
if (supported.length === 0) {
|
|
83
|
+
throw new SwapKitError("wallet_chain_not_supported", {
|
|
84
|
+
wallet: walletType,
|
|
85
|
+
chain: chains.join(", "),
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const unsupported = chains.filter((chain) => !supportedChains.includes(chain));
|
|
90
|
+
|
|
91
|
+
warnOnce(
|
|
92
|
+
unsupported.length > 0,
|
|
93
|
+
`${walletType} wallet does not support the following chains: ${unsupported.join(
|
|
94
|
+
", ",
|
|
95
|
+
)}. These chains will be ignored.`,
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
return supported as T;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export function wrapMethodWithNetworkSwitch<T extends (...args: any[]) => any>(
|
|
76
102
|
func: T,
|
|
77
103
|
provider: BrowserProvider,
|
|
78
|
-
|
|
79
|
-
)
|
|
104
|
+
chain: Chain,
|
|
105
|
+
) {
|
|
80
106
|
(async (...args: any[]) => {
|
|
81
107
|
try {
|
|
82
|
-
await switchEVMWalletNetwork(provider,
|
|
108
|
+
await switchEVMWalletNetwork(provider, chain);
|
|
83
109
|
} catch (error) {
|
|
84
110
|
throw new SwapKitError({
|
|
85
111
|
errorKey: "helpers_failed_to_switch_network",
|
|
@@ -88,25 +114,31 @@ export const wrapMethodWithNetworkSwitch = <T extends (...args: any[]) => any>(
|
|
|
88
114
|
}
|
|
89
115
|
return func(...args);
|
|
90
116
|
}) as unknown as T;
|
|
117
|
+
}
|
|
91
118
|
|
|
92
|
-
|
|
93
|
-
if (!provider?.send) {
|
|
94
|
-
throw new SwapKitError("helpers_not_found_provider");
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
const providerParams = params ? (Array.isArray(params) ? params : [params]) : [];
|
|
98
|
-
return provider.send(method, providerParams);
|
|
99
|
-
};
|
|
100
|
-
|
|
101
|
-
export const prepareNetworkSwitch = <T extends { [key: string]: (...args: any[]) => any }>({
|
|
119
|
+
export function prepareNetworkSwitch<T extends { [key: string]: (...args: any[]) => any }>({
|
|
102
120
|
toolbox,
|
|
103
|
-
|
|
121
|
+
chain,
|
|
104
122
|
provider = window.ethereum,
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
123
|
+
methodNames = [],
|
|
124
|
+
}: { toolbox: T; chain: Chain; provider?: BrowserProvider; methodNames?: string[] }) {
|
|
125
|
+
const methodsToWrap = [
|
|
126
|
+
...methodNames,
|
|
127
|
+
"approve",
|
|
128
|
+
"approvedAmount",
|
|
129
|
+
"call",
|
|
130
|
+
"sendTransaction",
|
|
131
|
+
"transfer",
|
|
132
|
+
"isApproved",
|
|
133
|
+
"approvedAmount",
|
|
134
|
+
"EIP1193SendTransaction",
|
|
135
|
+
"getFeeData",
|
|
136
|
+
"broadcastTransaction",
|
|
137
|
+
"estimateCall",
|
|
138
|
+
"estimateGasLimit",
|
|
139
|
+
"estimateGasPrices",
|
|
140
|
+
"createContractTxObject",
|
|
141
|
+
];
|
|
110
142
|
const wrappedMethods = methodsToWrap.reduce((object, methodName) => {
|
|
111
143
|
if (!toolbox[methodName]) return object;
|
|
112
144
|
const method = toolbox[methodName];
|
|
@@ -116,37 +148,23 @@ export const prepareNetworkSwitch = <T extends { [key: string]: (...args: any[])
|
|
|
116
148
|
return {
|
|
117
149
|
// biome-ignore lint/performance/noAccumulatingSpread: This is a valid use case
|
|
118
150
|
...object,
|
|
119
|
-
[methodName]: wrapMethodWithNetworkSwitch<typeof method>(method, provider,
|
|
151
|
+
[methodName]: wrapMethodWithNetworkSwitch<typeof method>(method, provider, chain),
|
|
120
152
|
};
|
|
121
153
|
}, {});
|
|
122
154
|
|
|
123
155
|
return { ...toolbox, ...wrappedMethods };
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
export const addEVMWalletNetwork = (provider: BrowserProvider, networkParams: NetworkParams) =>
|
|
127
|
-
providerRequest({ provider, method: "wallet_addEthereumChain", params: [networkParams] });
|
|
156
|
+
}
|
|
128
157
|
|
|
129
|
-
export
|
|
130
|
-
provider:
|
|
131
|
-
|
|
132
|
-
networkParams?: NetworkParams,
|
|
133
|
-
) => {
|
|
134
|
-
try {
|
|
135
|
-
providerRequest({ provider, method: "wallet_switchEthereumChain", params: [{ chainId }] });
|
|
136
|
-
} catch (_error) {
|
|
137
|
-
if (!networkParams) {
|
|
138
|
-
throw new Error("Failed to switch network, networkParams not provided");
|
|
139
|
-
}
|
|
140
|
-
addEVMWalletNetwork(provider, networkParams);
|
|
141
|
-
}
|
|
142
|
-
};
|
|
158
|
+
export function addEVMWalletNetwork(provider: BrowserProvider, networkParams: NetworkParams) {
|
|
159
|
+
return providerRequest({ provider, method: "wallet_addEthereumChain", params: [networkParams] });
|
|
160
|
+
}
|
|
143
161
|
|
|
144
|
-
export
|
|
162
|
+
export function addAccountsChangedCallback(callback: () => void) {
|
|
145
163
|
window.ethereum?.on("accountsChanged", () => callback());
|
|
146
164
|
window.xfi?.ethereum.on("accountsChanged", () => callback());
|
|
147
|
-
}
|
|
165
|
+
}
|
|
148
166
|
|
|
149
|
-
export
|
|
167
|
+
export function getETHDefaultWallet() {
|
|
150
168
|
const { isTrust, isBraveWallet, __XDEFI, overrideIsMetaMask, selectedProvider } =
|
|
151
169
|
window?.ethereum || {};
|
|
152
170
|
if (isTrust) return WalletOption.TRUSTWALLET_WEB;
|
|
@@ -154,44 +172,6 @@ export const getETHDefaultWallet = () => {
|
|
|
154
172
|
if (overrideIsMetaMask && selectedProvider?.isCoinbaseWallet) return WalletOption.COINBASE_WEB;
|
|
155
173
|
if (__XDEFI) WalletOption.CTRL;
|
|
156
174
|
return WalletOption.METAMASK;
|
|
157
|
-
};
|
|
158
|
-
|
|
159
|
-
export const isDetected = (walletOption: WalletOption) => {
|
|
160
|
-
return listWeb3EVMWallets().includes(walletOption);
|
|
161
|
-
};
|
|
162
|
-
|
|
163
|
-
export const listWeb3EVMWallets = () => {
|
|
164
|
-
const metamaskEnabled = window?.ethereum && !window.ethereum?.isBraveWallet;
|
|
165
|
-
// @ts-ignore that should be implemented in ctrl and hooked up via swapkit core
|
|
166
|
-
const ctrlEnabled = window?.xfi || window?.ethereum?.__XDEFI;
|
|
167
|
-
const braveEnabled = window?.ethereum?.isBraveWallet;
|
|
168
|
-
const trustEnabled = window?.ethereum?.isTrust || window?.trustwallet;
|
|
169
|
-
const coinbaseEnabled =
|
|
170
|
-
(window?.ethereum?.overrideIsMetaMask &&
|
|
171
|
-
window?.ethereum?.selectedProvider?.isCoinbaseWallet) ||
|
|
172
|
-
window?.coinbaseWalletExtension;
|
|
173
|
-
const bitgetEnabled = window?.bitkeep?.ethereum;
|
|
174
|
-
|
|
175
|
-
const wallets = [];
|
|
176
|
-
if (metamaskEnabled) wallets.push(WalletOption.METAMASK);
|
|
177
|
-
if (ctrlEnabled) wallets.push(WalletOption.CTRL);
|
|
178
|
-
if (braveEnabled) wallets.push(WalletOption.BRAVE);
|
|
179
|
-
if (trustEnabled) wallets.push(WalletOption.TRUSTWALLET_WEB);
|
|
180
|
-
if (coinbaseEnabled) wallets.push(WalletOption.COINBASE_WEB);
|
|
181
|
-
if (okxMobileEnabled()) wallets.push(WalletOption.OKX_MOBILE);
|
|
182
|
-
if (bitgetEnabled) wallets.push(WalletOption.BITGET);
|
|
183
|
-
|
|
184
|
-
return wallets;
|
|
185
|
-
};
|
|
186
|
-
|
|
187
|
-
export function pickEvmApiKey({
|
|
188
|
-
chain,
|
|
189
|
-
nonEthApiKey,
|
|
190
|
-
ethApiKey,
|
|
191
|
-
}: { chain: Chain; nonEthApiKey?: string; ethApiKey?: string }) {
|
|
192
|
-
const apiKey = chain === Chain.Ethereum ? ethApiKey : nonEthApiKey;
|
|
193
|
-
|
|
194
|
-
return apiKey;
|
|
195
175
|
}
|
|
196
176
|
|
|
197
177
|
export function getEIP6963Wallets() {
|
|
@@ -212,7 +192,7 @@ export function getEIP6963Wallets() {
|
|
|
212
192
|
return { providers, removeEIP6963EventListener };
|
|
213
193
|
}
|
|
214
194
|
|
|
215
|
-
export
|
|
195
|
+
export function okxMobileEnabled() {
|
|
216
196
|
const ua = navigator.userAgent;
|
|
217
197
|
const isIOS = /iphone|ipad|ipod|ios/i.test(ua);
|
|
218
198
|
const isAndroid = /android|XiaoMi|MiuiBrowser/i.test(ua);
|
|
@@ -220,6 +200,62 @@ export const okxMobileEnabled = () => {
|
|
|
220
200
|
const isOKApp = /OKApp/i.test(ua);
|
|
221
201
|
|
|
222
202
|
return isMobile && isOKApp;
|
|
223
|
-
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export function createWallet<
|
|
206
|
+
ConnectParams extends any[],
|
|
207
|
+
SupportedChains extends Chain[],
|
|
208
|
+
const Name extends string,
|
|
209
|
+
WalletType extends WalletOption,
|
|
210
|
+
>({
|
|
211
|
+
connect,
|
|
212
|
+
name,
|
|
213
|
+
supportedChains,
|
|
214
|
+
walletType,
|
|
215
|
+
}: {
|
|
216
|
+
connect: (connectParams: {
|
|
217
|
+
addChain: AddChainType;
|
|
218
|
+
walletType: WalletType;
|
|
219
|
+
supportedChains: SupportedChains;
|
|
220
|
+
}) => (...params: ConnectParams) => Promise<boolean>;
|
|
221
|
+
name: Name;
|
|
222
|
+
supportedChains: SupportedChains;
|
|
223
|
+
walletType?: WalletType;
|
|
224
|
+
}) {
|
|
225
|
+
function connectWallet(connectParams: {
|
|
226
|
+
addChain: AddChainType;
|
|
227
|
+
}) {
|
|
228
|
+
return connect({ ...connectParams, walletType: walletType as WalletType, supportedChains });
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
return {
|
|
232
|
+
[name]: { supportedChains, connectWallet },
|
|
233
|
+
} as unknown as {
|
|
234
|
+
[key in Name]: {
|
|
235
|
+
connectWallet: typeof connectWallet;
|
|
236
|
+
supportedChains: SupportedChains;
|
|
237
|
+
};
|
|
238
|
+
};
|
|
239
|
+
}
|
|
224
240
|
|
|
225
|
-
|
|
241
|
+
function providerRequest({
|
|
242
|
+
provider,
|
|
243
|
+
params,
|
|
244
|
+
method,
|
|
245
|
+
}: {
|
|
246
|
+
provider?: BrowserProvider;
|
|
247
|
+
params?: any;
|
|
248
|
+
method:
|
|
249
|
+
| "wallet_addEthereumChain"
|
|
250
|
+
| "wallet_switchEthereumChain"
|
|
251
|
+
| "eth_requestAccounts"
|
|
252
|
+
| "eth_sendTransaction"
|
|
253
|
+
| "eth_signTransaction";
|
|
254
|
+
}) {
|
|
255
|
+
if (!provider?.send) {
|
|
256
|
+
throw new SwapKitError("helpers_not_found_provider");
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
const providerParams = params ? (Array.isArray(params) ? params : [params]) : [];
|
|
260
|
+
return provider.send(method, providerParams);
|
|
261
|
+
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type { Chain } from "../types/chains";
|
|
2
|
-
import type { WalletOption } from "../types/wallet";
|
|
3
|
-
import { SwapKitError } from "./swapKitError";
|
|
4
|
-
|
|
5
|
-
export function filterSupportedChains<T extends Chain>(
|
|
6
|
-
chains: Chain[],
|
|
7
|
-
supportedChains: readonly T[],
|
|
8
|
-
walletOption: WalletOption,
|
|
9
|
-
) {
|
|
10
|
-
const supported = chains.filter((chain): chain is T => supportedChains.includes(chain as T));
|
|
11
|
-
|
|
12
|
-
if (supported.length === 0) {
|
|
13
|
-
throw new SwapKitError("wallet_chain_not_supported", {
|
|
14
|
-
wallet: walletOption,
|
|
15
|
-
chain: chains.join(", "),
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const unsupported = chains.filter((chain) => !supportedChains.includes(chain as T));
|
|
20
|
-
|
|
21
|
-
if (unsupported.length > 0) {
|
|
22
|
-
console.warn(
|
|
23
|
-
`${walletOption} wallet does not support the following chains: ${unsupported.join(
|
|
24
|
-
", ",
|
|
25
|
-
)}. These chains will be ignored.`,
|
|
26
|
-
);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return supported;
|
|
30
|
-
}
|
package/src/types/network.ts
DELETED
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
/** @deprecated Use getRPCUrl or RPC_URLS instead */
|
|
2
|
-
export enum RPCUrl {
|
|
3
|
-
Arbitrum = "https://arb1.arbitrum.io/rpc",
|
|
4
|
-
Avalanche = "https://avalanche-c-chain-rpc.publicnode.com",
|
|
5
|
-
Base = "https://base.llamarpc.com",
|
|
6
|
-
BinanceSmartChain = "https://bsc-dataseed.binance.org",
|
|
7
|
-
Bitcoin = "https://bitcoin-rpc.publicnode.com",
|
|
8
|
-
BitcoinCash = "https://node-router.thorswap.net/bitcoin-cash",
|
|
9
|
-
Chainflip = "wss://mainnet-archive.chainflip.io",
|
|
10
|
-
Cosmos = "https://node-router.thorswap.net/cosmos/rpc",
|
|
11
|
-
Dash = "https://dash-rpc.publicnode.com",
|
|
12
|
-
Dogecoin = "https://node-router.thorswap.net/dogecoin",
|
|
13
|
-
Ethereum = "https://ethereum-rpc.publicnode.com",
|
|
14
|
-
Kujira = "https://rpc-kujira.synergynodes.com/",
|
|
15
|
-
Litecoin = "https://node-router.thorswap.net/litecoin",
|
|
16
|
-
Maya = "https://tendermint.mayachain.info",
|
|
17
|
-
MayaStagenet = "https://stagenet.tendermint.mayachain.info",
|
|
18
|
-
Optimism = "https://mainnet.optimism.io",
|
|
19
|
-
Polkadot = "wss://rpc.polkadot.io",
|
|
20
|
-
Polygon = "https://polygon-rpc.com",
|
|
21
|
-
Radix = "https://radix-mainnet.rpc.grove.city/v1/326002fc/core",
|
|
22
|
-
THORChain = "https://rpc.thorswap.net",
|
|
23
|
-
THORChainStagenet = "https://stagenet-rpc.ninerealms.com",
|
|
24
|
-
Solana = "https://solana-rpc.publicnode.com",
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/** @deprecated Use EXPLORER_URLS instead */
|
|
28
|
-
export enum ExplorerUrl {
|
|
29
|
-
Arbitrum = "https://arbiscan.io",
|
|
30
|
-
Avalanche = "https://snowtrace.io",
|
|
31
|
-
Base = "https://basescan.org",
|
|
32
|
-
BinanceSmartChain = "https://bscscan.com",
|
|
33
|
-
Bitcoin = "https://blockchair.com/bitcoin",
|
|
34
|
-
BitcoinCash = "https://www.blockchair.com/bitcoin-cash",
|
|
35
|
-
Chainflip = "https://explorer.polkascan.io/polkadot",
|
|
36
|
-
Cosmos = "https://www.mintscan.io/cosmos",
|
|
37
|
-
Dash = "https://blockchair.com/dash",
|
|
38
|
-
Dogecoin = "https://blockchair.com/dogecoin",
|
|
39
|
-
Ethereum = "https://etherscan.io",
|
|
40
|
-
Kujira = "https://finder.kujira.network/kaiyo-1",
|
|
41
|
-
Litecoin = "https://blockchair.com/litecoin",
|
|
42
|
-
Maya = "https://www.mayascan.org",
|
|
43
|
-
Optimism = "https://optimistic.etherscan.io",
|
|
44
|
-
Polkadot = "https://polkadot.subscan.io",
|
|
45
|
-
Polygon = "https://polygonscan.com",
|
|
46
|
-
Radix = "https://dashboard.radixdlt.com",
|
|
47
|
-
THORChain = "https://runescan.io",
|
|
48
|
-
Solana = "https://solscan.io",
|
|
49
|
-
}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|