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

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 (232) hide show
  1. package/package.json +4 -3
  2. package/src/_cjs/core/Solana/SolanaStepExecutor.js +10 -0
  3. package/src/_cjs/core/Solana/SolanaStepExecutor.js.map +1 -1
  4. package/src/_cjs/core/UTXO/UTXO.js +2 -2
  5. package/src/_cjs/core/UTXO/UTXO.js.map +1 -1
  6. package/src/_cjs/core/UTXO/UTXOStepExecutor.js +3 -4
  7. package/src/_cjs/core/UTXO/UTXOStepExecutor.js.map +1 -1
  8. package/src/_cjs/core/UTXO/getUTXOAPIPublicClient.js +7 -7
  9. package/src/_cjs/core/UTXO/getUTXOAPIPublicClient.js.map +1 -1
  10. package/src/_cjs/core/UTXO/getUTXOPublicClient.js +2 -2
  11. package/src/_cjs/core/UTXO/getUTXOPublicClient.js.map +1 -1
  12. package/src/_cjs/index.js +2 -4
  13. package/src/_cjs/index.js.map +1 -1
  14. package/src/_cjs/version.js +1 -1
  15. package/src/_esm/core/Solana/SolanaStepExecutor.js +10 -0
  16. package/src/_esm/core/Solana/SolanaStepExecutor.js.map +1 -1
  17. package/src/_esm/core/UTXO/UTXO.js +1 -1
  18. package/src/_esm/core/UTXO/UTXO.js.map +1 -1
  19. package/src/_esm/core/UTXO/UTXOStepExecutor.js +1 -2
  20. package/src/_esm/core/UTXO/UTXOStepExecutor.js.map +1 -1
  21. package/src/_esm/core/UTXO/getUTXOAPIPublicClient.js +2 -2
  22. package/src/_esm/core/UTXO/getUTXOAPIPublicClient.js.map +1 -1
  23. package/src/_esm/core/UTXO/getUTXOPublicClient.js +1 -1
  24. package/src/_esm/core/UTXO/getUTXOPublicClient.js.map +1 -1
  25. package/src/_esm/index.js +0 -1
  26. package/src/_esm/index.js.map +1 -1
  27. package/src/_esm/version.js +1 -1
  28. package/src/_types/core/Solana/SolanaStepExecutor.d.ts.map +1 -1
  29. package/src/_types/core/UTXO/UTXOStepExecutor.d.ts.map +1 -1
  30. package/src/_types/core/UTXO/getUTXOAPIPublicClient.d.ts +2 -2
  31. package/src/_types/core/UTXO/getUTXOAPIPublicClient.d.ts.map +1 -1
  32. package/src/_types/core/UTXO/getUTXOPublicClient.d.ts +2 -2
  33. package/src/_types/core/UTXO/getUTXOPublicClient.d.ts.map +1 -1
  34. package/src/_types/index.d.ts +0 -2
  35. package/src/_types/index.d.ts.map +1 -1
  36. package/src/_types/version.d.ts +1 -1
  37. package/src/core/Solana/SolanaStepExecutor.ts +12 -0
  38. package/src/core/UTXO/UTXO.ts +1 -1
  39. package/src/core/UTXO/UTXOStepExecutor.ts +2 -5
  40. package/src/core/UTXO/getUTXOAPIPublicClient.ts +3 -3
  41. package/src/core/UTXO/getUTXOPublicClient.ts +2 -2
  42. package/src/index.ts +0 -8
  43. package/src/version.ts +1 -1
  44. package/src/_cjs/core/UTXO/isUTXOAddress.js +0 -133
  45. package/src/_cjs/core/UTXO/isUTXOAddress.js.map +0 -1
  46. package/src/_cjs/core/UTXO/utxo-stack/actions/getBalance.js +0 -11
  47. package/src/_cjs/core/UTXO/utxo-stack/actions/getBalance.js.map +0 -1
  48. package/src/_cjs/core/UTXO/utxo-stack/actions/getBlock.js +0 -31
  49. package/src/_cjs/core/UTXO/utxo-stack/actions/getBlock.js.map +0 -1
  50. package/src/_cjs/core/UTXO/utxo-stack/actions/getBlockCount.js +0 -11
  51. package/src/_cjs/core/UTXO/utxo-stack/actions/getBlockCount.js.map +0 -1
  52. package/src/_cjs/core/UTXO/utxo-stack/actions/getBlockStats.js +0 -27
  53. package/src/_cjs/core/UTXO/utxo-stack/actions/getBlockStats.js.map +0 -1
  54. package/src/_cjs/core/UTXO/utxo-stack/actions/getUTXOTransaction.js +0 -24
  55. package/src/_cjs/core/UTXO/utxo-stack/actions/getUTXOTransaction.js.map +0 -1
  56. package/src/_cjs/core/UTXO/utxo-stack/actions/sendUTXOTransaction.js +0 -15
  57. package/src/_cjs/core/UTXO/utxo-stack/actions/sendUTXOTransaction.js.map +0 -1
  58. package/src/_cjs/core/UTXO/utxo-stack/actions/signPsbt.js +0 -11
  59. package/src/_cjs/core/UTXO/utxo-stack/actions/signPsbt.js.map +0 -1
  60. package/src/_cjs/core/UTXO/utxo-stack/actions/waitForTransaction.js +0 -185
  61. package/src/_cjs/core/UTXO/utxo-stack/actions/waitForTransaction.js.map +0 -1
  62. package/src/_cjs/core/UTXO/utxo-stack/actions/watchBlockNumber.js +0 -45
  63. package/src/_cjs/core/UTXO/utxo-stack/actions/watchBlockNumber.js.map +0 -1
  64. package/src/_cjs/core/UTXO/utxo-stack/clients/types.js +0 -3
  65. package/src/_cjs/core/UTXO/utxo-stack/clients/types.js.map +0 -1
  66. package/src/_cjs/core/UTXO/utxo-stack/decorators/UTXOAPIActions.js +0 -10
  67. package/src/_cjs/core/UTXO/utxo-stack/decorators/UTXOAPIActions.js.map +0 -1
  68. package/src/_cjs/core/UTXO/utxo-stack/decorators/UTXOActions.js +0 -14
  69. package/src/_cjs/core/UTXO/utxo-stack/decorators/UTXOActions.js.map +0 -1
  70. package/src/_cjs/core/UTXO/utxo-stack/transports/utxo/ankr.js +0 -21
  71. package/src/_cjs/core/UTXO/utxo-stack/transports/utxo/ankr.js.map +0 -1
  72. package/src/_cjs/core/UTXO/utxo-stack/transports/utxo/blockchair.js +0 -24
  73. package/src/_cjs/core/UTXO/utxo-stack/transports/utxo/blockchair.js.map +0 -1
  74. package/src/_cjs/core/UTXO/utxo-stack/transports/utxo/blockcypher.js +0 -21
  75. package/src/_cjs/core/UTXO/utxo-stack/transports/utxo/blockcypher.js.map +0 -1
  76. package/src/_cjs/core/UTXO/utxo-stack/transports/utxo/getHttpRpcClient.js +0 -77
  77. package/src/_cjs/core/UTXO/utxo-stack/transports/utxo/getHttpRpcClient.js.map +0 -1
  78. package/src/_cjs/core/UTXO/utxo-stack/transports/utxo/getRpcProviderMethods.js +0 -22
  79. package/src/_cjs/core/UTXO/utxo-stack/transports/utxo/getRpcProviderMethods.js.map +0 -1
  80. package/src/_cjs/core/UTXO/utxo-stack/transports/utxo/mempool.js +0 -17
  81. package/src/_cjs/core/UTXO/utxo-stack/transports/utxo/mempool.js.map +0 -1
  82. package/src/_cjs/core/UTXO/utxo-stack/transports/utxo/types.js +0 -3
  83. package/src/_cjs/core/UTXO/utxo-stack/transports/utxo/types.js.map +0 -1
  84. package/src/_cjs/core/UTXO/utxo-stack/transports/utxo/utxo.js +0 -56
  85. package/src/_cjs/core/UTXO/utxo-stack/transports/utxo/utxo.js.map +0 -1
  86. package/src/_cjs/core/UTXO/utxo-stack/types/blockStats.js +0 -3
  87. package/src/_cjs/core/UTXO/utxo-stack/types/blockStats.js.map +0 -1
  88. package/src/_cjs/core/UTXO/utxo-stack/types/transaction.js +0 -3
  89. package/src/_cjs/core/UTXO/utxo-stack/types/transaction.js.map +0 -1
  90. package/src/_cjs/core/UTXO/utxo-stack/utils/cancelTransaction.js +0 -51
  91. package/src/_cjs/core/UTXO/utxo-stack/utils/cancelTransaction.js.map +0 -1
  92. package/src/_cjs/core/UTXO/utxo-stack/utils/modifyFee.js +0 -50
  93. package/src/_cjs/core/UTXO/utxo-stack/utils/modifyFee.js.map +0 -1
  94. package/src/_cjs/core/UTXO/utxo-stack/utils/observe.js +0 -48
  95. package/src/_cjs/core/UTXO/utxo-stack/utils/observe.js.map +0 -1
  96. package/src/_cjs/core/UTXO/utxo-stack/utils/poll.js +0 -30
  97. package/src/_cjs/core/UTXO/utxo-stack/utils/poll.js.map +0 -1
  98. package/src/_esm/core/UTXO/isUTXOAddress.js +0 -128
  99. package/src/_esm/core/UTXO/isUTXOAddress.js.map +0 -1
  100. package/src/_esm/core/UTXO/utxo-stack/actions/getBalance.js +0 -8
  101. package/src/_esm/core/UTXO/utxo-stack/actions/getBalance.js.map +0 -1
  102. package/src/_esm/core/UTXO/utxo-stack/actions/getBlock.js +0 -28
  103. package/src/_esm/core/UTXO/utxo-stack/actions/getBlock.js.map +0 -1
  104. package/src/_esm/core/UTXO/utxo-stack/actions/getBlockCount.js +0 -8
  105. package/src/_esm/core/UTXO/utxo-stack/actions/getBlockCount.js.map +0 -1
  106. package/src/_esm/core/UTXO/utxo-stack/actions/getBlockStats.js +0 -24
  107. package/src/_esm/core/UTXO/utxo-stack/actions/getBlockStats.js.map +0 -1
  108. package/src/_esm/core/UTXO/utxo-stack/actions/getUTXOTransaction.js +0 -21
  109. package/src/_esm/core/UTXO/utxo-stack/actions/getUTXOTransaction.js.map +0 -1
  110. package/src/_esm/core/UTXO/utxo-stack/actions/sendUTXOTransaction.js +0 -12
  111. package/src/_esm/core/UTXO/utxo-stack/actions/sendUTXOTransaction.js.map +0 -1
  112. package/src/_esm/core/UTXO/utxo-stack/actions/signPsbt.js +0 -8
  113. package/src/_esm/core/UTXO/utxo-stack/actions/signPsbt.js.map +0 -1
  114. package/src/_esm/core/UTXO/utxo-stack/actions/waitForTransaction.js +0 -230
  115. package/src/_esm/core/UTXO/utxo-stack/actions/waitForTransaction.js.map +0 -1
  116. package/src/_esm/core/UTXO/utxo-stack/actions/watchBlockNumber.js +0 -58
  117. package/src/_esm/core/UTXO/utxo-stack/actions/watchBlockNumber.js.map +0 -1
  118. package/src/_esm/core/UTXO/utxo-stack/clients/types.js +0 -2
  119. package/src/_esm/core/UTXO/utxo-stack/clients/types.js.map +0 -1
  120. package/src/_esm/core/UTXO/utxo-stack/decorators/UTXOAPIActions.js +0 -7
  121. package/src/_esm/core/UTXO/utxo-stack/decorators/UTXOAPIActions.js.map +0 -1
  122. package/src/_esm/core/UTXO/utxo-stack/decorators/UTXOActions.js +0 -11
  123. package/src/_esm/core/UTXO/utxo-stack/decorators/UTXOActions.js.map +0 -1
  124. package/src/_esm/core/UTXO/utxo-stack/transports/utxo/ankr.js +0 -18
  125. package/src/_esm/core/UTXO/utxo-stack/transports/utxo/ankr.js.map +0 -1
  126. package/src/_esm/core/UTXO/utxo-stack/transports/utxo/blockchair.js +0 -21
  127. package/src/_esm/core/UTXO/utxo-stack/transports/utxo/blockchair.js.map +0 -1
  128. package/src/_esm/core/UTXO/utxo-stack/transports/utxo/blockcypher.js +0 -18
  129. package/src/_esm/core/UTXO/utxo-stack/transports/utxo/blockcypher.js.map +0 -1
  130. package/src/_esm/core/UTXO/utxo-stack/transports/utxo/getHttpRpcClient.js +0 -74
  131. package/src/_esm/core/UTXO/utxo-stack/transports/utxo/getHttpRpcClient.js.map +0 -1
  132. package/src/_esm/core/UTXO/utxo-stack/transports/utxo/getRpcProviderMethods.js +0 -19
  133. package/src/_esm/core/UTXO/utxo-stack/transports/utxo/getRpcProviderMethods.js.map +0 -1
  134. package/src/_esm/core/UTXO/utxo-stack/transports/utxo/mempool.js +0 -14
  135. package/src/_esm/core/UTXO/utxo-stack/transports/utxo/mempool.js.map +0 -1
  136. package/src/_esm/core/UTXO/utxo-stack/transports/utxo/types.js +0 -2
  137. package/src/_esm/core/UTXO/utxo-stack/transports/utxo/types.js.map +0 -1
  138. package/src/_esm/core/UTXO/utxo-stack/transports/utxo/utxo.js +0 -53
  139. package/src/_esm/core/UTXO/utxo-stack/transports/utxo/utxo.js.map +0 -1
  140. package/src/_esm/core/UTXO/utxo-stack/types/blockStats.js +0 -2
  141. package/src/_esm/core/UTXO/utxo-stack/types/blockStats.js.map +0 -1
  142. package/src/_esm/core/UTXO/utxo-stack/types/transaction.js +0 -2
  143. package/src/_esm/core/UTXO/utxo-stack/types/transaction.js.map +0 -1
  144. package/src/_esm/core/UTXO/utxo-stack/utils/cancelTransaction.js +0 -55
  145. package/src/_esm/core/UTXO/utxo-stack/utils/cancelTransaction.js.map +0 -1
  146. package/src/_esm/core/UTXO/utxo-stack/utils/modifyFee.js +0 -53
  147. package/src/_esm/core/UTXO/utxo-stack/utils/modifyFee.js.map +0 -1
  148. package/src/_esm/core/UTXO/utxo-stack/utils/observe.js +0 -51
  149. package/src/_esm/core/UTXO/utxo-stack/utils/observe.js.map +0 -1
  150. package/src/_esm/core/UTXO/utxo-stack/utils/poll.js +0 -30
  151. package/src/_esm/core/UTXO/utxo-stack/utils/poll.js.map +0 -1
  152. package/src/_types/core/UTXO/isUTXOAddress.d.ts +0 -21
  153. package/src/_types/core/UTXO/isUTXOAddress.d.ts.map +0 -1
  154. package/src/_types/core/UTXO/utxo-stack/actions/getBalance.d.ts +0 -9
  155. package/src/_types/core/UTXO/utxo-stack/actions/getBalance.d.ts.map +0 -1
  156. package/src/_types/core/UTXO/utxo-stack/actions/getBlock.d.ts +0 -13
  157. package/src/_types/core/UTXO/utxo-stack/actions/getBlock.d.ts.map +0 -1
  158. package/src/_types/core/UTXO/utxo-stack/actions/getBlockCount.d.ts +0 -5
  159. package/src/_types/core/UTXO/utxo-stack/actions/getBlockCount.d.ts.map +0 -1
  160. package/src/_types/core/UTXO/utxo-stack/actions/getBlockStats.d.ts +0 -15
  161. package/src/_types/core/UTXO/utxo-stack/actions/getBlockStats.d.ts.map +0 -1
  162. package/src/_types/core/UTXO/utxo-stack/actions/getUTXOTransaction.d.ts +0 -12
  163. package/src/_types/core/UTXO/utxo-stack/actions/getUTXOTransaction.d.ts.map +0 -1
  164. package/src/_types/core/UTXO/utxo-stack/actions/sendUTXOTransaction.d.ts +0 -11
  165. package/src/_types/core/UTXO/utxo-stack/actions/sendUTXOTransaction.d.ts.map +0 -1
  166. package/src/_types/core/UTXO/utxo-stack/actions/signPsbt.d.ts +0 -4
  167. package/src/_types/core/UTXO/utxo-stack/actions/signPsbt.d.ts.map +0 -1
  168. package/src/_types/core/UTXO/utxo-stack/actions/waitForTransaction.d.ts +0 -76
  169. package/src/_types/core/UTXO/utxo-stack/actions/waitForTransaction.d.ts.map +0 -1
  170. package/src/_types/core/UTXO/utxo-stack/actions/watchBlockNumber.d.ts +0 -26
  171. package/src/_types/core/UTXO/utxo-stack/actions/watchBlockNumber.d.ts.map +0 -1
  172. package/src/_types/core/UTXO/utxo-stack/clients/types.d.ts +0 -44
  173. package/src/_types/core/UTXO/utxo-stack/clients/types.d.ts.map +0 -1
  174. package/src/_types/core/UTXO/utxo-stack/decorators/UTXOAPIActions.d.ts +0 -7
  175. package/src/_types/core/UTXO/utxo-stack/decorators/UTXOAPIActions.d.ts.map +0 -1
  176. package/src/_types/core/UTXO/utxo-stack/decorators/UTXOActions.d.ts +0 -11
  177. package/src/_types/core/UTXO/utxo-stack/decorators/UTXOActions.d.ts.map +0 -1
  178. package/src/_types/core/UTXO/utxo-stack/transports/utxo/ankr.d.ts +0 -3
  179. package/src/_types/core/UTXO/utxo-stack/transports/utxo/ankr.d.ts.map +0 -1
  180. package/src/_types/core/UTXO/utxo-stack/transports/utxo/blockchair.d.ts +0 -3
  181. package/src/_types/core/UTXO/utxo-stack/transports/utxo/blockchair.d.ts.map +0 -1
  182. package/src/_types/core/UTXO/utxo-stack/transports/utxo/blockcypher.d.ts +0 -3
  183. package/src/_types/core/UTXO/utxo-stack/transports/utxo/blockcypher.d.ts.map +0 -1
  184. package/src/_types/core/UTXO/utxo-stack/transports/utxo/getHttpRpcClient.d.ts +0 -25
  185. package/src/_types/core/UTXO/utxo-stack/transports/utxo/getHttpRpcClient.d.ts.map +0 -1
  186. package/src/_types/core/UTXO/utxo-stack/transports/utxo/getRpcProviderMethods.d.ts +0 -3
  187. package/src/_types/core/UTXO/utxo-stack/transports/utxo/getRpcProviderMethods.d.ts.map +0 -1
  188. package/src/_types/core/UTXO/utxo-stack/transports/utxo/mempool.d.ts +0 -3
  189. package/src/_types/core/UTXO/utxo-stack/transports/utxo/mempool.d.ts.map +0 -1
  190. package/src/_types/core/UTXO/utxo-stack/transports/utxo/types.d.ts +0 -61
  191. package/src/_types/core/UTXO/utxo-stack/transports/utxo/types.d.ts.map +0 -1
  192. package/src/_types/core/UTXO/utxo-stack/transports/utxo/utxo.d.ts +0 -7
  193. package/src/_types/core/UTXO/utxo-stack/transports/utxo/utxo.d.ts.map +0 -1
  194. package/src/_types/core/UTXO/utxo-stack/types/blockStats.d.ts +0 -35
  195. package/src/_types/core/UTXO/utxo-stack/types/blockStats.d.ts.map +0 -1
  196. package/src/_types/core/UTXO/utxo-stack/types/transaction.d.ts +0 -42
  197. package/src/_types/core/UTXO/utxo-stack/types/transaction.d.ts.map +0 -1
  198. package/src/_types/core/UTXO/utxo-stack/utils/cancelTransaction.d.ts +0 -3
  199. package/src/_types/core/UTXO/utxo-stack/utils/cancelTransaction.d.ts.map +0 -1
  200. package/src/_types/core/UTXO/utxo-stack/utils/modifyFee.d.ts +0 -3
  201. package/src/_types/core/UTXO/utxo-stack/utils/modifyFee.d.ts.map +0 -1
  202. package/src/_types/core/UTXO/utxo-stack/utils/observe.d.ts +0 -19
  203. package/src/_types/core/UTXO/utxo-stack/utils/observe.d.ts.map +0 -1
  204. package/src/_types/core/UTXO/utxo-stack/utils/poll.d.ts +0 -13
  205. package/src/_types/core/UTXO/utxo-stack/utils/poll.d.ts.map +0 -1
  206. package/src/core/UTXO/isUTXOAddress.ts +0 -165
  207. package/src/core/UTXO/utxo-stack/actions/getBalance.ts +0 -26
  208. package/src/core/UTXO/utxo-stack/actions/getBlock.ts +0 -58
  209. package/src/core/UTXO/utxo-stack/actions/getBlockCount.ts +0 -20
  210. package/src/core/UTXO/utxo-stack/actions/getBlockStats.ts +0 -55
  211. package/src/core/UTXO/utxo-stack/actions/getUTXOTransaction.ts +0 -43
  212. package/src/core/UTXO/utxo-stack/actions/sendUTXOTransaction.ts +0 -29
  213. package/src/core/UTXO/utxo-stack/actions/signPsbt.ts +0 -23
  214. package/src/core/UTXO/utxo-stack/actions/waitForTransaction.ts +0 -387
  215. package/src/core/UTXO/utxo-stack/actions/watchBlockNumber.ts +0 -105
  216. package/src/core/UTXO/utxo-stack/clients/types.ts +0 -48
  217. package/src/core/UTXO/utxo-stack/decorators/UTXOAPIActions.ts +0 -20
  218. package/src/core/UTXO/utxo-stack/decorators/UTXOActions.ts +0 -37
  219. package/src/core/UTXO/utxo-stack/transports/utxo/ankr.ts +0 -30
  220. package/src/core/UTXO/utxo-stack/transports/utxo/blockchair.ts +0 -27
  221. package/src/core/UTXO/utxo-stack/transports/utxo/blockcypher.ts +0 -32
  222. package/src/core/UTXO/utxo-stack/transports/utxo/getHttpRpcClient.ts +0 -122
  223. package/src/core/UTXO/utxo-stack/transports/utxo/getRpcProviderMethods.ts +0 -22
  224. package/src/core/UTXO/utxo-stack/transports/utxo/mempool.ts +0 -34
  225. package/src/core/UTXO/utxo-stack/transports/utxo/types.ts +0 -71
  226. package/src/core/UTXO/utxo-stack/transports/utxo/utxo.ts +0 -84
  227. package/src/core/UTXO/utxo-stack/types/blockStats.ts +0 -35
  228. package/src/core/UTXO/utxo-stack/types/transaction.ts +0 -43
  229. package/src/core/UTXO/utxo-stack/utils/cancelTransaction.ts +0 -75
  230. package/src/core/UTXO/utxo-stack/utils/modifyFee.ts +0 -78
  231. package/src/core/UTXO/utxo-stack/utils/observe.ts +0 -81
  232. package/src/core/UTXO/utxo-stack/utils/poll.ts +0 -48
