@chainlink/ccip-sdk 0.0.0 → 0.90.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 (319) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +109 -0
  3. package/dist/aptos/exec.d.ts +18 -0
  4. package/dist/aptos/exec.d.ts.map +1 -0
  5. package/dist/aptos/exec.js +55 -0
  6. package/dist/aptos/exec.js.map +1 -0
  7. package/dist/aptos/hasher.d.ts +11 -0
  8. package/dist/aptos/hasher.d.ts.map +1 -0
  9. package/dist/aptos/hasher.js +62 -0
  10. package/dist/aptos/hasher.js.map +1 -0
  11. package/dist/aptos/index.d.ts +92 -0
  12. package/dist/aptos/index.d.ts.map +1 -0
  13. package/dist/aptos/index.js +482 -0
  14. package/dist/aptos/index.js.map +1 -0
  15. package/dist/aptos/logs.d.ts +9 -0
  16. package/dist/aptos/logs.d.ts.map +1 -0
  17. package/dist/aptos/logs.js +167 -0
  18. package/dist/aptos/logs.js.map +1 -0
  19. package/dist/aptos/send.d.ts +11 -0
  20. package/dist/aptos/send.d.ts.map +1 -0
  21. package/dist/aptos/send.js +78 -0
  22. package/dist/aptos/send.js.map +1 -0
  23. package/dist/aptos/token.d.ts +4 -0
  24. package/dist/aptos/token.d.ts.map +1 -0
  25. package/dist/aptos/token.js +134 -0
  26. package/dist/aptos/token.js.map +1 -0
  27. package/dist/aptos/types.d.ts +78 -0
  28. package/dist/aptos/types.d.ts.map +1 -0
  29. package/dist/aptos/types.js +60 -0
  30. package/dist/aptos/types.js.map +1 -0
  31. package/dist/aptos/utils.d.ts +12 -0
  32. package/dist/aptos/utils.d.ts.map +1 -0
  33. package/dist/aptos/utils.js +15 -0
  34. package/dist/aptos/utils.js.map +1 -0
  35. package/dist/chain.d.ts +344 -0
  36. package/dist/chain.d.ts.map +1 -0
  37. package/dist/chain.js +41 -0
  38. package/dist/chain.js.map +1 -0
  39. package/dist/commits.d.ts +25 -0
  40. package/dist/commits.d.ts.map +1 -0
  41. package/dist/commits.js +29 -0
  42. package/dist/commits.js.map +1 -0
  43. package/dist/evm/abi/BurnMintERC677Token.d.ts +602 -0
  44. package/dist/evm/abi/BurnMintERC677Token.d.ts.map +1 -0
  45. package/dist/evm/abi/BurnMintERC677Token.js +488 -0
  46. package/dist/evm/abi/BurnMintERC677Token.js.map +1 -0
  47. package/dist/evm/abi/CommitStore_1_2.d.ts +688 -0
  48. package/dist/evm/abi/CommitStore_1_2.d.ts.map +1 -0
  49. package/dist/evm/abi/CommitStore_1_2.js +638 -0
  50. package/dist/evm/abi/CommitStore_1_2.js.map +1 -0
  51. package/dist/evm/abi/CommitStore_1_5.d.ts +708 -0
  52. package/dist/evm/abi/CommitStore_1_5.d.ts.map +1 -0
  53. package/dist/evm/abi/CommitStore_1_5.js +675 -0
  54. package/dist/evm/abi/CommitStore_1_5.js.map +1 -0
  55. package/dist/evm/abi/FeeQuoter_1_6.d.ts +1770 -0
  56. package/dist/evm/abi/FeeQuoter_1_6.d.ts.map +1 -0
  57. package/dist/evm/abi/FeeQuoter_1_6.js +1904 -0
  58. package/dist/evm/abi/FeeQuoter_1_6.js.map +1 -0
  59. package/dist/evm/abi/LockReleaseTokenPool_1_5.d.ts +1116 -0
  60. package/dist/evm/abi/LockReleaseTokenPool_1_5.d.ts.map +1 -0
  61. package/dist/evm/abi/LockReleaseTokenPool_1_5.js +1096 -0
  62. package/dist/evm/abi/LockReleaseTokenPool_1_5.js.map +1 -0
  63. package/dist/evm/abi/LockReleaseTokenPool_1_5_1.d.ts +1306 -0
  64. package/dist/evm/abi/LockReleaseTokenPool_1_5_1.d.ts.map +1 -0
  65. package/dist/evm/abi/LockReleaseTokenPool_1_5_1.js +1278 -0
  66. package/dist/evm/abi/LockReleaseTokenPool_1_5_1.js.map +1 -0
  67. package/dist/evm/abi/LockReleaseTokenPool_1_6_1.d.ts +1290 -0
  68. package/dist/evm/abi/LockReleaseTokenPool_1_6_1.d.ts.map +1 -0
  69. package/dist/evm/abi/LockReleaseTokenPool_1_6_1.js +1288 -0
  70. package/dist/evm/abi/LockReleaseTokenPool_1_6_1.js.map +1 -0
  71. package/dist/evm/abi/OffRamp_1_2.d.ts +1217 -0
  72. package/dist/evm/abi/OffRamp_1_2.d.ts.map +1 -0
  73. package/dist/evm/abi/OffRamp_1_2.js +1204 -0
  74. package/dist/evm/abi/OffRamp_1_2.js.map +1 -0
  75. package/dist/evm/abi/OffRamp_1_5.d.ts +1271 -0
  76. package/dist/evm/abi/OffRamp_1_5.d.ts.map +1 -0
  77. package/dist/evm/abi/OffRamp_1_5.js +1273 -0
  78. package/dist/evm/abi/OffRamp_1_5.js.map +1 -0
  79. package/dist/evm/abi/OffRamp_1_6.d.ts +1472 -0
  80. package/dist/evm/abi/OffRamp_1_6.d.ts.map +1 -0
  81. package/dist/evm/abi/OffRamp_1_6.js +1529 -0
  82. package/dist/evm/abi/OffRamp_1_6.js.map +1 -0
  83. package/dist/evm/abi/OnRamp_1_2.d.ts +1391 -0
  84. package/dist/evm/abi/OnRamp_1_2.d.ts.map +1 -0
  85. package/dist/evm/abi/OnRamp_1_2.js +1343 -0
  86. package/dist/evm/abi/OnRamp_1_2.js.map +1 -0
  87. package/dist/evm/abi/OnRamp_1_5.d.ts +1443 -0
  88. package/dist/evm/abi/OnRamp_1_5.d.ts.map +1 -0
  89. package/dist/evm/abi/OnRamp_1_5.js +1427 -0
  90. package/dist/evm/abi/OnRamp_1_5.js.map +1 -0
  91. package/dist/evm/abi/OnRamp_1_6.d.ts +796 -0
  92. package/dist/evm/abi/OnRamp_1_6.d.ts.map +1 -0
  93. package/dist/evm/abi/OnRamp_1_6.js +880 -0
  94. package/dist/evm/abi/OnRamp_1_6.js.map +1 -0
  95. package/dist/evm/abi/Router.d.ts +541 -0
  96. package/dist/evm/abi/Router.d.ts.map +1 -0
  97. package/dist/evm/abi/Router.js +508 -0
  98. package/dist/evm/abi/Router.js.map +1 -0
  99. package/dist/evm/abi/TokenAdminRegistry_1_5.d.ts +373 -0
  100. package/dist/evm/abi/TokenAdminRegistry_1_5.d.ts.map +1 -0
  101. package/dist/evm/abi/TokenAdminRegistry_1_5.js +333 -0
  102. package/dist/evm/abi/TokenAdminRegistry_1_5.js.map +1 -0
  103. package/dist/evm/const.d.ts +27 -0
  104. package/dist/evm/const.d.ts.map +1 -0
  105. package/dist/evm/const.js +63 -0
  106. package/dist/evm/const.js.map +1 -0
  107. package/dist/evm/errors.d.ts +36 -0
  108. package/dist/evm/errors.d.ts.map +1 -0
  109. package/dist/evm/errors.js +192 -0
  110. package/dist/evm/errors.js.map +1 -0
  111. package/dist/evm/hasher.d.ts +5 -0
  112. package/dist/evm/hasher.d.ts.map +1 -0
  113. package/dist/evm/hasher.js +116 -0
  114. package/dist/evm/hasher.js.map +1 -0
  115. package/dist/evm/index.d.ts +121 -0
  116. package/dist/evm/index.d.ts.map +1 -0
  117. package/dist/evm/index.js +904 -0
  118. package/dist/evm/index.js.map +1 -0
  119. package/dist/evm/messages.d.ts +35 -0
  120. package/dist/evm/messages.d.ts.map +1 -0
  121. package/dist/evm/messages.js +11 -0
  122. package/dist/evm/messages.js.map +1 -0
  123. package/dist/evm/offchain.d.ts +16 -0
  124. package/dist/evm/offchain.d.ts.map +1 -0
  125. package/dist/evm/offchain.js +142 -0
  126. package/dist/evm/offchain.js.map +1 -0
  127. package/dist/execution.d.ts +80 -0
  128. package/dist/execution.d.ts.map +1 -0
  129. package/dist/execution.js +91 -0
  130. package/dist/execution.js.map +1 -0
  131. package/dist/extra-args.d.ts +45 -0
  132. package/dist/extra-args.d.ts.map +1 -0
  133. package/dist/extra-args.js +44 -0
  134. package/dist/extra-args.js.map +1 -0
  135. package/dist/gas.d.ts +27 -0
  136. package/dist/gas.d.ts.map +1 -0
  137. package/dist/gas.js +80 -0
  138. package/dist/gas.js.map +1 -0
  139. package/dist/hasher/common.d.ts +12 -0
  140. package/dist/hasher/common.d.ts.map +1 -0
  141. package/dist/hasher/common.js +19 -0
  142. package/dist/hasher/common.js.map +1 -0
  143. package/dist/hasher/hasher.d.ts +4 -0
  144. package/dist/hasher/hasher.d.ts.map +1 -0
  145. package/dist/hasher/hasher.js +11 -0
  146. package/dist/hasher/hasher.js.map +1 -0
  147. package/dist/hasher/index.d.ts +4 -0
  148. package/dist/hasher/index.d.ts.map +1 -0
  149. package/dist/hasher/index.js +4 -0
  150. package/dist/hasher/index.js.map +1 -0
  151. package/dist/hasher/merklemulti.d.ts +58 -0
  152. package/dist/hasher/merklemulti.d.ts.map +1 -0
  153. package/dist/hasher/merklemulti.js +257 -0
  154. package/dist/hasher/merklemulti.js.map +1 -0
  155. package/dist/index.d.ts +13 -0
  156. package/dist/index.d.ts.map +1 -0
  157. package/dist/index.js +13 -0
  158. package/dist/index.js.map +1 -0
  159. package/dist/offchain.d.ts +20 -0
  160. package/dist/offchain.d.ts.map +1 -0
  161. package/dist/offchain.js +59 -0
  162. package/dist/offchain.js.map +1 -0
  163. package/dist/requests.d.ts +48 -0
  164. package/dist/requests.d.ts.map +1 -0
  165. package/dist/requests.js +286 -0
  166. package/dist/requests.js.map +1 -0
  167. package/dist/selectors.d.ts +9 -0
  168. package/dist/selectors.d.ts.map +1 -0
  169. package/dist/selectors.js +1330 -0
  170. package/dist/selectors.js.map +1 -0
  171. package/dist/solana/cleanup.d.ts +15 -0
  172. package/dist/solana/cleanup.d.ts.map +1 -0
  173. package/dist/solana/cleanup.js +159 -0
  174. package/dist/solana/cleanup.js.map +1 -0
  175. package/dist/solana/exec.d.ts +15 -0
  176. package/dist/solana/exec.d.ts.map +1 -0
  177. package/dist/solana/exec.js +417 -0
  178. package/dist/solana/exec.js.map +1 -0
  179. package/dist/solana/hasher.d.ts +4 -0
  180. package/dist/solana/hasher.d.ts.map +1 -0
  181. package/dist/solana/hasher.js +81 -0
  182. package/dist/solana/hasher.js.map +1 -0
  183. package/dist/solana/idl/1.6.0/BASE_TOKEN_POOL.d.ts +866 -0
  184. package/dist/solana/idl/1.6.0/BASE_TOKEN_POOL.d.ts.map +1 -0
  185. package/dist/solana/idl/1.6.0/BASE_TOKEN_POOL.js +866 -0
  186. package/dist/solana/idl/1.6.0/BASE_TOKEN_POOL.js.map +1 -0
  187. package/dist/solana/idl/1.6.0/BURN_MINT_TOKEN_POOL.d.ts +949 -0
  188. package/dist/solana/idl/1.6.0/BURN_MINT_TOKEN_POOL.d.ts.map +1 -0
  189. package/dist/solana/idl/1.6.0/BURN_MINT_TOKEN_POOL.js +949 -0
  190. package/dist/solana/idl/1.6.0/BURN_MINT_TOKEN_POOL.js.map +1 -0
  191. package/dist/solana/idl/1.6.0/CCIP_CCTP_TOKEN_POOL.d.ts +1374 -0
  192. package/dist/solana/idl/1.6.0/CCIP_CCTP_TOKEN_POOL.d.ts.map +1 -0
  193. package/dist/solana/idl/1.6.0/CCIP_CCTP_TOKEN_POOL.js +1374 -0
  194. package/dist/solana/idl/1.6.0/CCIP_CCTP_TOKEN_POOL.js.map +1 -0
  195. package/dist/solana/idl/1.6.0/CCIP_COMMON.d.ts +104 -0
  196. package/dist/solana/idl/1.6.0/CCIP_COMMON.d.ts.map +1 -0
  197. package/dist/solana/idl/1.6.0/CCIP_COMMON.js +104 -0
  198. package/dist/solana/idl/1.6.0/CCIP_COMMON.js.map +1 -0
  199. package/dist/solana/idl/1.6.0/CCIP_OFFRAMP.d.ts +2746 -0
  200. package/dist/solana/idl/1.6.0/CCIP_OFFRAMP.d.ts.map +1 -0
  201. package/dist/solana/idl/1.6.0/CCIP_OFFRAMP.js +2746 -0
  202. package/dist/solana/idl/1.6.0/CCIP_OFFRAMP.js.map +1 -0
  203. package/dist/solana/idl/1.6.0/CCIP_ROUTER.d.ts +2332 -0
  204. package/dist/solana/idl/1.6.0/CCIP_ROUTER.d.ts.map +1 -0
  205. package/dist/solana/idl/1.6.0/CCIP_ROUTER.js +2332 -0
  206. package/dist/solana/idl/1.6.0/CCIP_ROUTER.js.map +1 -0
  207. package/dist/solana/index.d.ts +205 -0
  208. package/dist/solana/index.d.ts.map +1 -0
  209. package/dist/solana/index.js +1085 -0
  210. package/dist/solana/index.js.map +1 -0
  211. package/dist/solana/offchain.d.ts +31 -0
  212. package/dist/solana/offchain.d.ts.map +1 -0
  213. package/dist/solana/offchain.js +152 -0
  214. package/dist/solana/offchain.js.map +1 -0
  215. package/dist/solana/patchBorsh.d.ts +2 -0
  216. package/dist/solana/patchBorsh.d.ts.map +1 -0
  217. package/dist/solana/patchBorsh.js +60 -0
  218. package/dist/solana/patchBorsh.js.map +1 -0
  219. package/dist/solana/send.d.ts +14 -0
  220. package/dist/solana/send.d.ts.map +1 -0
  221. package/dist/solana/send.js +272 -0
  222. package/dist/solana/send.js.map +1 -0
  223. package/dist/solana/types.d.ts +4 -0
  224. package/dist/solana/types.d.ts.map +1 -0
  225. package/dist/solana/types.js +2 -0
  226. package/dist/solana/types.js.map +1 -0
  227. package/dist/solana/utils.d.ts +58 -0
  228. package/dist/solana/utils.d.ts.map +1 -0
  229. package/dist/solana/utils.js +211 -0
  230. package/dist/solana/utils.js.map +1 -0
  231. package/dist/sui/hasher.d.ts +12 -0
  232. package/dist/sui/hasher.d.ts.map +1 -0
  233. package/dist/sui/hasher.js +63 -0
  234. package/dist/sui/hasher.js.map +1 -0
  235. package/dist/sui/index.d.ts +72 -0
  236. package/dist/sui/index.d.ts.map +1 -0
  237. package/dist/sui/index.js +128 -0
  238. package/dist/sui/index.js.map +1 -0
  239. package/dist/sui/types.d.ts +17 -0
  240. package/dist/sui/types.d.ts.map +1 -0
  241. package/dist/sui/types.js +17 -0
  242. package/dist/sui/types.js.map +1 -0
  243. package/dist/supported-chains.d.ts +5 -0
  244. package/dist/supported-chains.d.ts.map +1 -0
  245. package/dist/supported-chains.js +3 -0
  246. package/dist/supported-chains.js.map +1 -0
  247. package/dist/types.d.ts +118 -0
  248. package/dist/types.d.ts.map +1 -0
  249. package/dist/types.js +11 -0
  250. package/dist/types.js.map +1 -0
  251. package/dist/utils.d.ts +117 -0
  252. package/dist/utils.d.ts.map +1 -0
  253. package/dist/utils.js +336 -0
  254. package/dist/utils.js.map +1 -0
  255. package/package.json +66 -8
  256. package/src/aptos/exec.ts +69 -0
  257. package/src/aptos/hasher.ts +92 -0
  258. package/src/aptos/index.ts +660 -0
  259. package/src/aptos/logs.ts +210 -0
  260. package/src/aptos/send.ts +120 -0
  261. package/src/aptos/token.ts +150 -0
  262. package/src/aptos/types.ts +85 -0
  263. package/src/aptos/utils.ts +24 -0
  264. package/src/chain.ts +398 -0
  265. package/src/commits.ts +44 -0
  266. package/src/evm/abi/BurnMintERC677Token.ts +487 -0
  267. package/src/evm/abi/CommitStore_1_2.ts +637 -0
  268. package/src/evm/abi/CommitStore_1_5.ts +674 -0
  269. package/src/evm/abi/FeeQuoter_1_6.ts +1903 -0
  270. package/src/evm/abi/LockReleaseTokenPool_1_5.ts +1095 -0
  271. package/src/evm/abi/LockReleaseTokenPool_1_5_1.ts +1277 -0
  272. package/src/evm/abi/LockReleaseTokenPool_1_6_1.ts +1287 -0
  273. package/src/evm/abi/OffRamp_1_2.ts +1203 -0
  274. package/src/evm/abi/OffRamp_1_5.ts +1272 -0
  275. package/src/evm/abi/OffRamp_1_6.ts +1528 -0
  276. package/src/evm/abi/OnRamp_1_2.ts +1342 -0
  277. package/src/evm/abi/OnRamp_1_5.ts +1426 -0
  278. package/src/evm/abi/OnRamp_1_6.ts +879 -0
  279. package/src/evm/abi/Router.ts +507 -0
  280. package/src/evm/abi/TokenAdminRegistry_1_5.ts +332 -0
  281. package/src/evm/const.ts +69 -0
  282. package/src/evm/errors.ts +212 -0
  283. package/src/evm/hasher.ts +166 -0
  284. package/src/evm/index.ts +1262 -0
  285. package/src/evm/messages.ts +73 -0
  286. package/src/evm/offchain.ts +189 -0
  287. package/src/execution.ts +131 -0
  288. package/src/extra-args.ts +71 -0
  289. package/src/gas.ts +135 -0
  290. package/src/hasher/common.ts +23 -0
  291. package/src/hasher/hasher.ts +12 -0
  292. package/src/hasher/index.ts +3 -0
  293. package/src/hasher/merklemulti.ts +309 -0
  294. package/src/index.ts +51 -0
  295. package/src/offchain.ts +86 -0
  296. package/src/requests.ts +339 -0
  297. package/src/selectors.ts +1340 -0
  298. package/src/solana/cleanup.ts +216 -0
  299. package/src/solana/exec.ts +645 -0
  300. package/src/solana/hasher.ts +104 -0
  301. package/src/solana/idl/1.6.0/BASE_TOKEN_POOL.ts +1734 -0
  302. package/src/solana/idl/1.6.0/BURN_MINT_TOKEN_POOL.ts +1900 -0
  303. package/src/solana/idl/1.6.0/CCIP_CCTP_TOKEN_POOL.ts +2750 -0
  304. package/src/solana/idl/1.6.0/CCIP_COMMON.ts +210 -0
  305. package/src/solana/idl/1.6.0/CCIP_OFFRAMP.ts +5494 -0
  306. package/src/solana/idl/1.6.0/CCIP_ROUTER.ts +4671 -0
  307. package/src/solana/index.ts +1454 -0
  308. package/src/solana/offchain.ts +209 -0
  309. package/src/solana/patchBorsh.ts +67 -0
  310. package/src/solana/send.ts +436 -0
  311. package/src/solana/types.ts +6 -0
  312. package/src/solana/utils.ts +272 -0
  313. package/src/sui/hasher.ts +90 -0
  314. package/src/sui/index.ts +198 -0
  315. package/src/sui/types.ts +22 -0
  316. package/src/supported-chains.ts +4 -0
  317. package/src/types.ts +153 -0
  318. package/src/utils.ts +405 -0
  319. package/tsconfig.json +18 -0
