@layerzerolabs/protocol-starknet-v2 0.0.34

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 (504) hide show
  1. package/.turbo/turbo-build.log +186 -0
  2. package/.turbo/turbo-lint.log +71 -0
  3. package/.turbo/turbo-test.log +937 -0
  4. package/README.md +41 -0
  5. package/Scarb.lock +211 -0
  6. package/Scarb.toml +2 -0
  7. package/dist/4XD3ZRZ4.cjs +301 -0
  8. package/dist/4XD3ZRZ4.cjs.map +1 -0
  9. package/dist/4Z5IPBC3.js +299 -0
  10. package/dist/4Z5IPBC3.js.map +1 -0
  11. package/dist/5NEZDLVQ.cjs +474 -0
  12. package/dist/5NEZDLVQ.cjs.map +1 -0
  13. package/dist/6JYCOKDE.js +472 -0
  14. package/dist/6JYCOKDE.js.map +1 -0
  15. package/dist/7C4PFMIZ.cjs +1288 -0
  16. package/dist/7C4PFMIZ.cjs.map +1 -0
  17. package/dist/7ZSGGZUE.js +1229 -0
  18. package/dist/7ZSGGZUE.js.map +1 -0
  19. package/dist/ARHOGUYH.cjs +2136 -0
  20. package/dist/ARHOGUYH.cjs.map +1 -0
  21. package/dist/CRCRIUFX.js +1264 -0
  22. package/dist/CRCRIUFX.js.map +1 -0
  23. package/dist/DB7CQSED.cjs +430 -0
  24. package/dist/DB7CQSED.cjs.map +1 -0
  25. package/dist/DFXLWHYP.cjs +1266 -0
  26. package/dist/DFXLWHYP.cjs.map +1 -0
  27. package/dist/EOLZCMCK.js +988 -0
  28. package/dist/EOLZCMCK.js.map +1 -0
  29. package/dist/FFDPTOWG.cjs +331 -0
  30. package/dist/FFDPTOWG.cjs.map +1 -0
  31. package/dist/FOJGEAIO.js +2134 -0
  32. package/dist/FOJGEAIO.js.map +1 -0
  33. package/dist/IWIUMVGB.js +629 -0
  34. package/dist/IWIUMVGB.js.map +1 -0
  35. package/dist/MUEN6AWV.cjs +697 -0
  36. package/dist/MUEN6AWV.cjs.map +1 -0
  37. package/dist/ORE6VBZ4.cjs +990 -0
  38. package/dist/ORE6VBZ4.cjs.map +1 -0
  39. package/dist/OUFKWPZ7.js +732 -0
  40. package/dist/OUFKWPZ7.js.map +1 -0
  41. package/dist/T2QTYQXJ.js +1229 -0
  42. package/dist/T2QTYQXJ.js.map +1 -0
  43. package/dist/UPJTM7BR.cjs +631 -0
  44. package/dist/UPJTM7BR.cjs.map +1 -0
  45. package/dist/VNVNX2P3.cjs +1231 -0
  46. package/dist/VNVNX2P3.cjs.map +1 -0
  47. package/dist/VUOMXK5T.js +6 -0
  48. package/dist/VUOMXK5T.js.map +1 -0
  49. package/dist/WISWRTDG.js +1286 -0
  50. package/dist/WISWRTDG.js.map +1 -0
  51. package/dist/WU5L7YIQ.cjs +1231 -0
  52. package/dist/WU5L7YIQ.cjs.map +1 -0
  53. package/dist/X3B5JDMZ.js +695 -0
  54. package/dist/X3B5JDMZ.js.map +1 -0
  55. package/dist/XYNBDBBV.cjs +297 -0
  56. package/dist/XYNBDBBV.cjs.map +1 -0
  57. package/dist/Y5JFPCYJ.cjs +734 -0
  58. package/dist/Y5JFPCYJ.cjs.map +1 -0
  59. package/dist/YEHL7IYO.js +295 -0
  60. package/dist/YEHL7IYO.js.map +1 -0
  61. package/dist/YJF4D23A.cjs +8 -0
  62. package/dist/YJF4D23A.cjs.map +1 -0
  63. package/dist/YTS44OEA.js +428 -0
  64. package/dist/YTS44OEA.js.map +1 -0
  65. package/dist/Z2NIUZMW.js +329 -0
  66. package/dist/Z2NIUZMW.js.map +1 -0
  67. package/dist/abis/blocked-message-lib.cjs +13 -0
  68. package/dist/abis/blocked-message-lib.cjs.map +1 -0
  69. package/dist/abis/blocked-message-lib.d.ts +338 -0
  70. package/dist/abis/blocked-message-lib.d.ts.map +1 -0
  71. package/dist/abis/blocked-message-lib.js +4 -0
  72. package/dist/abis/blocked-message-lib.js.map +1 -0
  73. package/dist/abis/dvn-fee-lib.cjs +13 -0
  74. package/dist/abis/dvn-fee-lib.cjs.map +1 -0
  75. package/dist/abis/dvn-fee-lib.d.ts +214 -0
  76. package/dist/abis/dvn-fee-lib.d.ts.map +1 -0
  77. package/dist/abis/dvn-fee-lib.js +4 -0
  78. package/dist/abis/dvn-fee-lib.js.map +1 -0
  79. package/dist/abis/dvn.cjs +13 -0
  80. package/dist/abis/dvn.cjs.map +1 -0
  81. package/dist/abis/dvn.d.ts +952 -0
  82. package/dist/abis/dvn.d.ts.map +1 -0
  83. package/dist/abis/dvn.js +4 -0
  84. package/dist/abis/dvn.js.map +1 -0
  85. package/dist/abis/endpoint-v2.cjs +13 -0
  86. package/dist/abis/endpoint-v2.cjs.map +1 -0
  87. package/dist/abis/endpoint-v2.d.ts +1580 -0
  88. package/dist/abis/endpoint-v2.d.ts.map +1 -0
  89. package/dist/abis/endpoint-v2.js +4 -0
  90. package/dist/abis/endpoint-v2.js.map +1 -0
  91. package/dist/abis/executor-fee-lib.cjs +13 -0
  92. package/dist/abis/executor-fee-lib.cjs.map +1 -0
  93. package/dist/abis/executor-fee-lib.d.ts +217 -0
  94. package/dist/abis/executor-fee-lib.d.ts.map +1 -0
  95. package/dist/abis/executor-fee-lib.js +4 -0
  96. package/dist/abis/executor-fee-lib.js.map +1 -0
  97. package/dist/abis/executor.cjs +13 -0
  98. package/dist/abis/executor.cjs.map +1 -0
  99. package/dist/abis/executor.d.ts +914 -0
  100. package/dist/abis/executor.d.ts.map +1 -0
  101. package/dist/abis/executor.js +4 -0
  102. package/dist/abis/executor.js.map +1 -0
  103. package/dist/abis/o-app.cjs +13 -0
  104. package/dist/abis/o-app.cjs.map +1 -0
  105. package/dist/abis/o-app.d.ts +311 -0
  106. package/dist/abis/o-app.d.ts.map +1 -0
  107. package/dist/abis/o-app.js +4 -0
  108. package/dist/abis/o-app.js.map +1 -0
  109. package/dist/abis/oft-adapter.cjs +13 -0
  110. package/dist/abis/oft-adapter.cjs.map +1 -0
  111. package/dist/abis/oft-adapter.d.ts +722 -0
  112. package/dist/abis/oft-adapter.d.ts.map +1 -0
  113. package/dist/abis/oft-adapter.js +4 -0
  114. package/dist/abis/oft-adapter.js.map +1 -0
  115. package/dist/abis/oft.cjs +13 -0
  116. package/dist/abis/oft.cjs.map +1 -0
  117. package/dist/abis/oft.d.ts +922 -0
  118. package/dist/abis/oft.d.ts.map +1 -0
  119. package/dist/abis/oft.js +4 -0
  120. package/dist/abis/oft.js.map +1 -0
  121. package/dist/abis/omni-counter.cjs +13 -0
  122. package/dist/abis/omni-counter.cjs.map +1 -0
  123. package/dist/abis/omni-counter.d.ts +459 -0
  124. package/dist/abis/omni-counter.d.ts.map +1 -0
  125. package/dist/abis/omni-counter.js +4 -0
  126. package/dist/abis/omni-counter.js.map +1 -0
  127. package/dist/abis/price-feed.cjs +13 -0
  128. package/dist/abis/price-feed.cjs.map +1 -0
  129. package/dist/abis/price-feed.d.ts +505 -0
  130. package/dist/abis/price-feed.d.ts.map +1 -0
  131. package/dist/abis/price-feed.js +4 -0
  132. package/dist/abis/price-feed.js.map +1 -0
  133. package/dist/abis/simple-message-lib.cjs +13 -0
  134. package/dist/abis/simple-message-lib.cjs.map +1 -0
  135. package/dist/abis/simple-message-lib.d.ts +535 -0
  136. package/dist/abis/simple-message-lib.d.ts.map +1 -0
  137. package/dist/abis/simple-message-lib.js +4 -0
  138. package/dist/abis/simple-message-lib.js.map +1 -0
  139. package/dist/abis/treasury.cjs +13 -0
  140. package/dist/abis/treasury.cjs.map +1 -0
  141. package/dist/abis/treasury.d.ts +240 -0
  142. package/dist/abis/treasury.d.ts.map +1 -0
  143. package/dist/abis/treasury.js +4 -0
  144. package/dist/abis/treasury.js.map +1 -0
  145. package/dist/abis/ultra-light-node.cjs +13 -0
  146. package/dist/abis/ultra-light-node.cjs.map +1 -0
  147. package/dist/abis/ultra-light-node.d.ts +900 -0
  148. package/dist/abis/ultra-light-node.d.ts.map +1 -0
  149. package/dist/abis/ultra-light-node.js +4 -0
  150. package/dist/abis/ultra-light-node.js.map +1 -0
  151. package/dist/index.cjs +78 -0
  152. package/dist/index.cjs.map +1 -0
  153. package/dist/index.d.ts +15 -0
  154. package/dist/index.d.ts.map +1 -0
  155. package/dist/index.js +17 -0
  156. package/dist/index.js.map +1 -0
  157. package/dist/scripts/build-abi.cjs +28 -0
  158. package/dist/scripts/build-abi.cjs.map +1 -0
  159. package/dist/scripts/build-abi.d.ts +2 -0
  160. package/dist/scripts/build-abi.d.ts.map +1 -0
  161. package/dist/scripts/build-abi.js +26 -0
  162. package/dist/scripts/build-abi.js.map +1 -0
  163. package/layerzero/README.md +244 -0
  164. package/layerzero/Scarb.lock +203 -0
  165. package/layerzero/Scarb.toml +30 -0
  166. package/layerzero/snfoundry.toml +11 -0
  167. package/layerzero/src/common/constants.cairo +26 -0
  168. package/layerzero/src/common/conversions.cairo +16 -0
  169. package/layerzero/src/common/guid.cairo +20 -0
  170. package/layerzero/src/common/packet_v1_codec.cairo +307 -0
  171. package/layerzero/src/common/structs/messaging.cairo +40 -0
  172. package/layerzero/src/common/structs/packet.cairo +31 -0
  173. package/layerzero/src/endpoint/constants.cairo +14 -0
  174. package/layerzero/src/endpoint/endpoint.cairo +688 -0
  175. package/layerzero/src/endpoint/errors.cairo +108 -0
  176. package/layerzero/src/endpoint/events.cairo +124 -0
  177. package/layerzero/src/endpoint/interfaces/endpoint.cairo +286 -0
  178. package/layerzero/src/endpoint/interfaces/layerzero_composer.cairo +62 -0
  179. package/layerzero/src/endpoint/interfaces/layerzero_receiver.cairo +63 -0
  180. package/layerzero/src/endpoint/message_lib_manager/errors.cairo +95 -0
  181. package/layerzero/src/endpoint/message_lib_manager/events.cairo +90 -0
  182. package/layerzero/src/endpoint/message_lib_manager/interface.cairo +449 -0
  183. package/layerzero/src/endpoint/message_lib_manager/message_lib_manager.cairo +720 -0
  184. package/layerzero/src/endpoint/message_lib_manager/structs.cairo +33 -0
  185. package/layerzero/src/endpoint/messaging_channel/errors.cairo +37 -0
  186. package/layerzero/src/endpoint/messaging_channel/events.cairo +58 -0
  187. package/layerzero/src/endpoint/messaging_channel/interface.cairo +171 -0
  188. package/layerzero/src/endpoint/messaging_channel/messaging_channel.cairo +453 -0
  189. package/layerzero/src/endpoint/messaging_composer/errors.cairo +46 -0
  190. package/layerzero/src/endpoint/messaging_composer/events.cairo +67 -0
  191. package/layerzero/src/endpoint/messaging_composer/interface.cairo +132 -0
  192. package/layerzero/src/endpoint/messaging_composer/messaging_composer.cairo +223 -0
  193. package/layerzero/src/lib.cairo +189 -0
  194. package/layerzero/src/message_lib/blocked_message_lib.cairo +114 -0
  195. package/layerzero/src/message_lib/interface.cairo +63 -0
  196. package/layerzero/src/message_lib/sml/errors.cairo +23 -0
  197. package/layerzero/src/message_lib/sml/events.cairo +32 -0
  198. package/layerzero/src/message_lib/sml/simple_message_lib.cairo +312 -0
  199. package/layerzero/src/message_lib/structs.cairo +22 -0
  200. package/layerzero/src/message_lib/uln/errors.cairo +128 -0
  201. package/layerzero/src/message_lib/uln/events.cairo +97 -0
  202. package/layerzero/src/message_lib/uln/interface.cairo +83 -0
  203. package/layerzero/src/message_lib/uln/options.cairo +64 -0
  204. package/layerzero/src/message_lib/uln/structs/executor_config.cairo +35 -0
  205. package/layerzero/src/message_lib/uln/structs/payment_info.cairo +7 -0
  206. package/layerzero/src/message_lib/uln/structs/uln_config.cairo +155 -0
  207. package/layerzero/src/message_lib/uln/structs/uln_config_storage_node.cairo +91 -0
  208. package/layerzero/src/message_lib/uln/structs/verification.cairo +7 -0
  209. package/layerzero/src/message_lib/uln/ultra_light_node.cairo +965 -0
  210. package/layerzero/src/oapps/common/oapp_options_type_3/errors.cairo +22 -0
  211. package/layerzero/src/oapps/common/oapp_options_type_3/events.cairo +6 -0
  212. package/layerzero/src/oapps/common/oapp_options_type_3/interface.cairo +34 -0
  213. package/layerzero/src/oapps/common/oapp_options_type_3/oapp_options_type_3.cairo +120 -0
  214. package/layerzero/src/oapps/common/oapp_options_type_3/structs.cairo +6 -0
  215. package/layerzero/src/oapps/counter/constants.cairo +3 -0
  216. package/layerzero/src/oapps/counter/counter.cairo +170 -0
  217. package/layerzero/src/oapps/counter/interface.cairo +27 -0
  218. package/layerzero/src/oapps/counter/structs.cairo +20 -0
  219. package/layerzero/src/oapps/message_inspector/interface.cairo +21 -0
  220. package/layerzero/src/oapps/oapp/errors.cairo +72 -0
  221. package/layerzero/src/oapps/oapp/events.cairo +9 -0
  222. package/layerzero/src/oapps/oapp/interface.cairo +67 -0
  223. package/layerzero/src/oapps/oapp/oapp.cairo +70 -0
  224. package/layerzero/src/oapps/oapp/oapp_core.cairo +448 -0
  225. package/layerzero/src/oapps/oft/errors.cairo +42 -0
  226. package/layerzero/src/oapps/oft/events.cairo +33 -0
  227. package/layerzero/src/oapps/oft/interface.cairo +87 -0
  228. package/layerzero/src/oapps/oft/oft.cairo +188 -0
  229. package/layerzero/src/oapps/oft/oft_adapter.cairo +175 -0
  230. package/layerzero/src/oapps/oft/oft_compose_msg_codec.cairo +128 -0
  231. package/layerzero/src/oapps/oft/oft_core.cairo +542 -0
  232. package/layerzero/src/oapps/oft/oft_msg_codec.cairo +131 -0
  233. package/layerzero/src/oapps/oft/structs.cairo +72 -0
  234. package/layerzero/src/treasury/errors.cairo +22 -0
  235. package/layerzero/src/treasury/events.cairo +5 -0
  236. package/layerzero/src/treasury/interfaces/layerzero_treasury.cairo +54 -0
  237. package/layerzero/src/treasury/interfaces/lz_token_fee_lib.cairo +45 -0
  238. package/layerzero/src/treasury/interfaces/treasury_admin.cairo +39 -0
  239. package/layerzero/src/treasury/treasury.cairo +140 -0
  240. package/layerzero/src/workers/access_control.cairo +11 -0
  241. package/layerzero/src/workers/base/base.cairo +238 -0
  242. package/layerzero/src/workers/base/errors.cairo +24 -0
  243. package/layerzero/src/workers/base/events.cairo +43 -0
  244. package/layerzero/src/workers/base/interface.cairo +93 -0
  245. package/layerzero/src/workers/base/structs.cairo +10 -0
  246. package/layerzero/src/workers/common.cairo +59 -0
  247. package/layerzero/src/workers/dvn/constants.cairo +11 -0
  248. package/layerzero/src/workers/dvn/dvn.cairo +338 -0
  249. package/layerzero/src/workers/dvn/errors.cairo +80 -0
  250. package/layerzero/src/workers/dvn/events.cairo +30 -0
  251. package/layerzero/src/workers/dvn/fee_lib/dvn_fee_lib.cairo +152 -0
  252. package/layerzero/src/workers/dvn/fee_lib/interface.cairo +45 -0
  253. package/layerzero/src/workers/dvn/interface.cairo +131 -0
  254. package/layerzero/src/workers/dvn/options.cairo +125 -0
  255. package/layerzero/src/workers/dvn/structs.cairo +51 -0
  256. package/layerzero/src/workers/executor/errors.cairo +159 -0
  257. package/layerzero/src/workers/executor/events.cairo +32 -0
  258. package/layerzero/src/workers/executor/executor.cairo +392 -0
  259. package/layerzero/src/workers/executor/fee_lib/executor_fee_lib.cairo +160 -0
  260. package/layerzero/src/workers/executor/fee_lib/interface.cairo +87 -0
  261. package/layerzero/src/workers/executor/interface.cairo +131 -0
  262. package/layerzero/src/workers/executor/options.cairo +244 -0
  263. package/layerzero/src/workers/executor/structs.cairo +119 -0
  264. package/layerzero/src/workers/interface.cairo +32 -0
  265. package/layerzero/src/workers/price_feed/constants.cairo +7 -0
  266. package/layerzero/src/workers/price_feed/errors.cairo +28 -0
  267. package/layerzero/src/workers/price_feed/events.cairo +13 -0
  268. package/layerzero/src/workers/price_feed/interface.cairo +264 -0
  269. package/layerzero/src/workers/price_feed/price_feed.cairo +392 -0
  270. package/layerzero/src/workers/price_feed/structs.cairo +74 -0
  271. package/layerzero/tests/common/test_constants.cairo +21 -0
  272. package/layerzero/tests/common/test_guid.cairo +232 -0
  273. package/layerzero/tests/common/test_packet_v1_codec.cairo +372 -0
  274. package/layerzero/tests/common/utils.cairo +23 -0
  275. package/layerzero/tests/e2e/oft_utils.cairo +121 -0
  276. package/layerzero/tests/e2e/test_counter_with_sml.cairo +194 -0
  277. package/layerzero/tests/e2e/test_counter_with_uln.cairo +352 -0
  278. package/layerzero/tests/e2e/test_dvn.cairo +406 -0
  279. package/layerzero/tests/e2e/test_lz_token.cairo +354 -0
  280. package/layerzero/tests/e2e/test_oft_compose_with_uln.cairo +364 -0
  281. package/layerzero/tests/e2e/test_oft_with_sml.cairo +240 -0
  282. package/layerzero/tests/e2e/test_oft_with_uln.cairo +299 -0
  283. package/layerzero/tests/e2e/utils.cairo +490 -0
  284. package/layerzero/tests/endpoint/message_lib_manager/test_message_lib_manager.cairo +2051 -0
  285. package/layerzero/tests/endpoint/message_lib_manager/utils.cairo +45 -0
  286. package/layerzero/tests/endpoint/messaging_channel/test_messaging_channel.cairo +621 -0
  287. package/layerzero/tests/endpoint/messaging_channel/utils.cairo +96 -0
  288. package/layerzero/tests/endpoint/messaging_composer/test_messaging_composer.cairo +456 -0
  289. package/layerzero/tests/endpoint/messaging_composer/utils.cairo +75 -0
  290. package/layerzero/tests/endpoint/test_endpoint_commit.cairo +763 -0
  291. package/layerzero/tests/endpoint/test_endpoint_lzreceive.cairo +1253 -0
  292. package/layerzero/tests/endpoint/test_endpoint_quote.cairo +71 -0
  293. package/layerzero/tests/endpoint/test_endpoint_send.cairo +1327 -0
  294. package/layerzero/tests/endpoint/utils.cairo +129 -0
  295. package/layerzero/tests/fuzzable/blockchain_config.cairo +89 -0
  296. package/layerzero/tests/fuzzable/bytes32.cairo +16 -0
  297. package/layerzero/tests/fuzzable/contract_address.cairo +67 -0
  298. package/layerzero/tests/fuzzable/dst_config.cairo +37 -0
  299. package/layerzero/tests/fuzzable/eid.cairo +23 -0
  300. package/layerzero/tests/fuzzable/eth_address.cairo +17 -0
  301. package/layerzero/tests/fuzzable/expiry.cairo +27 -0
  302. package/layerzero/tests/fuzzable/felt_array.cairo +38 -0
  303. package/layerzero/tests/fuzzable/inbound_params.cairo +21 -0
  304. package/layerzero/tests/fuzzable/keys.cairo +16 -0
  305. package/layerzero/tests/fuzzable/model_type.cairo +27 -0
  306. package/layerzero/tests/fuzzable/origin.cairo +21 -0
  307. package/layerzero/tests/fuzzable/price.cairo +32 -0
  308. package/layerzero/tests/fuzzable/role_admin.cairo +29 -0
  309. package/layerzero/tests/fuzzable/small_byte_array.cairo +61 -0
  310. package/layerzero/tests/lib.cairo +177 -0
  311. package/layerzero/tests/message_lib/sml/test_simple_message_lib.cairo +224 -0
  312. package/layerzero/tests/message_lib/uln/test_uln_admin.cairo +2150 -0
  313. package/layerzero/tests/message_lib/uln/test_uln_config.cairo +527 -0
  314. package/layerzero/tests/message_lib/uln/test_uln_config_storage_node.cairo +69 -0
  315. package/layerzero/tests/message_lib/uln/test_uln_executor_config.cairo +173 -0
  316. package/layerzero/tests/message_lib/uln/test_uln_options.cairo +329 -0
  317. package/layerzero/tests/message_lib/uln/test_uln_quote.cairo +1038 -0
  318. package/layerzero/tests/message_lib/uln/test_uln_receive.cairo +715 -0
  319. package/layerzero/tests/message_lib/uln/test_uln_send.cairo +1155 -0
  320. package/layerzero/tests/message_lib/uln/utils.cairo +59 -0
  321. package/layerzero/tests/mocks/composer_target.cairo +76 -0
  322. package/layerzero/tests/mocks/endpoint.cairo +199 -0
  323. package/layerzero/tests/mocks/erc20/erc20.cairo +50 -0
  324. package/layerzero/tests/mocks/erc20/interface.cairo +8 -0
  325. package/layerzero/tests/mocks/message_inspector/message_inspector.cairo +17 -0
  326. package/layerzero/tests/mocks/message_lib_manager.cairo +98 -0
  327. package/layerzero/tests/mocks/messaging_channel/interface.cairo +23 -0
  328. package/layerzero/tests/mocks/messaging_channel/messaging_channel.cairo +138 -0
  329. package/layerzero/tests/mocks/messaging_composer.cairo +171 -0
  330. package/layerzero/tests/mocks/oapp_core/interface.cairo +53 -0
  331. package/layerzero/tests/mocks/oapp_core/oapp_core.cairo +142 -0
  332. package/layerzero/tests/mocks/oapp_options_type3.cairo +42 -0
  333. package/layerzero/tests/mocks/oft_core/interface.cairo +28 -0
  334. package/layerzero/tests/mocks/oft_core/oft_core.cairo +242 -0
  335. package/layerzero/tests/mocks/receiver.cairo +54 -0
  336. package/layerzero/tests/mocks/treasury/lz_token_fee_lib.cairo +57 -0
  337. package/layerzero/tests/mocks/treasury/treasury.cairo +74 -0
  338. package/layerzero/tests/mocks/uln_config/interface.cairo +12 -0
  339. package/layerzero/tests/mocks/uln_config/uln_config.cairo +35 -0
  340. package/layerzero/tests/mocks/workers/base.cairo +80 -0
  341. package/layerzero/tests/mocks/workers/dvn.cairo +115 -0
  342. package/layerzero/tests/mocks/workers/executor/decode/decode.cairo +97 -0
  343. package/layerzero/tests/mocks/workers/executor/decode/interface.cairo +59 -0
  344. package/layerzero/tests/mocks/workers/executor/executor.cairo +176 -0
  345. package/layerzero/tests/oapps/common/test_oapp_options_type_3.cairo +279 -0
  346. package/layerzero/tests/oapps/oft/test_oft_adapter.cairo +441 -0
  347. package/layerzero/tests/oapps/oft/test_oft_compose_msg_codec.cairo +139 -0
  348. package/layerzero/tests/oapps/oft/test_oft_core.cairo +751 -0
  349. package/layerzero/tests/oapps/oft/test_oft_msg_codec.cairo +268 -0
  350. package/layerzero/tests/oapps/test_counter.cairo +470 -0
  351. package/layerzero/tests/oapps/test_oapp_core.cairo +750 -0
  352. package/layerzero/tests/treasury/test_lz_token_fee_lib.cairo +63 -0
  353. package/layerzero/tests/treasury/test_treasury.cairo +458 -0
  354. package/layerzero/tests/treasury/utils.cairo +8 -0
  355. package/layerzero/tests/utils.cairo +48 -0
  356. package/layerzero/tests/workers/base/test_worker_base.cairo +1097 -0
  357. package/layerzero/tests/workers/base/utils.cairo +76 -0
  358. package/layerzero/tests/workers/dvn/fee_lib/test_dvn_fee_lib.cairo +361 -0
  359. package/layerzero/tests/workers/dvn/test_dvn.cairo +1101 -0
  360. package/layerzero/tests/workers/dvn/test_dvn_options.cairo +312 -0
  361. package/layerzero/tests/workers/dvn/utils.cairo +236 -0
  362. package/layerzero/tests/workers/executor/fee_lib/test_executor_fee_lib.cairo +223 -0
  363. package/layerzero/tests/workers/executor/test_decode.cairo +612 -0
  364. package/layerzero/tests/workers/executor/test_executor.cairo +1472 -0
  365. package/layerzero/tests/workers/executor/utils.cairo +296 -0
  366. package/layerzero/tests/workers/price_feed/test_price_feed.cairo +879 -0
  367. package/layerzero/tests/workers/price_feed/utils.cairo +37 -0
  368. package/libs/enumerable_set/Scarb.lock +24 -0
  369. package/libs/enumerable_set/Scarb.toml +17 -0
  370. package/libs/enumerable_set/src/enumerable_set.cairo +118 -0
  371. package/libs/enumerable_set/src/lib.cairo +4 -0
  372. package/libs/enumerable_set/tests/lib.cairo +5 -0
  373. package/libs/enumerable_set/tests/mocks/mock_enumerable_set.cairo +61 -0
  374. package/libs/enumerable_set/tests/test_enumerable_set.cairo +379 -0
  375. package/libs/lz_utils/Scarb.lock +24 -0
  376. package/libs/lz_utils/Scarb.toml +17 -0
  377. package/libs/lz_utils/src/bytes.cairo +33 -0
  378. package/libs/lz_utils/src/error.cairo +12 -0
  379. package/libs/lz_utils/src/keccak.cairo +28 -0
  380. package/libs/lz_utils/src/lib.cairo +3 -0
  381. package/libs/multisig/Scarb.lock +172 -0
  382. package/libs/multisig/Scarb.toml +23 -0
  383. package/libs/multisig/src/errors.cairo +84 -0
  384. package/libs/multisig/src/events.cairo +13 -0
  385. package/libs/multisig/src/interface.cairo +73 -0
  386. package/libs/multisig/src/lib.cairo +7 -0
  387. package/libs/multisig/src/multisig.cairo +241 -0
  388. package/libs/multisig/tests/lib.cairo +4 -0
  389. package/libs/multisig/tests/mocks/mock_multisig.cairo +57 -0
  390. package/libs/multisig/tests/test_multisig.cairo +452 -0
  391. package/package.json +41 -0
  392. package/src/scripts/build-abi.ts +51 -0
  393. package/target/CACHEDIR.TAG +3 -0
  394. package/target/dev/.fingerprint/alexandria_bytes-5ea6u5t70d7qi/alexandria_bytes +1 -0
  395. package/target/dev/.fingerprint/alexandria_data_structures-0aue3g6q80gs0/alexandria_data_structures +1 -0
  396. package/target/dev/.fingerprint/alexandria_math-h2fi7jdq4isuu/alexandria_math +1 -0
  397. package/target/dev/.fingerprint/core-lq3u730l5p1ag/core +1 -0
  398. package/target/dev/.fingerprint/core-vf7fc6rvic5vi/core +1 -0
  399. package/target/dev/.fingerprint/enumerable_set-eaerkg8njl85o/enumerable_set +1 -0
  400. package/target/dev/.fingerprint/enumerable_set-r54oje7t06ku8/enumerable_set +1 -0
  401. package/target/dev/.fingerprint/layerzero-oqgdqsaddpi2k/layerzero +1 -0
  402. package/target/dev/.fingerprint/lz_utils-kfkkeueiqg0pa/lz_utils +1 -0
  403. package/target/dev/.fingerprint/lz_utils-u4v1os6e7gkng/lz_utils +1 -0
  404. package/target/dev/.fingerprint/multisig-0fjetugejecge/multisig +1 -0
  405. package/target/dev/.fingerprint/multisig-6j5kqs436hm54/multisig +1 -0
  406. package/target/dev/.fingerprint/openzeppelin-ei1id1hu088lo/openzeppelin +1 -0
  407. package/target/dev/.fingerprint/openzeppelin-j9d5nd1qhfnu6/openzeppelin +1 -0
  408. package/target/dev/.fingerprint/openzeppelin_access-3oa41aikpaek0/openzeppelin_access +1 -0
  409. package/target/dev/.fingerprint/openzeppelin_access-p5h849v8so76q/openzeppelin_access +1 -0
  410. package/target/dev/.fingerprint/openzeppelin_account-4qhv5fks84g9u/openzeppelin_account +1 -0
  411. package/target/dev/.fingerprint/openzeppelin_account-hgbm8ln9ah7rm/openzeppelin_account +1 -0
  412. package/target/dev/.fingerprint/openzeppelin_finance-n70q9al0cps8i/openzeppelin_finance +1 -0
  413. package/target/dev/.fingerprint/openzeppelin_finance-nnd4f8703t3ak/openzeppelin_finance +1 -0
  414. package/target/dev/.fingerprint/openzeppelin_governance-3gnk21ubp5lis/openzeppelin_governance +1 -0
  415. package/target/dev/.fingerprint/openzeppelin_governance-rj1bfont4fij4/openzeppelin_governance +1 -0
  416. package/target/dev/.fingerprint/openzeppelin_introspection-3fja9hd1gvbcq/openzeppelin_introspection +1 -0
  417. package/target/dev/.fingerprint/openzeppelin_introspection-jc3nf5525eet6/openzeppelin_introspection +1 -0
  418. package/target/dev/.fingerprint/openzeppelin_merkle_tree-4en77ogr2r2l2/openzeppelin_merkle_tree +1 -0
  419. package/target/dev/.fingerprint/openzeppelin_merkle_tree-4t190frqs4db8/openzeppelin_merkle_tree +1 -0
  420. package/target/dev/.fingerprint/openzeppelin_presets-aqb0f6p9c0bp6/openzeppelin_presets +1 -0
  421. package/target/dev/.fingerprint/openzeppelin_presets-nseg8korhin8e/openzeppelin_presets +1 -0
  422. package/target/dev/.fingerprint/openzeppelin_security-g7p73ji1ih1qg/openzeppelin_security +1 -0
  423. package/target/dev/.fingerprint/openzeppelin_security-qp5328v80452u/openzeppelin_security +1 -0
  424. package/target/dev/.fingerprint/openzeppelin_token-jjf7tl9rphc6k/openzeppelin_token +1 -0
  425. package/target/dev/.fingerprint/openzeppelin_token-r6s43vlpj6rqk/openzeppelin_token +1 -0
  426. package/target/dev/.fingerprint/openzeppelin_upgrades-0dpbnre7engca/openzeppelin_upgrades +1 -0
  427. package/target/dev/.fingerprint/openzeppelin_upgrades-2sqgvbuv9s800/openzeppelin_upgrades +1 -0
  428. package/target/dev/.fingerprint/openzeppelin_utils-mj395ivff1ffo/openzeppelin_utils +1 -0
  429. package/target/dev/.fingerprint/openzeppelin_utils-oh1hse8sjumgm/openzeppelin_utils +1 -0
  430. package/target/dev/.fingerprint/starkware_utils-1qnnjnq0pf9u0/starkware_utils +1 -0
  431. package/target/dev/.fingerprint/starkware_utils-mh8e3te65lju4/starkware_utils +1 -0
  432. package/target/dev/enumerable_set.sierra.json +1 -0
  433. package/target/dev/incremental/alexandria_bytes-5ea6u5t70d7qi.bin +0 -0
  434. package/target/dev/incremental/alexandria_data_structures-0aue3g6q80gs0.bin +0 -0
  435. package/target/dev/incremental/alexandria_math-h2fi7jdq4isuu.bin +0 -0
  436. package/target/dev/incremental/core-lq3u730l5p1ag.bin +0 -0
  437. package/target/dev/incremental/core-vf7fc6rvic5vi.bin +0 -0
  438. package/target/dev/incremental/enumerable_set-eaerkg8njl85o.bin +0 -0
  439. package/target/dev/incremental/enumerable_set-r54oje7t06ku8.bin +0 -0
  440. package/target/dev/incremental/layerzero-oqgdqsaddpi2k.bin +0 -0
  441. package/target/dev/incremental/lz_utils-kfkkeueiqg0pa.bin +0 -0
  442. package/target/dev/incremental/lz_utils-u4v1os6e7gkng.bin +0 -0
  443. package/target/dev/incremental/multisig-0fjetugejecge.bin +0 -0
  444. package/target/dev/incremental/multisig-6j5kqs436hm54.bin +0 -0
  445. package/target/dev/incremental/openzeppelin-ei1id1hu088lo.bin +0 -0
  446. package/target/dev/incremental/openzeppelin-j9d5nd1qhfnu6.bin +0 -0
  447. package/target/dev/incremental/openzeppelin_access-3oa41aikpaek0.bin +0 -0
  448. package/target/dev/incremental/openzeppelin_access-p5h849v8so76q.bin +0 -0
  449. package/target/dev/incremental/openzeppelin_account-4qhv5fks84g9u.bin +0 -0
  450. package/target/dev/incremental/openzeppelin_account-hgbm8ln9ah7rm.bin +0 -0
  451. package/target/dev/incremental/openzeppelin_finance-n70q9al0cps8i.bin +0 -0
  452. package/target/dev/incremental/openzeppelin_finance-nnd4f8703t3ak.bin +0 -0
  453. package/target/dev/incremental/openzeppelin_governance-3gnk21ubp5lis.bin +0 -0
  454. package/target/dev/incremental/openzeppelin_governance-rj1bfont4fij4.bin +0 -0
  455. package/target/dev/incremental/openzeppelin_introspection-3fja9hd1gvbcq.bin +0 -0
  456. package/target/dev/incremental/openzeppelin_introspection-jc3nf5525eet6.bin +0 -0
  457. package/target/dev/incremental/openzeppelin_merkle_tree-4en77ogr2r2l2.bin +0 -0
  458. package/target/dev/incremental/openzeppelin_merkle_tree-4t190frqs4db8.bin +0 -0
  459. package/target/dev/incremental/openzeppelin_presets-aqb0f6p9c0bp6.bin +0 -0
  460. package/target/dev/incremental/openzeppelin_presets-nseg8korhin8e.bin +0 -0
  461. package/target/dev/incremental/openzeppelin_security-g7p73ji1ih1qg.bin +0 -0
  462. package/target/dev/incremental/openzeppelin_security-qp5328v80452u.bin +0 -0
  463. package/target/dev/incremental/openzeppelin_token-jjf7tl9rphc6k.bin +0 -0
  464. package/target/dev/incremental/openzeppelin_token-r6s43vlpj6rqk.bin +0 -0
  465. package/target/dev/incremental/openzeppelin_upgrades-0dpbnre7engca.bin +0 -0
  466. package/target/dev/incremental/openzeppelin_upgrades-2sqgvbuv9s800.bin +0 -0
  467. package/target/dev/incremental/openzeppelin_utils-mj395ivff1ffo.bin +0 -0
  468. package/target/dev/incremental/openzeppelin_utils-oh1hse8sjumgm.bin +0 -0
  469. package/target/dev/incremental/starkware_utils-1qnnjnq0pf9u0.bin +0 -0
  470. package/target/dev/incremental/starkware_utils-mh8e3te65lju4.bin +0 -0
  471. package/target/dev/layerzero.starknet_artifacts.json +1 -0
  472. package/target/dev/layerzero_BlockedMessageLib.compiled_contract_class.json +1 -0
  473. package/target/dev/layerzero_BlockedMessageLib.contract_class.json +1 -0
  474. package/target/dev/layerzero_Dvn.compiled_contract_class.json +1 -0
  475. package/target/dev/layerzero_Dvn.contract_class.json +1 -0
  476. package/target/dev/layerzero_DvnFeeLib.compiled_contract_class.json +1 -0
  477. package/target/dev/layerzero_DvnFeeLib.contract_class.json +1 -0
  478. package/target/dev/layerzero_Endpoint.compiled_contract_class.json +1 -0
  479. package/target/dev/layerzero_Endpoint.contract_class.json +1 -0
  480. package/target/dev/layerzero_Executor.compiled_contract_class.json +1 -0
  481. package/target/dev/layerzero_Executor.contract_class.json +1 -0
  482. package/target/dev/layerzero_ExecutorFeeLib.compiled_contract_class.json +1 -0
  483. package/target/dev/layerzero_ExecutorFeeLib.contract_class.json +1 -0
  484. package/target/dev/layerzero_OApp.compiled_contract_class.json +1 -0
  485. package/target/dev/layerzero_OApp.contract_class.json +1 -0
  486. package/target/dev/layerzero_OFT.compiled_contract_class.json +1 -0
  487. package/target/dev/layerzero_OFT.contract_class.json +1 -0
  488. package/target/dev/layerzero_OFTAdapter.compiled_contract_class.json +1 -0
  489. package/target/dev/layerzero_OFTAdapter.contract_class.json +1 -0
  490. package/target/dev/layerzero_OmniCounter.compiled_contract_class.json +1 -0
  491. package/target/dev/layerzero_OmniCounter.contract_class.json +1 -0
  492. package/target/dev/layerzero_PriceFeed.compiled_contract_class.json +1 -0
  493. package/target/dev/layerzero_PriceFeed.contract_class.json +1 -0
  494. package/target/dev/layerzero_SimpleMessageLib.compiled_contract_class.json +1 -0
  495. package/target/dev/layerzero_SimpleMessageLib.contract_class.json +1 -0
  496. package/target/dev/layerzero_Treasury.compiled_contract_class.json +1 -0
  497. package/target/dev/layerzero_Treasury.contract_class.json +1 -0
  498. package/target/dev/layerzero_UltraLightNode.compiled_contract_class.json +1 -0
  499. package/target/dev/layerzero_UltraLightNode.contract_class.json +1 -0
  500. package/target/dev/lz_utils.sierra.json +1 -0
  501. package/target/dev/multisig.sierra.json +1 -0
  502. package/tools/update_contracts.sh +19 -0
  503. package/tsconfig.json +20 -0
  504. package/tsup.config.ts +7 -0
