@lifi/sdk 0.0.0-preview-f5cf9f8

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 (555) hide show
  1. package/CHANGELOG.md +1213 -0
  2. package/LICENSE +201 -0
  3. package/README.md +79 -0
  4. package/dist/cjs/actions/getChains.d.ts +17 -0
  5. package/dist/cjs/actions/getChains.js +28 -0
  6. package/dist/cjs/actions/getChains.js.map +1 -0
  7. package/dist/cjs/actions/getConnections.d.ts +15 -0
  8. package/dist/cjs/actions/getConnections.js +34 -0
  9. package/dist/cjs/actions/getConnections.js.map +1 -0
  10. package/dist/cjs/actions/getContractCallsQuote.d.ts +16 -0
  11. package/dist/cjs/actions/getContractCallsQuote.js +45 -0
  12. package/dist/cjs/actions/getContractCallsQuote.js.map +1 -0
  13. package/dist/cjs/actions/getGasRecommendation.d.ts +16 -0
  14. package/dist/cjs/actions/getGasRecommendation.js +24 -0
  15. package/dist/cjs/actions/getGasRecommendation.js.map +1 -0
  16. package/dist/cjs/actions/getNameServiceAddress.d.ts +15 -0
  17. package/dist/cjs/actions/getNameServiceAddress.js +29 -0
  18. package/dist/cjs/actions/getNameServiceAddress.js.map +1 -0
  19. package/dist/cjs/actions/getQuote.d.ts +18 -0
  20. package/dist/cjs/actions/getQuote.js +35 -0
  21. package/dist/cjs/actions/getQuote.js.map +1 -0
  22. package/dist/cjs/actions/getRelayedTransactionStatus.d.ts +16 -0
  23. package/dist/cjs/actions/getRelayedTransactionStatus.js +30 -0
  24. package/dist/cjs/actions/getRelayedTransactionStatus.js.map +1 -0
  25. package/dist/cjs/actions/getRelayerQuote.d.ts +17 -0
  26. package/dist/cjs/actions/getRelayerQuote.js +44 -0
  27. package/dist/cjs/actions/getRelayerQuote.js.map +1 -0
  28. package/dist/cjs/actions/getRoutes.d.ts +16 -0
  29. package/dist/cjs/actions/getRoutes.js +32 -0
  30. package/dist/cjs/actions/getRoutes.js.map +1 -0
  31. package/dist/cjs/actions/getStatus.d.ts +17 -0
  32. package/dist/cjs/actions/getStatus.js +22 -0
  33. package/dist/cjs/actions/getStatus.js.map +1 -0
  34. package/dist/cjs/actions/getStepTransaction.d.ts +16 -0
  35. package/dist/cjs/actions/getStepTransaction.js +36 -0
  36. package/dist/cjs/actions/getStepTransaction.js.map +1 -0
  37. package/dist/cjs/actions/getToken.d.ts +17 -0
  38. package/dist/cjs/actions/getToken.js +26 -0
  39. package/dist/cjs/actions/getToken.js.map +1 -0
  40. package/dist/cjs/actions/getTokenBalance.d.ts +17 -0
  41. package/dist/cjs/actions/getTokenBalance.js +20 -0
  42. package/dist/cjs/actions/getTokenBalance.js.map +1 -0
  43. package/dist/cjs/actions/getTokenBalances.d.ts +17 -0
  44. package/dist/cjs/actions/getTokenBalances.js +15 -0
  45. package/dist/cjs/actions/getTokenBalances.js.map +1 -0
  46. package/dist/cjs/actions/getTokenBalancesByChain.d.ts +21 -0
  47. package/dist/cjs/actions/getTokenBalancesByChain.js +25 -0
  48. package/dist/cjs/actions/getTokenBalancesByChain.js.map +1 -0
  49. package/dist/cjs/actions/getTokens.d.ts +20 -0
  50. package/dist/cjs/actions/getTokens.js +17 -0
  51. package/dist/cjs/actions/getTokens.js.map +1 -0
  52. package/dist/cjs/actions/getTools.d.ts +15 -0
  53. package/dist/cjs/actions/getTools.js +21 -0
  54. package/dist/cjs/actions/getTools.js.map +1 -0
  55. package/dist/cjs/actions/getTransactionHistory.d.ts +26 -0
  56. package/dist/cjs/actions/getTransactionHistory.js +31 -0
  57. package/dist/cjs/actions/getTransactionHistory.js.map +1 -0
  58. package/dist/cjs/actions/getWalletBalances.d.ts +16 -0
  59. package/dist/cjs/actions/getWalletBalances.js +20 -0
  60. package/dist/cjs/actions/getWalletBalances.js.map +1 -0
  61. package/dist/cjs/actions/index.d.ts +172 -0
  62. package/dist/cjs/actions/index.js +52 -0
  63. package/dist/cjs/actions/index.js.map +1 -0
  64. package/dist/cjs/actions/patchContractCalls.d.ts +15 -0
  65. package/dist/cjs/actions/patchContractCalls.js +15 -0
  66. package/dist/cjs/actions/patchContractCalls.js.map +1 -0
  67. package/dist/cjs/actions/relayTransaction.d.ts +16 -0
  68. package/dist/cjs/actions/relayTransaction.js +34 -0
  69. package/dist/cjs/actions/relayTransaction.js.map +1 -0
  70. package/dist/cjs/client/createClient.d.ts +7 -0
  71. package/dist/cjs/client/createClient.js +70 -0
  72. package/dist/cjs/client/createClient.js.map +1 -0
  73. package/dist/cjs/client/getClientStorage.d.ts +14 -0
  74. package/dist/cjs/client/getClientStorage.js +48 -0
  75. package/dist/cjs/client/getClientStorage.js.map +1 -0
  76. package/dist/cjs/core/BaseStepExecutionTask.d.ts +10 -0
  77. package/dist/cjs/core/BaseStepExecutionTask.js +11 -0
  78. package/dist/cjs/core/BaseStepExecutionTask.js.map +1 -0
  79. package/dist/cjs/core/BaseStepExecutor.d.ts +24 -0
  80. package/dist/cjs/core/BaseStepExecutor.js +71 -0
  81. package/dist/cjs/core/BaseStepExecutor.js.map +1 -0
  82. package/dist/cjs/core/StatusManager.d.ts +83 -0
  83. package/dist/cjs/core/StatusManager.js +160 -0
  84. package/dist/cjs/core/StatusManager.js.map +1 -0
  85. package/dist/cjs/core/TaskPipeline.d.ts +12 -0
  86. package/dist/cjs/core/TaskPipeline.js +21 -0
  87. package/dist/cjs/core/TaskPipeline.js.map +1 -0
  88. package/dist/cjs/core/actionMessages.d.ts +9 -0
  89. package/dist/cjs/core/actionMessages.js +81 -0
  90. package/dist/cjs/core/actionMessages.js.map +1 -0
  91. package/dist/cjs/core/execution.d.ts +48 -0
  92. package/dist/cjs/core/execution.js +147 -0
  93. package/dist/cjs/core/execution.js.map +1 -0
  94. package/dist/cjs/core/executionState.d.ts +21 -0
  95. package/dist/cjs/core/executionState.js +29 -0
  96. package/dist/cjs/core/executionState.js.map +1 -0
  97. package/dist/cjs/core/prepareRestart.d.ts +7 -0
  98. package/dist/cjs/core/prepareRestart.js +21 -0
  99. package/dist/cjs/core/prepareRestart.js.map +1 -0
  100. package/dist/cjs/core/storage.d.ts +21 -0
  101. package/dist/cjs/core/storage.js +35 -0
  102. package/dist/cjs/core/storage.js.map +1 -0
  103. package/dist/cjs/core/tasks/CheckBalanceTask.d.ts +19 -0
  104. package/dist/cjs/core/tasks/CheckBalanceTask.js +35 -0
  105. package/dist/cjs/core/tasks/CheckBalanceTask.js.map +1 -0
  106. package/dist/cjs/core/tasks/PrepareTransactionTask.d.ts +10 -0
  107. package/dist/cjs/core/tasks/PrepareTransactionTask.js +30 -0
  108. package/dist/cjs/core/tasks/PrepareTransactionTask.js.map +1 -0
  109. package/dist/cjs/core/tasks/WaitForTransactionStatusTask.d.ts +13 -0
  110. package/dist/cjs/core/tasks/WaitForTransactionStatusTask.js +63 -0
  111. package/dist/cjs/core/tasks/WaitForTransactionStatusTask.js.map +1 -0
  112. package/dist/cjs/core/tasks/helpers/checkBalance.d.ts +30 -0
  113. package/dist/cjs/core/tasks/helpers/checkBalance.js +108 -0
  114. package/dist/cjs/core/tasks/helpers/checkBalance.js.map +1 -0
  115. package/dist/cjs/core/tasks/helpers/getTransactionRequestData.d.ts +7 -0
  116. package/dist/cjs/core/tasks/helpers/getTransactionRequestData.js +25 -0
  117. package/dist/cjs/core/tasks/helpers/getTransactionRequestData.js.map +1 -0
  118. package/dist/cjs/core/tasks/helpers/stepComparison.d.ts +21 -0
  119. package/dist/cjs/core/tasks/helpers/stepComparison.js +32 -0
  120. package/dist/cjs/core/tasks/helpers/stepComparison.js.map +1 -0
  121. package/dist/cjs/core/tasks/helpers/waitForTransactionStatus.d.ts +9 -0
  122. package/dist/cjs/core/tasks/helpers/waitForTransactionStatus.js +48 -0
  123. package/dist/cjs/core/tasks/helpers/waitForTransactionStatus.js.map +1 -0
  124. package/dist/cjs/core/utils.d.ts +17 -0
  125. package/dist/cjs/core/utils.js +42 -0
  126. package/dist/cjs/core/utils.js.map +1 -0
  127. package/dist/cjs/errors/SDKError.d.ts +17 -0
  128. package/dist/cjs/errors/SDKError.js +24 -0
  129. package/dist/cjs/errors/SDKError.js.map +1 -0
  130. package/dist/cjs/errors/baseError.d.ts +11 -0
  131. package/dist/cjs/errors/baseError.js +19 -0
  132. package/dist/cjs/errors/baseError.js.map +1 -0
  133. package/dist/cjs/errors/constants.d.ts +55 -0
  134. package/dist/cjs/errors/constants.js +61 -0
  135. package/dist/cjs/errors/constants.js.map +1 -0
  136. package/dist/cjs/errors/errors.d.ts +38 -0
  137. package/dist/cjs/errors/errors.js +62 -0
  138. package/dist/cjs/errors/errors.js.map +1 -0
  139. package/dist/cjs/errors/httpError.d.ts +24 -0
  140. package/dist/cjs/errors/httpError.js +70 -0
  141. package/dist/cjs/errors/httpError.js.map +1 -0
  142. package/dist/cjs/errors/utils/baseErrorRootCause.d.ts +8 -0
  143. package/dist/cjs/errors/utils/baseErrorRootCause.js +18 -0
  144. package/dist/cjs/errors/utils/baseErrorRootCause.js.map +1 -0
  145. package/dist/cjs/errors/utils/rootCause.d.ts +5 -0
  146. package/dist/cjs/errors/utils/rootCause.js +11 -0
  147. package/dist/cjs/errors/utils/rootCause.js.map +1 -0
  148. package/dist/cjs/index.d.ts +55 -0
  149. package/dist/cjs/index.js +130 -0
  150. package/dist/cjs/package.json +1 -0
  151. package/dist/cjs/types/actions.d.ts +14 -0
  152. package/dist/cjs/types/actions.js +0 -0
  153. package/dist/cjs/types/core.d.ts +184 -0
  154. package/dist/cjs/types/core.js +0 -0
  155. package/dist/cjs/types/execution.d.ts +28 -0
  156. package/dist/cjs/types/execution.js +0 -0
  157. package/dist/cjs/types/request.d.ts +7 -0
  158. package/dist/cjs/types/request.js +0 -0
  159. package/dist/cjs/utils/checkPackageUpdates.d.ts +5 -0
  160. package/dist/cjs/utils/checkPackageUpdates.js +15 -0
  161. package/dist/cjs/utils/checkPackageUpdates.js.map +1 -0
  162. package/dist/cjs/utils/convertQuoteToRoute.d.ts +22 -0
  163. package/dist/cjs/utils/convertQuoteToRoute.js +88 -0
  164. package/dist/cjs/utils/convertQuoteToRoute.js.map +1 -0
  165. package/dist/cjs/utils/decode.d.ts +5 -0
  166. package/dist/cjs/utils/decode.js +9 -0
  167. package/dist/cjs/utils/decode.js.map +1 -0
  168. package/dist/cjs/utils/fetchTxErrorDetails.d.ts +5 -0
  169. package/dist/cjs/utils/fetchTxErrorDetails.js +13 -0
  170. package/dist/cjs/utils/fetchTxErrorDetails.js.map +1 -0
  171. package/dist/cjs/utils/formatUnits.d.ts +8 -0
  172. package/dist/cjs/utils/formatUnits.js +18 -0
  173. package/dist/cjs/utils/formatUnits.js.map +1 -0
  174. package/dist/cjs/utils/getTransactionMessage.d.ts +8 -0
  175. package/dist/cjs/utils/getTransactionMessage.js +12 -0
  176. package/dist/cjs/utils/getTransactionMessage.js.map +1 -0
  177. package/dist/cjs/utils/isHex.d.ts +10 -0
  178. package/dist/cjs/utils/isHex.js +11 -0
  179. package/dist/cjs/utils/isHex.js.map +1 -0
  180. package/dist/cjs/utils/isRoutesRequest.d.ts +7 -0
  181. package/dist/cjs/utils/isRoutesRequest.js +11 -0
  182. package/dist/cjs/utils/isRoutesRequest.js.map +1 -0
  183. package/dist/cjs/utils/isStep.d.ts +7 -0
  184. package/dist/cjs/utils/isStep.js +23 -0
  185. package/dist/cjs/utils/isStep.js.map +1 -0
  186. package/dist/cjs/utils/isToken.d.ts +7 -0
  187. package/dist/cjs/utils/isToken.js +10 -0
  188. package/dist/cjs/utils/isToken.js.map +1 -0
  189. package/dist/cjs/utils/parseUnits.d.ts +8 -0
  190. package/dist/cjs/utils/parseUnits.js +35 -0
  191. package/dist/cjs/utils/parseUnits.js.map +1 -0
  192. package/dist/cjs/utils/request.d.ts +11 -0
  193. package/dist/cjs/utils/request.js +56 -0
  194. package/dist/cjs/utils/request.js.map +1 -0
  195. package/dist/cjs/utils/sleep.d.ts +5 -0
  196. package/dist/cjs/utils/sleep.js +11 -0
  197. package/dist/cjs/utils/sleep.js.map +1 -0
  198. package/dist/cjs/utils/waitForResult.d.ts +14 -0
  199. package/dist/cjs/utils/waitForResult.js +36 -0
  200. package/dist/cjs/utils/waitForResult.js.map +1 -0
  201. package/dist/cjs/utils/withDedupe.d.ts +23 -0
  202. package/dist/cjs/utils/withDedupe.js +34 -0
  203. package/dist/cjs/utils/withDedupe.js.map +1 -0
  204. package/dist/cjs/utils/withTimeout.d.ts +26 -0
  205. package/dist/cjs/utils/withTimeout.js +35 -0
  206. package/dist/cjs/utils/withTimeout.js.map +1 -0
  207. package/dist/cjs/version.d.ts +6 -0
  208. package/dist/cjs/version.js +9 -0
  209. package/dist/cjs/version.js.map +1 -0
  210. package/dist/esm/actions/getChains.d.ts +17 -0
  211. package/dist/esm/actions/getChains.d.ts.map +1 -0
  212. package/dist/esm/actions/getChains.js +26 -0
  213. package/dist/esm/actions/getChains.js.map +1 -0
  214. package/dist/esm/actions/getConnections.d.ts +15 -0
  215. package/dist/esm/actions/getConnections.d.ts.map +1 -0
  216. package/dist/esm/actions/getConnections.js +33 -0
  217. package/dist/esm/actions/getConnections.js.map +1 -0
  218. package/dist/esm/actions/getContractCallsQuote.d.ts +16 -0
  219. package/dist/esm/actions/getContractCallsQuote.d.ts.map +1 -0
  220. package/dist/esm/actions/getContractCallsQuote.js +44 -0
  221. package/dist/esm/actions/getContractCallsQuote.js.map +1 -0
  222. package/dist/esm/actions/getGasRecommendation.d.ts +16 -0
  223. package/dist/esm/actions/getGasRecommendation.d.ts.map +1 -0
  224. package/dist/esm/actions/getGasRecommendation.js +23 -0
  225. package/dist/esm/actions/getGasRecommendation.js.map +1 -0
  226. package/dist/esm/actions/getNameServiceAddress.d.ts +15 -0
  227. package/dist/esm/actions/getNameServiceAddress.d.ts.map +1 -0
  228. package/dist/esm/actions/getNameServiceAddress.js +28 -0
  229. package/dist/esm/actions/getNameServiceAddress.js.map +1 -0
  230. package/dist/esm/actions/getQuote.d.ts +18 -0
  231. package/dist/esm/actions/getQuote.d.ts.map +1 -0
  232. package/dist/esm/actions/getQuote.js +34 -0
  233. package/dist/esm/actions/getQuote.js.map +1 -0
  234. package/dist/esm/actions/getRelayedTransactionStatus.d.ts +16 -0
  235. package/dist/esm/actions/getRelayedTransactionStatus.d.ts.map +1 -0
  236. package/dist/esm/actions/getRelayedTransactionStatus.js +29 -0
  237. package/dist/esm/actions/getRelayedTransactionStatus.js.map +1 -0
  238. package/dist/esm/actions/getRelayerQuote.d.ts +17 -0
  239. package/dist/esm/actions/getRelayerQuote.d.ts.map +1 -0
  240. package/dist/esm/actions/getRelayerQuote.js +43 -0
  241. package/dist/esm/actions/getRelayerQuote.js.map +1 -0
  242. package/dist/esm/actions/getRoutes.d.ts +16 -0
  243. package/dist/esm/actions/getRoutes.d.ts.map +1 -0
  244. package/dist/esm/actions/getRoutes.js +31 -0
  245. package/dist/esm/actions/getRoutes.js.map +1 -0
  246. package/dist/esm/actions/getStatus.d.ts +17 -0
  247. package/dist/esm/actions/getStatus.d.ts.map +1 -0
  248. package/dist/esm/actions/getStatus.js +21 -0
  249. package/dist/esm/actions/getStatus.js.map +1 -0
  250. package/dist/esm/actions/getStepTransaction.d.ts +16 -0
  251. package/dist/esm/actions/getStepTransaction.d.ts.map +1 -0
  252. package/dist/esm/actions/getStepTransaction.js +35 -0
  253. package/dist/esm/actions/getStepTransaction.js.map +1 -0
  254. package/dist/esm/actions/getToken.d.ts +17 -0
  255. package/dist/esm/actions/getToken.d.ts.map +1 -0
  256. package/dist/esm/actions/getToken.js +25 -0
  257. package/dist/esm/actions/getToken.js.map +1 -0
  258. package/dist/esm/actions/getTokenBalance.d.ts +17 -0
  259. package/dist/esm/actions/getTokenBalance.d.ts.map +1 -0
  260. package/dist/esm/actions/getTokenBalance.js +19 -0
  261. package/dist/esm/actions/getTokenBalance.js.map +1 -0
  262. package/dist/esm/actions/getTokenBalances.d.ts +17 -0
  263. package/dist/esm/actions/getTokenBalances.d.ts.map +1 -0
  264. package/dist/esm/actions/getTokenBalances.js +14 -0
  265. package/dist/esm/actions/getTokenBalances.js.map +1 -0
  266. package/dist/esm/actions/getTokenBalancesByChain.d.ts +21 -0
  267. package/dist/esm/actions/getTokenBalancesByChain.d.ts.map +1 -0
  268. package/dist/esm/actions/getTokenBalancesByChain.js +24 -0
  269. package/dist/esm/actions/getTokenBalancesByChain.js.map +1 -0
  270. package/dist/esm/actions/getTokens.d.ts +20 -0
  271. package/dist/esm/actions/getTokens.d.ts.map +1 -0
  272. package/dist/esm/actions/getTokens.js +16 -0
  273. package/dist/esm/actions/getTokens.js.map +1 -0
  274. package/dist/esm/actions/getTools.d.ts +15 -0
  275. package/dist/esm/actions/getTools.d.ts.map +1 -0
  276. package/dist/esm/actions/getTools.js +20 -0
  277. package/dist/esm/actions/getTools.js.map +1 -0
  278. package/dist/esm/actions/getTransactionHistory.d.ts +26 -0
  279. package/dist/esm/actions/getTransactionHistory.d.ts.map +1 -0
  280. package/dist/esm/actions/getTransactionHistory.js +30 -0
  281. package/dist/esm/actions/getTransactionHistory.js.map +1 -0
  282. package/dist/esm/actions/getWalletBalances.d.ts +16 -0
  283. package/dist/esm/actions/getWalletBalances.d.ts.map +1 -0
  284. package/dist/esm/actions/getWalletBalances.js +19 -0
  285. package/dist/esm/actions/getWalletBalances.js.map +1 -0
  286. package/dist/esm/actions/index.d.ts +172 -0
  287. package/dist/esm/actions/index.d.ts.map +1 -0
  288. package/dist/esm/actions/index.js +51 -0
  289. package/dist/esm/actions/index.js.map +1 -0
  290. package/dist/esm/actions/patchContractCalls.d.ts +15 -0
  291. package/dist/esm/actions/patchContractCalls.d.ts.map +1 -0
  292. package/dist/esm/actions/patchContractCalls.js +14 -0
  293. package/dist/esm/actions/patchContractCalls.js.map +1 -0
  294. package/dist/esm/actions/relayTransaction.d.ts +16 -0
  295. package/dist/esm/actions/relayTransaction.d.ts.map +1 -0
  296. package/dist/esm/actions/relayTransaction.js +33 -0
  297. package/dist/esm/actions/relayTransaction.js.map +1 -0
  298. package/dist/esm/client/createClient.d.ts +7 -0
  299. package/dist/esm/client/createClient.d.ts.map +1 -0
  300. package/dist/esm/client/createClient.js +69 -0
  301. package/dist/esm/client/createClient.js.map +1 -0
  302. package/dist/esm/client/getClientStorage.d.ts +14 -0
  303. package/dist/esm/client/getClientStorage.d.ts.map +1 -0
  304. package/dist/esm/client/getClientStorage.js +47 -0
  305. package/dist/esm/client/getClientStorage.js.map +1 -0
  306. package/dist/esm/core/BaseStepExecutionTask.d.ts +10 -0
  307. package/dist/esm/core/BaseStepExecutionTask.d.ts.map +1 -0
  308. package/dist/esm/core/BaseStepExecutionTask.js +10 -0
  309. package/dist/esm/core/BaseStepExecutionTask.js.map +1 -0
  310. package/dist/esm/core/BaseStepExecutor.d.ts +24 -0
  311. package/dist/esm/core/BaseStepExecutor.d.ts.map +1 -0
  312. package/dist/esm/core/BaseStepExecutor.js +70 -0
  313. package/dist/esm/core/BaseStepExecutor.js.map +1 -0
  314. package/dist/esm/core/StatusManager.d.ts +83 -0
  315. package/dist/esm/core/StatusManager.d.ts.map +1 -0
  316. package/dist/esm/core/StatusManager.js +159 -0
  317. package/dist/esm/core/StatusManager.js.map +1 -0
  318. package/dist/esm/core/TaskPipeline.d.ts +12 -0
  319. package/dist/esm/core/TaskPipeline.d.ts.map +1 -0
  320. package/dist/esm/core/TaskPipeline.js +20 -0
  321. package/dist/esm/core/TaskPipeline.js.map +1 -0
  322. package/dist/esm/core/actionMessages.d.ts +9 -0
  323. package/dist/esm/core/actionMessages.d.ts.map +1 -0
  324. package/dist/esm/core/actionMessages.js +79 -0
  325. package/dist/esm/core/actionMessages.js.map +1 -0
  326. package/dist/esm/core/execution.d.ts +48 -0
  327. package/dist/esm/core/execution.d.ts.map +1 -0
  328. package/dist/esm/core/execution.js +141 -0
  329. package/dist/esm/core/execution.js.map +1 -0
  330. package/dist/esm/core/executionState.d.ts +21 -0
  331. package/dist/esm/core/executionState.d.ts.map +1 -0
  332. package/dist/esm/core/executionState.js +28 -0
  333. package/dist/esm/core/executionState.js.map +1 -0
  334. package/dist/esm/core/prepareRestart.d.ts +7 -0
  335. package/dist/esm/core/prepareRestart.d.ts.map +1 -0
  336. package/dist/esm/core/prepareRestart.js +20 -0
  337. package/dist/esm/core/prepareRestart.js.map +1 -0
  338. package/dist/esm/core/storage.d.ts +21 -0
  339. package/dist/esm/core/storage.d.ts.map +1 -0
  340. package/dist/esm/core/storage.js +32 -0
  341. package/dist/esm/core/storage.js.map +1 -0
  342. package/dist/esm/core/tasks/CheckBalanceTask.d.ts +19 -0
  343. package/dist/esm/core/tasks/CheckBalanceTask.d.ts.map +1 -0
  344. package/dist/esm/core/tasks/CheckBalanceTask.js +34 -0
  345. package/dist/esm/core/tasks/CheckBalanceTask.js.map +1 -0
  346. package/dist/esm/core/tasks/PrepareTransactionTask.d.ts +10 -0
  347. package/dist/esm/core/tasks/PrepareTransactionTask.d.ts.map +1 -0
  348. package/dist/esm/core/tasks/PrepareTransactionTask.js +29 -0
  349. package/dist/esm/core/tasks/PrepareTransactionTask.js.map +1 -0
  350. package/dist/esm/core/tasks/WaitForTransactionStatusTask.d.ts +13 -0
  351. package/dist/esm/core/tasks/WaitForTransactionStatusTask.d.ts.map +1 -0
  352. package/dist/esm/core/tasks/WaitForTransactionStatusTask.js +61 -0
  353. package/dist/esm/core/tasks/WaitForTransactionStatusTask.js.map +1 -0
  354. package/dist/esm/core/tasks/helpers/checkBalance.d.ts +30 -0
  355. package/dist/esm/core/tasks/helpers/checkBalance.d.ts.map +1 -0
  356. package/dist/esm/core/tasks/helpers/checkBalance.js +107 -0
  357. package/dist/esm/core/tasks/helpers/checkBalance.js.map +1 -0
  358. package/dist/esm/core/tasks/helpers/getTransactionRequestData.d.ts +7 -0
  359. package/dist/esm/core/tasks/helpers/getTransactionRequestData.d.ts.map +1 -0
  360. package/dist/esm/core/tasks/helpers/getTransactionRequestData.js +24 -0
  361. package/dist/esm/core/tasks/helpers/getTransactionRequestData.js.map +1 -0
  362. package/dist/esm/core/tasks/helpers/stepComparison.d.ts +21 -0
  363. package/dist/esm/core/tasks/helpers/stepComparison.d.ts.map +1 -0
  364. package/dist/esm/core/tasks/helpers/stepComparison.js +31 -0
  365. package/dist/esm/core/tasks/helpers/stepComparison.js.map +1 -0
  366. package/dist/esm/core/tasks/helpers/waitForTransactionStatus.d.ts +9 -0
  367. package/dist/esm/core/tasks/helpers/waitForTransactionStatus.d.ts.map +1 -0
  368. package/dist/esm/core/tasks/helpers/waitForTransactionStatus.js +47 -0
  369. package/dist/esm/core/tasks/helpers/waitForTransactionStatus.js.map +1 -0
  370. package/dist/esm/core/utils.d.ts +17 -0
  371. package/dist/esm/core/utils.d.ts.map +1 -0
  372. package/dist/esm/core/utils.js +40 -0
  373. package/dist/esm/core/utils.js.map +1 -0
  374. package/dist/esm/errors/SDKError.d.ts +17 -0
  375. package/dist/esm/errors/SDKError.d.ts.map +1 -0
  376. package/dist/esm/errors/SDKError.js +23 -0
  377. package/dist/esm/errors/SDKError.js.map +1 -0
  378. package/dist/esm/errors/baseError.d.ts +11 -0
  379. package/dist/esm/errors/baseError.d.ts.map +1 -0
  380. package/dist/esm/errors/baseError.js +18 -0
  381. package/dist/esm/errors/baseError.js.map +1 -0
  382. package/dist/esm/errors/constants.d.ts +55 -0
  383. package/dist/esm/errors/constants.d.ts.map +1 -0
  384. package/dist/esm/errors/constants.js +58 -0
  385. package/dist/esm/errors/constants.js.map +1 -0
  386. package/dist/esm/errors/errors.d.ts +38 -0
  387. package/dist/esm/errors/errors.d.ts.map +1 -0
  388. package/dist/esm/errors/errors.js +54 -0
  389. package/dist/esm/errors/errors.js.map +1 -0
  390. package/dist/esm/errors/httpError.d.ts +24 -0
  391. package/dist/esm/errors/httpError.d.ts.map +1 -0
  392. package/dist/esm/errors/httpError.js +69 -0
  393. package/dist/esm/errors/httpError.js.map +1 -0
  394. package/dist/esm/errors/utils/baseErrorRootCause.d.ts +8 -0
  395. package/dist/esm/errors/utils/baseErrorRootCause.d.ts.map +1 -0
  396. package/dist/esm/errors/utils/baseErrorRootCause.js +16 -0
  397. package/dist/esm/errors/utils/baseErrorRootCause.js.map +1 -0
  398. package/dist/esm/errors/utils/rootCause.d.ts +5 -0
  399. package/dist/esm/errors/utils/rootCause.d.ts.map +1 -0
  400. package/dist/esm/errors/utils/rootCause.js +10 -0
  401. package/dist/esm/errors/utils/rootCause.js.map +1 -0
  402. package/dist/esm/index.d.ts +55 -0
  403. package/dist/esm/index.js +53 -0
  404. package/dist/esm/package.json +1 -0
  405. package/dist/esm/types/actions.d.ts +14 -0
  406. package/dist/esm/types/actions.d.ts.map +1 -0
  407. package/dist/esm/types/actions.js +1 -0
  408. package/dist/esm/types/core.d.ts +184 -0
  409. package/dist/esm/types/core.d.ts.map +1 -0
  410. package/dist/esm/types/core.js +1 -0
  411. package/dist/esm/types/execution.d.ts +28 -0
  412. package/dist/esm/types/execution.d.ts.map +1 -0
  413. package/dist/esm/types/execution.js +1 -0
  414. package/dist/esm/types/request.d.ts +7 -0
  415. package/dist/esm/types/request.d.ts.map +1 -0
  416. package/dist/esm/types/request.js +1 -0
  417. package/dist/esm/utils/checkPackageUpdates.d.ts +5 -0
  418. package/dist/esm/utils/checkPackageUpdates.d.ts.map +1 -0
  419. package/dist/esm/utils/checkPackageUpdates.js +14 -0
  420. package/dist/esm/utils/checkPackageUpdates.js.map +1 -0
  421. package/dist/esm/utils/convertQuoteToRoute.d.ts +22 -0
  422. package/dist/esm/utils/convertQuoteToRoute.d.ts.map +1 -0
  423. package/dist/esm/utils/convertQuoteToRoute.js +86 -0
  424. package/dist/esm/utils/convertQuoteToRoute.js.map +1 -0
  425. package/dist/esm/utils/decode.d.ts +5 -0
  426. package/dist/esm/utils/decode.d.ts.map +1 -0
  427. package/dist/esm/utils/decode.js +8 -0
  428. package/dist/esm/utils/decode.js.map +1 -0
  429. package/dist/esm/utils/fetchTxErrorDetails.d.ts +5 -0
  430. package/dist/esm/utils/fetchTxErrorDetails.d.ts.map +1 -0
  431. package/dist/esm/utils/fetchTxErrorDetails.js +12 -0
  432. package/dist/esm/utils/fetchTxErrorDetails.js.map +1 -0
  433. package/dist/esm/utils/formatUnits.d.ts +8 -0
  434. package/dist/esm/utils/formatUnits.d.ts.map +1 -0
  435. package/dist/esm/utils/formatUnits.js +17 -0
  436. package/dist/esm/utils/formatUnits.js.map +1 -0
  437. package/dist/esm/utils/getTransactionMessage.d.ts +8 -0
  438. package/dist/esm/utils/getTransactionMessage.d.ts.map +1 -0
  439. package/dist/esm/utils/getTransactionMessage.js +11 -0
  440. package/dist/esm/utils/getTransactionMessage.js.map +1 -0
  441. package/dist/esm/utils/isHex.d.ts +10 -0
  442. package/dist/esm/utils/isHex.d.ts.map +1 -0
  443. package/dist/esm/utils/isHex.js +10 -0
  444. package/dist/esm/utils/isHex.js.map +1 -0
  445. package/dist/esm/utils/isRoutesRequest.d.ts +7 -0
  446. package/dist/esm/utils/isRoutesRequest.d.ts.map +1 -0
  447. package/dist/esm/utils/isRoutesRequest.js +10 -0
  448. package/dist/esm/utils/isRoutesRequest.js.map +1 -0
  449. package/dist/esm/utils/isStep.d.ts +7 -0
  450. package/dist/esm/utils/isStep.d.ts.map +1 -0
  451. package/dist/esm/utils/isStep.js +22 -0
  452. package/dist/esm/utils/isStep.js.map +1 -0
  453. package/dist/esm/utils/isToken.d.ts +7 -0
  454. package/dist/esm/utils/isToken.d.ts.map +1 -0
  455. package/dist/esm/utils/isToken.js +9 -0
  456. package/dist/esm/utils/isToken.js.map +1 -0
  457. package/dist/esm/utils/parseUnits.d.ts +8 -0
  458. package/dist/esm/utils/parseUnits.d.ts.map +1 -0
  459. package/dist/esm/utils/parseUnits.js +34 -0
  460. package/dist/esm/utils/parseUnits.js.map +1 -0
  461. package/dist/esm/utils/request.d.ts +11 -0
  462. package/dist/esm/utils/request.d.ts.map +1 -0
  463. package/dist/esm/utils/request.js +54 -0
  464. package/dist/esm/utils/request.js.map +1 -0
  465. package/dist/esm/utils/sleep.d.ts +5 -0
  466. package/dist/esm/utils/sleep.d.ts.map +1 -0
  467. package/dist/esm/utils/sleep.js +10 -0
  468. package/dist/esm/utils/sleep.js.map +1 -0
  469. package/dist/esm/utils/waitForResult.d.ts +14 -0
  470. package/dist/esm/utils/waitForResult.d.ts.map +1 -0
  471. package/dist/esm/utils/waitForResult.js +35 -0
  472. package/dist/esm/utils/waitForResult.js.map +1 -0
  473. package/dist/esm/utils/withDedupe.d.ts +23 -0
  474. package/dist/esm/utils/withDedupe.d.ts.map +1 -0
  475. package/dist/esm/utils/withDedupe.js +32 -0
  476. package/dist/esm/utils/withDedupe.js.map +1 -0
  477. package/dist/esm/utils/withTimeout.d.ts +26 -0
  478. package/dist/esm/utils/withTimeout.d.ts.map +1 -0
  479. package/dist/esm/utils/withTimeout.js +34 -0
  480. package/dist/esm/utils/withTimeout.js.map +1 -0
  481. package/dist/esm/version.d.ts +6 -0
  482. package/dist/esm/version.d.ts.map +1 -0
  483. package/dist/esm/version.js +7 -0
  484. package/dist/esm/version.js.map +1 -0
  485. package/package.json +75 -0
  486. package/src/actions/getChains.ts +55 -0
  487. package/src/actions/getConnections.ts +55 -0
  488. package/src/actions/getContractCallsQuote.ts +81 -0
  489. package/src/actions/getGasRecommendation.ts +47 -0
  490. package/src/actions/getNameServiceAddress.ts +42 -0
  491. package/src/actions/getQuote.ts +105 -0
  492. package/src/actions/getRelayedTransactionStatus.ts +67 -0
  493. package/src/actions/getRelayerQuote.ts +86 -0
  494. package/src/actions/getRoutes.ts +43 -0
  495. package/src/actions/getStatus.ts +41 -0
  496. package/src/actions/getStepTransaction.ts +52 -0
  497. package/src/actions/getToken.ts +47 -0
  498. package/src/actions/getTokenBalance.ts +21 -0
  499. package/src/actions/getTokenBalances.ts +47 -0
  500. package/src/actions/getTokenBalancesByChain.ts +76 -0
  501. package/src/actions/getTokens.ts +57 -0
  502. package/src/actions/getTools.ts +34 -0
  503. package/src/actions/getTransactionHistory.ts +54 -0
  504. package/src/actions/getWalletBalances.ts +36 -0
  505. package/src/actions/index.ts +347 -0
  506. package/src/actions/patchContractCalls.ts +30 -0
  507. package/src/actions/relayTransaction.ts +74 -0
  508. package/src/client/createClient.ts +100 -0
  509. package/src/client/getClientStorage.ts +65 -0
  510. package/src/core/BaseStepExecutionTask.ts +9 -0
  511. package/src/core/BaseStepExecutor.ts +129 -0
  512. package/src/core/StatusManager.ts +245 -0
  513. package/src/core/TaskPipeline.ts +28 -0
  514. package/src/core/actionMessages.ts +103 -0
  515. package/src/core/execution.ts +243 -0
  516. package/src/core/executionState.ts +48 -0
  517. package/src/core/prepareRestart.ts +28 -0
  518. package/src/core/storage.ts +42 -0
  519. package/src/core/tasks/CheckBalanceTask.ts +46 -0
  520. package/src/core/tasks/PrepareTransactionTask.ts +62 -0
  521. package/src/core/tasks/WaitForTransactionStatusTask.ts +114 -0
  522. package/src/core/tasks/helpers/checkBalance.ts +218 -0
  523. package/src/core/tasks/helpers/getTransactionRequestData.ts +47 -0
  524. package/src/core/tasks/helpers/stepComparison.ts +50 -0
  525. package/src/core/tasks/helpers/waitForTransactionStatus.ts +76 -0
  526. package/src/core/utils.ts +59 -0
  527. package/src/errors/SDKError.ts +26 -0
  528. package/src/errors/baseError.ts +22 -0
  529. package/src/errors/constants.ts +54 -0
  530. package/src/errors/errors.ts +68 -0
  531. package/src/errors/httpError.ts +92 -0
  532. package/src/errors/utils/baseErrorRootCause.ts +18 -0
  533. package/src/errors/utils/rootCause.ts +7 -0
  534. package/src/index.ts +122 -0
  535. package/src/types/actions.ts +16 -0
  536. package/src/types/core.ts +264 -0
  537. package/src/types/execution.ts +32 -0
  538. package/src/types/request.ts +3 -0
  539. package/src/utils/checkPackageUpdates.ts +22 -0
  540. package/src/utils/convertQuoteToRoute.ts +154 -0
  541. package/src/utils/decode.ts +13 -0
  542. package/src/utils/fetchTxErrorDetails.ts +15 -0
  543. package/src/utils/formatUnits.ts +22 -0
  544. package/src/utils/getTransactionMessage.ts +17 -0
  545. package/src/utils/isHex.ts +14 -0
  546. package/src/utils/isRoutesRequest.ts +31 -0
  547. package/src/utils/isStep.ts +41 -0
  548. package/src/utils/isToken.ts +11 -0
  549. package/src/utils/parseUnits.ts +50 -0
  550. package/src/utils/request.ts +100 -0
  551. package/src/utils/sleep.ts +5 -0
  552. package/src/utils/waitForResult.ts +45 -0
  553. package/src/utils/withDedupe.ts +45 -0
  554. package/src/utils/withTimeout.ts +50 -0
  555. package/src/version.ts +2 -0
