@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
@@ -0,0 +1,268 @@
1
+ import { ConfigService } from '../services/ConfigService.js';
2
+ import { ValidationError } from '../utils/errors.js';
3
+ import { StatusManager } from './StatusManager.js';
4
+ import { prepareRestart } from './prepareRestart.js';
5
+ export class RouteExecutionManager {
6
+ constructor(options) {
7
+ Object.defineProperty(this, "executionDictionary", {
8
+ enumerable: true,
9
+ configurable: true,
10
+ writable: true,
11
+ value: {}
12
+ });
13
+ Object.defineProperty(this, "executionPromiseDictionary", {
14
+ enumerable: true,
15
+ configurable: true,
16
+ writable: true,
17
+ value: {}
18
+ });
19
+ Object.defineProperty(this, "configService", {
20
+ enumerable: true,
21
+ configurable: true,
22
+ writable: true,
23
+ value: void 0
24
+ });
25
+ Object.defineProperty(this, "providers", {
26
+ enumerable: true,
27
+ configurable: true,
28
+ writable: true,
29
+ value: void 0
30
+ });
31
+ /**
32
+ * Execute a route.
33
+ * @param route - The route that should be executed. Cannot be an active route.
34
+ * @param settings - An object containing settings and callbacks.
35
+ * @returns The executed route.
36
+ * @throws {LiFiError} Throws a LiFiError if the execution fails.
37
+ */
38
+ Object.defineProperty(this, "executeRoute", {
39
+ enumerable: true,
40
+ configurable: true,
41
+ writable: true,
42
+ value: async (route, settings) => {
43
+ // Deep clone to prevent side effects
44
+ const clonedRoute = structuredClone(route);
45
+ let executionPromise = this.executionPromiseDictionary[clonedRoute.id];
46
+ // Check if route is already running
47
+ if (executionPromise) {
48
+ return executionPromise;
49
+ }
50
+ executionPromise = this.executeSteps(clonedRoute, settings);
51
+ this.executionPromiseDictionary[clonedRoute.id] = executionPromise;
52
+ return executionPromise;
53
+ }
54
+ });
55
+ /**
56
+ * Resume the execution of a route that has been stopped or had an error while executing.
57
+ * @param route - The route that is to be executed. Cannot be an active route.
58
+ * @param settings - An object containing settings and callbacks.
59
+ * @returns The executed route.
60
+ * @throws {LiFiError} Throws a LiFiError if the execution fails.
61
+ */
62
+ Object.defineProperty(this, "resumeRoute", {
63
+ enumerable: true,
64
+ configurable: true,
65
+ writable: true,
66
+ value: async (route, settings) => {
67
+ // Deep clone to prevent side effects
68
+ const clonedRoute = structuredClone(route);
69
+ const execution = this.executionDictionary[clonedRoute.id];
70
+ if (execution) {
71
+ const executionHalted = execution.executors.some((executor) => !executor.allowExecution);
72
+ if (!executionHalted) {
73
+ // Check if we want to resume route execution in the background
74
+ this.updateRouteExecution(route, {
75
+ executeInBackground: settings?.executeInBackground,
76
+ });
77
+ const executionPromise = this.executionPromiseDictionary[clonedRoute.id];
78
+ return executionPromise ?? clonedRoute;
79
+ }
80
+ }
81
+ await prepareRestart(clonedRoute);
82
+ const executionPromise = this.executeSteps(clonedRoute, settings);
83
+ this.executionPromiseDictionary[clonedRoute.id] = executionPromise;
84
+ return executionPromise;
85
+ }
86
+ });
87
+ Object.defineProperty(this, "executeSteps", {
88
+ enumerable: true,
89
+ configurable: true,
90
+ writable: true,
91
+ value: async (route, settings) => {
92
+ const config = this.configService.getConfig();
93
+ const execution = {
94
+ route,
95
+ executors: [],
96
+ settings: { ...config.defaultExecutionSettings, ...settings },
97
+ };
98
+ this.executionDictionary[route.id] = execution;
99
+ const statusManager = new StatusManager(route, execution.settings, (route) => {
100
+ if (this.executionDictionary[route.id]) {
101
+ execution.route = route;
102
+ }
103
+ });
104
+ // Loop over steps and execute them
105
+ for (let index = 0; index < route.steps.length; index++) {
106
+ const execution = this.executionDictionary[route.id];
107
+ // Check if execution has stopped in the meantime
108
+ if (!execution) {
109
+ break;
110
+ }
111
+ const step = route.steps[index];
112
+ const previousStep = route.steps[index - 1];
113
+ // Check if the step is already done
114
+ //
115
+ if (step.execution?.status === 'DONE') {
116
+ continue;
117
+ }
118
+ // Update amount using output of previous execution. In the future this should be handled by calling `updateRoute`
119
+ if (previousStep?.execution?.toAmount) {
120
+ step.action.fromAmount = previousStep.execution.toAmount;
121
+ }
122
+ try {
123
+ const provider = this.providers?.find((provider) => provider.isProviderStep(step));
124
+ if (!provider) {
125
+ throw new Error('SDK Execution Provider not found.');
126
+ }
127
+ const stepExecutor = await provider.getStepExecutor({
128
+ statusManager,
129
+ settings: execution.settings,
130
+ });
131
+ execution.executors.push(stepExecutor);
132
+ // Check if we want to execute this step in the background
133
+ this.updateRouteExecution(route, execution.settings);
134
+ const executedStep = await stepExecutor.executeStep(step);
135
+ // We may reach this point if user interaction isn't allowed. We want to stop execution until we resume it
136
+ if (executedStep.execution?.status !== 'DONE') {
137
+ this.stopExecution(route);
138
+ }
139
+ // Execution stopped during the current step, we don't want to continue to the next step so we return already
140
+ if (stepExecutor.allowExecution) {
141
+ return route;
142
+ }
143
+ }
144
+ catch (e) {
145
+ this.stopExecution(route);
146
+ throw e;
147
+ }
148
+ }
149
+ // Clean up after the execution
150
+ delete this.executionDictionary[route.id];
151
+ return route;
152
+ }
153
+ });
154
+ /**
155
+ * Updates route execution to background or foreground state.
156
+ * @param route - A route that is currently in execution.
157
+ * @param settings - An object with execution settings.
158
+ */
159
+ Object.defineProperty(this, "updateRouteExecution", {
160
+ enumerable: true,
161
+ configurable: true,
162
+ writable: true,
163
+ value: (route, settings) => {
164
+ const execution = this.executionDictionary[route.id];
165
+ if (!execution) {
166
+ return;
167
+ }
168
+ for (const executor of execution.executors) {
169
+ executor.setInteraction({
170
+ allowInteraction: !settings.executeInBackground,
171
+ allowUpdates: true,
172
+ });
173
+ }
174
+ // Update active route settings so we know what the current state of execution is
175
+ execution.settings = {
176
+ ...execution.settings,
177
+ ...settings,
178
+ };
179
+ }
180
+ });
181
+ /**
182
+ * Update the ExecutionSettings for an active route.
183
+ * @param settings - An object with execution settings.
184
+ * @param route - The active route that gets the new execution settings.
185
+ * @throws {ValidationError} Throws a ValidationError if parameters are invalid.
186
+ */
187
+ Object.defineProperty(this, "updateExecutionSettings", {
188
+ enumerable: true,
189
+ configurable: true,
190
+ writable: true,
191
+ value: (settings, route) => {
192
+ const execution = this.executionDictionary[route.id];
193
+ if (!execution) {
194
+ throw new ValidationError("Can't set ExecutionSettings for the inactive route.");
195
+ }
196
+ const config = this.configService.getConfig();
197
+ execution.settings = {
198
+ ...config.defaultExecutionSettings,
199
+ ...settings,
200
+ };
201
+ }
202
+ });
203
+ /**
204
+ * Stops the execution of an active route.
205
+ * @param route - A route that is currently in execution.
206
+ * @returns The stopped route.
207
+ */
208
+ Object.defineProperty(this, "stopExecution", {
209
+ enumerable: true,
210
+ configurable: true,
211
+ writable: true,
212
+ value: (route) => {
213
+ const execution = this.executionDictionary[route.id];
214
+ if (!execution) {
215
+ return route;
216
+ }
217
+ for (const executor of execution.executors) {
218
+ executor.setInteraction({
219
+ allowInteraction: false,
220
+ allowUpdates: false,
221
+ allowExecution: false,
222
+ });
223
+ }
224
+ delete this.executionDictionary[route.id];
225
+ return route;
226
+ }
227
+ });
228
+ /**
229
+ * Get the list of active routes.
230
+ * @returns A list of routes.
231
+ */
232
+ Object.defineProperty(this, "getActiveRoutes", {
233
+ enumerable: true,
234
+ configurable: true,
235
+ writable: true,
236
+ value: () => {
237
+ return Object.values(this.executionDictionary)
238
+ .map((dict) => dict?.route)
239
+ .filter(Boolean);
240
+ }
241
+ });
242
+ /**
243
+ * Return the current route information for given route. The route has to be active.
244
+ * @param route - A route object.
245
+ * @returns The updated route.
246
+ */
247
+ Object.defineProperty(this, "getActiveRoute", {
248
+ enumerable: true,
249
+ configurable: true,
250
+ writable: true,
251
+ value: (route) => {
252
+ return this.executionDictionary[route.id]?.route;
253
+ }
254
+ });
255
+ Object.defineProperty(this, "getProvider", {
256
+ enumerable: true,
257
+ configurable: true,
258
+ writable: true,
259
+ value: (type) => {
260
+ return this.providers?.find((provider) => provider.type === type);
261
+ }
262
+ });
263
+ this.configService = ConfigService.getInstance();
264
+ this.configService.updateConfig(options);
265
+ this.providers = options.providers;
266
+ }
267
+ }
268
+ //# sourceMappingURL=RouteExecutionManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RouteExecutionManager.js","sourceRoot":"","sources":["../../../src/execution/RouteExecutionManager.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAA;AAE5D,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAA;AAQpD,MAAM,OAAO,qBAAqB;IAMhC,YAAY,OAAmB;QALvB;;;;mBAAgD,EAAE;WAAA;QAClD;;;;mBAA8D,EAAE;WAAA;QAC9D;;;;;WAA4B;QAC9B;;;;;WAAyB;QAQjC;;;;;;WAMG;QACH;;;;mBAAe,KAAK,EAClB,KAAY,EACZ,QAA4B,EACZ,EAAE;gBAClB,qCAAqC;gBACrC,MAAM,WAAW,GAAG,eAAe,CAAQ,KAAK,CAAC,CAAA;gBAEjD,IAAI,gBAAgB,GAAG,IAAI,CAAC,0BAA0B,CAAC,WAAW,CAAC,EAAE,CAAC,CAAA;gBACtE,oCAAoC;gBACpC,IAAI,gBAAgB,EAAE;oBACpB,OAAO,gBAAgB,CAAA;iBACxB;gBAED,gBAAgB,GAAG,IAAI,CAAC,YAAY,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAA;gBAE3D,IAAI,CAAC,0BAA0B,CAAC,WAAW,CAAC,EAAE,CAAC,GAAG,gBAAgB,CAAA;gBAElE,OAAO,gBAAgB,CAAA;YACzB,CAAC;WAAA;QAED;;;;;;WAMG;QACH;;;;mBAAc,KAAK,EACjB,KAAY,EACZ,QAA4B,EACZ,EAAE;gBAClB,qCAAqC;gBACrC,MAAM,WAAW,GAAG,eAAe,CAAQ,KAAK,CAAC,CAAA;gBAEjD,MAAM,SAAS,GAAG,IAAI,CAAC,mBAAmB,CAAC,WA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;;;mBAAc,CAAC,IAAkB,EAA2B,EAAE;gBAC5D,OAAO,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,KAAK,IAAI,CAAC,CAAA;YACnE,CAAC;WAAA;QA3PC,IAAI,CAAC,aAAa,GAAG,aAAa,CAAC,WAAW,EAAE,CAAA;QAChD,IAAI,CAAC,aAAa,CAAC,YAAY,CAAC,OAAO,CAAC,CAAA;QACxC,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,CAAA;IACpC,CAAC;CAyPF"}
@@ -0,0 +1,216 @@
1
+ import { emptyExecution } from '@lifi/types';
2
+ import { getProcessMessage } from './utils.js';
3
+ /**
4
+ * Manages status updates of a route and provides various functions for tracking processes
5
+ * @param {Route} route The route this StatusManger belongs to.
6
+ * @param {InternalExecutionSettings} settings The ExecutionSettings for this route.
7
+ * @param {InternalUpdateRouteCallback} internalUpdateRouteCallback Internal callback to propage route changes.
8
+ * @returns {StatusManager} An instance of StatusManager.
9
+ */
10
+ export class StatusManager {
11
+ constructor(route, settings, internalUpdateRouteCallback) {
12
+ Object.defineProperty(this, "route", {
13
+ enumerable: true,
14
+ configurable: true,
15
+ writable: true,
16
+ value: void 0
17
+ });
18
+ Object.defineProperty(this, "settings", {
19
+ enumerable: true,
20
+ configurable: true,
21
+ writable: true,
22
+ value: void 0
23
+ });
24
+ Object.defineProperty(this, "internalUpdateRouteCallback", {
25
+ enumerable: true,
26
+ configurable: true,
27
+ writable: true,
28
+ value: void 0
29
+ });
30
+ Object.defineProperty(this, "shouldUpdate", {
31
+ enumerable: true,
32
+ configurable: true,
33
+ writable: true,
34
+ value: true
35
+ });
36
+ /**
37
+ * Initializes the execution object of a Step.
38
+ * @param step The current step in execution
39
+ * @returns The initialized execution object for this step and a function to update this step
40
+ */
41
+ Object.defineProperty(this, "initExecutionObject", {
42
+ enumerable: true,
43
+ configurable: true,
44
+ writable: true,
45
+ value: (step) => {
46
+ const currentExecution = step.execution || structuredClone(emptyExecution);
47
+ if (!step.execution) {
48
+ step.execution = currentExecution;
49
+ step.execution.status = 'PENDING';
50
+ this.updateStepInRoute(step);
51
+ }
52
+ // Change status to PENDING after resuming from FAILED
53
+ if (currentExecution.status === 'FAILED') {
54
+ currentExecution.status = 'PENDING';
55
+ this.updateStepInRoute(step);
56
+ }
57
+ return currentExecution;
58
+ }
59
+ });
60
+ /**
61
+ * Create and push a new process into the execution.
62
+ * @param step The step that should contain the new process.
63
+ * @param type Type of the process. Used to identify already existing processes.
64
+ * @param status By default created procces is set to the STARTED status. We can override new process with the needed status.
65
+ * @returns Returns process.
66
+ */
67
+ Object.defineProperty(this, "findOrCreateProcess", {
68
+ enumerable: true,
69
+ configurable: true,
70
+ writable: true,
71
+ value: (step, type, status) => {
72
+ if (!step.execution?.process) {
73
+ throw new Error("Execution hasn't been initialized.");
74
+ }
75
+ const process = step.execution.process.find((p) => p.type === type);
76
+ if (process) {
77
+ if (status && process.status !== status) {
78
+ process.status = status;
79
+ this.updateStepInRoute(step);
80
+ }
81
+ return process;
82
+ }
83
+ const newProcess = {
84
+ type: type,
85
+ startedAt: Date.now(),
86
+ message: getProcessMessage(type, status ?? 'STARTED'),
87
+ status: status ?? 'STARTED',
88
+ };
89
+ step.execution.process.push(newProcess);
90
+ this.updateStepInRoute(step);
91
+ return newProcess;
92
+ }
93
+ });
94
+ /**
95
+ * Update a process object.
96
+ * @param step The step where the process should be updated
97
+ * @param type The process type to update
98
+ * @param status The status the process gets.
99
+ * @param [params] Additional parameters to append to the process.
100
+ * @returns The update process
101
+ */
102
+ Object.defineProperty(this, "updateProcess", {
103
+ enumerable: true,
104
+ configurable: true,
105
+ writable: true,
106
+ value: (step, type, status, params) => {
107
+ if (!step.execution) {
108
+ throw new Error("Can't update an empty step execution.");
109
+ }
110
+ const currentProcess = step?.execution?.process.find((p) => p.type === type);
111
+ if (!currentProcess) {
112
+ throw new Error("Can't find a process for the given type.");
113
+ }
114
+ switch (status) {
115
+ case 'CANCELLED':
116
+ currentProcess.doneAt = Date.now();
117
+ break;
118
+ case 'FAILED':
119
+ currentProcess.doneAt = Date.now();
120
+ step.execution.status = 'FAILED';
121
+ break;
122
+ case 'DONE':
123
+ currentProcess.doneAt = Date.now();
124
+ break;
125
+ case 'PENDING':
126
+ step.execution.status = 'PENDING';
127
+ break;
128
+ case 'ACTION_REQUIRED':
129
+ step.execution.status = 'ACTION_REQUIRED';
130
+ break;
131
+ default:
132
+ break;
133
+ }
134
+ currentProcess.status = status;
135
+ currentProcess.message = getProcessMessage(type, status);
136
+ // set extra parameters or overwritte the standard params set in the switch statement
137
+ if (params) {
138
+ for (const [key, value] of Object.entries(params)) {
139
+ currentProcess[key] = value;
140
+ }
141
+ }
142
+ // Sort processes, the ones with DONE status go first
143
+ step.execution.process = [
144
+ ...step?.execution?.process.filter((process) => process.status === 'DONE'),
145
+ ...step?.execution?.process.filter((process) => process.status !== 'DONE'),
146
+ ];
147
+ this.updateStepInRoute(step); // updates the step in the route
148
+ return currentProcess;
149
+ }
150
+ });
151
+ /**
152
+ * Remove a process from the execution
153
+ * @param step The step where the process should be removed from
154
+ * @param type The process type to remove
155
+ */
156
+ Object.defineProperty(this, "removeProcess", {
157
+ enumerable: true,
158
+ configurable: true,
159
+ writable: true,
160
+ value: (step, type) => {
161
+ if (!step.execution) {
162
+ throw new Error("Execution hasn't been initialized.");
163
+ }
164
+ const index = step.execution.process.findIndex((p) => p.type === type);
165
+ step.execution.process.splice(index, 1);
166
+ this.updateStepInRoute(step);
167
+ }
168
+ });
169
+ Object.defineProperty(this, "updateStepInRoute", {
170
+ enumerable: true,
171
+ configurable: true,
172
+ writable: true,
173
+ value: (step) => {
174
+ if (!this.shouldUpdate) {
175
+ return step;
176
+ }
177
+ const stepIndex = this.route.steps.findIndex((routeStep) => routeStep.id === step.id);
178
+ if (stepIndex === -1) {
179
+ throw new Error("Couldn't find a step to update.");
180
+ }
181
+ this.route.steps[stepIndex] = Object.assign(this.route.steps[stepIndex], step);
182
+ this.settings.updateRouteHook(this.route);
183
+ this.internalUpdateRouteCallback(this.route);
184
+ return this.route.steps[stepIndex];
185
+ }
186
+ });
187
+ this.route = route;
188
+ this.settings = settings;
189
+ this.internalUpdateRouteCallback = internalUpdateRouteCallback;
190
+ }
191
+ /**
192
+ * Updates the execution object of a Step.
193
+ * @param step The current step in execution
194
+ * @param status The status for the execution
195
+ * @param receipt Optional. Information about received tokens
196
+ * @returns The step with the updated execution object
197
+ */
198
+ updateExecution(step, status, receipt) {
199
+ if (!step.execution) {
200
+ throw Error("Can't update empty execution.");
201
+ }
202
+ step.execution.status = status;
203
+ if (receipt) {
204
+ step.execution = {
205
+ ...step.execution,
206
+ ...receipt,
207
+ };
208
+ }
209
+ this.updateStepInRoute(step);
210
+ return step;
211
+ }
212
+ allowUpdates(value) {
213
+ this.shouldUpdate = value;
214
+ }
215
+ }
216
+ //# sourceMappingURL=StatusManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"StatusManager.js","sourceRoot":"","sources":["../../../src/execution/StatusManager.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAE5C,OAAO,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAA;AA6B9C;;;;;;GAMG;AACH,MAAM,OAAO,aAAa;IAMxB,YACE,KAAY,EACZ,QAAmC,EACnC,2BAAwD;QARzC;;;;;WAAY;QACZ;;;;;WAAmC;QACnC;;;;;WAAwD;QACjE;;;;mBAAe,IAAI;WAAA;QAY3B;;;;WAIG;QACH;;;;mBAAsB,CAAC,IAAc,EAAa,EAAE;gBAClD,MAAM,gBAAgB,GACpB,IAAI,CAAC,SAAS,IAAI,eAAe,CAAY,cAAc,CAAC,CAAA;gBAE9D,IAAI,CAAC,IAAI,CAAC,SAAS,EAAE;oBACnB,IAAI,CAAC,SAAS,GAAG,gBAAgB,CAAA;oBACjC,IAAI,CAAC,SAAS,CAAC,MAAM,GAAG,SAAS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