@lifi/sdk 2.3.1 → 3.0.0-alpha.10

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 (379) hide show
  1. package/dist/cjs/LiFi.js +222 -250
  2. package/dist/cjs/LiFi.js.map +1 -0
  3. package/dist/cjs/allowance/getAllowance.js +82 -0
  4. package/dist/cjs/allowance/getAllowance.js.map +1 -0
  5. package/dist/cjs/allowance/index.js +5 -16
  6. package/dist/cjs/allowance/index.js.map +1 -0
  7. package/dist/cjs/allowance/setAllowance.js +71 -0
  8. package/dist/cjs/allowance/setAllowance.js.map +1 -0
  9. package/dist/cjs/{types/internal.types.js → allowance/types.js} +1 -0
  10. package/dist/cjs/allowance/types.js.map +1 -0
  11. package/dist/cjs/balance/getBalance.js +97 -0
  12. package/dist/cjs/balance/getBalance.js.map +1 -0
  13. package/dist/cjs/balance/getTokenBalance.js +7 -10
  14. package/dist/cjs/balance/getTokenBalance.js.map +1 -0
  15. package/dist/cjs/balance/index.js +4 -24
  16. package/dist/cjs/balance/index.js.map +1 -0
  17. package/dist/cjs/connectors.js +28 -48
  18. package/dist/cjs/connectors.js.map +1 -0
  19. package/dist/cjs/constants.js +7 -0
  20. package/dist/cjs/constants.js.map +1 -0
  21. package/dist/cjs/execution/BaseStepExecutor.js +54 -0
  22. package/dist/cjs/execution/BaseStepExecutor.js.map +1 -0
  23. package/dist/cjs/execution/EVMStepExecutor.js +271 -0
  24. package/dist/cjs/execution/EVMStepExecutor.js.map +1 -0
  25. package/dist/cjs/execution/RouteExecutionManager.js +196 -197
  26. package/dist/cjs/execution/RouteExecutionManager.js.map +1 -0
  27. package/dist/cjs/execution/StatusManager.js +142 -136
  28. package/dist/cjs/execution/StatusManager.js.map +1 -0
  29. package/dist/cjs/execution/StepExecutionManager.js +220 -233
  30. package/dist/cjs/execution/StepExecutionManager.js.map +1 -0
  31. package/dist/cjs/execution/checkAllowance.js +76 -0
  32. package/dist/cjs/execution/checkAllowance.js.map +1 -0
  33. package/dist/cjs/execution/checkBalance.js +42 -0
  34. package/dist/cjs/execution/checkBalance.js.map +1 -0
  35. package/dist/cjs/execution/index.js +4 -15
  36. package/dist/cjs/execution/index.js.map +1 -0
  37. package/dist/cjs/execution/multisig.js +13 -17
  38. package/dist/cjs/execution/multisig.js.map +1 -0
  39. package/dist/cjs/execution/prepareRestart.js +23 -0
  40. package/dist/cjs/execution/prepareRestart.js.map +1 -0
  41. package/dist/cjs/execution/stepComparison.js +5 -17
  42. package/dist/cjs/execution/stepComparison.js.map +1 -0
  43. package/dist/cjs/execution/switchChain.js +10 -22
  44. package/dist/cjs/execution/switchChain.js.map +1 -0
  45. package/dist/cjs/execution/types.js +3 -0
  46. package/dist/cjs/execution/types.js.map +1 -0
  47. package/dist/cjs/execution/utils.js +12 -67
  48. package/dist/cjs/execution/utils.js.map +1 -0
  49. package/dist/cjs/execution/waitForReceivingTransaction.js +56 -0
  50. package/dist/cjs/execution/waitForReceivingTransaction.js.map +1 -0
  51. package/dist/cjs/helpers.js +12 -58
  52. package/dist/cjs/helpers.js.map +1 -0
  53. package/dist/cjs/index.js +16 -22
  54. package/dist/cjs/index.js.map +1 -0
  55. package/dist/cjs/package.json +1 -0
  56. package/dist/cjs/providers/EVM.js +35 -0
  57. package/dist/cjs/providers/EVM.js.map +1 -0
  58. package/dist/cjs/providers/Solana.js +38 -0
  59. package/dist/cjs/providers/Solana.js.map +1 -0
  60. package/dist/cjs/providers/index.js +5 -0
  61. package/dist/cjs/providers/index.js.map +1 -0
  62. package/dist/cjs/providers/types.js +9 -0
  63. package/dist/cjs/providers/types.js.map +1 -0
  64. package/dist/cjs/request.js +10 -13
  65. package/dist/cjs/request.js.map +1 -0
  66. package/dist/cjs/services/ApiService.js +70 -86
  67. package/dist/cjs/services/ApiService.js.map +1 -0
  68. package/dist/cjs/services/ChainsService.js +19 -9
  69. package/dist/cjs/services/ChainsService.js.map +1 -0
  70. package/dist/cjs/services/ConfigService.js +94 -67
  71. package/dist/cjs/services/ConfigService.js.map +1 -0
  72. package/dist/cjs/typeguards.js +1 -0
  73. package/dist/cjs/typeguards.js.map +1 -0
  74. package/dist/cjs/types/abi.js +46 -0
  75. package/dist/cjs/types/abi.js.map +1 -0
  76. package/dist/cjs/types/index.js +4 -20
  77. package/dist/cjs/types/index.js.map +1 -0
  78. package/dist/cjs/types/internal.js +3 -0
  79. package/dist/cjs/types/internal.js.map +1 -0
  80. package/dist/cjs/utils/errors.js +63 -40
  81. package/dist/cjs/utils/errors.js.map +1 -0
  82. package/dist/cjs/utils/getMaxPriorityFeePerGas.js +23 -0
  83. package/dist/cjs/utils/getMaxPriorityFeePerGas.js.map +1 -0
  84. package/dist/cjs/utils/index.js +9 -0
  85. package/dist/cjs/utils/index.js.map +1 -0
  86. package/dist/cjs/utils/median.js +16 -0
  87. package/dist/cjs/utils/median.js.map +1 -0
  88. package/dist/cjs/utils/parseError.js +55 -92
  89. package/dist/cjs/utils/parseError.js.map +1 -0
  90. package/dist/cjs/utils/utils.js +10 -85
  91. package/dist/cjs/utils/utils.js.map +1 -0
  92. package/dist/cjs/version.js +2 -1
  93. package/dist/cjs/version.js.map +1 -0
  94. package/dist/esm/LiFi.js +375 -0
  95. package/dist/esm/LiFi.js.map +1 -0
  96. package/dist/esm/allowance/getAllowance.js +79 -0
  97. package/dist/esm/allowance/getAllowance.js.map +1 -0
  98. package/dist/esm/allowance/index.js +4 -0
  99. package/dist/esm/allowance/index.js.map +1 -0
  100. package/dist/esm/allowance/setAllowance.js +67 -0
  101. package/dist/esm/allowance/setAllowance.js.map +1 -0
  102. package/dist/esm/allowance/types.js +2 -0
  103. package/dist/esm/allowance/types.js.map +1 -0
  104. package/dist/esm/balance/getBalance.js +93 -0
  105. package/dist/esm/balance/getBalance.js.map +1 -0
  106. package/dist/{balance → esm/balance}/getTokenBalance.js +5 -4
  107. package/dist/esm/balance/getTokenBalance.js.map +1 -0
  108. package/dist/esm/balance/index.js +3 -0
  109. package/dist/esm/balance/index.js.map +1 -0
  110. package/dist/esm/connectors.js +42 -0
  111. package/dist/esm/connectors.js.map +1 -0
  112. package/dist/esm/constants.js +7 -0
  113. package/dist/esm/constants.js.map +1 -0
  114. package/dist/esm/execution/BaseStepExecutor.js +51 -0
  115. package/dist/esm/execution/BaseStepExecutor.js.map +1 -0
  116. package/dist/esm/execution/EVMStepExecutor.js +299 -0
  117. package/dist/esm/execution/EVMStepExecutor.js.map +1 -0
  118. package/dist/esm/execution/RouteExecutionManager.js +268 -0
  119. package/dist/esm/execution/RouteExecutionManager.js.map +1 -0
  120. package/dist/esm/execution/StatusManager.js +216 -0
  121. package/dist/esm/execution/StatusManager.js.map +1 -0
  122. package/dist/esm/execution/StepExecutionManager.js +280 -0
  123. package/dist/esm/execution/StepExecutionManager.js.map +1 -0
  124. package/dist/esm/execution/checkAllowance.js +74 -0
  125. package/dist/esm/execution/checkAllowance.js.map +1 -0
  126. package/dist/esm/execution/checkBalance.js +39 -0
  127. package/dist/esm/execution/checkBalance.js.map +1 -0
  128. package/dist/esm/execution/index.js +3 -0
  129. package/dist/esm/execution/index.js.map +1 -0
  130. package/dist/esm/execution/multisig.js +26 -0
  131. package/dist/esm/execution/multisig.js.map +1 -0
  132. package/dist/esm/execution/prepareRestart.js +64 -0
  133. package/dist/esm/execution/prepareRestart.js.map +1 -0
  134. package/dist/{execution → esm/execution}/stepComparison.js +5 -4
  135. package/dist/esm/execution/stepComparison.js.map +1 -0
  136. package/dist/{execution → esm/execution}/switchChain.js +19 -12
  137. package/dist/esm/execution/switchChain.js.map +1 -0
  138. package/dist/esm/execution/types.js +2 -0
  139. package/dist/esm/execution/types.js.map +1 -0
  140. package/dist/esm/execution/utils.js +80 -0
  141. package/dist/esm/execution/utils.js.map +1 -0
  142. package/dist/esm/execution/waitForReceivingTransaction.js +52 -0
  143. package/dist/esm/execution/waitForReceivingTransaction.js.map +1 -0
  144. package/dist/{helpers.js → esm/helpers.js} +9 -37
  145. package/dist/esm/helpers.js.map +1 -0
  146. package/dist/esm/index.js +10 -0
  147. package/dist/esm/index.js.map +1 -0
  148. package/dist/esm/package.json +1 -0
  149. package/dist/esm/providers/EVM.js +30 -0
  150. package/dist/esm/providers/EVM.js.map +1 -0
  151. package/dist/esm/providers/Solana.js +34 -0
  152. package/dist/esm/providers/Solana.js.map +1 -0
  153. package/dist/esm/providers/index.js +2 -0
  154. package/dist/esm/providers/index.js.map +1 -0
  155. package/dist/esm/providers/types.js +6 -0
  156. package/dist/esm/providers/types.js.map +1 -0
  157. package/dist/{request.js → esm/request.js} +6 -5
  158. package/dist/esm/request.js.map +1 -0
  159. package/dist/{services → esm/services}/ApiService.js +29 -26
  160. package/dist/esm/services/ApiService.js.map +1 -0
  161. package/dist/{services → esm/services}/ChainsService.js +16 -4
  162. package/dist/esm/services/ChainsService.js.map +1 -0
  163. package/dist/esm/services/ConfigService.js +143 -0
  164. package/dist/esm/services/ConfigService.js.map +1 -0
  165. package/dist/{typeguards.js → esm/typeguards.js} +1 -0
  166. package/dist/esm/typeguards.js.map +1 -0
  167. package/dist/esm/types/abi.js +43 -0
  168. package/dist/esm/types/abi.js.map +1 -0
  169. package/dist/esm/types/index.js +3 -0
  170. package/dist/esm/types/index.js.map +1 -0
  171. package/dist/esm/types/internal.js +2 -0
  172. package/dist/esm/types/internal.js.map +1 -0
  173. package/dist/{utils → esm/utils}/errors.js +61 -35
  174. package/dist/esm/utils/errors.js.map +1 -0
  175. package/dist/esm/utils/getMaxPriorityFeePerGas.js +19 -0
  176. package/dist/esm/utils/getMaxPriorityFeePerGas.js.map +1 -0
  177. package/dist/esm/utils/index.js +6 -0
  178. package/dist/esm/utils/index.js.map +1 -0
  179. package/dist/esm/utils/median.js +12 -0
  180. package/dist/esm/utils/median.js.map +1 -0
  181. package/dist/{utils → esm/utils}/parseError.js +45 -41
  182. package/dist/esm/utils/parseError.js.map +1 -0
  183. package/dist/esm/utils/utils.js +38 -0
  184. package/dist/esm/utils/utils.js.map +1 -0
  185. package/dist/esm/version.js +3 -0
  186. package/dist/esm/version.js.map +1 -0
  187. package/dist/types/LiFi.d.ts +179 -0
  188. package/dist/types/LiFi.d.ts.map +1 -0
  189. package/dist/types/allowance/getAllowance.d.ts +7 -0
  190. package/dist/types/allowance/getAllowance.d.ts.map +1 -0
  191. package/dist/types/allowance/index.d.ts +4 -0
  192. package/dist/types/allowance/index.d.ts.map +1 -0
  193. package/dist/types/allowance/setAllowance.d.ts +7 -0
  194. package/dist/types/allowance/setAllowance.d.ts.map +1 -0
  195. package/dist/types/allowance/types.d.ts +28 -0
  196. package/dist/types/allowance/types.d.ts.map +1 -0
  197. package/dist/types/balance/getBalance.d.ts +3 -0
  198. package/dist/types/balance/getBalance.d.ts.map +1 -0
  199. package/dist/{balance → types/balance}/getTokenBalance.d.ts +3 -2
  200. package/dist/types/balance/getTokenBalance.d.ts.map +1 -0
  201. package/dist/types/balance/index.d.ts +3 -0
  202. package/dist/types/balance/index.d.ts.map +1 -0
  203. package/dist/types/connectors.d.ts +9 -0
  204. package/dist/types/connectors.d.ts.map +1 -0
  205. package/dist/types/constants.d.ts +7 -0
  206. package/dist/types/constants.d.ts.map +1 -0
  207. package/dist/types/execution/BaseStepExecutor.d.ts +13 -0
  208. package/dist/types/execution/BaseStepExecutor.d.ts.map +1 -0
  209. package/dist/types/execution/EVMStepExecutor.d.ts +14 -0
  210. package/dist/types/execution/EVMStepExecutor.d.ts.map +1 -0
  211. package/dist/types/execution/RouteExecutionManager.d.ts +61 -0
  212. package/dist/types/execution/RouteExecutionManager.d.ts.map +1 -0
  213. package/dist/types/execution/StatusManager.d.ts +69 -0
  214. package/dist/types/execution/StatusManager.d.ts.map +1 -0
  215. package/dist/types/execution/StepExecutionManager.d.ts +8 -0
  216. package/dist/types/execution/StepExecutionManager.d.ts.map +1 -0
  217. package/dist/types/execution/checkAllowance.d.ts +6 -0
  218. package/dist/types/execution/checkAllowance.d.ts.map +1 -0
  219. package/dist/types/execution/checkBalance.d.ts +3 -0
  220. package/dist/types/execution/checkBalance.d.ts.map +1 -0
  221. package/dist/types/execution/index.d.ts +3 -0
  222. package/dist/types/execution/index.d.ts.map +1 -0
  223. package/dist/types/execution/multisig.d.ts +5 -0
  224. package/dist/types/execution/multisig.d.ts.map +1 -0
  225. package/dist/types/execution/prepareRestart.d.ts +3 -0
  226. package/dist/types/execution/prepareRestart.d.ts.map +1 -0
  227. package/dist/{execution → types/execution}/stepComparison.d.ts +6 -4
  228. package/dist/types/execution/stepComparison.d.ts.map +1 -0
  229. package/dist/types/execution/switchChain.d.ts +23 -0
  230. package/dist/types/execution/switchChain.d.ts.map +1 -0
  231. package/dist/types/execution/types.d.ts +83 -0
  232. package/dist/types/execution/types.d.ts.map +1 -0
  233. package/dist/types/execution/utils.d.ts +13 -0
  234. package/dist/types/execution/utils.d.ts.map +1 -0
  235. package/dist/types/execution/waitForReceivingTransaction.d.ts +4 -0
  236. package/dist/types/execution/waitForReceivingTransaction.d.ts.map +1 -0
  237. package/dist/types/helpers.d.ts +19 -0
  238. package/dist/types/helpers.d.ts.map +1 -0
  239. package/dist/types/index.d.ts +9 -3
  240. package/dist/types/index.d.ts.map +1 -0
  241. package/dist/types/providers/EVM.d.ts +11 -0
  242. package/dist/types/providers/EVM.d.ts.map +1 -0
  243. package/dist/types/providers/Solana.d.ts +10 -0
  244. package/dist/types/providers/Solana.d.ts.map +1 -0
  245. package/dist/types/providers/index.d.ts +2 -0
  246. package/dist/types/providers/index.d.ts.map +1 -0
  247. package/dist/types/providers/types.d.ts +13 -0
  248. package/dist/types/providers/types.d.ts.map +1 -0
  249. package/dist/{request.d.ts → types/request.d.ts} +1 -0
  250. package/dist/types/request.d.ts.map +1 -0
  251. package/dist/{cjs → types}/services/ApiService.d.ts +5 -5
  252. package/dist/types/services/ApiService.d.ts.map +1 -0
  253. package/dist/{services → types/services}/ChainsService.d.ts +3 -2
  254. package/dist/types/services/ChainsService.d.ts.map +1 -0
  255. package/dist/{services → types/services}/ConfigService.d.ts +10 -6
  256. package/dist/types/services/ConfigService.d.ts.map +1 -0
  257. package/dist/{cjs → types}/typeguards.d.ts +3 -2
  258. package/dist/types/typeguards.d.ts.map +1 -0
  259. package/dist/types/types/abi.d.ts +6 -0
  260. package/dist/types/types/abi.d.ts.map +1 -0
  261. package/dist/types/types/index.d.ts +3 -0
  262. package/dist/types/types/index.d.ts.map +1 -0
  263. package/dist/types/types/internal.d.ts +61 -0
  264. package/dist/types/types/internal.d.ts.map +1 -0
  265. package/dist/{cjs → types}/utils/errors.d.ts +16 -14
  266. package/dist/types/utils/errors.d.ts.map +1 -0
  267. package/dist/types/utils/getMaxPriorityFeePerGas.d.ts +3 -0
  268. package/dist/types/utils/getMaxPriorityFeePerGas.d.ts.map +1 -0
  269. package/dist/types/utils/index.d.ts +6 -0
  270. package/dist/types/utils/index.d.ts.map +1 -0
  271. package/dist/types/utils/median.d.ts +2 -0
  272. package/dist/types/utils/median.d.ts.map +1 -0
  273. package/dist/{utils → types/utils}/parseError.d.ts +7 -6
  274. package/dist/types/utils/parseError.d.ts.map +1 -0
  275. package/dist/types/utils/utils.d.ts +11 -0
  276. package/dist/types/utils/utils.d.ts.map +1 -0
  277. package/dist/types/version.d.ts +3 -0
  278. package/dist/types/version.d.ts.map +1 -0
  279. package/package.json +37 -95
  280. package/dist/LiFi.d.ts +0 -164
  281. package/dist/LiFi.js +0 -235
  282. package/dist/allowance/checkAllowance.d.ts +0 -4
  283. package/dist/allowance/checkAllowance.js +0 -96
  284. package/dist/allowance/index.d.ts +0 -2
  285. package/dist/allowance/index.js +0 -2
  286. package/dist/allowance/tokenApproval.d.ts +0 -22
  287. package/dist/allowance/tokenApproval.js +0 -59
  288. package/dist/allowance/utils.d.ts +0 -14
  289. package/dist/allowance/utils.js +0 -72
  290. package/dist/balance/checkBalance.d.ts +0 -3
  291. package/dist/balance/checkBalance.js +0 -38
  292. package/dist/balance/index.d.ts +0 -13
  293. package/dist/balance/index.js +0 -10
  294. package/dist/balance/utils.d.ts +0 -6
  295. package/dist/balance/utils.js +0 -143
  296. package/dist/cjs/LiFi.d.ts +0 -164
  297. package/dist/cjs/allowance/checkAllowance.d.ts +0 -4
  298. package/dist/cjs/allowance/checkAllowance.js +0 -103
  299. package/dist/cjs/allowance/index.d.ts +0 -2
  300. package/dist/cjs/allowance/tokenApproval.d.ts +0 -22
  301. package/dist/cjs/allowance/tokenApproval.js +0 -69
  302. package/dist/cjs/allowance/utils.d.ts +0 -14
  303. package/dist/cjs/allowance/utils.js +0 -82
  304. package/dist/cjs/balance/checkBalance.d.ts +0 -3
  305. package/dist/cjs/balance/checkBalance.js +0 -45
  306. package/dist/cjs/balance/getTokenBalance.d.ts +0 -8
  307. package/dist/cjs/balance/index.d.ts +0 -13
  308. package/dist/cjs/balance/utils.d.ts +0 -6
  309. package/dist/cjs/balance/utils.js +0 -150
  310. package/dist/cjs/connectors.d.ts +0 -6
  311. package/dist/cjs/execution/RouteExecutionManager.d.ts +0 -65
  312. package/dist/cjs/execution/StatusManager.d.ts +0 -68
  313. package/dist/cjs/execution/StepExecutionManager.d.ts +0 -7
  314. package/dist/cjs/execution/StepExecutor.d.ts +0 -15
  315. package/dist/cjs/execution/StepExecutor.js +0 -62
  316. package/dist/cjs/execution/index.d.ts +0 -1
  317. package/dist/cjs/execution/multisig.d.ts +0 -3
  318. package/dist/cjs/execution/stepComparison.d.ts +0 -14
  319. package/dist/cjs/execution/switchChain.d.ts +0 -16
  320. package/dist/cjs/execution/utils.d.ts +0 -6
  321. package/dist/cjs/helpers.d.ts +0 -28
  322. package/dist/cjs/index.d.ts +0 -5
  323. package/dist/cjs/request.d.ts +0 -9
  324. package/dist/cjs/services/ChainsService.d.ts +0 -11
  325. package/dist/cjs/services/ConfigService.d.ts +0 -23
  326. package/dist/cjs/types/ERC20.d.ts +0 -22
  327. package/dist/cjs/types/ERC20.js +0 -53
  328. package/dist/cjs/types/index.d.ts +0 -4
  329. package/dist/cjs/types/internal.types.d.ts +0 -151
  330. package/dist/cjs/utils/getProvider.d.ts +0 -3
  331. package/dist/cjs/utils/getProvider.js +0 -11
  332. package/dist/cjs/utils/multicall.d.ts +0 -10
  333. package/dist/cjs/utils/multicall.js +0 -68
  334. package/dist/cjs/utils/multicallAbi.json +0 -313
  335. package/dist/cjs/utils/parseError.d.ts +0 -37
  336. package/dist/cjs/utils/preRestart.d.ts +0 -3
  337. package/dist/cjs/utils/preRestart.js +0 -56
  338. package/dist/cjs/utils/utils.d.ts +0 -25
  339. package/dist/cjs/version.d.ts +0 -2
  340. package/dist/connectors.d.ts +0 -6
  341. package/dist/connectors.js +0 -57
  342. package/dist/execution/RouteExecutionManager.d.ts +0 -65
  343. package/dist/execution/RouteExecutionManager.js +0 -213
  344. package/dist/execution/StatusManager.d.ts +0 -68
  345. package/dist/execution/StatusManager.js +0 -168
  346. package/dist/execution/StepExecutionManager.d.ts +0 -7
  347. package/dist/execution/StepExecutionManager.js +0 -267
  348. package/dist/execution/StepExecutor.d.ts +0 -15
  349. package/dist/execution/StepExecutor.js +0 -58
  350. package/dist/execution/index.d.ts +0 -1
  351. package/dist/execution/index.js +0 -1
  352. package/dist/execution/multisig.d.ts +0 -3
  353. package/dist/execution/multisig.js +0 -27
  354. package/dist/execution/switchChain.d.ts +0 -16
  355. package/dist/execution/utils.d.ts +0 -6
  356. package/dist/execution/utils.js +0 -122
  357. package/dist/helpers.d.ts +0 -28
  358. package/dist/index.d.ts +0 -5
  359. package/dist/index.js +0 -6
  360. package/dist/services/ApiService.d.ts +0 -17
  361. package/dist/services/ConfigService.js +0 -101
  362. package/dist/typeguards.d.ts +0 -4
  363. package/dist/types/ERC20.d.ts +0 -22
  364. package/dist/types/ERC20.js +0 -50
  365. package/dist/types/index.js +0 -4
  366. package/dist/types/internal.types.d.ts +0 -151
  367. package/dist/types/internal.types.js +0 -1
  368. package/dist/utils/errors.d.ts +0 -106
  369. package/dist/utils/getProvider.d.ts +0 -3
  370. package/dist/utils/getProvider.js +0 -7
  371. package/dist/utils/multicall.d.ts +0 -10
  372. package/dist/utils/multicall.js +0 -61
  373. package/dist/utils/multicallAbi.json +0 -313
  374. package/dist/utils/preRestart.d.ts +0 -3
  375. package/dist/utils/preRestart.js +0 -52
  376. package/dist/utils/utils.d.ts +0 -25
  377. package/dist/utils/utils.js +0 -99
  378. package/dist/version.d.ts +0 -2
  379. package/dist/version.js +0 -2