@@ -0,0 +1,218 @@
1
+ import type { LiFiStep, Token, TokenAmount } from '@lifi/types'
2
+ import { BalanceError } from '../../../errors/errors.js'
3
+ import type { SDKClient } from '../../../types/core.js'
4
+ import { formatUnits } from '../../../utils/formatUnits.js'
5
+ import { sleep } from '../../../utils/sleep.js'
6
+ import { withTimeout } from '../../../utils/withTimeout.js'
7
+
8
+ const MAX_ATTEMPTS = 6
9
+ // Exponential backoff: 150, 300, 600, 1200, 2400 → ≈4.65s of sleep total.
10
+ const BACKOFF_BASE_MS = 150
11
+ const OVERALL_TIMEOUT_MS = 10_000
12
+ const SLIPPAGE_PRECISION = 1_000_000_000n
13
+
14
+ type Bucket = 'source' | 'gas' | 'fee'
15
+
16
+ type Requirement = {
17
+ token: Token
18
+ sourcePart: bigint // step.action.fromAmount
19
+ gasPart: bigint // step.estimate.gasCosts in this token
20
+ feePart: bigint // non-included step.estimate.feeCosts in this token
21
+ }
22
+
23
+ export type CheckBalanceOptions = {
24
+ /**
25
+ * Set to `false` when outer-tx gas is paid by something other than
26
+ * `walletAddress` (SCA executor, 4337 bundler / paymaster, relayer):
27
+ * `gasPart` is excluded from the sufficiency check and slippage rescue.
28
+ * Source amount and non-included fees (e.g. LZ `msg.value`) are still
29
+ * verified. Defaults to `true` (strict, today's behavior).
30
+ */
31
+ walletPaysGas?: boolean
32
+ }
33
+
34
+ /**
35
+ * Verifies that the wallet holds enough of every token required to execute
36
+ * the step on its source chain — the source-token amount, any gas costs, and
37
+ * any non-included fee costs. Reads all balances in one batched provider
38
+ * call, retries within a bounded budget to absorb transient RPC failures and
39
+ * post-confirmation propagation lag, and applies slippage to the source-token
40
+ * portion only as a last resort (overhead is never trimmed).
41
+ *
42
+ * Throws BalanceError("The balance is too low.") on a genuine shortfall, or
43
+ * BalanceError("Could not read wallet balance.") if the balance can't be read
44
+ * after retries.
45
+ */
46
+ export const checkBalance = async (
47
+ client: SDKClient,
48
+ walletAddress: string,
49
+ step: LiFiStep,
50
+ options: CheckBalanceOptions = {}
51
+ ): Promise<void> => {
52
+ const fromChainId = step.action.fromChainId
53
+ // Chains with non-standard native decimals (e.g. Tempo, Stable) report
54
+ // gas costs in units that don't align with wallet balances — drop the
55
+ // gas portion of the check on those chains.
56
+ const fromChain = await client.getChainById(fromChainId)
57
+ const walletPaysGas =
58
+ (options.walletPaysGas ?? true) && !fromChain.nonStandardNativeDecimals
59
+ const requirements = new Map<string, Requirement>()
60
+ const add = (token: Token, amount: bigint, bucket: Bucket): void => {
61
+ if (token.chainId !== fromChainId || amount === 0n) {
62
+ return
63
+ }
64
+ const key = token.address.toLowerCase()
65
+ const req = requirements.get(key) ?? {
66
+ token,
67
+ sourcePart: 0n,
68
+ gasPart: 0n,
69
+ feePart: 0n,
70
+ }
71
+ if (bucket === 'source') {
72
+ req.sourcePart += amount
73
+ } else if (bucket === 'gas') {
74
+ req.gasPart += amount
75
+ } else {
76
+ req.feePart += amount
77
+ }
78
+ requirements.set(key, req)
79
+ }
80
+ add(step.action.fromToken, BigInt(step.action.fromAmount), 'source')
81
+ for (const gas of step.estimate?.gasCosts ?? []) {
82
+ add(gas.token, BigInt(gas.amount), 'gas')
83
+ }
84
+ for (const fee of step.estimate?.feeCosts ?? []) {
85
+ // Included fees are already part of fromAmount — don't count twice.
86
+ if (!fee.included) {
87
+ add(fee.token, BigInt(fee.amount), 'fee')
88
+ }
89
+ }
90
+
91
+ const reservedOverhead = (r: Requirement): bigint =>
92
+ r.feePart + (walletPaysGas ? r.gasPart : 0n)
93
+ const need = (r: Requirement): bigint => r.sourcePart + reservedOverhead(r)
94
+
95
+ // Drop pure-gas entries when `walletPaysGas` is false (e.g. native ETH
96
+ // on Safe Apps with only `gasPart`) — saves one balance read each.
97
+ for (const [key, req] of requirements) {
98
+ if (need(req) === 0n) {
99
+ requirements.delete(key)
100
+ }
101
+ }
102
+
103
+ if (requirements.size === 0) {
104
+ return
105
+ }
106
+
107
+ // Provider is dispatched by wallet address; all requirements share the
108
+ // source chain, which matches this provider by virtue of the address.
109
+ const provider = client.providers.find((p) => p.isAddress(walletAddress))
110
+ if (!provider) {
111
+ throw new Error(`SDK Token Provider for ${walletAddress} is not found.`)
112
+ }
113
+
114
+ const reqs = Array.from(requirements.values())
115
+ const tokens = reqs.map((r) => r.token)
116
+ const slippage = step.action.slippage ?? 0
117
+ const slippageScaled = BigInt(
118
+ Math.floor((1 - slippage) * Number(SLIPPAGE_PRECISION))
119
+ )
120
+
121
+ await withTimeout(
122
+ async () => {
123
+ for (let attempt = 0; attempt < MAX_ATTEMPTS; attempt++) {
124
+ const isFinal = attempt === MAX_ATTEMPTS - 1
125
+
126
+ let balances: TokenAmount[]
127
+ try {
128
+ balances = await provider.getBalance(client, walletAddress, tokens)
129
+ } catch (error) {
130
+ if (isFinal) {
131
+ throw new BalanceError(
132
+ 'Could not read wallet balance.',
133
+ error as Error
134
+ )
135
+ }
136
+ await sleep(BACKOFF_BASE_MS * 2 ** attempt)
137
+ continue
138
+ }
139
+
140
+ const balanceByAddress = new Map(
141
+ balances.map((b) => [b.address.toLowerCase(), b.amount] as const)
142
+ )
143
+
144
+ const unknown: Token[] = []
145
+ const insufficient: { req: Requirement; have: bigint }[] = []
146
+ for (const req of reqs) {
147
+ const have = balanceByAddress.get(req.token.address.toLowerCase())
148
+ if (have === undefined) {
149
+ unknown.push(req.token)
150
+ } else if (have < need(req)) {
151
+ insufficient.push({ req, have })
152
+ }
153
+ }
154
+
155
+ if (unknown.length === 0 && insufficient.length === 0) {
156
+ return
157
+ }
158
+
159
+ // Final-attempt slippage rescue: only when the sole shortfall is
160
+ // the source-token portion. Trim source to (balance − reserved
161
+ // overhead) so the overhead reserve is preserved.
162
+ if (
163
+ isFinal &&
164
+ unknown.length === 0 &&
165
+ insufficient.length === 1 &&
166
+ insufficient[0].req.sourcePart > 0n
167
+ ) {
168
+ const { req, have } = insufficient[0]
169
+ const reserved = reservedOverhead(req)
170
+ const minAcceptable =
171
+ (req.sourcePart * slippageScaled) / SLIPPAGE_PRECISION + reserved
172
+ if (have >= minAcceptable) {
173
+ const newFromAmount = (have - reserved).toString()
174
+ step.action.fromAmount = newFromAmount
175
+ if (step.includedSteps?.length) {
176
+ step.includedSteps[0].action.fromAmount = newFromAmount
177
+ }
178
+ return
179
+ }
180
+ }
181
+
182
+ if (isFinal) {
183
+ if (unknown.length > 0) {
184
+ throw new BalanceError(
185
+ 'Could not read wallet balance.',
186
+ new Error(
187
+ `Could not read balance for: ${unknown
188
+ .map((t) => t.symbol || t.address)
189
+ .join(', ')}.`
190
+ )
191
+ )
192
+ }
193
+ const lines = insufficient.map(({ req, have }) => {
194
+ const needed = formatUnits(need(req), req.token.decimals)
195
+ const current = formatUnits(have, req.token.decimals)
196
+ const symbol = req.token.symbol
197
+ // The "fees" branch covers pure-overhead tokens; with
198
+ // walletPaysGas=false, gas is excluded from `need(req)` so it
199
+ // only fires for genuine fee shortfalls.
200
+ return req.sourcePart > 0n
201
+ ? `Your ${symbol} balance is too low, you try to transfer ${needed} ${symbol}, but your wallet only holds ${current} ${symbol}.`
202
+ : `Insufficient ${symbol} for fees: need ${needed} ${symbol}, have ${current} ${symbol}.`
203
+ })
204
+ throw new BalanceError(
205
+ 'The balance is too low.',
206
+ new Error(`${lines.join(' ')} No funds have been sent.`)
207
+ )
208
+ }
209
+
210
+ await sleep(BACKOFF_BASE_MS * 2 ** attempt)
211
+ }
212
+ },
213
+ {
214
+ timeout: OVERALL_TIMEOUT_MS,
215
+ errorInstance: new BalanceError('Could not read wallet balance.'),
216
+ }
217
+ )
218
+ }
@@ -0,0 +1,47 @@
1
+ import { LiFiErrorCode } from '../../../errors/constants.js'
2
+ import { TransactionError } from '../../../errors/errors.js'
3
+ import type {
4
+ ExecutionOptions,
5
+ LiFiStepExtended,
6
+ TransactionParameters,
7
+ } from '../../../types/core.js'
8
+
9
+ export const getTransactionRequestData = async (
10
+ step: LiFiStepExtended,
11
+ executionOptions?: ExecutionOptions
12
+ ): Promise<string> => {
13
+ if (!step.transactionRequest?.data) {
14
+ throw new TransactionError(
15
+ LiFiErrorCode.TransactionUnprepared,
16
+ 'Unable to prepare transaction. Transaction request data is not found.'
17
+ )
18
+ }
19
+
20
+ let transactionRequest: TransactionParameters = {
21
+ data: step.transactionRequest.data,
22
+ }
23
+
24
+ if (executionOptions?.updateTransactionRequestHook) {
25
+ const customizedTransactionRequest: TransactionParameters =
26
+ await executionOptions.updateTransactionRequestHook({
27
+ requestType: 'transaction',
28
+ ...transactionRequest,
29
+ })
30
+
31
+ transactionRequest = {
32
+ ...transactionRequest,
33
+ ...customizedTransactionRequest,
34
+ }
35
+ }
36
+
37
+ const transactionRequestData = transactionRequest.data
38
+
39
+ if (!transactionRequestData) {
40
+ throw new TransactionError(
41
+ LiFiErrorCode.TransactionUnprepared,
42
+ 'Unable to prepare transaction. Transaction request data is not found.'
43
+ )
44
+ }
45
+
46
+ return transactionRequestData
47
+ }
@@ -0,0 +1,50 @@
1
+ import type { LiFiStep } from '@lifi/types'
2
+ import type { StatusManager } from '../../../core/StatusManager.js'
3
+ import { checkStepSlippageThreshold } from '../../../core/utils.js'
4
+ import { LiFiErrorCode } from '../../../errors/constants.js'
5
+ import { TransactionError } from '../../../errors/errors.js'
6
+ import type { ExecutionOptions } from '../../../types/core.js'
7
+
8
+ /**
9
+ * This method checks whether the new and updated Step meets the required exchange rate conditions.
10
+ * If yes it returns the updated Step.
11
+ * If no and if user interaction is allowed it triggers the acceptExchangeRateUpdateHook. If no user interaction is allowed it aborts.
12
+ * @param statusManager
13
+ * @param oldStep
14
+ * @param newStep
15
+ * @param settings
16
+ * @param allowUserInteraction
17
+ * @param executionOptions
18
+ * @returns Return LiFiStep
19
+ */
20
+ export const stepComparison = async (
21
+ statusManager: StatusManager,
22
+ oldStep: LiFiStep,
23
+ newStep: LiFiStep,
24
+ allowUserInteraction: boolean,
25
+ executionOptions?: ExecutionOptions
26
+ ): Promise<LiFiStep> => {
27
+ // Check if changed exchange rate is in the range of slippage threshold
28
+ if (checkStepSlippageThreshold(oldStep, newStep)) {
29
+ return statusManager.updateStepInRoute(newStep)
30
+ }
31
+
32
+ let allowStepUpdate: boolean | undefined
33
+ if (allowUserInteraction) {
34
+ allowStepUpdate = await executionOptions?.acceptExchangeRateUpdateHook?.({
35
+ oldToAmount: oldStep.estimate.toAmount,
36
+ newToAmount: newStep.estimate.toAmount,
37
+ toToken: newStep.action.toToken,
38
+ })
39
+ }
40
+
41
+ if (!allowStepUpdate) {
42
+ // The user declined the new exchange rate, so we are not going to proceed
43
+ throw new TransactionError(
44
+ LiFiErrorCode.ExchangeRateUpdateCanceled,
45
+ 'Exchange rate has changed!\nTransaction was not sent, your funds are still in your wallet.\nThe exchange rate has changed and the previous estimation can not be fulfilled due to value loss.'
46
+ )
47
+ }
48
+
49
+ return statusManager.updateStepInRoute(newStep)
50
+ }
@@ -0,0 +1,76 @@
1
+ import type { FullStatusData, LiFiStep, StatusResponse } from '@lifi/types'
2
+ import { getStatus } from '../../../actions/getStatus.js'
3
+ import { ServerError } from '../../../errors/errors.js'
4
+ import type { ExecutionActionType, SDKClient } from '../../../types/core.js'
5
+ import { waitForResult } from '../../../utils/waitForResult.js'
6
+ import { getSubstatusMessage } from '../../actionMessages.js'
7
+ import type { StatusManager } from '../../StatusManager.js'
8
+
9
+ const TRANSACTION_HASH_OBSERVERS: Record<string, Promise<StatusResponse>> = {}
10
+
11
+ export async function waitForTransactionStatus(
12
+ client: SDKClient,
13
+ statusManager: StatusManager,
14
+ txHash: string,
15
+ step: LiFiStep,
16
+ actionType: ExecutionActionType,
17
+ interval = 5_000
18
+ ): Promise<StatusResponse> {
19
+ const _getStatus = (): Promise<StatusResponse | undefined> => {
20
+ return getStatus(client, {
21
+ fromChain: step.action.fromChainId,
22
+ fromAddress: step.action.fromAddress,
23
+ toChain: step.action.toChainId,
24
+ txHash,
25
+ ...(step.tool !== 'custom' && { bridge: step.tool }),
26
+ ...(step.transactionId && { transactionId: step.transactionId }),
27
+ })
28
+ .then((statusResponse) => {
29
+ switch (statusResponse.status) {
30
+ case 'DONE':
31
+ return statusResponse
32
+ case 'PENDING':
33
+ statusManager?.updateAction(step, actionType, 'PENDING', {
34
+ substatus: statusResponse.substatus,
35
+ substatusMessage:
36
+ statusResponse.substatusMessage ||
37
+ getSubstatusMessage(
38
+ statusResponse.status,
39
+ statusResponse.substatus
40
+ ),
41
+ txLink: (statusResponse as FullStatusData).bridgeExplorerLink,
42
+ })
43
+ return undefined
44
+ case 'NOT_FOUND':
45
+ return undefined
46
+ default:
47
+ return Promise.reject()
48
+ }
49
+ })
50
+ .catch((e) => {
51
+ if (process.env.NODE_ENV === 'development') {
52
+ console.debug('Fetching status from backend failed.', e)
53
+ }
54
+ return undefined
55
+ })
56
+ }
57
+
58
+ let status = TRANSACTION_HASH_OBSERVERS[txHash]
59
+
60
+ if (!status) {
61
+ status = waitForResult(_getStatus, interval).finally(() => {
62
+ delete TRANSACTION_HASH_OBSERVERS[txHash]
63
+ })
64
+ TRANSACTION_HASH_OBSERVERS[txHash] = status
65
+ }
66
+
67
+ const resolvedStatus = await status
68
+
69
+ if (!('receiving' in resolvedStatus)) {
70
+ throw new ServerError(
71
+ "Status doesn't contain destination chain information."
72
+ )
73
+ }
74
+
75
+ return resolvedStatus
76
+ }
@@ -0,0 +1,59 @@
1
+ import type { ChainId, ExtendedChain, LiFiStep } from '@lifi/types'
2
+ import type { RPCUrls } from '../types/core.js'
3
+
4
+ // Standard threshold for destination amount difference (0.5%)
5
+ const standardThreshold = 0.005
6
+
7
+ /**
8
+ * Used to check if changed exchange rate is in the range of slippage threshold.
9
+ * We use a slippage value as a threshold to trigger the rate change hook.
10
+ * This can result in almost doubled slippage for the user and need to be revisited.
11
+ * @param oldStep - old step
12
+ * @param newStep - new step
13
+ * @returns Boolean
14
+ */
15
+ export function checkStepSlippageThreshold(
16
+ oldStep: LiFiStep,
17
+ newStep: LiFiStep
18
+ ): boolean {
19
+ const setSlippage = oldStep.action.slippage || standardThreshold
20
+ const oldEstimatedToAmount = BigInt(oldStep.estimate.toAmountMin)
21
+ const newEstimatedToAmount = BigInt(newStep.estimate.toAmountMin)
22
+ const amountDifference = oldEstimatedToAmount - newEstimatedToAmount
23
+ // oldEstimatedToAmount can be 0 when we use contract calls
24
+ let actualSlippage = 0
25
+ if (oldEstimatedToAmount > 0) {
26
+ actualSlippage =
27
+ Number((amountDifference * 1_000_000_000n) / oldEstimatedToAmount) /
28
+ 1_000_000_000
29
+ }
30
+ return actualSlippage <= setSlippage
31
+ }
32
+
33
+ export function getRpcUrlsFromChains(
34
+ existingRpcUrls: RPCUrls,
35
+ chains: ExtendedChain[],
36
+ skipChains?: ChainId[]
37
+ ): RPCUrls {
38
+ const rpcUrlsFromChains = chains.reduce((rpcUrls, chain) => {
39
+ if (chain.metamask?.rpcUrls?.length) {
40
+ rpcUrls[chain.id as ChainId] = chain.metamask.rpcUrls
41
+ }
42
+ return rpcUrls
43
+ }, {} as RPCUrls)
44
+ const result = { ...existingRpcUrls }
45
+ for (const rpcUrlsKey in rpcUrlsFromChains) {
46
+ const chainId = Number(rpcUrlsKey) as ChainId
47
+ const urls = rpcUrlsFromChains[chainId]
48
+ if (!urls?.length) {
49
+ continue
50
+ }
51
+ if (!result[chainId]?.length) {
52
+ result[chainId] = Array.from(urls)
53
+ } else if (!skipChains?.includes(chainId)) {
54
+ const filteredUrls = urls.filter((url) => !result[chainId]?.includes(url))
55
+ result[chainId].push(...filteredUrls)
56
+ }
57
+ }
58
+ return result
59
+ }
@@ -0,0 +1,26 @@
1
+ import type { LiFiStep } from '@lifi/types'
2
+ import type { ExecutionAction } from '../types/core.js'
3
+ import { version } from '../version.js'
4
+ import type { BaseError } from './baseError.js'
5
+ import type { ErrorCode } from './constants.js'
6
+
7
+ // Note: SDKError is used to wrapper and present errors at the top level
8
+ // Where opportunity allows we also add the step and the action related to the error
9
+ export class SDKError extends Error {
10
+ step?: LiFiStep
11
+ action?: ExecutionAction
12
+ code: ErrorCode
13
+ override name = 'SDKError'
14
+ override cause: BaseError
15
+
16
+ constructor(cause: BaseError, step?: LiFiStep, action?: ExecutionAction) {
17
+ const errorMessage = `${cause.message ? `[${cause.name}] ${cause.message}` : 'Unknown error occurred'}\nLI.FI SDK version: ${version}`
18
+ super(errorMessage)
19
+ this.name = 'SDKError'
20
+ this.step = step
21
+ this.action = action
22
+ this.cause = cause
23
+ this.stack = this.cause.stack
24
+ this.code = cause.code
25
+ }
26
+ }
@@ -0,0 +1,22 @@
1
+ import type { ErrorCode, ErrorName } from './constants.js'
2
+ import { getRootCause } from './utils/rootCause.js'
3
+
4
+ // Note: we use the BaseErrors to capture errors at specific points in the code
5
+ // they can carry addition to help give more context
6
+ export class BaseError extends Error {
7
+ code: ErrorCode
8
+ override cause?: Error
9
+
10
+ constructor(name: ErrorName, code: number, message: string, cause?: Error) {
11
+ super(message)
12
+
13
+ this.name = name
14
+ this.code = code
15
+ this.cause = cause
16
+
17
+ const rootCause = getRootCause(this.cause)
18
+ if (rootCause?.stack) {
19
+ this.stack = rootCause.stack
20
+ }
21
+ }
22
+ }
@@ -0,0 +1,54 @@
1
+ export enum ErrorName {
2
+ RPCError = 'RPCError',
3
+ ProviderError = 'ProviderError',
4
+ ServerError = 'ServerError',
5
+ TransactionError = 'TransactionError',
6
+ ValidationError = 'ValidationError',
7
+ BalanceError = 'BalanceError',
8
+ NotFoundError = 'NotFoundError',
9
+ UnknownError = 'UnknownError',
10
+ SlippageError = 'SlippageError',
11
+ HTTPError = 'HTTPError',
12
+ ConfigError = 'ConfigError',
13
+ ExecuteStepRetryError = 'ExecuteStepRetryError',
14
+ }
15
+
16
+ export type ErrorCode = LiFiErrorCode
17
+
18
+ export enum LiFiErrorCode {
19
+ InternalError = 1000,
20
+ ValidationError = 1001,
21
+ TransactionUnderpriced = 1002,
22
+ TransactionFailed = 1003,
23
+ Timeout = 1004,
24
+ ProviderUnavailable = 1005,
25
+ NotFound = 1006,
26
+ ChainSwitchError = 1007,
27
+ TransactionUnprepared = 1008,
28
+ GasLimitError = 1009,
29
+ TransactionCanceled = 1010,
30
+ SlippageError = 1011,
31
+ SignatureRejected = 1012,
32
+ BalanceError = 1013,
33
+ AllowanceRequired = 1014,
34
+ InsufficientFunds = 1015,
35
+ ExchangeRateUpdateCanceled = 1016,
36
+ WalletChangedDuringExecution = 1017,
37
+ TransactionExpired = 1018,
38
+ TransactionSimulationFailed = 1019,
39
+ TransactionConflict = 1020,
40
+ TransactionNotFound = 1021,
41
+ TransactionRejected = 1022,
42
+ RateLimitExceeded = 1023,
43
+ ThirdPartyError = 1024,
44
+ InsufficientGas = 1025,
45
+ ConfigError = 1026,
46
+ }
47
+
48
+ export enum ErrorMessage {
49
+ UnknownError = 'Unknown error occurred.',
50
+ SlippageError = 'The slippage is larger than the defined threshold. Please request a new route to get a fresh quote.',
51
+ GasLimitLow = 'Gas limit is too low.',
52
+ TransactionUnderpriced = 'Transaction is underpriced.',
53
+ TransactionReverted = 'Transaction was reverted.',
54
+ }
@@ -0,0 +1,68 @@
1
+ import type { ExecuteStepRetryParams } from '../types/core.js'
2
+ import { BaseError } from './baseError.js'
3
+ import { ErrorName, LiFiErrorCode } from './constants.js'
4
+
5
+ export class RPCError extends BaseError {
6
+ constructor(code: LiFiErrorCode, message: string, cause?: Error) {
7
+ super(ErrorName.RPCError, code, message, cause)
8
+ }
9
+ }
10
+
11
+ export class ProviderError extends BaseError {
12
+ constructor(code: LiFiErrorCode, message: string, cause?: Error) {
13
+ super(ErrorName.ProviderError, code, message, cause)
14
+ }
15
+ }
16
+
17
+ export class TransactionError extends BaseError {
18
+ constructor(code: LiFiErrorCode, message: string, cause?: Error) {
19
+ super(ErrorName.TransactionError, code, message, cause)
20
+ }
21
+ }
22
+
23
+ export class UnknownError extends BaseError {
24
+ constructor(message: string, cause?: Error) {
25
+ super(ErrorName.UnknownError, LiFiErrorCode.InternalError, message, cause)
26
+ }
27
+ }
28
+
29
+ export class BalanceError extends BaseError {
30
+ constructor(message: string, cause?: Error) {
31
+ super(ErrorName.BalanceError, LiFiErrorCode.BalanceError, message, cause)
32
+ }
33
+ }
34
+
35
+ export class ServerError extends BaseError {
36
+ constructor(message: string) {
37
+ super(ErrorName.ServerError, LiFiErrorCode.InternalError, message)
38
+ }
39
+ }
40
+
41
+ export class ValidationError extends BaseError {
42
+ constructor(message: string) {
43
+ super(ErrorName.ValidationError, LiFiErrorCode.ValidationError, message)
44
+ }
45
+ }
46
+
47
+ /**
48
+ * Thrown by a step executor when executeStep should be retried with the given params
49
+ * (e.g. wallet rejected 7702 upgrade → retry with atomicityNotReady).
50
+ * The execution layer catches this and retries executeStep(client, step, retryParams).
51
+ */
52
+ export class ExecuteStepRetryError extends BaseError {
53
+ readonly retryParams: ExecuteStepRetryParams
54
+
55
+ constructor(
56
+ message: string,
57
+ retryParams: ExecuteStepRetryParams,
58
+ cause?: Error
59
+ ) {
60
+ super(
61
+ ErrorName.ExecuteStepRetryError,
62
+ LiFiErrorCode.InternalError,
63
+ message,
64
+ cause
65
+ )
66
+ this.retryParams = retryParams
67
+ }
68
+ }