@xswap-link/sdk 0.3.5 → 0.4.1

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 (199) hide show
  1. package/.eslintrc.json +9 -5
  2. package/CHANGELOG.md +16 -0
  3. package/README.md +2 -1
  4. package/dist/index.d.mts +106 -20
  5. package/dist/index.d.ts +106 -20
  6. package/dist/index.global.js +856 -307
  7. package/dist/index.global.js.map +1 -0
  8. package/dist/index.js +105 -3564
  9. package/dist/index.js.map +1 -0
  10. package/dist/index.mjs +105 -3534
  11. package/dist/index.mjs.map +1 -0
  12. package/nodemon.json +1 -1
  13. package/package.json +16 -9
  14. package/postcss.config.js +8 -1
  15. package/src/{components → assets}/icons/ArrowDownIcon.tsx +1 -2
  16. package/src/assets/icons/ArrowDownLongIcon.tsx +12 -0
  17. package/src/{components → assets}/icons/ArrowLeftIcon.tsx +1 -5
  18. package/src/{components → assets}/icons/ArrowRightIcon.tsx +1 -5
  19. package/src/assets/icons/ArrowUpIcon.tsx +12 -0
  20. package/src/{components → assets}/icons/ArrowUpRightIcon.tsx +1 -5
  21. package/src/assets/icons/CashbacklIcon.tsx +28 -0
  22. package/src/{components → assets}/icons/CheckIcon.tsx +1 -5
  23. package/src/assets/icons/ChevronDownIcon.tsx +12 -0
  24. package/src/assets/icons/ChevronUpIcon.tsx +7 -0
  25. package/src/{components → assets}/icons/CircularProgressIcon.tsx +1 -2
  26. package/src/assets/icons/CloseIcon.tsx +15 -0
  27. package/src/{components → assets}/icons/CoinsIcon.tsx +0 -2
  28. package/src/assets/icons/CopyIcon.tsx +15 -0
  29. package/src/assets/icons/DotGreenIcon.tsx +12 -0
  30. package/src/{components → assets}/icons/DownArrorIcon.tsx +0 -2
  31. package/src/{components → assets}/icons/ErrorIcon.tsx +0 -1
  32. package/src/assets/icons/ErrorModalStatusIcon.tsx +31 -0
  33. package/src/assets/icons/HelpIcon.tsx +21 -0
  34. package/src/assets/icons/HistoryGradientBgIcon.tsx +32 -0
  35. package/src/assets/icons/HistoryIcon.tsx +12 -0
  36. package/src/{components → assets}/icons/HourGlassIcon.tsx +1 -5
  37. package/src/assets/icons/Icon.tsx +5 -0
  38. package/src/{components → assets}/icons/InfoIcon.tsx +0 -1
  39. package/src/assets/icons/LinkExternalIcon.tsx +15 -0
  40. package/src/{components → assets}/icons/PercentageIcon.tsx +0 -1
  41. package/src/assets/icons/RankIcon.tsx +28 -0
  42. package/src/assets/icons/SettingsGradientBgIcon.tsx +32 -0
  43. package/src/assets/icons/SettingsIcon.tsx +12 -0
  44. package/src/{components → assets}/icons/SignIcon.tsx +0 -2
  45. package/src/{components → assets}/icons/SuccessIcon.tsx +0 -1
  46. package/src/assets/icons/SuccessModalStatusIcon.tsx +31 -0
  47. package/src/assets/icons/ThumbUpRoundedIcon.tsx +15 -0
  48. package/src/{components → assets}/icons/TimerIcon.tsx +0 -1
  49. package/src/assets/icons/TokensIcon.tsx +16 -0
  50. package/src/assets/icons/WaitingIcon.tsx +15 -0
  51. package/src/{components → assets}/icons/XMarkIcon.tsx +1 -5
  52. package/src/assets/icons/XPowerIcon.tsx +28 -0
  53. package/src/{components → assets}/icons/index.ts +16 -0
  54. package/src/components/Alert/index.tsx +1 -1
  55. package/src/components/Button/index.tsx +57 -0
  56. package/src/components/MessageBar/SnackMessage.tsx +32 -0
  57. package/src/components/MessageBar/index.tsx +44 -0
  58. package/src/components/Modal/index.tsx +52 -0
  59. package/src/components/PoweredBy/index.tsx +12 -0
  60. package/src/components/SafeInput/index.tsx +51 -0
  61. package/src/components/Skeleton/index.tsx +5 -9
  62. package/src/components/Spinner/index.tsx +6 -8
  63. package/src/components/Swap/Header/Controls/index.tsx +57 -0
  64. package/src/components/Swap/Header/index.tsx +16 -0
  65. package/src/components/Swap/HistoryView/index.tsx +34 -0
  66. package/src/components/Swap/SettingsView/Delivery/index.tsx +42 -0
  67. package/src/components/Swap/SettingsView/Slippage/index.tsx +80 -0
  68. package/src/components/Swap/SettingsView/index.tsx +11 -0
  69. package/src/components/Swap/SwapView/ConfirmationView/TxOverview/ArrowIcon.tsx +13 -0
  70. package/src/components/Swap/SwapView/ConfirmationView/TxOverview/Header/index.tsx +37 -0
  71. package/src/components/Swap/SwapView/ConfirmationView/TxOverview/Steps/index.tsx +145 -0
  72. package/src/components/Swap/SwapView/ConfirmationView/TxOverview/SwapPanel/index.tsx +61 -0
  73. package/src/components/Swap/SwapView/ConfirmationView/TxOverview/index.tsx +291 -0
  74. package/src/components/Swap/SwapView/ConfirmationView/TxResult/TokenItem/index.tsx +24 -0
  75. package/src/components/Swap/SwapView/ConfirmationView/TxResult/index.tsx +84 -0
  76. package/src/components/Swap/SwapView/ConfirmationView/index.tsx +17 -0
  77. package/src/components/Swap/SwapView/FeesPanel/DeliveryInfo/index.tsx +25 -0
  78. package/src/components/Swap/SwapView/FeesPanel/Fee/index.tsx +18 -0
  79. package/src/components/Swap/SwapView/FeesPanel/Fees/index.tsx +71 -0
  80. package/src/components/Swap/SwapView/FeesPanel/index.tsx +67 -0
  81. package/src/components/Swap/SwapView/SwapButton/index.tsx +154 -0
  82. package/src/components/Swap/SwapView/SwapPanel/AmountPanel/Balance/index.tsx +23 -0
  83. package/src/components/Swap/SwapView/SwapPanel/AmountPanel/index.tsx +56 -0
  84. package/src/components/Swap/SwapView/SwapPanel/ChainPanel/ChainPicker/ChainItem/index.tsx +70 -0
  85. package/src/components/Swap/SwapView/SwapPanel/ChainPanel/ChainPicker/index.tsx +62 -0
  86. package/src/components/Swap/SwapView/SwapPanel/ChainPanel/index.tsx +74 -0
  87. package/src/components/Swap/SwapView/SwapPanel/MaxPanel/index.tsx +35 -0
  88. package/src/components/Swap/SwapView/SwapPanel/TokenPanel/TokenPicker/QuickPickTokenItem/index.tsx +40 -0
  89. package/src/components/Swap/SwapView/SwapPanel/TokenPanel/TokenPicker/TokenItem/index.tsx +62 -0
  90. package/src/components/Swap/SwapView/SwapPanel/TokenPanel/TokenPicker/index.tsx +399 -0
  91. package/src/components/Swap/SwapView/SwapPanel/TokenPanel/index.tsx +104 -0
  92. package/src/components/Swap/SwapView/SwapPanel/index.tsx +42 -0
  93. package/src/components/Swap/SwapView/index.tsx +20 -0
  94. package/src/components/Swap/index.tsx +34 -0
  95. package/src/components/TextInput/index.tsx +67 -0
  96. package/src/components/Timer/index.tsx +57 -0
  97. package/src/components/ToggleButton/index.tsx +24 -0
  98. package/src/components/{UnknownTokenLogo/UnknownTokenLogo.tsx → TokenLogo/Unknown/index.tsx} +3 -4
  99. package/src/components/TokenLogo/WithChain/index.tsx +34 -0
  100. package/src/components/TokenLogo/index.tsx +22 -0
  101. package/src/components/Tooltip/index.tsx +108 -0
  102. package/src/components/TxConfigForm/index.tsx +63 -42
  103. package/src/components/TxDataCard/TokenDetails/index.tsx +30 -0
  104. package/src/components/TxDataCard/TxDataCardUI/index.tsx +133 -0
  105. package/src/components/TxDataCard/index.tsx +30 -0
  106. package/src/components/TxStatusButton/index.tsx +64 -108
  107. package/src/components/global.css +115 -4
  108. package/src/components/index.ts +18 -1
  109. package/src/config/fonts.ts +114 -0
  110. package/src/config/global.d.ts +4 -0
  111. package/src/config/init.tsx +35 -31
  112. package/src/constants/crosschainEstimationTimes.ts +52 -0
  113. package/src/constants/index.ts +8 -0
  114. package/src/context/GlobalDataProvider.tsx +165 -0
  115. package/src/context/HistoryProvider.tsx +339 -0
  116. package/src/context/ModalProvider.tsx +47 -0
  117. package/src/context/SwapProvider.tsx +664 -0
  118. package/src/context/TransactionProvider.tsx +86 -0
  119. package/src/context/TxUIWrapper.tsx +388 -0
  120. package/src/context/index.ts +5 -0
  121. package/src/contracts/abi/CustomXSwapRouter.json +953 -0
  122. package/src/contracts/abi/StakingStableAPR.json +1438 -0
  123. package/src/contracts/abi/XSwapRouter.json +1242 -0
  124. package/src/contracts/abi/XSwapTokenFeeDistributor.json +350 -0
  125. package/src/contracts/abi/index.ts +8 -0
  126. package/src/contracts/addresses.ts +24 -6
  127. package/src/fonts/Satoshi-Black.woff2 +0 -0
  128. package/src/fonts/Satoshi-BlackItalic.woff2 +0 -0
  129. package/src/fonts/Satoshi-Bold.woff2 +0 -0
  130. package/src/fonts/Satoshi-BoldItalic.woff2 +0 -0
  131. package/src/fonts/Satoshi-Light.woff2 +0 -0
  132. package/src/fonts/Satoshi-LightItalic.woff2 +0 -0
  133. package/src/fonts/Satoshi-Medium.woff2 +0 -0
  134. package/src/fonts/Satoshi-MediumItalic.woff2 +0 -0
  135. package/src/fonts/Satoshi-Regular.woff2 +0 -0
  136. package/src/fonts/Satoshi-RegularItalic.woff2 +0 -0
  137. package/src/fonts/Satoshi-Variable.woff2 +0 -0
  138. package/src/fonts/Satoshi-VariableItalic.woff2 +0 -0
  139. package/src/hooks/index.ts +5 -0
  140. package/src/hooks/networkManagement/clientToSigner.tsx +17 -0
  141. package/src/hooks/networkManagement/useNetworks.ts +51 -0
  142. package/src/hooks/useBatchQuery.ts +46 -0
  143. package/src/hooks/useDebounce.tsx +28 -0
  144. package/src/hooks/useEvmContractApi.ts +85 -0
  145. package/src/hooks/usePortal.ts +79 -0
  146. package/src/hooks/useXPower.ts +58 -0
  147. package/src/models/Addresses.ts +8 -2
  148. package/src/models/TokenData.ts +13 -0
  149. package/src/models/TransactionHistory.ts +2 -0
  150. package/src/models/TxUIWrapper.ts +51 -0
  151. package/src/models/XSwapConfig.ts +1 -0
  152. package/src/models/index.ts +1 -0
  153. package/src/models/payloads/GetBalancesPayload.ts +3 -0
  154. package/src/models/payloads/GetFinishedLeaderboardQuestsPayload.ts +3 -0
  155. package/src/models/payloads/GetLeaderboardChangePayload.ts +4 -0
  156. package/src/models/payloads/{GetSwapTxPayload.ts → ModalIntegrationPayload.ts} +3 -1
  157. package/src/models/payloads/index.ts +5 -2
  158. package/src/services/api.ts +34 -5
  159. package/src/services/integrations/monitoring.ts +49 -37
  160. package/src/services/integrations/transactions.ts +50 -6
  161. package/src/utils/contracts.ts +29 -0
  162. package/src/utils/index.ts +3 -3
  163. package/src/utils/numbers.ts +14 -0
  164. package/src/utils/parseWeb3Error.ts +7 -3
  165. package/tailwind.config.js +15 -5
  166. package/tsconfig.json +7 -7
  167. package/tsup.config.ts +62 -0
  168. package/xswap.config.ts +1 -0
  169. package/dist/index.css +0 -1
  170. package/src/components/TxConfigForm/BalanceComponent.tsx +0 -52
  171. package/src/components/TxConfigForm/Button.tsx +0 -20
  172. package/src/components/TxConfigForm/ChainListElement.tsx +0 -36
  173. package/src/components/TxConfigForm/ConfirmationAmount.tsx +0 -91
  174. package/src/components/TxConfigForm/ConfirmationView/ErrorView.tsx +0 -38
  175. package/src/components/TxConfigForm/ConfirmationView/SuccessView.tsx +0 -159
  176. package/src/components/TxConfigForm/ConfirmationView/index.tsx +0 -149
  177. package/src/components/TxConfigForm/ConnectWalletPrompt.tsx +0 -21
  178. package/src/components/TxConfigForm/Description.tsx +0 -17
  179. package/src/components/TxConfigForm/ErrorField.tsx +0 -19
  180. package/src/components/TxConfigForm/FeesDetails.tsx +0 -117
  181. package/src/components/TxConfigForm/Form.tsx +0 -574
  182. package/src/components/TxConfigForm/History.tsx +0 -131
  183. package/src/components/TxConfigForm/HistoryCard.tsx +0 -182
  184. package/src/components/TxConfigForm/PoweredBy.tsx +0 -12
  185. package/src/components/TxConfigForm/Settings.tsx +0 -143
  186. package/src/components/TxConfigForm/Summary.tsx +0 -105
  187. package/src/components/TxConfigForm/SwapPanel.tsx +0 -185
  188. package/src/components/TxConfigForm/TokenPicker.tsx +0 -176
  189. package/src/components/TxConfigForm/TopBar.tsx +0 -58
  190. package/src/components/TxConfigForm/UsdPrice.tsx +0 -44
  191. package/src/components/icons/ChevronDownIcon.tsx +0 -15
  192. package/src/components/icons/ChevronUpIcon.tsx +0 -10
  193. package/src/components/icons/CloseIcon.tsx +0 -15
  194. package/src/components/icons/HistoryIcon.tsx +0 -16
  195. package/src/components/icons/SettingsIcon.tsx +0 -16
  196. /package/src/{components → assets}/icons/ChainlinkCCIPIcon.tsx +0 -0
  197. /package/src/{components → assets}/icons/SearchIcon.tsx +0 -0
  198. /package/src/{components → assets}/icons/XSwapBadgeIcon.tsx +0 -0
  199. /package/src/{components → assets}/icons/XSwapLogo.tsx +0 -0
