@lifi/sdk 3.3.0-alpha.3 → 3.3.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (431) hide show
  1. package/README.md +2 -2
  2. package/package.json +5 -8
  3. package/src/_cjs/config.js +4 -1
  4. package/src/_cjs/config.js.map +1 -1
  5. package/src/_cjs/core/EVM/EVM.js +1 -1
  6. package/src/_cjs/core/EVM/EVMStepExecutor.js +19 -7
  7. package/src/_cjs/core/EVM/EVMStepExecutor.js.map +1 -1
  8. package/src/_cjs/core/EVM/checkAllowance.js +5 -1
  9. package/src/_cjs/core/EVM/checkAllowance.js.map +1 -1
  10. package/src/_cjs/core/EVM/getAllowance.js +3 -3
  11. package/src/_cjs/core/EVM/getAllowance.js.map +1 -1
  12. package/src/_cjs/core/EVM/getEVMBalance.js +4 -6
  13. package/src/_cjs/core/EVM/getEVMBalance.js.map +1 -1
  14. package/src/_cjs/core/EVM/parseEVMErrors.js +3 -3
  15. package/src/_cjs/core/EVM/parseEVMErrors.js.map +1 -1
  16. package/src/_cjs/core/EVM/switchChain.js +5 -1
  17. package/src/_cjs/core/EVM/switchChain.js.map +1 -1
  18. package/src/_cjs/core/EVM/utils.js +4 -1
  19. package/src/_cjs/core/EVM/utils.js.map +1 -1
  20. package/src/_cjs/core/EVM/waitForTransactionReceipt.js +5 -4
  21. package/src/_cjs/core/EVM/waitForTransactionReceipt.js.map +1 -1
  22. package/src/_cjs/core/Solana/Solana.js +1 -1
  23. package/src/_cjs/core/Solana/SolanaStepExecutor.js +14 -6
  24. package/src/_cjs/core/Solana/SolanaStepExecutor.js.map +1 -1
  25. package/src/_cjs/core/Solana/connection.js +1 -3
  26. package/src/_cjs/core/Solana/connection.js.map +1 -1
  27. package/src/_cjs/core/Solana/getSolanaBalance.js +3 -3
  28. package/src/_cjs/core/Solana/getSolanaBalance.js.map +1 -1
  29. package/src/_cjs/core/Solana/isSVMAddress.js +1 -1
  30. package/src/_cjs/core/Solana/isSVMAddress.js.map +1 -1
  31. package/src/_cjs/core/Solana/parseSolanaErrors.js +1 -1
  32. package/src/_cjs/core/Solana/parseSolanaErrors.js.map +1 -1
  33. package/src/_cjs/core/StatusManager.js +4 -3
  34. package/src/_cjs/core/StatusManager.js.map +1 -1
  35. package/src/_cjs/core/UTXO/UTXO.js +1 -1
  36. package/src/_cjs/core/UTXO/UTXOStepExecutor.js +43 -21
  37. package/src/_cjs/core/UTXO/UTXOStepExecutor.js.map +1 -1
  38. package/src/_cjs/core/UTXO/getUTXOBalance.js +3 -3
  39. package/src/_cjs/core/UTXO/getUTXOBalance.js.map +1 -1
  40. package/src/_cjs/core/UTXO/getUTXOPublicClient.js +1 -0
  41. package/src/_cjs/core/UTXO/getUTXOPublicClient.js.map +1 -1
  42. package/src/_cjs/core/UTXO/isUTXOAddress.js +7 -7
  43. package/src/_cjs/core/UTXO/isUTXOAddress.js.map +1 -1
  44. package/src/_cjs/core/UTXO/parseUTXOErrors.js +5 -1
  45. package/src/_cjs/core/UTXO/parseUTXOErrors.js.map +1 -1
  46. package/src/_cjs/core/UTXO/utxo-stack/actions/getBlock.js +31 -0
  47. package/src/_cjs/core/UTXO/utxo-stack/actions/getBlock.js.map +1 -0
  48. package/src/_cjs/core/UTXO/utxo-stack/actions/getBlockStats.js +27 -0
  49. package/src/_cjs/core/UTXO/utxo-stack/actions/getBlockStats.js.map +1 -0
  50. package/src/_cjs/core/UTXO/utxo-stack/actions/getUTXOTransaction.js +18 -9
  51. package/src/_cjs/core/UTXO/utxo-stack/actions/getUTXOTransaction.js.map +1 -1
  52. package/src/_cjs/core/UTXO/utxo-stack/actions/waitForTransaction.js +185 -0
  53. package/src/_cjs/core/UTXO/utxo-stack/actions/waitForTransaction.js.map +1 -0
  54. package/src/_cjs/core/UTXO/utxo-stack/actions/watchBlockNumber.js +45 -0
  55. package/src/_cjs/core/UTXO/utxo-stack/actions/watchBlockNumber.js.map +1 -0
  56. package/src/_cjs/core/UTXO/utxo-stack/decorators/UTXOAPIActions.js.map +1 -1
  57. package/src/_cjs/core/UTXO/utxo-stack/types/blockStats.js +3 -0
  58. package/src/_cjs/core/UTXO/utxo-stack/types/blockStats.js.map +1 -0
  59. package/src/_cjs/core/UTXO/utxo-stack/utils/cancelTransaction.js +51 -0
  60. package/src/_cjs/core/UTXO/utxo-stack/utils/cancelTransaction.js.map +1 -0
  61. package/src/_cjs/core/UTXO/utxo-stack/utils/modifyFee.js +50 -0
  62. package/src/_cjs/core/UTXO/utxo-stack/utils/modifyFee.js.map +1 -0
  63. package/src/_cjs/core/UTXO/utxo-stack/utils/observe.js +48 -0
  64. package/src/_cjs/core/UTXO/utxo-stack/utils/observe.js.map +1 -0
  65. package/src/_cjs/core/UTXO/utxo-stack/utils/poll.js +30 -0
  66. package/src/_cjs/core/UTXO/utxo-stack/utils/poll.js.map +1 -0
  67. package/src/_cjs/core/checkBalance.js +2 -7
  68. package/src/_cjs/core/checkBalance.js.map +1 -1
  69. package/src/_cjs/core/execution.js.map +1 -1
  70. package/src/_cjs/core/stepComparison.js +1 -1
  71. package/src/_cjs/core/waitForReceivingTransaction.js +36 -41
  72. package/src/_cjs/core/waitForReceivingTransaction.js.map +1 -1
  73. package/src/_cjs/createConfig.js.map +1 -1
  74. package/src/_cjs/errors/baseError.js +1 -1
  75. package/src/_cjs/errors/baseError.js.map +1 -1
  76. package/src/_cjs/errors/constants.js +1 -0
  77. package/src/_cjs/errors/constants.js.map +1 -1
  78. package/src/_cjs/errors/errors.js +1 -1
  79. package/src/_cjs/errors/errors.js.map +1 -1
  80. package/src/_cjs/errors/httpError.js +1 -1
  81. package/src/_cjs/errors/httpError.js.map +1 -1
  82. package/src/_cjs/helpers.js +3 -3
  83. package/src/_cjs/helpers.js.map +1 -1
  84. package/src/_cjs/index.js +67 -11
  85. package/src/_cjs/index.js.map +1 -1
  86. package/src/_cjs/request.js +1 -1
  87. package/src/_cjs/request.js.map +1 -1
  88. package/src/_cjs/services/api.js +30 -18
  89. package/src/_cjs/services/api.js.map +1 -1
  90. package/src/_cjs/services/balance.js +11 -4
  91. package/src/_cjs/services/balance.js.map +1 -1
  92. package/src/_cjs/utils/getTransactionMessage.js +3 -4
  93. package/src/_cjs/utils/getTransactionMessage.js.map +1 -1
  94. package/src/_cjs/utils/withDedupe.js.map +1 -1
  95. package/src/_cjs/version.js +1 -1
  96. package/src/_cjs/version.js.map +1 -1
  97. package/src/_esm/config.js +4 -1
  98. package/src/_esm/config.js.map +1 -1
  99. package/src/_esm/core/EVM/EVM.js +1 -1
  100. package/src/_esm/core/EVM/EVMStepExecutor.js +18 -6
  101. package/src/_esm/core/EVM/EVMStepExecutor.js.map +1 -1
  102. package/src/_esm/core/EVM/checkAllowance.js +5 -1
  103. package/src/_esm/core/EVM/checkAllowance.js.map +1 -1
  104. package/src/_esm/core/EVM/getAllowance.js +3 -3
  105. package/src/_esm/core/EVM/getAllowance.js.map +1 -1
  106. package/src/_esm/core/EVM/getEVMBalance.js +4 -6
  107. package/src/_esm/core/EVM/getEVMBalance.js.map +1 -1
  108. package/src/_esm/core/EVM/parseEVMErrors.js +2 -3
  109. package/src/_esm/core/EVM/parseEVMErrors.js.map +1 -1
  110. package/src/_esm/core/EVM/publicClient.js +1 -1
  111. package/src/_esm/core/EVM/publicClient.js.map +1 -1
  112. package/src/_esm/core/EVM/switchChain.js +5 -1
  113. package/src/_esm/core/EVM/switchChain.js.map +1 -1
  114. package/src/_esm/core/EVM/types.js +0 -1
  115. package/src/_esm/core/EVM/types.js.map +1 -1
  116. package/src/_esm/core/EVM/utils.js +4 -2
  117. package/src/_esm/core/EVM/utils.js.map +1 -1
  118. package/src/_esm/core/EVM/waitForTransactionReceipt.js +3 -2
  119. package/src/_esm/core/EVM/waitForTransactionReceipt.js.map +1 -1
  120. package/src/_esm/core/Solana/Solana.js +1 -1
  121. package/src/_esm/core/Solana/SolanaStepExecutor.js +13 -6
  122. package/src/_esm/core/Solana/SolanaStepExecutor.js.map +1 -1
  123. package/src/_esm/core/Solana/connection.js +1 -3
  124. package/src/_esm/core/Solana/connection.js.map +1 -1
  125. package/src/_esm/core/Solana/getSolanaBalance.js +3 -3
  126. package/src/_esm/core/Solana/getSolanaBalance.js.map +1 -1
  127. package/src/_esm/core/Solana/isSVMAddress.js +1 -1
  128. package/src/_esm/core/Solana/isSVMAddress.js.map +1 -1
  129. package/src/_esm/core/Solana/parseSolanaErrors.js +1 -1
  130. package/src/_esm/core/Solana/parseSolanaErrors.js.map +1 -1
  131. package/src/_esm/core/Solana/types.js +0 -1
  132. package/src/_esm/core/Solana/types.js.map +1 -1
  133. package/src/_esm/core/StatusManager.js +13 -6
  134. package/src/_esm/core/StatusManager.js.map +1 -1
  135. package/src/_esm/core/UTXO/UTXO.js +1 -1
  136. package/src/_esm/core/UTXO/UTXOStepExecutor.js +44 -38
  137. package/src/_esm/core/UTXO/UTXOStepExecutor.js.map +1 -1
  138. package/src/_esm/core/UTXO/getUTXOAPIPublicClient.js.map +1 -1
  139. package/src/_esm/core/UTXO/getUTXOBalance.js +3 -3
  140. package/src/_esm/core/UTXO/getUTXOBalance.js.map +1 -1
  141. package/src/_esm/core/UTXO/getUTXOPublicClient.js +2 -1
  142. package/src/_esm/core/UTXO/getUTXOPublicClient.js.map +1 -1
  143. package/src/_esm/core/UTXO/isUTXOAddress.js +7 -7
  144. package/src/_esm/core/UTXO/isUTXOAddress.js.map +1 -1
  145. package/src/_esm/core/UTXO/parseUTXOErrors.js +6 -1
  146. package/src/_esm/core/UTXO/parseUTXOErrors.js.map +1 -1
  147. package/src/_esm/core/UTXO/types.js +0 -1
  148. package/src/_esm/core/UTXO/types.js.map +1 -1
  149. package/src/_esm/core/UTXO/utxo-stack/actions/getBalance.js +0 -1
  150. package/src/_esm/core/UTXO/utxo-stack/actions/getBalance.js.map +1 -1
  151. package/src/_esm/core/UTXO/utxo-stack/actions/getBlock.js +28 -0
  152. package/src/_esm/core/UTXO/utxo-stack/actions/getBlock.js.map +1 -0
  153. package/src/_esm/core/UTXO/utxo-stack/actions/getBlockCount.js +0 -1
  154. package/src/_esm/core/UTXO/utxo-stack/actions/getBlockCount.js.map +1 -1
  155. package/src/_esm/core/UTXO/utxo-stack/actions/getBlockStats.js +24 -0
  156. package/src/_esm/core/UTXO/utxo-stack/actions/getBlockStats.js.map +1 -0
  157. package/src/_esm/core/UTXO/utxo-stack/actions/getUTXOTransaction.js +18 -10
  158. package/src/_esm/core/UTXO/utxo-stack/actions/getUTXOTransaction.js.map +1 -1
  159. package/src/_esm/core/UTXO/utxo-stack/actions/sendUTXOTransaction.js +0 -1
  160. package/src/_esm/core/UTXO/utxo-stack/actions/sendUTXOTransaction.js.map +1 -1
  161. package/src/_esm/core/UTXO/utxo-stack/actions/signPsbt.js +0 -1
  162. package/src/_esm/core/UTXO/utxo-stack/actions/signPsbt.js.map +1 -1
  163. package/src/_esm/core/UTXO/utxo-stack/actions/waitForTransaction.js +230 -0
  164. package/src/_esm/core/UTXO/utxo-stack/actions/waitForTransaction.js.map +1 -0
  165. package/src/_esm/core/UTXO/utxo-stack/actions/watchBlockNumber.js +58 -0
  166. package/src/_esm/core/UTXO/utxo-stack/actions/watchBlockNumber.js.map +1 -0
  167. package/src/_esm/core/UTXO/utxo-stack/decorators/UTXOAPIActions.js.map +1 -1
  168. package/src/_esm/core/UTXO/utxo-stack/decorators/UTXOActions.js.map +1 -1
  169. package/src/_esm/core/UTXO/utxo-stack/transports/utxo/getHttpRpcClient.js +1 -1
  170. package/src/_esm/core/UTXO/utxo-stack/transports/utxo/getHttpRpcClient.js.map +1 -1
  171. package/src/_esm/core/UTXO/utxo-stack/transports/utxo/utxo.js +1 -1
  172. package/src/_esm/core/UTXO/utxo-stack/transports/utxo/utxo.js.map +1 -1
  173. package/src/_esm/core/UTXO/utxo-stack/types/blockStats.js +2 -0
  174. package/src/_esm/core/UTXO/utxo-stack/types/blockStats.js.map +1 -0
  175. package/src/_esm/core/UTXO/utxo-stack/utils/cancelTransaction.js +55 -0
  176. package/src/_esm/core/UTXO/utxo-stack/utils/cancelTransaction.js.map +1 -0
  177. package/src/_esm/core/UTXO/utxo-stack/utils/modifyFee.js +53 -0
  178. package/src/_esm/core/UTXO/utxo-stack/utils/modifyFee.js.map +1 -0
  179. package/src/_esm/core/UTXO/utxo-stack/utils/observe.js +51 -0
  180. package/src/_esm/core/UTXO/utxo-stack/utils/observe.js.map +1 -0
  181. package/src/_esm/core/UTXO/utxo-stack/utils/poll.js +30 -0
  182. package/src/_esm/core/UTXO/utxo-stack/utils/poll.js.map +1 -0
  183. package/src/_esm/core/checkBalance.js +2 -7
  184. package/src/_esm/core/checkBalance.js.map +1 -1
  185. package/src/_esm/core/execution.js.map +1 -1
  186. package/src/_esm/core/processMessages.js +0 -1
  187. package/src/_esm/core/processMessages.js.map +1 -1
  188. package/src/_esm/core/rpc.js +0 -1
  189. package/src/_esm/core/rpc.js.map +1 -1
  190. package/src/_esm/core/stepComparison.js +1 -1
  191. package/src/_esm/core/utils.js +0 -1
  192. package/src/_esm/core/utils.js.map +1 -1
  193. package/src/_esm/core/waitForReceivingTransaction.js +36 -41
  194. package/src/_esm/core/waitForReceivingTransaction.js.map +1 -1
  195. package/src/_esm/createConfig.js +0 -1
  196. package/src/_esm/createConfig.js.map +1 -1
  197. package/src/_esm/errors/SDKError.js +0 -1
  198. package/src/_esm/errors/SDKError.js.map +1 -1
  199. package/src/_esm/errors/baseError.js +2 -2
  200. package/src/_esm/errors/baseError.js.map +1 -1
  201. package/src/_esm/errors/constants.js +1 -0
  202. package/src/_esm/errors/constants.js.map +1 -1
  203. package/src/_esm/errors/errors.js +1 -1
  204. package/src/_esm/errors/errors.js.map +1 -1
  205. package/src/_esm/errors/httpError.js +2 -2
  206. package/src/_esm/errors/httpError.js.map +1 -1
  207. package/src/_esm/helpers.js +4 -6
  208. package/src/_esm/helpers.js.map +1 -1
  209. package/src/_esm/index.js +13 -9
  210. package/src/_esm/index.js.map +1 -1
  211. package/src/_esm/request.js +1 -1
  212. package/src/_esm/request.js.map +1 -1
  213. package/src/_esm/services/api.js +30 -19
  214. package/src/_esm/services/api.js.map +1 -1
  215. package/src/_esm/services/balance.js +11 -4
  216. package/src/_esm/services/balance.js.map +1 -1
  217. package/src/_esm/utils/getTransactionMessage.js +3 -4
  218. package/src/_esm/utils/getTransactionMessage.js.map +1 -1
  219. package/src/_esm/utils/withDedupe.js +0 -1
  220. package/src/_esm/utils/withDedupe.js.map +1 -1
  221. package/src/_esm/version.js +1 -1
  222. package/src/_esm/version.js.map +1 -1
  223. package/src/_types/config.d.ts.map +1 -1
  224. package/src/_types/core/EVM/EVMStepExecutor.d.ts.map +1 -1
  225. package/src/_types/core/EVM/checkAllowance.d.ts.map +1 -1
  226. package/src/_types/core/EVM/getEVMBalance.d.ts.map +1 -1
  227. package/src/_types/core/EVM/parseEVMErrors.d.ts +1 -1
  228. package/src/_types/core/EVM/parseEVMErrors.d.ts.map +1 -1
  229. package/src/_types/core/EVM/types.d.ts +1 -1
  230. package/src/_types/core/EVM/types.d.ts.map +1 -1
  231. package/src/_types/core/EVM/utils.d.ts +1 -1
  232. package/src/_types/core/EVM/utils.d.ts.map +1 -1
  233. package/src/_types/core/EVM/waitForTransactionReceipt.d.ts.map +1 -1
  234. package/src/_types/core/Solana/SolanaStepExecutor.d.ts +1 -1
  235. package/src/_types/core/Solana/SolanaStepExecutor.d.ts.map +1 -1
  236. package/src/_types/core/Solana/connection.d.ts.map +1 -1
  237. package/src/_types/core/Solana/parseSolanaErrors.d.ts.map +1 -1
  238. package/src/_types/core/Solana/types.d.ts +1 -1
  239. package/src/_types/core/Solana/types.d.ts.map +1 -1
  240. package/src/_types/core/StatusManager.d.ts +18 -8
  241. package/src/_types/core/StatusManager.d.ts.map +1 -1
  242. package/src/_types/core/UTXO/UTXOStepExecutor.d.ts.map +1 -1
  243. package/src/_types/core/UTXO/getUTXOAPIPublicClient.d.ts.map +1 -1
  244. package/src/_types/core/UTXO/getUTXOBalance.d.ts.map +1 -1
  245. package/src/_types/core/UTXO/getUTXOPublicClient.d.ts.map +1 -1
  246. package/src/_types/core/UTXO/isUTXOAddress.d.ts.map +1 -1
  247. package/src/_types/core/UTXO/parseUTXOErrors.d.ts.map +1 -1
  248. package/src/_types/core/UTXO/types.d.ts +1 -1
  249. package/src/_types/core/UTXO/types.d.ts.map +1 -1
  250. package/src/_types/core/UTXO/utxo-stack/actions/getBalance.d.ts +1 -1
  251. package/src/_types/core/UTXO/utxo-stack/actions/getBalance.d.ts.map +1 -1
  252. package/src/_types/core/UTXO/utxo-stack/actions/getBlock.d.ts +13 -0
  253. package/src/_types/core/UTXO/utxo-stack/actions/getBlock.d.ts.map +1 -0
  254. package/src/_types/core/UTXO/utxo-stack/actions/getBlockCount.d.ts +1 -1
  255. package/src/_types/core/UTXO/utxo-stack/actions/getBlockCount.d.ts.map +1 -1
  256. package/src/_types/core/UTXO/utxo-stack/actions/getBlockStats.d.ts +15 -0
  257. package/src/_types/core/UTXO/utxo-stack/actions/getBlockStats.d.ts.map +1 -0
  258. package/src/_types/core/UTXO/utxo-stack/actions/getUTXOTransaction.d.ts +2 -2
  259. package/src/_types/core/UTXO/utxo-stack/actions/getUTXOTransaction.d.ts.map +1 -1
  260. package/src/_types/core/UTXO/utxo-stack/actions/sendUTXOTransaction.d.ts +2 -2
  261. package/src/_types/core/UTXO/utxo-stack/actions/sendUTXOTransaction.d.ts.map +1 -1
  262. package/src/_types/core/UTXO/utxo-stack/actions/signPsbt.d.ts +1 -1
  263. package/src/_types/core/UTXO/utxo-stack/actions/signPsbt.d.ts.map +1 -1
  264. package/src/_types/core/UTXO/utxo-stack/actions/waitForTransaction.d.ts +76 -0
  265. package/src/_types/core/UTXO/utxo-stack/actions/waitForTransaction.d.ts.map +1 -0
  266. package/src/_types/core/UTXO/utxo-stack/actions/watchBlockNumber.d.ts +26 -0
  267. package/src/_types/core/UTXO/utxo-stack/actions/watchBlockNumber.d.ts.map +1 -0
  268. package/src/_types/core/UTXO/utxo-stack/decorators/UTXOAPIActions.d.ts.map +1 -1
  269. package/src/_types/core/UTXO/utxo-stack/decorators/UTXOActions.d.ts.map +1 -1
  270. package/src/_types/core/UTXO/utxo-stack/transports/utxo/types.d.ts +16 -0
  271. package/src/_types/core/UTXO/utxo-stack/transports/utxo/types.d.ts.map +1 -1
  272. package/src/_types/core/UTXO/utxo-stack/transports/utxo/utxo.d.ts.map +1 -1
  273. package/src/_types/core/UTXO/utxo-stack/types/blockStats.d.ts +35 -0
  274. package/src/_types/core/UTXO/utxo-stack/types/blockStats.d.ts.map +1 -0
  275. package/src/_types/core/UTXO/utxo-stack/utils/cancelTransaction.d.ts +3 -0
  276. package/src/_types/core/UTXO/utxo-stack/utils/cancelTransaction.d.ts.map +1 -0
  277. package/src/_types/core/UTXO/utxo-stack/utils/modifyFee.d.ts +3 -0
  278. package/src/_types/core/UTXO/utxo-stack/utils/modifyFee.d.ts.map +1 -0
  279. package/src/_types/core/UTXO/utxo-stack/utils/observe.d.ts +19 -0
  280. package/src/_types/core/UTXO/utxo-stack/utils/observe.d.ts.map +1 -0
  281. package/src/_types/core/UTXO/utxo-stack/utils/poll.d.ts +13 -0
  282. package/src/_types/core/UTXO/utxo-stack/utils/poll.d.ts.map +1 -0
  283. package/src/_types/core/checkBalance.d.ts.map +1 -1
  284. package/src/_types/core/execution.d.ts.map +1 -1
  285. package/src/_types/core/processMessages.d.ts +1 -1
  286. package/src/_types/core/processMessages.d.ts.map +1 -1
  287. package/src/_types/core/rpc.d.ts +1 -1
  288. package/src/_types/core/rpc.d.ts.map +1 -1
  289. package/src/_types/core/utils.d.ts +1 -1
  290. package/src/_types/core/utils.d.ts.map +1 -1
  291. package/src/_types/core/waitForReceivingTransaction.d.ts.map +1 -1
  292. package/src/_types/createConfig.d.ts +1 -1
  293. package/src/_types/createConfig.d.ts.map +1 -1
  294. package/src/_types/errors/SDKError.d.ts +1 -1
  295. package/src/_types/errors/SDKError.d.ts.map +1 -1
  296. package/src/_types/errors/constants.d.ts +2 -1
  297. package/src/_types/errors/constants.d.ts.map +1 -1
  298. package/src/_types/errors/errors.d.ts +1 -1
  299. package/src/_types/errors/errors.d.ts.map +1 -1
  300. package/src/_types/errors/httpError.d.ts +1 -1
  301. package/src/_types/errors/httpError.d.ts.map +1 -1
  302. package/src/_types/helpers.d.ts +1 -1
  303. package/src/_types/helpers.d.ts.map +1 -1
  304. package/src/_types/index.d.ts +15 -9
  305. package/src/_types/index.d.ts.map +1 -1
  306. package/src/_types/services/api.d.ts.map +1 -1
  307. package/src/_types/services/balance.d.ts.map +1 -1
  308. package/src/_types/types/internal.d.ts +1 -39
  309. package/src/_types/types/internal.d.ts.map +1 -1
  310. package/src/_types/utils/getTransactionMessage.d.ts.map +1 -1
  311. package/src/_types/utils/withDedupe.d.ts.map +1 -1
  312. package/src/_types/version.d.ts +1 -1
  313. package/src/_types/version.d.ts.map +1 -1
  314. package/src/config.ts +4 -1
  315. package/src/core/EVM/EVM.ts +1 -1
  316. package/src/core/EVM/EVMStepExecutor.ts +15 -13
  317. package/src/core/EVM/checkAllowance.ts +4 -3
  318. package/src/core/EVM/getAllowance.ts +3 -3
  319. package/src/core/EVM/getEVMBalance.ts +4 -5
  320. package/src/core/EVM/parseEVMErrors.ts +3 -3
  321. package/src/core/EVM/publicClient.ts +2 -2
  322. package/src/core/EVM/switchChain.ts +5 -5
  323. package/src/core/EVM/types.ts +2 -2
  324. package/src/core/EVM/utils.ts +5 -5
  325. package/src/core/EVM/waitForTransactionReceipt.ts +3 -2
  326. package/src/core/Solana/Solana.ts +1 -1
  327. package/src/core/Solana/SolanaStepExecutor.ts +13 -12
  328. package/src/core/Solana/connection.ts +1 -2
  329. package/src/core/Solana/getSolanaBalance.ts +3 -3
  330. package/src/core/Solana/isSVMAddress.ts +1 -1
  331. package/src/core/Solana/parseSolanaErrors.ts +1 -1
  332. package/src/core/Solana/types.ts +1 -1
  333. package/src/core/StatusManager.ts +26 -28
  334. package/src/core/UTXO/UTXO.ts +1 -1
  335. package/src/core/UTXO/UTXOStepExecutor.ts +59 -56
  336. package/src/core/UTXO/getUTXOAPIPublicClient.ts +3 -3
  337. package/src/core/UTXO/getUTXOBalance.ts +3 -4
  338. package/src/core/UTXO/getUTXOPublicClient.ts +4 -3
  339. package/src/core/UTXO/isUTXOAddress.ts +10 -11
  340. package/src/core/UTXO/parseUTXOErrors.ts +12 -1
  341. package/src/core/UTXO/types.ts +1 -1
  342. package/src/core/UTXO/utxo-stack/actions/getBalance.ts +1 -1
  343. package/src/core/UTXO/utxo-stack/actions/getBlock.ts +58 -0
  344. package/src/core/UTXO/utxo-stack/actions/getBlockCount.ts +1 -1
  345. package/src/core/UTXO/utxo-stack/actions/getBlockStats.ts +55 -0
  346. package/src/core/UTXO/utxo-stack/actions/getUTXOTransaction.ts +24 -11
  347. package/src/core/UTXO/utxo-stack/actions/sendUTXOTransaction.ts +2 -2
  348. package/src/core/UTXO/utxo-stack/actions/signPsbt.ts +1 -1
  349. package/src/core/UTXO/utxo-stack/actions/waitForTransaction.ts +387 -0
  350. package/src/core/UTXO/utxo-stack/actions/watchBlockNumber.ts +105 -0
  351. package/src/core/UTXO/utxo-stack/decorators/UTXOAPIActions.ts +1 -2
  352. package/src/core/UTXO/utxo-stack/decorators/UTXOActions.ts +3 -3
  353. package/src/core/UTXO/utxo-stack/transports/utxo/getHttpRpcClient.ts +1 -1
  354. package/src/core/UTXO/utxo-stack/transports/utxo/types.ts +16 -0
  355. package/src/core/UTXO/utxo-stack/transports/utxo/utxo.ts +3 -3
  356. package/src/core/UTXO/utxo-stack/types/blockStats.ts +35 -0
  357. package/src/core/UTXO/utxo-stack/utils/cancelTransaction.ts +75 -0
  358. package/src/core/UTXO/utxo-stack/utils/modifyFee.ts +78 -0
  359. package/src/core/UTXO/utxo-stack/utils/observe.ts +81 -0
  360. package/src/core/UTXO/utxo-stack/utils/poll.ts +48 -0
  361. package/src/core/checkBalance.ts +2 -8
  362. package/src/core/execution.ts +0 -1
  363. package/src/core/processMessages.ts +5 -5
  364. package/src/core/rpc.ts +1 -1
  365. package/src/core/stepComparison.ts +1 -1
  366. package/src/core/utils.ts +1 -1
  367. package/src/core/waitForReceivingTransaction.ts +42 -46
  368. package/src/createConfig.ts +1 -2
  369. package/src/errors/SDKError.ts +1 -1
  370. package/src/errors/baseError.ts +2 -2
  371. package/src/errors/constants.ts +1 -0
  372. package/src/errors/errors.ts +1 -1
  373. package/src/errors/httpError.ts +3 -3
  374. package/src/helpers.ts +4 -5
  375. package/src/index.ts +84 -9
  376. package/src/request.ts +1 -1
  377. package/src/services/api.ts +29 -33
  378. package/src/services/balance.ts +13 -4
  379. package/src/types/internal.ts +1 -40
  380. package/src/utils/getTransactionMessage.ts +3 -4
  381. package/src/utils/withDedupe.ts +0 -1
  382. package/src/version.ts +1 -1
  383. package/src/_cjs/core/UTXO/blockchairApi.js +0 -169
  384. package/src/_cjs/core/UTXO/blockchairApi.js.map +0 -1
  385. package/src/_cjs/core/UTXO/blockchairApiTypes.js +0 -26
  386. package/src/_cjs/core/UTXO/blockchairApiTypes.js.map +0 -1
  387. package/src/_cjs/core/UTXO/requestClient.js +0 -63
  388. package/src/_cjs/core/UTXO/requestClient.js.map +0 -1
  389. package/src/_cjs/core/index.js +0 -7
  390. package/src/_cjs/core/index.js.map +0 -1
  391. package/src/_cjs/errors/index.js +0 -11
  392. package/src/_cjs/errors/index.js.map +0 -1
  393. package/src/_cjs/types/index.js +0 -5
  394. package/src/_cjs/types/index.js.map +0 -1
  395. package/src/_cjs/utils/index.js +0 -8
  396. package/src/_cjs/utils/index.js.map +0 -1
  397. package/src/_esm/core/UTXO/blockchairApi.js +0 -167
  398. package/src/_esm/core/UTXO/blockchairApi.js.map +0 -1
  399. package/src/_esm/core/UTXO/blockchairApiTypes.js +0 -23
  400. package/src/_esm/core/UTXO/blockchairApiTypes.js.map +0 -1
  401. package/src/_esm/core/UTXO/requestClient.js +0 -59
  402. package/src/_esm/core/UTXO/requestClient.js.map +0 -1
  403. package/src/_esm/core/index.js +0 -4
  404. package/src/_esm/core/index.js.map +0 -1
  405. package/src/_esm/errors/index.js +0 -8
  406. package/src/_esm/errors/index.js.map +0 -1
  407. package/src/_esm/types/index.js +0 -2
  408. package/src/_esm/types/index.js.map +0 -1
  409. package/src/_esm/utils/index.js +0 -5
  410. package/src/_esm/utils/index.js.map +0 -1
  411. package/src/_types/core/UTXO/blockchairApi.d.ts +0 -37
  412. package/src/_types/core/UTXO/blockchairApi.d.ts.map +0 -1
  413. package/src/_types/core/UTXO/blockchairApiTypes.d.ts +0 -229
  414. package/src/_types/core/UTXO/blockchairApiTypes.d.ts.map +0 -1
  415. package/src/_types/core/UTXO/requestClient.d.ts +0 -22
  416. package/src/_types/core/UTXO/requestClient.d.ts.map +0 -1
  417. package/src/_types/core/index.d.ts +0 -4
  418. package/src/_types/core/index.d.ts.map +0 -1
  419. package/src/_types/errors/index.d.ts +0 -8
  420. package/src/_types/errors/index.d.ts.map +0 -1
  421. package/src/_types/types/index.d.ts +0 -2
  422. package/src/_types/types/index.d.ts.map +0 -1
  423. package/src/_types/utils/index.d.ts +0 -5
  424. package/src/_types/utils/index.d.ts.map +0 -1
  425. package/src/core/UTXO/blockchairApi.ts +0 -273
  426. package/src/core/UTXO/blockchairApiTypes.ts +0 -253
  427. package/src/core/UTXO/requestClient.ts +0 -84
  428. package/src/core/index.ts +0 -3
  429. package/src/errors/index.ts +0 -7
  430. package/src/types/index.ts +0 -1
  431. package/src/utils/index.ts +0 -4
