@across-protocol/sdk 4.1.63-alpha.1 → 4.1.63-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 (363) 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 +424 -0
  6. package/dist/cjs/arch/svm/SpokeUtils.js.map +1 -0
  7. package/dist/cjs/arch/svm/constants.d.ts +2 -0
  8. package/dist/cjs/arch/svm/constants.js +7 -0
  9. package/dist/cjs/arch/svm/constants.js.map +1 -0
  10. package/dist/cjs/arch/svm/eventsClient.d.ts +26 -0
  11. package/dist/cjs/arch/svm/eventsClient.js +253 -0
  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 +114 -114
  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 +13 -0
  76. package/dist/cjs/interfaces/SpokePool.js.map +1 -1
  77. package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.d.ts +1 -1
  78. package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.js +5 -4
  79. package/dist/cjs/relayFeeCalculator/chain-queries/baseQuery.js.map +1 -1
  80. package/dist/cjs/relayFeeCalculator/chain-queries/factory.d.ts +4 -2
  81. package/dist/cjs/relayFeeCalculator/chain-queries/factory.js +7 -1
  82. package/dist/cjs/relayFeeCalculator/chain-queries/factory.js.map +1 -1
  83. package/dist/cjs/relayFeeCalculator/chain-queries/index.d.ts +1 -0
  84. package/dist/cjs/relayFeeCalculator/chain-queries/index.js +1 -0
  85. package/dist/cjs/relayFeeCalculator/chain-queries/index.js.map +1 -1
  86. package/dist/cjs/relayFeeCalculator/chain-queries/svmQuery.d.ts +31 -0
  87. package/dist/cjs/relayFeeCalculator/chain-queries/svmQuery.js +136 -0
  88. package/dist/cjs/relayFeeCalculator/chain-queries/svmQuery.js.map +1 -0
  89. package/dist/cjs/utils/AddressUtils.d.ts +9 -3
  90. package/dist/cjs/utils/AddressUtils.js +36 -6
  91. package/dist/cjs/utils/AddressUtils.js.map +1 -1
  92. package/dist/cjs/utils/ArrayUtils.d.ts +1 -0
  93. package/dist/cjs/utils/ArrayUtils.js +6 -1
  94. package/dist/cjs/utils/ArrayUtils.js.map +1 -1
  95. package/dist/cjs/utils/EventUtils.d.ts +4 -4
  96. package/dist/cjs/utils/EventUtils.js +7 -4
  97. package/dist/cjs/utils/EventUtils.js.map +1 -1
  98. package/dist/cjs/utils/JSONUtils.js +3 -0
  99. package/dist/cjs/utils/JSONUtils.js.map +1 -1
  100. package/dist/cjs/utils/SpokeUtils.js +5 -0
  101. package/dist/cjs/utils/SpokeUtils.js.map +1 -1
  102. package/dist/esm/arch/evm/SpokeUtils.d.ts +1 -1
  103. package/dist/esm/arch/evm/SpokeUtils.js +6 -5
  104. package/dist/esm/arch/evm/SpokeUtils.js.map +1 -1
  105. package/dist/esm/arch/svm/SpokeUtils.d.ts +94 -0
  106. package/dist/esm/arch/svm/SpokeUtils.js +509 -0
  107. package/dist/esm/arch/svm/SpokeUtils.js.map +1 -0
  108. package/dist/esm/arch/svm/constants.d.ts +2 -0
  109. package/dist/esm/arch/svm/constants.js +3 -0
  110. package/dist/esm/arch/svm/constants.js.map +1 -0
  111. package/dist/esm/arch/svm/eventsClient.d.ts +87 -0
  112. package/dist/esm/arch/svm/eventsClient.js +316 -0
  113. package/dist/esm/arch/svm/eventsClient.js.map +1 -0
  114. package/dist/esm/arch/svm/index.d.ts +5 -1
  115. package/dist/esm/arch/svm/index.js +5 -1
  116. package/dist/esm/arch/svm/index.js.map +1 -1
  117. package/dist/{types → esm/arch}/svm/types.d.ts +9 -5
  118. package/dist/esm/arch/svm/types.js.map +1 -0
  119. package/dist/esm/arch/svm/utils.d.ts +59 -0
  120. package/dist/esm/arch/svm/utils.js +248 -0
  121. package/dist/esm/arch/svm/utils.js.map +1 -0
  122. package/dist/esm/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.d.ts +1 -1
  123. package/dist/esm/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js +7 -7
  124. package/dist/esm/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.js.map +1 -1
  125. package/dist/esm/clients/BaseAbstractClient.d.ts +6 -5
  126. package/dist/esm/clients/BaseAbstractClient.js +30 -19
  127. package/dist/esm/clients/BaseAbstractClient.js.map +1 -1
  128. package/dist/esm/clients/BundleDataClient/BundleDataClient.js +17 -14
  129. package/dist/esm/clients/BundleDataClient/BundleDataClient.js.map +1 -1
  130. package/dist/esm/clients/BundleDataClient/utils/PoolRebalanceUtils.js +1 -1
  131. package/dist/esm/clients/BundleDataClient/utils/PoolRebalanceUtils.js.map +1 -1
  132. package/dist/esm/clients/BundleDataClient/utils/SuperstructUtils.d.ts +114 -114
  133. package/dist/esm/clients/HubPoolClient.d.ts +1 -1
  134. package/dist/esm/clients/HubPoolClient.js +16 -16
  135. package/dist/esm/clients/HubPoolClient.js.map +1 -1
  136. package/dist/esm/clients/SpokePoolClient/EVMSpokePoolClient.d.ts +3 -3
  137. package/dist/esm/clients/SpokePoolClient/EVMSpokePoolClient.js +23 -20
  138. package/dist/esm/clients/SpokePoolClient/EVMSpokePoolClient.js.map +1 -1
  139. package/dist/esm/clients/SpokePoolClient/SVMSpokePoolClient.d.ts +67 -0
  140. package/dist/esm/clients/SpokePoolClient/SVMSpokePoolClient.js +196 -0
  141. package/dist/esm/clients/SpokePoolClient/SVMSpokePoolClient.js.map +1 -0
  142. package/dist/esm/clients/SpokePoolClient/SpokePoolClient.d.ts +7 -7
  143. package/dist/esm/clients/SpokePoolClient/SpokePoolClient.js +51 -55
  144. package/dist/esm/clients/SpokePoolClient/SpokePoolClient.js.map +1 -1
  145. package/dist/esm/clients/SpokePoolClient/index.d.ts +8 -0
  146. package/dist/esm/clients/SpokePoolClient/index.js +10 -0
  147. package/dist/esm/clients/SpokePoolClient/index.js.map +1 -1
  148. package/dist/esm/clients/index.d.ts +1 -1
  149. package/dist/esm/clients/index.js +1 -1
  150. package/dist/esm/clients/index.js.map +1 -1
  151. package/dist/esm/clients/mocks/MockConfigStoreClient.d.ts +1 -1
  152. package/dist/esm/clients/mocks/MockConfigStoreClient.js +2 -2
  153. package/dist/esm/clients/mocks/MockConfigStoreClient.js.map +1 -1
  154. package/dist/esm/clients/mocks/MockHubPoolClient.js +2 -2
  155. package/dist/esm/clients/mocks/MockHubPoolClient.js.map +1 -1
  156. package/dist/esm/clients/mocks/MockSpokePoolClient.js +8 -5
  157. package/dist/esm/clients/mocks/MockSpokePoolClient.js.map +1 -1
  158. package/dist/esm/gasPriceOracle/adapters/arbitrum.d.ts +2 -2
  159. package/dist/esm/gasPriceOracle/adapters/arbitrum.js.map +1 -1
  160. package/dist/esm/gasPriceOracle/adapters/ethereum.d.ts +4 -4
  161. package/dist/esm/gasPriceOracle/adapters/ethereum.js.map +1 -1
  162. package/dist/esm/gasPriceOracle/adapters/linea-viem.js +3 -2
  163. package/dist/esm/gasPriceOracle/adapters/linea-viem.js.map +1 -1
  164. package/dist/esm/gasPriceOracle/adapters/polygon.d.ts +4 -4
  165. package/dist/esm/gasPriceOracle/adapters/polygon.js +1 -1
  166. package/dist/esm/gasPriceOracle/adapters/solana.d.ts +8 -0
  167. package/dist/esm/gasPriceOracle/adapters/solana.js +43 -0
  168. package/dist/esm/gasPriceOracle/adapters/solana.js.map +1 -0
  169. package/dist/esm/gasPriceOracle/index.d.ts +1 -1
  170. package/dist/esm/gasPriceOracle/oracle.d.ts +4 -3
  171. package/dist/esm/gasPriceOracle/oracle.js +18 -9
  172. package/dist/esm/gasPriceOracle/oracle.js.map +1 -1
  173. package/dist/esm/gasPriceOracle/types.d.ts +6 -1
  174. package/dist/esm/index.d.ts +0 -1
  175. package/dist/esm/index.js +0 -2
  176. package/dist/esm/index.js.map +1 -1
  177. package/dist/esm/interfaces/SpokePool.d.ts +13 -0
  178. package/dist/esm/interfaces/SpokePool.js.map +1 -1
  179. package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.d.ts +1 -1
  180. package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.js +4 -3
  181. package/dist/esm/relayFeeCalculator/chain-queries/baseQuery.js.map +1 -1
  182. package/dist/esm/relayFeeCalculator/chain-queries/factory.d.ts +4 -2
  183. package/dist/esm/relayFeeCalculator/chain-queries/factory.js +8 -2
  184. package/dist/esm/relayFeeCalculator/chain-queries/factory.js.map +1 -1
  185. package/dist/esm/relayFeeCalculator/chain-queries/index.d.ts +1 -0
  186. package/dist/esm/relayFeeCalculator/chain-queries/index.js +1 -0
  187. package/dist/esm/relayFeeCalculator/chain-queries/index.js.map +1 -1
  188. package/dist/esm/relayFeeCalculator/chain-queries/svmQuery.d.ts +66 -0
  189. package/dist/esm/relayFeeCalculator/chain-queries/svmQuery.js +169 -0
  190. package/dist/esm/relayFeeCalculator/chain-queries/svmQuery.js.map +1 -0
  191. package/dist/esm/utils/AddressUtils.d.ts +9 -3
  192. package/dist/esm/utils/AddressUtils.js +41 -6
  193. package/dist/esm/utils/AddressUtils.js.map +1 -1
  194. package/dist/esm/utils/ArrayUtils.d.ts +6 -0
  195. package/dist/esm/utils/ArrayUtils.js +9 -0
  196. package/dist/esm/utils/ArrayUtils.js.map +1 -1
  197. package/dist/esm/utils/EventUtils.d.ts +4 -4
  198. package/dist/esm/utils/EventUtils.js +7 -4
  199. package/dist/esm/utils/EventUtils.js.map +1 -1
  200. package/dist/esm/utils/JSONUtils.js +3 -0
  201. package/dist/esm/utils/JSONUtils.js.map +1 -1
  202. package/dist/esm/utils/SpokeUtils.js +5 -0
  203. package/dist/esm/utils/SpokeUtils.js.map +1 -1
  204. package/dist/types/arch/evm/SpokeUtils.d.ts +1 -1
  205. package/dist/types/arch/evm/SpokeUtils.d.ts.map +1 -1
  206. package/dist/types/arch/svm/SpokeUtils.d.ts +95 -0
  207. package/dist/types/arch/svm/SpokeUtils.d.ts.map +1 -0
  208. package/dist/types/arch/svm/constants.d.ts +3 -0
  209. package/dist/types/arch/svm/constants.d.ts.map +1 -0
  210. package/dist/types/arch/svm/eventsClient.d.ts +88 -0
  211. package/dist/types/arch/svm/eventsClient.d.ts.map +1 -0
  212. package/dist/types/arch/svm/index.d.ts +5 -1
  213. package/dist/types/arch/svm/index.d.ts.map +1 -1
  214. package/dist/{esm → types/arch}/svm/types.d.ts +10 -4
  215. package/dist/types/arch/svm/types.d.ts.map +1 -0
  216. package/dist/types/arch/svm/utils.d.ts +60 -0
  217. package/dist/types/arch/svm/utils.d.ts.map +1 -0
  218. package/dist/types/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.d.ts +1 -1
  219. package/dist/types/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.d.ts.map +1 -1
  220. package/dist/types/clients/BaseAbstractClient.d.ts +6 -5
  221. package/dist/types/clients/BaseAbstractClient.d.ts.map +1 -1
  222. package/dist/types/clients/BundleDataClient/BundleDataClient.d.ts.map +1 -1
  223. package/dist/types/clients/BundleDataClient/utils/SuperstructUtils.d.ts +114 -114
  224. package/dist/types/clients/HubPoolClient.d.ts +1 -1
  225. package/dist/types/clients/HubPoolClient.d.ts.map +1 -1
  226. package/dist/types/clients/SpokePoolClient/EVMSpokePoolClient.d.ts +3 -3
  227. package/dist/types/clients/SpokePoolClient/EVMSpokePoolClient.d.ts.map +1 -1
  228. package/dist/types/clients/SpokePoolClient/SVMSpokePoolClient.d.ts +68 -0
  229. package/dist/types/clients/SpokePoolClient/SVMSpokePoolClient.d.ts.map +1 -0
  230. package/dist/types/clients/SpokePoolClient/SpokePoolClient.d.ts +7 -7
  231. package/dist/types/clients/SpokePoolClient/SpokePoolClient.d.ts.map +1 -1
  232. package/dist/types/clients/SpokePoolClient/index.d.ts +8 -0
  233. package/dist/types/clients/SpokePoolClient/index.d.ts.map +1 -1
  234. package/dist/types/clients/index.d.ts +1 -1
  235. package/dist/types/clients/index.d.ts.map +1 -1
  236. package/dist/types/clients/mocks/MockConfigStoreClient.d.ts +1 -1
  237. package/dist/types/clients/mocks/MockConfigStoreClient.d.ts.map +1 -1
  238. package/dist/types/clients/mocks/MockSpokePoolClient.d.ts.map +1 -1
  239. package/dist/types/gasPriceOracle/adapters/arbitrum.d.ts +2 -2
  240. package/dist/types/gasPriceOracle/adapters/arbitrum.d.ts.map +1 -1
  241. package/dist/types/gasPriceOracle/adapters/ethereum.d.ts +4 -4
  242. package/dist/types/gasPriceOracle/adapters/ethereum.d.ts.map +1 -1
  243. package/dist/types/gasPriceOracle/adapters/linea-viem.d.ts.map +1 -1
  244. package/dist/types/gasPriceOracle/adapters/polygon.d.ts +4 -4
  245. package/dist/types/gasPriceOracle/adapters/polygon.d.ts.map +1 -1
  246. package/dist/types/gasPriceOracle/adapters/solana.d.ts +9 -0
  247. package/dist/types/gasPriceOracle/adapters/solana.d.ts.map +1 -0
  248. package/dist/types/gasPriceOracle/index.d.ts +1 -1
  249. package/dist/types/gasPriceOracle/index.d.ts.map +1 -1
  250. package/dist/types/gasPriceOracle/oracle.d.ts +4 -3
  251. package/dist/types/gasPriceOracle/oracle.d.ts.map +1 -1
  252. package/dist/types/gasPriceOracle/types.d.ts +6 -1
  253. package/dist/types/gasPriceOracle/types.d.ts.map +1 -1
  254. package/dist/types/index.d.ts +0 -1
  255. package/dist/types/index.d.ts.map +1 -1
  256. package/dist/types/interfaces/SpokePool.d.ts +13 -0
  257. package/dist/types/interfaces/SpokePool.d.ts.map +1 -1
  258. package/dist/types/relayFeeCalculator/chain-queries/baseQuery.d.ts +1 -1
  259. package/dist/types/relayFeeCalculator/chain-queries/baseQuery.d.ts.map +1 -1
  260. package/dist/types/relayFeeCalculator/chain-queries/factory.d.ts +4 -2
  261. package/dist/types/relayFeeCalculator/chain-queries/factory.d.ts.map +1 -1
  262. package/dist/types/relayFeeCalculator/chain-queries/index.d.ts +1 -0
  263. package/dist/types/relayFeeCalculator/chain-queries/index.d.ts.map +1 -1
  264. package/dist/types/relayFeeCalculator/chain-queries/svmQuery.d.ts +67 -0
  265. package/dist/types/relayFeeCalculator/chain-queries/svmQuery.d.ts.map +1 -0
  266. package/dist/types/utils/AddressUtils.d.ts +9 -3
  267. package/dist/types/utils/AddressUtils.d.ts.map +1 -1
  268. package/dist/types/utils/ArrayUtils.d.ts +6 -0
  269. package/dist/types/utils/ArrayUtils.d.ts.map +1 -1
  270. package/dist/types/utils/EventUtils.d.ts +4 -4
  271. package/dist/types/utils/EventUtils.d.ts.map +1 -1
  272. package/dist/types/utils/JSONUtils.d.ts.map +1 -1
  273. package/dist/types/utils/SpokeUtils.d.ts.map +1 -1
  274. package/package.json +5 -2
  275. package/src/arch/evm/SpokeUtils.ts +5 -5
  276. package/src/arch/svm/SpokeUtils.ts +526 -0
  277. package/src/arch/svm/constants.ts +2 -0
  278. package/src/arch/svm/eventsClient.ts +334 -0
  279. package/src/arch/svm/index.ts +5 -1
  280. package/src/{svm → arch/svm}/types.ts +21 -4
  281. package/src/arch/svm/utils.ts +222 -0
  282. package/src/clients/AcrossConfigStoreClient/AcrossConfigStoreClient.ts +7 -7
  283. package/src/clients/BaseAbstractClient.ts +20 -13
  284. package/src/clients/BundleDataClient/BundleDataClient.ts +28 -19
  285. package/src/clients/BundleDataClient/utils/PoolRebalanceUtils.ts +1 -1
  286. package/src/clients/HubPoolClient.ts +16 -16
  287. package/src/clients/SpokePoolClient/EVMSpokePoolClient.ts +23 -21
  288. package/src/clients/SpokePoolClient/SVMSpokePoolClient.ts +244 -0
  289. package/src/clients/SpokePoolClient/SpokePoolClient.ts +44 -56
  290. package/src/clients/SpokePoolClient/index.ts +11 -0
  291. package/src/clients/index.ts +1 -1
  292. package/src/clients/mocks/MockConfigStoreClient.ts +2 -2
  293. package/src/clients/mocks/MockHubPoolClient.ts +2 -2
  294. package/src/clients/mocks/MockSpokePoolClient.ts +9 -4
  295. package/src/gasPriceOracle/adapters/arbitrum.ts +5 -2
  296. package/src/gasPriceOracle/adapters/ethereum.ts +7 -4
  297. package/src/gasPriceOracle/adapters/linea-viem.ts +3 -1
  298. package/src/gasPriceOracle/adapters/polygon.ts +6 -6
  299. package/src/gasPriceOracle/adapters/solana.ts +45 -0
  300. package/src/gasPriceOracle/index.ts +1 -1
  301. package/src/gasPriceOracle/oracle.ts +20 -4
  302. package/src/gasPriceOracle/types.ts +7 -1
  303. package/src/index.ts +0 -1
  304. package/src/interfaces/SpokePool.ts +14 -0
  305. package/src/relayFeeCalculator/chain-queries/baseQuery.ts +5 -3
  306. package/src/relayFeeCalculator/chain-queries/factory.ts +21 -5
  307. package/src/relayFeeCalculator/chain-queries/index.ts +1 -0
  308. package/src/relayFeeCalculator/chain-queries/svmQuery.ts +193 -0
  309. package/src/utils/AddressUtils.ts +49 -6
  310. package/src/utils/ArrayUtils.ts +12 -0
  311. package/src/utils/EventUtils.ts +11 -11
  312. package/src/utils/JSONUtils.ts +2 -0
  313. package/src/utils/SpokeUtils.ts +7 -3
  314. package/dist/cjs/svm/eventsClient.d.ts +0 -15
  315. package/dist/cjs/svm/eventsClient.js +0 -157
  316. package/dist/cjs/svm/eventsClient.js.map +0 -1
  317. package/dist/cjs/svm/index.d.ts +0 -3
  318. package/dist/cjs/svm/index.js +0 -8
  319. package/dist/cjs/svm/index.js.map +0 -1
  320. package/dist/cjs/svm/types.js.map +0 -1
  321. package/dist/cjs/svm/utils/events.d.ts +0 -8
  322. package/dist/cjs/svm/utils/events.js +0 -47
  323. package/dist/cjs/svm/utils/events.js.map +0 -1
  324. package/dist/cjs/svm/utils/helpers.d.ts +0 -2
  325. package/dist/cjs/svm/utils/helpers.js +0 -19
  326. package/dist/cjs/svm/utils/helpers.js.map +0 -1
  327. package/dist/cjs/svm/utils/index.d.ts +0 -1
  328. package/dist/cjs/svm/utils/index.js +0 -5
  329. package/dist/cjs/svm/utils/index.js.map +0 -1
  330. package/dist/esm/svm/eventsClient.d.ts +0 -51
  331. package/dist/esm/svm/eventsClient.js +0 -195
  332. package/dist/esm/svm/eventsClient.js.map +0 -1
  333. package/dist/esm/svm/index.d.ts +0 -3
  334. package/dist/esm/svm/index.js +0 -5
  335. package/dist/esm/svm/index.js.map +0 -1
  336. package/dist/esm/svm/types.js.map +0 -1
  337. package/dist/esm/svm/utils/events.d.ts +0 -17
  338. package/dist/esm/svm/utils/events.js +0 -55
  339. package/dist/esm/svm/utils/events.js.map +0 -1
  340. package/dist/esm/svm/utils/helpers.d.ts +0 -5
  341. package/dist/esm/svm/utils/helpers.js +0 -18
  342. package/dist/esm/svm/utils/helpers.js.map +0 -1
  343. package/dist/esm/svm/utils/index.d.ts +0 -1
  344. package/dist/esm/svm/utils/index.js +0 -2
  345. package/dist/esm/svm/utils/index.js.map +0 -1
  346. package/dist/types/svm/eventsClient.d.ts +0 -52
  347. package/dist/types/svm/eventsClient.d.ts.map +0 -1
  348. package/dist/types/svm/index.d.ts +0 -4
  349. package/dist/types/svm/index.d.ts.map +0 -1
  350. package/dist/types/svm/types.d.ts.map +0 -1
  351. package/dist/types/svm/utils/events.d.ts +0 -18
  352. package/dist/types/svm/utils/events.d.ts.map +0 -1
  353. package/dist/types/svm/utils/helpers.d.ts +0 -6
  354. package/dist/types/svm/utils/helpers.d.ts.map +0 -1
  355. package/dist/types/svm/utils/index.d.ts +0 -2
  356. package/dist/types/svm/utils/index.d.ts.map +0 -1
  357. package/src/svm/eventsClient.ts +0 -199
  358. package/src/svm/index.ts +0 -3
  359. package/src/svm/utils/events.ts +0 -58
  360. package/src/svm/utils/helpers.ts +0 -9
  361. package/src/svm/utils/index.ts +0 -1
  362. /package/dist/cjs/{svm → arch/svm}/types.js +0 -0
  363. /package/dist/esm/{svm → arch/svm}/types.js +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"SpokeUtils.d.ts","sourceRoot":"","sources":["../../../src/utils/SpokeUtils.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAEnD,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAG7C;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,aAAa,CAAC,GAAG,SAAS,CAepF;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,GAAG,MAAM,CAgCzF;AAED,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,SAAS,GAAG;IAAE,kBAAkB,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAE3F;AAED,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,SAAS,GAAG,OAAO,CAQ/D;AAGD,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAEtD;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEtD"}
