@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,154 @@
1
+ import type { LiFiStep, Route, Step } from '@lifi/types'
2
+ import { ValidationError } from '../errors/errors.js'
3
+ import { SDKError } from '../errors/SDKError.js'
4
+ import { formatUnits } from './formatUnits.js'
5
+
6
+ interface ConvertQuoteToRouteOptions {
7
+ /**
8
+ * When true, if the quote has zero output values (toAmount, toAmountMin, toAmountUSD),
9
+ * use the values from the previous included step that has non-zero output.
10
+ */
11
+ adjustZeroOutputFromPreviousStep?: boolean
12
+ }
13
+
14
+ const parseBigInt = (value: string | undefined): bigint => {
15
+ if (!value) {
16
+ return 0n
17
+ }
18
+ try {
19
+ return BigInt(value)
20
+ } catch {
21
+ return 0n
22
+ }
23
+ }
24
+
25
+ const parseNumber = (value: string | undefined): number => {
26
+ if (!value) {
27
+ return 0
28
+ }
29
+ const parsed = Number(value)
30
+ return Number.isNaN(parsed) ? 0 : parsed
31
+ }
32
+
33
+ const isZeroOutput = (
34
+ toAmount: string,
35
+ toAmountMin: string,
36
+ toAmountUSD?: string
37
+ ): boolean => {
38
+ return (
39
+ !parseBigInt(toAmount) &&
40
+ !parseBigInt(toAmountMin) &&
41
+ !parseNumber(toAmountUSD)
42
+ )
43
+ }
44
+
45
+ const hasNonZeroOutput = (step: Step): boolean => {
46
+ return (
47
+ !!parseBigInt(step.estimate.toAmount) ||
48
+ !!parseBigInt(step.estimate.toAmountMin)
49
+ )
50
+ }
51
+
52
+ const findPreviousNonZeroStep = (steps: Step[]): Step | undefined => {
53
+ // Find the last step that has non-zero output (the step before the zero output step)
54
+ for (let i = steps.length - 1; i >= 0; i--) {
55
+ const step = steps[i]
56
+ if (hasNonZeroOutput(step)) {
57
+ return step
58
+ }
59
+ }
60
+ return undefined
61
+ }
62
+
63
+ export function formatTokenPrice(
64
+ amount?: string | bigint,
65
+ price?: string,
66
+ decimals?: number
67
+ ): number {
68
+ if (!amount || !price) {
69
+ return 0
70
+ }
71
+
72
+ const formattedAmount =
73
+ typeof amount === 'bigint' && decimals !== undefined
74
+ ? formatUnits(amount, decimals)
75
+ : amount.toString()
76
+
77
+ if (Number.isNaN(Number(formattedAmount)) || Number.isNaN(Number(price))) {
78
+ return 0
79
+ }
80
+ return Number.parseFloat(formattedAmount) * Number.parseFloat(price)
81
+ }
82
+
83
+ /**
84
+ * Converts a quote to Route
85
+ * @param quote - Step returned from the quote endpoint.
86
+ * @param options - Optional configuration for handling edge cases.
87
+ * @returns - The route to be executed.
88
+ * @throws {BaseError} Throws a ValidationError if the step has missing values.
89
+ */
90
+ export const convertQuoteToRoute = (
91
+ quote: LiFiStep,
92
+ options?: ConvertQuoteToRouteOptions
93
+ ): Route => {
94
+ let toAmount = quote.estimate.toAmount
95
+ let toAmountMin = quote.estimate.toAmountMin
96
+ let toAmountUSD = quote.estimate.toAmountUSD
97
+
98
+ // Handle zero output values by looking at previous included step
99
+ if (
100
+ options?.adjustZeroOutputFromPreviousStep &&
101
+ quote.includedSteps?.length &&
102
+ isZeroOutput(toAmount, toAmountMin, toAmountUSD)
103
+ ) {
104
+ const previousStep = findPreviousNonZeroStep(quote.includedSteps)
105
+ if (previousStep) {
106
+ toAmount = previousStep.estimate.toAmount
107
+ toAmountMin = previousStep.estimate.toAmountMin
108
+ toAmountUSD = formatTokenPrice(
109
+ parseBigInt(toAmount),
110
+ previousStep.action.toToken.priceUSD,
111
+ previousStep.action.toToken.decimals
112
+ ).toFixed(2)
113
+
114
+ // Update the last included step's estimate with the adjusted values
115
+ const lastStep = quote.includedSteps[quote.includedSteps.length - 1]
116
+ if (lastStep && !hasNonZeroOutput(lastStep)) {
117
+ lastStep.estimate.toAmount = toAmount
118
+ lastStep.estimate.toAmountMin = toAmountMin
119
+ }
120
+ }
121
+ }
122
+
123
+ if (!quote.estimate.fromAmountUSD) {
124
+ throw new SDKError(
125
+ new ValidationError("Missing 'fromAmountUSD' in step estimate.")
126
+ )
127
+ }
128
+
129
+ if (!toAmountUSD) {
130
+ throw new SDKError(
131
+ new ValidationError("Missing 'toAmountUSD' in step estimate.")
132
+ )
133
+ }
134
+
135
+ const route: Route = {
136
+ id: quote.id,
137
+ fromChainId: quote.action.fromToken.chainId,
138
+ fromToken: quote.action.fromToken,
139
+ fromAmount: quote.action.fromAmount,
140
+ fromAmountUSD: quote.estimate.fromAmountUSD,
141
+ fromAddress: quote.action.fromAddress,
142
+ toChainId: quote.action.toToken.chainId,
143
+ toToken: quote.action.toToken,
144
+ toAmount,
145
+ toAmountMin,
146
+ toAmountUSD,
147
+ toAddress: quote.action.toAddress || quote.action.fromAddress,
148
+ gasCostUSD: quote.estimate.gasCosts?.[0]?.amountUSD || '0',
149
+ steps: [quote],
150
+ insurance: { state: 'NOT_INSURABLE', feeAmountUsd: '0' },
151
+ }
152
+
153
+ return route
154
+ }
@@ -0,0 +1,13 @@
1
+ export const decodeTaskId = (taskId: string): string[] => {
2
+ const decoded = new TextDecoder()
3
+ .decode(
4
+ new Uint8Array(
5
+ taskId
6
+ .slice(2)
7
+ .match(/.{1,2}/g)
8
+ ?.map((byte) => Number.parseInt(byte, 16)) ?? []
9
+ )
10
+ )
11
+ .split('|')
12
+ return decoded
13
+ }
@@ -0,0 +1,15 @@
1
+ export const fetchTxErrorDetails = async (
2
+ txHash: string,
3
+ chainId: number
4
+ ): Promise<unknown> => {
5
+ try {
6
+ const response = await fetch(
7
+ `https://api.tenderly.co/api/v1/public-contract/${chainId}/tx/${txHash}`
8
+ )
9
+ const reponseBody = await response.json()
10
+
11
+ return reponseBody
12
+ } catch (_) {
13
+ return undefined
14
+ }
15
+ }
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Divides a number by a given exponent of base 10 (10exponent), and formats it into a string representation of the number.
3
+ */
4
+ export function formatUnits(value: bigint, decimals: number): string {
5
+ let display = value.toString()
6
+
7
+ const negative = display.startsWith('-')
8
+ if (negative) {
9
+ display = display.slice(1)
10
+ }
11
+
12
+ display = display.padStart(decimals, '0')
13
+
14
+ let [integer, fraction] = [
15
+ display.slice(0, display.length - decimals),
16
+ display.slice(display.length - decimals),
17
+ ]
18
+ fraction = fraction.replace(/(0+)$/, '')
19
+ return `${negative ? '-' : ''}${integer || '0'}${
20
+ fraction ? `.${fraction}` : ''
21
+ }`
22
+ }
@@ -0,0 +1,17 @@
1
+ import type { LiFiStep } from '@lifi/types'
2
+ import type { SDKClient } from '../types/core.js'
3
+
4
+ export const getTransactionFailedMessage = async (
5
+ client: SDKClient,
6
+ step: LiFiStep,
7
+ txLink?: string
8
+ ): Promise<string> => {
9
+ const chain = await client.getChainById(step.action.toChainId)
10
+
11
+ const baseString = `It appears that your transaction may not have been successful.
12
+ However, to confirm this, please check your ${chain.name} wallet for ${step.action.toToken.symbol}.`
13
+ return txLink
14
+ ? `${baseString}
15
+ You can also check the&nbsp;<a href="${txLink}" target="_blank" rel="nofollow noreferrer">block explorer</a> for more information.`
16
+ : baseString
17
+ }
@@ -0,0 +1,14 @@
1
+ export type Hex = `0x${string}`
2
+
3
+ export function isHex(
4
+ value: unknown,
5
+ { strict = true }: { strict?: boolean | undefined } = {}
6
+ ): value is Hex {
7
+ if (!value) {
8
+ return false
9
+ }
10
+ if (typeof value !== 'string') {
11
+ return false
12
+ }
13
+ return strict ? /^0x[0-9a-fA-F]*$/.test(value) : value.startsWith('0x')
14
+ }
@@ -0,0 +1,31 @@
1
+ import type { RouteOptions, RoutesRequest } from '@lifi/types'
2
+
3
+ const isRoutesOptions = (
4
+ routeOptions: RouteOptions
5
+ ): routeOptions is RouteOptions =>
6
+ !routeOptions?.slippage || typeof routeOptions.slippage === 'number'
7
+
8
+ export const isRoutesRequest = (
9
+ routesRequest: RoutesRequest
10
+ ): routesRequest is RoutesRequest => {
11
+ const {
12
+ fromChainId,
13
+ fromAmount,
14
+ fromTokenAddress,
15
+ toChainId,
16
+ toTokenAddress,
17
+ options,
18
+ } = routesRequest
19
+
20
+ return (
21
+ typeof fromChainId === 'number' &&
22
+ typeof fromAmount === 'string' &&
23
+ fromAmount !== '' &&
24
+ typeof fromTokenAddress === 'string' &&
25
+ fromTokenAddress !== '' &&
26
+ typeof toChainId === 'number' &&
27
+ typeof toTokenAddress === 'string' &&
28
+ toTokenAddress !== '' &&
29
+ (!options || isRoutesOptions(options))
30
+ )
31
+ }
@@ -0,0 +1,41 @@
1
+ import type { Action, Estimate, LiFiStep } from '@lifi/types'
2
+ import { isToken } from './isToken.js'
3
+
4
+ const isAction = (action: Action): action is Action => {
5
+ const { fromChainId, fromAmount, fromToken, toChainId, toToken } = action
6
+
7
+ return (
8
+ typeof fromChainId === 'number' &&
9
+ typeof fromAmount === 'string' &&
10
+ fromAmount !== '' &&
11
+ isToken(fromToken) &&
12
+ typeof toChainId === 'number' &&
13
+ isToken(toToken)
14
+ )
15
+ }
16
+
17
+ const isEstimate = (estimate: Estimate): estimate is Estimate => {
18
+ const { fromAmount, toAmount, toAmountMin, approvalAddress } = estimate
19
+
20
+ return (
21
+ typeof fromAmount === 'string' &&
22
+ fromAmount !== '' &&
23
+ typeof toAmount === 'string' &&
24
+ toAmount !== '' &&
25
+ typeof toAmountMin === 'string' &&
26
+ toAmountMin !== '' &&
27
+ (typeof approvalAddress === 'string' || approvalAddress === null)
28
+ )
29
+ }
30
+
31
+ export const isStep = (step: LiFiStep): step is LiFiStep => {
32
+ const { id, type, tool, action, estimate } = step
33
+
34
+ return (
35
+ typeof id === 'string' &&
36
+ ['swap', 'cross', 'lifi'].includes(type) &&
37
+ typeof tool === 'string' &&
38
+ isAction(action) &&
39
+ isEstimate(estimate)
40
+ )
41
+ }
@@ -0,0 +1,11 @@
1
+ import type { StaticToken } from '@lifi/types'
2
+
3
+ export const isToken = (token: StaticToken): token is StaticToken => {
4
+ const { address, decimals, chainId } = token
5
+
6
+ return (
7
+ typeof address === 'string' &&
8
+ typeof decimals === 'number' &&
9
+ typeof chainId === 'number'
10
+ )
11
+ }
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Multiplies a string representation of a number by a given exponent of base 10 (10exponent).
3
+ */
4
+ export function parseUnits(value: string, decimals: number): bigint {
5
+ if (!/^(-?)([0-9]*)\.?([0-9]*)$/.test(value)) {
6
+ throw new Error(`Number \`${value}\` is not a valid decimal number.`)
7
+ }
8
+
9
+ let [integer, fraction = '0'] = value.split('.')
10
+
11
+ const negative = integer.startsWith('-')
12
+ if (negative) {
13
+ integer = integer.slice(1)
14
+ }
15
+
16
+ // trim trailing zeros.
17
+ fraction = fraction.replace(/(0+)$/, '')
18
+
19
+ // round off if the fraction is larger than the number of decimals.
20
+ if (decimals === 0) {
21
+ if (Math.round(Number(`.${fraction}`)) === 1) {
22
+ integer = `${BigInt(integer) + 1n}`
23
+ }
24
+ fraction = ''
25
+ } else if (fraction.length > decimals) {
26
+ const [left, unit, right] = [
27
+ fraction.slice(0, decimals - 1),
28
+ fraction.slice(decimals - 1, decimals),
29
+ fraction.slice(decimals),
30
+ ]
31
+
32
+ const rounded = Math.round(Number(`${unit}.${right}`))
33
+ if (rounded > 9) {
34
+ fraction = `${BigInt(left) + BigInt(1)}0`.padStart(left.length + 1, '0')
35
+ } else {
36
+ fraction = `${left}${rounded}`
37
+ }
38
+
39
+ if (fraction.length > decimals) {
40
+ fraction = fraction.slice(1)
41
+ integer = `${BigInt(integer) + 1n}`
42
+ }
43
+
44
+ fraction = fraction.slice(0, decimals)
45
+ } else {
46
+ fraction = fraction.padEnd(decimals, '0')
47
+ }
48
+
49
+ return BigInt(`${negative ? '-' : ''}${integer}${fraction}`)
50
+ }
@@ -0,0 +1,100 @@
1
+ import { ValidationError } from '../errors/errors.js'
2
+ import { HTTPError } from '../errors/httpError.js'
3
+ import { SDKError } from '../errors/SDKError.js'
4
+ import type { SDKBaseConfig } from '../types/core.js'
5
+ import type { ExtendedRequestInit } from '../types/request.js'
6
+ import { version } from '../version.js'
7
+ import { sleep } from './sleep.js'
8
+
9
+ export const requestSettings = {
10
+ retries: 1,
11
+ }
12
+
13
+ const stripExtendRequestInitProperties = ({
14
+ retries,
15
+ ...rest
16
+ }: ExtendedRequestInit): RequestInit => ({
17
+ ...rest,
18
+ })
19
+
20
+ export const request = async <T = Response>(
21
+ config: SDKBaseConfig,
22
+ url: RequestInfo | URL,
23
+ options: ExtendedRequestInit = {
24
+ retries: requestSettings.retries,
25
+ }
26
+ ): Promise<T> => {
27
+ const { userId, integrator, widgetVersion, apiKey, requestInterceptor } =
28
+ config
29
+
30
+ if (!integrator) {
31
+ throw new SDKError(
32
+ new ValidationError(
33
+ 'You need to provide the Integrator property. Please see documentation https://docs.li.fi/integrate-li.fi-js-sdk/set-up-the-sdk'
34
+ )
35
+ )
36
+ }
37
+
38
+ options.retries = options.retries ?? requestSettings.retries
39
+
40
+ try {
41
+ if (apiKey) {
42
+ options.headers = {
43
+ ...options.headers,
44
+ 'x-lifi-api-key': apiKey,
45
+ }
46
+ }
47
+
48
+ if (userId) {
49
+ options.headers = {
50
+ ...options.headers,
51
+ 'x-lifi-userid': userId,
52
+ }
53
+ }
54
+
55
+ if (widgetVersion) {
56
+ options.headers = {
57
+ ...options.headers,
58
+ 'x-lifi-widget': widgetVersion,
59
+ }
60
+ }
61
+
62
+ if (version) {
63
+ options.headers = {
64
+ ...options.headers,
65
+ 'x-lifi-sdk': version,
66
+ }
67
+ }
68
+
69
+ // integrator is mandatory during SDK initialization
70
+ options.headers = {
71
+ ...options.headers,
72
+ 'x-lifi-integrator': integrator,
73
+ }
74
+
75
+ if (requestInterceptor) {
76
+ options = await requestInterceptor(options)
77
+ }
78
+
79
+ const response: Response = await fetch(
80
+ url,
81
+ stripExtendRequestInitProperties(options)
82
+ )
83
+
84
+ if (!response.ok) {
85
+ throw new HTTPError(response, url, options)
86
+ }
87
+
88
+ return await response.json()
89
+ } catch (error) {
90
+ const retries = options.retries ?? 0
91
+ if (retries > 0 && (error as HTTPError).status === 500) {
92
+ await sleep(500)
93
+ return request<T>(config, url, { ...options, retries: retries - 1 })
94
+ }
95
+
96
+ await (error as HTTPError).buildAdditionalDetails?.()
97
+
98
+ throw new SDKError(error as HTTPError)
99
+ }
100
+ }
@@ -0,0 +1,5 @@
1
+ export function sleep(ms: number): Promise<null> {
2
+ return new Promise((resolve) => {
3
+ setTimeout(() => resolve(null), ms)
4
+ })
5
+ }
@@ -0,0 +1,45 @@
1
+ import { sleep } from './sleep.js'
2
+
3
+ /**
4
+ * Repeatedly calls a given asynchronous function until it resolves with a value
5
+ * @param fn The function that should be repeated
6
+ * @param interval The timeout in milliseconds between retries, or a function that receives the current poll count and returns the interval. Defaults to 5000
7
+ * @param maxRetries Maximum number of retries before throwing an error, defaults to 3
8
+ * @param shouldRetry Optional predicate to determine if an error should trigger a retry
9
+ * @returns The result of the fn function
10
+ * @throws Error if maximum retries is reached, if function keeps returning undefined, or if shouldRetry returns false
11
+ */
12
+ export const waitForResult = async <T>(
13
+ fn: () => Promise<T | undefined>,
14
+ interval: number | ((poll: number) => number) = 5000,
15
+ maxRetries = 3,
16
+ shouldRetry: (count: number, error: unknown) => boolean = () => true
17
+ ): Promise<T> => {
18
+ let result: T | undefined
19
+ let attempts = 0
20
+ let polls = 0
21
+
22
+ const getInterval = typeof interval === 'function' ? interval : () => interval
23
+
24
+ while (!result) {
25
+ try {
26
+ result = await fn()
27
+ if (!result) {
28
+ await sleep(getInterval(polls))
29
+ polls++
30
+ }
31
+ } catch (error) {
32
+ if (!shouldRetry(attempts, error)) {
33
+ throw error
34
+ }
35
+ attempts++
36
+ if (attempts === maxRetries) {
37
+ throw error
38
+ }
39
+ await sleep(getInterval(polls))
40
+ polls++
41
+ }
42
+ }
43
+
44
+ return result
45
+ }
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Map with a LRU (Least recently used) policy.
3
+ *
4
+ * https://en.wikipedia.org/wiki/Cache_replacement_policies#LRU
5
+ */
6
+ export class LruMap<value = unknown> extends Map<string, value> {
7
+ maxSize: number
8
+
9
+ constructor(size: number) {
10
+ super()
11
+ this.maxSize = size
12
+ }
13
+
14
+ override set(key: string, value: value): this {
15
+ super.set(key, value)
16
+ if (this.maxSize && this.size > this.maxSize) {
17
+ this.delete(this.keys().next().value!)
18
+ }
19
+ return this
20
+ }
21
+ }
22
+
23
+ /** @internal */
24
+ const promiseCache = /*#__PURE__*/ new LruMap<Promise<any>>(8192)
25
+
26
+ type WithDedupeOptions = {
27
+ enabled?: boolean | undefined
28
+ id?: string | undefined
29
+ }
30
+
31
+ /** Deduplicates in-flight promises. */
32
+ export function withDedupe<T>(
33
+ fn: () => Promise<T>,
34
+ { enabled = true, id }: WithDedupeOptions
35
+ ): Promise<T> {
36
+ if (!enabled || !id) {
37
+ return fn()
38
+ }
39
+ if (promiseCache.get(id)) {
40
+ return promiseCache.get(id)!
41
+ }
42
+ const promise = fn().finally(() => promiseCache.delete(id))
43
+ promiseCache.set(id, promise)
44
+ return promise
45
+ }
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Wraps a function in a timeout.
3
+ * Based on viem's withTimeout implementation.
4
+ * @param fn - The function to wrap.
5
+ * @param timeout - The timeout in milliseconds.
6
+ * @param errorInstance - The error instance to throw when the timeout is reached.
7
+ * @param signal - Whether or not the timeout should use an abort signal.
8
+ * @returns The result of the function.
9
+ */
10
+ export function withTimeout<T>(
11
+ fn: ({ signal }: { signal: AbortController['signal'] | null }) => Promise<T>,
12
+ {
13
+ errorInstance = new Error('Timed out after waiting for too long.'),
14
+ timeout,
15
+ signal,
16
+ }: {
17
+ // The error instance to throw when the timeout is reached.
18
+ errorInstance?: Error | undefined
19
+ // The timeout (in ms).
20
+ timeout: number
21
+ // Whether or not the timeout should use an abort signal.
22
+ signal?: boolean | undefined
23
+ }
24
+ ): Promise<T> {
25
+ return new Promise((resolve, reject) => {
26
+ ;(async () => {
27
+ let timeoutId!: NodeJS.Timeout
28
+ try {
29
+ const controller = new AbortController()
30
+ if (timeout > 0) {
31
+ timeoutId = setTimeout(() => {
32
+ if (signal) {
33
+ controller.abort()
34
+ } else {
35
+ reject(errorInstance)
36
+ }
37
+ }, timeout) as NodeJS.Timeout // need to cast because bun globals.d.ts overrides @types/node
38
+ }
39
+ resolve(await fn({ signal: controller?.signal || null }))
40
+ } catch (err) {
41
+ if ((err as Error)?.name === 'AbortError') {
42
+ reject(errorInstance)
43
+ }
44
+ reject(err)
45
+ } finally {
46
+ clearTimeout(timeoutId)
47
+ }
48
+ })()
49
+ })
50
+ }
package/src/version.ts ADDED
@@ -0,0 +1,2 @@
1
+ export const name = '@lifi/sdk'
2
+ export const version = '0.0.0-preview-f5cf9f8'