@0xsquid/react-hooks 1.0.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/.babelrc +7 -0
- package/.eslintignore +1 -0
- package/.eslintrc.json +44 -0
- package/dist/index.js +6 -0
- package/jest.config.ts +28 -0
- package/package.json +124 -0
- package/scripts/copyAssets.js +27 -0
- package/scripts/removeBuildTestFolder.js +28 -0
- package/scripts/replacePaths.js +37 -0
- package/src/assets/images/icons/wallets/binance.svg +4 -0
- package/src/assets/images/icons/wallets/bitget.svg +43 -0
- package/src/assets/images/icons/wallets/bitkeep.svg +9 -0
- package/src/assets/images/icons/wallets/blockchaindotcom.svg +11 -0
- package/src/assets/images/icons/wallets/brave.svg +18 -0
- package/src/assets/images/icons/wallets/c98.svg +3 -0
- package/src/assets/images/icons/wallets/coinbase.svg +5 -0
- package/src/assets/images/icons/wallets/cosmostation.svg +9 -0
- package/src/assets/images/icons/wallets/defiConnect.svg +25 -0
- package/src/assets/images/icons/wallets/exodus.svg +33 -0
- package/src/assets/images/icons/wallets/fetchai.svg +1 -0
- package/src/assets/images/icons/wallets/index.ts +43 -0
- package/src/assets/images/icons/wallets/keplr.svg +9 -0
- package/src/assets/images/icons/wallets/leap.svg +35 -0
- package/src/assets/images/icons/wallets/metamask.svg +48 -0
- package/src/assets/images/icons/wallets/okx.svg +1 -0
- package/src/assets/images/icons/wallets/rabby.svg +1 -0
- package/src/assets/images/icons/wallets/trustwallet.svg +11 -0
- package/src/assets/images/icons/wallets/walletConnect.svg +11 -0
- package/src/assets/images/icons/wallets/wallet_icon.svg +1 -0
- package/src/assets/images/icons/wallets/xdefi.svg +9 -0
- package/src/assets/images/icons/wallets/zerion.svg +11 -0
- package/src/connectors/ExodusConnector.ts +6 -0
- package/src/connectors/LedgerLiveConnector.ts +226 -0
- package/src/contracts/typechain/ERC20.d.ts +441 -0
- package/src/contracts/typechain/factories/ERC20__factory.d.ts +56 -0
- package/src/contracts/typechain/factories/ERC20__factory.ts +340 -0
- package/src/core/constants.ts +549 -0
- package/src/core/externalLinks.ts +26 -0
- package/src/core/index.ts +1 -0
- package/src/core/multicall3.ts +22 -0
- package/src/core/numbers.ts +44 -0
- package/src/core/providers/CosmosProvider.tsx +55 -0
- package/src/core/queries/queries-keys.ts +156 -0
- package/src/core/queries/react-query-config.ts +13 -0
- package/src/core/types/components.ts +16 -0
- package/src/core/types/config.ts +52 -0
- package/src/core/types/dex.ts +31 -0
- package/src/core/types/error.ts +52 -0
- package/src/core/types/event.ts +16 -0
- package/src/core/types/route.ts +21 -0
- package/src/core/types/swap.ts +8 -0
- package/src/core/types/tokens.ts +30 -0
- package/src/core/types/transaction.ts +84 -0
- package/src/core/types/types.ts +37 -0
- package/src/core/types/wallet.ts +83 -0
- package/src/hooks/chains/useSquidChains.ts +66 -0
- package/src/hooks/cosmos/useCosmos.ts +279 -0
- package/src/hooks/cosmos/useCosmosForChain.ts +33 -0
- package/src/hooks/index.ts +32 -0
- package/src/hooks/navigation/useKeyboardNavigation.ts +88 -0
- package/src/hooks/store/useSquidStore.ts +80 -0
- package/src/hooks/swap/useSwap.ts +359 -0
- package/src/hooks/tokens/useAllTokensWithBalance.ts +157 -0
- package/src/hooks/tokens/useBalance.ts +180 -0
- package/src/hooks/tokens/useMultiChainBalance.ts +59 -0
- package/src/hooks/tokens/usePrices.ts +52 -0
- package/src/hooks/tokens/useSingleTokenPrice.ts +45 -0
- package/src/hooks/tokens/useSquidTokens.ts +48 -0
- package/src/hooks/tokens/useTokensWithBalance.ts +169 -0
- package/src/hooks/transaction/useEstimate.ts +397 -0
- package/src/hooks/transaction/useEstimatePriceImpact.ts +39 -0
- package/src/hooks/transaction/useExecuteTransaction.ts +440 -0
- package/src/hooks/transaction/useExpress.ts +46 -0
- package/src/hooks/transaction/useGetRoute.ts +145 -0
- package/src/hooks/transaction/useSingleTransaction.ts +155 -0
- package/src/hooks/transaction/useTransaction.ts +734 -0
- package/src/hooks/user/useUserParams.ts +63 -0
- package/src/hooks/wallet/useAddToken.ts +53 -0
- package/src/hooks/wallet/useAutoConnect.ts +56 -0
- package/src/hooks/wallet/useGnosisContext.ts +84 -0
- package/src/hooks/wallet/useIntegratorContext.ts +44 -0
- package/src/hooks/wallet/useMultiChainWallet.ts +146 -0
- package/src/hooks/wallet/useWallet.ts +86 -0
- package/src/hooks/webapp-router/useSquidRouter.ts +42 -0
- package/src/index.ts +5 -0
- package/src/provider/index.tsx +105 -0
- package/src/react-app-env.d.ts +2 -0
- package/src/services/external/analyticsService.ts +46 -0
- package/src/services/external/coingeckoService.ts +35 -0
- package/src/services/external/rpcService.ts +196 -0
- package/src/services/external/secretService.ts +178 -0
- package/src/services/index.ts +1 -0
- package/src/services/internal/apiService.ts +6 -0
- package/src/services/internal/assetsService.ts +84 -0
- package/src/services/internal/configService.ts +261 -0
- package/src/services/internal/errorService.ts +124 -0
- package/src/services/internal/eventService.ts +93 -0
- package/src/services/internal/priceService.ts +10 -0
- package/src/services/internal/transactionService.ts +255 -0
- package/src/services/internal/transactionStatusService.ts +293 -0
- package/src/services/internal/walletService.ts +158 -0
- package/src/tests/assetsService.test.ts +176 -0
- package/src/tests/configService.test.ts +486 -0
- package/src/tests/fetchSquidData.ts +43 -0
- package/src/tests/jest-svg-transform.ts +19 -0
- package/src/tests/sample.json +0 -0
- package/src/tests/walletService.test.ts +178 -0
- package/tsconfig.json +30 -0
|
@@ -0,0 +1,549 @@
|
|
|
1
|
+
import { ChainType } from "@0xsquid/sdk/dist/types";
|
|
2
|
+
import { CoinbaseWalletConnector } from "@wagmi/connectors/coinbaseWallet";
|
|
3
|
+
import { InjectedConnector } from "@wagmi/connectors/injected";
|
|
4
|
+
import { MetaMaskConnector } from "@wagmi/connectors/metaMask";
|
|
5
|
+
import { WalletConnectConnector } from "@wagmi/connectors/walletConnect";
|
|
6
|
+
import { SquidConfigState } from "@/hooks/store/useSquidStore";
|
|
7
|
+
import { walletIcons } from "@/assets/images/icons/wallets";
|
|
8
|
+
import { ExodusConnector } from "@/connectors/ExodusConnector";
|
|
9
|
+
import { squidApiBaseUrl } from "./externalLinks";
|
|
10
|
+
import type { SlippageOption } from "./types/config";
|
|
11
|
+
import type { ConnectorID, TypedWindow, Wallet } from "./types/wallet";
|
|
12
|
+
import { WindowWalletFlag } from "./types/wallet";
|
|
13
|
+
|
|
14
|
+
export const nativeEvmTokenAddress =
|
|
15
|
+
"0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee";
|
|
16
|
+
export const maxPriceImpact = 30;
|
|
17
|
+
export const limitTradeSizeUsd = 10000000;
|
|
18
|
+
export const defaultSlippage: SlippageOption = 1.5;
|
|
19
|
+
export const chainIdResetValue = -1;
|
|
20
|
+
export const destinationAddressResetValue = "null";
|
|
21
|
+
export const widgetHeight = 684;
|
|
22
|
+
export const widgetWidth = 440;
|
|
23
|
+
export const gasRefundMultiplier = 25;
|
|
24
|
+
export const transparentClass = "tw-bg-opacity-80";
|
|
25
|
+
export const subTransparentClass = "tw-bg-opacity-50";
|
|
26
|
+
export const backendVersion = "v2";
|
|
27
|
+
|
|
28
|
+
// We need that because it's the chain id where the fallback address will be
|
|
29
|
+
// Fallback address is used if a cosmos swap fails, funds will end up on the fallback address
|
|
30
|
+
export const osmosisChainId = {
|
|
31
|
+
mainnet: "osmosis-1",
|
|
32
|
+
testnet: "osmo-test-5",
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export const widgetHeaderSize = {
|
|
36
|
+
height: 60,
|
|
37
|
+
paddingY: 16,
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
export const defaultValues: SquidConfigState = {
|
|
41
|
+
config: {
|
|
42
|
+
integratorId: "squid-swap-widget-v2",
|
|
43
|
+
companyName: "Squid",
|
|
44
|
+
slippage: defaultSlippage,
|
|
45
|
+
infiniteApproval: false,
|
|
46
|
+
enableExpress: true,
|
|
47
|
+
apiUrl: squidApiBaseUrl,
|
|
48
|
+
comingSoonChainIds: [],
|
|
49
|
+
onChainQuoting: false,
|
|
50
|
+
priceImpactWarnings: {
|
|
51
|
+
warning: 3,
|
|
52
|
+
critical: 5,
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export enum PriorityConnectors {
|
|
58
|
+
Safe = "safe",
|
|
59
|
+
LedgerLive = "ledgerLive",
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
export const wallets: Wallet[] = [
|
|
63
|
+
{
|
|
64
|
+
name: "Trust Wallet",
|
|
65
|
+
type: ChainType.EVM,
|
|
66
|
+
connectorId: "trustwallet",
|
|
67
|
+
connectorName: "Trust Wallet",
|
|
68
|
+
windowFlag: WindowWalletFlag.TrustWallet,
|
|
69
|
+
connector: (chains) =>
|
|
70
|
+
new InjectedConnector({
|
|
71
|
+
chains,
|
|
72
|
+
options: {
|
|
73
|
+
name: "Trust Wallet",
|
|
74
|
+
shimDisconnect: true,
|
|
75
|
+
getProvider: () =>
|
|
76
|
+
typeof window !== "undefined" &&
|
|
77
|
+
(window as TypedWindow)?.trustwallet &&
|
|
78
|
+
(window as TypedWindow)?.trustwallet
|
|
79
|
+
? (window as TypedWindow)?.trustwallet
|
|
80
|
+
: undefined,
|
|
81
|
+
},
|
|
82
|
+
}),
|
|
83
|
+
icon: walletIcons.trustwallet,
|
|
84
|
+
canSwitchWallets: false,
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
name: "Metamask",
|
|
88
|
+
type: ChainType.EVM,
|
|
89
|
+
connectorId: "metaMask",
|
|
90
|
+
connectorName: "MetaMask",
|
|
91
|
+
connector: (chains) => new MetaMaskConnector({ chains }),
|
|
92
|
+
icon: walletIcons.metamask,
|
|
93
|
+
windowFlag: WindowWalletFlag.MetaMask,
|
|
94
|
+
canSwitchWallets: true,
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
name: "Coinbase Wallet",
|
|
98
|
+
type: ChainType.EVM,
|
|
99
|
+
connectorId: "coinbaseWallet",
|
|
100
|
+
connectorName: "Coinbase Wallet",
|
|
101
|
+
windowFlag: WindowWalletFlag.Coinbase,
|
|
102
|
+
connector: (chains) =>
|
|
103
|
+
new CoinbaseWalletConnector({
|
|
104
|
+
chains,
|
|
105
|
+
options: { appName: "Coinbase" },
|
|
106
|
+
}),
|
|
107
|
+
icon: walletIcons.coinbase,
|
|
108
|
+
canSwitchWallets: false,
|
|
109
|
+
},
|
|
110
|
+
|
|
111
|
+
{
|
|
112
|
+
name: "XDEFI Wallet",
|
|
113
|
+
type: ChainType.EVM,
|
|
114
|
+
connectorId: "xdefi",
|
|
115
|
+
connectorName: "XDefi",
|
|
116
|
+
windowFlag: WindowWalletFlag.Xdefi,
|
|
117
|
+
connector: (chains) =>
|
|
118
|
+
new InjectedConnector({
|
|
119
|
+
chains,
|
|
120
|
+
options: {
|
|
121
|
+
name: "XDefi",
|
|
122
|
+
shimDisconnect: true,
|
|
123
|
+
getProvider: () =>
|
|
124
|
+
typeof window !== "undefined" &&
|
|
125
|
+
(window as TypedWindow)?.xfi &&
|
|
126
|
+
(window as TypedWindow)?.xfi.ethereum
|
|
127
|
+
? (window as TypedWindow)?.xfi.ethereum
|
|
128
|
+
: undefined,
|
|
129
|
+
},
|
|
130
|
+
}),
|
|
131
|
+
icon: walletIcons.xdefi,
|
|
132
|
+
canSwitchWallets: false,
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
name: "Rabby",
|
|
136
|
+
type: ChainType.EVM,
|
|
137
|
+
connectorId: "rabby",
|
|
138
|
+
connectorName: "Rabby",
|
|
139
|
+
windowFlag: WindowWalletFlag.Rabby,
|
|
140
|
+
connector: (chains) =>
|
|
141
|
+
new InjectedConnector({
|
|
142
|
+
chains,
|
|
143
|
+
options: {
|
|
144
|
+
name: "Rabby",
|
|
145
|
+
shimDisconnect: true,
|
|
146
|
+
getProvider: () =>
|
|
147
|
+
typeof window !== "undefined" &&
|
|
148
|
+
(window as TypedWindow)?.ethereum &&
|
|
149
|
+
((window as any)?.ethereum.isRabby as any)
|
|
150
|
+
? ((window as TypedWindow)?.ethereum as any)
|
|
151
|
+
: undefined,
|
|
152
|
+
},
|
|
153
|
+
}),
|
|
154
|
+
icon: walletIcons.rabby,
|
|
155
|
+
canSwitchWallets: false,
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
name: "Injected",
|
|
159
|
+
type: ChainType.EVM,
|
|
160
|
+
connectorId: "injected",
|
|
161
|
+
connectorName: "Injected",
|
|
162
|
+
windowFlag: WindowWalletFlag.Injected,
|
|
163
|
+
connector: (chains) =>
|
|
164
|
+
new InjectedConnector({
|
|
165
|
+
chains,
|
|
166
|
+
}),
|
|
167
|
+
icon: walletIcons.injected,
|
|
168
|
+
canSwitchWallets: false,
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
name: "Zerion",
|
|
172
|
+
type: ChainType.EVM,
|
|
173
|
+
connectorId: "zerion",
|
|
174
|
+
connectorName: "Zerion",
|
|
175
|
+
windowFlag: WindowWalletFlag.Zerion,
|
|
176
|
+
connector: (chains) =>
|
|
177
|
+
new InjectedConnector({
|
|
178
|
+
chains,
|
|
179
|
+
options: {
|
|
180
|
+
name: "Zerion",
|
|
181
|
+
shimDisconnect: true,
|
|
182
|
+
getProvider: () =>
|
|
183
|
+
typeof window !== "undefined" &&
|
|
184
|
+
(window as TypedWindow)?.ethereum &&
|
|
185
|
+
((window as any)?.ethereum?.isZerion as any)
|
|
186
|
+
? ((window as any)?.zerionWallet as any)
|
|
187
|
+
: undefined,
|
|
188
|
+
},
|
|
189
|
+
}),
|
|
190
|
+
icon: walletIcons.zerion,
|
|
191
|
+
canSwitchWallets: false,
|
|
192
|
+
},
|
|
193
|
+
{
|
|
194
|
+
name: "WalletConnect",
|
|
195
|
+
type: ChainType.EVM,
|
|
196
|
+
connectorId: "walletConnect",
|
|
197
|
+
connectorName: "WalletConnect",
|
|
198
|
+
windowFlag: WindowWalletFlag.WalletConnect,
|
|
199
|
+
connector: (chains) =>
|
|
200
|
+
new WalletConnectConnector({
|
|
201
|
+
chains,
|
|
202
|
+
options: {
|
|
203
|
+
showQrModal: true,
|
|
204
|
+
projectId: "db6a4f6ff58e4172b2fd52f01360bc49",
|
|
205
|
+
},
|
|
206
|
+
}),
|
|
207
|
+
icon: walletIcons.walletConnect,
|
|
208
|
+
canSwitchWallets: false,
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
name: "Blockchain.com",
|
|
212
|
+
type: ChainType.EVM,
|
|
213
|
+
connectorId: "blockchaindotcom",
|
|
214
|
+
connectorName: "Blockchain.com",
|
|
215
|
+
windowFlag: WindowWalletFlag.BlockchainDotCom,
|
|
216
|
+
connector: (chains) =>
|
|
217
|
+
new WalletConnectConnector({
|
|
218
|
+
chains,
|
|
219
|
+
options: {
|
|
220
|
+
showQrModal: true,
|
|
221
|
+
projectId: "db6a4f6ff58e4172b2fd52f01360bc49",
|
|
222
|
+
},
|
|
223
|
+
}),
|
|
224
|
+
icon: walletIcons.blockchainDotCom,
|
|
225
|
+
canSwitchWallets: false,
|
|
226
|
+
},
|
|
227
|
+
{
|
|
228
|
+
name: "Cosmostation",
|
|
229
|
+
type: ChainType.EVM,
|
|
230
|
+
connectorId: "cosmostation",
|
|
231
|
+
connectorName: "Cosmostation",
|
|
232
|
+
windowFlag: WindowWalletFlag.CosmostationEVM,
|
|
233
|
+
connector: (chains) =>
|
|
234
|
+
new InjectedConnector({
|
|
235
|
+
chains,
|
|
236
|
+
options: {
|
|
237
|
+
name: "Cosmostation",
|
|
238
|
+
getProvider: () =>
|
|
239
|
+
typeof window !== "undefined" &&
|
|
240
|
+
(window as TypedWindow)?.cosmostation
|
|
241
|
+
? (window as TypedWindow)?.cosmostation.ethereum
|
|
242
|
+
: undefined,
|
|
243
|
+
},
|
|
244
|
+
}),
|
|
245
|
+
icon: walletIcons.cosmostation,
|
|
246
|
+
canSwitchWallets: false,
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
name: "BitGet Wallet",
|
|
250
|
+
type: ChainType.EVM,
|
|
251
|
+
connectorId: "bitget",
|
|
252
|
+
connectorName: "BitGet Wallet",
|
|
253
|
+
windowFlag: WindowWalletFlag.BitGet,
|
|
254
|
+
connector: (chains) =>
|
|
255
|
+
new InjectedConnector({
|
|
256
|
+
chains,
|
|
257
|
+
options: {
|
|
258
|
+
name: "BitGet Wallet",
|
|
259
|
+
shimDisconnect: true,
|
|
260
|
+
getProvider: () =>
|
|
261
|
+
typeof window !== "undefined" &&
|
|
262
|
+
(window as TypedWindow)?.bitkeep &&
|
|
263
|
+
(window as TypedWindow)?.bitkeep.ethereum
|
|
264
|
+
? (window as TypedWindow)?.bitkeep.ethereum
|
|
265
|
+
: undefined,
|
|
266
|
+
},
|
|
267
|
+
}),
|
|
268
|
+
icon: walletIcons.bitget,
|
|
269
|
+
canSwitchWallets: false,
|
|
270
|
+
},
|
|
271
|
+
{
|
|
272
|
+
name: "OKX Wallet",
|
|
273
|
+
type: ChainType.EVM,
|
|
274
|
+
connectorId: "okx",
|
|
275
|
+
connectorName: "okx",
|
|
276
|
+
windowFlag: WindowWalletFlag.OKX,
|
|
277
|
+
connector: (chains) =>
|
|
278
|
+
new InjectedConnector({
|
|
279
|
+
chains,
|
|
280
|
+
options: {
|
|
281
|
+
name: "OKX",
|
|
282
|
+
shimDisconnect: true,
|
|
283
|
+
getProvider: () =>
|
|
284
|
+
typeof window !== "undefined" &&
|
|
285
|
+
(window as TypedWindow)?.ethereum &&
|
|
286
|
+
(window as TypedWindow)?.okxwallet
|
|
287
|
+
? (window as TypedWindow)?.okxwallet
|
|
288
|
+
: undefined,
|
|
289
|
+
},
|
|
290
|
+
}),
|
|
291
|
+
icon: walletIcons.okx,
|
|
292
|
+
canSwitchWallets: false,
|
|
293
|
+
},
|
|
294
|
+
{
|
|
295
|
+
name: "Coin98",
|
|
296
|
+
type: ChainType.EVM,
|
|
297
|
+
connectorId: "coin98",
|
|
298
|
+
connectorName: "Coin98",
|
|
299
|
+
windowFlag: WindowWalletFlag.Coin98,
|
|
300
|
+
connector: (chains) =>
|
|
301
|
+
new InjectedConnector({
|
|
302
|
+
chains,
|
|
303
|
+
options: {
|
|
304
|
+
name: "Coin98",
|
|
305
|
+
shimDisconnect: true,
|
|
306
|
+
getProvider: () =>
|
|
307
|
+
typeof window !== "undefined" && (window as TypedWindow)?.coin98
|
|
308
|
+
? (window as TypedWindow)?.coin98.provider
|
|
309
|
+
: undefined,
|
|
310
|
+
},
|
|
311
|
+
}),
|
|
312
|
+
icon: walletIcons.coin98,
|
|
313
|
+
canSwitchWallets: false,
|
|
314
|
+
},
|
|
315
|
+
{
|
|
316
|
+
name: "Defi Connect",
|
|
317
|
+
type: ChainType.EVM,
|
|
318
|
+
connectorId: "deficonnect",
|
|
319
|
+
connectorName: "Defi Connect",
|
|
320
|
+
windowFlag: WindowWalletFlag.DefiConnect,
|
|
321
|
+
connector: (chains) =>
|
|
322
|
+
new InjectedConnector({
|
|
323
|
+
chains,
|
|
324
|
+
options: {
|
|
325
|
+
name: "Defi Connect",
|
|
326
|
+
shimDisconnect: true,
|
|
327
|
+
getProvider: () =>
|
|
328
|
+
typeof window !== "undefined" &&
|
|
329
|
+
(window as TypedWindow)?.deficonnectProvider
|
|
330
|
+
? (window as TypedWindow)?.deficonnectProvider
|
|
331
|
+
: undefined,
|
|
332
|
+
},
|
|
333
|
+
}),
|
|
334
|
+
icon: walletIcons.defiConnect,
|
|
335
|
+
canSwitchWallets: false,
|
|
336
|
+
},
|
|
337
|
+
{
|
|
338
|
+
name: "Keplr",
|
|
339
|
+
type: ChainType.COSMOS,
|
|
340
|
+
windowFlag: WindowWalletFlag.Keplr,
|
|
341
|
+
icon: walletIcons.keplr,
|
|
342
|
+
canSwitchWallets: false,
|
|
343
|
+
connectorId: "keplr",
|
|
344
|
+
connectorName: "Keplr",
|
|
345
|
+
},
|
|
346
|
+
{
|
|
347
|
+
name: "XDEFI Wallet",
|
|
348
|
+
type: ChainType.COSMOS,
|
|
349
|
+
connectorId: "xdeficosmos",
|
|
350
|
+
connectorName: "XDefi",
|
|
351
|
+
windowFlag: WindowWalletFlag.XdefiCosmos,
|
|
352
|
+
icon: walletIcons.xdefi,
|
|
353
|
+
canSwitchWallets: false,
|
|
354
|
+
},
|
|
355
|
+
{
|
|
356
|
+
name: "Leap",
|
|
357
|
+
type: ChainType.COSMOS,
|
|
358
|
+
windowFlag: WindowWalletFlag.Leap,
|
|
359
|
+
icon: walletIcons.leap,
|
|
360
|
+
canSwitchWallets: false,
|
|
361
|
+
connectorId: "leap",
|
|
362
|
+
connectorName: "Leap",
|
|
363
|
+
},
|
|
364
|
+
{
|
|
365
|
+
name: "Cosmostation",
|
|
366
|
+
type: ChainType.COSMOS,
|
|
367
|
+
connectorId: "cosmostationCosmos",
|
|
368
|
+
connectorName: "Cosmostation Cosmos",
|
|
369
|
+
windowFlag: WindowWalletFlag.CosmostationCosmos,
|
|
370
|
+
connector: (chains) =>
|
|
371
|
+
new InjectedConnector({
|
|
372
|
+
chains,
|
|
373
|
+
options: {
|
|
374
|
+
name: "Cosmostation",
|
|
375
|
+
getProvider: () =>
|
|
376
|
+
typeof window !== "undefined" &&
|
|
377
|
+
(window as TypedWindow)?.cosmostation
|
|
378
|
+
? (window as TypedWindow)?.cosmostation.ethereum
|
|
379
|
+
: undefined,
|
|
380
|
+
},
|
|
381
|
+
}),
|
|
382
|
+
icon: walletIcons.cosmostation,
|
|
383
|
+
canSwitchWallets: false,
|
|
384
|
+
},
|
|
385
|
+
{
|
|
386
|
+
name: "Fetch.ai",
|
|
387
|
+
type: ChainType.COSMOS,
|
|
388
|
+
connectorId: "fetchai",
|
|
389
|
+
connectorName: "Fetch.ai",
|
|
390
|
+
windowFlag: WindowWalletFlag.FetchAi,
|
|
391
|
+
icon: walletIcons.fetchai,
|
|
392
|
+
canSwitchWallets: false,
|
|
393
|
+
},
|
|
394
|
+
{
|
|
395
|
+
name: "Cosmos Extension",
|
|
396
|
+
type: ChainType.COSMOS,
|
|
397
|
+
connectorId: "snapper",
|
|
398
|
+
connectorName: "Cosmos Extension",
|
|
399
|
+
windowFlag: WindowWalletFlag.Snapper,
|
|
400
|
+
icon: walletIcons.metamask,
|
|
401
|
+
canSwitchWallets: false,
|
|
402
|
+
},
|
|
403
|
+
{
|
|
404
|
+
name: "Exodus",
|
|
405
|
+
type: ChainType.EVM,
|
|
406
|
+
connectorId: "exodus",
|
|
407
|
+
connectorName: "Exodus",
|
|
408
|
+
windowFlag: WindowWalletFlag.Exodus,
|
|
409
|
+
connector: (chains) =>
|
|
410
|
+
new ExodusConnector({
|
|
411
|
+
chains,
|
|
412
|
+
options: {
|
|
413
|
+
name: "Exodus",
|
|
414
|
+
shimDisconnect: true,
|
|
415
|
+
getProvider: () =>
|
|
416
|
+
typeof window !== "undefined" &&
|
|
417
|
+
(window as TypedWindow).exodus?.ethereum &&
|
|
418
|
+
((window as any).exodus.ethereum.isExodus as any)
|
|
419
|
+
? ((window as TypedWindow).exodus.ethereum as any)
|
|
420
|
+
: undefined,
|
|
421
|
+
},
|
|
422
|
+
}),
|
|
423
|
+
icon: walletIcons.exodus,
|
|
424
|
+
canSwitchWallets: false,
|
|
425
|
+
},
|
|
426
|
+
];
|
|
427
|
+
|
|
428
|
+
export const axelarSuccessStatuses = [
|
|
429
|
+
"destination_executed",
|
|
430
|
+
"executed",
|
|
431
|
+
"express_executed",
|
|
432
|
+
];
|
|
433
|
+
|
|
434
|
+
export const axelarEndStatuses = [
|
|
435
|
+
...axelarSuccessStatuses,
|
|
436
|
+
"error_fetching_status",
|
|
437
|
+
"error",
|
|
438
|
+
];
|
|
439
|
+
|
|
440
|
+
export const walletStoreLinks: {
|
|
441
|
+
[key in ConnectorID]: {
|
|
442
|
+
chrome: string;
|
|
443
|
+
firefox: string;
|
|
444
|
+
};
|
|
445
|
+
} = {
|
|
446
|
+
leap: {
|
|
447
|
+
chrome:
|
|
448
|
+
"https://chrome.google.com/webstore/detail/leap-cosmos-wallet/fcfcfllfndlomdhbehjjcoimbgofdncg",
|
|
449
|
+
firefox: "",
|
|
450
|
+
},
|
|
451
|
+
keplr: {
|
|
452
|
+
chrome:
|
|
453
|
+
"https://chrome.google.com/webstore/detail/keplr/dmkamcknogkgcdfhhbddcghachkejeap",
|
|
454
|
+
firefox:
|
|
455
|
+
"https://addons.mozilla.org/en-US/firefox/addon/keplr/?utm_source=addons.mozilla.org&utm_medium=referral&utm_content=search",
|
|
456
|
+
},
|
|
457
|
+
metaMask: {
|
|
458
|
+
chrome:
|
|
459
|
+
"https://chrome.google.com/webstore/detail/metamask/nkbihfbeogaeaoehlefnkodbefgpgknn",
|
|
460
|
+
firefox:
|
|
461
|
+
"https://addons.mozilla.org/en-US/firefox/addon/ether-metamask/?utm_source=addons.mozilla.org&utm_medium=referral&utm_content=search",
|
|
462
|
+
},
|
|
463
|
+
walletConnect: {
|
|
464
|
+
chrome: "",
|
|
465
|
+
firefox: "",
|
|
466
|
+
},
|
|
467
|
+
blockchaindotcom: {
|
|
468
|
+
chrome: "",
|
|
469
|
+
firefox: "",
|
|
470
|
+
},
|
|
471
|
+
coinbaseWallet: {
|
|
472
|
+
chrome:
|
|
473
|
+
"https://chrome.google.com/webstore/detail/coinbase-wallet-extension/hnfanknocfeofbddgcijnmhnfnkdnaad",
|
|
474
|
+
firefox: "",
|
|
475
|
+
},
|
|
476
|
+
cosmostation: {
|
|
477
|
+
chrome:
|
|
478
|
+
"https://chrome.google.com/webstore/detail/cosmostation-wallet/fpkhgmpbidmiogeglndfbkegfdlnajnf",
|
|
479
|
+
firefox: "",
|
|
480
|
+
},
|
|
481
|
+
cosmostationCosmos: {
|
|
482
|
+
chrome:
|
|
483
|
+
"https://chrome.google.com/webstore/detail/cosmostation-wallet/fpkhgmpbidmiogeglndfbkegfdlnajnf",
|
|
484
|
+
firefox: "",
|
|
485
|
+
},
|
|
486
|
+
xdefi: {
|
|
487
|
+
chrome:
|
|
488
|
+
"https://chrome.google.com/webstore/detail/xdefi-wallet/hmeobnfnfcmdkdcmlblgagmfpfboieaf",
|
|
489
|
+
firefox: "",
|
|
490
|
+
},
|
|
491
|
+
xdeficosmos: {
|
|
492
|
+
chrome:
|
|
493
|
+
"https://chrome.google.com/webstore/detail/xdefi-wallet/hmeobnfnfcmdkdcmlblgagmfpfboieaf",
|
|
494
|
+
firefox: "",
|
|
495
|
+
},
|
|
496
|
+
bitget: {
|
|
497
|
+
chrome:
|
|
498
|
+
"https://chrome.google.com/webstore/detail/bitget-wallet-formerly-bi/jiidiaalihmmhddjgbnbgdfflelocpak",
|
|
499
|
+
firefox: "",
|
|
500
|
+
},
|
|
501
|
+
trustwallet: {
|
|
502
|
+
chrome:
|
|
503
|
+
"https://chrome.google.com/webstore/detail/trust-wallet/egjidjbpglichdcondbcbdnbeeppgdph",
|
|
504
|
+
firefox: "",
|
|
505
|
+
},
|
|
506
|
+
fetchai: {
|
|
507
|
+
chrome:
|
|
508
|
+
"https://chrome.google.com/webstore/detail/fetch-wallet/ellkdbaphhldpeajbepobaecooaoafpg",
|
|
509
|
+
firefox: "",
|
|
510
|
+
},
|
|
511
|
+
coin98: {
|
|
512
|
+
chrome:
|
|
513
|
+
"https://chrome.google.com/webstore/detail/coin98-wallet/aeachknmefphepccionboohckonoeemg",
|
|
514
|
+
firefox: "",
|
|
515
|
+
},
|
|
516
|
+
rabby: {
|
|
517
|
+
chrome:
|
|
518
|
+
"https://chrome.google.com/webstore/detail/rabby-wallet/acmacodkjbdgmoleebolmdjonilkdbch",
|
|
519
|
+
firefox: "",
|
|
520
|
+
},
|
|
521
|
+
okx: {
|
|
522
|
+
chrome:
|
|
523
|
+
"https://chrome.google.com/webstore/detail/okx-wallet/mcohilncbfahbmgdjkbpemcciiolgcge",
|
|
524
|
+
firefox: "",
|
|
525
|
+
},
|
|
526
|
+
injected: {
|
|
527
|
+
chrome: "",
|
|
528
|
+
firefox: "",
|
|
529
|
+
},
|
|
530
|
+
zerion: {
|
|
531
|
+
chrome:
|
|
532
|
+
"https://chrome.google.com/webstore/detail/zerion-wallet-for-web3-nf/klghhnkeealcohjjanjjdaeeggmfmlpl",
|
|
533
|
+
firefox: "",
|
|
534
|
+
},
|
|
535
|
+
deficonnect: {
|
|
536
|
+
chrome:
|
|
537
|
+
"https://chrome.google.com/webstore/detail/cryptocom-wallet-extensio/hifafgmccdpekplomjjkcfgodnhcellj",
|
|
538
|
+
firefox: "",
|
|
539
|
+
},
|
|
540
|
+
snapper: {
|
|
541
|
+
chrome: "https://metamask.mysticlabs.xyz/",
|
|
542
|
+
firefox: "",
|
|
543
|
+
},
|
|
544
|
+
exodus: {
|
|
545
|
+
chrome:
|
|
546
|
+
"https://chromewebstore.google.com/detail/exodus-web3-wallet/aholpfdialjgjfhomihkjbmgjidlcdno",
|
|
547
|
+
firefox: "",
|
|
548
|
+
},
|
|
549
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// Squid Links
|
|
2
|
+
export const squidMainLink = "https://www.squidrouter.com/";
|
|
3
|
+
export const squidDocLink = "https://docs.widget.squidrouter.com/";
|
|
4
|
+
export const squidApiBaseUrl = "https://v2.api.squidrouter.com";
|
|
5
|
+
export const squidDiscordLink = "https://discord.gg/squidrouter";
|
|
6
|
+
export const squidSupportLink = "https://support.squidrouter.com";
|
|
7
|
+
|
|
8
|
+
export const squidHelpLink = `${squidDocLink}troubleshooting#additional-support`;
|
|
9
|
+
export const squidInfiniteApprovalLink = `${squidDocLink}settings#infinite-approval`;
|
|
10
|
+
export const squidSlippageToleranceLink = `${squidDocLink}settings#slippage-tolerance`;
|
|
11
|
+
export const squidAxlUSDCWarningLink = `${squidDocLink}troubleshooting#you-received-axlusdc-unexpectedly`;
|
|
12
|
+
export const squidTrackingDataUnavailableLink = `${squidDocLink}troubleshooting#tracking-data-unavailable`;
|
|
13
|
+
export const squidGasFeesRefundLink = `${squidDocLink}gas-fees#gas-refunds`;
|
|
14
|
+
|
|
15
|
+
// Axelar Links
|
|
16
|
+
export const axelarTokenDataUrl =
|
|
17
|
+
"https://axelar-mainnet.s3.us-east-2.amazonaws.com/mainnet-config.json";
|
|
18
|
+
export const axelarMainLink = "https://axelar.network/";
|
|
19
|
+
export const axelarPoweredByLink =
|
|
20
|
+
"https://axelar.network/?utm_source=dynamic&utm_medium=referral&utm_campaign=squidrouter-widget";
|
|
21
|
+
|
|
22
|
+
// Other links
|
|
23
|
+
export const defaultFiatOnRamp = {
|
|
24
|
+
name: "Kado",
|
|
25
|
+
link: "https://app.kado.money?apiKey=4dcd0735-f55e-4063-a862-734158decbfe",
|
|
26
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { wallets } from "./constants";
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export const multicallAddress = "0xcA11bde05977b3631167028862bE2a173976CA11";
|
|
2
|
+
export const multicallAbi = [
|
|
3
|
+
{
|
|
4
|
+
inputs: [
|
|
5
|
+
{
|
|
6
|
+
internalType: "address",
|
|
7
|
+
name: "account",
|
|
8
|
+
type: "address",
|
|
9
|
+
},
|
|
10
|
+
],
|
|
11
|
+
name: "getEthBalance",
|
|
12
|
+
outputs: [
|
|
13
|
+
{
|
|
14
|
+
internalType: "uint256",
|
|
15
|
+
name: "",
|
|
16
|
+
type: "uint256",
|
|
17
|
+
},
|
|
18
|
+
],
|
|
19
|
+
stateMutability: "view",
|
|
20
|
+
type: "function",
|
|
21
|
+
},
|
|
22
|
+
];
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/* eslint-disable prefer-const */
|
|
2
|
+
import type { BigNumberish } from "ethers";
|
|
3
|
+
import { ethers } from "ethers";
|
|
4
|
+
import take from "lodash/take";
|
|
5
|
+
import takeWhile from "lodash/takeWhile";
|
|
6
|
+
|
|
7
|
+
export const roundNumericValue = (
|
|
8
|
+
value: string = "0",
|
|
9
|
+
precision: number = 2,
|
|
10
|
+
useComaEvery3Digits = true,
|
|
11
|
+
significantFigures: number = 0
|
|
12
|
+
): string => {
|
|
13
|
+
let newValue = value;
|
|
14
|
+
|
|
15
|
+
const temp = newValue?.toString() ?? "";
|
|
16
|
+
let [integers, decimals] = temp.split(".");
|
|
17
|
+
|
|
18
|
+
// toLocaleString is supported on all modern browsers
|
|
19
|
+
// We might monitor and have a polyfill if some people are not
|
|
20
|
+
// Seeing the comas.
|
|
21
|
+
if (useComaEvery3Digits && integers !== "0") {
|
|
22
|
+
integers = parseInt(integers, 10).toLocaleString("en-US").toString();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (significantFigures && decimals) {
|
|
26
|
+
const zeros = takeWhile(decimals?.toString(), (c) => c === "0").length;
|
|
27
|
+
return `${integers}.${take(decimals, zeros + significantFigures).join("")}`;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return decimals
|
|
31
|
+
? `${integers}.${take(decimals, precision).join("")}`
|
|
32
|
+
: integers;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export function formatUnitsRounded(
|
|
36
|
+
value: BigNumberish,
|
|
37
|
+
decimals?: string | BigNumberish,
|
|
38
|
+
maxDecimalDigits?: number
|
|
39
|
+
) {
|
|
40
|
+
const dc = decimals ?? "0";
|
|
41
|
+
return ethers.FixedNumber.from(ethers.utils.formatUnits(value, dc))
|
|
42
|
+
.round(maxDecimalDigits ?? ethers.BigNumber.from(dc).toNumber())
|
|
43
|
+
.toString();
|
|
44
|
+
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { Wallet } from "@/core/types/wallet";
|
|
2
|
+
import { useCosmos } from "@/hooks/cosmos/useCosmos";
|
|
3
|
+
import type { ChainData } from "@0xsquid/sdk/dist/types";
|
|
4
|
+
import type { OfflineSigner } from "@cosmjs/proto-signing";
|
|
5
|
+
import type { Keplr } from "@keplr-wallet/types";
|
|
6
|
+
import type { UseMutationResult } from "@tanstack/react-query";
|
|
7
|
+
import type { ReactNode } from "react";
|
|
8
|
+
import React from "react";
|
|
9
|
+
|
|
10
|
+
interface ICosmsosContextData {
|
|
11
|
+
connectCosmos?: UseMutationResult<
|
|
12
|
+
void,
|
|
13
|
+
unknown,
|
|
14
|
+
{ chain: ChainData; wallet?: Wallet; direction?: "from" | "to" },
|
|
15
|
+
unknown
|
|
16
|
+
>;
|
|
17
|
+
|
|
18
|
+
cosmosConnectedWallet?: Wallet;
|
|
19
|
+
keplrTypeWallet?: Keplr;
|
|
20
|
+
cosmosChainId?: string;
|
|
21
|
+
setCosmosChainId?: React.Dispatch<React.SetStateAction<string | undefined>>;
|
|
22
|
+
isConnected?: boolean;
|
|
23
|
+
onCosmosChainChange?: (chainId: string) => void;
|
|
24
|
+
isInstalled?: boolean;
|
|
25
|
+
cosmosSigner?: OfflineSigner;
|
|
26
|
+
cosmosAddress?: string;
|
|
27
|
+
getCosmosWalletInfos?: UseMutationResult<
|
|
28
|
+
string | undefined,
|
|
29
|
+
unknown,
|
|
30
|
+
{
|
|
31
|
+
chainId: string;
|
|
32
|
+
cosmosWalletObject?: Keplr | undefined;
|
|
33
|
+
},
|
|
34
|
+
unknown
|
|
35
|
+
>;
|
|
36
|
+
getCosmosAddressForChain: (chainId?: string) => Promise<string | undefined>;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export const CosmosContext = React.createContext<ICosmsosContextData>({
|
|
40
|
+
getCosmosAddressForChain: async () => "",
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
export const CosmosProvider: React.FC<{
|
|
44
|
+
children?: ReactNode;
|
|
45
|
+
}> = ({ children }) => {
|
|
46
|
+
return (
|
|
47
|
+
<CosmosContext.Provider value={useCosmos()}>
|
|
48
|
+
{children}
|
|
49
|
+
</CosmosContext.Provider>
|
|
50
|
+
);
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export function useCosmosContext() {
|
|
54
|
+
return React.useContext(CosmosContext);
|
|
55
|
+
}
|