package/src/chain.ts ADDED
@@ -0,0 +1,398 @@
1
+ import util from 'util'
2
+
3
+ import type { BytesLike } from 'ethers'
4
+
5
+ import { fetchCommitReport } from './commits.ts'
6
+ import { fetchExecutionReceipts } from './execution.ts'
7
+ import type {
8
+ EVMExtraArgsV1,
9
+ EVMExtraArgsV2,
10
+ ExtraArgs,
11
+ SVMExtraArgsV1,
12
+ SuiExtraArgsV1,
13
+ } from './extra-args.ts'
14
+ import type { LeafHasher } from './hasher/common.ts'
15
+ import type {
16
+ AnyMessage,
17
+ CCIPCommit,
18
+ CCIPExecution,
19
+ CCIPMessage,
20
+ CCIPRequest,
21
+ CommitReport,
22
+ ExecutionReceipt,
23
+ ExecutionReport,
24
+ Lane,
25
+ Log_,
26
+ NetworkInfo,
27
+ OffchainTokenData,
28
+ } from './types.ts'
29
+
30
+ export const ChainFamily = {
31
+ EVM: 'evm',
32
+ Solana: 'solana',
33
+ Aptos: 'aptos',
34
+ Sui: 'sui',
35
+ } as const
36
+ export type ChainFamily = (typeof ChainFamily)[keyof typeof ChainFamily]
37
+
38
+ export type LogFilter = {
39
+ startBlock?: number
40
+ startTime?: number
41
+ endBlock?: number
42
+ endBefore?: string
43
+ address?: string
44
+ topics?: string[] | string[][]
45
+ page?: number
46
+ }
47
+
48
+ export type ChainTransaction = {
49
+ chain: Chain
50
+ hash: string
51
+ logs: readonly Log_[]
52
+ blockNumber: number
53
+ timestamp: number
54
+ from: string
55
+ error?: unknown
56
+ }
57
+
58
+ export type TokenInfo = {
59
+ readonly symbol: string
60
+ readonly decimals: number
61
+ readonly name?: string
62
+ }
63
+
64
+ export type RateLimiterState = {
65
+ tokens: bigint
66
+ capacity: bigint
67
+ rate: bigint
68
+ } | null
69
+
70
+ export type TokenPoolRemote = {
71
+ remoteToken: string
72
+ remotePools: string[]
73
+ inboundRateLimiterState: RateLimiterState
74
+ outboundRateLimiterState: RateLimiterState
75
+ }
76
+
77
+ /**
78
+ * Works like an interface for a base Chain class, but provides implementation (which can be
79
+ * specialized) for some basic methods
80
+ */
81
+ export abstract class Chain<F extends ChainFamily = ChainFamily> {
82
+ abstract readonly network: NetworkInfo<F>
83
+ abstract destroy?(): Promise<void>
84
+
85
+ [util.inspect.custom]() {
86
+ return `${this.constructor.name} { ${this.network.name} }`
87
+ }
88
+
89
+ /**
90
+ * Fetch the timestamp of a given block
91
+ * @param block - block number or 'finalized'
92
+ * @returns timestamp of the block, in seconds
93
+ */
94
+ abstract getBlockTimestamp(block: number | 'finalized'): Promise<number>
95
+ /**
96
+ * Fetch a transaction by its hash
97
+ * @param hash - transaction hash
98
+ * @returns generic transaction details
99
+ */
100
+ abstract getTransaction(hash: string): Promise<ChainTransaction>
101
+ /**
102
+ * An async generator that yields logs based on the provided options.
103
+ * @param opts - options object
104
+ * @param opts.startBlock - if provided, fetch and generate logs forward starting from this block;
105
+ * otherwise, returns logs backwards in time from endBlock;
106
+ * optionally, startTime may be provided to fetch logs forward starting from this time;
107
+ * @param opts.endBlock - if omitted, use latest block
108
+ * @param opts.endBefore - optional hint signature for end of iteration, instead of endBlock
109
+ * @param opts.address - if provided, fetch logs for this address only (may be required in some
110
+ * networks/implementations)
111
+ * @param opts.topics - if provided, fetch logs for these topics only;
112
+ * if string[], it's assumed to be a list of topic0s (i.e. string[] or string[][0], event_ids);
113
+ * some networks/implementations may not be able to filter topics other than topic0s, so one may
114
+ * want to assume those are optimization hints, instead of hard filters, and verify results
115
+ * @param opts.page - if provided, try to use this page/range for batches
116
+ * @returns an async iterable iterator of logs
117
+ */
118
+ abstract getLogs(opts: LogFilter): AsyncIterableIterator<Log_>
119
+ /**
120
+ * Fetch the typeAndVersion tag of a given CCIP contract
121
+ * @param address - CCIP contract address
122
+ * @returns typeAndVersion tag, validated and split
123
+ */
124
+ abstract typeAndVersion(
125
+ address: string,
126
+ ): Promise<
127
+ | [type_: string, version: string, typeAndVersion: string]
128
+ | [type_: string, version: string, typeAndVersion: string, suffix: string]
129
+ >
130
+
131
+ /**
132
+ * Fetch the Router address set in OnRamp config
133
+ * Used to discover OffRamp connected to OnRamp
134
+ * @param onRamp - OnRamp contract address
135
+ * @param destChainSelector - destination chain selector
136
+ * @returns Router address
137
+ */
138
+ abstract getRouterForOnRamp(onRamp: string, destChainSelector: bigint): Promise<string>
139
+ /**
140
+ * Fetch the Router address set in OffRamp config
141
+ * @param offRamp - OffRamp contract address
142
+ * @param sourceChainSelector - source chain selector
143
+ * @returns Router address
144
+ */
145
+ abstract getRouterForOffRamp(offRamp: string, sourceChainSelector: bigint): Promise<string>
146
+ /**
147
+ * Get the native token address for a Router
148
+ * @param router - router contract address
149
+ * @returns native token address (usually wrapped)
150
+ */
151
+ abstract getNativeTokenForRouter(router: string): Promise<string>
152
+ /**
153
+ * Fetch the OffRamps allowlisted in a Router
154
+ * Used to discover OffRamp connected to an OnRamp
155
+ * @param router - Router contract address
156
+ * @param sourceChainSelector - source chain selector
157
+ * @returns array of OffRamp addresses
158
+ */
159
+ abstract getOffRampsForRouter(router: string, sourceChainSelector: bigint): Promise<string[]>
160
+ /**
161
+ * Fetch the OnRamp registered in a Router for a destination chain
162
+ * @param router - Router contract address
163
+ * @param destChainSelector - destination chain selector
164
+ * @returns OnRamp addresses
165
+ */
166
+ abstract getOnRampForRouter(router: string, destChainSelector: bigint): Promise<string>
167
+ /**
168
+ * Fetch the OnRamp address set in OffRamp config
169
+ * Used to discover OffRamp connected to an OnRamp
170
+ * @param offRamp - OffRamp contract address
171
+ * @param sourceChainSelector - source chain selector
172
+ * @returns OnRamp address
173
+ */
174
+ abstract getOnRampForOffRamp(offRamp: string, sourceChainSelector: bigint): Promise<string>
175
+ /**
176
+ * Fetch the CommitStore set in OffRamp config (CCIP<=v1.5)
177
+ * For CCIP>=v1.6, it should return the offRamp address
178
+ * @param offRamp - OffRamp contract address
179
+ * @returns CommitStore address
180
+ */
181
+ abstract getCommitStoreForOffRamp(offRamp: string): Promise<string>
182
+ /**
183
+ * Fetch the TokenPool's token/mint
184
+ * @param tokenPool - TokenPool address
185
+ * @returns Token or mint address
186
+ */
187
+ abstract getTokenForTokenPool(tokenPool: string): Promise<string>
188
+ /**
189
+ * Fetch token metadata
190
+ * @param token - Token address
191
+ * @returns Token symbol and decimals, and optionally name
192
+ */
193
+ abstract getTokenInfo(token: string): Promise<TokenInfo>
194
+ /**
195
+ * Fetch TokenAdminRegistry configured in a given OnRamp, Router, etc
196
+ * Needed to map a source token to its dest counterparts
197
+ * @param onRamp - Some contract for which we can fetch a TokenAdminRegistry
198
+ */
199
+ abstract getTokenAdminRegistryFor(address: string): Promise<string>
200
+ /**
201
+ * Build, derive, load or fetch a wallet for this instance which will be used in any tx send operation
202
+ * @param opts.wallet - cli or environmental parameters to help pick a wallet
203
+ * @returns address of fetched (and stored internally) account
204
+ */
205
+ abstract getWalletAddress(opts?: { wallet?: unknown }): Promise<string>
206
+ /**
207
+ * Fetch the current fee for a given intended message
208
+ * @param router - router address on this chain
209
+ * @param destChainSelector - dest network selector
210
+ * @param message - message to send
211
+ */
212
+ abstract getFee(router: string, destChainSelector: bigint, message: AnyMessage): Promise<bigint>
213
+ /**
214
+ * Send a CCIP message through a router using loaded wallet
215
+ * @param router - router address on this chain
216
+ * @param destChainSelector - dest network selector
217
+ * @param message - message to send
218
+ * @param opts.wallet - cli or environmental parameters to help pick a wallet
219
+ * @param opts.approveMax - approve the maximum amount of tokens to transfer
220
+ */
221
+ abstract sendMessage(
222
+ router: string,
223
+ destChainSelector: bigint,
224
+ message: AnyMessage & { fee: bigint },
225
+ opts?: { wallet?: unknown; approveMax?: boolean },
226
+ ): Promise<ChainTransaction>
227
+ /**
228
+ * Fetch supported offchain token data for a request from this network
229
+ * @param request - CCIP request, with tx, logs and message
230
+ * @returns array with one offchain token data for each token transfer in request
231
+ */
232
+ abstract fetchOffchainTokenData(request: CCIPRequest): Promise<OffchainTokenData[]>
233
+ /**
234
+ * Execute messages in report in an offRamp
235
+ * @param offRamp - offRamp address on this dest chain
236
+ * @param execReport - execution report containing messages to execute, proofs and offchainTokenData
237
+ * @param opts - general options for execution
238
+ * @returns transaction hash of the execution
239
+ */
240
+ abstract executeReport(
241
+ offRamp: string,
242
+ execReport: ExecutionReport,
243
+ opts?: Record<string, unknown>,
244
+ ): Promise<ChainTransaction>
245
+
246
+ /**
247
+ * Look for a CommitReport at dest for given CCIP request
248
+ * May be specialized by some subclasses
249
+ *
250
+ * @param dest - Destination network provider
251
+ * @param request - CCIP request info
252
+ * @param hints - Additional filtering hints
253
+ * @returns CCIP commit info
254
+ **/
255
+ async fetchCommitReport(
256
+ commitStore: string,
257
+ request: {
258
+ lane: Lane
259
+ message: { header: { sequenceNumber: bigint } }
260
+ timestamp?: number
261
+ },
262
+ hints?: { startBlock?: number; page?: number },
263
+ ): Promise<CCIPCommit> {
264
+ return fetchCommitReport(this, commitStore, request, hints)
265
+ }
266
+
267
+ /**
268
+ * Default/generic implementation of fetchExecutionReceipts
269
+ * @param offRamp - Off-ramp address
270
+ * @param messageIds - Set of message IDs to fetch receipts for
271
+ * @param hints - Additional filtering hints
272
+ * @returns Async generator of CCIP execution receipts
273
+ */
274
+ async *fetchExecutionReceipts(
275
+ offRamp: string,
276
+ messageIds: Set<string>,
277
+ hints?: { startBlock?: number; startTime?: number; page?: number; commit?: CommitReport },
278
+ ): AsyncGenerator<CCIPExecution> {
279
+ yield* fetchExecutionReceipts(this, offRamp, messageIds, hints)
280
+ }
281
+
282
+ /**
283
+ * List tokens supported by given TokenAdminRegistry contract
284
+ * @param address - Usually TokenAdminRegistry, but chain may support receiving Router, OnRamp, etc
285
+ * @param opts.page - Page range, if needed
286
+ * @retursn array of supported token addresses
287
+ */
288
+ abstract getSupportedTokens(address: string, opts?: { page?: number }): Promise<string[]>
289
+
290
+ /**
291
+ * Get TokenConfig for a given token address in a TokenAdminRegistry
292
+ * @param address - TokenAdminRegistry contract address
293
+ * @param token - Token address
294
+ */
295
+ abstract getRegistryTokenConfig(
296
+ registry: string,
297
+ token: string,
298
+ ): Promise<{
299
+ administrator: string
300
+ pendingAdministrator?: string
301
+ tokenPool?: string
302
+ }>
303
+
304
+ /**
305
+ * Get TokenPool state and configurations
306
+ * @param tokenPool - Token pool address
307
+ */
308
+ abstract getTokenPoolConfigs(tokenPool: string): Promise<{
309
+ token: string
310
+ router: string
311
+ typeAndVersion?: string
312
+ }>
313
+
314
+ /**
315
+ * Get TokenPool remote configurations
316
+ * @param tokenPool - Token pool address
317
+ * @param remoteChainSelector - If provided, only return remotes for the specified chain (may error if remote not supported)
318
+ * @param Record of network *names* and remote configurations (remoteToken, remotePools, rateLimitStates)
319
+ */
320
+ abstract getTokenPoolRemotes(
321
+ tokenPool: string,
322
+ remoteChainSelector?: bigint,
323
+ ): Promise<Record<string, TokenPoolRemote>>
324
+
325
+ /**
326
+ * Fetch list and info of supported feeTokens
327
+ * @param router address on this chain
328
+ * @returns mapping of token addresses to respective TokenInfo objects
329
+ */
330
+ abstract listFeeTokens(router: string): Promise<Record<string, TokenInfo>>
331
+ }
332
+
333
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
334
+ export type ChainStatic<F extends ChainFamily = ChainFamily> = Function & {
335
+ readonly family: F
336
+ readonly decimals: number
337
+ /**
338
+ * async constructor: builds a Chain from a rpc endpoint url
339
+ * @param url - rpc endpoint url
340
+ */
341
+ fromUrl(url: string): Promise<Chain<F>>
342
+ /**
343
+ * Try to decode a CCIP message *from* a log/event *originated* from this *source* chain,
344
+ * but which may *target* other dest chain families
345
+ * iow: the parsing is specific to this chain family, but content may be intended to alien chains
346
+ * e.g: EVM-born (abi.encoded) bytearray may output message.computeUnits for Solana
347
+ * @param log - Chain generic log
348
+ * @returns decoded CCIP message with merged extraArgs
349
+ */
350
+ decodeMessage(log: Pick<Log_, 'data'>): CCIPMessage | undefined
351
+ /**
352
+ * Try to decode an extraArgs array serialized for this chain family
353
+ * @param extraArgs - extra args bytes (Uint8Array, HexString or base64)
354
+ * @returns object containing decoded extraArgs and their tags
355
+ */
356
+ decodeExtraArgs(
357
+ extraArgs: BytesLike,
358
+ ):
359
+ | (EVMExtraArgsV1 & { _tag: 'EVMExtraArgsV1' })
360
+ | (EVMExtraArgsV2 & { _tag: 'EVMExtraArgsV2' })
361
+ | (SVMExtraArgsV1 & { _tag: 'SVMExtraArgsV1' })
362
+ | (SuiExtraArgsV1 & { _tag: 'SuiExtraArgsV1' })
363
+ | undefined
364
+ encodeExtraArgs(extraArgs: ExtraArgs): string
365
+ /**
366
+ * Decode a commit (CommitReportAccepted) event
367
+ * @param log - Chain generic log
368
+ * @param lane - if passed, filter or validate reports by lane
369
+ * @returns Array of commit reports contained in the log
370
+ */
371
+ decodeCommits(log: Pick<Log_, 'data'>, lane?: Lane): CommitReport[] | undefined
372
+ /**
373
+ * Decode a receipt (ExecutioStateChanged) event
374
+ * @param log - Chain generic log
375
+ * @returns ExecutionReceipt or undefined if not a recognized receipt
376
+ */
377
+ decodeReceipt(log: Pick<Log_, 'data'>): ExecutionReceipt | undefined
378
+ /**
379
+ * Receive a bytes array and try to decode and normalize it as an address of this chain family
380
+ * @param bytes - Bytes array (Uint8Array, HexString or Base64)
381
+ * @returns Address in this chain family's format
382
+ */
383
+ getAddress(bytes: BytesLike): string
384
+ /**
385
+ * Create a leaf hasher for this dest chain and lane
386
+ * @param lane - source, dest and onramp lane info
387
+ * @returns LeafHasher is a function that takes a message and returns a hash of it
388
+ */
389
+ getDestLeafHasher(lane: Lane): LeafHasher
390
+ /**
391
+ * Try to parse an error or bytearray generated by this chain family
392
+ * @param error - catched object, string or bytearray
393
+ * @returns Ordered record with messages/properties, or undefined if not a recognized error
394
+ */
395
+ parse?(data: unknown): Record<string, unknown> | undefined | null
396
+ }
397
+
398
+ export type ChainGetter = (idOrSelectorOrName: number | string | bigint) => Promise<Chain>
package/src/commits.ts ADDED
@@ -0,0 +1,44 @@
1
+ import type { Chain, ChainStatic } from './chain.ts'
2
+ import { type CCIPCommit, type Lane, CCIPVersion } from './types.ts'
3
+
4
+ /**
5
+ * Look for a CommitReport at dest for given CCIPRequest
6
+ * Provides a basic/generic implementation, but subclasses of Chain may override with more specific
7
+ * logic in Chain.fetchCommitReport method
8
+ *
9
+ * @param dest - Destination network provider
10
+ * @param request - CCIP request info
11
+ * @param hints - Additional filtering hints
12
+ * @returns CCIP commit info
13
+ **/
14
+ export async function fetchCommitReport(
15
+ dest: Chain,
16
+ commitStore: string,
17
+ {
18
+ lane,
19
+ message: { header },
20
+ timestamp: requestTimestamp,
21
+ }: {
22
+ lane: Lane
23
+ message: { header: { sequenceNumber: bigint } }
24
+ timestamp?: number
25
+ },
26
+ hints?: { startBlock?: number; page?: number },
27
+ ): Promise<CCIPCommit> {
28
+ for await (const log of dest.getLogs({
29
+ ...hints,
30
+ ...(!hints?.startBlock ? { startTime: requestTimestamp } : { startBlock: hints.startBlock }),
31
+ address: commitStore,
32
+ topics: [lane.version < CCIPVersion.V1_6 ? 'ReportAccepted' : 'CommitReportAccepted'],
33
+ })) {
34
+ const report = (dest.constructor as ChainStatic).decodeCommits(log, lane)?.[0]
35
+ if (!report || report.maxSeqNr < header.sequenceNumber) continue
36
+ // since we walk forward from some startBlock/startTime, give up if we find a newer report
37
+ if (report.minSeqNr > header.sequenceNumber) break
38
+ return { report, log }
39
+ }
40
+
41
+ throw new Error(
42
+ `Could not find commit after ${hints?.startBlock ?? requestTimestamp} for sequenceNumber=${header.sequenceNumber}`,
43
+ )
44
+ }