@layerzerolabs/lz-solana-sdk-v2 3.0.47 → 3.0.49

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 (323) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/package.json +11 -10
  3. package/src/base-oapp.ts +159 -0
  4. package/src/config.ts +32 -0
  5. package/src/deployment.test.ts +11 -0
  6. package/src/deployment.ts +128 -0
  7. package/src/dvn.ts +606 -0
  8. package/src/endpoint.ts +1518 -0
  9. package/src/executor.ts +577 -0
  10. package/src/generated/blocked_messagelib/index.ts +18 -0
  11. package/src/generated/blocked_messagelib/instructions/index.ts +1 -0
  12. package/src/generated/blocked_messagelib/instructions/version.ts +59 -0
  13. package/src/generated/dvn/accounts/DvnConfig.ts +217 -0
  14. package/src/generated/dvn/accounts/ExecuteHash.ts +179 -0
  15. package/src/generated/dvn/accounts/ReceiveConfig.ts +169 -0
  16. package/src/generated/dvn/accounts/index.ts +9 -0
  17. package/src/generated/dvn/errors/index.ts +396 -0
  18. package/src/generated/dvn/events/AdminConfigSetEvent.ts +22 -0
  19. package/src/generated/dvn/events/FeeWithdrawnEvent.ts +26 -0
  20. package/src/generated/dvn/events/MultisigConfigSetEvent.ts +22 -0
  21. package/src/generated/dvn/events/index.ts +3 -0
  22. package/src/generated/dvn/index.ts +21 -0
  23. package/src/generated/dvn/instructions/closeExecute.ts +148 -0
  24. package/src/generated/dvn/instructions/index.ts +7 -0
  25. package/src/generated/dvn/instructions/initDvn.ts +144 -0
  26. package/src/generated/dvn/instructions/invoke.ts +178 -0
  27. package/src/generated/dvn/instructions/quoteDvn.ts +145 -0
  28. package/src/generated/dvn/instructions/setConfig.ts +157 -0
  29. package/src/generated/dvn/instructions/verifiable.ts +160 -0
  30. package/src/generated/dvn/instructions/withdrawFee.ts +172 -0
  31. package/src/generated/dvn/types/Acl.ts +26 -0
  32. package/src/generated/dvn/types/AdminConfig.ts +100 -0
  33. package/src/generated/dvn/types/CloseExecuteParams.ts +21 -0
  34. package/src/generated/dvn/types/DstConfig.ts +28 -0
  35. package/src/generated/dvn/types/ExecuteTransactionDigest.ts +37 -0
  36. package/src/generated/dvn/types/InitDvnParams.ts +34 -0
  37. package/src/generated/dvn/types/InvokeParams.ts +28 -0
  38. package/src/generated/dvn/types/LzOption.ts +24 -0
  39. package/src/generated/dvn/types/Multisig.ts +24 -0
  40. package/src/generated/dvn/types/MultisigConfig.ts +124 -0
  41. package/src/generated/dvn/types/QuoteDvnParams.ts +38 -0
  42. package/src/generated/dvn/types/SetConfigParams.ts +22 -0
  43. package/src/generated/dvn/types/TransactionAccount.ts +29 -0
  44. package/src/generated/dvn/types/UlnConfig.ts +34 -0
  45. package/src/generated/dvn/types/VerifiableParams.ts +24 -0
  46. package/src/generated/dvn/types/VerificationState.ts +27 -0
  47. package/src/generated/dvn/types/WithdrawFeeParams.ts +20 -0
  48. package/src/generated/dvn/types/index.ts +17 -0
  49. package/src/generated/endpoint/accounts/ComposeMessageState.ts +170 -0
  50. package/src/generated/endpoint/accounts/EndpointSettings.ts +184 -0
  51. package/src/generated/endpoint/accounts/MessageLibInfo.ts +178 -0
  52. package/src/generated/endpoint/accounts/Nonce.ts +193 -0
  53. package/src/generated/endpoint/accounts/OAppRegistry.ts +169 -0
  54. package/src/generated/endpoint/accounts/PayloadHash.ts +169 -0
  55. package/src/generated/endpoint/accounts/PendingInboundNonce.ts +172 -0
  56. package/src/generated/endpoint/accounts/ReceiveLibraryConfig.ts +183 -0
  57. package/src/generated/endpoint/accounts/SendLibraryConfig.ts +171 -0
  58. package/src/generated/endpoint/accounts/index.ts +31 -0
  59. package/src/generated/endpoint/errors/index.ts +428 -0
  60. package/src/generated/endpoint/events/AdminTransferredEvent.ts +23 -0
  61. package/src/generated/endpoint/events/ComposeDeliveredEvent.ts +31 -0
  62. package/src/generated/endpoint/events/ComposeSentEvent.ts +33 -0
  63. package/src/generated/endpoint/events/DefaultReceiveLibrarySetEvent.ts +27 -0
  64. package/src/generated/endpoint/events/DefaultReceiveLibraryTimeoutSetEvent.ts +29 -0
  65. package/src/generated/endpoint/events/DefaultSendLibrarySetEvent.ts +27 -0
  66. package/src/generated/endpoint/events/DelegateSetEvent.ts +22 -0
  67. package/src/generated/endpoint/events/InboundNonceSkippedEvent.ts +31 -0
  68. package/src/generated/endpoint/events/LibraryRegisteredEvent.ts +27 -0
  69. package/src/generated/endpoint/events/LzComposeAlertEvent.ts +43 -0
  70. package/src/generated/endpoint/events/LzReceiveAlertEvent.ts +45 -0
  71. package/src/generated/endpoint/events/LzTokenSetEvent.ts +23 -0
  72. package/src/generated/endpoint/events/OAppRegisteredEvent.ts +27 -0
  73. package/src/generated/endpoint/events/PacketBurntEvent.ts +32 -0
  74. package/src/generated/endpoint/events/PacketDeliveredEvent.ts +31 -0
  75. package/src/generated/endpoint/events/PacketNilifiedEvent.ts +33 -0
  76. package/src/generated/endpoint/events/PacketSentEvent.ts +29 -0
  77. package/src/generated/endpoint/events/PacketVerifiedEvent.ts +33 -0
  78. package/src/generated/endpoint/events/ReceiveLibrarySetEvent.ts +29 -0
  79. package/src/generated/endpoint/events/ReceiveLibraryTimeoutSetEvent.ts +33 -0
  80. package/src/generated/endpoint/events/RentWithdrawnEvent.ts +27 -0
  81. package/src/generated/endpoint/events/SendLibrarySetEvent.ts +29 -0
  82. package/src/generated/endpoint/events/index.ts +22 -0
  83. package/src/generated/endpoint/index.ts +21 -0
  84. package/src/generated/endpoint/instructions/burn.ts +191 -0
  85. package/src/generated/endpoint/instructions/clear.ts +193 -0
  86. package/src/generated/endpoint/instructions/clearCompose.ts +160 -0
  87. package/src/generated/endpoint/instructions/index.ts +32 -0
  88. package/src/generated/endpoint/instructions/initConfig.ts +172 -0
  89. package/src/generated/endpoint/instructions/initDefaultReceiveLibrary.ts +195 -0
  90. package/src/generated/endpoint/instructions/initDefaultSendLibrary.ts +195 -0
  91. package/src/generated/endpoint/instructions/initEndpoint.ts +147 -0
  92. package/src/generated/endpoint/instructions/initNonce.ts +168 -0
  93. package/src/generated/endpoint/instructions/initReceiveLibrary.ts +159 -0
  94. package/src/generated/endpoint/instructions/initSendLibrary.ts +159 -0
  95. package/src/generated/endpoint/instructions/initVerify.ts +159 -0
  96. package/src/generated/endpoint/instructions/lzComposeAlert.ts +148 -0
  97. package/src/generated/endpoint/instructions/lzReceiveAlert.ts +148 -0
  98. package/src/generated/endpoint/instructions/nilify.ts +193 -0
  99. package/src/generated/endpoint/instructions/quote.ts +181 -0
  100. package/src/generated/endpoint/instructions/registerLibrary.ts +183 -0
  101. package/src/generated/endpoint/instructions/registerOapp.ts +183 -0
  102. package/src/generated/endpoint/instructions/send.ts +215 -0
  103. package/src/generated/endpoint/instructions/sendCompose.ts +183 -0
  104. package/src/generated/endpoint/instructions/setConfig.ts +169 -0
  105. package/src/generated/endpoint/instructions/setDefaultReceiveLibrary.ts +184 -0
  106. package/src/generated/endpoint/instructions/setDefaultReceiveLibraryTimeout.ts +185 -0
  107. package/src/generated/endpoint/instructions/setDefaultSendLibrary.ts +184 -0
  108. package/src/generated/endpoint/instructions/setDelegate.ts +160 -0
  109. package/src/generated/endpoint/instructions/setLzToken.ts +160 -0
  110. package/src/generated/endpoint/instructions/setReceiveLibrary.ts +190 -0
  111. package/src/generated/endpoint/instructions/setReceiveLibraryTimeout.ts +184 -0
  112. package/src/generated/endpoint/instructions/setSendLibrary.ts +190 -0
  113. package/src/generated/endpoint/instructions/skip.ts +203 -0
  114. package/src/generated/endpoint/instructions/transferAdmin.ts +160 -0
  115. package/src/generated/endpoint/instructions/verify.ts +205 -0
  116. package/src/generated/endpoint/instructions/withdrawRent.ts +172 -0
  117. package/src/generated/endpoint/types/BurnParams.ts +32 -0
  118. package/src/generated/endpoint/types/ClearComposeParams.ts +31 -0
  119. package/src/generated/endpoint/types/ClearParams.ts +34 -0
  120. package/src/generated/endpoint/types/InitConfigParams.ts +26 -0
  121. package/src/generated/endpoint/types/InitDefaultReceiveLibraryParams.ts +27 -0
  122. package/src/generated/endpoint/types/InitDefaultSendLibraryParams.ts +27 -0
  123. package/src/generated/endpoint/types/InitEndpointParams.ts +27 -0
  124. package/src/generated/endpoint/types/InitNonceParams.ts +28 -0
  125. package/src/generated/endpoint/types/InitReceiveLibraryParams.ts +27 -0
  126. package/src/generated/endpoint/types/InitSendLibraryParams.ts +27 -0
  127. package/src/generated/endpoint/types/InitVerifyParams.ts +30 -0
  128. package/src/generated/endpoint/types/LzComposeAlertParams.ts +41 -0
  129. package/src/generated/endpoint/types/LzReceiveAlertParams.ts +43 -0
  130. package/src/generated/endpoint/types/MessageLibType.ts +25 -0
  131. package/src/generated/endpoint/types/MessagingFee.ts +24 -0
  132. package/src/generated/endpoint/types/MessagingReceipt.ts +27 -0
  133. package/src/generated/endpoint/types/NilifyParams.ts +32 -0
  134. package/src/generated/endpoint/types/QuoteParams.ts +34 -0
  135. package/src/generated/endpoint/types/ReceiveLibraryTimeout.ts +27 -0
  136. package/src/generated/endpoint/types/RegisterLibraryParams.ts +28 -0
  137. package/src/generated/endpoint/types/RegisterOAppParams.ts +23 -0
  138. package/src/generated/endpoint/types/SendComposeParams.ts +31 -0
  139. package/src/generated/endpoint/types/SendParams.ts +32 -0
  140. package/src/generated/endpoint/types/SetConfigParams.ts +31 -0
  141. package/src/generated/endpoint/types/SetDefaultReceiveLibraryParams.ts +29 -0
  142. package/src/generated/endpoint/types/SetDefaultReceiveLibraryTimeoutParams.ts +29 -0
  143. package/src/generated/endpoint/types/SetDefaultSendLibraryParams.ts +27 -0
  144. package/src/generated/endpoint/types/SetDelegateParams.ts +22 -0
  145. package/src/generated/endpoint/types/SetLzTokenParams.ts +23 -0
  146. package/src/generated/endpoint/types/SetReceiveLibraryParams.ts +31 -0
  147. package/src/generated/endpoint/types/SetReceiveLibraryTimeoutParams.ts +31 -0
  148. package/src/generated/endpoint/types/SetSendLibraryParams.ts +29 -0
  149. package/src/generated/endpoint/types/SkipParams.ts +30 -0
  150. package/src/generated/endpoint/types/TransferAdminParams.ts +23 -0
  151. package/src/generated/endpoint/types/VerifyParams.ts +32 -0
  152. package/src/generated/endpoint/types/WithdrawRentParams.ts +21 -0
  153. package/src/generated/endpoint/types/index.ts +36 -0
  154. package/src/generated/executor/accounts/ExecutorConfig.ts +216 -0
  155. package/src/generated/executor/accounts/Nonce.ts +193 -0
  156. package/src/generated/executor/accounts/index.ts +7 -0
  157. package/src/generated/executor/errors/index.ts +434 -0
  158. package/src/generated/executor/events/NativeDropAppliedEvent.ts +38 -0
  159. package/src/generated/executor/events/index.ts +1 -0
  160. package/src/generated/executor/index.ts +21 -0
  161. package/src/generated/executor/instructions/adminSetConfig.ts +136 -0
  162. package/src/generated/executor/instructions/compose.ts +181 -0
  163. package/src/generated/executor/instructions/executable.ts +136 -0
  164. package/src/generated/executor/instructions/execute.ts +181 -0
  165. package/src/generated/executor/instructions/index.ts +8 -0
  166. package/src/generated/executor/instructions/initExecutor.ts +147 -0
  167. package/src/generated/executor/instructions/nativeDrop.ts +171 -0
  168. package/src/generated/executor/instructions/ownerSetConfig.ts +136 -0
  169. package/src/generated/executor/instructions/quoteExecutor.ts +148 -0
  170. package/src/generated/executor/types/Acl.ts +26 -0
  171. package/src/generated/executor/types/AdminSetConfigParams.ts +83 -0
  172. package/src/generated/executor/types/ComposeParams.ts +27 -0
  173. package/src/generated/executor/types/DstConfig.ts +32 -0
  174. package/src/generated/executor/types/ExecutableParams.ts +30 -0
  175. package/src/generated/executor/types/ExecuteParams.ts +31 -0
  176. package/src/generated/executor/types/ExecutionState.ts +26 -0
  177. package/src/generated/executor/types/InitExecutorParams.ts +33 -0
  178. package/src/generated/executor/types/LzComposeParams.ts +35 -0
  179. package/src/generated/executor/types/LzOption.ts +24 -0
  180. package/src/generated/executor/types/LzReceiveParams.ts +33 -0
  181. package/src/generated/executor/types/NativeDropParams.ts +36 -0
  182. package/src/generated/executor/types/NativeDropRequest.ts +26 -0
  183. package/src/generated/executor/types/OwnerSetConfigParams.ts +123 -0
  184. package/src/generated/executor/types/QuoteExecutorParams.ts +34 -0
  185. package/src/generated/executor/types/index.ts +15 -0
  186. package/src/generated/pricefeed/accounts/PriceFeed.ts +220 -0
  187. package/src/generated/pricefeed/accounts/index.ts +5 -0
  188. package/src/generated/pricefeed/errors/index.ts +115 -0
  189. package/src/generated/pricefeed/index.ts +21 -0
  190. package/src/generated/pricefeed/instructions/getFee.ts +121 -0
  191. package/src/generated/pricefeed/instructions/index.ts +6 -0
  192. package/src/generated/pricefeed/instructions/initPriceFeed.ts +147 -0
  193. package/src/generated/pricefeed/instructions/setPrice.ts +133 -0
  194. package/src/generated/pricefeed/instructions/setPriceFeed.ts +136 -0
  195. package/src/generated/pricefeed/instructions/setSolPrice.ts +136 -0
  196. package/src/generated/pricefeed/instructions/transferAdmin.ts +136 -0
  197. package/src/generated/pricefeed/types/GetFeeParams.ts +26 -0
  198. package/src/generated/pricefeed/types/InitPriceFeedParams.ts +27 -0
  199. package/src/generated/pricefeed/types/ModelType.ts +66 -0
  200. package/src/generated/pricefeed/types/Price.ts +31 -0
  201. package/src/generated/pricefeed/types/PriceParams.ts +29 -0
  202. package/src/generated/pricefeed/types/SetPriceFeedParams.ts +29 -0
  203. package/src/generated/pricefeed/types/SetPriceParams.ts +26 -0
  204. package/src/generated/pricefeed/types/SetSolPriceParams.ts +21 -0
  205. package/src/generated/pricefeed/types/TransferAdminParams.ts +23 -0
  206. package/src/generated/pricefeed/types/index.ts +9 -0
  207. package/src/generated/simple_messagelib/accounts/MessageLib.ts +222 -0
  208. package/src/generated/simple_messagelib/accounts/ReceiveConfigStore.ts +168 -0
  209. package/src/generated/simple_messagelib/accounts/SendConfigStore.ts +170 -0
  210. package/src/generated/simple_messagelib/accounts/index.ts +13 -0
  211. package/src/generated/simple_messagelib/errors/index.ts +207 -0
  212. package/src/generated/simple_messagelib/index.ts +21 -0
  213. package/src/generated/simple_messagelib/instructions/index.ts +15 -0
  214. package/src/generated/simple_messagelib/instructions/initConfig.ts +183 -0
  215. package/src/generated/simple_messagelib/instructions/initDefaultConfig.ts +171 -0
  216. package/src/generated/simple_messagelib/instructions/initMessageLib.ts +147 -0
  217. package/src/generated/simple_messagelib/instructions/quote.ts +133 -0
  218. package/src/generated/simple_messagelib/instructions/revertCall.ts +59 -0
  219. package/src/generated/simple_messagelib/instructions/send.ts +154 -0
  220. package/src/generated/simple_messagelib/instructions/sendWithLzToken.ts +207 -0
  221. package/src/generated/simple_messagelib/instructions/setConfig.ts +157 -0
  222. package/src/generated/simple_messagelib/instructions/setDefaultConfig.ts +171 -0
  223. package/src/generated/simple_messagelib/instructions/setFee.ts +133 -0
  224. package/src/generated/simple_messagelib/instructions/setWlCaller.ts +136 -0
  225. package/src/generated/simple_messagelib/instructions/transferAdmin.ts +136 -0
  226. package/src/generated/simple_messagelib/instructions/validatePacket.ts +136 -0
  227. package/src/generated/simple_messagelib/instructions/version.ts +59 -0
  228. package/src/generated/simple_messagelib/instructions/withdrawFees.ts +148 -0
  229. package/src/generated/simple_messagelib/types/InitConfigParams.ts +26 -0
  230. package/src/generated/simple_messagelib/types/InitDefaultConfigParams.ts +27 -0
  231. package/src/generated/simple_messagelib/types/InitMessageLibParams.ts +35 -0
  232. package/src/generated/simple_messagelib/types/MessagingFee.ts +24 -0
  233. package/src/generated/simple_messagelib/types/Packet.ts +36 -0
  234. package/src/generated/simple_messagelib/types/QuoteParams.ts +27 -0
  235. package/src/generated/simple_messagelib/types/SendParams.ts +27 -0
  236. package/src/generated/simple_messagelib/types/SendWithLzTokenParams.ts +34 -0
  237. package/src/generated/simple_messagelib/types/SetConfigParams.ts +31 -0
  238. package/src/generated/simple_messagelib/types/SetDefaultConfigParams.ts +27 -0
  239. package/src/generated/simple_messagelib/types/SetFeeParams.ts +24 -0
  240. package/src/generated/simple_messagelib/types/SetWlCallerParams.ts +22 -0
  241. package/src/generated/simple_messagelib/types/TransferAdminParams.ts +23 -0
  242. package/src/generated/simple_messagelib/types/ValidatePacketParams.ts +21 -0
  243. package/src/generated/simple_messagelib/types/Version.ts +26 -0
  244. package/src/generated/simple_messagelib/types/WithdrawFeesParams.ts +21 -0
  245. package/src/generated/simple_messagelib/types/index.ts +16 -0
  246. package/src/generated/uln/accounts/Confirmations.ts +171 -0
  247. package/src/generated/uln/accounts/ReceiveConfig.ts +169 -0
  248. package/src/generated/uln/accounts/SendConfig.ts +177 -0
  249. package/src/generated/uln/accounts/UlnSettings.ts +195 -0
  250. package/src/generated/uln/accounts/index.ts +16 -0
  251. package/src/generated/uln/errors/index.ts +761 -0
  252. package/src/generated/uln/events/AdminTransferredEvent.ts +23 -0
  253. package/src/generated/uln/events/ConfigSetEvent.ts +30 -0
  254. package/src/generated/uln/events/DefaultConfigSetEvent.ts +31 -0
  255. package/src/generated/uln/events/FeesPaidEvent.ts +28 -0
  256. package/src/generated/uln/events/LzTokenSetEvent.ts +23 -0
  257. package/src/generated/uln/events/PayloadVerifiedEvent.ts +31 -0
  258. package/src/generated/uln/events/RentWithdrawnEvent.ts +27 -0
  259. package/src/generated/uln/events/TreasuryFeeCapSetEvent.ts +21 -0
  260. package/src/generated/uln/events/TreasurySetEvent.ts +22 -0
  261. package/src/generated/uln/events/index.ts +7 -0
  262. package/src/generated/uln/index.ts +21 -0
  263. package/src/generated/uln/instructions/closeVerify.ts +148 -0
  264. package/src/generated/uln/instructions/commitVerification.ts +148 -0
  265. package/src/generated/uln/instructions/index.ts +16 -0
  266. package/src/generated/uln/instructions/initConfig.ts +183 -0
  267. package/src/generated/uln/instructions/initDefaultConfig.ts +195 -0
  268. package/src/generated/uln/instructions/initUln.ts +144 -0
  269. package/src/generated/uln/instructions/initVerify.ts +147 -0
  270. package/src/generated/uln/instructions/quote.ts +157 -0
  271. package/src/generated/uln/instructions/send.ts +220 -0
  272. package/src/generated/uln/instructions/sendWithLzToken.ts +255 -0
  273. package/src/generated/uln/instructions/setConfig.ts +205 -0
  274. package/src/generated/uln/instructions/setDefaultConfig.ts +184 -0
  275. package/src/generated/uln/instructions/setTreasury.ts +160 -0
  276. package/src/generated/uln/instructions/transferAdmin.ts +160 -0
  277. package/src/generated/uln/instructions/verify.ts +157 -0
  278. package/src/generated/uln/instructions/version.ts +59 -0
  279. package/src/generated/uln/instructions/withdrawRent.ts +172 -0
  280. package/src/generated/uln/types/CloseVerifyParams.ts +24 -0
  281. package/src/generated/uln/types/CommitVerificationParams.ts +25 -0
  282. package/src/generated/uln/types/Config.ts +75 -0
  283. package/src/generated/uln/types/ExecutorConfig.ts +26 -0
  284. package/src/generated/uln/types/InitConfigParams.ts +26 -0
  285. package/src/generated/uln/types/InitDefaultConfigParams.ts +31 -0
  286. package/src/generated/uln/types/InitUlnParams.ts +30 -0
  287. package/src/generated/uln/types/InitVerifyParams.ts +28 -0
  288. package/src/generated/uln/types/LzTokenTreasury.ts +26 -0
  289. package/src/generated/uln/types/MessagingFee.ts +24 -0
  290. package/src/generated/uln/types/Packet.ts +36 -0
  291. package/src/generated/uln/types/QuoteParams.ts +27 -0
  292. package/src/generated/uln/types/SendParams.ts +27 -0
  293. package/src/generated/uln/types/SendWithLzTokenParams.ts +34 -0
  294. package/src/generated/uln/types/SetConfigParams.ts +31 -0
  295. package/src/generated/uln/types/SetDefaultConfigParams.ts +31 -0
  296. package/src/generated/uln/types/SetTreasuryParams.ts +22 -0
  297. package/src/generated/uln/types/TransferAdminParams.ts +23 -0
  298. package/src/generated/uln/types/Treasury.ts +31 -0
  299. package/src/generated/uln/types/TreasuryFee.ts +28 -0
  300. package/src/generated/uln/types/UlnConfig.ts +34 -0
  301. package/src/generated/uln/types/VerifyParams.ts +26 -0
  302. package/src/generated/uln/types/Version.ts +26 -0
  303. package/src/generated/uln/types/WithdrawRentParams.ts +21 -0
  304. package/src/generated/uln/types/WorkerFee.ts +26 -0
  305. package/src/generated/uln/types/index.ts +25 -0
  306. package/src/generated/worker_interface/errors/index.ts +75 -0
  307. package/src/generated/worker_interface/index.ts +20 -0
  308. package/src/generated/worker_interface/instructions/index.ts +2 -0
  309. package/src/generated/worker_interface/instructions/quoteDvn.ts +145 -0
  310. package/src/generated/worker_interface/instructions/quoteExecutor.ts +148 -0
  311. package/src/generated/worker_interface/types/LzOption.ts +24 -0
  312. package/src/generated/worker_interface/types/QuoteDvnParams.ts +38 -0
  313. package/src/generated/worker_interface/types/QuoteExecutorParams.ts +34 -0
  314. package/src/generated/worker_interface/types/index.ts +3 -0
  315. package/src/index.ts +120 -0
  316. package/src/pda-deriver.ts +658 -0
  317. package/src/pricefeed.ts +208 -0
  318. package/src/recevie.ts +269 -0
  319. package/src/send-helper.ts +504 -0
  320. package/src/simple-message-lib.ts +303 -0
  321. package/src/types.ts +222 -0
  322. package/src/uln.ts +1045 -0
  323. package/src/utility.ts +592 -0
