@across-protocol/sdk 4.1.62 → 4.1.63-beta.0

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 (358) hide show
  1. package/dist/cjs/arch/evm/SpokeUtils.d.ts +1 -1
  2. package/dist/cjs/arch/evm/SpokeUtils.js +6 -5
  3. package/dist/cjs/arch/evm/SpokeUtils.js.map +1 -1
  4. package/dist/cjs/arch/svm/SpokeUtils.d.ts +20 -0
  5. package/dist/cjs/arch/svm/SpokeUtils.js +428 -0
  6. package/dist/cjs/arch/svm/SpokeUtils.js.map +1 -0
  7. package/dist/cjs/arch/svm/constants.d.ts +1 -0
  8. package/dist/cjs/arch/svm/constants.js +5 -0
  9. package/dist/cjs/arch/svm/constants.js.map +1 -0
  10. package/dist/cjs/arch/svm/eventsClient.d.ts +21 -0
  11. package/dist/cjs/{svm → arch/svm}/eventsClient.js +60 -28
  12. package/dist/cjs/arch/svm/eventsClient.js.map +1 -0
  13. package/dist/cjs/arch/svm/index.d.ts +5 -1
  14. package/dist/cjs/arch/svm/index.js +6 -2
  15. package/dist/cjs/arch/svm/index.js.map +1 -1
  16. package/dist/cjs/{svm → arch/svm}/types.d.ts +9 -4
  17. package/dist/cjs/arch/svm/types.js.map +1 -0
  18. package/dist/cjs/arch/svm/utils.d.ts +17 -0
  19. package/dist/cjs/arch/svm/utils.js +204 -0
  20. package/dist/cjs/arch/svm/utils.js.map +1 -0
  21. package/dist/cjs/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.d.ts +1 -1
  22. package/dist/cjs/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js +7 -7
  23. package/dist/cjs/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js.map +1 -1
  24. package/dist/cjs/clients/BaseAbstractClient.d.ts +6 -5
  25. package/dist/cjs/clients/BaseAbstractClient.js +30 -19
  26. package/dist/cjs/clients/BaseAbstractClient.js.map +1 -1
  27. package/dist/cjs/clients/BundleDataClient/BundleDataClient.js +15 -11
  28. package/dist/cjs/clients/BundleDataClient/BundleDataClient.js.map +1 -1
  29. package/dist/cjs/clients/BundleDataClient/utils/PoolRebalanceUtils.js +1 -1
  30. package/dist/cjs/clients/BundleDataClient/utils/PoolRebalanceUtils.js.map +1 -1
  31. package/dist/cjs/clients/BundleDataClient/utils/SuperstructUtils.d.ts +90 -90
  32. package/dist/cjs/clients/HubPoolClient.d.ts +1 -1
  33. package/dist/cjs/clients/HubPoolClient.js +16 -16
  34. package/dist/cjs/clients/HubPoolClient.js.map +1 -1
  35. package/dist/cjs/clients/SpokePoolClient/EVMSpokePoolClient.d.ts +3 -3
  36. package/dist/cjs/clients/SpokePoolClient/EVMSpokePoolClient.js +23 -20
  37. package/dist/cjs/clients/SpokePoolClient/EVMSpokePoolClient.js.map +1 -1
  38. package/dist/cjs/clients/SpokePoolClient/SVMSpokePoolClient.d.ts +23 -0
  39. package/dist/cjs/clients/SpokePoolClient/SVMSpokePoolClient.js +145 -0
  40. package/dist/cjs/clients/SpokePoolClient/SVMSpokePoolClient.js.map +1 -0
  41. package/dist/cjs/clients/SpokePoolClient/SpokePoolClient.d.ts +5 -5
  42. package/dist/cjs/clients/SpokePoolClient/SpokePoolClient.js +50 -54
  43. package/dist/cjs/clients/SpokePoolClient/SpokePoolClient.js.map +1 -1
  44. package/dist/cjs/clients/SpokePoolClient/index.d.ts +3 -0
  45. package/dist/cjs/clients/SpokePoolClient/index.js +8 -1
  46. package/dist/cjs/clients/SpokePoolClient/index.js.map +1 -1
  47. package/dist/cjs/clients/index.d.ts +1 -1
  48. package/dist/cjs/clients/index.js +2 -1
  49. package/dist/cjs/clients/index.js.map +1 -1
  50. package/dist/cjs/clients/mocks/MockConfigStoreClient.d.ts +1 -1
  51. package/dist/cjs/clients/mocks/MockConfigStoreClient.js +2 -2
  52. package/dist/cjs/clients/mocks/MockConfigStoreClient.js.map +1 -1
  53. package/dist/cjs/clients/mocks/MockHubPoolClient.js +2 -2
  54. package/dist/cjs/clients/mocks/MockHubPoolClient.js.map +1 -1
  55. package/dist/cjs/clients/mocks/MockSpokePoolClient.js +7 -4
  56. package/dist/cjs/clients/mocks/MockSpokePoolClient.js.map +1 -1
  57. package/dist/cjs/gasPriceOracle/adapters/arbitrum.d.ts +2 -2
  58. package/dist/cjs/gasPriceOracle/adapters/arbitrum.js.map +1 -1
  59. package/dist/cjs/gasPriceOracle/adapters/ethereum.d.ts +4 -4
  60. package/dist/cjs/gasPriceOracle/adapters/ethereum.js.map +1 -1
  61. package/dist/cjs/gasPriceOracle/adapters/linea-viem.js +3 -2
  62. package/dist/cjs/gasPriceOracle/adapters/linea-viem.js.map +1 -1
  63. package/dist/cjs/gasPriceOracle/adapters/polygon.d.ts +3 -3
  64. package/dist/cjs/gasPriceOracle/adapters/solana.d.ts +4 -0
  65. package/dist/cjs/gasPriceOracle/adapters/solana.js +43 -0
  66. package/dist/cjs/gasPriceOracle/adapters/solana.js.map +1 -0
  67. package/dist/cjs/gasPriceOracle/index.d.ts +1 -1
  68. package/dist/cjs/gasPriceOracle/oracle.d.ts +4 -3
  69. package/dist/cjs/gasPriceOracle/oracle.js +16 -9
  70. package/dist/cjs/gasPriceOracle/oracle.js.map +1 -1
  71. package/dist/cjs/gasPriceOracle/types.d.ts +6 -1
  72. package/dist/cjs/index.d.ts +0 -1
  73. package/dist/cjs/index.js +1 -2
  74. package/dist/cjs/index.js.map +1 -1
  75. package/dist/cjs/interfaces/SpokePool.d.ts +7 -0
  76. package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.d.ts +1 -1
  77. package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.js +5 -4
  78. package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.js.map +1 -1
  79. package/dist/cjs/relayFeeCalculator/chain-queries/factory.d.ts +4 -2
  80. package/dist/cjs/relayFeeCalculator/chain-queries/factory.js +7 -1
  81. package/dist/cjs/relayFeeCalculator/chain-queries/factory.js.map +1 -1
  82. package/dist/cjs/relayFeeCalculator/chain-queries/index.d.ts +1 -0
  83. package/dist/cjs/relayFeeCalculator/chain-queries/index.js +1 -0
  84. package/dist/cjs/relayFeeCalculator/chain-queries/index.js.map +1 -1
  85. package/dist/cjs/relayFeeCalculator/chain-queries/svmQuery.d.ts +31 -0
  86. package/dist/cjs/relayFeeCalculator/chain-queries/svmQuery.js +136 -0
  87. package/dist/cjs/relayFeeCalculator/chain-queries/svmQuery.js.map +1 -0
  88. package/dist/cjs/utils/AddressUtils.d.ts +9 -3
  89. package/dist/cjs/utils/AddressUtils.js +36 -6
  90. package/dist/cjs/utils/AddressUtils.js.map +1 -1
  91. package/dist/cjs/utils/ArrayUtils.d.ts +1 -0
  92. package/dist/cjs/utils/ArrayUtils.js +6 -1
  93. package/dist/cjs/utils/ArrayUtils.js.map +1 -1
  94. package/dist/cjs/utils/EventUtils.d.ts +4 -4
  95. package/dist/cjs/utils/EventUtils.js +7 -4
  96. package/dist/cjs/utils/EventUtils.js.map +1 -1
  97. package/dist/cjs/utils/JSONUtils.js +3 -0
  98. package/dist/cjs/utils/JSONUtils.js.map +1 -1
  99. package/dist/cjs/utils/SpokeUtils.js +5 -0
  100. package/dist/cjs/utils/SpokeUtils.js.map +1 -1
  101. package/dist/esm/arch/evm/SpokeUtils.d.ts +1 -1
  102. package/dist/esm/arch/evm/SpokeUtils.js +6 -5
  103. package/dist/esm/arch/evm/SpokeUtils.js.map +1 -1
  104. package/dist/esm/arch/svm/SpokeUtils.d.ts +94 -0
  105. package/dist/esm/arch/svm/SpokeUtils.js +513 -0
  106. package/dist/esm/arch/svm/SpokeUtils.js.map +1 -0
  107. package/dist/esm/arch/svm/constants.d.ts +1 -0
  108. package/dist/esm/arch/svm/constants.js +2 -0
  109. package/dist/esm/arch/svm/constants.js.map +1 -0
  110. package/dist/esm/arch/svm/eventsClient.d.ts +67 -0
  111. package/dist/esm/{svm → arch/svm}/eventsClient.js +69 -27
  112. package/dist/esm/arch/svm/eventsClient.js.map +1 -0
  113. package/dist/esm/arch/svm/index.d.ts +5 -1
  114. package/dist/esm/arch/svm/index.js +5 -1
  115. package/dist/esm/arch/svm/index.js.map +1 -1
  116. package/dist/{types → esm/arch}/svm/types.d.ts +9 -5
  117. package/dist/esm/arch/svm/types.js.map +1 -0
  118. package/dist/esm/arch/svm/utils.d.ts +59 -0
  119. package/dist/esm/arch/svm/utils.js +248 -0
  120. package/dist/esm/arch/svm/utils.js.map +1 -0
  121. package/dist/esm/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.d.ts +1 -1
  122. package/dist/esm/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js +7 -7
  123. package/dist/esm/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js.map +1 -1
  124. package/dist/esm/clients/BaseAbstractClient.d.ts +6 -5
  125. package/dist/esm/clients/BaseAbstractClient.js +30 -19
  126. package/dist/esm/clients/BaseAbstractClient.js.map +1 -1
  127. package/dist/esm/clients/BundleDataClient/BundleDataClient.js +17 -14
  128. package/dist/esm/clients/BundleDataClient/BundleDataClient.js.map +1 -1
  129. package/dist/esm/clients/BundleDataClient/utils/PoolRebalanceUtils.js +1 -1
  130. package/dist/esm/clients/BundleDataClient/utils/PoolRebalanceUtils.js.map +1 -1
  131. package/dist/esm/clients/BundleDataClient/utils/SuperstructUtils.d.ts +90 -90
  132. package/dist/esm/clients/HubPoolClient.d.ts +1 -1
  133. package/dist/esm/clients/HubPoolClient.js +16 -16
  134. package/dist/esm/clients/HubPoolClient.js.map +1 -1
  135. package/dist/esm/clients/SpokePoolClient/EVMSpokePoolClient.d.ts +3 -3
  136. package/dist/esm/clients/SpokePoolClient/EVMSpokePoolClient.js +23 -20
  137. package/dist/esm/clients/SpokePoolClient/EVMSpokePoolClient.js.map +1 -1
  138. package/dist/esm/clients/SpokePoolClient/SVMSpokePoolClient.d.ts +67 -0
  139. package/dist/esm/clients/SpokePoolClient/SVMSpokePoolClient.js +196 -0
  140. package/dist/esm/clients/SpokePoolClient/SVMSpokePoolClient.js.map +1 -0
  141. package/dist/esm/clients/SpokePoolClient/SpokePoolClient.d.ts +7 -7
  142. package/dist/esm/clients/SpokePoolClient/SpokePoolClient.js +51 -55
  143. package/dist/esm/clients/SpokePoolClient/SpokePoolClient.js.map +1 -1
  144. package/dist/esm/clients/SpokePoolClient/index.d.ts +8 -0
  145. package/dist/esm/clients/SpokePoolClient/index.js +10 -0
  146. package/dist/esm/clients/SpokePoolClient/index.js.map +1 -1
  147. package/dist/esm/clients/index.d.ts +1 -1
  148. package/dist/esm/clients/index.js +1 -1
  149. package/dist/esm/clients/index.js.map +1 -1
  150. package/dist/esm/clients/mocks/MockConfigStoreClient.d.ts +1 -1
  151. package/dist/esm/clients/mocks/MockConfigStoreClient.js +2 -2
  152. package/dist/esm/clients/mocks/MockConfigStoreClient.js.map +1 -1
  153. package/dist/esm/clients/mocks/MockHubPoolClient.js +2 -2
  154. package/dist/esm/clients/mocks/MockHubPoolClient.js.map +1 -1
  155. package/dist/esm/clients/mocks/MockSpokePoolClient.js +8 -5
  156. package/dist/esm/clients/mocks/MockSpokePoolClient.js.map +1 -1
  157. package/dist/esm/gasPriceOracle/adapters/arbitrum.d.ts +2 -2
  158. package/dist/esm/gasPriceOracle/adapters/arbitrum.js.map +1 -1
  159. package/dist/esm/gasPriceOracle/adapters/ethereum.d.ts +4 -4
  160. package/dist/esm/gasPriceOracle/adapters/ethereum.js.map +1 -1
  161. package/dist/esm/gasPriceOracle/adapters/linea-viem.js +3 -2
  162. package/dist/esm/gasPriceOracle/adapters/linea-viem.js.map +1 -1
  163. package/dist/esm/gasPriceOracle/adapters/polygon.d.ts +4 -4
  164. package/dist/esm/gasPriceOracle/adapters/polygon.js +1 -1
  165. package/dist/esm/gasPriceOracle/adapters/solana.d.ts +8 -0
  166. package/dist/esm/gasPriceOracle/adapters/solana.js +43 -0
  167. package/dist/esm/gasPriceOracle/adapters/solana.js.map +1 -0
  168. package/dist/esm/gasPriceOracle/index.d.ts +1 -1
  169. package/dist/esm/gasPriceOracle/oracle.d.ts +4 -3
  170. package/dist/esm/gasPriceOracle/oracle.js +18 -9
  171. package/dist/esm/gasPriceOracle/oracle.js.map +1 -1
  172. package/dist/esm/gasPriceOracle/types.d.ts +6 -1
  173. package/dist/esm/index.d.ts +0 -1
  174. package/dist/esm/index.js +0 -2
  175. package/dist/esm/index.js.map +1 -1
  176. package/dist/esm/interfaces/SpokePool.d.ts +7 -0
  177. package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.d.ts +1 -1
  178. package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.js +4 -3
  179. package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.js.map +1 -1
  180. package/dist/esm/relayFeeCalculator/chain-queries/factory.d.ts +4 -2
  181. package/dist/esm/relayFeeCalculator/chain-queries/factory.js +8 -2
  182. package/dist/esm/relayFeeCalculator/chain-queries/factory.js.map +1 -1
  183. package/dist/esm/relayFeeCalculator/chain-queries/index.d.ts +1 -0
  184. package/dist/esm/relayFeeCalculator/chain-queries/index.js +1 -0
  185. package/dist/esm/relayFeeCalculator/chain-queries/index.js.map +1 -1
  186. package/dist/esm/relayFeeCalculator/chain-queries/svmQuery.d.ts +66 -0
  187. package/dist/esm/relayFeeCalculator/chain-queries/svmQuery.js +169 -0
  188. package/dist/esm/relayFeeCalculator/chain-queries/svmQuery.js.map +1 -0
  189. package/dist/esm/utils/AddressUtils.d.ts +9 -3
  190. package/dist/esm/utils/AddressUtils.js +41 -6
  191. package/dist/esm/utils/AddressUtils.js.map +1 -1
  192. package/dist/esm/utils/ArrayUtils.d.ts +6 -0
  193. package/dist/esm/utils/ArrayUtils.js +9 -0
  194. package/dist/esm/utils/ArrayUtils.js.map +1 -1
  195. package/dist/esm/utils/EventUtils.d.ts +4 -4
  196. package/dist/esm/utils/EventUtils.js +7 -4
  197. package/dist/esm/utils/EventUtils.js.map +1 -1
  198. package/dist/esm/utils/JSONUtils.js +3 -0
  199. package/dist/esm/utils/JSONUtils.js.map +1 -1
  200. package/dist/esm/utils/SpokeUtils.js +5 -0
  201. package/dist/esm/utils/SpokeUtils.js.map +1 -1
  202. package/dist/types/arch/evm/SpokeUtils.d.ts +1 -1
  203. package/dist/types/arch/evm/SpokeUtils.d.ts.map +1 -1
  204. package/dist/types/arch/svm/SpokeUtils.d.ts +95 -0
  205. package/dist/types/arch/svm/SpokeUtils.d.ts.map +1 -0
  206. package/dist/types/arch/svm/constants.d.ts +2 -0
  207. package/dist/types/arch/svm/constants.d.ts.map +1 -0
  208. package/dist/types/arch/svm/eventsClient.d.ts +68 -0
  209. package/dist/types/arch/svm/eventsClient.d.ts.map +1 -0
  210. package/dist/types/arch/svm/index.d.ts +5 -1
  211. package/dist/types/arch/svm/index.d.ts.map +1 -1
  212. package/dist/{esm → types/arch}/svm/types.d.ts +10 -4
  213. package/dist/types/arch/svm/types.d.ts.map +1 -0
  214. package/dist/types/arch/svm/utils.d.ts +60 -0
  215. package/dist/types/arch/svm/utils.d.ts.map +1 -0
  216. package/dist/types/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.d.ts +1 -1
  217. package/dist/types/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.d.ts.map +1 -1
  218. package/dist/types/clients/BaseAbstractClient.d.ts +6 -5
  219. package/dist/types/clients/BaseAbstractClient.d.ts.map +1 -1
  220. package/dist/types/clients/BundleDataClient/BundleDataClient.d.ts.map +1 -1
  221. package/dist/types/clients/BundleDataClient/utils/SuperstructUtils.d.ts +90 -90
  222. package/dist/types/clients/HubPoolClient.d.ts +1 -1
  223. package/dist/types/clients/HubPoolClient.d.ts.map +1 -1
  224. package/dist/types/clients/SpokePoolClient/EVMSpokePoolClient.d.ts +3 -3
  225. package/dist/types/clients/SpokePoolClient/EVMSpokePoolClient.d.ts.map +1 -1
  226. package/dist/types/clients/SpokePoolClient/SVMSpokePoolClient.d.ts +68 -0
  227. package/dist/types/clients/SpokePoolClient/SVMSpokePoolClient.d.ts.map +1 -0
  228. package/dist/types/clients/SpokePoolClient/SpokePoolClient.d.ts +7 -7
  229. package/dist/types/clients/SpokePoolClient/SpokePoolClient.d.ts.map +1 -1
  230. package/dist/types/clients/SpokePoolClient/index.d.ts +8 -0
  231. package/dist/types/clients/SpokePoolClient/index.d.ts.map +1 -1
  232. package/dist/types/clients/index.d.ts +1 -1
  233. package/dist/types/clients/index.d.ts.map +1 -1
  234. package/dist/types/clients/mocks/MockConfigStoreClient.d.ts +1 -1
  235. package/dist/types/clients/mocks/MockConfigStoreClient.d.ts.map +1 -1
  236. package/dist/types/clients/mocks/MockSpokePoolClient.d.ts.map +1 -1
  237. package/dist/types/gasPriceOracle/adapters/arbitrum.d.ts +2 -2
  238. package/dist/types/gasPriceOracle/adapters/arbitrum.d.ts.map +1 -1
  239. package/dist/types/gasPriceOracle/adapters/ethereum.d.ts +4 -4
  240. package/dist/types/gasPriceOracle/adapters/ethereum.d.ts.map +1 -1
  241. package/dist/types/gasPriceOracle/adapters/linea-viem.d.ts.map +1 -1
  242. package/dist/types/gasPriceOracle/adapters/polygon.d.ts +4 -4
  243. package/dist/types/gasPriceOracle/adapters/polygon.d.ts.map +1 -1
  244. package/dist/types/gasPriceOracle/adapters/solana.d.ts +9 -0
  245. package/dist/types/gasPriceOracle/adapters/solana.d.ts.map +1 -0
  246. package/dist/types/gasPriceOracle/index.d.ts +1 -1
  247. package/dist/types/gasPriceOracle/index.d.ts.map +1 -1
  248. package/dist/types/gasPriceOracle/oracle.d.ts +4 -3
  249. package/dist/types/gasPriceOracle/oracle.d.ts.map +1 -1
  250. package/dist/types/gasPriceOracle/types.d.ts +6 -1
  251. package/dist/types/gasPriceOracle/types.d.ts.map +1 -1
  252. package/dist/types/index.d.ts +0 -1
  253. package/dist/types/index.d.ts.map +1 -1
  254. package/dist/types/interfaces/SpokePool.d.ts +7 -0
  255. package/dist/types/interfaces/SpokePool.d.ts.map +1 -1
  256. package/dist/types/relayFeeCalculator/chain-queries/baseQuery.d.ts +1 -1
  257. package/dist/types/relayFeeCalculator/chain-queries/baseQuery.d.ts.map +1 -1
  258. package/dist/types/relayFeeCalculator/chain-queries/factory.d.ts +4 -2
  259. package/dist/types/relayFeeCalculator/chain-queries/factory.d.ts.map +1 -1
  260. package/dist/types/relayFeeCalculator/chain-queries/index.d.ts +1 -0
  261. package/dist/types/relayFeeCalculator/chain-queries/index.d.ts.map +1 -1
  262. package/dist/types/relayFeeCalculator/chain-queries/svmQuery.d.ts +67 -0
  263. package/dist/types/relayFeeCalculator/chain-queries/svmQuery.d.ts.map +1 -0
  264. package/dist/types/utils/AddressUtils.d.ts +9 -3
  265. package/dist/types/utils/AddressUtils.d.ts.map +1 -1
  266. package/dist/types/utils/ArrayUtils.d.ts +6 -0
  267. package/dist/types/utils/ArrayUtils.d.ts.map +1 -1
  268. package/dist/types/utils/EventUtils.d.ts +4 -4
  269. package/dist/types/utils/EventUtils.d.ts.map +1 -1
  270. package/dist/types/utils/JSONUtils.d.ts.map +1 -1
  271. package/dist/types/utils/SpokeUtils.d.ts.map +1 -1
  272. package/package.json +4 -1
  273. package/src/arch/evm/SpokeUtils.ts +5 -5
  274. package/src/arch/svm/SpokeUtils.ts +526 -0
  275. package/src/arch/svm/constants.ts +1 -0
  276. package/src/{svm → arch/svm}/eventsClient.ts +67 -45
  277. package/src/arch/svm/index.ts +5 -1
  278. package/src/{svm → arch/svm}/types.ts +21 -4
  279. package/src/arch/svm/utils.ts +222 -0
  280. package/src/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.ts +7 -7
  281. package/src/clients/BaseAbstractClient.ts +20 -13
  282. package/src/clients/BundleDataClient/BundleDataClient.ts +28 -19
  283. package/src/clients/BundleDataClient/utils/PoolRebalanceUtils.ts +1 -1
  284. package/src/clients/HubPoolClient.ts +16 -16
  285. package/src/clients/SpokePoolClient/EVMSpokePoolClient.ts +23 -21
  286. package/src/clients/SpokePoolClient/SVMSpokePoolClient.ts +244 -0
  287. package/src/clients/SpokePoolClient/SpokePoolClient.ts +44 -56
  288. package/src/clients/SpokePoolClient/index.ts +11 -0
  289. package/src/clients/index.ts +1 -1
  290. package/src/clients/mocks/MockConfigStoreClient.ts +2 -2
  291. package/src/clients/mocks/MockHubPoolClient.ts +2 -2
  292. package/src/clients/mocks/MockSpokePoolClient.ts +9 -4
  293. package/src/gasPriceOracle/adapters/arbitrum.ts +5 -2
  294. package/src/gasPriceOracle/adapters/ethereum.ts +7 -4
  295. package/src/gasPriceOracle/adapters/linea-viem.ts +3 -1
  296. package/src/gasPriceOracle/adapters/polygon.ts +6 -6
  297. package/src/gasPriceOracle/adapters/solana.ts +45 -0
  298. package/src/gasPriceOracle/index.ts +1 -1
  299. package/src/gasPriceOracle/oracle.ts +20 -4
  300. package/src/gasPriceOracle/types.ts +7 -1
  301. package/src/index.ts +0 -1
  302. package/src/interfaces/SpokePool.ts +7 -0
  303. package/src/relayFeeCalculator/chain-queries/baseQuery.ts +5 -3
  304. package/src/relayFeeCalculator/chain-queries/factory.ts +21 -5
  305. package/src/relayFeeCalculator/chain-queries/index.ts +1 -0
  306. package/src/relayFeeCalculator/chain-queries/svmQuery.ts +193 -0
  307. package/src/utils/AddressUtils.ts +49 -6
  308. package/src/utils/ArrayUtils.ts +12 -0
  309. package/src/utils/EventUtils.ts +11 -11
  310. package/src/utils/JSONUtils.ts +2 -0
  311. package/src/utils/SpokeUtils.ts +5 -1
  312. package/dist/cjs/svm/eventsClient.d.ts +0 -15
  313. package/dist/cjs/svm/eventsClient.js.map +0 -1
  314. package/dist/cjs/svm/index.d.ts +0 -3
  315. package/dist/cjs/svm/index.js +0 -8
  316. package/dist/cjs/svm/index.js.map +0 -1
  317. package/dist/cjs/svm/types.js.map +0 -1
  318. package/dist/cjs/svm/utils/events.d.ts +0 -8
  319. package/dist/cjs/svm/utils/events.js +0 -47
  320. package/dist/cjs/svm/utils/events.js.map +0 -1
  321. package/dist/cjs/svm/utils/helpers.d.ts +0 -2
  322. package/dist/cjs/svm/utils/helpers.js +0 -19
  323. package/dist/cjs/svm/utils/helpers.js.map +0 -1
  324. package/dist/cjs/svm/utils/index.d.ts +0 -1
  325. package/dist/cjs/svm/utils/index.js +0 -5
  326. package/dist/cjs/svm/utils/index.js.map +0 -1
  327. package/dist/esm/svm/eventsClient.d.ts +0 -51
  328. package/dist/esm/svm/eventsClient.js.map +0 -1
  329. package/dist/esm/svm/index.d.ts +0 -3
  330. package/dist/esm/svm/index.js +0 -5
  331. package/dist/esm/svm/index.js.map +0 -1
  332. package/dist/esm/svm/types.js.map +0 -1
  333. package/dist/esm/svm/utils/events.d.ts +0 -17
  334. package/dist/esm/svm/utils/events.js +0 -55
  335. package/dist/esm/svm/utils/events.js.map +0 -1
  336. package/dist/esm/svm/utils/helpers.d.ts +0 -5
  337. package/dist/esm/svm/utils/helpers.js +0 -18
  338. package/dist/esm/svm/utils/helpers.js.map +0 -1
  339. package/dist/esm/svm/utils/index.d.ts +0 -1
  340. package/dist/esm/svm/utils/index.js +0 -2
  341. package/dist/esm/svm/utils/index.js.map +0 -1
  342. package/dist/types/svm/eventsClient.d.ts +0 -52
  343. package/dist/types/svm/eventsClient.d.ts.map +0 -1
  344. package/dist/types/svm/index.d.ts +0 -4
  345. package/dist/types/svm/index.d.ts.map +0 -1
  346. package/dist/types/svm/types.d.ts.map +0 -1
  347. package/dist/types/svm/utils/events.d.ts +0 -18
  348. package/dist/types/svm/utils/events.d.ts.map +0 -1
  349. package/dist/types/svm/utils/helpers.d.ts +0 -6
  350. package/dist/types/svm/utils/helpers.d.ts.map +0 -1
  351. package/dist/types/svm/utils/index.d.ts +0 -2
  352. package/dist/types/svm/utils/index.d.ts.map +0 -1
  353. package/src/svm/index.ts +0 -3
  354. package/src/svm/utils/events.ts +0 -58
  355. package/src/svm/utils/helpers.ts +0 -9
  356. package/src/svm/utils/index.ts +0 -1
  357. /package/dist/cjs/{svm → arch/svm}/types.js +0 -0
  358. /package/dist/esm/{svm → arch/svm}/types.js +0 -0