@@ -0,0 +1,105 @@
1
+ import { type Chain, type Client, type Transport, stringify } from 'viem'
2
+ import { getAction } from 'viem/utils'
3
+ import { observe } from '../utils/observe.js'
4
+ import { poll } from '../utils/poll.js'
5
+ import { type GetBlockCountReturnType, getBlockCount } from './getBlockCount.js'
6
+
7
+ export type OnBlockNumberParameter = GetBlockCountReturnType
8
+ export type OnBlockNumberFn = (
9
+ blockNumber: OnBlockNumberParameter,
10
+ prevBlockNumber: OnBlockNumberParameter | undefined
11
+ ) => Promise<void>
12
+
13
+ export type WatchBlockNumberParameters = {
14
+ /** The callback to call when a new block number is received. */
15
+ onBlockNumber: OnBlockNumberFn
16
+ /** The callback to call when an error occurred when trying to get for a new block. */
17
+ onError?: ((error: Error) => void) | undefined
18
+ } & {
19
+ /** Whether or not to emit the missed block numbers to the callback. */
20
+ emitMissed?: boolean | undefined
21
+ /** Whether or not to emit the latest block number to the callback when the subscription opens. */
22
+ emitOnBegin?: boolean | undefined
23
+ /** Polling frequency (in ms). Defaults to Client's pollingInterval config. */
24
+ pollingInterval?: number | undefined
25
+ }
26
+
27
+ export type WatchBlockNumberReturnType = () => void
28
+
29
+ /**
30
+ * Watches and returns incoming block numbers.
31
+ * @param client - Client to use
32
+ * @param parameters - {@link WatchBlockNumberParameters}
33
+ * @returns A function that can be invoked to stop watching for new block numbers. {@link WatchBlockNumberReturnType}
34
+ */
35
+ export function watchBlockNumber<
36
+ chain extends Chain | undefined,
37
+ transport extends Transport,
38
+ >(
39
+ client: Client<transport, chain>,
40
+ {
41
+ emitOnBegin = false,
42
+ emitMissed = false,
43
+ onBlockNumber,
44
+ onError,
45
+ pollingInterval = client.pollingInterval,
46
+ }: WatchBlockNumberParameters
47
+ ): WatchBlockNumberReturnType {
48
+ let prevBlockNumber: GetBlockCountReturnType | undefined
49
+
50
+ const observerId = stringify([
51
+ 'watchBlockNumber',
52
+ client.uid,
53
+ emitOnBegin,
54
+ emitMissed,
55
+ pollingInterval,
56
+ ])
57
+
58
+ // TODO (edge cases):
59
+ // 1) Stop iterating block numbers if we are happy with the result of one onBlockNumber execution but there is more in the queue.
60
+ // 2) If we missed some time - user closed the page and came back when the block is already mined.
61
+ // In this case we probably want to save the block when we send the transaction and track the currently checked blocks until we find the relevant one.
62
+ return observe(observerId, { onBlockNumber, onError }, (emit) =>
63
+ poll(
64
+ async () => {
65
+ try {
66
+ const blockNumber = await getAction(
67
+ client,
68
+ getBlockCount,
69
+ 'getBlockCount'
70
+ )({ cacheTime: 0 })
71
+
72
+ if (prevBlockNumber) {
73
+ // If the current block number is the same as the previous,
74
+ // we can skip.
75
+ if (blockNumber === prevBlockNumber) {
76
+ return
77
+ }
78
+
79
+ // If we have missed out on some previous blocks, and the
80
+ // `emitMissed` flag is truthy, let's emit those blocks.
81
+ if (blockNumber - prevBlockNumber > 1 && emitMissed) {
82
+ for (let i = prevBlockNumber + 1; i < blockNumber; i++) {
83
+ await emit.onBlockNumber(i, prevBlockNumber)
84
+ prevBlockNumber = i
85
+ }
86
+ }
87
+ }
88
+
89
+ // If the next block number is greater than the previous,
90
+ // it is not in the past, and we can emit the new block number.
91
+ if (!prevBlockNumber || blockNumber > prevBlockNumber) {
92
+ await emit.onBlockNumber(blockNumber, prevBlockNumber)
93
+ prevBlockNumber = blockNumber
94
+ }
95
+ } catch (err) {
96
+ emit.onError?.(err as Error)
97
+ }
98
+ },
99
+ {
100
+ emitOnBegin,
101
+ interval: pollingInterval,
102
+ }
103
+ )
104
+ )
105
+ }
@@ -1,9 +1,8 @@
1
- /* eslint-disable @typescript-eslint/no-unused-vars */
2
1
  import type { Account, Chain, Client, Transport } from 'viem'