1
+ {"version":3,"file":"SpokeUtils.d.ts","sourceRoot":"","sources":["../../../src/utils/SpokeUtils.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAEnD,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAK7C;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,IAAI,CAAC,OAAO,EAAE,aAAa,CAAC,GAAG,SAAS,CAepF;AAED;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,SAAS,EAAE,kBAAkB,EAAE,MAAM,GAAG,MAAM,CAkCzF;AAED,wBAAgB,qBAAqB,CAAC,CAAC,EAAE,SAAS,GAAG;IAAE,kBAAkB,EAAE,MAAM,CAAA;CAAE,GAAG,MAAM,CAE3F;AAED,wBAAgB,iBAAiB,CAAC,SAAS,EAAE,SAAS,GAAG,OAAO,CAQ/D;AAGD,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAEtD;AAED,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAEtD"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@across-protocol/sdk",
3
3
  "author": "UMA Team",
4
- "version": "4.1.63-alpha.1",
4
+ "version": "4.1.63-beta.1",
5
5
  "license": "AGPL-3.0",
6
6
  "homepage": "https://docs.across.to/reference/sdk",
7
7
  "files": [
@@ -105,13 +105,16 @@
105
105
  "dependencies": {
106
106
  "@across-protocol/across-token": "^1.0.0",
107
107
  "@across-protocol/constants": "^3.1.64",
108
- "@across-protocol/contracts": "4.0.11-alpha.1",
108
+ "@across-protocol/contracts": "^4.0.9",
109
109
  "@coral-xyz/anchor": "^0.30.1",
110
110
  "@eth-optimism/sdk": "^3.3.1",
111
111
  "@ethersproject/bignumber": "^5.7.0",
112
112
  "@pinata/sdk": "^2.1.0",
113
113
  "@solana/kit": "^2.1.0",
114
+ "@solana-program/system": "^0.7.0",
115
+ "@solana-program/token-2022": "^0.4.0",
114
116
  "@solana/web3.js": "^1.31.0",
117
+ "@solana-program/system": "^0.7.0",
115
118
  "@types/mocha": "^10.0.1",
116
119
  "@uma/sdk": "^0.34.10",
117
120
  "arweave": "^1.14.4",
@@ -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 { SvmSpokeClient } from "@across-protocol/contracts";
2
+ import { decodeFillStatusAccount, fetchState } from "@across-protocol/contracts/dist/src/svm/clients/SvmSpoke";
3
+ import { hashNonEmptyMessage } from "@across-protocol/contracts/dist/src/svm/web3-v1";
4
+ import {
5
+ ASSOCIATED_TOKEN_PROGRAM_ADDRESS,
6
+ TOKEN_PROGRAM_ADDRESS,
7
+ getApproveCheckedInstruction,
8
+ } from "@solana-program/token";
9
+ import {
10
+ Address,
11
+ address,
12
+ fetchEncodedAccount,
13
+ fetchEncodedAccounts,
14
+ getAddressEncoder,
15
+ getProgramDerivedAddress,
16
+ getU32Encoder,
17
+ getU64Encoder,
18
+ some,
19
+ type TransactionSigner,
20
+ } from "@solana/kit";
21
+ import assert from "assert";
22
+ import { arrayify, hexZeroPad, hexlify } from "ethers/lib/utils";
23
+ import { Logger } from "winston";
24
+ import { CHAIN_IDs } from "../../constants";
25
+ import { Deposit, FillStatus, FillWithBlock, RelayData } from "../../interfaces";
26
+ import {
27
+ BigNumber,
28
+ SvmAddress,
29
+ chainIsSvm,
30
+ chunk,
31
+ getTokenInfo,
32
+ isDefined,
33
+ isUnsafeDepositId,
34
+ keccak256,
35
+ toAddressType,
36
+ } from "../../utils";
37
+ import { SvmCpiEventsClient, getEventAuthority, getFillStatusPda, getStatePda, unwrapEventData } from "./";
38
+ import { SVMEventNames, SVMProvider } from "./types";
39
+
40
+ /**
41
+ * @param spokePool SpokePool Contract instance.
42
+ * @param deposit V3Deopsit instance.
43
+ * @param repaymentChainId Optional repaymentChainId (defaults to destinationChainId).
44
+ * @returns An Ethers UnsignedTransaction instance.
45
+ */
46
+ export function populateV3Relay(
47
+ _spokePool: unknown,
48
+ _deposit: Omit<Deposit, "messageHash">,
49
+ _relayer: string,
50
+ _repaymentChainId = _deposit.destinationChainId
51
+ ): Promise<unknown> {
52
+ throw new Error("populateV3Relay: not implemented");
53
+ }
54
+
55
+ /**
56
+ * Retrieves the chain time at a particular slot.
57
+ */
58
+ export async function getTimestampForSlot(provider: SVMProvider, slotNumber: number): Promise<number> {
59
+ // @note: getBlockTime receives a slot number, not a block number.
60
+ const slotTime = await provider.getBlockTime(BigInt(slotNumber)).send();
61
+ return Number(slotTime);
62
+ }
63
+
64
+ /**
65
+ * Returns the current fill deadline buffer.
66
+ * @param provider SVM Provider instance
67
+ * @param statePda Spoke Pool's State PDA
68
+ * @returns fill deadline buffer
69
+ */
70
+ export async function getFillDeadline(provider: SVMProvider, statePda: Address): Promise<number> {
71
+ const state = await fetchState(provider, statePda);
72
+ return state.data.fillDeadlineBuffer;
73
+ }
74
+
75
+ /**
76
+ * Finds the deposit id at a specific block number.
77
+ * @param blockTag The block number to search for the deposit ID at.
78
+ * @returns The deposit ID.
79
+ */
80
+ export function getDepositIdAtBlock(_contract: unknown, _blockTag: number): Promise<BigNumber> {
81
+ throw new Error("getDepositIdAtBlock: not implemented");
82
+ }
83
+
84
+ export function findDepositBlock(
85
+ _spokePool: unknown,
86
+ depositId: BigNumber,
87
+ _lowBlock: number,
88
+ _highBlock?: number
89
+ ): Promise<number | undefined> {
90
+ // We can only perform this search when we have a safe deposit ID.
91
+ if (isUnsafeDepositId(depositId)) {
92
+ throw new Error(`Cannot binary search for depositId ${depositId}`);
93
+ }
94
+ throw new Error("findDepositBlock: not implemented");
95
+ }
96
+
97
+ /**
98
+ * Resolves the fill status of a deposit at a specific slot or at the current confirmed one.
99
+ *
100
+ * If no slot is provided, attempts to solve the fill status using the PDA. Otherwise, it is reconstructed from PDA events.
101
+ *
102
+ * @param programId - The spoke pool program ID.
103
+ * @param relayData - Deposit information used to locate the fill status.
104
+ * @param destinationChainId - Destination chain ID (must be an SVM chain).
105
+ * @param provider - SVM provider instance.
106
+ * @param svmEventsClient - SVM events client for querying events.
107
+ * @param atHeight - (Optional) Specific slot number to query. Defaults to the latest confirmed slot.
108
+ * @returns The fill status for the deposit at the specified or current slot.
109
+ */
110
+ export async function relayFillStatus(
111
+ programId: Address,
112
+ relayData: RelayData,
113
+ destinationChainId: number,
114
+ svmEventsClient: SvmCpiEventsClient,
115
+ atHeight?: number
116
+ ): Promise<FillStatus> {
117
+ assert(chainIsSvm(destinationChainId), "Destination chain must be an SVM chain");
118
+ const provider = svmEventsClient.getRpc();
119
+ // Get fill status PDA using relayData
120
+ const fillStatusPda = await getFillStatusPda(programId, relayData, destinationChainId);
121
+ const currentSlot = await provider.getSlot({ commitment: "confirmed" }).send();
122
+
123
+ // If no specific slot is requested, try fetching the current status from the PDA
124
+ if (atHeight === undefined) {
125
+ const [fillStatusAccount, currentSlotTimestamp] = await Promise.all([
126
+ fetchEncodedAccount(provider, fillStatusPda, { commitment: "confirmed" }),
127
+ provider.getBlockTime(currentSlot).send(),
128
+ ]);
129
+ // If the PDA exists, return the stored fill status
130
+ if (fillStatusAccount.exists) {
131
+ const decodedAccountData = decodeFillStatusAccount(fillStatusAccount);
132
+ return decodedAccountData.data.status;
133
+ }
134
+ // If the PDA doesn't exist and the deadline hasn't passed yet, the deposit must be unfilled,
135
+ // since PDAs can't be closed before the fill deadline.
136
+ else if (Number(currentSlotTimestamp) < relayData.fillDeadline) {
137
+ return FillStatus.Unfilled;
138
+ }
139
+ }
140
+
141
+ // If status couldn't be determined from the PDA, or if a specific slot was requested, reconstruct the status from events
142
+ const toSlot = atHeight ? BigInt(atHeight) : currentSlot;
143
+
144
+ return resolveFillStatusFromPdaEvents(fillStatusPda, toSlot, svmEventsClient);
145
+ }
146
+
147
+ /**
148
+ * Resolves fill statuses for multiple deposits at a specific or latest confirmed slot,
149
+ * using PDAs when possible and falling back to events if needed.
150
+ *
151
+ * @param programId The spoke pool program ID.
152
+ * @param relayData An array of relay data to resolve fill statuses for.
153
+ * @param destinationChainId The destination chain ID (must be an SVM chain).
154
+ * @param provider SVM Provider instance.
155
+ * @param svmEventsClient SVM events client instance for querying events.
156
+ * @param atHeight (Optional) The slot number to query at. If omitted, queries the latest confirmed slot.
157
+ * @returns An array of fill statuses for the specified deposits at the requested slot (or at the current confirmed slot).
158
+ */
159
+ export async function fillStatusArray(
160
+ programId: Address,
161
+ relayData: RelayData[],
162
+ destinationChainId: number,
163
+ svmEventsClient: SvmCpiEventsClient,
164
+ atHeight?: number,
165
+ logger?: Logger
166
+ ): Promise<(FillStatus | undefined)[]> {
167
+ assert(chainIsSvm(destinationChainId), "Destination chain must be an SVM chain");
168
+ const provider = svmEventsClient.getRpc();
169
+ const chunkSize = 100;
170
+ const chunkedRelayData = chunk(relayData, chunkSize);
171
+
172
+ // Get all PDAs
173
+ const fillStatusPdas = (
174
+ await Promise.all(
175
+ chunkedRelayData.map((relayDataChunk) =>
176
+ Promise.all(relayDataChunk.map((relayData) => getFillStatusPda(programId, relayData, destinationChainId)))
177
+ )
178
+ )
179
+ ).flat();
180
+
181
+ if (atHeight !== undefined && logger) {
182
+ logger.warn({
183
+ at: "SvmSpokeUtils#fillStatusArray",
184
+ message:
185
+ "Querying specific slots for large arrays is slow. For current status, omit 'atHeight' param to use latest confirmed slot instead.",
186
+ });
187
+ }
188
+
189
+ // If no specific slot is requested, try fetching current statuses from PDAs
190
+ // Otherwise, initialize all statuses as undefined
191
+ const fillStatuses: (FillStatus | undefined)[] =
192
+ atHeight === undefined
193
+ ? await fetchBatchFillStatusFromPdaAccounts(provider, fillStatusPdas, relayData)
194
+ : new Array(relayData.length).fill(undefined);
195
+
196
+ // Collect indices of deposits that still need their status resolved
197
+ const missingStatuses = fillStatuses.reduce<number[]>((acc, status, index) => {
198
+ if (status === undefined) {
199
+ acc.push(index);
200
+ }
201
+ return acc;
202
+ }, []);
203
+
204
+ // Chunk the missing deposits for batch processing
205
+ const missingChunked = chunk(missingStatuses, chunkSize);
206
+ const missingResults: { index: number; fillStatus: FillStatus }[] = [];
207
+
208
+ // Determine the toSlot to use for event reconstruction
209
+ const toSlot = atHeight ? BigInt(atHeight) : await provider.getSlot({ commitment: "confirmed" }).send();
210
+
211
+ // @note: This path is mostly used for deposits past their fill deadline.
212
+ // If it becomes a bottleneck, consider returning an "Unknown" status that can be handled downstream.
213
+ for (const chunk of missingChunked) {
214
+ const chunkResults = await Promise.all(
215
+ chunk.map(async (missingIndex) => {
216
+ return {
217
+ index: missingIndex,
218
+ fillStatus: await resolveFillStatusFromPdaEvents(fillStatusPdas[missingIndex], toSlot, svmEventsClient),
219
+ };
220
+ })
221
+ );
222
+ missingResults.push(...chunkResults);
223
+ }
224
+
225
+ // Fill in missing statuses back to the result array
226
+ missingResults.forEach(({ index, fillStatus }) => {
227
+ fillStatuses[index] = fillStatus;
228
+ });
229
+
230
+ return fillStatuses;
231
+ }
232
+
233
+ /**
234
+ * Finds the `FilledRelay` event for a given deposit within the provided slot range.
235
+ *
236
+ * @param relayData - Deposit information that is used to complete a fill.
237
+ * @param destinationChainId - Destination chain ID (must be an SVM chain).
238
+ * @param svmEventsClient - SVM events client instance for querying events.
239
+ * @param fromSlot - Starting slot to search.
240
+ * @param toSlot (Optional) Ending slot to search. If not provided, the current confirmed slot will be used.
241
+ * @returns The fill event with block info, or `undefined` if not found.
242
+ */
243
+ export async function findFillEvent(
244
+ relayData: RelayData,
245
+ destinationChainId: number,
246
+ svmEventsClient: SvmCpiEventsClient,
247
+ fromSlot: number,
248
+ toSlot?: number
249
+ ): Promise<FillWithBlock | undefined> {
250
+ assert(chainIsSvm(destinationChainId), "Destination chain must be an SVM chain");
251
+ toSlot ??= Number(await svmEventsClient.getRpc().getSlot({ commitment: "confirmed" }).send());
252
+
253
+ // Get fillStatus PDA using relayData
254
+ const programId = svmEventsClient.getProgramAddress();
255
+ const fillStatusPda = await getFillStatusPda(programId, relayData, destinationChainId);
256
+
257
+ // Get fill events from fillStatus PDA
258
+ const fillEvents = await svmEventsClient.queryDerivedAddressEvents(
259
+ SVMEventNames.FilledRelay,
260
+ fillStatusPda,
261
+ BigInt(fromSlot),
262
+ BigInt(toSlot),
263
+ { limit: 10 }
264
+ );
265
+ assert(fillEvents.length <= 1, `Expected at most one fill event for ${fillStatusPda}, got ${fillEvents.length}`);
266
+
267
+ if (fillEvents.length > 0) {
268
+ const rawFillEvent = fillEvents[0];
269
+ const parsedFillEvent = {
270
+ transactionHash: rawFillEvent.signature,
271
+ blockNumber: Number(rawFillEvent.slot),
272
+ transactionIndex: 0,
273
+ logIndex: 0,
274
+ destinationChainId,
275
+ ...(unwrapEventData(rawFillEvent.data) as Record<string, unknown>),
276
+ } as unknown as FillWithBlock;
277
+ return parsedFillEvent;
278
+ }
279
+
280
+ return undefined;
281
+ }
282
+
283
+ /**
284
+ * @param spokePool Address (program ID) of the SvmSpoke.
285
+ * @param deposit V3Deopsit instance.
286
+ * @param relayer Address of the relayer filling the deposit.
287
+ * @param repaymentChainId Optional repaymentChainId (defaults to destinationChainId).
288
+ * @returns An Ethers UnsignedTransaction instance.
289
+ */
290
+ export async function fillRelayInstruction(
291
+ spokePool: SvmAddress,
292
+ deposit: Omit<Deposit, "messageHash">,
293
+ relayer: TransactionSigner<string>,
294
+ recipientTokenAccount: Address<string>,
295
+ repaymentChainId = deposit.destinationChainId
296
+ ) {
297
+ const programId = spokePool.toBase58();
298
+ const relayerAddress = SvmAddress.from(relayer.address);
299
+
300
+ // @todo we need to convert the deposit's relayData to svm-like since the interface assumes the data originates from an EVM Spoke pool.
301
+ // Once we migrate to `Address` types, this can be modified/removed.
302
+ const [depositor, recipient, exclusiveRelayer, inputToken, outputToken] = [
303
+ deposit.depositor,
304
+ deposit.recipient,
305
+ deposit.exclusiveRelayer,
306
+ deposit.inputToken,
307
+ deposit.outputToken,
308
+ ].map((addr) => toAddressType(addr).forceSvmAddress());
309
+
310
+ const _relayDataHash = getRelayDataHash(deposit, deposit.destinationChainId);
311
+ const relayDataHash = new Uint8Array(Buffer.from(_relayDataHash.slice(2), "hex"));
312
+
313
+ // Create ATA for the relayer and recipient token accounts
314
+ const relayerTokenAccount = await getAssociatedTokenAddress(relayerAddress, outputToken);
315
+
316
+ const [statePda, fillStatusPda, eventAuthority] = await Promise.all([
317
+ getStatePda(spokePool.toV2Address()),
318
+ getFillStatusPda(spokePool.toV2Address(), deposit, deposit.destinationChainId),
319
+ getEventAuthority(),
320
+ ]);
321
+ const depositIdBuffer = Buffer.alloc(32);
322
+ const shortenedBuffer = Buffer.from(deposit.depositId.toHexString().slice(2), "hex");
323
+ shortenedBuffer.copy(depositIdBuffer, 32 - shortenedBuffer.length);
324
+
325
+ return SvmSpokeClient.getFillRelayInstruction({
326
+ signer: relayer,
327
+ state: statePda,
328
+ mint: outputToken.toV2Address(),
329
+ relayerTokenAccount: relayerTokenAccount,
330
+ recipientTokenAccount: recipientTokenAccount,
331
+ fillStatus: fillStatusPda,
332
+ eventAuthority,
333
+ program: address(programId),
334
+ relayHash: relayDataHash,
335
+ relayData: some({
336
+ depositor: depositor.toV2Address(),
337
+ recipient: recipient.toV2Address(),
338
+ exclusiveRelayer: exclusiveRelayer.toV2Address(),
339
+ inputToken: inputToken.toV2Address(),
340
+ outputToken: outputToken.toV2Address(),
341
+ inputAmount: deposit.inputAmount.toBigInt(),
342
+ outputAmount: deposit.outputAmount.toBigInt(),
343
+ originChainId: BigInt(deposit.originChainId),
344
+ fillDeadline: deposit.fillDeadline,
345
+ exclusivityDeadline: deposit.exclusivityDeadline,
346
+ depositId: new Uint8Array(depositIdBuffer),
347
+ message: new Uint8Array(Buffer.from(deposit.message.slice(2), "hex")),
348
+ }),
349
+ repaymentChainId: some(BigInt(repaymentChainId)),
350
+ repaymentAddress: some(relayerAddress.toV2Address()),
351
+ });
352
+ }
353
+
354
+ /**
355
+ * @param mint Address of the token corresponding to the account being made.
356
+ * @param relayer Address of the relayer filling the deposit.
357
+ * @returns An instruction for creating a new token account.
358
+ */
359
+ export function createTokenAccountsInstruction(
360
+ mint: SvmAddress,
361
+ relayer: TransactionSigner<string>
362
+ ): SvmSpokeClient.CreateTokenAccountsInstruction {
363
+ return SvmSpokeClient.getCreateTokenAccountsInstruction({
364
+ signer: relayer,
365
+ mint: mint.toV2Address(),
366
+ });
367
+ }
368
+
369
+ /**
370
+ * @param mint Address of the token corresponding to the account being made.
371
+ * @param amount Amount of the token to approve.
372
+ * @param relayer Address of the relayer filling the deposit.
373
+ * @param spokePool Address (program ID) of the SvmSpoke.
374
+ * @returns A token approval instruction.
375
+ */
376
+ export async function createApproveInstruction(
377
+ mint: SvmAddress,
378
+ amount: BigNumber,
379
+ relayer: SvmAddress,
380
+ spokePool: SvmAddress,
381
+ mintDecimals?: number
382
+ ) {
383
+ const [relayerTokenAccount, statePda] = await Promise.all([
384
+ getAssociatedTokenAddress(relayer, mint, TOKEN_PROGRAM_ADDRESS),
385
+ getStatePda(spokePool.toV2Address()),
386
+ ]);
387
+
388
+ // If no mint decimals were supplied, then assign it to whatever value we have in TOKEN_SYMBOLS_MAP.
389
+ // If this token is not in TOKEN_SYMBOLS_MAP, then throw an error.
390
+ mintDecimals ??= getTokenInfo(mint.toBase58(), CHAIN_IDs.SOLANA)?.decimals;
391
+ if (!isDefined(mintDecimals)) {
392
+ throw new Error(`No mint decimals found for token ${mint.toBase58()}`);
393
+ }
394
+
395
+ return getApproveCheckedInstruction({
396
+ source: relayerTokenAccount,
397
+ mint: mint.toV2Address(),
398
+ delegate: statePda,
399
+ owner: relayer.toV2Address(),
400
+ amount: amount.toBigInt(),
401
+ decimals: mintDecimals,
402
+ });
403
+ }
404
+
405
+ export async function getAssociatedTokenAddress(
406
+ owner: SvmAddress,
407
+ mint: SvmAddress,
408
+ tokenProgramId: Address<string> = TOKEN_PROGRAM_ADDRESS
409
+ ): Promise<Address<string>> {
410
+ const [associatedToken] = await getProgramDerivedAddress({
411
+ programAddress: ASSOCIATED_TOKEN_PROGRAM_ADDRESS,
412
+ seeds: [owner.toBuffer(), SvmAddress.from(tokenProgramId).toBuffer(), mint.toBuffer()],
413
+ });
414
+ return associatedToken;
415
+ }
416
+
417
+ export function getRelayDataHash(relayData: RelayData, destinationChainId: number): string {
418
+ const addressEncoder = getAddressEncoder();
419
+ const uint64Encoder = getU64Encoder();
420
+ const uint32Encoder = getU32Encoder();
421
+
422
+ assert(relayData.message.startsWith("0x"), "Message must be a hex string");
423
+
424
+ const contentToHash = Buffer.concat([
425
+ Uint8Array.from(addressEncoder.encode(SvmAddress.from(relayData.depositor, "base16").toV2Address())),
426
+ Uint8Array.from(addressEncoder.encode(SvmAddress.from(relayData.recipient, "base16").toV2Address())),
427
+ Uint8Array.from(addressEncoder.encode(SvmAddress.from(relayData.exclusiveRelayer, "base16").toV2Address())),
428
+ Uint8Array.from(addressEncoder.encode(SvmAddress.from(relayData.inputToken, "base16").toV2Address())),
429
+ Uint8Array.from(addressEncoder.encode(SvmAddress.from(relayData.outputToken, "base16").toV2Address())),
430
+ Uint8Array.from(uint64Encoder.encode(BigInt(relayData.inputAmount.toString()))),
431
+ Uint8Array.from(uint64Encoder.encode(BigInt(relayData.outputAmount.toString()))),
432
+ Uint8Array.from(uint64Encoder.encode(BigInt(relayData.originChainId.toString()))),
433
+ arrayify(hexZeroPad(hexlify(relayData.depositId), 32)),
434
+ Uint8Array.from(uint32Encoder.encode(relayData.fillDeadline)),
435
+ Uint8Array.from(uint32Encoder.encode(relayData.exclusivityDeadline)),
436
+ hashNonEmptyMessage(Buffer.from(arrayify(relayData.message))),
437
+ Uint8Array.from(uint64Encoder.encode(BigInt(destinationChainId))),
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,2 @@
1
+ export { SYSTEM_PROGRAM_ADDRESS as SVM_DEFAULT_ADDRESS } from "@solana-program/system";
2
+ export const SVM_SPOKE_SEED = BigInt(0);