@@ -0,0 +1,1518 @@
1
+ import {
2
+ AccountMeta,
3
+ Commitment,
4
+ Connection,
5
+ GetAccountInfoConfig,
6
+ PublicKey,
7
+ TransactionInstruction,
8
+ } from '@solana/web3.js'
9
+ import BN from 'bn.js'
10
+ import invariant from 'tiny-invariant'
11
+
12
+ import { keccak_256 } from '@layerzerolabs/lz-foundation'
13
+ import { arrayify } from '@layerzerolabs/lz-utilities'
14
+ import { PacketV1Codec, addressToBytes32 } from '@layerzerolabs/lz-v2-utilities'
15
+
16
+ import { ComposeMessageState, EndpointSettings, MessageLibInfo, PayloadHash } from './generated/endpoint'
17
+ import * as accounts from './generated/endpoint/accounts'
18
+ import * as errors from './generated/endpoint/errors'
19
+ import * as events from './generated/endpoint/events'
20
+ import * as instructions from './generated/endpoint/instructions'
21
+ import * as types from './generated/endpoint/types'
22
+ import { Version } from './generated/simple_messagelib'
23
+ import * as pdaDeriver from './pda-deriver'
24
+ import { EventPDADeriver, MessageLibPDADeriver, OAPP_SEED } from './pda-deriver'
25
+
26
+ import {
27
+ MessageLibInterface,
28
+ SetConfigType,
29
+ SimpleMessageLibProgram,
30
+ SolanaPacketPath,
31
+ UlnProgram,
32
+ simulateTransaction,
33
+ } from '.'
34
+
35
+ export { accounts, instructions, types, events, errors }
36
+ export { PROGRAM_ID } from './generated/endpoint'
37
+
38
+ // https://github.com/coral-xyz/anchor/blob/c7ccbb8f620aed3ffecf8ab2f9c9007946f0f5cc/lang/src/event.rs#L2
39
+ export const EventEmitDiscriminator = 'e445a52e51cb9a1d' // Sha256(anchor:event)[..8] then evert
40
+
41
+ export const DefaultMessageLib = PublicKey.default // [0u8; 32]
42
+
43
+ /**
44
+ * Class representing an Endpoint.
45
+ */
46
+ export class Endpoint {
47
+ deriver: pdaDeriver.EndpointPDADeriver
48
+ eventAuthorityPDA: PublicKey
49
+
50
+ /**
51
+ * Creates an instance of the Endpoint class.
52
+ *
53
+ * @param {PublicKey} program - The program public key.
54
+ */
55
+ constructor(public program: PublicKey) {
56
+ this.deriver = new pdaDeriver.EndpointPDADeriver(program)
57
+ const [eventAuthorityPDA] = new EventPDADeriver(program).eventAuthority()
58
+ this.eventAuthorityPDA = eventAuthorityPDA
59
+ }
60
+
61
+ /**
62
+ * Initializes the endpoint settings, including eid and admin, and registers the blocked message library.
63
+ *
64
+ * @param {number} endpointId - The endpoint ID.
65
+ * @param {PublicKey} payer - The payer public key.
66
+ * @param {PublicKey} admin - The admin public key.
67
+ * @returns {TransactionInstruction} The transaction instruction.
68
+ */
69
+ initEndpoint(endpointId: number, payer: PublicKey, admin: PublicKey): TransactionInstruction {
70
+ const [settingPDA] = this.deriver.setting()
71
+ return instructions.createInitEndpointInstruction(
72
+ {
73
+ payer,
74
+ endpoint: settingPDA,
75
+ } satisfies instructions.InitEndpointInstructionAccounts,
76
+ {
77
+ params: {
78
+ eid: endpointId,
79
+ admin,
80
+ } satisfies types.InitEndpointParams,
81
+ } satisfies instructions.InitEndpointInstructionArgs,
82
+ this.program
83
+ )
84
+ }
85
+
86
+ // async initOrUpdateConfig(connection:Connection,)
87
+ /**
88
+ * Registers a library.
89
+ * call this function after endpoint initialized. Only admin can call this function.
90
+ *
91
+ * @param {PublicKey} admin - The admin public key.
92
+ * @param {PublicKey} messageLibProgram - The message library program public key.
93
+ * @param {types.MessageLibType} [libType=types.MessageLibType.SendAndReceive] - The library type.
94
+ * @returns {TransactionInstruction} The transaction instruction.
95
+ */
96
+ registerLibrary(
97
+ admin: PublicKey,
98
+ messageLibProgram: PublicKey,
99
+ libType: types.MessageLibType = types.MessageLibType.SendAndReceive
100
+ ): TransactionInstruction {
101
+ const [msgLibPda] = new pdaDeriver.MessageLibPDADeriver(messageLibProgram).messageLib()
102
+ const [msgLibInfoPda] = this.deriver.messageLibraryInfo(msgLibPda)
103
+
104
+ const [settingPDA] = this.deriver.setting()
105
+ return instructions.createRegisterLibraryInstruction(
106
+ {
107
+ admin,
108
+ endpoint: settingPDA,
109
+ messageLibInfo: msgLibInfoPda,
110
+ eventAuthority: this.eventAuthorityPDA,
111
+ program: this.program,
112
+ },
113
+ {
114
+ params: {
115
+ libProgram: messageLibProgram,
116
+ libType,
117
+ },
118
+ },
119
+ this.program
120
+ )
121
+ }
122
+
123
+ /**
124
+ * Sets the default send library.
125
+ *
126
+ * @param {Connection} connection - The connection to the Solana cluster.
127
+ * @param {PublicKey} admin - The admin public key.
128
+ * @param {PublicKey} messageLibProgram - The message library program public key.
129
+ * @param {number} dstEid - The destination endpoint ID.
130
+ * @param {Commitment | GetAccountInfoConfig} [commitmentOrConfig] - The commitment level or account info configuration.
131
+ * @returns {Promise<TransactionInstruction | null>} A promise that resolves to the transaction instruction or null if not needed.
132
+ */
133
+ async setDefaultSendLibrary(
134
+ connection: Connection,
135
+ admin: PublicKey,
136
+ messageLibProgram: PublicKey,
137
+ dstEid: number,
138
+ commitmentOrConfig?: Commitment | GetAccountInfoConfig
139
+ ): Promise<TransactionInstruction | null> {
140
+ const [msgLib] = new pdaDeriver.MessageLibPDADeriver(messageLibProgram).messageLib()
141
+ const [defaultSendLibConfig] = this.deriver.defaultSendLibraryConfig(dstEid)
142
+ const [settingPDA] = this.deriver.setting()
143
+ const [msgLibInfo] = this.deriver.messageLibraryInfo(msgLib)
144
+
145
+ const info = await connection.getAccountInfo(defaultSendLibConfig, commitmentOrConfig)
146
+ if (!info) {
147
+ return instructions.createInitDefaultSendLibraryInstruction(
148
+ {
149
+ admin,
150
+ endpoint: settingPDA,
151
+ defaultSendLibraryConfig: defaultSendLibConfig,
152
+ messageLibInfo: msgLibInfo,
153
+ program: this.program,
154
+ eventAuthority: this.eventAuthorityPDA,
155
+ } satisfies instructions.InitDefaultSendLibraryInstructionAccounts,
156
+ {
157
+ params: {
158
+ eid: dstEid,
159
+ newLib: msgLib,
160
+ } satisfies types.InitDefaultSendLibraryParams,
161
+ } satisfies instructions.InitDefaultSendLibraryInstructionArgs,
162
+ this.program
163
+ )
164
+ } else {
165
+ // get current default send library
166
+ const sendLibConfig = await accounts.SendLibraryConfig.fromAccountAddress(
167
+ connection,
168
+ defaultSendLibConfig,
169
+ commitmentOrConfig
170
+ )
171
+ if (sendLibConfig.messageLib.toBase58() === msgLib.toBase58()) {
172
+ return null
173
+ }
174
+
175
+ return instructions.createSetDefaultSendLibraryInstruction(
176
+ {
177
+ admin,
178
+ endpoint: settingPDA,
179
+ defaultSendLibraryConfig: defaultSendLibConfig,
180
+ messageLibInfo: msgLibInfo,
181
+ program: this.program,
182
+ eventAuthority: this.eventAuthorityPDA,
183
+ } satisfies instructions.SetDefaultSendLibraryInstructionAccounts,
184
+ {
185
+ params: {
186
+ eid: dstEid,
187
+ newLib: msgLib,
188
+ } satisfies types.SetDefaultSendLibraryParams,
189
+ } satisfies instructions.SetDefaultSendLibraryInstructionArgs,
190
+ this.program
191
+ )
192
+ }
193
+ }
194
+
195
+ /**
196
+ * Sets the default receive library.
197
+ *
198
+ * @param {Connection} connection - The connection to the Solana cluster.
199
+ * @param {PublicKey} admin - The admin public key.
200
+ * @param {PublicKey} messageLibProgram - The message library program public key.
201
+ * @param {number} srcEid - The source endpoint ID.
202
+ * @param {Commitment | GetAccountInfoConfig} [commitmentOrConfig] - The commitment level or account info configuration.
203
+ * @returns {Promise<TransactionInstruction | null>} A promise that resolves to the transaction instruction or null if not needed.
204
+ */
205
+ async setDefaultReceiveLibrary(
206
+ connection: Connection,
207
+ admin: PublicKey,
208
+ messageLibProgram: PublicKey,
209
+ srcEid: number,
210
+ commitmentOrConfig?: Commitment | GetAccountInfoConfig
211
+ ): Promise<TransactionInstruction | null> {
212
+ const [msgLib] = new pdaDeriver.MessageLibPDADeriver(messageLibProgram).messageLib()
213
+ const [defaultReceiveLibConfig] = this.deriver.defaultReceiveLibraryConfig(srcEid)
214
+ const [settingPDA] = this.deriver.setting()
215
+ const [defaultMsgLibInfo] = this.deriver.messageLibraryInfo(msgLib)
216
+ const info = await connection.getAccountInfo(defaultReceiveLibConfig, commitmentOrConfig)
217
+ if (!info) {
218
+ return instructions.createInitDefaultReceiveLibraryInstruction(
219
+ {
220
+ admin,
221
+ endpoint: settingPDA,
222
+ defaultReceiveLibraryConfig: defaultReceiveLibConfig,
223
+ messageLibInfo: defaultMsgLibInfo,
224
+ program: this.program,
225
+ eventAuthority: this.eventAuthorityPDA,
226
+ } satisfies instructions.InitDefaultReceiveLibraryInstructionAccounts,
227
+ {
228
+ params: {
229
+ eid: srcEid,
230
+ newLib: msgLib,
231
+ } satisfies types.InitDefaultReceiveLibraryParams,
232
+ } satisfies instructions.InitDefaultReceiveLibraryInstructionArgs,
233
+ this.program
234
+ )
235
+ } else {
236
+ // get current default receive library
237
+ const receiveLibConfig = await accounts.ReceiveLibraryConfig.fromAccountAddress(
238
+ connection,
239
+ defaultReceiveLibConfig,
240
+ commitmentOrConfig
241
+ )
242
+ if (receiveLibConfig.messageLib.toBase58() === msgLib.toBase58()) {
243
+ return null
244
+ }
245
+
246
+ return instructions.createSetDefaultReceiveLibraryInstruction(
247
+ {
248
+ admin,
249
+ endpoint: settingPDA,
250
+ defaultReceiveLibraryConfig: defaultReceiveLibConfig,
251
+ messageLibInfo: defaultMsgLibInfo,
252
+ program: this.program,
253
+ eventAuthority: this.eventAuthorityPDA,
254
+ } satisfies instructions.SetDefaultReceiveLibraryInstructionAccounts,
255
+ {
256
+ params: {
257
+ eid: srcEid,
258
+ newLib: msgLib,
259
+ gracePeriod: 0, // TODO: set grace period
260
+ } satisfies types.SetDefaultReceiveLibraryParams,
261
+ } satisfies instructions.SetDefaultReceiveLibraryInstructionArgs,
262
+ this.program
263
+ )
264
+ }
265
+ }
266
+
267
+ /**
268
+ * Initializes the OApp configuration.
269
+ *
270
+ * @param {PublicKey} delegate - The delegate public key.
271
+ * @param {MessageLibInterface} msgLibSDK - The message library SDK.
272
+ * @param {PublicKey} payer - The payer public key.
273
+ * @param {PublicKey} oappID - The OApp ID public key.
274
+ * @param {number} eid - The endpoint ID.
275
+ * @returns {TransactionInstruction} The transaction instruction.
276
+ */
277
+ initOAppConfig(
278
+ delegate: PublicKey,
279
+ msgLibSDK: MessageLibInterface,
280
+ payer: PublicKey,
281
+ oappID: PublicKey,
282
+ eid: number
283
+ ): TransactionInstruction {
284
+ const [msgLib] = new MessageLibPDADeriver(msgLibSDK.program).messageLib()
285
+ const [oappRegistry] = this.deriver.oappRegistry(oappID)
286
+
287
+ const [msgLibInfo] = this.deriver.messageLibraryInfo(msgLib)
288
+ // if (!(await uln.getOappConfig(connection, oappID, eid, commitmentOrConfig))) {
289
+ // init oapp config
290
+ return instructions.createInitConfigInstruction(
291
+ {
292
+ delegate,
293
+ oappRegistry,
294
+ messageLib: msgLib,
295
+ messageLibInfo: msgLibInfo,
296
+ messageLibProgram: msgLibSDK.program,
297
+ anchorRemainingAccounts: msgLibSDK.getInitConfigIXAccountMetaForCPI(payer, oappID, eid),
298
+ } satisfies instructions.InitConfigInstructionAccounts,
299
+ {
300
+ params: {
301
+ eid: eid,
302
+ oapp: oappID,
303
+ } satisfies types.InitConfigParams,
304
+ } satisfies instructions.InitConfigInstructionArgs,
305
+ this.program
306
+ )
307
+ }
308
+
309
+ /**
310
+ * Initializes the OApp nonce.
311
+ *
312
+ * @param {PublicKey} delegate - The delegate public key.
313
+ * @param {number} dstEid - The destination endpoint ID.
314
+ * @param {PublicKey} oappIDPDA - The OApp ID PDA.
315
+ * @param {Uint8Array} remoteOappAddr - The remote OApp address.
316
+ * @returns {TransactionInstruction} The transaction instruction.
317
+ */
318
+ initOAppNonce(
319
+ delegate: PublicKey, // payer
320
+ dstEid: number,
321
+ oappIDPDA: PublicKey,
322
+ remoteOappAddr: Uint8Array
323
+ ): TransactionInstruction {
324
+ const [nonce] = this.deriver.nonce(oappIDPDA, dstEid, remoteOappAddr)
325
+ const [pendingNonce] = this.deriver.pendingNonce(oappIDPDA, dstEid, remoteOappAddr)
326
+ const [oappRegistry] = this.deriver.oappRegistry(oappIDPDA)
327
+
328
+ return instructions.createInitNonceInstruction(
329
+ {
330
+ nonce,
331
+ pendingInboundNonce: pendingNonce,
332
+ oappRegistry,
333
+ delegate,
334
+ } satisfies instructions.InitNonceInstructionAccounts,
335
+ {
336
+ params: {
337
+ localOapp: oappIDPDA,
338
+ remoteOapp: Array.from(remoteOappAddr),
339
+ remoteEid: dstEid,
340
+ } satisfies types.InitNonceParams,
341
+ } satisfies instructions.InitNonceInstructionArgs,
342
+ this.program
343
+ )
344
+ }
345
+
346
+ /**
347
+ * Initializes the send library.
348
+ *
349
+ * @param {PublicKey} delegate - The delegate public key.
350
+ * @param {PublicKey} sender - The sender public key.
351
+ * @param {number} dstEid - The destination endpoint ID.
352
+ * @returns {TransactionInstruction} The transaction instruction.
353
+ */
354
+ initSendLibrary(delegate: PublicKey, sender: PublicKey, dstEid: number): TransactionInstruction {
355
+ const [oappRegistry] = this.deriver.oappRegistry(sender)
356
+ const [sendLibraryConfig] = this.deriver.sendLibraryConfig(sender, dstEid)
357
+
358
+ return instructions.createInitSendLibraryInstruction(
359
+ {
360
+ delegate,
361
+ oappRegistry,
362
+ sendLibraryConfig: sendLibraryConfig,
363
+ } satisfies instructions.InitSendLibraryInstructionAccounts,
364
+ {
365
+ params: {
366
+ sender,
367
+ eid: dstEid,
368
+ } satisfies types.InitSendLibraryParams,
369
+ } satisfies instructions.InitSendLibraryInstructionArgs,
370
+ this.program
371
+ )
372
+ }
373
+
374
+ /**
375
+ * Sets the send library.
376
+ *
377
+ * @param {PublicKey} oappAdmin - The OApp admin public key.
378
+ * @param {PublicKey} oappIDPDA - The OApp ID PDA.
379
+ * @param {PublicKey} newSendLibProgram - The new send library program public key.
380
+ * @param {number} dstEid - The destination endpoint ID.
381
+ * @returns {TransactionInstruction} The transaction instruction.
382
+ */
383
+ setSendLibrary(
384
+ oappAdmin: PublicKey,
385
+ oappIDPDA: PublicKey,
386
+ newSendLibProgram: PublicKey,
387
+ dstEid: number
388
+ ): TransactionInstruction {
389
+ const [newSendLib] = new MessageLibPDADeriver(newSendLibProgram).messageLib()
390
+ const [sendLibraryConfig] = this.deriver.sendLibraryConfig(oappIDPDA, dstEid)
391
+ const [sendLibraryInfo] = this.deriver.messageLibraryInfo(newSendLib)
392
+ const [oappRegistry] = this.deriver.oappRegistry(oappIDPDA)
393
+
394
+ const ix = instructions.createSetSendLibraryInstruction(
395
+ {
396
+ signer: oappAdmin,
397
+ sendLibraryConfig: sendLibraryConfig,
398
+ messageLibInfo: sendLibraryInfo,
399
+ oappRegistry,
400
+ program: this.program,
401
+ eventAuthority: this.eventAuthorityPDA,
402
+ } satisfies instructions.SetSendLibraryInstructionAccounts,
403
+ {
404
+ params: {
405
+ sender: oappIDPDA,
406
+ eid: dstEid,
407
+ newLib: newSendLib,
408
+ } satisfies types.SetSendLibraryParams,
409
+ } satisfies instructions.SetSendLibraryInstructionArgs,
410
+ this.program
411
+ )
412
+ return ix
413
+ }
414
+
415
+ /**
416
+ * Initializes the receive library.
417
+ *
418
+ * @param {PublicKey} delegate - The delegate public key.
419
+ * @param {PublicKey} receiver - The receiver public key.
420
+ * @param {number} srcEid - The source endpoint ID.
421
+ * @returns {TransactionInstruction} The transaction instruction.
422
+ */
423
+ initReceiveLibrary(delegate: PublicKey, receiver: PublicKey, srcEid: number): TransactionInstruction {
424
+ const [oappRegistry] = this.deriver.oappRegistry(receiver)
425
+ const [receiveLibraryConfig] = this.deriver.receiveLibraryConfig(receiver, srcEid)
426
+
427
+ return instructions.createInitReceiveLibraryInstruction(
428
+ {
429
+ delegate,
430
+ oappRegistry,
431
+ receiveLibraryConfig: receiveLibraryConfig,
432
+ } satisfies instructions.InitReceiveLibraryInstructionAccounts,
433
+ {
434
+ params: {
435
+ receiver,
436
+ eid: srcEid,
437
+ } satisfies types.InitReceiveLibraryParams,
438
+ } satisfies instructions.InitReceiveLibraryInstructionArgs,
439
+ this.program
440
+ )
441
+ }
442
+
443
+ /**
444
+ * Sets the receive library.
445
+ *
446
+ * @param {PublicKey} oappAdmin - The OApp admin public key.
447
+ * @param {PublicKey} oappIDPDA - The OApp ID PDA.
448
+ * @param {PublicKey} newReceiveLibProgram - The new receive library program public key.
449
+ * @param {number} srcEid - The source endpoint ID.
450
+ * @param {bigint | number} [gracePeriod] - The grace period.
451
+ * @returns {TransactionInstruction} The transaction instruction.
452
+ */
453
+ setReceiveLibrary(
454
+ oappAdmin: PublicKey,
455
+ oappIDPDA: PublicKey,
456
+ newReceiveLibProgram: PublicKey,
457
+ srcEid: number,
458
+ gracePeriod?: bigint | number
459
+ ): TransactionInstruction {
460
+ const [newReceiveLib] = new MessageLibPDADeriver(newReceiveLibProgram).messageLib()
461
+ const [receiveLibraryConfig] = this.deriver.receiveLibraryConfig(oappIDPDA, srcEid)
462
+ const [receiveLibraryInfo] = this.deriver.messageLibraryInfo(newReceiveLib)
463
+ const [oappRegistry] = this.deriver.oappRegistry(oappIDPDA)
464
+
465
+ const ix = instructions.createSetReceiveLibraryInstruction(
466
+ {
467
+ signer: oappAdmin,
468
+ receiveLibraryConfig: receiveLibraryConfig,
469
+ messageLibInfo: receiveLibraryInfo,
470
+ oappRegistry,
471
+ program: this.program,
472
+ eventAuthority: this.eventAuthorityPDA,
473
+ } satisfies instructions.SetReceiveLibraryInstructionAccounts,
474
+ {
475
+ params: {
476
+ receiver: oappIDPDA,
477
+ eid: srcEid,
478
+ newLib: newReceiveLib,
479
+ gracePeriod: gracePeriod === undefined ? 0 : new BN(gracePeriod.toString()),
480
+ } satisfies types.SetReceiveLibraryParams,
481
+ } satisfies instructions.SetReceiveLibraryInstructionArgs,
482
+ this.program
483
+ )
484
+ return ix
485
+ }
486
+
487
+ /**
488
+ * Sets the OApp configuration.
489
+ *
490
+ * @param {Connection} connection - The connection to the Solana cluster.
491
+ * @param {PublicKey} oappDelegate - The OApp delegate public key.
492
+ * @param {PublicKey} oappID - The OApp ID public key.
493
+ * @param {PublicKey} msgLibProgram - The message library program public key.
494
+ * @param {number} eid - The endpoint ID.
495
+ * @param {object} config - The configuration object.
496
+ * @param {SetConfigType} config.configType - The configuration type.
497
+ * @param {UlnProgram.types.ExecutorConfig | UlnProgram.types.UlnConfig} config.value - The configuration value.
498
+ * @param {Commitment} [commitment='confirmed'] - The commitment level.
499
+ * @returns {Promise<TransactionInstruction>} A promise that resolves to the transaction instruction.
500
+ * @throws {Error} If the message library version is unsupported.
501
+ */
502
+ async setOappConfig(
503
+ connection: Connection,
504
+ oappDelegate: PublicKey,
505
+ oappID: PublicKey,
506
+ msgLibProgram: PublicKey,
507
+ eid: number,
508
+ config: {
509
+ configType: SetConfigType
510
+ value: UlnProgram.types.ExecutorConfig | UlnProgram.types.UlnConfig
511
+ },
512
+ commitment: Commitment = 'confirmed'
513
+ ): Promise<TransactionInstruction> {
514
+ const [msgLib] = new MessageLibPDADeriver(msgLibProgram).messageLib()
515
+ const [msgLibInfo] = this.deriver.messageLibraryInfo(msgLib)
516
+
517
+ const msgLibVersion = await this.getMessageLibVersion(connection, oappDelegate, msgLibProgram, commitment)
518
+ let msgLibClient: MessageLibInterface
519
+ if (msgLibVersion?.major.toString() === '0' && msgLibVersion.minor == 0 && msgLibVersion.endpointVersion == 2) {
520
+ msgLibClient = new SimpleMessageLibProgram.SimpleMessageLib(msgLibProgram)
521
+ } else if (
522
+ msgLibVersion?.major.toString() === '3' &&
523
+ msgLibVersion.minor == 0 &&
524
+ msgLibVersion.endpointVersion == 2
525
+ ) {
526
+ msgLibClient = new UlnProgram.Uln(msgLibProgram)
527
+ } else {
528
+ throw new Error(
529
+ `unsupported message lib version ${msgLibVersion?.major.toString()}.${msgLibVersion?.minor.toString()}`
530
+ )
531
+ }
532
+
533
+ const [oappRegistry] = this.deriver.oappRegistry(oappID)
534
+ const ix = instructions.createSetConfigInstruction(
535
+ {
536
+ signer: oappDelegate,
537
+ messageLibInfo: msgLibInfo,
538
+ messageLib: msgLib,
539
+ messageLibProgram: msgLibProgram,
540
+ oappRegistry,
541
+ anchorRemainingAccounts: await msgLibClient.getSetConfigIXAccountMetaForCPI(this.program, oappID, eid),
542
+ },
543
+ {
544
+ params: {
545
+ eid,
546
+ configType: config.configType,
547
+ config:
548
+ msgLibProgram.toBase58() === SimpleMessageLibProgram.PROGRAM_ID.toBase58()
549
+ ? new Uint8Array(10)
550
+ : UlnProgram.Uln.constructSetConfigData(config.configType, config.value),
551
+ oapp: oappID,
552
+ } satisfies types.SetConfigParams,
553
+ } satisfies instructions.SetConfigInstructionArgs,
554
+ this.program
555
+ )
556
+ return ix
557
+ }
558
+
559
+ /// send a simulated transaction to the endpoint to get the fee for sending a message
560
+ /**
561
+ *
562
+ * Gets the account metadata for the CPI (Cross-Program Invocation) of the quote instruction.
563
+ *
564
+ * caculate the fee for sending a message with ULN:
565
+ * 1. executorFee: feeForGas + feeForOptionType
566
+ * * feeForGas: ((gas + gasForCalldata) * gasPriceInUnit * priceRatio / priceRatioDenominator) * multiplier_bps / 10000
567
+ * * feeForOptionType: nativeDrop/lzReceive/lzCompose
568
+ * 2. oracleFee: feeForGas
569
+ * * feeForGas: same above
570
+ *
571
+ * The priceRatioDenominator is 10^20
572
+ * totalFee = executorFee + oracleFee * numOracles(requiredOracles + optionalOracles)
573
+ *
574
+ * @param {Connection} connection - The connection to the Solana cluster.
575
+ * @param {PublicKey} payer - The payer public key.
576
+ * @param {PacketPath} path - The packet path.
577
+ * @param {MessageLibInterface} msgLibProgram - The message library program.
578
+ * @returns {Promise<AccountMeta[]>} A promise that resolves to an array of account metadata.
579
+ * @throws {Error} If the default send library is not initialized or the message library is blocked.
580
+ */
581
+ async getQuoteIXAccountMetaForCPI(
582
+ connection: Connection,
583
+ payer: PublicKey,
584
+ path: SolanaPacketPath,
585
+ msgLibProgram: MessageLibInterface
586
+ ): Promise<AccountMeta[]> {
587
+ const { sender: sender_, dstEid, receiver: receiver_ } = path
588
+ const sender = new PublicKey(arrayify(sender_))
589
+ const receiver = addressToBytes32(receiver_)
590
+ const sendLibInfo = await this.getSendLibrary(connection, sender, dstEid)
591
+ if (!sendLibInfo?.programId) {
592
+ throw new Error('default send library not initialized or blocked message lib')
593
+ }
594
+ const { msgLib, programId: owner } = sendLibInfo
595
+ const [sendLibraryInfo] = this.deriver.messageLibraryInfo(msgLib)
596
+ const remainingAccounts = await msgLibProgram.getQuoteIXAccountMetaForCPI(connection, payer, path)
597
+
598
+ const [setting] = this.deriver.setting()
599
+ const [defaultSendLibraryConfig] = this.deriver.defaultSendLibraryConfig(dstEid)
600
+ const [sendLibraryConfig] = this.deriver.sendLibraryConfig(sender, dstEid)
601
+ const [nonce] = this.deriver.nonce(sender, dstEid, receiver)
602
+
603
+ const accounts = instructions.createQuoteInstructionAccounts(
604
+ {
605
+ sendLibraryConfig: sendLibraryConfig,
606
+ sendLibraryProgram: owner,
607
+ defaultSendLibraryConfig: defaultSendLibraryConfig,
608
+ endpoint: setting,
609
+ nonce,
610
+ sendLibraryInfo,
611
+ anchorRemainingAccounts: remainingAccounts,
612
+ } satisfies instructions.QuoteInstructionAccounts,
613
+ this.program
614
+ )
615
+ return Promise.resolve(
616
+ [
617
+ {
618
+ pubkey: this.program,
619
+ isSigner: false,
620
+ isWritable: false,
621
+ },
622
+ ].concat(accounts)
623
+ )
624
+ }
625
+
626
+ /**
627
+ * Gets the account metadata for the CPI (Cross-Program Invocation) of the send instruction.
628
+ *
629
+ * @param {Connection} connection - The connection to the Solana cluster.
630
+ * @param {PublicKey} payer - The payer public key.
631
+ * @param {PacketPath} path - The packet path.
632
+ * @param {MessageLibInterface} msgLibProgram - The message library program.
633
+ * @param {Commitment | GetAccountInfoConfig} [commitmentOrConfig] - The commitment level or account info configuration.
634
+ * @returns {Promise<AccountMeta[]>} A promise that resolves to an array of account metadata.
635
+ * @throws {Error} If the default send library is not initialized or the message library is blocked.
636
+ */
637
+ async getSendIXAccountMetaForCPI(
638
+ connection: Connection,
639
+ payer: PublicKey,
640
+ path: SolanaPacketPath,
641
+ msgLibProgram: MessageLibInterface,
642
+ commitmentOrConfig?: Commitment | GetAccountInfoConfig
643
+ ): Promise<AccountMeta[]> {
644
+ const { sender: sender_, dstEid, receiver: receiver_ } = path
645
+ const sender = new PublicKey(arrayify(sender_))
646
+ const receiver = addressToBytes32(receiver_)
647
+ const info = await this.getSendLibrary(connection, sender, dstEid, commitmentOrConfig)
648
+ if (!info?.programId) {
649
+ throw new Error('default send library not initialized or blocked message lib')
650
+ }
651
+ const sendLibrary = info.msgLib
652
+
653
+ const [sendLibraryInfo] = this.deriver.messageLibraryInfo(sendLibrary)
654
+ const remainingAccounts = await msgLibProgram.getSendIXAccountMetaForCPI(connection, payer, path)
655
+
656
+ const [defaultSendLibraryConfig] = this.deriver.defaultSendLibraryConfig(dstEid)
657
+ const [sendLibraryConfig] = this.deriver.sendLibraryConfig(sender, dstEid)
658
+ const [nonce] = this.deriver.nonce(sender, dstEid, receiver)
659
+
660
+ const accounts = instructions.createSendInstructionAccounts(
661
+ {
662
+ sender, //signer
663
+ /// this account should be derived from message lib
664
+ sendLibraryProgram: info.programId,
665
+ sendLibraryConfig,
666
+ defaultSendLibraryConfig: defaultSendLibraryConfig,
667
+ sendLibraryInfo,
668
+ endpoint: this.deriver.setting()[0],
669
+ program: this.program,
670
+ nonce: nonce,
671
+ eventAuthority: this.eventAuthorityPDA,
672
+ anchorRemainingAccounts: remainingAccounts,
673
+ } satisfies instructions.SendInstructionAccounts,
674
+ this.program
675
+ )
676
+
677
+ accounts.forEach((item: AccountMeta) => {
678
+ item.isSigner = false
679
+ })
680
+ return [
681
+ {
682
+ pubkey: this.program,
683
+ isSigner: false,
684
+ isWritable: false,
685
+ },
686
+ ].concat(accounts)
687
+ }
688
+
689
+ /**
690
+ * Skips a message.
691
+ *
692
+ * @param {PublicKey} payer - The payer public key.
693
+ * @param {PublicKey} sender - The sender public key.
694
+ * @param {PublicKey} receiver - The receiver public key.
695
+ * @param {number} srcEid - The source endpoint ID.
696
+ * @param {string} nonce - The nonce.
697
+ * @returns {Promise<TransactionInstruction | null>} A promise that resolves to the transaction instruction or null if not needed.
698
+ */
699
+ async skip(
700
+ payer: PublicKey,
701
+ sender: PublicKey,
702
+ receiver: PublicKey,
703
+ srcEid: number,
704
+ nonce: string
705
+ ): Promise<TransactionInstruction | null> {
706
+ const [nonceAccount] = this.deriver.nonce(receiver, srcEid, addressToBytes32(sender.toBase58()))
707
+ const [payloadHash] = this.deriver.payloadHash(receiver, srcEid, sender.toBytes(), parseInt(nonce))
708
+ const [pendingInboundNonce] = this.deriver.pendingNonce(receiver, srcEid, sender.toBytes())
709
+ // get the delegate from endpoint
710
+ const [oAppRegistry] = PublicKey.findProgramAddressSync(
711
+ [Buffer.from(OAPP_SEED, 'utf-8'), receiver.toBuffer()],
712
+ this.program
713
+ )
714
+ const ix = instructions.createSkipInstruction(
715
+ {
716
+ signer: payer,
717
+ oappRegistry: oAppRegistry,
718
+ nonce: nonceAccount,
719
+ pendingInboundNonce: pendingInboundNonce,
720
+ payloadHash: payloadHash,
721
+ endpoint: this.deriver.setting()[0],
722
+ eventAuthority: this.eventAuthorityPDA,
723
+ program: this.program,
724
+ } satisfies instructions.SkipInstructionAccounts,
725
+ {
726
+ params: {
727
+ receiver: receiver,
728
+ srcEid: srcEid,
729
+ sender: Array.from(sender.toBytes()),
730
+ nonce: new BN(nonce),
731
+ } satisfies types.SkipParams,
732
+ } satisfies instructions.SkipInstructionArgs,
733
+ this.program
734
+ )
735
+ return Promise.resolve(ix)
736
+ }
737
+
738
+ /**
739
+ * Initializes the verification process.
740
+ *
741
+ * @param {Connection} connection - The connection to the Solana cluster.
742
+ * @param {PublicKey} payer - The payer public key.
743
+ * @param {PublicKey} sender - The sender public key.
744
+ * @param {PublicKey} receiver - The receiver public key.
745
+ * @param {number} srcEid - The source endpoint ID.
746
+ * @param {string} nonce - The nonce.
747
+ * @param {Commitment | GetAccountInfoConfig} [commitmentOrConfig] - The commitment level or account info configuration.
748
+ * @returns {Promise<TransactionInstruction | null>} A promise that resolves to the transaction instruction or null if not needed.
749
+ */
750
+ async initVerify(
751
+ connection: Connection,
752
+ payer: PublicKey,
753
+ sender: PublicKey,
754
+ receiver: PublicKey,
755
+ srcEid: number,
756
+ nonce: string,
757
+ commitmentOrConfig?: Commitment | GetAccountInfoConfig
758
+ ): Promise<TransactionInstruction | null> {
759
+ const [nonceAccount] = this.deriver.nonce(receiver, srcEid, addressToBytes32(sender.toBase58()))
760
+ const [payloadHash] = this.deriver.payloadHash(receiver, srcEid, sender.toBytes(), parseInt(nonce))
761
+ const payloadHashInfo = await connection.getAccountInfo(payloadHash, commitmentOrConfig)
762
+ if (payloadHashInfo) {
763
+ // throw new Error('init verify already executed')
764
+ return null
765
+ }
766
+ return instructions.createInitVerifyInstruction(
767
+ {
768
+ payer,
769
+ nonce: nonceAccount,
770
+ payloadHash,
771
+ } satisfies instructions.InitVerifyInstructionAccounts,
772
+ {
773
+ params: {
774
+ srcEid,
775
+ sender: Array.from(sender.toBytes()),
776
+ receiver,
777
+ nonce: new BN(nonce),
778
+ } satisfies types.InitVerifyParams,
779
+ } satisfies instructions.InitVerifyInstructionArgs,
780
+ this.program
781
+ )
782
+ }
783
+
784
+ /**
785
+ * Gets the account metadata for the CPI (Cross-Program Invocation) of the verify instruction.
786
+ *
787
+ * @param {PacketV1Codec} packet - The packet.
788
+ * @param {PublicKey} receiveLibrary - The receive library public key.
789
+ * @returns {AccountMeta[]} An array of account metadata.
790
+ */
791
+ getVerifyIXAccountMetaForCPI(packet: PacketV1Codec, receiveLibrary: PublicKey): AccountMeta[] {
792
+ const receiver = new PublicKey(Buffer.from(packet.receiver().slice(2), 'hex'))
793
+ const srcEid = packet.srcEid()
794
+ const sender = addressToBytes32(packet.sender())
795
+
796
+ const [payloadHash] = this.deriver.payloadHash(receiver, srcEid, sender, parseInt(packet.nonce()))
797
+ const [defaultReceiveLibraryConfig] = this.deriver.defaultReceiveLibraryConfig(srcEid)
798
+ const [receiveLibraryConfig] = this.deriver.receiveLibraryConfig(receiver, srcEid)
799
+
800
+ const [nonce] = this.deriver.nonce(receiver, srcEid, sender)
801
+ const [pendingNonce] = this.deriver.pendingNonce(receiver, srcEid, sender)
802
+ // const [receiveLibraryPDA] = this.endpointDeriver.receiveLibrary(receiver, srcEid)
803
+ const accounts = instructions.createVerifyInstructionAccounts(
804
+ {
805
+ receiveLibrary: receiveLibrary,
806
+ receiveLibraryConfig: receiveLibraryConfig,
807
+ defaultReceiveLibraryConfig: defaultReceiveLibraryConfig,
808
+ nonce: nonce,
809
+ pendingInboundNonce: pendingNonce,
810
+ payloadHash: payloadHash,
811
+ program: this.program,
812
+ eventAuthority: this.eventAuthorityPDA,
813
+ } satisfies instructions.VerifyInstructionAccounts,
814
+ this.program
815
+ )
816
+ accounts.forEach((key) => {
817
+ key.isSigner = false
818
+ })
819
+ const program: AccountMeta = {
820
+ pubkey: this.program,
821
+ isSigner: false,
822
+ isWritable: false,
823
+ }
824
+ return [program, ...accounts]
825
+ }
826
+
827
+ /***
828
+ * resetConfig is only supported by ULN
829
+ */
830
+ // async getResetConfigIXAccountMetaForCPI(
831
+ // connection: Connection,
832
+ // msgLibProgram: PublicKey,
833
+ // oappID: PublicKey,
834
+ // eid: number,
835
+ // commitmentOrConfig: Commitment | GetAccountInfoConfig = 'confirmed'
836
+ // ): Promise<AccountMeta[]> {
837
+ // const uln = new UlnProgram.Uln(msgLibProgram)
838
+ // const [msgLib] = uln.ulnDeriver.messageLib()
839
+ // const [msgLibInfo] = this.endpointDeriver.messageLibraryAuthority(msgLib)
840
+
841
+ // const ix = instructions.createResetConfigInstruction(
842
+ // {
843
+ // oapp: oappID,
844
+ // messageLibAuthority: msgLibInfo,
845
+ // messageLib: msgLib,
846
+ // anchorRemainingAccounts: await uln.getResetConfigIXAccountMetaForCPI(
847
+ // connection,
848
+ // this.program,
849
+ // oappID,
850
+ // eid,
851
+ // commitmentOrConfig
852
+ // ),
853
+ // } as instructions.ResetConfigInstructionAccounts,
854
+ // // Fake params. Just to get the ix.keys
855
+ // {
856
+ // params: {
857
+ // eid: eid,
858
+ // messageLib: msgLib,
859
+ // } as types.ResetConfigParams,
860
+ // } as instructions.ResetConfigInstructionArgs
861
+ // )
862
+ // ix.keys.forEach((key) => {
863
+ // key.isSigner = false
864
+ // })
865
+ // return [
866
+ // {
867
+ // pubkey: this.program,
868
+ // isWritable: false,
869
+ // isSigner: false,
870
+ // } as AccountMeta,
871
+ // ].concat(ix.keys)
872
+ // }
873
+
874
+ /**
875
+ * snapshotConfig is only supported by ULN
876
+ */
877
+ // async getSnapshotConfigIXAccountMetaForCPI(
878
+ // connection: Connection,
879
+ // msgLibProgram: PublicKey,
880
+ // oappID: PublicKey,
881
+ // eid: number,
882
+ // commitmentOrConfig: Commitment | GetAccountInfoConfig = 'confirmed'
883
+ // ): Promise<AccountMeta[]> {
884
+ // const uln = new UlnProgram.Uln(msgLibProgram)
885
+ // const [msgLib] = uln.ulnDeriver.messageLib()
886
+ // const [msgLibInfo] = this.endpointDeriver.messageLibraryAuthority(msgLib)
887
+
888
+ // const ix = instructions.createSnapshotConfigInstruction(
889
+ // {
890
+ // oapp: oappID,
891
+ // messageLibAuthority: msgLibInfo,
892
+ // messageLib: msgLib,
893
+ // anchorRemainingAccounts: await uln.getSnapshotConfigIXAccountMetaForCPI(
894
+ // connection,
895
+ // this.program,
896
+ // oappID,
897
+ // eid,
898
+ // commitmentOrConfig
899
+ // ),
900
+ // } satisfies instructions.SnapshotConfigInstructionAccounts,
901
+ // // Fake params. Just to get the ix.keys
902
+ // {
903
+ // params: {
904
+ // eid: eid,
905
+ // messageLib: msgLib,
906
+ // } as types.SnapshotConfigParams,
907
+ // } as instructions.SnapshotConfigInstructionArgs
908
+ // )
909
+ // ix.keys.forEach((key) => {
910
+ // key.isSigner = false
911
+ // })
912
+ // return [
913
+ // {
914
+ // pubkey: this.program,
915
+ // isWritable: false,
916
+ // isSigner: false,
917
+ // },
918
+ // ].concat(ix.keys)
919
+ // }
920
+
921
+ /**
922
+ * @param composer. The composer is usually the PDA of the app's ID. It depends on the oapp's implementation.
923
+ */
924
+ // getDeliverComposedMessageIXAccountMetaForCPI(
925
+ // payer: PublicKey,
926
+ // composer: PublicKey,
927
+ // packet: PacketV1Codec
928
+ // ): AccountMeta[] {
929
+ // const receiver = new PublicKey(Buffer.from(packet.receiver().slice(2), 'hex'))
930
+ // const guid = Uint8Array.from(Buffer.from(packet.guid().slice(2), 'hex'))
931
+ // const message = ethers.utils.arrayify(ethers.utils.keccak256(packet.message()))
932
+ // const ix = instructions.createDeliverComposedMessageInstruction(
933
+ // {
934
+ // payer,
935
+ // receiver,
936
+ // composedMessage: this.endpointDeriver.composedMessage(receiver, guid, composer, message)[0],
937
+ // endpoint: this.endpointDeriver.setting()[0],
938
+ // endpointProgram: this.program,
939
+ // } satisfies instructions.DeliverComposedMessageInstructionAccounts,
940
+ // // Fake params. Just to get the ix.keys
941
+ // {
942
+ // params: {
943
+ // composer: payer,
944
+ // guid: Array.from(guid),
945
+ // message: Uint8Array.from([]),
946
+ // } as types.DeliverComposedMessageParams,
947
+ // } as instructions.DeliverComposedMessageInstructionArgs
948
+ // )
949
+ // ix.keys.forEach((key) => {
950
+ // key.isSigner = false
951
+ // })
952
+ // return [
953
+ // {
954
+ // pubkey: this.program,
955
+ // isWritable: false,
956
+ // isSigner: false,
957
+ // },
958
+ // ].concat(ix.keys)
959
+ // }
960
+
961
+ /**
962
+ * @param composer. The composer is usually the PDA of the app's ID. It depends on the oapp's implementation.
963
+ */
964
+ // getClearComposedMessageIXAccountMetaForCPI(composer: PublicKey, packet: PacketV1Codec): AccountMeta[] {
965
+ // const receiver = new PublicKey(Buffer.from(packet.receiver().slice(2), 'hex'))
966
+ // const guid = Uint8Array.from(Buffer.from(packet.guid().slice(2), 'hex'))
967
+ // const message = ethers.utils.arrayify(ethers.utils.keccak256(packet.message()))
968
+ // const ix = instructions.createClearComposedMessageInstruction(
969
+ // {
970
+ // composer,
971
+ // composedMessage: this.endpointDeriver.composedMessage(receiver, guid, composer, message)[0],
972
+ // endpoint: this.endpointDeriver.setting()[0],
973
+ // endpointProgram: this.program,
974
+ // } satisfies instructions.ClearComposedMessageInstructionAccounts,
975
+ // // Fake params. Just to get the ix.keys
976
+ // {
977
+ // params: {
978
+ // receiver: composer,
979
+ // guid: Array.from(guid),
980
+ // message: Uint8Array.from([]),
981
+ // } as types.ClearComposedMessageParams,
982
+ // } as instructions.ClearComposedMessageInstructionArgs
983
+ // )
984
+ // ix.keys.forEach((key) => {
985
+ // key.isSigner = false
986
+ // })
987
+ // return [
988
+ // {
989
+ // pubkey: this.program,
990
+ // isWritable: false,
991
+ // isSigner: false,
992
+ // } as AccountMeta,
993
+ // ].concat(ix.keys)
994
+ // }
995
+
996
+ /**
997
+ * Gets the account metadata for the CPI (Cross-Program Invocation) of the register OApp instruction.
998
+ *
999
+ * @param {PublicKey} payer - The payer public key.
1000
+ * @param {PublicKey} oapp - The OApp public key.
1001
+ * @returns {AccountMeta[]} An array of account metadata.
1002
+ */
1003
+ getRegisterOappIxAccountMetaForCPI(payer: PublicKey, oapp: PublicKey): AccountMeta[] {
1004
+ const [oappRegistry] = this.deriver.oappRegistry(oapp)
1005
+ const eventAuthority = this.eventAuthorityPDA
1006
+ const keys = instructions.createRegisterOappInstructionAccounts(
1007
+ {
1008
+ payer,
1009
+ oapp,
1010
+ oappRegistry,
1011
+ eventAuthority,
1012
+ program: this.program,
1013
+ } satisfies instructions.RegisterOappInstructionAccounts,
1014
+ this.program
1015
+ )
1016
+ keys.forEach((key) => {
1017
+ key.isSigner = false
1018
+ })
1019
+ return [
1020
+ {
1021
+ pubkey: this.program,
1022
+ isSigner: false,
1023
+ isWritable: false,
1024
+ },
1025
+ ].concat(keys)
1026
+ }
1027
+
1028
+ /**
1029
+ * Gets the account metadata for the CPI (Cross-Program Invocation) of the skip instruction.
1030
+ *
1031
+ * @param {PublicKey} receiver - The receiver public key.
1032
+ * @param {Uint8Array} sender - The sender address.
1033
+ * @param {number} srcEid - The source endpoint ID.
1034
+ * @param {number} nonce - The nonce.
1035
+ * @returns {AccountMeta[]} An array of account metadata.
1036
+ */
1037
+ getSkipIxAccountMetaForCPI(receiver: PublicKey, sender: Uint8Array, srcEid: number, nonce: number): AccountMeta[] {
1038
+ const [noncePDA] = this.deriver.nonce(receiver, srcEid, sender)
1039
+ const [pendingNonce] = this.deriver.pendingNonce(receiver, srcEid, sender)
1040
+ const [payloadHash] = this.deriver.payloadHash(receiver, srcEid, sender, nonce)
1041
+ const [oappRegistry] = this.deriver.oappRegistry(receiver)
1042
+ const keys = instructions.createSkipInstructionAccounts(
1043
+ {
1044
+ signer: receiver,
1045
+ oappRegistry,
1046
+ nonce: noncePDA,
1047
+ pendingInboundNonce: pendingNonce,
1048
+ payloadHash,
1049
+ endpoint: this.deriver.setting()[0],
1050
+ program: this.program,
1051
+ eventAuthority: this.eventAuthorityPDA,
1052
+ } satisfies instructions.SkipInstructionAccounts,
1053
+ this.program
1054
+ )
1055
+ keys.forEach((key) => {
1056
+ key.isSigner = false
1057
+ })
1058
+ return [
1059
+ {
1060
+ pubkey: this.program,
1061
+ isSigner: false,
1062
+ isWritable: false,
1063
+ },
1064
+ ].concat(keys)
1065
+ }
1066
+
1067
+ /**
1068
+ * Checks if the given message library program is the default send library.
1069
+ *
1070
+ * @param {Connection} connection - The connection to the Solana cluster.
1071
+ * @param {PublicKey} messageLibProgram - The message library program public key.
1072
+ * @param {number} dstEid - The destination endpoint ID.
1073
+ * @param {Commitment | GetAccountInfoConfig} [commitmentOrConfig] - The commitment level or account info configuration.
1074
+ * @returns {Promise<boolean>} A promise that resolves to true if the message library program is the default send library, false otherwise.
1075
+ */
1076
+ async isDefaultSendLibrary(
1077
+ connection: Connection,
1078
+ messageLibProgram: PublicKey,
1079
+ dstEid: number,
1080
+ commitmentOrConfig?: Commitment | GetAccountInfoConfig
1081
+ ): Promise<boolean> {
1082
+ const [msgLib] = new pdaDeriver.MessageLibPDADeriver(messageLibProgram).messageLib()
1083
+ const info = await this.getDefaultSendLibrary(connection, dstEid, commitmentOrConfig)
1084
+ if (info) {
1085
+ // const [defaultSendLib] = new MessageLibPDADeriver(messageLibProgram).messageLib()
1086
+ return info.msgLib.equals(msgLib)
1087
+ }
1088
+ return false
1089
+ }
1090
+
1091
+ /**
1092
+ * Checks if the given message library program is the default receive library.
1093
+ *
1094
+ * @param {Connection} connection - The connection to the Solana cluster.
1095
+ * @param {PublicKey} messageLibProgram - The message library program public key.
1096
+ * @param {number} srcEid - The source endpoint ID.
1097
+ * @param {Commitment | GetAccountInfoConfig} [commitmentOrConfig] - The commitment level or account info configuration.
1098
+ * @returns {Promise<boolean>} A promise that resolves to true if the message library program is the default receive library, false otherwise.
1099
+ */
1100
+ async isDefaultReceiveLibrary(
1101
+ connection: Connection,
1102
+ messageLibProgram: PublicKey,
1103
+ srcEid: number,
1104
+ commitmentOrConfig?: Commitment | GetAccountInfoConfig
1105
+ ): Promise<boolean> {
1106
+ const [msgLib] = new pdaDeriver.MessageLibPDADeriver(messageLibProgram).messageLib()
1107
+ const info = await this.getDefaultReceiveLibrary(connection, srcEid, commitmentOrConfig)
1108
+ if (info) {
1109
+ return info.msgLib.equals(msgLib)
1110
+ }
1111
+ return false
1112
+ }
1113
+
1114
+ // all of below functions are retrieving accounts state
1115
+ /**
1116
+ * Gets the endpoint settings.
1117
+ *
1118
+ * @param {Connection} connection - The connection to the Solana cluster.
1119
+ * @param {Commitment | GetAccountInfoConfig} [commitmentOrConfig] - The commitment level or account info configuration.
1120
+ * @returns {Promise<EndpointSettings | null>} A promise that resolves to the endpoint settings or null if not found.
1121
+ */
1122
+ async getSetting(
1123
+ connection: Connection,
1124
+ commitmentOrConfig?: Commitment | GetAccountInfoConfig
1125
+ ): Promise<EndpointSettings | null> {
1126
+ const [setting] = this.deriver.setting()
1127
+ try {
1128
+ return await accounts.EndpointSettings.fromAccountAddress(connection, setting, commitmentOrConfig)
1129
+ } catch (e) {
1130
+ return null
1131
+ }
1132
+ }
1133
+
1134
+ /**
1135
+ * Gets the message library information.
1136
+ *
1137
+ * @param {Connection} connection - The connection to the Solana cluster.
1138
+ * @param {PublicKey} messageLibProgram - The message library program public key, It is a PDA of the message library program
1139
+ * @param {Commitment | GetAccountInfoConfig} [commitmentOrConfig] - The commitment level or account info configuration.
1140
+ * @returns {Promise<MessageLibInfo | null>} A promise that resolves to the message library information or null if not found.
1141
+ */
1142
+ async getMessageLibInfo(
1143
+ connection: Connection,
1144
+ messageLibProgram: PublicKey,
1145
+ commitmentOrConfig?: Commitment | GetAccountInfoConfig
1146
+ ): Promise<MessageLibInfo | null> {
1147
+ const [msgLib] = new pdaDeriver.MessageLibPDADeriver(messageLibProgram).messageLib()
1148
+ const [messageLibInfo] = this.deriver.messageLibraryInfo(msgLib)
1149
+ try {
1150
+ return await accounts.MessageLibInfo.fromAccountAddress(connection, messageLibInfo, commitmentOrConfig)
1151
+ } catch (e) {
1152
+ return null
1153
+ }
1154
+ }
1155
+
1156
+ /**
1157
+ * Gets the default receive library.
1158
+ *
1159
+ * @param {Connection} connection - The connection to the Solana cluster.
1160
+ * @param {number} srcEid - The source endpoint ID.
1161
+ * @param {Commitment | GetAccountInfoConfig} [commitmentOrConfig] - The commitment level or account info configuration.
1162
+ * @returns {Promise<{ msgLib: PublicKey; owner?: PublicKey } | null>} A promise that resolves to the default receive library or null if not found.
1163
+ */
1164
+ async getDefaultReceiveLibrary(
1165
+ connection: Connection,
1166
+ srcEid: number,
1167
+ commitmentOrConfig?: Commitment | GetAccountInfoConfig
1168
+ ): Promise<{ msgLib: PublicKey; owner?: PublicKey } | null> {
1169
+ const [defaultReceiveLibConfig] = this.deriver.defaultReceiveLibraryConfig(srcEid)
1170
+ try {
1171
+ const defaultInfo = await accounts.ReceiveLibraryConfig.fromAccountAddress(
1172
+ connection,
1173
+ defaultReceiveLibConfig,
1174
+ commitmentOrConfig
1175
+ )
1176
+ const messageLibInfo = await connection.getAccountInfo(defaultInfo.messageLib, commitmentOrConfig)
1177
+ // notice: BlockedMessageLib is not initialized its PDA, so it will be null if defaultInfo.messageLib is BlockedMessageLib
1178
+ if (!messageLibInfo) {
1179
+ return {
1180
+ msgLib: defaultInfo.messageLib,
1181
+ }
1182
+ }
1183
+ return {
1184
+ owner: messageLibInfo.owner,
1185
+ msgLib: defaultInfo.messageLib,
1186
+ }
1187
+ } catch (e) {
1188
+ return null
1189
+ }
1190
+ }
1191
+
1192
+ /**
1193
+ * Gets the default send library.
1194
+ *
1195
+ * @param {Connection} connection - The connection to the Solana cluster.
1196
+ * @param {number} dstEid - The destination endpoint ID.
1197
+ * @param {Commitment | GetAccountInfoConfig} [commitmentOrConfig] - The commitment level or account info configuration.
1198
+ * @returns {Promise<{ msgLib: PublicKey; owner?: PublicKey } | null>} A promise that resolves to the default send library or null if not found.
1199
+ */
1200
+ async getDefaultSendLibrary(
1201
+ connection: Connection,
1202
+ dstEid: number,
1203
+ commitmentOrConfig?: Commitment | GetAccountInfoConfig
1204
+ ): Promise<{ msgLib: PublicKey; owner?: PublicKey } | null> {
1205
+ const [defaultSendLibConfig] = this.deriver.defaultSendLibraryConfig(dstEid)
1206
+ try {
1207
+ const defaultInfo = await accounts.SendLibraryConfig.fromAccountAddress(
1208
+ connection,
1209
+ defaultSendLibConfig,
1210
+ commitmentOrConfig
1211
+ )
1212
+ const messageLibInfo = await connection.getAccountInfo(defaultInfo.messageLib, commitmentOrConfig)
1213
+ // notice: BlockedMessageLib is not initialized its PDA, so it will be null if defaultInfo.messageLib is BlockedMessageLib
1214
+ if (!messageLibInfo) {
1215
+ return {
1216
+ msgLib: defaultInfo.messageLib,
1217
+ }
1218
+ }
1219
+ return {
1220
+ owner: messageLibInfo.owner,
1221
+ msgLib: defaultInfo.messageLib,
1222
+ }
1223
+ } catch (e) {
1224
+ return null
1225
+ }
1226
+ }
1227
+
1228
+ /**
1229
+ * Gets the configured send library for the app.
1230
+ *
1231
+ * @param {Connection} connection - The connection to the Solana cluster.
1232
+ * @param {PublicKey} oappPda - The OApp PDA.
1233
+ * @param {number} dstEid - The destination endpoint ID.
1234
+ * @param {Commitment | GetAccountInfoConfig} [commitmentOrConfig='confirmed'] - The commitment level or account info configuration.
1235
+ * @returns {Promise<{ msgLib: PublicKey; programId?: PublicKey; isDefault: boolean } | null>} A promise that resolves to the configured send library or null if not found.
1236
+ */
1237
+ async getSendLibrary(
1238
+ connection: Connection,
1239
+ oappPda: PublicKey,
1240
+ dstEid: number,
1241
+ commitmentOrConfig: Commitment | GetAccountInfoConfig = 'confirmed'
1242
+ ): Promise<{ msgLib: PublicKey; programId?: PublicKey; isDefault: boolean } | null> {
1243
+ const [sendLibConfig] = this.deriver.sendLibraryConfig(oappPda, dstEid)
1244
+ const [defaultSendLibConfig] = this.deriver.defaultSendLibraryConfig(dstEid)
1245
+ const [defaultSendLibConfigBuf, sendLibConfigBuf] = await connection.getMultipleAccountsInfo(
1246
+ [defaultSendLibConfig, sendLibConfig],
1247
+ commitmentOrConfig
1248
+ )
1249
+ if (!defaultSendLibConfigBuf || !sendLibConfigBuf) {
1250
+ console.warn('send library not initialized, return empty array')
1251
+ return null
1252
+ }
1253
+ const [sendLibConfigInfo] = accounts.SendLibraryConfig.fromAccountInfo(sendLibConfigBuf, 0)
1254
+ const [defaultSendLibConfigInfo] = accounts.SendLibraryConfig.fromAccountInfo(defaultSendLibConfigBuf, 0)
1255
+ const msgLib =
1256
+ sendLibConfigInfo.messageLib.toString() === DefaultMessageLib.toString()
1257
+ ? defaultSendLibConfigInfo.messageLib
1258
+ : sendLibConfigInfo.messageLib
1259
+ const isDefault = sendLibConfigInfo.messageLib.toString() === DefaultMessageLib.toString()
1260
+ const msgLibInfo = await connection.getAccountInfo(msgLib, commitmentOrConfig)
1261
+
1262
+ // notice: BlockedMessageLib is not initialized its PDA, so it will be null if msgLib is BlockedMessageLib
1263
+ if (!msgLibInfo) {
1264
+ return {
1265
+ programId: undefined,
1266
+ msgLib,
1267
+ isDefault,
1268
+ }
1269
+ } else {
1270
+ return {
1271
+ programId: msgLibInfo.owner,
1272
+ msgLib,
1273
+ isDefault,
1274
+ }
1275
+ }
1276
+ }
1277
+
1278
+ /**
1279
+ * Gets the configured receive library for the app.
1280
+ *
1281
+ * @param {Connection} connection - The connection to the Solana cluster.
1282
+ * @param {PublicKey} oappPda - The OApp PDA.
1283
+ * @param {number} srcEid - The source endpoint ID.
1284
+ * @param {Commitment | GetAccountInfoConfig} [commitmentOrConfig] - The commitment level or account info configuration.
1285
+ * @returns {Promise<{ msgLib: PublicKey; programId?: PublicKey; isDefault: boolean; timeout: { msgLib: PublicKey; expiry: bigint } | null } | null>} A promise that resolves to the configured receive library or null if not found.
1286
+ */
1287
+ async getReceiveLibrary(
1288
+ connection: Connection,
1289
+ oappPda: PublicKey,
1290
+ srcEid: number,
1291
+ commitmentOrConfig?: Commitment | GetAccountInfoConfig
1292
+ ): Promise<{
1293
+ msgLib: PublicKey // message library pda, it might be null if the message lib is blocked
1294
+ programId?: PublicKey
1295
+ isDefault: boolean
1296
+ timeout: { msgLib: PublicKey; expiry: bigint } | null
1297
+ } | null> {
1298
+ const [receiveLibConfig] = this.deriver.receiveLibraryConfig(oappPda, srcEid)
1299
+ const accountInfo = await connection.getAccountInfo(receiveLibConfig, commitmentOrConfig)
1300
+ if (accountInfo == null) {
1301
+ // throw new Error(`Unable to find MessageLibConfig account at ${sendLibPda}`)
1302
+ return null
1303
+ }
1304
+ const [info] = accounts.ReceiveLibraryConfig.fromAccountInfo(accountInfo, 0)
1305
+ if (info.messageLib.toString() == DefaultMessageLib.toString()) {
1306
+ // use default message lib
1307
+ const [defaultReceiveLibConfig] = this.deriver.defaultReceiveLibraryConfig(srcEid)
1308
+ const defaultInfo = await accounts.ReceiveLibraryConfig.fromAccountAddress(
1309
+ connection,
1310
+ defaultReceiveLibConfig,
1311
+ commitmentOrConfig
1312
+ )
1313
+ const messageLibInfo = await connection.getAccountInfo(defaultInfo.messageLib, commitmentOrConfig)
1314
+ if (messageLibInfo) {
1315
+ const { timeout } = defaultInfo
1316
+ if (timeout) {
1317
+ return {
1318
+ programId: defaultInfo.messageLib,
1319
+ msgLib: defaultInfo.messageLib,
1320
+ isDefault: true,
1321
+ timeout: { msgLib: timeout.messageLib, expiry: BigInt(timeout.expiry.toString()) },
1322
+ }
1323
+ }
1324
+ }
1325
+ return {
1326
+ programId: messageLibInfo?.owner,
1327
+ msgLib: defaultInfo.messageLib,
1328
+ isDefault: true,
1329
+ timeout: null,
1330
+ }
1331
+ }
1332
+ const messageLibInfo = await connection.getAccountInfo(info.messageLib, commitmentOrConfig)
1333
+ invariant(messageLibInfo, 'messageLibInfo should not be null')
1334
+ const { timeout } = info
1335
+ if (timeout) {
1336
+ // const slot = await connection.getSlot()
1337
+ // const timestamp = await connection.getBlockTime(slot)
1338
+ // invariant(timestamp, 'timestamp should not be null')
1339
+ // const isValid = parseInt(timeout.expiry.toString()) > timestamp
1340
+ return {
1341
+ programId: messageLibInfo.owner,
1342
+ msgLib: info.messageLib,
1343
+ isDefault: false,
1344
+ timeout: { msgLib: timeout.messageLib, expiry: BigInt(timeout.expiry.toString()) },
1345
+ }
1346
+ }
1347
+ return { programId: messageLibInfo.owner, msgLib: info.messageLib, isDefault: false, timeout: null }
1348
+ }
1349
+
1350
+ // rename to a more generic name
1351
+ /**
1352
+ * Gets the inbound payload hash.
1353
+ *
1354
+ * @param {Connection} connection - The connection to the Solana cluster.
1355
+ * @param {PublicKey} receiver - The receiver public key.
1356
+ * @param {number} srcEid - The source endpoint ID.
1357
+ * @param {Uint8Array} sender - The sender address.
1358
+ * @param {number} nonce - The nonce.
1359
+ * @param {Uint8Array} _payloadHash - The payload hash.
1360
+ * @param {Commitment | GetAccountInfoConfig} [commitmentOrConfig] - The commitment level or account info configuration.
1361
+ * @returns {Promise<PayloadHash | null>} A promise that resolves to the payload hash or null if not found.
1362
+ */
1363
+ async getInboundPayloadHash(
1364
+ connection: Connection,
1365
+ receiver: PublicKey,
1366
+ srcEid: number,
1367
+ sender: Uint8Array,
1368
+ nonce: number,
1369
+ _payloadHash: Uint8Array,
1370
+ commitmentOrConfig?: Commitment | GetAccountInfoConfig
1371
+ ): Promise<PayloadHash | null> {
1372
+ const [payloadHashPDA] = this.deriver.payloadHash(receiver, srcEid, sender, nonce)
1373
+ const accountInfo = await connection.getAccountInfo(payloadHashPDA, commitmentOrConfig)
1374
+ if (!accountInfo) {
1375
+ return null
1376
+ }
1377
+ return PayloadHash.fromAccountInfo(accountInfo, 0)[0]
1378
+ }
1379
+
1380
+ /**
1381
+ * Gets the composed message state.
1382
+ *
1383
+ * @param {Connection} connection - The connection to the Solana cluster.
1384
+ * @param {PublicKey} from - The sender public key.
1385
+ * @param {types.SendComposeParams} params - The send compose parameters.
1386
+ * @param {Commitment | GetAccountInfoConfig} [commitmentOrConfig] - The commitment level or account info configuration.
1387
+ * @returns {Promise<ComposeMessageState | null>} A promise that resolves to the composed message state or null if not found.
1388
+ */
1389
+ async getComposedMessageState(
1390
+ connection: Connection,
1391
+ from: PublicKey,
1392
+ params: types.SendComposeParams,
1393
+ commitmentOrConfig?: Commitment | GetAccountInfoConfig
1394
+ ): Promise<ComposeMessageState | null> {
1395
+ const message = keccak_256(params.message)
1396
+ const [composedMessagePDA] = this.deriver.composedMessage(
1397
+ from,
1398
+ Uint8Array.from(params.guid),
1399
+ params.index,
1400
+ params.to,
1401
+ message
1402
+ )
1403
+ const accountInfo = await connection.getAccountInfo(composedMessagePDA, commitmentOrConfig)
1404
+ if (!accountInfo) {
1405
+ return null
1406
+ }
1407
+ return ComposeMessageState.fromAccountInfo(accountInfo, 0)[0]
1408
+ }
1409
+
1410
+ /**
1411
+ * Gets the nonce.
1412
+ *
1413
+ * @param {Connection} connection - The connection to the Solana cluster.
1414
+ * @param {PublicKey} oappIDPDA - The OApp ID PDA.
1415
+ * @param {number} remoteEid - The remote endpoint ID.
1416
+ * @param {Uint8Array} remoteOappAddr - The remote OApp address.
1417
+ * @param {Commitment | GetAccountInfoConfig} [commitmentOrConfig] - The commitment level or account info configuration.
1418
+ * @returns {Promise<accounts.Nonce | null>} A promise that resolves to the nonce or null if not found.
1419
+ */
1420
+ async getNonce(
1421
+ connection: Connection,
1422
+ oappIDPDA: PublicKey,
1423
+ remoteEid: number,
1424
+ remoteOappAddr: Uint8Array,
1425
+ commitmentOrConfig?: Commitment | GetAccountInfoConfig
1426
+ ): Promise<accounts.Nonce | null> {
1427
+ const [nonce] = this.deriver.nonce(oappIDPDA, remoteEid, remoteOappAddr)
1428
+ try {
1429
+ return await accounts.Nonce.fromAccountAddress(connection, nonce, commitmentOrConfig)
1430
+ } catch (e) {
1431
+ return null
1432
+ }
1433
+ }
1434
+
1435
+ /**
1436
+ * Gets the pending inbound nonce.
1437
+ *
1438
+ * @param {Connection} connection - The connection to the Solana cluster.
1439
+ * @param {PublicKey} oappIDPDA - The OApp ID PDA.
1440
+ * @param {number} remoteEid - The remote endpoint ID.
1441
+ * @param {Uint8Array} remoteOappAddr - The remote OApp address.
1442
+ * @param {Commitment | GetAccountInfoConfig} [commitmentOrConfig] - The commitment level or account info configuration.
1443
+ * @returns {Promise<accounts.PendingInboundNonce | null>} A promise that resolves to the pending inbound nonce or null if not found.
1444
+ */
1445
+ async getPendingInboundNonce(
1446
+ connection: Connection,
1447
+ oappIDPDA: PublicKey,
1448
+ remoteEid: number,
1449
+ remoteOappAddr: Uint8Array,
1450
+ commitmentOrConfig?: Commitment | GetAccountInfoConfig
1451
+ ): Promise<accounts.PendingInboundNonce | null> {
1452
+ const [nonce] = this.deriver.pendingNonce(oappIDPDA, remoteEid, remoteOappAddr)
1453
+ try {
1454
+ return await accounts.PendingInboundNonce.fromAccountAddress(connection, nonce, commitmentOrConfig)
1455
+ } catch (e) {
1456
+ return null
1457
+ }
1458
+ }
1459
+
1460
+ /**
1461
+ * Gets the message library version.
1462
+ *
1463
+ * @param {Connection} connection - The connection to the Solana cluster.
1464
+ * @param {PublicKey} payer - The payer public key.
1465
+ * @param {PublicKey} messageLibProgram - The message library program public key.
1466
+ * @param {Commitment} [commitment='confirmed'] - The commitment level.
1467
+ * @returns {Promise<Version | null>} A promise that resolves to the version or null if not found.
1468
+ */
1469
+ async getMessageLibVersion(
1470
+ connection: Connection,
1471
+ payer: PublicKey,
1472
+ messageLibProgram: PublicKey,
1473
+ commitment: Commitment = 'confirmed'
1474
+ ): Promise<Version | null> {
1475
+ const ix = SimpleMessageLibProgram.instructions.createVersionInstruction(messageLibProgram)
1476
+
1477
+ const simulateResp = await simulateTransaction(connection, [ix], messageLibProgram, payer, commitment)
1478
+ const version = SimpleMessageLibProgram.types.versionBeet.read(simulateResp, 0)
1479
+ return version
1480
+ }
1481
+
1482
+ /**
1483
+ * Transfers the admin role to a new admin.
1484
+ *
1485
+ * @param {Connection} connection - The connection to the Solana cluster.
1486
+ * @param {PublicKey} admin - The current admin public key.
1487
+ * @param {PublicKey} newAdmin - The new admin public key.
1488
+ * @param {Commitment} [commitment='confirmed'] - The commitment level.
1489
+ * @returns {Promise<TransactionInstruction | null>} A promise that resolves to the transaction instruction or null if not needed.
1490
+ */
1491
+ async transferAdmin(
1492
+ connection: Connection,
1493
+ admin: PublicKey,
1494
+ newAdmin: PublicKey,
1495
+ commitment: Commitment = 'confirmed'
1496
+ ): Promise<TransactionInstruction | null> {
1497
+ const [settingPDA] = this.deriver.setting()
1498
+ const endpointSettings = await accounts.EndpointSettings.fromAccountAddress(connection, settingPDA, commitment)
1499
+ if (endpointSettings.admin.toBase58() === newAdmin.toBase58()) {
1500
+ console.warn('endpoint admin not need change')
1501
+ return null
1502
+ }
1503
+ return instructions.createTransferAdminInstruction(
1504
+ {
1505
+ admin,
1506
+ endpoint: settingPDA,
1507
+ eventAuthority: this.eventAuthorityPDA,
1508
+ program: this.program,
1509
+ },
1510
+ {
1511
+ params: {
1512
+ admin: newAdmin,
1513
+ },
1514
+ },
1515
+ this.program
1516
+ )
1517
+ }
1518
+ }