@@ -1,22 +0,0 @@
1
- import { Token } from '@lifi/types';
2
- import { Signer } from 'ethers';
3
- import { RevokeTokenData } from '../types';
4
- export interface ApproveTokenRequest {
5
- signer: Signer;
6
- token: Token;
7
- approvalAddress: string;
8
- amount: string;
9
- infiniteApproval?: boolean;
10
- }
11
- export interface RevokeApprovalRequest {
12
- signer: Signer;
13
- token: Token;
14
- approvalAddress: string;
15
- }
16
- export declare const getTokenApproval: (signer: Signer, token: Token, approvalAddress: string) => Promise<string | undefined>;
17
- export declare const bulkGetTokenApproval: (signer: Signer, tokenData: RevokeTokenData[]) => Promise<{
18
- token: Token;
19
- approval: string | undefined;
20
- }[]>;
21
- export declare const approveToken: ({ signer, token, approvalAddress, amount, infiniteApproval, }: ApproveTokenRequest) => Promise<void>;
22
- export declare const revokeTokenApproval: ({ signer, token, approvalAddress, }: RevokeApprovalRequest) => Promise<void>;
@@ -1,59 +0,0 @@
1
- import BigNumber from 'bignumber.js';
2
- import { constants } from 'ethers';
3
- import { isSameToken } from '../helpers';
4
- import { isNativeTokenAddress } from '../utils/utils';
5
- import { getAllowanceViaMulticall, getApproved, groupByChain, setApproval, } from './utils';
6
- export const getTokenApproval = async (signer, token, approvalAddress) => {
7
- // native token don't need approval
8
- if (isNativeTokenAddress(token.address)) {
9
- return;
10
- }
11
- const approved = await getApproved(signer, token.address, approvalAddress);
12
- return approved.toFixed(0);
13
- };
14
- export const bulkGetTokenApproval = async (signer, tokenData) => {
15
- // filter out native tokens
16
- const filteredTokenData = tokenData.filter(({ token }) => !isNativeTokenAddress(token.address));
17
- // group by chain
18
- const tokenDataByChain = groupByChain(filteredTokenData);
19
- const approvalPromises = Object.keys(tokenDataByChain).map(async (chainId) => {
20
- const parsedChainId = Number.parseInt(chainId);
21
- // get allowances for current chain and token list
22
- return getAllowanceViaMulticall(signer, parsedChainId, tokenDataByChain[parsedChainId]);
23
- });
24
- const approvalsByChain = await Promise.all(approvalPromises);
25
- const approvals = approvalsByChain.flat();
26
- return tokenData.map(({ token }) => {
27
- // native token don't need approval
28
- if (isNativeTokenAddress(token.address)) {
29
- return { token, approval: undefined };
30
- }
31
- const approved = approvals.find((approval) => isSameToken(approval.token, token));
32
- return { token, approval: approved?.approvedAmount.toString() };
33
- });
34
- };
35
- export const approveToken = async ({ signer, token, approvalAddress, amount, infiniteApproval = false, }) => {
36
- // native token don't need approval
37
- if (isNativeTokenAddress(token.address)) {
38
- return;
39
- }
40
- const approvedAmount = await getApproved(signer, token.address, approvalAddress);
41
- if (new BigNumber(amount).gt(approvedAmount)) {
42
- const approvalAmount = infiniteApproval
43
- ? constants.MaxUint256.toString()
44
- : amount;
45
- const approveTx = await setApproval(signer, token.address, approvalAddress, approvalAmount);
46
- await approveTx.wait();
47
- }
48
- };
49
- export const revokeTokenApproval = async ({ signer, token, approvalAddress, }) => {
50
- // native token don't need approval
51
- if (isNativeTokenAddress(token.address)) {
52
- return;
53
- }
54
- const approvedAmount = await getApproved(signer, token.address, approvalAddress);
55
- if (!approvedAmount.isZero()) {
56
- const approveTx = await setApproval(signer, token.address, approvalAddress, '0');
57
- await approveTx.wait();
58
- }
59
- };
@@ -1,14 +0,0 @@
1
- import { ChainId, Token } from '@lifi/types';
2
- import BigNumber from 'bignumber.js';
3
- import { ContractTransaction, PopulatedTransaction, Signer } from 'ethers';
4
- import { RevokeTokenData } from '../types';
5
- export declare const getApproved: (signer: Signer, tokenAddress: string, contractAddress: string) => Promise<BigNumber>;
6
- export declare const setApproval: (signer: Signer, tokenAddress: string, contractAddress: string, amount: string, returnPopulatedTransaction?: boolean) => Promise<ContractTransaction | PopulatedTransaction>;
7
- export declare const getAllowanceViaMulticall: (signer: Signer, chainId: ChainId, tokenData: RevokeTokenData[]) => Promise<{
8
- token: Token;
9
- approvalAddress: string;
10
- approvedAmount: BigNumber;
11
- }[]>;
12
- export declare const groupByChain: (tokenDataList: RevokeTokenData[]) => {
13
- [chainId: number]: RevokeTokenData[];
14
- };
@@ -1,72 +0,0 @@
1
- import BigNumber from 'bignumber.js';
2
- import { Contract, ethers, } from 'ethers';
3
- import ChainsService from '../services/ChainsService';
4
- import { ERC20_ABI } from '../types';
5
- import { ServerError } from '../utils/errors';
6
- import { fetchDataUsingMulticall } from '../utils/multicall';
7
- export const getApproved = async (signer, tokenAddress, contractAddress) => {
8
- const signerAddress = await signer.getAddress();
9
- const erc20 = new Contract(tokenAddress, ERC20_ABI, signer);
10
- try {
11
- const approved = await erc20.allowance(signerAddress, contractAddress);
12
- return new BigNumber(approved.toString());
13
- }
14
- catch (e) {
15
- return new BigNumber(0);
16
- }
17
- };
18
- export const setApproval = async (signer, tokenAddress, contractAddress, amount, returnPopulatedTransaction) => {
19
- const erc20 = new Contract(tokenAddress, ERC20_ABI, signer);
20
- if (returnPopulatedTransaction) {
21
- return erc20.populateTransaction.approve(contractAddress, amount);
22
- }
23
- const transactionRequest = await erc20.populateTransaction.approve(contractAddress, amount);
24
- try {
25
- const estimatedGasLimit = await signer.estimateGas(transactionRequest);
26
- if (estimatedGasLimit) {
27
- const formattedGasLimit = ethers.BigNumber.from(`${(BigInt(estimatedGasLimit.toString()) * 125n) / 100n}`);
28
- transactionRequest.gasLimit = formattedGasLimit;
29
- }
30
- }
31
- catch (error) { }
32
- return signer.sendTransaction(transactionRequest);
33
- };
34
- export const getAllowanceViaMulticall = async (signer, chainId, tokenData) => {
35
- const chainsService = ChainsService.getInstance();
36
- const chain = await chainsService.getChainById(chainId);
37
- if (!chain.multicallAddress) {
38
- throw new ServerError(`No multicall address configured for chainId ${chainId}.`);
39
- }
40
- const ownerAddress = await signer.getAddress();
41
- const calls = [];
42
- tokenData.map(({ token, approvalAddress }) => {
43
- calls.push({
44
- address: token.address,
45
- name: 'allowance',
46
- params: [ownerAddress, approvalAddress],
47
- });
48
- });
49
- const result = await fetchDataUsingMulticall(calls, ERC20_ABI, chainId, chain.multicallAddress);
50
- if (!result.length) {
51
- throw new ServerError(`Couldn't load allowance from chainId ${chainId} using multicall.`);
52
- }
53
- const parsedResult = result.map(({ data }) => ({
54
- approvalAmount: data ?? new BigNumber(0),
55
- }));
56
- return tokenData.map(({ token, approvalAddress }, i) => ({
57
- token,
58
- approvalAddress,
59
- approvedAmount: parsedResult[i].approvalAmount,
60
- }));
61
- };
62
- export const groupByChain = (tokenDataList) => {
63
- // group by chain
64
- const tokenDataByChain = {};
65
- tokenDataList.forEach((tokenData) => {
66
- if (!tokenDataByChain[tokenData.token.chainId]) {
67
- tokenDataByChain[tokenData.token.chainId] = [];
68
- }
69
- tokenDataByChain[tokenData.token.chainId].push(tokenData);
70
- });
71
- return tokenDataByChain;
72
- };
@@ -1,3 +0,0 @@
1
- import { ethers } from 'ethers';
2
- import { LifiStep } from '..';
3
- export declare const checkBalance: (signer: ethers.Signer, step: LifiStep, depth?: number) => Promise<void>;
@@ -1,38 +0,0 @@
1
- import BigNumber from 'bignumber.js';
2
- import { BalanceError } from '../utils/errors';
3
- import { getTokenBalance } from './getTokenBalance';
4
- export const checkBalance = async (signer, step, depth = 0) => {
5
- const tokenAmount = await getTokenBalance(await signer.getAddress(), step.action.fromToken);
6
- if (tokenAmount) {
7
- const currentBalance = new BigNumber(tokenAmount.amount).shiftedBy(tokenAmount.decimals);
8
- const neededBalance = new BigNumber(step.action.fromAmount);
9
- if (currentBalance.lt(neededBalance)) {
10
- if (depth <= 3) {
11
- await new Promise((resolve) => {
12
- setTimeout(resolve, 200);
13
- });
14
- await checkBalance(signer, step, depth + 1);
15
- }
16
- else if (neededBalance.multipliedBy(1 - step.action.slippage).lte(currentBalance)) {
17
- // adjust amount in slippage limits
18
- step.action.fromAmount = currentBalance.toFixed(0);
19
- }
20
- else {
21
- const neeeded = neededBalance.shiftedBy(-tokenAmount.decimals).toFixed();
22
- const current = currentBalance
23
- .shiftedBy(-tokenAmount.decimals)
24
- .toFixed();
25
- let errorMessage = `Your ${tokenAmount.symbol} balance is too low, ` +
26
- `you try to transfer ${neeeded} ${tokenAmount.symbol}, ` +
27
- `but your wallet only holds ${current} ${tokenAmount.symbol}. ` +
28
- `No funds have been sent. `;
29
- if (!currentBalance.isZero()) {
30
- errorMessage +=
31
- `If the problem consists, please delete this transfer and ` +
32
- `start a new one with a maximum of ${current} ${tokenAmount.symbol}.`;
33
- }
34
- throw new BalanceError('The balance is too low.', errorMessage);
35
- }
36
- }
37
- }
38
- };
@@ -1,13 +0,0 @@
1
- export * from './checkBalance';
2
- export * from './getTokenBalance';
3
- declare const _default: {
4
- checkBalance: (signer: import("ethers").Signer, step: import("@lifi/types").LifiStep, depth?: number) => Promise<void>;
5
- getTokenBalance: (walletAddress: string, token: import("@lifi/types").Token) => Promise<import("@lifi/types").TokenAmount | null>;
6
- getTokenBalances: (walletAddress: string, tokens: import("@lifi/types").Token[]) => Promise<import("@lifi/types").TokenAmount[]>;
7
- getTokenBalancesForChains: (walletAddress: string, tokensByChain: {
8
- [chainId: number]: import("@lifi/types").Token[];
9
- }) => Promise<{
10
- [chainId: number]: import("@lifi/types").TokenAmount[];
11
- }>;
12
- };
13
- export default _default;
@@ -1,10 +0,0 @@
1
- export * from './checkBalance';
2
- export * from './getTokenBalance';
3
- import { checkBalance } from './checkBalance';
4
- import { getTokenBalance, getTokenBalances, getTokenBalancesForChains, } from './getTokenBalance';
5
- export default {
6
- checkBalance,
7
- getTokenBalance,
8
- getTokenBalances,
9
- getTokenBalancesForChains,
10
- };
@@ -1,6 +0,0 @@
1
- import { Token, TokenAmount } from '@lifi/types';
2
- export declare const getBalances: (walletAddress: string, tokens: Token[]) => Promise<TokenAmount[]>;
3
- declare const _default: {
4
- getBalances: (walletAddress: string, tokens: Token[]) => Promise<TokenAmount[]>;
5
- };
6
- export default _default;
@@ -1,143 +0,0 @@
1
- import BigNumber from 'bignumber.js';
2
- import { ethers } from 'ethers';
3
- import { getMulticallAddress, getRpcProvider } from '../connectors';
4
- import { fetchDataUsingMulticall } from '../utils/multicall';
5
- import { isZeroAddress } from '../utils/utils';
6
- const balanceAbi = [
7
- {
8
- constant: true,
9
- inputs: [{ name: 'who', type: 'address' }],
10
- name: 'balanceOf',
11
- outputs: [{ name: '', type: 'uint256' }],
12
- payable: false,
13
- stateMutability: 'view',
14
- type: 'function',
15
- },
16
- {
17
- constant: true,
18
- inputs: [{ name: 'addr', type: 'address' }],
19
- name: 'getEthBalance',
20
- outputs: [{ name: 'balance', type: 'uint256' }],
21
- payable: false,
22
- stateMutability: 'view',
23
- type: 'function',
24
- },
25
- ];
26
- export const getBalances = async (walletAddress, tokens) => {
27
- if (tokens.length === 0) {
28
- return [];
29
- }
30
- const { chainId } = tokens[0];
31
- tokens.forEach((token) => {
32
- if (token.chainId !== chainId) {
33
- // eslint-disable-next-line no-console
34
- console.warn(`Requested tokens have to be on the same chain.`);
35
- return [];
36
- }
37
- });
38
- if ((await getMulticallAddress(chainId)) && tokens.length > 1) {
39
- return getBalancesFromProviderUsingMulticall(walletAddress, tokens);
40
- }
41
- else {
42
- return getBalancesFromProvider(walletAddress, tokens);
43
- }
44
- };
45
- const getBalancesFromProviderUsingMulticall = async (walletAddress, tokens) => {
46
- // Configuration
47
- const { chainId } = tokens[0];
48
- const multicallAddress = await getMulticallAddress(chainId);
49
- if (!multicallAddress) {
50
- throw new Error('No multicallAddress found for the given chain.');
51
- }
52
- return executeMulticall(walletAddress, tokens, multicallAddress, chainId);
53
- };
54
- const executeMulticall = async (walletAddress, tokens, multicallAddress, chainId) => {
55
- // Collect calls we want to make
56
- const calls = [];
57
- tokens.map((token) => {
58
- if (isZeroAddress(token.address)) {
59
- calls.push({
60
- address: multicallAddress,
61
- name: 'getEthBalance',
62
- params: [walletAddress],
63
- });
64
- }
65
- else {
66
- calls.push({
67
- address: token.address,
68
- name: 'balanceOf',
69
- params: [walletAddress],
70
- });
71
- }
72
- });
73
- const res = await fetchViaMulticall(calls, balanceAbi, chainId, multicallAddress);
74
- if (!res.length) {
75
- return [];
76
- }
77
- return tokens.map((token, i) => {
78
- const amount = new BigNumber(res[i].amount.toString() || '0')
79
- .shiftedBy(-token.decimals)
80
- .toFixed();
81
- return {
82
- ...token,
83
- amount: amount || '0',
84
- blockNumber: res[i].blockNumber,
85
- };
86
- });
87
- };
88
- const fetchViaMulticall = async (calls, abi, chainId, multicallAddress) => {
89
- const result = await fetchDataUsingMulticall(calls, abi, chainId, multicallAddress);
90
- return result.map(({ data, blockNumber }) => ({
91
- amount: data ? data : new BigNumber(0),
92
- blockNumber,
93
- }));
94
- };
95
- const getBalancesFromProvider = async (walletAddress, tokens) => {
96
- const chainId = tokens[0].chainId;
97
- const rpc = await getRpcProvider(chainId);
98
- const tokenAmountPromises = tokens.map(async (token) => {
99
- let amount = '0';
100
- let blockNumber;
101
- try {
102
- const balance = await getBalanceFromProvider(walletAddress, token.address, chainId, rpc);
103
- amount = new BigNumber(balance.amount.toString())
104
- .shiftedBy(-token.decimals)
105
- .toString();
106
- blockNumber = balance.blockNumber;
107
- }
108
- catch (e) {
109
- // eslint-disable-next-line no-console
110
- console.warn(e);
111
- }
112
- return {
113
- ...token,
114
- amount,
115
- blockNumber,
116
- };
117
- });
118
- return Promise.all(tokenAmountPromises);
119
- };
120
- const getBalanceFromProvider = async (walletAddress, assetId, chainId, provider) => {
121
- const blockNumber = await getCurrentBlockNumber(chainId);
122
- let balance;
123
- if (isZeroAddress(assetId)) {
124
- balance = await provider.getBalance(walletAddress, blockNumber);
125
- }
126
- else {
127
- const contract = new ethers.Contract(assetId, ['function balanceOf(address owner) view returns (uint256)'], provider);
128
- balance = await contract.balanceOf(walletAddress, {
129
- blockTag: blockNumber,
130
- });
131
- }
132
- return {
133
- amount: balance,
134
- blockNumber,
135
- };
136
- };
137
- const getCurrentBlockNumber = async (chainId) => {
138
- const rpc = await getRpcProvider(chainId);
139
- return rpc.getBlockNumber();
140
- };
141
- export default {
142
- getBalances,
143
- };
@@ -1,164 +0,0 @@
1
- import { FallbackProvider } from '@ethersproject/providers';
2
- import { ChainId, ChainKey, ConnectionsRequest, ConnectionsResponse, ContractCallQuoteRequest, ExtendedChain, GasRecommendationRequest, GasRecommendationResponse, GetStatusRequest, LifiStep, PossibilitiesRequest, PossibilitiesResponse, QuoteRequest, RequestOptions, RoutesRequest, RoutesResponse, StatusResponse, Token, TokenAmount, TokensRequest, TokensResponse, ToolsRequest, ToolsResponse } from '@lifi/types';
3
- import { Signer } from 'ethers';
4
- import { ApproveTokenRequest, RevokeApprovalRequest } from './allowance';
5
- import { RouteExecutionManager } from './execution/RouteExecutionManager';
6
- import { Config, ConfigUpdate, RevokeTokenData } from './types';
7
- export declare class LiFi extends RouteExecutionManager {
8
- private chainsService;
9
- constructor(configUpdate: ConfigUpdate);
10
- /**
11
- * Get the current configuration of the SDK
12
- * @return {Config} - The config object
13
- */
14
- getConfig: () => Config;
15
- /**
16
- * Get the SDK configuration after all setup calls are finished
17
- * @return {Promise<Config>} - The config object
18
- */
19
- getConfigAsync: () => Promise<Config>;
20
- /**
21
- * Get an instance of a provider for a specific chain
22
- * @param {number} chainId - Id of the chain the provider is for
23
- * @param {boolean} archive - Whether to use an archive provider that is based on a default rpc or not. defaults to false
24
- * @return {FallbackProvider} The provider for the given chain
25
- */
26
- getRpcProvider: (chainId: number, archive?: boolean) => Promise<FallbackProvider>;
27
- /**
28
- * Set a new confuration for the SDK
29
- * @param {ConfigUpdate} configUpdate - An object containing the configuration fields that should be updated.
30
- * @return {Config} The renewed config object
31
- */
32
- setConfig: (configUpdate: Partial<ConfigUpdate>) => Config;
33
- /**
34
- * Get a set of current possibilities based on a request that specifies which chains, exchanges and bridges are preferred or unwanted.
35
- * @param {PossibilitiesRequest} request - Object defining preferences regarding chain, exchanges and bridges
36
- * @return {Promise<PossibilitiesResponse>} Object listing current possibilities for any-to-any cross-chain-swaps based on the provided preferences.
37
- * @throws {LifiError} Throws a LifiError if request fails.
38
- * @deprecated We don't want to support this endpoint anymore in the future. /chains, /tools, /connections, and /tokens should be used instead
39
- */
40
- getPossibilities: (request?: PossibilitiesRequest, options?: RequestOptions) => Promise<PossibilitiesResponse>;
41
- /**
42
- * Fetch information about a Token
43
- * @param {ChainKey | ChainId} chain - Id or key of the chain that contains the token
44
- * @param {string} token - Address or symbol of the token on the requested chain
45
- * @throws {LifiError} - Throws a LifiError if request fails
46
- */
47
- getToken: (chain: ChainKey | ChainId, token: string, options?: RequestOptions) => Promise<Token>;
48
- /**
49
- * Get a quote for a token transfer
50
- * @param {QuoteRequest} request - The configuration of the requested quote
51
- * @throws {LifiError} - Throws a LifiError if request fails
52
- */
53
- getQuote: (request: QuoteRequest, options?: RequestOptions) => Promise<LifiStep>;
54
- /**
55
- * Get a quote for a destination contract call
56
- * @param {ContractCallQuoteRequest} request - The configuration of the requested destination call
57
- * @throws {LifiError} - Throws a LifiError if request fails
58
- */
59
- getContractCallQuote: (request: ContractCallQuoteRequest, options?: RequestOptions) => Promise<LifiStep>;
60
- /**
61
- * Check the status of a transfer. For cross chain transfers, the "bridge" parameter is required.
62
- * @param {GetStatusRequest} request - Configuration of the requested status
63
- * @throws {LifiError} - Throws a LifiError if request fails
64
- */
65
- getStatus: (request: GetStatusRequest, options?: RequestOptions) => Promise<StatusResponse>;
66
- /**
67
- * Get the available tools to bridge and swap tokens.
68
- * @param {ToolsRequest?} request - The configuration of the requested tools
69
- * @returns The tools that are available on the requested chains
70
- */
71
- getTools: (request?: ToolsRequest, options?: RequestOptions) => Promise<ToolsResponse>;
72
- /**
73
- * Get all known tokens.
74
- * @param {TokensRequest?} request - The configuration of the requested tokens
75
- * @returns The tokens that are available on the requested chains
76
- */
77
- getTokens: (request?: TokensRequest, options?: RequestOptions) => Promise<TokensResponse>;
78
- /**
79
- * Get all available chains
80
- * @return {Promise<Chain[]>} A list of all available chains
81
- * @throws {LifiError} Throws a LifiError if request fails.
82
- */
83
- getChains: () => Promise<ExtendedChain[]>;
84
- /**
85
- * Get a set of routes for a request that describes a transfer of tokens.
86
- * @param {RoutesRequest} request - A description of the transfer.
87
- * @return {Promise<RoutesResponse>} The resulting routes that can be used to realize the described transfer of tokens.
88
- * @throws {LifiError} Throws a LifiError if request fails.
89
- */
90
- getRoutes: (request: RoutesRequest, options?: RequestOptions) => Promise<RoutesResponse>;
91
- /**
92
- * Get the transaction data for a single step of a route
93
- * @param {LifiStep} step - The step object.
94
- * @return {Promise<LifiStep>} The step populated with the transaction data.
95
- * @throws {LifiError} Throws a LifiError if request fails.
96
- */
97
- getStepTransaction: (step: LifiStep, options?: RequestOptions) => Promise<LifiStep>;
98
- /**
99
- * Get gas recommendation for a certain chain
100
- * @param {GasRecommendationRequest} request - Configuration of the requested recommendation.
101
- * @throws {LifiError} Throws a LifiError if request fails.
102
- */
103
- getGasRecommendation: (request: GasRecommendationRequest, options?: RequestOptions) => Promise<GasRecommendationResponse>;
104
- /**
105
- * Returns the balances of a specific token a wallet holds across all aggregated chains.
106
- * @param {string} walletAddress - A wallet address.
107
- * @param {Token} token - A Token object.
108
- * @return {Promise<TokenAmount | null>} An object containing the token and the amounts on different chains.
109
- * @throws {ValidationError} Throws a ValidationError if parameters are invalid.
110
- */
111
- getTokenBalance: (walletAddress: string, token: Token) => Promise<TokenAmount | null>;
112
- /**
113
- * Returns the balances for a list tokens a wallet holds across all aggregated chains.
114
- * @param {string} walletAddress - A wallet address.
115
- * @param {Token[]} tokens - A list of Token objects.
116
- * @return {Promise<TokenAmount[]>} A list of objects containing the tokens and the amounts on different chains.
117
- * @throws {ValidationError} Throws a ValidationError if parameters are invalid.
118
- */
119
- getTokenBalances: (walletAddress: string, tokens: Token[]) => Promise<TokenAmount[]>;
120
- /**
121
- * This method queries the balances of tokens for a specific list of chains for a given wallet.
122
- * @param {string} walletAddress - A walletaddress.
123
- * @param {{ [chainId: number]: Token[] }} tokensByChain - A list of Token objects organized by chain ids.
124
- * @return {Promise<{ [chainId: number]: TokenAmount[] }>} A list of objects containing the tokens and the amounts on different chains organized by the chosen chains.
125
- * @throws {ValidationError} Throws a ValidationError if parameters are invalid.
126
- */
127
- getTokenBalancesForChains: (walletAddress: string, tokensByChain: {
128
- [chainId: number]: Token[];
129
- }) => Promise<{
130
- [chainId: number]: TokenAmount[];
131
- }>;
132
- /**
133
- * Get the current approval for a certain token.
134
- * @param signer - The signer owning the token
135
- * @param token - The token that should be checked
136
- * @param approvalAddress - The address that has be approved
137
- */
138
- getTokenApproval: (signer: Signer, token: Token, approvalAddress: string) => Promise<string | undefined>;
139
- /**
140
- * Get the current approval for a list of token / approval address pairs.
141
- * @param signer - The signer owning the tokens
142
- * @param tokenData - A list of token and approval address pairs
143
- */
144
- bulkGetTokenApproval: (signer: Signer, tokenData: RevokeTokenData[]) => Promise<{
145
- token: Token;
146
- approval: string | undefined;
147
- }[]>;
148
- /**
149
- * Set approval for a certain token and amount.
150
- * @param { ApproveTokenRequest } request - The approval request
151
- */
152
- approveToken: (request: ApproveTokenRequest) => Promise<void>;
153
- /**
154
- * Revoke approval for a certain token.
155
- * @param { RevokeApprovalRequest } request - The revoke request
156
- */
157
- revokeTokenApproval: (request: RevokeApprovalRequest) => Promise<void>;
158
- /**
159
- * Get all the available connections for swap/bridging tokens
160
- * @param connectionRequest ConnectionsRequest
161
- * @returns ConnectionsResponse
162
- */
163
- getConnections: (connectionRequest: ConnectionsRequest) => Promise<ConnectionsResponse>;
164
- }
@@ -1,4 +0,0 @@
1
- import { PopulatedTransaction, Signer } from 'ethers';
2
- import { StatusManager } from '../execution/StatusManager';
3
- import { Chain, InternalExecutionSettings, LifiStep } from '../types';
4
- export declare const checkAllowance: (signer: Signer, step: LifiStep, statusManager: StatusManager, settings: InternalExecutionSettings, chain: Chain, allowUserInteraction?: boolean, shouldBatchTransactions?: boolean) => Promise<void | PopulatedTransaction>;
@@ -1,103 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.checkAllowance = void 0;
7
- const bignumber_js_1 = __importDefault(require("bignumber.js"));
8
- const ethers_1 = require("ethers");
9
- const utils_1 = require("../allowance/utils");
10
- const getProvider_1 = require("../utils/getProvider");
11
- const parseError_1 = require("../utils/parseError");
12
- const checkAllowance = async (signer, step, statusManager, settings, chain, allowUserInteraction = false, shouldBatchTransactions = false) => {
13
- // Ask the user to set an allowance
14
- let allowanceProcess = statusManager.findOrCreateProcess(step, 'TOKEN_ALLOWANCE');
15
- // Check allowance
16
- try {
17
- if (allowanceProcess.txHash && allowanceProcess.status !== 'DONE') {
18
- if (allowanceProcess.status !== 'PENDING') {
19
- allowanceProcess = statusManager.updateProcess(step, allowanceProcess.type, 'PENDING');
20
- }
21
- await (0, getProvider_1.getProvider)(signer).waitForTransaction(allowanceProcess.txHash);
22
- allowanceProcess = statusManager.updateProcess(step, allowanceProcess.type, 'DONE');
23
- }
24
- else {
25
- const approvalRequest = {
26
- from: step.action.fromToken.address,
27
- to: step.estimate.approvalAddress,
28
- };
29
- if (settings.updateTransactionRequestHook) {
30
- const config = await settings.updateTransactionRequestHook(approvalRequest);
31
- approvalRequest.gasLimit = config.gasLimit;
32
- approvalRequest.gasPrice = config.gasPrice;
33
- approvalRequest.maxFeePerGas = config.maxFeePerGas;
34
- approvalRequest.maxPriorityFeePerGas = config.maxPriorityFeePerGas;
35
- }
36
- if (!approvalRequest.from) {
37
- throw new Error('Missing Signer address');
38
- }
39
- if (!approvalRequest.to) {
40
- throw new Error('Missing ERC20 contract address');
41
- }
42
- const approved = await (0, utils_1.getApproved)(signer, approvalRequest.from, approvalRequest.to);
43
- if (new bignumber_js_1.default(step.action.fromAmount).gt(approved)) {
44
- if (!allowUserInteraction) {
45
- return;
46
- }
47
- const approvalAmount = settings.infiniteApproval
48
- ? ethers_1.constants.MaxUint256.toString()
49
- : step.action.fromAmount;
50
- if (shouldBatchTransactions) {
51
- const populatedTransaction = await (0, utils_1.setApproval)(signer, step.action.fromToken.address, step.estimate.approvalAddress, approvalAmount, true);
52
- allowanceProcess = statusManager.updateProcess(step, allowanceProcess.type, 'DONE');
53
- return populatedTransaction;
54
- }
55
- const approveTx = (await (0, utils_1.setApproval)(signer, step.action.fromToken.address, step.estimate.approvalAddress, approvalAmount));
56
- allowanceProcess = statusManager.updateProcess(step, allowanceProcess.type, 'PENDING', {
57
- txHash: approveTx.hash,
58
- txLink: chain.metamask.blockExplorerUrls[0] + 'tx/' + approveTx.hash,
59
- });
60
- // Wait for the transcation
61
- await approveTx.wait();
62
- allowanceProcess = statusManager.updateProcess(step, allowanceProcess.type, 'DONE');
63
- }
64
- else {
65
- allowanceProcess = statusManager.updateProcess(step, allowanceProcess.type, 'DONE');
66
- }
67
- }
68
- }
69
- catch (e) {
70
- if (e.code === 'TRANSACTION_REPLACED' && e.replacement) {
71
- await transactionReplaced(e.replacement, allowanceProcess, step, chain, statusManager);
72
- }
73
- else {
74
- const error = await (0, parseError_1.parseError)(e, step, allowanceProcess);
75
- allowanceProcess = statusManager.updateProcess(step, allowanceProcess.type, 'FAILED', {
76
- error: {
77
- message: error.message,
78
- htmlMessage: error.htmlMessage,
79
- code: error.code,
80
- },
81
- });
82
- statusManager.updateExecution(step, 'FAILED');
83
- throw error;
84
- }
85
- }
86
- };
87
- exports.checkAllowance = checkAllowance;
88
- const transactionReplaced = async (replacementTx, allowanceProcess, step, chain, statusManager) => {
89
- try {
90
- allowanceProcess = statusManager.updateProcess(step, allowanceProcess.type, 'PENDING', {
91
- txHash: replacementTx.hash,
92
- txLink: chain.metamask.blockExplorerUrls[0] + 'tx/' + replacementTx.hash,
93
- });
94
- await replacementTx.wait();
95
- allowanceProcess = statusManager.updateProcess(step, allowanceProcess.type, 'DONE');
96
- }
97
- catch (e) {
98
- if (e.code === 'TRANSACTION_REPLACED' && e.replacement) {
99
- await transactionReplaced(e.replacement, allowanceProcess, step, chain, statusManager);
100
- }
101
- throw e;
102
- }
103
- };
@@ -1,2 +0,0 @@
1
- export * from './checkAllowance';
2
- export * from './tokenApproval';