@@ -160,7 +160,7 @@ export async function findDepositBlock(
160
160
  export async function relayFillStatus(
161
161
  spokePool: Contract,
162
162
  relayData: RelayData,
163
- blockTag?: number | "latest",
163
+ blockTag: BlockTag = "latest",
164
164
  destinationChainId?: number
165
165
  ): Promise<FillStatus> {
166
166
  destinationChainId ??= await spokePool.chainId();
@@ -290,20 +290,20 @@ export async function findFillEvent(
290
290
  if (!blockNumber) return undefined;
291
291
 
292
292
  // We can hardcode this to 0 to instruct paginatedEventQuery to make a single request for the same block number.
293
- const maxBlockLookBack = 0;
294
- const [fromBlock, toBlock] = [blockNumber, blockNumber];
293
+ const maxLookBack = 0;
294
+ const [from, to] = [blockNumber, blockNumber];
295
295
 
296
296
  const query = (
297
297
  await Promise.all([
298
298
  paginatedEventQuery(
299
299
  spokePool,
300
300
  spokePool.filters.FilledRelay(null, null, null, null, null, relayData.originChainId, relayData.depositId),
301
- { fromBlock, toBlock, maxBlockLookBack }
301
+ { from, to, maxLookBack }
302
302
  ),
303
303
  paginatedEventQuery(
304
304
  spokePool,
305
305
  spokePool.filters.FilledV3Relay(null, null, null, null, null, relayData.originChainId, relayData.depositId),
306
- { fromBlock, toBlock, maxBlockLookBack }
306
+ { from, to, maxLookBack }
307
307
  ),
308
308
  ])
309
309
  ).flat();
@@ -0,0 +1,526 @@
1
+ import {
2
+ SvmAddress,
3
+ getTokenInfo,
4
+ BigNumber,
5
+ isDefined,
6
+ isUnsafeDepositId,
7
+ toAddressType,
8
+ toBN,
9
+ getMessageHash,
10
+ keccak256,
11
+ chainIsSvm,
12
+ chunk,
13
+ } from "../../utils";
14
+ import { SvmSpokeClient } from "@across-protocol/contracts";
15
+ import { getStatePda, SvmCpiEventsClient, getFillStatusPda, unwrapEventData, getEventAuthority } from "./";
16
+ import { Deposit, FillStatus, FillWithBlock, RelayData } from "../../interfaces";
17
+ import {
18
+ TOKEN_PROGRAM_ADDRESS,
19
+ ASSOCIATED_TOKEN_PROGRAM_ADDRESS,
20
+ getApproveCheckedInstruction,
21
+ } from "@solana-program/token";
22
+ import {
23
+ Address,
24
+ some,
25
+ address,
26
+ getProgramDerivedAddress,
27
+ fetchEncodedAccounts,
28
+ fetchEncodedAccount,
29
+ type TransactionSigner,
30
+ } from "@solana/kit";
31
+ import assert from "assert";
32
+ import { Logger } from "winston";
33
+ import { fetchState, decodeFillStatusAccount } from "@across-protocol/contracts/dist/src/svm/clients/SvmSpoke";
34
+ import { SVMEventNames, SVMProvider } from "./types";
35
+ import { CHAIN_IDs } from "../../constants";
36
+
37
+ /**
38
+ * @param spokePool SpokePool Contract instance.
39
+ * @param deposit V3Deopsit instance.
40
+ * @param repaymentChainId Optional repaymentChainId (defaults to destinationChainId).
41
+ * @returns An Ethers UnsignedTransaction instance.
42
+ */
43
+ export function populateV3Relay(
44
+ _spokePool: unknown,
45
+ _deposit: Omit<Deposit, "messageHash">,
46
+ _relayer: string,
47
+ _repaymentChainId = _deposit.destinationChainId
48
+ ): Promise<unknown> {
49
+ throw new Error("populateV3Relay: not implemented");
50
+ }
51
+
52
+ /**
53
+ * Retrieves the chain time at a particular slot.
54
+ */
55
+ export async function getTimestampForSlot(provider: SVMProvider, slotNumber: number): Promise<number> {
56
+ // @note: getBlockTime receives a slot number, not a block number.
57
+ const slotTime = await provider.getBlockTime(BigInt(slotNumber)).send();
58
+ return Number(slotTime);
59
+ }
60
+
61
+ /**
62
+ * Returns the current fill deadline buffer.
63
+ * @param provider SVM Provider instance
64
+ * @param statePda Spoke Pool's State PDA
65
+ * @returns fill deadline buffer
66
+ */
67
+ export async function getFillDeadline(provider: SVMProvider, statePda: Address): Promise<number> {
68
+ const state = await fetchState(provider, statePda);
69
+ return state.data.fillDeadlineBuffer;
70
+ }
71
+
72
+ /**
73
+ * Finds the deposit id at a specific block number.
74
+ * @param blockTag The block number to search for the deposit ID at.
75
+ * @returns The deposit ID.
76
+ */
77
+ export function getDepositIdAtBlock(_contract: unknown, _blockTag: number): Promise<BigNumber> {
78
+ throw new Error("getDepositIdAtBlock: not implemented");
79
+ }
80
+
81
+ export function findDepositBlock(
82
+ _spokePool: unknown,
83
+ depositId: BigNumber,
84
+ _lowBlock: number,
85
+ _highBlock?: number
86
+ ): Promise<number | undefined> {
87
+ // We can only perform this search when we have a safe deposit ID.
88
+ if (isUnsafeDepositId(depositId)) {
89
+ throw new Error(`Cannot binary search for depositId ${depositId}`);
90
+ }
91
+ throw new Error("findDepositBlock: not implemented");
92
+ }
93
+
94
+ /**
95
+ * Resolves the fill status of a deposit at a specific slot or at the current confirmed one.
96
+ *
97
+ * If no slot is provided, attempts to solve the fill status using the PDA. Otherwise, it is reconstructed from PDA events.
98
+ *
99
+ * @param programId - The spoke pool program ID.
100
+ * @param relayData - Deposit information used to locate the fill status.
101
+ * @param destinationChainId - Destination chain ID (must be an SVM chain).
102
+ * @param provider - SVM provider instance.
103
+ * @param svmEventsClient - SVM events client for querying events.
104
+ * @param atHeight - (Optional) Specific slot number to query. Defaults to the latest confirmed slot.
105
+ * @returns The fill status for the deposit at the specified or current slot.
106
+ */
107
+ export async function relayFillStatus(
108
+ programId: Address,
109
+ relayData: RelayData,
110
+ destinationChainId: number,
111
+ svmEventsClient: SvmCpiEventsClient,
112
+ atHeight?: number
113
+ ): Promise<FillStatus> {
114
+ assert(chainIsSvm(destinationChainId), "Destination chain must be an SVM chain");
115
+ const provider = svmEventsClient.getRpc();
116
+ // Get fill status PDA using relayData
117
+ const fillStatusPda = await getFillStatusPda(programId, relayData, destinationChainId);
118
+ const currentSlot = await provider.getSlot({ commitment: "confirmed" }).send();
119
+
120
+ // If no specific slot is requested, try fetching the current status from the PDA
121
+ if (atHeight === undefined) {
122
+ const [fillStatusAccount, currentSlotTimestamp] = await Promise.all([
123
+ fetchEncodedAccount(provider, fillStatusPda, { commitment: "confirmed" }),
124
+ provider.getBlockTime(currentSlot).send(),
125
+ ]);
126
+ // If the PDA exists, return the stored fill status
127
+ if (fillStatusAccount.exists) {
128
+ const decodedAccountData = decodeFillStatusAccount(fillStatusAccount);
129
+ return decodedAccountData.data.status;
130
+ }
131
+ // If the PDA doesn't exist and the deadline hasn't passed yet, the deposit must be unfilled,
132
+ // since PDAs can't be closed before the fill deadline.
133
+ else if (Number(currentSlotTimestamp) < relayData.fillDeadline) {
134
+ return FillStatus.Unfilled;
135
+ }
136
+ }
137
+
138
+ // If status couldn't be determined from the PDA, or if a specific slot was requested, reconstruct the status from events
139
+ const toSlot = atHeight ? BigInt(atHeight) : currentSlot;
140
+
141
+ return resolveFillStatusFromPdaEvents(fillStatusPda, toSlot, svmEventsClient);
142
+ }
143
+
144
+ /**
145
+ * Resolves fill statuses for multiple deposits at a specific or latest confirmed slot,
146
+ * using PDAs when possible and falling back to events if needed.
147
+ *
148
+ * @param programId The spoke pool program ID.
149
+ * @param relayData An array of relay data to resolve fill statuses for.
150
+ * @param destinationChainId The destination chain ID (must be an SVM chain).
151
+ * @param provider SVM Provider instance.
152
+ * @param svmEventsClient SVM events client instance for querying events.
153
+ * @param atHeight (Optional) The slot number to query at. If omitted, queries the latest confirmed slot.
154
+ * @returns An array of fill statuses for the specified deposits at the requested slot (or at the current confirmed slot).
155
+ */
156
+ export async function fillStatusArray(
157
+ programId: Address,
158
+ relayData: RelayData[],
159
+ destinationChainId: number,
160
+ svmEventsClient: SvmCpiEventsClient,
161
+ atHeight?: number,
162
+ logger?: Logger
163
+ ): Promise<(FillStatus | undefined)[]> {
164
+ assert(chainIsSvm(destinationChainId), "Destination chain must be an SVM chain");
165
+ const provider = svmEventsClient.getRpc();
166
+ const chunkSize = 100;
167
+ const chunkedRelayData = chunk(relayData, chunkSize);
168
+
169
+ // Get all PDAs
170
+ const fillStatusPdas = (
171
+ await Promise.all(
172
+ chunkedRelayData.map((relayDataChunk) =>
173
+ Promise.all(relayDataChunk.map((relayData) => getFillStatusPda(programId, relayData, destinationChainId)))
174
+ )
175
+ )
176
+ ).flat();
177
+
178
+ if (atHeight !== undefined && logger) {
179
+ logger.warn({
180
+ at: "SvmSpokeUtils#fillStatusArray",
181
+ message:
182
+ "Querying specific slots for large arrays is slow. For current status, omit 'atHeight' param to use latest confirmed slot instead.",
183
+ });
184
+ }
185
+
186
+ // If no specific slot is requested, try fetching current statuses from PDAs
187
+ // Otherwise, initialize all statuses as undefined
188
+ const fillStatuses: (FillStatus | undefined)[] =
189
+ atHeight === undefined
190
+ ? await fetchBatchFillStatusFromPdaAccounts(provider, fillStatusPdas, relayData)
191
+ : new Array(relayData.length).fill(undefined);
192
+
193
+ // Collect indices of deposits that still need their status resolved
194
+ const missingStatuses = fillStatuses.reduce<number[]>((acc, status, index) => {
195
+ if (status === undefined) {
196
+ acc.push(index);
197
+ }
198
+ return acc;
199
+ }, []);
200
+
201
+ // Chunk the missing deposits for batch processing
202
+ const missingChunked = chunk(missingStatuses, chunkSize);
203
+ const missingResults: { index: number; fillStatus: FillStatus }[] = [];
204
+
205
+ // Determine the toSlot to use for event reconstruction
206
+ const toSlot = atHeight ? BigInt(atHeight) : await provider.getSlot({ commitment: "confirmed" }).send();
207
+
208
+ // @note: This path is mostly used for deposits past their fill deadline.
209
+ // If it becomes a bottleneck, consider returning an "Unknown" status that can be handled downstream.
210
+ for (const chunk of missingChunked) {
211
+ const chunkResults = await Promise.all(
212
+ chunk.map(async (missingIndex) => {
213
+ return {
214
+ index: missingIndex,
215
+ fillStatus: await resolveFillStatusFromPdaEvents(fillStatusPdas[missingIndex], toSlot, svmEventsClient),
216
+ };
217
+ })
218
+ );
219
+ missingResults.push(...chunkResults);
220
+ }
221
+
222
+ // Fill in missing statuses back to the result array
223
+ missingResults.forEach(({ index, fillStatus }) => {
224
+ fillStatuses[index] = fillStatus;
225
+ });
226
+
227
+ return fillStatuses;
228
+ }
229
+
230
+ /**
231
+ * Finds the `FilledRelay` event for a given deposit within the provided slot range.
232
+ *
233
+ * @param relayData - Deposit information that is used to complete a fill.
234
+ * @param destinationChainId - Destination chain ID (must be an SVM chain).
235
+ * @param svmEventsClient - SVM events client instance for querying events.
236
+ * @param fromSlot - Starting slot to search.
237
+ * @param toSlot (Optional) Ending slot to search. If not provided, the current confirmed slot will be used.
238
+ * @returns The fill event with block info, or `undefined` if not found.
239
+ */
240
+ export async function findFillEvent(
241
+ relayData: RelayData,
242
+ destinationChainId: number,
243
+ svmEventsClient: SvmCpiEventsClient,
244
+ fromSlot: number,
245
+ toSlot?: number
246
+ ): Promise<FillWithBlock | undefined> {
247
+ assert(chainIsSvm(destinationChainId), "Destination chain must be an SVM chain");
248
+ toSlot ??= Number(await svmEventsClient.getRpc().getSlot({ commitment: "confirmed" }).send());
249
+
250
+ // Get fillStatus PDA using relayData
251
+ const programId = svmEventsClient.getProgramAddress();
252
+ const fillStatusPda = await getFillStatusPda(programId, relayData, destinationChainId);
253
+
254
+ // Get fill events from fillStatus PDA
255
+ const fillEvents = await svmEventsClient.queryDerivedAddressEvents(
256
+ SVMEventNames.FilledRelay,
257
+ fillStatusPda,
258
+ BigInt(fromSlot),
259
+ BigInt(toSlot),
260
+ { limit: 10 }
261
+ );
262
+ assert(fillEvents.length <= 1, `Expected at most one fill event for ${fillStatusPda}, got ${fillEvents.length}`);
263
+
264
+ if (fillEvents.length > 0) {
265
+ const rawFillEvent = fillEvents[0];
266
+ const parsedFillEvent = {
267
+ transactionHash: rawFillEvent.signature,
268
+ blockNumber: Number(rawFillEvent.slot),
269
+ transactionIndex: 0,
270
+ logIndex: 0,
271
+ destinationChainId,
272
+ ...(unwrapEventData(rawFillEvent.data) as Record<string, unknown>),
273
+ } as unknown as FillWithBlock;
274
+ return parsedFillEvent;
275
+ }
276
+
277
+ return undefined;
278
+ }
279
+
280
+ /**
281
+ * @param spokePool Address (program ID) of the SvmSpoke.
282
+ * @param deposit V3Deopsit instance.
283
+ * @param relayer Address of the relayer filling the deposit.
284
+ * @param repaymentChainId Optional repaymentChainId (defaults to destinationChainId).
285
+ * @returns An Ethers UnsignedTransaction instance.
286
+ */
287
+ export async function fillRelayInstruction(
288
+ spokePool: SvmAddress,
289
+ deposit: Omit<Deposit, "messageHash">,
290
+ relayer: TransactionSigner<string>,
291
+ recipientTokenAccount: Address<string>,
292
+ repaymentChainId = deposit.destinationChainId
293
+ ) {
294
+ const programId = spokePool.toBase58();
295
+ const relayerAddress = SvmAddress.from(relayer.address);
296
+
297
+ // @todo we need to convert the deposit's relayData to svm-like since the interface assumes the data originates from an EVM Spoke pool.
298
+ // Once we migrate to `Address` types, this can be modified/removed.
299
+ const [depositor, recipient, exclusiveRelayer, inputToken, outputToken] = [
300
+ deposit.depositor,
301
+ deposit.recipient,
302
+ deposit.exclusiveRelayer,
303
+ deposit.inputToken,
304
+ deposit.outputToken,
305
+ ].map((addr) => toAddressType(addr).forceSvmAddress());
306
+
307
+ const _relayDataHash = getRelayDataHash(deposit, deposit.destinationChainId);
308
+ const relayDataHash = new Uint8Array(Buffer.from(_relayDataHash.slice(2), "hex"));
309
+
310
+ // Create ATA for the relayer and recipient token accounts
311
+ const relayerTokenAccount = await getAssociatedTokenAddress(relayerAddress, outputToken);
312
+
313
+ const [statePda, fillStatusPda, eventAuthority] = await Promise.all([
314
+ getStatePda(spokePool.toV2Address()),
315
+ getFillStatusPda(spokePool.toV2Address(), deposit, deposit.destinationChainId),
316
+ getEventAuthority(),
317
+ ]);
318
+ const depositIdBuffer = Buffer.alloc(32);
319
+ const shortenedBuffer = Buffer.from(deposit.depositId.toHexString().slice(2), "hex");
320
+ shortenedBuffer.copy(depositIdBuffer, 32 - shortenedBuffer.length);
321
+
322
+ return SvmSpokeClient.getFillRelayInstruction({
323
+ signer: relayer,
324
+ state: statePda,
325
+ mint: outputToken.toV2Address(),
326
+ relayerTokenAccount: relayerTokenAccount,
327
+ recipientTokenAccount: recipientTokenAccount,
328
+ fillStatus: fillStatusPda,
329
+ eventAuthority,
330
+ program: address(programId),
331
+ relayHash: relayDataHash,
332
+ relayData: some({
333
+ depositor: depositor.toV2Address(),
334
+ recipient: recipient.toV2Address(),
335
+ exclusiveRelayer: exclusiveRelayer.toV2Address(),
336
+ inputToken: inputToken.toV2Address(),
337
+ outputToken: outputToken.toV2Address(),
338
+ inputAmount: deposit.inputAmount.toBigInt(),
339
+ outputAmount: deposit.outputAmount.toBigInt(),
340
+ originChainId: BigInt(deposit.originChainId),
341
+ fillDeadline: deposit.fillDeadline,
342
+ exclusivityDeadline: deposit.exclusivityDeadline,
343
+ depositId: new Uint8Array(depositIdBuffer),
344
+ message: new Uint8Array(Buffer.from(deposit.message.slice(2), "hex")),
345
+ }),
346
+ repaymentChainId: some(BigInt(repaymentChainId)),
347
+ repaymentAddress: some(relayerAddress.toV2Address()),
348
+ });
349
+ }
350
+
351
+ /**
352
+ * @param mint Address of the token corresponding to the account being made.
353
+ * @param relayer Address of the relayer filling the deposit.
354
+ * @returns An instruction for creating a new token account.
355
+ */
356
+ export function createTokenAccountsInstruction(
357
+ mint: SvmAddress,
358
+ relayer: TransactionSigner<string>
359
+ ): SvmSpokeClient.CreateTokenAccountsInstruction {
360
+ return SvmSpokeClient.getCreateTokenAccountsInstruction({
361
+ signer: relayer,
362
+ mint: mint.toV2Address(),
363
+ });
364
+ }
365
+
366
+ /**
367
+ * @param mint Address of the token corresponding to the account being made.
368
+ * @param amount Amount of the token to approve.
369
+ * @param relayer Address of the relayer filling the deposit.
370
+ * @param spokePool Address (program ID) of the SvmSpoke.
371
+ * @returns A token approval instruction.
372
+ */
373
+ export async function createApproveInstruction(
374
+ mint: SvmAddress,
375
+ amount: BigNumber,
376
+ relayer: SvmAddress,
377
+ spokePool: SvmAddress,
378
+ mintDecimals?: number
379
+ ) {
380
+ const [relayerTokenAccount, statePda] = await Promise.all([
381
+ getAssociatedTokenAddress(relayer, mint, TOKEN_PROGRAM_ADDRESS),
382
+ getStatePda(spokePool.toV2Address()),
383
+ ]);
384
+
385
+ // If no mint decimals were supplied, then assign it to whatever value we have in TOKEN_SYMBOLS_MAP.
386
+ // If this token is not in TOKEN_SYMBOLS_MAP, then throw an error.
387
+ mintDecimals ??= getTokenInfo(mint.toBase58(), CHAIN_IDs.SOLANA)?.decimals;
388
+ if (!isDefined(mintDecimals)) {
389
+ throw new Error(`No mint decimals found for token ${mint.toBase58()}`);
390
+ }
391
+
392
+ return getApproveCheckedInstruction({
393
+ source: relayerTokenAccount,
394
+ mint: mint.toV2Address(),
395
+ delegate: statePda,
396
+ owner: relayer.toV2Address(),
397
+ amount: amount.toBigInt(),
398
+ decimals: mintDecimals,
399
+ });
400
+ }
401
+
402
+ export async function getAssociatedTokenAddress(
403
+ owner: SvmAddress,
404
+ mint: SvmAddress,
405
+ tokenProgramId: Address<string> = TOKEN_PROGRAM_ADDRESS
406
+ ): Promise<Address<string>> {
407
+ const [associatedToken] = await getProgramDerivedAddress({
408
+ programAddress: ASSOCIATED_TOKEN_PROGRAM_ADDRESS,
409
+ seeds: [owner.toBuffer(), SvmAddress.from(tokenProgramId).toBuffer(), mint.toBuffer()],
410
+ });
411
+ return associatedToken;
412
+ }
413
+
414
+ export function getRelayDataHash(relayData: RelayData, destinationChainId: number): string {
415
+ const toBuffer = (hex: string, byteLength: number, littleEndian: boolean = true) => {
416
+ const buffer = Buffer.from(hex.slice(2), "hex");
417
+ if (buffer.length < byteLength) {
418
+ const zeroPad = Buffer.alloc(byteLength);
419
+ buffer.copy(zeroPad, byteLength - buffer.length);
420
+ return littleEndian ? zeroPad.reverse() : zeroPad;
421
+ }
422
+ return littleEndian ? buffer.slice(0, byteLength).reverse() : buffer.slice(0, byteLength);
423
+ };
424
+ const contentToHash = Buffer.concat([
425
+ toBuffer(relayData.depositor, 32, false),
426
+ toBuffer(relayData.recipient, 32, false),
427
+ toBuffer(relayData.exclusiveRelayer, 32, false),
428
+ toBuffer(relayData.inputToken, 32, false),
429
+ toBuffer(relayData.outputToken, 32, false),
430
+ toBuffer(relayData.inputAmount.toHexString(), 8),
431
+ toBuffer(relayData.outputAmount.toHexString(), 8),
432
+ toBuffer(toBN(relayData.originChainId).toHexString(), 8),
433
+ toBuffer(relayData.depositId.toHexString(), 32, false),
434
+ toBuffer(toBN(relayData.fillDeadline).toHexString(), 4),
435
+ toBuffer(toBN(relayData.exclusivityDeadline).toHexString(), 4),
436
+ toBuffer(getMessageHash(relayData.message), 32, false),
437
+ toBuffer(toBN(destinationChainId).toHexString(), 8),
438
+ ]);
439
+ return keccak256(contentToHash);
440
+ }
441
+
442
+ async function resolveFillStatusFromPdaEvents(
443
+ fillStatusPda: Address,
444
+ toSlot: bigint,
445
+ svmEventsClient: SvmCpiEventsClient
446
+ ): Promise<FillStatus> {
447
+ // Get fill and requested slow fill events from fillStatus PDA
448
+ const eventsToQuery = [SVMEventNames.FilledRelay, SVMEventNames.RequestedSlowFill];
449
+ const relevantEvents = (
450
+ await Promise.all(
451
+ eventsToQuery.map((eventName) =>
452
+ // PDAs should have only a few events, requesting up to 10 should be enough.
453
+ svmEventsClient.queryDerivedAddressEvents(eventName, fillStatusPda, undefined, toSlot, { limit: 10 })
454
+ )
455
+ )
456
+ ).flat();
457
+
458
+ if (relevantEvents.length === 0) {
459
+ // No fill or requested slow fill events found for this PDA
460
+ return FillStatus.Unfilled;
461
+ }
462
+
463
+ // Sort events in ascending order of slot number
464
+ relevantEvents.sort((a, b) => Number(a.slot - b.slot));
465
+
466
+ // At this point we have an ordered array of only fill and requested slow fill events and
467
+ // since it's not possible to submit a slow fill request once a fill has been submitted,
468
+ // we can use the last event in the list to determine the fill status at the requested slot.
469
+ const fillStatusEvent = relevantEvents.pop();
470
+ switch (fillStatusEvent!.name) {
471
+ case SVMEventNames.FilledRelay:
472
+ return FillStatus.Filled;
473
+ case SVMEventNames.RequestedSlowFill:
474
+ return FillStatus.RequestedSlowFill;
475
+ default:
476
+ throw new Error(`Unexpected event name: ${fillStatusEvent!.name}`);
477
+ }
478
+ }
479
+
480
+ /**
481
+ * Attempts to resolve the fill status for an array of deposits by reading their fillStatus PDAs.
482
+ *
483
+ * - If a PDA exists, the status is read directly from it.
484
+ * - If the PDA does not exist but the deposit's fill deadline has not passed, the deposit is considered unfilled.
485
+ * - If the PDA does not exist and the fill deadline has passed, the status cannot be determined and is set to undefined.
486
+ *
487
+ * Assumes PDAs can only be closed after the fill deadline expires.
488
+ *
489
+ * @param provider SVM provider instance
490
+ * @param fillStatusPdas An array of fill status PDAs to retrieve the fill status for.
491
+ * @param relayData An array of relay data from which the fill status PDAs were derived.
492
+ */
493
+ async function fetchBatchFillStatusFromPdaAccounts(
494
+ provider: SVMProvider,
495
+ fillStatusPdas: Address[],
496
+ relayDataArray: RelayData[]
497
+ ): Promise<(FillStatus | undefined)[]> {
498
+ const chunkSize = 100; // SVM method getMultipleAccounts allows a max of 100 addresses per request
499
+ const currentSlot = await provider.getSlot({ commitment: "confirmed" }).send();
500
+
501
+ const [pdaAccounts, currentSlotTimestamp] = await Promise.all([
502
+ Promise.all(
503
+ chunk(fillStatusPdas, chunkSize).map((chunk) =>
504
+ fetchEncodedAccounts(provider, chunk, { commitment: "confirmed" })
505
+ )
506
+ ),
507
+ provider.getBlockTime(currentSlot).send(),
508
+ ]);
509
+
510
+ const fillStatuses = pdaAccounts.flat().map((account, index) => {
511
+ // If the PDA exists, we can fetch the status directly.
512
+ if (account.exists) {
513
+ const decodedAccount = decodeFillStatusAccount(account);
514
+ return decodedAccount.data.status;
515
+ }
516
+ // If the PDA doesn't exist and the deadline hasn't passed yet, the deposit must be unfilled,
517
+ // since PDAs can't be closed before the fill deadline.
518
+ else if (Number(currentSlotTimestamp) < relayDataArray[index].fillDeadline) {
519
+ return FillStatus.Unfilled;
520
+ }
521
+ // If the PDA doesn't exist and the fill deadline has passed, then the status can't be determined and is set to undefined.
522
+ return undefined;
523
+ });
524
+
525
+ return fillStatuses;
526
+ }
@@ -0,0 +1 @@
1
+ export const SVM_SPOKE_SEED = BigInt(0);