@@ -0,0 +1,350 @@
1
+ [
2
+ {
3
+ "inputs": [],
4
+ "stateMutability": "nonpayable",
5
+ "type": "constructor"
6
+ },
7
+ {
8
+ "inputs": [],
9
+ "name": "FailedToSendNative",
10
+ "type": "error"
11
+ },
12
+ {
13
+ "inputs": [],
14
+ "name": "ZeroAddressProvided",
15
+ "type": "error"
16
+ },
17
+ {
18
+ "anonymous": false,
19
+ "inputs": [
20
+ {
21
+ "indexed": false,
22
+ "internalType": "address",
23
+ "name": "previousAdmin",
24
+ "type": "address"
25
+ },
26
+ {
27
+ "indexed": false,
28
+ "internalType": "address",
29
+ "name": "newAdmin",
30
+ "type": "address"
31
+ }
32
+ ],
33
+ "name": "AdminChanged",
34
+ "type": "event"
35
+ },
36
+ {
37
+ "anonymous": false,
38
+ "inputs": [
39
+ {
40
+ "indexed": true,
41
+ "internalType": "address",
42
+ "name": "beacon",
43
+ "type": "address"
44
+ }
45
+ ],
46
+ "name": "BeaconUpgraded",
47
+ "type": "event"
48
+ },
49
+ {
50
+ "anonymous": false,
51
+ "inputs": [
52
+ {
53
+ "indexed": false,
54
+ "internalType": "uint8",
55
+ "name": "version",
56
+ "type": "uint8"
57
+ }
58
+ ],
59
+ "name": "Initialized",
60
+ "type": "event"
61
+ },
62
+ {
63
+ "anonymous": false,
64
+ "inputs": [
65
+ {
66
+ "indexed": true,
67
+ "internalType": "address",
68
+ "name": "previousOwner",
69
+ "type": "address"
70
+ },
71
+ {
72
+ "indexed": true,
73
+ "internalType": "address",
74
+ "name": "newOwner",
75
+ "type": "address"
76
+ }
77
+ ],
78
+ "name": "OwnershipTransferStarted",
79
+ "type": "event"
80
+ },
81
+ {
82
+ "anonymous": false,
83
+ "inputs": [
84
+ {
85
+ "indexed": true,
86
+ "internalType": "address",
87
+ "name": "previousOwner",
88
+ "type": "address"
89
+ },
90
+ {
91
+ "indexed": true,
92
+ "internalType": "address",
93
+ "name": "newOwner",
94
+ "type": "address"
95
+ }
96
+ ],
97
+ "name": "OwnershipTransferred",
98
+ "type": "event"
99
+ },
100
+ {
101
+ "anonymous": false,
102
+ "inputs": [
103
+ {
104
+ "indexed": false,
105
+ "internalType": "address",
106
+ "name": "newFeeCollector",
107
+ "type": "address"
108
+ }
109
+ ],
110
+ "name": "SetFeeCollector",
111
+ "type": "event"
112
+ },
113
+ {
114
+ "anonymous": false,
115
+ "inputs": [
116
+ {
117
+ "indexed": false,
118
+ "internalType": "address",
119
+ "name": "token",
120
+ "type": "address"
121
+ },
122
+ {
123
+ "indexed": false,
124
+ "internalType": "address",
125
+ "name": "reciever",
126
+ "type": "address"
127
+ },
128
+ {
129
+ "indexed": false,
130
+ "internalType": "uint256",
131
+ "name": "amount",
132
+ "type": "uint256"
133
+ },
134
+ {
135
+ "indexed": false,
136
+ "internalType": "address",
137
+ "name": "feeCollector",
138
+ "type": "address"
139
+ },
140
+ {
141
+ "indexed": false,
142
+ "internalType": "uint256",
143
+ "name": "remainingAmount",
144
+ "type": "uint256"
145
+ }
146
+ ],
147
+ "name": "TokensDistributed",
148
+ "type": "event"
149
+ },
150
+ {
151
+ "anonymous": false,
152
+ "inputs": [
153
+ {
154
+ "indexed": true,
155
+ "internalType": "address",
156
+ "name": "implementation",
157
+ "type": "address"
158
+ }
159
+ ],
160
+ "name": "Upgraded",
161
+ "type": "event"
162
+ },
163
+ {
164
+ "inputs": [],
165
+ "name": "acceptOwnership",
166
+ "outputs": [],
167
+ "stateMutability": "nonpayable",
168
+ "type": "function"
169
+ },
170
+ {
171
+ "inputs": [
172
+ {
173
+ "internalType": "address",
174
+ "name": "token",
175
+ "type": "address"
176
+ },
177
+ {
178
+ "internalType": "address",
179
+ "name": "reciever",
180
+ "type": "address"
181
+ },
182
+ {
183
+ "internalType": "uint256",
184
+ "name": "originalAmount",
185
+ "type": "uint256"
186
+ },
187
+ {
188
+ "internalType": "uint256",
189
+ "name": "percentage",
190
+ "type": "uint256"
191
+ },
192
+ {
193
+ "internalType": "uint256",
194
+ "name": "maxAmount",
195
+ "type": "uint256"
196
+ }
197
+ ],
198
+ "name": "distributeTokensFee",
199
+ "outputs": [],
200
+ "stateMutability": "nonpayable",
201
+ "type": "function"
202
+ },
203
+ {
204
+ "inputs": [],
205
+ "name": "feeCollector",
206
+ "outputs": [
207
+ {
208
+ "internalType": "contract IFeeCollector",
209
+ "name": "",
210
+ "type": "address"
211
+ }
212
+ ],
213
+ "stateMutability": "view",
214
+ "type": "function"
215
+ },
216
+ {
217
+ "inputs": [
218
+ {
219
+ "internalType": "address",
220
+ "name": "_feeCollector",
221
+ "type": "address"
222
+ },
223
+ {
224
+ "internalType": "address",
225
+ "name": "owner",
226
+ "type": "address"
227
+ }
228
+ ],
229
+ "name": "initialize",
230
+ "outputs": [],
231
+ "stateMutability": "nonpayable",
232
+ "type": "function"
233
+ },
234
+ {
235
+ "inputs": [],
236
+ "name": "owner",
237
+ "outputs": [
238
+ {
239
+ "internalType": "address",
240
+ "name": "",
241
+ "type": "address"
242
+ }
243
+ ],
244
+ "stateMutability": "view",
245
+ "type": "function"
246
+ },
247
+ {
248
+ "inputs": [],
249
+ "name": "pendingOwner",
250
+ "outputs": [
251
+ {
252
+ "internalType": "address",
253
+ "name": "",
254
+ "type": "address"
255
+ }
256
+ ],
257
+ "stateMutability": "view",
258
+ "type": "function"
259
+ },
260
+ {
261
+ "inputs": [],
262
+ "name": "precision",
263
+ "outputs": [
264
+ {
265
+ "internalType": "uint256",
266
+ "name": "",
267
+ "type": "uint256"
268
+ }
269
+ ],
270
+ "stateMutability": "view",
271
+ "type": "function"
272
+ },
273
+ {
274
+ "inputs": [],
275
+ "name": "proxiableUUID",
276
+ "outputs": [
277
+ {
278
+ "internalType": "bytes32",
279
+ "name": "",
280
+ "type": "bytes32"
281
+ }
282
+ ],
283
+ "stateMutability": "view",
284
+ "type": "function"
285
+ },
286
+ {
287
+ "inputs": [],
288
+ "name": "renounceOwnership",
289
+ "outputs": [],
290
+ "stateMutability": "nonpayable",
291
+ "type": "function"
292
+ },
293
+ {
294
+ "inputs": [
295
+ {
296
+ "internalType": "address",
297
+ "name": "_feeCollector",
298
+ "type": "address"
299
+ }
300
+ ],
301
+ "name": "setFeeCollectorAddress",
302
+ "outputs": [],
303
+ "stateMutability": "nonpayable",
304
+ "type": "function"
305
+ },
306
+ {
307
+ "inputs": [
308
+ {
309
+ "internalType": "address",
310
+ "name": "newOwner",
311
+ "type": "address"
312
+ }
313
+ ],
314
+ "name": "transferOwnership",
315
+ "outputs": [],
316
+ "stateMutability": "nonpayable",
317
+ "type": "function"
318
+ },
319
+ {
320
+ "inputs": [
321
+ {
322
+ "internalType": "address",
323
+ "name": "newImplementation",
324
+ "type": "address"
325
+ }
326
+ ],
327
+ "name": "upgradeTo",
328
+ "outputs": [],
329
+ "stateMutability": "nonpayable",
330
+ "type": "function"
331
+ },
332
+ {
333
+ "inputs": [
334
+ {
335
+ "internalType": "address",
336
+ "name": "newImplementation",
337
+ "type": "address"
338
+ },
339
+ {
340
+ "internalType": "bytes",
341
+ "name": "data",
342
+ "type": "bytes"
343
+ }
344
+ ],
345
+ "name": "upgradeToAndCall",
346
+ "outputs": [],
347
+ "stateMutability": "payable",
348
+ "type": "function"
349
+ }
350
+ ]
@@ -1,5 +1,13 @@
1
1
  import BatchQuery from "./BatchQuery.json";