@@ -0,0 +1,965 @@
1
+ //! Ultra light node component implementation
2
+
3
+ #[starknet::contract]
4
+ pub mod UltraLightNode {
5
+ use core::dict::Felt252DictEntryTrait;
6
+ use lz_utils::bytes::Bytes32;
7
+ use lz_utils::keccak::keccak256;
8
+ use openzeppelin::access::ownable::OwnableComponent;
9
+ use starknet::storage::{
10
+ Map, Mutable, StoragePath, StoragePathEntry, StoragePointerReadAccess,
11
+ StoragePointerWriteAccess,
12
+ };
13
+ use starknet::{ContractAddress, get_caller_address, get_contract_address};
14
+ use starkware_utils::errors::assert_with_byte_array;
15
+ use crate::common::constants::ZERO_ADDRESS;
16
+ use crate::common::packet_v1_codec::PacketV1Codec;
17
+ use crate::common::structs::messaging::{
18
+ MessageLibSendResult, MessageReceipt, MessagingFee, Payee,
19
+ };
20
+ use crate::common::structs::packet::{Origin, Packet, PacketHeader};
21
+ use crate::endpoint::interfaces::endpoint::{IEndpointDispatcher, IEndpointDispatcherTrait};
22
+ use crate::endpoint::messaging_channel::interface::{
23
+ IMessagingChannelDispatcher, IMessagingChannelDispatcherTrait,
24
+ };
25
+ use crate::message_lib::interface::{IMessageLib, VerificationState};
26
+ use crate::message_lib::structs::{MessageLibType, SetConfigParam};
27
+ use crate::message_lib::uln::errors::{
28
+ err_caller_not_endpoint, err_invalid_config_type, err_invalid_confirmations,
29
+ err_invalid_treasury_native_fee_cap, err_message_too_large, err_uln_verifying,
30
+ err_unsupported_receive_eid, err_unsupported_send_eid,
31
+ };
32
+ use crate::message_lib::uln::events::{
33
+ DefaultExecutorConfigSet, DefaultUlnReceiveConfigSet, DefaultUlnSendConfigSet, DvnFeesPaid,
34
+ ExecutorFeePaid, OAppExecutorConfigSet, OAppUlnReceiveConfigSet, OAppUlnSendConfigSet,
35
+ PayloadVerified, TreasuryFeePaid, TreasuryNativeFeeCapSet,
36
+ };
37
+ use crate::message_lib::uln::interface::IUltraLightNodeAdmin;
38
+ use crate::message_lib::uln::options::split_options;
39
+ use crate::message_lib::uln::structs::executor_config::{
40
+ ExecutorConfig, ExecutorConfigResolverImpl,
41
+ };
42
+ use crate::message_lib::uln::structs::payment_info::DvnPaymentInfo;
43
+ use crate::message_lib::uln::structs::uln_config::{
44
+ SetDefaultUlnConfigParam, UlnConfig, UlnConfigUtilsImpl,
45
+ };
46
+ use crate::message_lib::uln::structs::uln_config_storage_node::{
47
+ UlnConfigStorageNode, UlnConfigStorageNodeTrait,
48
+ };
49
+ use crate::message_lib::uln::structs::verification::Verification;
50
+ use crate::treasury::interfaces::layerzero_treasury::{
51
+ ILayerZeroTreasuryDispatcher, ILayerZeroTreasuryDispatcherTrait,
52
+ };
53
+ use crate::workers::base::structs::QuoteParams;
54
+ use crate::workers::dvn::options::group_dvn_options_by_idx;
55
+ use crate::workers::interface::{ILayerZeroWorkerDispatcher, ILayerZeroWorkerDispatcherTrait};
56
+
57
+ // Default configuration address
58
+ const DEFAULT_CONFIG: ContractAddress = ZERO_ADDRESS;
59
+
60
+ // Config type constants
61
+ pub const CONFIG_TYPE_EXECUTOR: u32 = 1;
62
+ pub const CONFIG_TYPE_ULN: u32 = 2;
63
+
64
+ // Empty verification, equivalent to Default::default() but more explicit
65
+ pub const EMPTY_VERIFICATION: Verification = Verification {
66
+ submitted: false, confirmations: 0,
67
+ };
68
+
69
+ component!(path: OwnableComponent, storage: ownable, event: OwnableEvent);
70
+
71
+ // Ownable Mixin
72
+ #[abi(embed_v0)]
73
+ impl OwnableImpl = OwnableComponent::OwnableImpl<ContractState>;
74
+ impl OwnableInternalImpl = OwnableComponent::InternalImpl<ContractState>;
75
+
76
+ #[storage]
77
+ struct Storage {
78
+ #[substorage(v0)]
79
+ ownable: OwnableComponent::Storage,
80
+ // Send-side storage items:
81
+ // sender => dst_eid => UlnConfig
82
+ send_configs: Map<ContractAddress, Map<u32, UlnConfigStorageNode>>,
83
+ executor_configs: Map<ContractAddress, Map<u32, ExecutorConfig>>,
84
+ treasury: ContractAddress,
85
+ endpoint: ContractAddress,
86
+ treasury_native_fee_cap: u256,
87
+ // Receive-side storage items:
88
+ // headerHash => payloadHash => dvn => Verification
89
+ hash_lookup: Map<Bytes32, Map<Bytes32, Map<ContractAddress, Verification>>>,
90
+ // receiver => src_eid => UlnConfig
91
+ receive_configs: Map<ContractAddress, Map<u32, UlnConfigStorageNode>>,
92
+ }
93
+
94
+ #[event]
95
+ #[derive(Drop, starknet::Event)]
96
+ pub enum Event {
97
+ #[flat]
98
+ OwnableEvent: OwnableComponent::Event,
99
+ DefaultUlnSendConfigSet: DefaultUlnSendConfigSet,
100
+ DefaultUlnReceiveConfigSet: DefaultUlnReceiveConfigSet,
101
+ OAppUlnSendConfigSet: OAppUlnSendConfigSet,
102
+ OAppUlnReceiveConfigSet: OAppUlnReceiveConfigSet,
103
+ DefaultExecutorConfigSet: DefaultExecutorConfigSet,
104
+ OAppExecutorConfigSet: OAppExecutorConfigSet,
105
+ DvnFeesPaid: DvnFeesPaid,
106
+ ExecutorFeePaid: ExecutorFeePaid,
107
+ TreasuryFeePaid: TreasuryFeePaid,
108
+ TreasuryNativeFeeCapSet: TreasuryNativeFeeCapSet,
109
+ PayloadVerified: PayloadVerified,
110
+ }
111
+
112
+ #[constructor]
113
+ fn constructor(
114
+ ref self: ContractState,
115
+ owner: ContractAddress,
116
+ treasury: ContractAddress,
117
+ endpoint: ContractAddress,
118
+ treasury_native_fee_cap: u256,
119
+ ) {
120
+ self.ownable.initializer(owner);
121
+ self.treasury.write(treasury);
122
+ self.endpoint.write(endpoint);
123
+ self.treasury_native_fee_cap.write(treasury_native_fee_cap);
124
+ }
125
+
126
+ #[derive(Drop, PartialEq, Copy)]
127
+ enum WorkerOperationType {
128
+ Quote,
129
+ Pay,
130
+ }
131
+
132
+ #[abi(embed_v0)]
133
+ impl UltraLightNodeImpl of IMessageLib<ContractState> {
134
+ fn send(
135
+ ref self: ContractState, packet: Packet, options: ByteArray, pay_in_lz_token: bool,
136
+ ) -> MessageLibSendResult {
137
+ // Assert onlyEndpoint
138
+ self._assert_only_endpoint();
139
+ let sender = packet.sender;
140
+
141
+ let (executor_options, dvn_options) = split_options(@options);
142
+ let uln_config = self.get_oapp_uln_send_config(packet.sender, packet.dst_eid);
143
+
144
+ let packet_header = PacketHeader {
145
+ nonce: packet.nonce,
146
+ src_eid: packet.src_eid,
147
+ sender: packet.sender,
148
+ dst_eid: packet.dst_eid,
149
+ receiver: packet.receiver,
150
+ };
151
+
152
+ // pay DVNs
153
+ let DvnPaymentInfo {
154
+ mut payees, mut total_native_fee,
155
+ } = self._pay_dvns(@uln_config, dvn_options, @packet);
156
+ self
157
+ .emit(
158
+ DvnFeesPaid {
159
+ oapp: sender, payees: payees.clone(), packet_header: packet_header.clone(),
160
+ },
161
+ );
162
+
163
+ // pay executor
164
+ let executor_payee = self._pay_executor(@uln_config, executor_options, @packet);
165
+ total_native_fee += executor_payee.native_amount;
166
+ payees.append(executor_payee.clone());
167
+ self
168
+ .emit(
169
+ ExecutorFeePaid {
170
+ oapp: sender, payee: executor_payee, packet_header: packet_header.clone(),
171
+ },
172
+ );
173
+
174
+ // pay treasury
175
+ let treasury_payee = self._pay_treasury(@packet, total_native_fee, pay_in_lz_token);
176
+ payees.append(treasury_payee.clone());
177
+ self.emit(TreasuryFeePaid { oapp: sender, payee: treasury_payee, packet_header });
178
+
179
+ MessageLibSendResult {
180
+ message_receipt: MessageReceipt { guid: packet.guid, nonce: packet.nonce, payees },
181
+ encoded_packet: PacketV1Codec::encode(@packet),
182
+ }
183
+ }
184
+
185
+ fn verify(
186
+ ref self: ContractState,
187
+ packet_header: ByteArray,
188
+ payload_hash: Bytes32,
189
+ confirmations: u64,
190
+ ) {
191
+ let dvn = get_caller_address();
192
+ let header_hash = keccak256(@packet_header);
193
+
194
+ // Store the verification: hashLookup[headerHash][payloadHash][dvn] = Verification
195
+ self
196
+ ._hash_lookup_entry(header_hash, payload_hash, dvn)
197
+ .write(Verification { submitted: true, confirmations });
198
+
199
+ // Emit PayloadVerified event
200
+ self
201
+ .emit(
202
+ PayloadVerified {
203
+ dvn,
204
+ header: packet_header,
205
+ confirmations: confirmations.into(),
206
+ proof_hash: payload_hash,
207
+ },
208
+ );
209
+ }
210
+
211
+ fn commit(ref self: ContractState, packet_header: ByteArray, payload_hash: Bytes32) {
212
+ let endpoint_dispatcher = IEndpointDispatcher {
213
+ contract_address: self.endpoint.read(),
214
+ };
215
+
216
+ // Validate the packet header
217
+ PacketV1Codec::assert_header(@packet_header, endpoint_dispatcher.get_eid());
218
+
219
+ // Extract receiver and src_eid from packet header
220
+ let receiver = PacketV1Codec::receiver_address(@packet_header);
221
+ let src_eid = PacketV1Codec::src_eid(@packet_header);
222
+
223
+ // Get the receive configuration for this path
224
+ let config = self.get_oapp_uln_receive_config(receiver, src_eid);
225
+
226
+ // Verify and reclaim storage
227
+ self._verify_and_reclaim_storage(@config, keccak256(@packet_header), payload_hash);
228
+
229
+ // Create Origin struct for endpoint.commit
230
+ let origin = Origin {
231
+ src_eid,
232
+ sender: PacketV1Codec::sender(@packet_header),
233
+ nonce: PacketV1Codec::nonce(@packet_header),
234
+ };
235
+
236
+ // Call endpoint to commit the verification
237
+ endpoint_dispatcher.commit(origin, receiver, payload_hash);
238
+ }
239
+
240
+ fn quote(
241
+ ref self: ContractState, packet: Packet, options: ByteArray, pay_in_lz_token: bool,
242
+ ) -> MessagingFee {
243
+ let (executor_options, dvn_options) = split_options(@options);
244
+
245
+ let uln_config = self.get_oapp_uln_send_config(packet.sender, packet.dst_eid);
246
+
247
+ let native_fee = self._quote_dvns(@uln_config, dvn_options, @packet)
248
+ + self._quote_executor(@uln_config, executor_options, @packet);
249
+ let treasury_payee = self._quote_treasury(@packet, native_fee, pay_in_lz_token);
250
+
251
+ MessagingFee {
252
+ native_fee: native_fee + treasury_payee.native_amount,
253
+ lz_token_fee: treasury_payee.lz_token_amount,
254
+ }
255
+ }
256
+
257
+ fn message_lib_type(self: @ContractState) -> MessageLibType {
258
+ MessageLibType::SendAndReceive
259
+ }
260
+
261
+ /// @dev a supported Eid must have a valid default uln config, which has at least one dvn
262
+ fn is_supported_send_eid(self: @ContractState, dst_eid: u32) -> bool {
263
+ let default_config = self.get_default_uln_send_config(dst_eid);
264
+
265
+ let required_count = default_config.required_dvns.len();
266
+ let optional_threshold = default_config.optional_dvn_threshold;
267
+
268
+ required_count > 0 || optional_threshold > 0
269
+ }
270
+
271
+ /// @dev a supported receive Eid must have a valid default uln receive config, which has at
272
+ /// least one dvn
273
+ fn is_supported_receive_eid(self: @ContractState, src_eid: u32) -> bool {
274
+ let default_config = self.get_default_uln_receive_config(src_eid);
275
+
276
+ let required_count = default_config.required_dvns.len();
277
+ let optional_threshold = default_config.optional_dvn_threshold;
278
+
279
+ required_count > 0 || optional_threshold > 0
280
+ }
281
+
282
+ fn set_send_config(
283
+ ref self: ContractState, oapp: ContractAddress, params: Array<SetConfigParam>,
284
+ ) {
285
+ self._assert_only_endpoint();
286
+
287
+ for param in params.into_iter() {
288
+ // only allow it to happen if there is a default config for the eid
289
+ self._assert_supported_send_eid(param.eid);
290
+
291
+ if param.config_type == CONFIG_TYPE_EXECUTOR {
292
+ let mut config_span = param.config.span();
293
+ let config: ExecutorConfig = Serde::deserialize(ref config_span).unwrap();
294
+ self._set_oapp_executor_config(oapp, param.eid, config);
295
+ } else {
296
+ assert_with_byte_array(
297
+ param.config_type == CONFIG_TYPE_ULN,
298
+ err_invalid_config_type(param.config_type),
299
+ );
300
+ let mut config_span = param.config.span();
301
+ let config: UlnConfig = Serde::deserialize(ref config_span).unwrap();
302
+ self._set_oapp_uln_send_config(oapp, param.eid, config);
303
+ }
304
+ }
305
+ }
306
+
307
+ fn get_send_config(
308
+ self: @ContractState, eid: u32, oapp: ContractAddress, config_type: u32,
309
+ ) -> Array<felt252> {
310
+ let mut serialized = array![];
311
+ if config_type == CONFIG_TYPE_EXECUTOR {
312
+ let config = self.get_oapp_executor_config(oapp, eid);
313
+ Serde::serialize(@config, ref serialized);
314
+ } else {
315
+ assert_with_byte_array(
316
+ config_type == CONFIG_TYPE_ULN, err_invalid_config_type(config_type),
317
+ );
318
+ let config = self.get_oapp_uln_send_config(oapp, eid);
319
+ Serde::serialize(@config, ref serialized);
320
+ }
321
+ serialized
322
+ }
323
+
324
+ fn set_receive_config(
325
+ ref self: ContractState, oapp: ContractAddress, params: Array<SetConfigParam>,
326
+ ) {
327
+ self._assert_only_endpoint();
328
+
329
+ for param in params.into_iter() {
330
+ // only allow it to happen if there is a default config for the eid
331
+ self._assert_supported_receive_eid(param.eid);
332
+
333
+ assert_with_byte_array(
334
+ param.config_type == CONFIG_TYPE_ULN,
335
+ err_invalid_config_type(param.config_type),
336
+ );
337
+
338
+ let mut config_span = param.config.span();
339
+ let config: UlnConfig = Serde::deserialize(ref config_span).unwrap();
340
+ self._set_oapp_uln_receive_config(oapp, param.eid, config);
341
+ }
342
+ }
343
+
344
+ fn get_receive_config(
345
+ self: @ContractState, eid: u32, oapp: ContractAddress, config_type: u32,
346
+ ) -> Array<felt252> {
347
+ let mut serialized = array![];
348
+ assert_with_byte_array(
349
+ config_type == CONFIG_TYPE_ULN, err_invalid_config_type(config_type),
350
+ );
351
+ let config = self.get_oapp_uln_receive_config(oapp, eid);
352
+ Serde::serialize(@config, ref serialized);
353
+
354
+ serialized
355
+ }
356
+
357
+ fn verifiable(
358
+ self: @ContractState, packet_header: ByteArray, payload_hash: Bytes32,
359
+ ) -> VerificationState {
360
+ let endpoint_dispatcher = IEndpointDispatcher {
361
+ contract_address: self.endpoint.read(),
362
+ };
363
+ PacketV1Codec::assert_header(@packet_header, endpoint_dispatcher.get_eid());
364
+
365
+ let receiver = PacketV1Codec::receiver_address(@packet_header);
366
+
367
+ let src_eid = PacketV1Codec::src_eid(@packet_header);
368
+ let sender = PacketV1Codec::sender(@packet_header);
369
+ let nonce = PacketV1Codec::nonce(@packet_header);
370
+
371
+ let origin = Origin { src_eid, sender, nonce };
372
+
373
+ // check endpoint initializable
374
+ if (!endpoint_dispatcher.initializable(origin.clone(), receiver)) {
375
+ return VerificationState::NotInitializable;
376
+ }
377
+
378
+ // check endpoint verifiable
379
+ if (!self._endpoint_verifiable(origin, receiver, payload_hash)) {
380
+ return VerificationState::Verified;
381
+ }
382
+
383
+ // check uln verifiable
384
+ if self
385
+ ._check_verifiable(
386
+ @self.get_oapp_uln_receive_config(receiver, src_eid),
387
+ keccak256(@packet_header),
388
+ payload_hash,
389
+ ) {
390
+ VerificationState::Verifiable
391
+ } else {
392
+ VerificationState::Verifying
393
+ }
394
+ }
395
+ }
396
+
397
+ // Admin functions for configuration management
398
+ #[abi(embed_v0)]
399
+ impl UltraLightNodeAdminImpl of IUltraLightNodeAdmin<ContractState> {
400
+ // =============================== ULN Config Setters ======================================
401
+
402
+ fn set_default_uln_send_config(
403
+ ref self: ContractState, configs: Array<SetDefaultUlnConfigParam>,
404
+ ) {
405
+ self.ownable.assert_only_owner();
406
+
407
+ for config_param in configs.into_iter() {
408
+ // Assert that the set config is valid
409
+ UlnConfigUtilsImpl::assert_no_duplicate_dvns(@config_param.config);
410
+ UlnConfigUtilsImpl::assert_valid_standalone_config(@config_param.config);
411
+
412
+ assert_with_byte_array(
413
+ config_param.config.confirmations > 0, err_invalid_confirmations(),
414
+ );
415
+
416
+ self
417
+ .send_configs
418
+ .entry(DEFAULT_CONFIG)
419
+ .entry(config_param.eid)
420
+ .set_uln_config(config_param.config.clone());
421
+ self
422
+ .emit(
423
+ DefaultUlnSendConfigSet {
424
+ dst_eid: config_param.eid, config: config_param.config,
425
+ },
426
+ );
427
+ }
428
+ }
429
+
430
+ fn set_default_uln_receive_config(
431
+ ref self: ContractState, configs: Array<SetDefaultUlnConfigParam>,
432
+ ) {
433
+ self.ownable.assert_only_owner();
434
+
435
+ for config_param in configs.into_iter() {
436
+ // Assert that the set config is valid
437
+ UlnConfigUtilsImpl::assert_no_duplicate_dvns(@config_param.config);
438
+ UlnConfigUtilsImpl::assert_valid_standalone_config(@config_param.config);
439
+
440
+ assert_with_byte_array(
441
+ config_param.config.confirmations > 0, err_invalid_confirmations(),
442
+ );
443
+
444
+ self
445
+ .receive_configs
446
+ .entry(DEFAULT_CONFIG)
447
+ .entry(config_param.eid)
448
+ .set_uln_config(config_param.config.clone());
449
+ self
450
+ .emit(
451
+ DefaultUlnReceiveConfigSet {
452
+ src_eid: config_param.eid, config: config_param.config,
453
+ },
454
+ );
455
+ }
456
+ }
457
+
458
+ // =============================== ULN Config Getters ======================================
459
+
460
+ // Getter functions for testing and verification
461
+ fn get_default_uln_send_config(self: @ContractState, dst_eid: u32) -> UlnConfig {
462
+ self.send_configs.entry(DEFAULT_CONFIG).entry(dst_eid).get_uln_config()
463
+ }
464
+
465
+ fn get_default_uln_receive_config(self: @ContractState, src_eid: u32) -> UlnConfig {
466
+ self.receive_configs.entry(DEFAULT_CONFIG).entry(src_eid).get_uln_config()
467
+ }
468
+
469
+ fn get_raw_oapp_uln_send_config(
470
+ self: @ContractState, oapp: ContractAddress, dst_eid: u32,
471
+ ) -> UlnConfig {
472
+ self.send_configs.entry(oapp).entry(dst_eid).get_uln_config()
473
+ }
474
+
475
+ fn get_oapp_uln_send_config(
476
+ self: @ContractState, oapp: ContractAddress, dst_eid: u32,
477
+ ) -> UlnConfig {
478
+ let default_config = self.get_default_uln_send_config(dst_eid);
479
+ let raw_oapp_config = self.get_raw_oapp_uln_send_config(oapp, dst_eid);
480
+ UlnConfigUtilsImpl::resolve(@default_config, @raw_oapp_config)
481
+ }
482
+
483
+ fn get_raw_oapp_uln_receive_config(
484
+ self: @ContractState, oapp: ContractAddress, src_eid: u32,
485
+ ) -> UlnConfig {
486
+ self.receive_configs.entry(oapp).entry(src_eid).get_uln_config()
487
+ }
488
+
489
+ fn get_oapp_uln_receive_config(
490
+ self: @ContractState, oapp: ContractAddress, src_eid: u32,
491
+ ) -> UlnConfig {
492
+ let default_config = self.get_default_uln_receive_config(src_eid);
493
+ let raw_oapp_config = self.get_raw_oapp_uln_receive_config(oapp, src_eid);
494
+ UlnConfigUtilsImpl::resolve(@default_config, @raw_oapp_config)
495
+ }
496
+
497
+ // =============================== Executor Config Setters
498
+ // ======================================
499
+
500
+ fn set_default_executor_config(
501
+ ref self: ContractState, dst_eid: u32, config: ExecutorConfig,
502
+ ) {
503
+ self.ownable.assert_only_owner();
504
+ self.executor_configs.entry(DEFAULT_CONFIG).entry(dst_eid).write(config.clone());
505
+ self.emit(DefaultExecutorConfigSet { dst_eid, config });
506
+ }
507
+
508
+ // =============================== Executor Config Getters
509
+ // ======================================
510
+
511
+ fn get_default_executor_config(self: @ContractState, dst_eid: u32) -> ExecutorConfig {
512
+ self.executor_configs.entry(DEFAULT_CONFIG).entry(dst_eid).read()
513
+ }
514
+
515
+ fn get_raw_oapp_executor_config(
516
+ self: @ContractState, oapp: ContractAddress, dst_eid: u32,
517
+ ) -> ExecutorConfig {
518
+ self.executor_configs.entry(oapp).entry(dst_eid).read()
519
+ }
520
+
521
+ fn get_oapp_executor_config(
522
+ self: @ContractState, oapp: ContractAddress, dst_eid: u32,
523
+ ) -> ExecutorConfig {
524
+ let default_config = self.get_default_executor_config(dst_eid);
525
+ let raw_oapp_config = self.get_raw_oapp_executor_config(oapp, dst_eid);
526
+ ExecutorConfigResolverImpl::resolve(@default_config, @raw_oapp_config)
527
+ }
528
+
529
+ // =============================== Treasury Config Setters
530
+ // ======================================
531
+
532
+ fn set_treasury_native_fee_cap(ref self: ContractState, native_fee_cap: u256) {
533
+ self.ownable.assert_only_owner();
534
+ let old_cap = self.treasury_native_fee_cap.read();
535
+ assert_with_byte_array(
536
+ native_fee_cap < old_cap,
537
+ err_invalid_treasury_native_fee_cap(old_cap, native_fee_cap),
538
+ );
539
+ self.treasury_native_fee_cap.write(native_fee_cap);
540
+ self.emit(TreasuryNativeFeeCapSet { native_fee_cap });
541
+ }
542
+
543
+ // =============================== Treasury Config Getters
544
+ // ======================================
545
+
546
+ fn get_treasury(self: @ContractState) -> ContractAddress {
547
+ self.treasury.read()
548
+ }
549
+
550
+ fn get_treasury_native_fee_cap(self: @ContractState) -> u256 {
551
+ self.treasury_native_fee_cap.read()
552
+ }
553
+
554
+ fn has_payload_signed(
555
+ self: @ContractState, header_hash: Bytes32, payload_hash: Bytes32, dvn: ContractAddress,
556
+ ) -> bool {
557
+ self._hash_lookup(header_hash, payload_hash, dvn) != EMPTY_VERIFICATION
558
+ }
559
+ }
560
+
561
+ #[generate_trait]
562
+ impl UltraLightNodeInternalImpl of UltraLightNodeInternalTrait {
563
+ fn _assert_supported_send_eid(self: @ContractState, dst_eid: u32) {
564
+ assert_with_byte_array(
565
+ self.is_supported_send_eid(dst_eid), err_unsupported_send_eid(dst_eid),
566
+ );
567
+ }
568
+
569
+ fn _assert_supported_receive_eid(self: @ContractState, src_eid: u32) {
570
+ assert_with_byte_array(
571
+ self.is_supported_receive_eid(src_eid), err_unsupported_receive_eid(src_eid),
572
+ );
573
+ }
574
+
575
+ /// Given a packet, return the dst_eid, sender, and message size
576
+ fn _expand_packet(self: @ContractState, packet: @Packet) -> (u32, ContractAddress, u32) {
577
+ (*packet.dst_eid, *packet.sender, packet.message.len())
578
+ }
579
+
580
+ /// Given a uln config, return all the dvns and the confirmations
581
+ fn _expand_config(
582
+ self: @ContractState, config: @UlnConfig,
583
+ ) -> (Array<ContractAddress>, u64) {
584
+ let mut all_dvns = config.required_dvns.clone();
585
+ all_dvns.append_span(config.optional_dvns.span());
586
+
587
+ (all_dvns, *config.confirmations)
588
+ }
589
+
590
+ // Helper function that contains the shared logic for both quote and pay operations
591
+ fn _process_dvns_shared(
592
+ self: @ContractState,
593
+ uln_config: @UlnConfig,
594
+ options: ByteArray,
595
+ packet: @Packet,
596
+ worker_operation_type: WorkerOperationType,
597
+ ) -> DvnPaymentInfo {
598
+ let (dst_eid, sender, calldata_size) = self._expand_packet(packet);
599
+ let (all_dvns, confirmations) = self._expand_config(uln_config);
600
+ let mut dvn_options_dict = group_dvn_options_by_idx(@options);
601
+
602
+ let mut total_native_fee: u256 = 0;
603
+ let mut payees = array![];
604
+
605
+ for (i, dvn_address) in all_dvns.into_iter().enumerate() {
606
+ let (entry, dvn_options_nullable) = dvn_options_dict.entry(i.into());
607
+
608
+ // Handle the nullable properly
609
+ let dvn_options_bytes = match dvn_options_nullable.is_null() {
610
+ true => Default::default(),
611
+ false => dvn_options_nullable.as_snapshot().deref(),
612
+ };
613
+
614
+ let quote_params = QuoteParams {
615
+ dst_eid,
616
+ confirmations,
617
+ sender,
618
+ options: dvn_options_bytes.clone(),
619
+ calldata_size,
620
+ };
621
+
622
+ let dvn_dispatcher = ILayerZeroWorkerDispatcher { contract_address: dvn_address };
623
+ let native_amount = match worker_operation_type {
624
+ WorkerOperationType::Quote => dvn_dispatcher.quote(quote_params),
625
+ WorkerOperationType::Pay => dvn_dispatcher.assign_job(quote_params),
626
+ };
627
+
628
+ total_native_fee += native_amount;
629
+
630
+ // Only create payees for pay operation
631
+ if worker_operation_type == WorkerOperationType::Pay {
632
+ payees
633
+ .append(Payee { receiver: dvn_address, native_amount, lz_token_amount: 0 });
634
+ }
635
+
636
+ dvn_options_dict = entry.finalize(dvn_options_nullable);
637
+ }
638
+
639
+ DvnPaymentInfo { total_native_fee, payees }
640
+ }
641
+
642
+ fn _quote_dvns(
643
+ self: @ContractState, uln_config: @UlnConfig, options: ByteArray, packet: @Packet,
644
+ ) -> u256 {
645
+ self
646
+ ._process_dvns_shared(uln_config, options, packet, WorkerOperationType::Quote)
647
+ .total_native_fee
648
+ }
649
+
650
+ fn _pay_dvns(
651
+ ref self: ContractState, uln_config: @UlnConfig, options: ByteArray, packet: @Packet,
652
+ ) -> DvnPaymentInfo {
653
+ self._process_dvns_shared(uln_config, options, packet, WorkerOperationType::Pay)
654
+ }
655
+
656
+ // Helper function for shared executor logic
657
+ fn _process_executor_shared(
658
+ ref self: ContractState,
659
+ uln_config: @UlnConfig,
660
+ options: ByteArray,
661
+ packet: @Packet,
662
+ worker_operation_type: WorkerOperationType,
663
+ ) -> Payee {
664
+ let executor_address = self._verify_packet_size(packet);
665
+ let (dst_eid, sender, calldata_size) = self._expand_packet(packet);
666
+
667
+ let quote_params = QuoteParams {
668
+ dst_eid, sender, calldata_size, options, confirmations: *uln_config.confirmations,
669
+ };
670
+
671
+ let executor_dispatcher = ILayerZeroWorkerDispatcher {
672
+ contract_address: executor_address,
673
+ };
674
+ let executor_native_fee = match worker_operation_type {
675
+ WorkerOperationType::Quote => executor_dispatcher.quote(quote_params),
676
+ WorkerOperationType::Pay => executor_dispatcher.assign_job(quote_params),
677
+ };
678
+
679
+ Payee {
680
+ receiver: executor_address, native_amount: executor_native_fee, lz_token_amount: 0,
681
+ }
682
+ }
683
+
684
+ fn _quote_executor(
685
+ ref self: ContractState, uln_config: @UlnConfig, options: ByteArray, packet: @Packet,
686
+ ) -> u256 {
687
+ self
688
+ ._process_executor_shared(uln_config, options, packet, WorkerOperationType::Quote)
689
+ .native_amount
690
+ }
691
+
692
+ fn _pay_executor(
693
+ ref self: ContractState, uln_config: @UlnConfig, options: ByteArray, packet: @Packet,
694
+ ) -> Payee {
695
+ self._process_executor_shared(uln_config, options, packet, WorkerOperationType::Pay)
696
+ }
697
+
698
+ fn _process_treasury_shared(
699
+ ref self: ContractState,
700
+ packet: @Packet,
701
+ native_fee: u256,
702
+ pay_in_lz_token: bool,
703
+ worker_operation_type: WorkerOperationType,
704
+ ) -> Payee {
705
+ let (dst_eid, sender, _) = self._expand_packet(packet);
706
+
707
+ let treasury_dispatcher = ILayerZeroTreasuryDispatcher {
708
+ contract_address: self.treasury.read(),
709
+ };
710
+
711
+ let treasury_fee = match worker_operation_type {
712
+ WorkerOperationType::Quote => treasury_dispatcher
713
+ .get_fee(sender, dst_eid, native_fee, pay_in_lz_token),
714
+ WorkerOperationType::Pay => treasury_dispatcher
715
+ .pay_fee(sender, dst_eid, native_fee, pay_in_lz_token),
716
+ };
717
+
718
+ let treasury_fee_capped = self
719
+ ._apply_treasury_fee_cap(native_fee, treasury_fee, pay_in_lz_token);
720
+
721
+ let (native_amount, lz_token_amount) = if pay_in_lz_token {
722
+ (0, treasury_fee_capped)
723
+ } else {
724
+ (treasury_fee_capped, 0)
725
+ };
726
+
727
+ Payee { receiver: treasury_dispatcher.contract_address, native_amount, lz_token_amount }
728
+ }
729
+
730
+ fn _quote_treasury(
731
+ ref self: ContractState, packet: @Packet, native_fee: u256, pay_in_lz_token: bool,
732
+ ) -> Payee {
733
+ self
734
+ ._process_treasury_shared(
735
+ packet, native_fee, pay_in_lz_token, WorkerOperationType::Quote,
736
+ )
737
+ }
738
+
739
+ fn _pay_treasury(
740
+ ref self: ContractState, packet: @Packet, native_fee: u256, pay_in_lz_token: bool,
741
+ ) -> Payee {
742
+ self
743
+ ._process_treasury_shared(
744
+ packet, native_fee, pay_in_lz_token, WorkerOperationType::Pay,
745
+ )
746
+ }
747
+
748
+ fn _apply_treasury_fee_cap(
749
+ ref self: ContractState, native_fee: u256, treasury_fee: u256, pay_in_lz_token: bool,
750
+ ) -> u256 {
751
+ if pay_in_lz_token {
752
+ return treasury_fee;
753
+ }
754
+
755
+ // we must prevent high-treasuryFee Dos attack
756
+ // nativeFee = min(treasureFeeQuote, maxNativeFee)
757
+ // opportunistically raise the maxNativeFee to be the same as _totalNativeFee
758
+ // can't use the _totalNativeFee alone because the oapp can use custom workers to force
759
+ // the fee to 0.
760
+ // maxNativeFee = max (_totalNativeFee, treasuryNativeFeeCap)
761
+ let treasury_native_fee_cap = self.treasury_native_fee_cap.read();
762
+ let max_native_fee = if native_fee > treasury_native_fee_cap {
763
+ native_fee
764
+ } else {
765
+ treasury_native_fee_cap
766
+ };
767
+
768
+ if treasury_fee > max_native_fee {
769
+ max_native_fee
770
+ } else {
771
+ treasury_fee
772
+ }
773
+ }
774
+
775
+ // Asserts whether the packet has a valid size and returns the executor address if so
776
+ fn _verify_packet_size(ref self: ContractState, packet: @Packet) -> ContractAddress {
777
+ // quote executor
778
+ let executor_config = self.get_oapp_executor_config(*packet.sender, *packet.dst_eid);
779
+
780
+ let packet_message_size = packet.message.len();
781
+ let max_message_size = executor_config.max_message_size;
782
+ assert_with_byte_array(
783
+ packet_message_size <= max_message_size,
784
+ err_message_too_large(packet_message_size, max_message_size),
785
+ );
786
+
787
+ executor_config.executor
788
+ }
789
+
790
+ fn _assert_only_endpoint(self: @ContractState) {
791
+ let caller = get_caller_address();
792
+ let endpoint = self.endpoint.read();
793
+ assert_with_byte_array(caller == endpoint, err_caller_not_endpoint(caller, endpoint));
794
+ }
795
+
796
+ /// @dev checks for endpoint verifiable and endpoint has payload hash
797
+ fn _endpoint_verifiable(
798
+ self: @ContractState, origin: Origin, receiver: ContractAddress, payload_hash: Bytes32,
799
+ ) -> bool {
800
+ let endpoint_dispatcher = IEndpointDispatcher {
801
+ contract_address: self.endpoint.read(),
802
+ };
803
+ let channel_dispatcher = IMessagingChannelDispatcher {
804
+ contract_address: self.endpoint.read(),
805
+ };
806
+
807
+ // check endpoint verifiable (equivalent to committable in Cairo)
808
+ if (!endpoint_dispatcher
809
+ .committable_with_receive_lib(origin.clone(), receiver, get_contract_address())) {
810
+ return false;
811
+ }
812
+
813
+ // if endpoint.verifiable, also check if the payload hash matches
814
+ // endpoint allows re-verify, check if this payload has already been verified
815
+ if (channel_dispatcher
816
+ .inbound_payload_hash(
817
+ receiver, origin.src_eid, origin.sender, origin.nonce,
818
+ ) == payload_hash) {
819
+ return false;
820
+ }
821
+
822
+ true
823
+ }
824
+
825
+ /// Checks if the verification is ready to be committed to the endpoint
826
+ fn _check_verifiable(
827
+ self: @ContractState, config: @UlnConfig, header_hash: Bytes32, payload_hash: Bytes32,
828
+ ) -> bool {
829
+ // Check required DVNs
830
+ if config.required_dvns.len() > 0 {
831
+ for dvn in config.required_dvns {
832
+ if !self._verified(*dvn, header_hash, payload_hash, *config.confirmations) {
833
+ // return if any of the required DVNs haven't signed
834
+ return false;
835
+ }
836
+ }
837
+ if config.optional_dvns.is_empty() {
838
+ // returns early if all required DVNs have signed and there are no optional DVNs
839
+ return true;
840
+ }
841
+ }
842
+
843
+ // Check optional DVNs threshold
844
+ let mut remaining_threshold = *config.optional_dvn_threshold;
845
+ for dvn in config.optional_dvns {
846
+ if self._verified(*dvn, header_hash, payload_hash, *config.confirmations) {
847
+ // decrement the threshold if the optional DVN has signed
848
+ remaining_threshold -= 1;
849
+ if remaining_threshold == 0 {
850
+ // early return if the optional threshold has hit
851
+ return true;
852
+ }
853
+ }
854
+ }
855
+
856
+ // return false as a catch-all
857
+ false
858
+ }
859
+
860
+ /// Checks if a specific DVN has verified the payload with sufficient confirmations
861
+ fn _verified(
862
+ self: @ContractState,
863
+ dvn: ContractAddress,
864
+ header_hash: Bytes32,
865
+ payload_hash: Bytes32,
866
+ required_confirmations: u64,
867
+ ) -> bool {
868
+ let verification = self._hash_lookup(header_hash, payload_hash, dvn);
869
+ verification.submitted && verification.confirmations >= required_confirmations
870
+ }
871
+
872
+ /// Verifies that all required DVNs have signed and reclaims storage
873
+ fn _verify_and_reclaim_storage(
874
+ ref self: ContractState,
875
+ config: @UlnConfig,
876
+ header_hash: Bytes32,
877
+ payload_hash: Bytes32,
878
+ ) {
879
+ assert_with_byte_array(
880
+ self._check_verifiable(config, header_hash, payload_hash), err_uln_verifying(),
881
+ );
882
+
883
+ // iterate the required DVNs and delete their verifications
884
+ if config.required_dvns.len() > 0 {
885
+ for dvn in config.required_dvns {
886
+ self
887
+ ._hash_lookup_entry(header_hash, payload_hash, *dvn)
888
+ .write(EMPTY_VERIFICATION);
889
+ }
890
+ }
891
+
892
+ // iterate the optional DVNs and delete their verifications
893
+ if config.optional_dvns.len() > 0 {
894
+ for dvn in config.optional_dvns {
895
+ self
896
+ ._hash_lookup_entry(header_hash, payload_hash, *dvn)
897
+ .write(EMPTY_VERIFICATION);
898
+ }
899
+ }
900
+ }
901
+
902
+ // =============================== OApp Config Setters ==================
903
+
904
+ fn _set_oapp_executor_config(
905
+ ref self: ContractState, oapp: ContractAddress, dst_eid: u32, config: ExecutorConfig,
906
+ ) {
907
+ self._assert_supported_send_eid(dst_eid);
908
+ self.executor_configs.entry(oapp).entry(dst_eid).write(config.clone());
909
+ self.emit(OAppExecutorConfigSet { oapp, dst_eid, config });
910
+ }
911
+
912
+ fn _set_oapp_uln_send_config(
913
+ ref self: ContractState, oapp: ContractAddress, dst_eid: u32, config: UlnConfig,
914
+ ) {
915
+ self._assert_supported_send_eid(dst_eid);
916
+
917
+ // Assert no duplicates in DVN arrays before setting
918
+ UlnConfigUtilsImpl::assert_no_duplicate_dvns(@config);
919
+
920
+ self.send_configs.entry(oapp).entry(dst_eid).set_uln_config(config.clone());
921
+
922
+ // Calling this will make sure the newly set OApp config
923
+ // will end up with us having a valid resolved config,
924
+ // if not, it will revert.
925
+ let _config = self.get_oapp_uln_send_config(oapp, dst_eid);
926
+
927
+ self.emit(OAppUlnSendConfigSet { oapp, dst_eid, config });
928
+ }
929
+
930
+ fn _set_oapp_uln_receive_config(
931
+ ref self: ContractState, oapp: ContractAddress, src_eid: u32, config: UlnConfig,
932
+ ) {
933
+ self._assert_supported_receive_eid(src_eid);
934
+
935
+ // Assert no duplicates in DVN arrays before setting
936
+ UlnConfigUtilsImpl::assert_no_duplicate_dvns(@config);
937
+
938
+ self.receive_configs.entry(oapp).entry(src_eid).set_uln_config(config.clone());
939
+
940
+ // Calling this will make sure the newly set OApp config
941
+ // will end up with us having a valid resolved config,
942
+ // if not, it will revert.
943
+ let _config = self.get_oapp_uln_receive_config(oapp, src_eid);
944
+
945
+ self.emit(OAppUlnReceiveConfigSet { oapp, src_eid, config });
946
+ }
947
+
948
+ // Read-only getter for hash_lookup
949
+ fn _hash_lookup(
950
+ self: @ContractState, header_hash: Bytes32, payload_hash: Bytes32, dvn: ContractAddress,
951
+ ) -> Verification {
952
+ self.hash_lookup.entry(header_hash).entry(payload_hash).entry(dvn).read()
953
+ }
954
+
955
+ // Mutable setter for hash_lookup
956
+ fn _hash_lookup_entry(
957
+ ref self: ContractState,
958
+ header_hash: Bytes32,
959
+ payload_hash: Bytes32,
960
+ dvn: ContractAddress,
961
+ ) -> StoragePath<Mutable<Verification>> {
962
+ self.hash_lookup.entry(header_hash).entry(payload_hash).entry(dvn)
963
+ }
964
+ }
965
+ }