3
2
  import {
4
- getBalance,
5
3
  type GetBalanceParameters,
6
4
  type GetBalanceReturnType,
5
+ getBalance,
7
6
  } from '../actions/getBalance.js'
8
7
 
9
8
  export type UTXOAPIActions = {
@@ -1,17 +1,17 @@
1
1
  import type { Account, Chain, Client, Transport } from 'viem'
2
2
  import {
3
- getBlockCount,
4
3
  type GetBlockCountReturnType,
4
+ getBlockCount,
5
5
  } from '../actions/getBlockCount.js'
6
6
  import {
7
- getUTXOTransaction,
8
7
  type GetUTXOTransactionParameters,
9
8
  type GetUTXOTransactionReturnType,
9
+ getUTXOTransaction,
10
10
  } from '../actions/getUTXOTransaction.js'
11
11
  import {
12
- sendUTXOTransaction,
13
12
  type SendUTXOTransactionParameters,
14
13
  type SendUTXOTransactionReturnType,
14
+ sendUTXOTransaction,
15
15
  } from '../actions/sendUTXOTransaction.js'
16
16
 
17
17
  export type UTXOActions = {
@@ -1,4 +1,4 @@
1
- import { HttpRequestError, stringify, TimeoutError, withTimeout } from 'viem'
1
+ import { HttpRequestError, TimeoutError, stringify, withTimeout } from 'viem'
2
2
  import type { HttpRequestReturnType, HttpRpcClientOptions } from 'viem/utils'
3
3
 
4
4
  export type RpcRequest = {
@@ -1,3 +1,4 @@
1
+ import type { BlockStats, BlockStatsKeys } from '../../types/blockStats.js'
1
2
  import type { UTXOTransaction } from '../../types/transaction.js'
2
3
  import type { HttpRpcClient } from './getHttpRpcClient.js'
3
4
 
@@ -7,6 +8,21 @@ export type UTXOSchema = [
7
8
  Parameters: []
8
9
  ReturnType: number
9
10
  },
11
+ {
12
+ Method: 'getblockhash'
13
+ Parameters: [number]
14
+ ReturnType: string
15
+ },
16
+ {
17
+ Method: 'getblock'
18
+ Parameters: [string, number]
19
+ ReturnType: string
20
+ },
21
+ {
22
+ Method: 'getblockstats'
23
+ Parameters: [string | number, Array<BlockStatsKeys>?]
24
+ ReturnType: BlockStats
25
+ },
10
26
  {
11
27
  Method: 'sendrawtransaction'
12
28
  Parameters: [string, number?]
@@ -1,9 +1,9 @@
1
1
  import {
2
- createTransport,
3
- RpcRequestError,
4
- UrlRequiredError,
5
2
  type HttpTransport,
6
3
  type HttpTransportConfig,
4
+ RpcRequestError,
5
+ UrlRequiredError,
6
+ createTransport,
7
7
  } from 'viem'
8
8
  import { getHttpRpcClient } from './getHttpRpcClient.js'
9
9
  import { getRpcProviderMethods } from './getRpcProviderMethods.js'
@@ -0,0 +1,35 @@
1
+ export type BlockStats = Partial<{
2
+ avgfee: number
3
+ avgfeerate: number
4
+ avgtxsize: number
5
+ blockhash: string
6
+ feerate_percentiles: number[]
7
+ height: number
8
+ ins: number
9
+ maxfee: number
10
+ maxfeerate: number
11
+ maxtxsize: number
12
+ medianfee: number
13
+ mediantime: number
14
+ mediantxsize: number
15
+ minfee: number
16
+ minfeerate: number
17
+ mintxsize: number
18
+ outs: number
19
+ subsidy: number
20
+ swtotal_size: number
21
+ swtotal_weight: number
22
+ swtxs: number
23
+ time: number
24
+ total_out: number
25
+ total_size: number
26
+ total_weight: number
27
+ totalfee: number
28
+ txs: number
29
+ utxo_increase: number
30
+ utxo_size_inc: number
31
+ utxo_increase_actual: number
32
+ utxo_size_inc_actual: number
33
+ }>
34
+
35
+ export type BlockStatsKeys = keyof BlockStats
@@ -0,0 +1,75 @@
1
+ import { Psbt, address } from 'bitcoinjs-lib'
2
+
3
+ interface InputData {
4
+ hash: Uint8Array
5
+ index: number
6
+ nonWitnessUtxo?: Uint8Array
7
+ witnessUtxo?: {
8
+ script: Uint8Array
9
+ value: bigint
10
+ }
11
+ redeemScript?: Uint8Array
12
+ witnessScript?: Uint8Array
13
+ }
14
+
15
+ export function cancelTransaction(psbt: Psbt, accountAddress: string): Psbt {
16
+ const newPsbt = new Psbt()
17
+ const inputs = psbt.data.inputs
18
+ const txInputs = psbt.txInputs
19
+
20
+ // Add inputs to the new PSBT
21
+ for (let i = 0; i < inputs.length; i++) {
22
+ const input = inputs[i]
23
+ const txInput = txInputs[i]
24
+ const inputData: InputData = {
25
+ hash: txInput.hash,
26
+ index: txInput.index,
27
+ }
28
+
29
+ // Include UTXO information
30
+ if (input.nonWitnessUtxo) {
31
+ inputData.nonWitnessUtxo = input.nonWitnessUtxo
32
+ } else if (input.witnessUtxo) {
33
+ inputData.witnessUtxo = input.witnessUtxo
34
+ } else {
35
+ throw new Error('Input UTXO information is missing')
36
+ }
37
+
38
+ // Include scripts if necessary
39
+ if (input.redeemScript) {
40
+ inputData.redeemScript = input.redeemScript
41
+ }
42
+ if (input.witnessScript) {
43
+ inputData.witnessScript = input.witnessScript
44
+ }
45
+
46
+ newPsbt.addInput(inputData)
47
+ }
48
+
49
+ // Compute total output amount from the original transaction
50
+ const outputs = psbt.txOutputs
51
+ let totalOutputValue = BigInt(0)
52
+
53
+ for (const output of outputs) {
54
+ totalOutputValue += output.value
55
+ }
56
+
57
+ if (totalOutputValue <= BigInt(0)) {
58
+ throw new Error('Total output value must be greater than zero')
59
+ }
60
+
61
+ // Create the output to send funds back to sender's address
62
+ const outputScript = address.toOutputScript(accountAddress)
63
+ newPsbt.addOutput({
64
+ script: outputScript,
65
+ value: totalOutputValue,
66
+ })
67
+
68
+ // Modify the input sequence number to enable RBF
69
+ newPsbt.txInputs.forEach((_, index) => {
70
+ // Set sequence number to less than 0xfffffffe, e.g., 0xfffffffd
71
+ newPsbt.setInputSequence(index, 0xfffffffd)
72
+ })
73
+
74
+ return newPsbt
75
+ }
@@ -0,0 +1,78 @@
1
+ import { Psbt, address } from 'bitcoinjs-lib'
2
+
3
+ interface InputData {
4
+ hash: Uint8Array
5
+ index: number
6
+ nonWitnessUtxo?: Uint8Array
7
+ witnessUtxo?: {
8
+ script: Uint8Array
9
+ value: bigint
10
+ }
11
+ redeemScript?: Uint8Array
12
+ witnessScript?: Uint8Array
13
+ }
14
+
15
+ export function modifyFee(psbt: Psbt, newFee: bigint, accountAddress: string) {
16
+ const newPsbt = new Psbt()
17
+ const inputs = psbt.data.inputs
18
+ const outputs = psbt.txOutputs
19
+
20
+ // Add inputs to the new PSBT
21
+ for (let i = 0; i < inputs.length; i++) {
22
+ const input = inputs[i]
23
+ const inputData: InputData = {
24
+ hash: psbt.txInputs[i].hash,
25
+ index: psbt.txInputs[i].index,
26
+ }
27
+
28
+ // Include UTXO information
29
+ if (input.nonWitnessUtxo) {
30
+ inputData.nonWitnessUtxo = input.nonWitnessUtxo
31
+ } else if (input.witnessUtxo) {
32
+ inputData.witnessUtxo = input.witnessUtxo
33
+ }
34
+
35
+ // Include scripts if necessary
36
+ if (input.redeemScript) {
37
+ inputData.redeemScript = input.redeemScript
38
+ }
39
+ if (input.witnessScript) {
40
+ inputData.witnessScript = input.witnessScript
41
+ }
42
+
43
+ newPsbt.addInput(inputData)
44
+ }
45
+
46
+ const changeOutputScript = address.toOutputScript(accountAddress)
47
+
48
+ // Add outputs to the new PSBT
49
+ for (const output of outputs) {
50
+ const outputData = {
51
+ script: output.script,
52
+ value: output.value,
53
+ }
54
+
55
+ const scriptsAreEqual =
56
+ output.script.length === changeOutputScript.length &&
57
+ output.script.every((value, index) => value === changeOutputScript[index])
58
+
59
+ if (scriptsAreEqual) {
60
+ outputData.value = output.value - newFee
61
+ if (outputData.value < 0) {
62
+ throw new Error(
63
+ 'Insufficient funds to adjust the fee by the specified amount.'
64
+ )
65
+ }
66
+ }
67
+
68
+ newPsbt.addOutput(outputData)
69
+ }
70
+
71
+ // Modify the input sequence number to enable RBF
72
+ newPsbt.txInputs.forEach((_, index) => {
73
+ // Set sequence number to less than 0xfffffffe, e.g., 0xfffffffd
74
+ newPsbt.setInputSequence(index, 0xfffffffd)
75
+ })
76
+
77
+ return newPsbt
78
+ }
@@ -0,0 +1,81 @@
1
+ import type { MaybePromise } from 'viem'
2
+
3
+ type Callback = ((...args: any[]) => any) | undefined
4
+ type Callbacks = Record<string, Callback>
5
+
6
+ /** @internal */
7
+ export const listenersCache = /*#__PURE__*/ new Map<
8
+ string,
9
+ { id: number; fns: Callbacks }[]
10
+ >()
11
+ /** @internal */
12
+ export const cleanupCache = /*#__PURE__*/ new Map<string, () => void>()
13
+
14
+ type EmitFunction<callbacks extends Callbacks> = (
15
+ emit: callbacks
16
+ ) => MaybePromise<void | (() => void)>
17
+
18
+ let callbackCount = 0
19
+
20
+ /**
21
+ * @description Sets up an observer for a given function. If another function
22
+ * is set up under the same observer id, the function will only be called once
23
+ * for both instances of the observer.
24
+ */
25
+ export function observe<callbacks extends Callbacks>(
26
+ observerId: string,
27
+ callbacks: callbacks,
28
+ fn: EmitFunction<callbacks>
29
+ ) {
30
+ const callbackId = ++callbackCount
31
+
32
+ const getListeners = () => listenersCache.get(observerId) || []
33
+
34
+ const unsubscribe = () => {
35
+ const listeners = getListeners()
36
+ listenersCache.set(
37
+ observerId,
38
+ listeners.filter((cb: any) => cb.id !== callbackId)
39
+ )
40
+ }
41
+
42
+ const unwatch = () => {
43
+ const cleanup = cleanupCache.get(observerId)
44
+ if (getListeners().length === 1 && cleanup) {
45
+ cleanup()
46
+ }
47
+ unsubscribe()
48
+ }
49
+
50
+ const listeners = getListeners()
51
+ listenersCache.set(observerId, [
52
+ ...listeners,
53
+ { id: callbackId, fns: callbacks },
54
+ ])
55
+
56
+ if (listeners && listeners.length > 0) {
57
+ return unwatch
58
+ }
59
+
60
+ const emit: callbacks = {} as callbacks
61
+ for (const key in callbacks) {
62
+ emit[key] = ((
63
+ ...args: Parameters<NonNullable<callbacks[keyof callbacks]>>
64
+ ) => {
65
+ const listeners = getListeners()
66
+ if (listeners.length === 0) {
67
+ return
68
+ }
69
+ for (const listener of listeners) {
70
+ listener.fns[key]?.(...args)
71
+ }
72
+ }) as callbacks[Extract<keyof callbacks, string>]
73
+ }
74
+
75
+ const cleanup = fn(emit)
76
+ if (typeof cleanup === 'function') {
77
+ cleanupCache.set(observerId, cleanup)
78
+ }
79
+
80
+ return unwatch
81
+ }
@@ -0,0 +1,48 @@
1
+ import { sleep } from '../../../../utils/sleep.js'
2
+
3
+ type PollOptions<T> = {
4
+ // Whether or not to emit when the polling starts.
5
+ emitOnBegin?: boolean | undefined
6
+ // The initial wait time (in ms) before polling.
7
+ initialWaitTime?: ((data: T | undefined) => Promise<number>) | undefined
8
+ // The interval (in ms).
9
+ interval: number
10
+ }
11
+
12
+ /**
13
+ * @description Polls a function at a specified interval.
14
+ */
15
+ export function poll<T>(
16
+ fn: ({ unpoll }: { unpoll: () => void }) => Promise<T | undefined>,
17
+ { emitOnBegin, initialWaitTime, interval }: PollOptions<T>
18
+ ) {
19
+ let active = true
20
+
21
+ const unwatch = () => {
22
+ active = false
23
+ }
24
+
25
+ const watch = async () => {
26
+ let data: T | undefined = undefined
27
+ if (emitOnBegin) {
28
+ data = await fn({ unpoll: unwatch })
29
+ }
30
+
31
+ const initialWait = (await initialWaitTime?.(data)) ?? interval
32
+ await sleep(initialWait)
33
+
34
+ const poll = async () => {
35
+ if (!active) {
36
+ return
37
+ }
38
+ await fn({ unpoll: unwatch })
39
+ await sleep(interval)
40
+ poll()
41
+ }
42
+
43
+ poll()
44
+ }
45
+ watch()
46
+
47
+ return unwatch
48
+ }
@@ -28,16 +28,10 @@ export const checkBalance = async (
28
28
  } else {
29
29
  const neeeded = formatUnits(neededBalance, token.decimals)
30
30
  const current = formatUnits(currentBalance, token.decimals)
31
- let errorMessage =
32
- `Your ${token.symbol} balance is too low, ` +
33
- `you try to transfer ${neeeded} ${token.symbol}, ` +
34
- `but your wallet only holds ${current} ${token.symbol}. ` +
35
- `No funds have been sent.`
31
+ let _errorMessage = `Your ${token.symbol} balance is too low, you try to transfer ${neeeded} ${token.symbol}, but your wallet only holds ${current} ${token.symbol}. No funds have been sent.`
36
32
 
37
33
  if (currentBalance !== 0n) {
38
- errorMessage +=
39
- `If the problem consists, please delete this transfer and ` +
40
- `start a new one with a maximum of ${current} ${token.symbol}.`
34
+ _errorMessage += `If the problem consists, please delete this transfer and start a new one with a maximum of ${current} ${token.symbol}.`
41
35
  }
42
36
 
43
37
  throw new BalanceError('The balance is too low.')
@@ -1,4 +1,3 @@
1
- /* eslint-disable @typescript-eslint/no-empty-function */
2
1
  import type { Route } from '@lifi/types'
3
2
  import { config } from '../config.js'
4
3
  import { executionState } from './executionState.js'
@@ -1,8 +1,8 @@
1
- import {
2
- type ProcessStatus,
3
- type ProcessType,
4
- type StatusMessage,
5
- type Substatus,
1
+ import type {
2
+ ProcessStatus,
3
+ ProcessType,
4
+ StatusMessage,
5
+ Substatus,
6
6
  } from '@lifi/types'
7
7
 
8
8
  const processMessages: Record<
package/src/core/rpc.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { type ChainId } from '@lifi/types'
1
+ import type { ChainId } from '@lifi/types'
2
2
  import { config } from '../config.js'
3
3
 
4
4
  export const getRpcUrl = async (chainId: ChainId): Promise<string> => {
@@ -42,7 +42,7 @@ export const stepComparison = async (
42
42
  // The user declined the new exchange rate, so we are not going to proceed
43
43
  throw new TransactionError(
44
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.`
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
46
  )
47
47
  }
48
48
 
package/src/core/utils.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { type LiFiStep } from '@lifi/types'
1
+ import type { LiFiStep } from '@lifi/types'
2
2
 
3
3
  /**
4
4
  * Used to check if changed exchange rate is in the range of slippage threshold.
@@ -17,59 +17,55 @@ export async function waitForReceivingTransaction(
17
17
  statusManager: StatusManager,
18
18
  processType: ProcessType,
19
19
  step: LiFiStep,
20
- interval: number = 5_000
20
+ interval = 5_000
21
21
  ): Promise<StatusResponse> {
22
- const _getStatus = (): Promise<StatusResponse | undefined> =>
23
- new Promise(async (resolve, reject) => {
24
- let statusResponse: StatusResponse
25
- try {
26
- statusResponse = await getStatus({
27
- fromChain: step.action.fromChainId,
28
- toChain: step.action.toChainId,
29
- txHash,
30
- ...(step.tool !== 'custom' && { bridge: step.tool }),
31
- })
32
- } catch (e: any) {
33
- console.debug('Fetching status from backend failed.', e)
34
- return resolve(undefined)
35
- }
36
-
37
- switch (statusResponse.status) {
38
- case 'DONE':
39
- return resolve(statusResponse)
40
- case 'PENDING':
41
- statusManager?.updateProcess(step, processType, 'PENDING', {
42
- substatus: statusResponse.substatus,
43
- substatusMessage:
44
- statusResponse.substatusMessage ||
45
- getSubstatusMessage(
46
- statusResponse.status,
47
- statusResponse.substatus
48
- ),
49
- txLink: (statusResponse as FullStatusData).bridgeExplorerLink,
50
- })
51
- return resolve(undefined)
52
- case 'NOT_FOUND':
53
- return resolve(undefined)
54
- case 'INVALID':
55
- case 'FAILED':
56
- default:
57
- return reject()
58
- }
22
+ const _getStatus = (): Promise<StatusResponse | undefined> => {
23
+ return getStatus({
24
+ fromChain: step.action.fromChainId,
25
+ toChain: step.action.toChainId,
26
+ txHash,
27
+ ...(step.tool !== 'custom' && { bridge: step.tool }),
59
28
  })
29
+ .then((statusResponse) => {
30
+ switch (statusResponse.status) {
31
+ case 'DONE':
32
+ return statusResponse
33
+ case 'PENDING':
34
+ statusManager?.updateProcess(step, processType, 'PENDING', {
35
+ substatus: statusResponse.substatus,
36
+ substatusMessage:
37
+ statusResponse.substatusMessage ||
38
+ getSubstatusMessage(
39
+ statusResponse.status,
40
+ statusResponse.substatus
41
+ ),
42
+ txLink: (statusResponse as FullStatusData).bridgeExplorerLink,
43
+ })
44
+ return undefined
45
+ case 'NOT_FOUND':
46
+ return undefined
47
+ default:
48
+ return Promise.reject()
49
+ }
50
+ })
51
+ .catch((e) => {
52
+ console.debug('Fetching status from backend failed.', e)
53
+ return undefined
54
+ })
55
+ }
60
56
 
61
- let status
57
+ let status = TRANSACTION_HASH_OBSERVERS[txHash]
62
58
 
63
- if (txHash in TRANSACTION_HASH_OBSERVERS) {
64
- status = await TRANSACTION_HASH_OBSERVERS[txHash]
65
- } else {
66
- TRANSACTION_HASH_OBSERVERS[txHash] = waitForResult(_getStatus, interval)
67
- status = await TRANSACTION_HASH_OBSERVERS[txHash]
59
+ if (!status) {
60
+ status = waitForResult(_getStatus, interval)
61
+ TRANSACTION_HASH_OBSERVERS[txHash] = status
68
62
  }
69
63
 
70
- if (!('receiving' in status)) {
64
+ const resolvedStatus = await status
65
+
66
+ if (!('receiving' in resolvedStatus)) {
71
67
  throw new ServerError("Status doesn't contain receiving information.")
72
68
  }
73
69
 
74
- return status
70
+ return resolvedStatus
75
71
  }
@@ -1,9 +1,8 @@
1
- /* eslint-disable @typescript-eslint/no-empty-function */
2
1
  import { ChainType } from '@lifi/types'
3
2
  import { config } from './config.js'
4
3
  import { checkPackageUpdates } from './helpers.js'
5
4
  import { getChains } from './services/api.js'
6
- import type { SDKConfig } from './types/index.js'
5
+ import type { SDKConfig } from './types/internal.js'
7
6
  import { name, version } from './version.js'
8
7
 
9
8
  function createBaseConfig(options: SDKConfig) {