2
2
  import ERC20 from "./ERC20.json";
3
+ import XSwapRouter from "./XSwapRouter.json";
4
+ import XSwapTokenFeeDistributor from "./XSwapTokenFeeDistributor.json";
5
+ import CustomXSwapRouter from "./CustomXSwapRouter.json";
6
+ import StakingStableAPR from "./StakingStableAPR.json";
3
7
 
4
8
  export const BatchQueryAbi = BatchQuery;
5
9
  export const ERC20Abi = ERC20;
10
+ export const XSwapRouterAbi = XSwapRouter;
11
+ export const XSwapTokenFeeDistributorAbi = XSwapTokenFeeDistributor;
12
+ export const CustomXSwapRouterAbi = CustomXSwapRouter;
13
+ export const StakingStableAPRAbi = StakingStableAPR;
@@ -3,38 +3,56 @@ import { Addresses, ContractName } from "@src/models";
3
3
  export const ADDRESSES: Addresses = {
4
4
  // arbitrum
5
5
  "42161": {
6
+ [ContractName.USDC]: "0xaf88d065e77c8cc2239327c5edb3a432268e5831",
6
7
  [ContractName.BatchQuery]: "0xb5f9934ea0810ef5faa677e8c68c6983b88664b1",
7
- [ContractName.XSwapRouter]: "0xe1c14b9f065dead2e89ee35382f8bd42bdb87a04",
8
8
  [ContractName.FeeCollector]: "0xb37275558f02f05104c2ba35199d16adeb43432f",
9
+ [ContractName.XSwapRouter]: "0xe1c14b9f065dead2e89ee35382f8bd42bdb87a04",
9
10
  },
10
11
  // avalanche
11
12
  "43114": {
13
+ [ContractName.USDC]: "0xb97ef9ef8734c71904d8002f8b6bc66dd9c48a6e",
12
14
  [ContractName.BatchQuery]: "0xb5f9934ea0810ef5faa677e8c68c6983b88664b1",
13
- [ContractName.XSwapRouter]: "0xe1c14b9f065dead2e89ee35382f8bd42bdb87a04",
14
15
  [ContractName.FeeCollector]: "0xb37275558f02f05104c2ba35199d16adeb43432f",
16
+ [ContractName.XSwapRouter]: "0xe1c14b9f065dead2e89ee35382f8bd42bdb87a04",
15
17
  },
16
18
  // base
17
19
  "8453": {
20
+ [ContractName.USDC]: "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913",
18
21
  [ContractName.BatchQuery]: "0xb5f9934ea0810ef5faa677e8c68c6983b88664b1",
19
- [ContractName.XSwapRouter]: "0xe1c14b9f065dead2e89ee35382f8bd42bdb87a04",
22
+ [ContractName.CustomXSwapRouter]:
23
+ "0x9B64aC0aD647768838a3957Bc12c40E1C539cb93",
20
24
  [ContractName.FeeCollector]: "0xb37275558f02f05104c2ba35199d16adeb43432f",
25
+ [ContractName.StakingCosmicCadets]:
26
+ "0x67798736bFb7d9A1F143215E258fe15Da68c85F0",
27
+ [ContractName.StakingSolarDivision]:
28
+ "0xF86e9f328e840658bAc6C5726a76ba4db1eFe923",
29
+ [ContractName.StakingIntergalacticCommand]:
30
+ "0x29A09C1642222eE5ae14EF19445f1326BCFCAC01",
31
+ [ContractName.XSwapRouter]: "0xe1c14b9f065dead2e89ee35382f8bd42bdb87a04",
32
+ [ContractName.XSwapToken]: "0x8fe815417913a93ea99049fc0718ee1647a2a07c",
21
33
  },
22
34
  // ethereum
23
35
  "1": {
36
+ [ContractName.USDC]: "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48",
24
37
  [ContractName.BatchQuery]: "0xb5f9934ea0810ef5faa677e8c68c6983b88664b1",
25
- [ContractName.XSwapRouter]: "0xe1c14b9f065dead2e89ee35382f8bd42bdb87a04",
38
+ [ContractName.CustomXSwapRouter]:
39
+ "0x9B64aC0aD647768838a3957Bc12c40E1C539cb93",
26
40
  [ContractName.FeeCollector]: "0xb37275558f02f05104c2ba35199d16adeb43432f",
41
+ [ContractName.XSwapRouter]: "0xe1c14b9f065dead2e89ee35382f8bd42bdb87a04",
42
+ [ContractName.XSwapToken]: "0x8fe815417913a93ea99049fc0718ee1647a2a07c",
27
43
  },
28
44
  // optimism
29
45
  "10": {
46
+ [ContractName.USDC]: "0x0b2c639c533813f4aa9d7837caf62653d097ff85",
30
47
  [ContractName.BatchQuery]: "0xb5f9934ea0810ef5faa677e8c68c6983b88664b1",
31
- [ContractName.XSwapRouter]: "0xe1c14b9f065dead2e89ee35382f8bd42bdb87a04",
32
48
  [ContractName.FeeCollector]: "0xb37275558f02f05104c2ba35199d16adeb43432f",
49
+ [ContractName.XSwapRouter]: "0xe1c14b9f065dead2e89ee35382f8bd42bdb87a04",
33
50
  },
34
51
  // polygon
35
52
  "137": {
53
+ [ContractName.USDC]: "0xf1e3a5842eeef51f2967b3f05d45dd4f4205ff40",
36
54
  [ContractName.BatchQuery]: "0xb5f9934ea0810ef5faa677e8c68c6983b88664b1",
37
- [ContractName.XSwapRouter]: "0xe1c14b9f065dead2e89ee35382f8bd42bdb87a04",
38
55
  [ContractName.FeeCollector]: "0xb37275558f02f05104c2ba35199d16adeb43432f",
56
+ [ContractName.XSwapRouter]: "0xe1c14b9f065dead2e89ee35382f8bd42bdb87a04",
39
57
  },
40
58
  };