@@ -1,122 +0,0 @@
1
- import { HttpRequestError, TimeoutError, stringify, withTimeout } from 'viem'
2
- import type { HttpRequestReturnType, HttpRpcClientOptions } from 'viem/utils'
3
-
4
- export type RpcRequest = {
5
- jsonrpc?: '2.0'
6
- method: string
7
- params?: any
8
- id?: number
9
- }
10
-
11
- export type HttpRequestParameters<
12
- body extends RpcRequest | RpcRequest[] = RpcRequest,
13
- > = {
14
- url?: string
15
- /** The RPC request body. */
16
- body?: body
17
- /** Request configuration to pass to `fetch`. */
18
- fetchOptions?: HttpRpcClientOptions['fetchOptions'] | undefined
19
- /** A callback to handle the response. */
20
- onRequest?: ((request: Request) => Promise<void> | void) | undefined
21
- /** A callback to handle the response. */
22
- onResponse?: ((response: Response) => Promise<void> | void) | undefined
23
- /** The timeout (in ms) for the request. */
24
- timeout?: HttpRpcClientOptions['timeout'] | undefined
25
- }
26
-
27
- export type HttpRpcClient = {
28
- request<body extends RpcRequest | RpcRequest[]>(
29
- params: HttpRequestParameters<body>
30
- ): Promise<HttpRequestReturnType<body>>
31
- }
32
-
33
- export function getHttpRpcClient(
34
- url: string,
35
- options: HttpRpcClientOptions = {}
36
- ): HttpRpcClient {
37
- return {
38
- async request(params) {
39
- const {
40
- body,
41
- onRequest = options.onRequest,
42
- onResponse = options.onResponse,
43
- timeout = options.timeout ?? 10_000,
44
- } = params
45
-
46
- const fetchOptions = {
47
- ...(options.fetchOptions ?? {}),
48
- ...(params.fetchOptions ?? {}),
49
- }
50
-
51
- const { headers, method, signal: signal_ } = fetchOptions
52
-
53
- try {
54
- const response = await withTimeout(
55
- async ({ signal }) => {
56
- const init: RequestInit = {
57
- ...fetchOptions,
58
- body: body ? stringify(body) : undefined,
59
- headers: {
60
- ...(method !== 'GET'
61
- ? { 'Content-Type': 'application/json' }
62
- : undefined),
63
- ...headers,
64
- },
65
- method: method,
66
- signal: signal_ || (timeout > 0 ? signal : null),
67
- }
68
- const request = new Request(params.url ?? url, init)
69
- if (onRequest) {
70
- await onRequest(request)
71
- }
72
- const response = await fetch(params.url ?? url, init)
73
- return response
74
- },
75
- {
76
- errorInstance: new TimeoutError({ body: body ?? {}, url }),
77
- timeout,
78
- signal: true,
79
- }
80
- )
81
-
82
- if (onResponse) {
83
- await onResponse(response)
84
- }
85
-
86
- let data: any
87
- if (
88
- response.headers.get('Content-Type')?.startsWith('application/json')
89
- ) {
90
- data = await response.json()
91
- } else {
92
- data = await response.text()
93
- data = JSON.parse(data || '{}')
94
- }
95
-
96
- if (!response.ok) {
97
- throw new HttpRequestError({
98
- body,
99
- details: stringify(data.error) || response.statusText,
100
- headers: response.headers,
101
- status: response.status,
102
- url,
103
- })
104
- }
105
-
106
- return data
107
- } catch (err) {
108
- if (err instanceof HttpRequestError) {
109
- throw err
110
- }
111
- if (err instanceof TimeoutError) {
112
- throw err
113
- }
114
- throw new HttpRequestError({
115
- body,
116
- cause: err as Error,
117
- url,
118
- })
119
- }
120
- },
121
- }
122
- }
@@ -1,22 +0,0 @@
1
- import { ankrMethods } from './ankr.js'
2
- import { blockchairMethods } from './blockchair.js'
3
- import { blockcypherMethods } from './blockcypher.js'
4
- import { mempoolMethods } from './mempool.js'
5
- import type { RpcMethods } from './types.js'
6
-
7
- export function getRpcProviderMethods(
8
- key: 'blockchair' | 'ankr' | 'blockcypher' | 'mempool' | string
9
- ): RpcMethods | null {
10
- switch (key) {
11
- case 'blockchair':
12
- return blockchairMethods
13
- case 'ankr':
14
- return ankrMethods
15
- case 'blockcypher':
16
- return blockcypherMethods
17
- case 'mempool':
18
- return mempoolMethods
19
- default:
20
- return null
21
- }
22
- }
@@ -1,34 +0,0 @@
1
- import type { RpcMethods } from './types.js'
2
-
3
- type MempoolBalanceResponse = {
4
- address: string
5
- chain_stats: {
6
- funded_txo_count: number
7
- funded_txo_sum: number
8
- spent_txo_count: number
9
- spent_txo_sum: number
10
- tx_count: number
11
- }
12
- mempool_stats: {
13
- funded_txo_count: number
14
- funded_txo_sum: number
15
- spent_txo_count: number
16
- spent_txo_sum: number
17
- tx_count: number
18
- }
19
- }
20
-
21
- export const mempoolMethods: RpcMethods = {
22
- getBalance: async (client, baseUrl, { address }) => {
23
- const apiUrl = `${baseUrl}/address/${address}`
24
- const response = (await client.request({
25
- url: apiUrl,
26
- fetchOptions: { method: 'GET' },
27
- })) as unknown as MempoolBalanceResponse
28
- const balance =
29
- response.chain_stats.funded_txo_sum - response.chain_stats.spent_txo_sum
30
- return {
31
- result: BigInt(balance),
32
- }
33
- },
34
- }
@@ -1,71 +0,0 @@
1
- import type { BlockStats, BlockStatsKeys } from '../../types/blockStats.js'
2
- import type { UTXOTransaction } from '../../types/transaction.js'
3
- import type { HttpRpcClient } from './getHttpRpcClient.js'
4
-
5
- export type UTXOSchema = [
6
- {
7
- Method: 'getblockcount'
8
- Parameters: []
9
- ReturnType: number
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
- },
26
- {
27
- Method: 'sendrawtransaction'
28
- Parameters: [string, number?]
29
- ReturnType: string
30
- },
31
- {
32
- Method: 'getrawtransaction'
33
- Parameters: [string, boolean, string?]
34
- ReturnType: UTXOTransaction
35
- },
36
- ]
37
-
38
- export type UTXOAPISchema = [
39
- {
40
- Method: 'getBalance'
41
- Parameters: { address: string }
42
- ReturnType: bigint
43
- },
44
- ]
45
-
46
- export type UTXOAPIMethod = UTXOAPISchema[number]['Method']
47
-
48
- export type SuccessResult<result> = {
49
- method?: undefined
50
- result: result
51
- error?: undefined
52
- }
53
- export type ErrorResult<error> = {
54
- method?: undefined
55
- result?: undefined
56
- error: error
57
- }
58
-
59
- export type RpcResponse<result = any, error = any> =
60
- | SuccessResult<result>
61
- | ErrorResult<error>
62
-
63
- export type RpcMethodHandler = (
64
- client: HttpRpcClient,
65
- baseUrl: string,
66
- params: any
67
- ) => Promise<RpcResponse>
68
-
69
- export type RpcMethods = {
70
- [key in UTXOAPIMethod]: RpcMethodHandler
71
- }
@@ -1,84 +0,0 @@
1
- import {
2
- type HttpTransport,
3
- type HttpTransportConfig,
4
- RpcRequestError,
5
- UrlRequiredError,
6
- createTransport,
7
- } from 'viem'
8
- import { getHttpRpcClient } from './getHttpRpcClient.js'
9
- import { getRpcProviderMethods } from './getRpcProviderMethods.js'
10
- import type { UTXOAPIMethod } from './types.js'
11
-
12
- type UTXOHttpTransportConfig = HttpTransportConfig & {
13
- includeChainToURL?: boolean
14
- }
15
-
16
- export function utxo(
17
- url?: string,
18
- config: UTXOHttpTransportConfig = {}
19
- ): HttpTransport {
20
- const {
21
- fetchOptions,
22
- key = 'utxo',
23
- name = 'UTXO HTTP API',
24
- onFetchRequest,
25
- onFetchResponse,
26
- retryDelay,
27
- } = config
28
- return ({ chain, retryCount: retryCount_, timeout: timeout_ }) => {
29
- const retryCount = config.retryCount ?? retryCount_
30
- const timeout = timeout_ ?? config.timeout ?? 10_000
31
- let url_ = url
32
- if (config.includeChainToURL) {
33
- const chainName = chain?.name.replace(' ', '-').toLowerCase()
34
- url_ = `${url}${chainName ? `/${chainName}` : ''}`
35
- }
36
- if (!url_) {
37
- throw new UrlRequiredError()
38
- }
39
-
40
- const client = getHttpRpcClient(url_, {
41
- fetchOptions,
42
- onRequest: onFetchRequest,
43
- onResponse: onFetchResponse,
44
- timeout,
45
- })
46
-
47
- const rpcMethods = getRpcProviderMethods(key)
48
-
49
- return createTransport(
50
- {
51
- key,
52
- name,
53
- async request({ method, params }) {
54
- const body = { method, params }
55
- const methodHandler = rpcMethods?.[method as UTXOAPIMethod]
56
- const { error, result } = await (methodHandler?.(
57
- client,
58
- url_,
59
- params
60
- ) ??
61
- client.request({
62
- body,
63
- }))
64
- if (error) {
65
- throw new RpcRequestError({
66
- body,
67
- error,
68
- url: url_,
69
- })
70
- }
71
- return result
72
- },
73
- retryCount,
74
- retryDelay,
75
- timeout,
76
- type: 'http',
77
- },
78
- {
79
- fetchOptions,
80
- url: url_,
81
- }
82
- )
83
- }
84
- }
@@ -1,35 +0,0 @@
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
@@ -1,43 +0,0 @@
1
- export type UTXOTransaction = {
2
- blockhash?: string
3
- blocktime?: number
4
- confirmations?: number
5
- hash: string
6
- hex: string
7
- in_active_chain?: boolean
8
- locktime: number
9
- size: number
10
- time?: number
11
- txid: string
12
- version: number
13
- vsize: number
14
- weight: number
15
- vin: {
16
- scriptSig: {
17
- asm: string
18
- hex: string
19
- }
20
- sequence: number
21
- txid: string
22
- txinwitness: string[]
23
- vout: number
24
- }[]
25
- vout: {
26
- n: 0
27
- scriptPubKey:
28
- | {
29
- address: string
30
- asm: string
31
- desc: string
32
- hex: string
33
- type: string
34
- }
35
- | {
36
- asm: string
37
- desc: string
38
- hex: string
39
- type: string
40
- }
41
- value: number
42
- }[]
43
- }
@@ -1,75 +0,0 @@
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
- }
@@ -1,78 +0,0 @@
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
- }
@@ -1,81 +0,0 @@
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
- }
@@ -1,48 +0,0 @@
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
- }