Binary file
Binary file
Binary file
Binary file
Binary file
Binary file
@@ -0,0 +1,5 @@
1
+ export * from "./useBatchQuery";
2
+ export * from "./useDebounce";
3
+ export * from "./useEvmContractApi";
4
+ export * from "./usePortal";
5
+ export * from "./useXPower";
@@ -0,0 +1,17 @@
1
+ import { providers } from "ethers";
2
+ import { useMemo } from "react";
3
+ import type { Account, Chain, Client, Transport } from "viem";
4
+ import { Config, useConnectorClient } from "wagmi";
5
+
6
+ export function clientToSigner(client: Client<Transport, Chain, Account>) {
7
+ const { account, transport } = client;
8
+ const provider = new providers.Web3Provider(transport, "any");
9
+ const signer = provider.getSigner(account.address);
10
+ return signer;
11
+ }
12
+
13
+ /** Hook to convert a Viem Client to an ethers.js Signer. */
14
+ export async function useEthersSigner({ chainId }: { chainId?: number } = {}) {
15
+ const { data: client } = useConnectorClient<Config>({ chainId });
16
+ return useMemo(() => (client ? clientToSigner(client) : undefined), [client]);
17
+ }
@@ -0,0 +1,51 @@
1
+ import { JsonRpcProvider, JsonRpcSigner } from "@ethersproject/providers";
2
+ import { useEffect, useMemo, useState } from "react";
3
+ import { useAccount } from "wagmi";
4
+ import { useEthersSigner } from "./clientToSigner";
5
+
6
+ export interface Network {
7
+ networkName: string;
8
+ chainId: string;
9
+ address?: string;
10
+ }
11
+ export interface EvmNetwork extends Network {
12
+ provider?: JsonRpcProvider;
13
+ signer?: JsonRpcSigner;
14
+ }
15
+
16
+ export const useNetworks = (): {
17
+ networks: {
18
+ evm: EvmNetwork;
19
+ };
20
+ } => {
21
+ const [signer, setSigner] = useState<JsonRpcSigner>();
22
+
23
+ const ethersSigner = useEthersSigner();
24
+
25
+ useEffect(() => {
26
+ ethersSigner.then((signer) => setSigner(signer));
27
+ }, [ethersSigner]);
28
+
29
+ // Evm
30
+ const account = useAccount();
31
+
32
+ const evm = useMemo(
33
+ () => ({
34
+ networkName: "EVM",
35
+ // Is non-nullable assertion here safe?
36
+ // In xswap-dapp we fallback to the default chain, but it doesn't seem to be enforced anywhere.
37
+ // So that fallback is probably not right as well.
38
+ chainId: account.chainId!.toString(),
39
+ address: account.address,
40
+ signer: signer,
41
+ provider: signer?.provider,
42
+ }),
43
+ [account.address, account.chainId, signer],
44
+ );
45
+
46
+ return {
47
+ networks: { evm },
48
+ };
49
+ };
50
+
51
+ export default useNetworks;
@@ -0,0 +1,46 @@
1
+ import { ADDRESSES, BatchQueryAbi } from "@src/contracts";
2
+ import { useSwapContext } from "@src/context";
3
+ import useEvmContractApi from "./useEvmContractApi";
4
+ import { Ecosystem } from "@src/models";
5
+ import { ethers } from "ethers";
6
+ import { useCallback } from "react";
7
+
8
+ export const useBatchQuery = () => {
9
+ const evmContractApi = useEvmContractApi();
10
+ const { supportedChains } = useSwapContext();
11
+
12
+ const contract = useCallback(
13
+ (chainId: string) => {
14
+ const rpcUrl = supportedChains.find(
15
+ (chain) =>
16
+ chain.ecosystem === Ecosystem.EVM && chain.chainId === chainId,
17
+ )?.publicRpcUrls[0];
18
+ const contractAddress = ADDRESSES[chainId]?.BatchQuery;
19
+ if (rpcUrl && contractAddress) {
20
+ return new ethers.Contract(
21
+ contractAddress,
22
+ BatchQueryAbi,
23
+ ethers.getDefaultProvider(rpcUrl),
24
+ );
25
+ }
26
+ return null;
27
+ },
28
+ [supportedChains],
29
+ );
30
+
31
+ return {
32
+ batchQuery: useCallback(
33
+ async (
34
+ chainId: string,
35
+ targetAddresses: string[],
36
+ calldatas: string[],
37
+ ) => {
38
+ return await evmContractApi.query(contract(chainId), "batchQuery", [
39
+ targetAddresses,
40
+ calldatas,
41
+ ]);
42
+ },
43
+ [contract, evmContractApi],
44
+ ),
45
+ };
46
+ };
@@ -0,0 +1,28 @@
1
+ import { useCallback, useRef } from "react";
2
+
3
+ export const useDebounce = ({
4
+ delayMs,
5
+ instantExecution,
6
+ }: {
7
+ delayMs: number;
8
+ instantExecution?: () => void;
9
+ }) => {
10
+ const timerRef = useRef<NodeJS.Timeout | null>(null);
11
+
12
+ const debounce = useCallback(
13
+ (callback: () => void) => {
14
+ if (timerRef.current) {
15
+ clearTimeout(timerRef.current);
16
+ timerRef.current = null;
17
+ }
18
+
19
+ if (instantExecution) {
20
+ instantExecution();
21
+ }
22
+ timerRef.current = setTimeout(callback, delayMs);
23
+ },
24
+ [delayMs, instantExecution],
25
+ );
26
+
27
+ return { debounce };
28
+ };
@@ -0,0 +1,85 @@
1
+ import { GAS_LIMIT_MULTIPLIER } from "@src/constants";
2
+ import { ethers } from "ethers";
3
+ import { useMemo } from "react";
4
+
5
+ export const useEvmContractApi = () =>
6
+ useMemo(
7
+ () => ({
8
+ // TODO check if we can avoid nullable contract (think about error handling)
9
+ query: async (
10
+ contract: ethers.Contract | null,
11
+ method: string,
12
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
13
+ args: any[] = [],
14
+ ) => {
15
+ if (contract?.provider) {
16
+ return await contract[method](...args);
17
+ }
18
+ return null;
19
+ },
20
+ execute: async (
21
+ contract: ethers.Contract | null,
22
+ method: string,
23
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
24
+ args: any[] = [],
25
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
26
+ options: Record<string, any> = {},
27
+ ) => {
28
+ try {
29
+ if (contract?.provider) {
30
+ // @ts-expect-error idk, needs to be handled another time in the future
31
+ const gasEstimation = await contract.estimateGas[method](
32
+ ...args,
33
+ options,
34
+ );
35
+ if (!options.gasLimit) {
36
+ options.gasLimit = Math.floor(
37
+ gasEstimation.toNumber() * GAS_LIMIT_MULTIPLIER,
38
+ );
39
+ }
40
+ return await contract[method](...args, options);
41
+ }
42
+ return null;
43
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
44
+ } catch (err: any) {
45
+ let decodedError;
46
+ try {
47
+ // Try to decode custom error from smart contract
48
+ decodedError = contract?.interface.parseError(
49
+ err?.error?.data?.data,
50
+ );
51
+ } catch (_) {
52
+ // If it fails but there is a message - throw that message
53
+ if (err?.error?.data?.message) {
54
+ throw new Error(err?.error?.data?.message);
55
+ }
56
+ // Else throw whole error to be handled by TransactionProvider
57
+ throw err;
58
+ }
59
+ throw new Error(decodedError?.name);
60
+ }
61
+ },
62
+ executeCalldata: async (signer, transaction) => {
63
+ try {
64
+ const gasEstimation = await signer.estimateGas({
65
+ ...transaction,
66
+ });
67
+ return await signer.sendTransaction({
68
+ ...transaction,
69
+ gasLimit: Math.floor(
70
+ gasEstimation.toNumber() * GAS_LIMIT_MULTIPLIER,
71
+ ),
72
+ });
73
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
74
+ } catch (err: any) {
75
+ if (err?.error?.data?.message) {
76
+ throw new Error(err?.error?.data?.message);
77
+ }
78
+ throw err;
79
+ }
80
+ },
81
+ }),
82
+ [],
83
+ );
84
+
85
+ export default useEvmContractApi;