@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.
- package/.turbo/turbo-build.log +186 -0
- package/.turbo/turbo-lint.log +71 -0
- package/.turbo/turbo-test.log +937 -0
- package/README.md +41 -0
- package/Scarb.lock +211 -0
- package/Scarb.toml +2 -0
- package/dist/4XD3ZRZ4.cjs +301 -0
- package/dist/4XD3ZRZ4.cjs.map +1 -0
- package/dist/4Z5IPBC3.js +299 -0
- package/dist/4Z5IPBC3.js.map +1 -0
- package/dist/5NEZDLVQ.cjs +474 -0
- package/dist/5NEZDLVQ.cjs.map +1 -0
- package/dist/6JYCOKDE.js +472 -0
- package/dist/6JYCOKDE.js.map +1 -0
- package/dist/7C4PFMIZ.cjs +1288 -0
- package/dist/7C4PFMIZ.cjs.map +1 -0
- package/dist/7ZSGGZUE.js +1229 -0
- package/dist/7ZSGGZUE.js.map +1 -0
- package/dist/ARHOGUYH.cjs +2136 -0
- package/dist/ARHOGUYH.cjs.map +1 -0
- package/dist/CRCRIUFX.js +1264 -0
- package/dist/CRCRIUFX.js.map +1 -0
- package/dist/DB7CQSED.cjs +430 -0
- package/dist/DB7CQSED.cjs.map +1 -0
- package/dist/DFXLWHYP.cjs +1266 -0
- package/dist/DFXLWHYP.cjs.map +1 -0
- package/dist/EOLZCMCK.js +988 -0
- package/dist/EOLZCMCK.js.map +1 -0
- package/dist/FFDPTOWG.cjs +331 -0
- package/dist/FFDPTOWG.cjs.map +1 -0
- package/dist/FOJGEAIO.js +2134 -0
- package/dist/FOJGEAIO.js.map +1 -0
- package/dist/IWIUMVGB.js +629 -0
- package/dist/IWIUMVGB.js.map +1 -0
- package/dist/MUEN6AWV.cjs +697 -0
- package/dist/MUEN6AWV.cjs.map +1 -0
- package/dist/ORE6VBZ4.cjs +990 -0
- package/dist/ORE6VBZ4.cjs.map +1 -0
- package/dist/OUFKWPZ7.js +732 -0
- package/dist/OUFKWPZ7.js.map +1 -0
- package/dist/T2QTYQXJ.js +1229 -0
- package/dist/T2QTYQXJ.js.map +1 -0
- package/dist/UPJTM7BR.cjs +631 -0
- package/dist/UPJTM7BR.cjs.map +1 -0
- package/dist/VNVNX2P3.cjs +1231 -0
- package/dist/VNVNX2P3.cjs.map +1 -0
- package/dist/VUOMXK5T.js +6 -0
- package/dist/VUOMXK5T.js.map +1 -0
- package/dist/WISWRTDG.js +1286 -0
- package/dist/WISWRTDG.js.map +1 -0
- package/dist/WU5L7YIQ.cjs +1231 -0
- package/dist/WU5L7YIQ.cjs.map +1 -0
- package/dist/X3B5JDMZ.js +695 -0
- package/dist/X3B5JDMZ.js.map +1 -0
- package/dist/XYNBDBBV.cjs +297 -0
- package/dist/XYNBDBBV.cjs.map +1 -0
- package/dist/Y5JFPCYJ.cjs +734 -0
- package/dist/Y5JFPCYJ.cjs.map +1 -0
- package/dist/YEHL7IYO.js +295 -0
- package/dist/YEHL7IYO.js.map +1 -0
- package/dist/YJF4D23A.cjs +8 -0
- package/dist/YJF4D23A.cjs.map +1 -0
- package/dist/YTS44OEA.js +428 -0
- package/dist/YTS44OEA.js.map +1 -0
- package/dist/Z2NIUZMW.js +329 -0
- package/dist/Z2NIUZMW.js.map +1 -0
- package/dist/abis/blocked-message-lib.cjs +13 -0
- package/dist/abis/blocked-message-lib.cjs.map +1 -0
- package/dist/abis/blocked-message-lib.d.ts +338 -0
- package/dist/abis/blocked-message-lib.d.ts.map +1 -0
- package/dist/abis/blocked-message-lib.js +4 -0
- package/dist/abis/blocked-message-lib.js.map +1 -0
- package/dist/abis/dvn-fee-lib.cjs +13 -0
- package/dist/abis/dvn-fee-lib.cjs.map +1 -0
- package/dist/abis/dvn-fee-lib.d.ts +214 -0
- package/dist/abis/dvn-fee-lib.d.ts.map +1 -0
- package/dist/abis/dvn-fee-lib.js +4 -0
- package/dist/abis/dvn-fee-lib.js.map +1 -0
- package/dist/abis/dvn.cjs +13 -0
- package/dist/abis/dvn.cjs.map +1 -0
- package/dist/abis/dvn.d.ts +952 -0
- package/dist/abis/dvn.d.ts.map +1 -0
- package/dist/abis/dvn.js +4 -0
- package/dist/abis/dvn.js.map +1 -0
- package/dist/abis/endpoint-v2.cjs +13 -0
- package/dist/abis/endpoint-v2.cjs.map +1 -0
- package/dist/abis/endpoint-v2.d.ts +1580 -0
- package/dist/abis/endpoint-v2.d.ts.map +1 -0
- package/dist/abis/endpoint-v2.js +4 -0
- package/dist/abis/endpoint-v2.js.map +1 -0
- package/dist/abis/executor-fee-lib.cjs +13 -0
- package/dist/abis/executor-fee-lib.cjs.map +1 -0
- package/dist/abis/executor-fee-lib.d.ts +217 -0
- package/dist/abis/executor-fee-lib.d.ts.map +1 -0
- package/dist/abis/executor-fee-lib.js +4 -0
- package/dist/abis/executor-fee-lib.js.map +1 -0
- package/dist/abis/executor.cjs +13 -0
- package/dist/abis/executor.cjs.map +1 -0
- package/dist/abis/executor.d.ts +914 -0
- package/dist/abis/executor.d.ts.map +1 -0
- package/dist/abis/executor.js +4 -0
- package/dist/abis/executor.js.map +1 -0
- package/dist/abis/o-app.cjs +13 -0
- package/dist/abis/o-app.cjs.map +1 -0
- package/dist/abis/o-app.d.ts +311 -0
- package/dist/abis/o-app.d.ts.map +1 -0
- package/dist/abis/o-app.js +4 -0
- package/dist/abis/o-app.js.map +1 -0
- package/dist/abis/oft-adapter.cjs +13 -0
- package/dist/abis/oft-adapter.cjs.map +1 -0
- package/dist/abis/oft-adapter.d.ts +722 -0
- package/dist/abis/oft-adapter.d.ts.map +1 -0
- package/dist/abis/oft-adapter.js +4 -0
- package/dist/abis/oft-adapter.js.map +1 -0
- package/dist/abis/oft.cjs +13 -0
- package/dist/abis/oft.cjs.map +1 -0
- package/dist/abis/oft.d.ts +922 -0
- package/dist/abis/oft.d.ts.map +1 -0
- package/dist/abis/oft.js +4 -0
- package/dist/abis/oft.js.map +1 -0
- package/dist/abis/omni-counter.cjs +13 -0
- package/dist/abis/omni-counter.cjs.map +1 -0
- package/dist/abis/omni-counter.d.ts +459 -0
- package/dist/abis/omni-counter.d.ts.map +1 -0
- package/dist/abis/omni-counter.js +4 -0
- package/dist/abis/omni-counter.js.map +1 -0
- package/dist/abis/price-feed.cjs +13 -0
- package/dist/abis/price-feed.cjs.map +1 -0
- package/dist/abis/price-feed.d.ts +505 -0
- package/dist/abis/price-feed.d.ts.map +1 -0
- package/dist/abis/price-feed.js +4 -0
- package/dist/abis/price-feed.js.map +1 -0
- package/dist/abis/simple-message-lib.cjs +13 -0
- package/dist/abis/simple-message-lib.cjs.map +1 -0
- package/dist/abis/simple-message-lib.d.ts +535 -0
- package/dist/abis/simple-message-lib.d.ts.map +1 -0
- package/dist/abis/simple-message-lib.js +4 -0
- package/dist/abis/simple-message-lib.js.map +1 -0
- package/dist/abis/treasury.cjs +13 -0
- package/dist/abis/treasury.cjs.map +1 -0
- package/dist/abis/treasury.d.ts +240 -0
- package/dist/abis/treasury.d.ts.map +1 -0
- package/dist/abis/treasury.js +4 -0
- package/dist/abis/treasury.js.map +1 -0
- package/dist/abis/ultra-light-node.cjs +13 -0
- package/dist/abis/ultra-light-node.cjs.map +1 -0
- package/dist/abis/ultra-light-node.d.ts +900 -0
- package/dist/abis/ultra-light-node.d.ts.map +1 -0
- package/dist/abis/ultra-light-node.js +4 -0
- package/dist/abis/ultra-light-node.js.map +1 -0
- package/dist/index.cjs +78 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +17 -0
- package/dist/index.js.map +1 -0
- package/dist/scripts/build-abi.cjs +28 -0
- package/dist/scripts/build-abi.cjs.map +1 -0
- package/dist/scripts/build-abi.d.ts +2 -0
- package/dist/scripts/build-abi.d.ts.map +1 -0
- package/dist/scripts/build-abi.js +26 -0
- package/dist/scripts/build-abi.js.map +1 -0
- package/layerzero/README.md +244 -0
- package/layerzero/Scarb.lock +203 -0
- package/layerzero/Scarb.toml +30 -0
- package/layerzero/snfoundry.toml +11 -0
- package/layerzero/src/common/constants.cairo +26 -0
- package/layerzero/src/common/conversions.cairo +16 -0
- package/layerzero/src/common/guid.cairo +20 -0
- package/layerzero/src/common/packet_v1_codec.cairo +307 -0
- package/layerzero/src/common/structs/messaging.cairo +40 -0
- package/layerzero/src/common/structs/packet.cairo +31 -0
- package/layerzero/src/endpoint/constants.cairo +14 -0
- package/layerzero/src/endpoint/endpoint.cairo +688 -0
- package/layerzero/src/endpoint/errors.cairo +108 -0
- package/layerzero/src/endpoint/events.cairo +124 -0
- package/layerzero/src/endpoint/interfaces/endpoint.cairo +286 -0
- package/layerzero/src/endpoint/interfaces/layerzero_composer.cairo +62 -0
- package/layerzero/src/endpoint/interfaces/layerzero_receiver.cairo +63 -0
- package/layerzero/src/endpoint/message_lib_manager/errors.cairo +95 -0
- package/layerzero/src/endpoint/message_lib_manager/events.cairo +90 -0
- package/layerzero/src/endpoint/message_lib_manager/interface.cairo +449 -0
- package/layerzero/src/endpoint/message_lib_manager/message_lib_manager.cairo +720 -0
- package/layerzero/src/endpoint/message_lib_manager/structs.cairo +33 -0
- package/layerzero/src/endpoint/messaging_channel/errors.cairo +37 -0
- package/layerzero/src/endpoint/messaging_channel/events.cairo +58 -0
- package/layerzero/src/endpoint/messaging_channel/interface.cairo +171 -0
- package/layerzero/src/endpoint/messaging_channel/messaging_channel.cairo +453 -0
- package/layerzero/src/endpoint/messaging_composer/errors.cairo +46 -0
- package/layerzero/src/endpoint/messaging_composer/events.cairo +67 -0
- package/layerzero/src/endpoint/messaging_composer/interface.cairo +132 -0
- package/layerzero/src/endpoint/messaging_composer/messaging_composer.cairo +223 -0
- package/layerzero/src/lib.cairo +189 -0
- package/layerzero/src/message_lib/blocked_message_lib.cairo +114 -0
- package/layerzero/src/message_lib/interface.cairo +63 -0
- package/layerzero/src/message_lib/sml/errors.cairo +23 -0
- package/layerzero/src/message_lib/sml/events.cairo +32 -0
- package/layerzero/src/message_lib/sml/simple_message_lib.cairo +312 -0
- package/layerzero/src/message_lib/structs.cairo +22 -0
- package/layerzero/src/message_lib/uln/errors.cairo +128 -0
- package/layerzero/src/message_lib/uln/events.cairo +97 -0
- package/layerzero/src/message_lib/uln/interface.cairo +83 -0
- package/layerzero/src/message_lib/uln/options.cairo +64 -0
- package/layerzero/src/message_lib/uln/structs/executor_config.cairo +35 -0
- package/layerzero/src/message_lib/uln/structs/payment_info.cairo +7 -0
- package/layerzero/src/message_lib/uln/structs/uln_config.cairo +155 -0
- package/layerzero/src/message_lib/uln/structs/uln_config_storage_node.cairo +91 -0
- package/layerzero/src/message_lib/uln/structs/verification.cairo +7 -0
- package/layerzero/src/message_lib/uln/ultra_light_node.cairo +965 -0
- package/layerzero/src/oapps/common/oapp_options_type_3/errors.cairo +22 -0
- package/layerzero/src/oapps/common/oapp_options_type_3/events.cairo +6 -0
- package/layerzero/src/oapps/common/oapp_options_type_3/interface.cairo +34 -0
- package/layerzero/src/oapps/common/oapp_options_type_3/oapp_options_type_3.cairo +120 -0
- package/layerzero/src/oapps/common/oapp_options_type_3/structs.cairo +6 -0
- package/layerzero/src/oapps/counter/constants.cairo +3 -0
- package/layerzero/src/oapps/counter/counter.cairo +170 -0
- package/layerzero/src/oapps/counter/interface.cairo +27 -0
- package/layerzero/src/oapps/counter/structs.cairo +20 -0
- package/layerzero/src/oapps/message_inspector/interface.cairo +21 -0
- package/layerzero/src/oapps/oapp/errors.cairo +72 -0
- package/layerzero/src/oapps/oapp/events.cairo +9 -0
- package/layerzero/src/oapps/oapp/interface.cairo +67 -0
- package/layerzero/src/oapps/oapp/oapp.cairo +70 -0
- package/layerzero/src/oapps/oapp/oapp_core.cairo +448 -0
- package/layerzero/src/oapps/oft/errors.cairo +42 -0
- package/layerzero/src/oapps/oft/events.cairo +33 -0
- package/layerzero/src/oapps/oft/interface.cairo +87 -0
- package/layerzero/src/oapps/oft/oft.cairo +188 -0
- package/layerzero/src/oapps/oft/oft_adapter.cairo +175 -0
- package/layerzero/src/oapps/oft/oft_compose_msg_codec.cairo +128 -0
- package/layerzero/src/oapps/oft/oft_core.cairo +542 -0
- package/layerzero/src/oapps/oft/oft_msg_codec.cairo +131 -0
- package/layerzero/src/oapps/oft/structs.cairo +72 -0
- package/layerzero/src/treasury/errors.cairo +22 -0
- package/layerzero/src/treasury/events.cairo +5 -0
- package/layerzero/src/treasury/interfaces/layerzero_treasury.cairo +54 -0
- package/layerzero/src/treasury/interfaces/lz_token_fee_lib.cairo +45 -0
- package/layerzero/src/treasury/interfaces/treasury_admin.cairo +39 -0
- package/layerzero/src/treasury/treasury.cairo +140 -0
- package/layerzero/src/workers/access_control.cairo +11 -0
- package/layerzero/src/workers/base/base.cairo +238 -0
- package/layerzero/src/workers/base/errors.cairo +24 -0
- package/layerzero/src/workers/base/events.cairo +43 -0
- package/layerzero/src/workers/base/interface.cairo +93 -0
- package/layerzero/src/workers/base/structs.cairo +10 -0
- package/layerzero/src/workers/common.cairo +59 -0
- package/layerzero/src/workers/dvn/constants.cairo +11 -0
- package/layerzero/src/workers/dvn/dvn.cairo +338 -0
- package/layerzero/src/workers/dvn/errors.cairo +80 -0
- package/layerzero/src/workers/dvn/events.cairo +30 -0
- package/layerzero/src/workers/dvn/fee_lib/dvn_fee_lib.cairo +152 -0
- package/layerzero/src/workers/dvn/fee_lib/interface.cairo +45 -0
- package/layerzero/src/workers/dvn/interface.cairo +131 -0
- package/layerzero/src/workers/dvn/options.cairo +125 -0
- package/layerzero/src/workers/dvn/structs.cairo +51 -0
- package/layerzero/src/workers/executor/errors.cairo +159 -0
- package/layerzero/src/workers/executor/events.cairo +32 -0
- package/layerzero/src/workers/executor/executor.cairo +392 -0
- package/layerzero/src/workers/executor/fee_lib/executor_fee_lib.cairo +160 -0
- package/layerzero/src/workers/executor/fee_lib/interface.cairo +87 -0
- package/layerzero/src/workers/executor/interface.cairo +131 -0
- package/layerzero/src/workers/executor/options.cairo +244 -0
- package/layerzero/src/workers/executor/structs.cairo +119 -0
- package/layerzero/src/workers/interface.cairo +32 -0
- package/layerzero/src/workers/price_feed/constants.cairo +7 -0
- package/layerzero/src/workers/price_feed/errors.cairo +28 -0
- package/layerzero/src/workers/price_feed/events.cairo +13 -0
- package/layerzero/src/workers/price_feed/interface.cairo +264 -0
- package/layerzero/src/workers/price_feed/price_feed.cairo +392 -0
- package/layerzero/src/workers/price_feed/structs.cairo +74 -0
- package/layerzero/tests/common/test_constants.cairo +21 -0
- package/layerzero/tests/common/test_guid.cairo +232 -0
- package/layerzero/tests/common/test_packet_v1_codec.cairo +372 -0
- package/layerzero/tests/common/utils.cairo +23 -0
- package/layerzero/tests/e2e/oft_utils.cairo +121 -0
- package/layerzero/tests/e2e/test_counter_with_sml.cairo +194 -0
- package/layerzero/tests/e2e/test_counter_with_uln.cairo +352 -0
- package/layerzero/tests/e2e/test_dvn.cairo +406 -0
- package/layerzero/tests/e2e/test_lz_token.cairo +354 -0
- package/layerzero/tests/e2e/test_oft_compose_with_uln.cairo +364 -0
- package/layerzero/tests/e2e/test_oft_with_sml.cairo +240 -0
- package/layerzero/tests/e2e/test_oft_with_uln.cairo +299 -0
- package/layerzero/tests/e2e/utils.cairo +490 -0
- package/layerzero/tests/endpoint/message_lib_manager/test_message_lib_manager.cairo +2051 -0
- package/layerzero/tests/endpoint/message_lib_manager/utils.cairo +45 -0
- package/layerzero/tests/endpoint/messaging_channel/test_messaging_channel.cairo +621 -0
- package/layerzero/tests/endpoint/messaging_channel/utils.cairo +96 -0
- package/layerzero/tests/endpoint/messaging_composer/test_messaging_composer.cairo +456 -0
- package/layerzero/tests/endpoint/messaging_composer/utils.cairo +75 -0
- package/layerzero/tests/endpoint/test_endpoint_commit.cairo +763 -0
- package/layerzero/tests/endpoint/test_endpoint_lzreceive.cairo +1253 -0
- package/layerzero/tests/endpoint/test_endpoint_quote.cairo +71 -0
- package/layerzero/tests/endpoint/test_endpoint_send.cairo +1327 -0
- package/layerzero/tests/endpoint/utils.cairo +129 -0
- package/layerzero/tests/fuzzable/blockchain_config.cairo +89 -0
- package/layerzero/tests/fuzzable/bytes32.cairo +16 -0
- package/layerzero/tests/fuzzable/contract_address.cairo +67 -0
- package/layerzero/tests/fuzzable/dst_config.cairo +37 -0
- package/layerzero/tests/fuzzable/eid.cairo +23 -0
- package/layerzero/tests/fuzzable/eth_address.cairo +17 -0
- package/layerzero/tests/fuzzable/expiry.cairo +27 -0
- package/layerzero/tests/fuzzable/felt_array.cairo +38 -0
- package/layerzero/tests/fuzzable/inbound_params.cairo +21 -0
- package/layerzero/tests/fuzzable/keys.cairo +16 -0
- package/layerzero/tests/fuzzable/model_type.cairo +27 -0
- package/layerzero/tests/fuzzable/origin.cairo +21 -0
- package/layerzero/tests/fuzzable/price.cairo +32 -0
- package/layerzero/tests/fuzzable/role_admin.cairo +29 -0
- package/layerzero/tests/fuzzable/small_byte_array.cairo +61 -0
- package/layerzero/tests/lib.cairo +177 -0
- package/layerzero/tests/message_lib/sml/test_simple_message_lib.cairo +224 -0
- package/layerzero/tests/message_lib/uln/test_uln_admin.cairo +2150 -0
- package/layerzero/tests/message_lib/uln/test_uln_config.cairo +527 -0
- package/layerzero/tests/message_lib/uln/test_uln_config_storage_node.cairo +69 -0
- package/layerzero/tests/message_lib/uln/test_uln_executor_config.cairo +173 -0
- package/layerzero/tests/message_lib/uln/test_uln_options.cairo +329 -0
- package/layerzero/tests/message_lib/uln/test_uln_quote.cairo +1038 -0
- package/layerzero/tests/message_lib/uln/test_uln_receive.cairo +715 -0
- package/layerzero/tests/message_lib/uln/test_uln_send.cairo +1155 -0
- package/layerzero/tests/message_lib/uln/utils.cairo +59 -0
- package/layerzero/tests/mocks/composer_target.cairo +76 -0
- package/layerzero/tests/mocks/endpoint.cairo +199 -0
- package/layerzero/tests/mocks/erc20/erc20.cairo +50 -0
- package/layerzero/tests/mocks/erc20/interface.cairo +8 -0
- package/layerzero/tests/mocks/message_inspector/message_inspector.cairo +17 -0
- package/layerzero/tests/mocks/message_lib_manager.cairo +98 -0
- package/layerzero/tests/mocks/messaging_channel/interface.cairo +23 -0
- package/layerzero/tests/mocks/messaging_channel/messaging_channel.cairo +138 -0
- package/layerzero/tests/mocks/messaging_composer.cairo +171 -0
- package/layerzero/tests/mocks/oapp_core/interface.cairo +53 -0
- package/layerzero/tests/mocks/oapp_core/oapp_core.cairo +142 -0
- package/layerzero/tests/mocks/oapp_options_type3.cairo +42 -0
- package/layerzero/tests/mocks/oft_core/interface.cairo +28 -0
- package/layerzero/tests/mocks/oft_core/oft_core.cairo +242 -0
- package/layerzero/tests/mocks/receiver.cairo +54 -0
- package/layerzero/tests/mocks/treasury/lz_token_fee_lib.cairo +57 -0
- package/layerzero/tests/mocks/treasury/treasury.cairo +74 -0
- package/layerzero/tests/mocks/uln_config/interface.cairo +12 -0
- package/layerzero/tests/mocks/uln_config/uln_config.cairo +35 -0
- package/layerzero/tests/mocks/workers/base.cairo +80 -0
- package/layerzero/tests/mocks/workers/dvn.cairo +115 -0
- package/layerzero/tests/mocks/workers/executor/decode/decode.cairo +97 -0
- package/layerzero/tests/mocks/workers/executor/decode/interface.cairo +59 -0
- package/layerzero/tests/mocks/workers/executor/executor.cairo +176 -0
- package/layerzero/tests/oapps/common/test_oapp_options_type_3.cairo +279 -0
- package/layerzero/tests/oapps/oft/test_oft_adapter.cairo +441 -0
- package/layerzero/tests/oapps/oft/test_oft_compose_msg_codec.cairo +139 -0
- package/layerzero/tests/oapps/oft/test_oft_core.cairo +751 -0
- package/layerzero/tests/oapps/oft/test_oft_msg_codec.cairo +268 -0
- package/layerzero/tests/oapps/test_counter.cairo +470 -0
- package/layerzero/tests/oapps/test_oapp_core.cairo +750 -0
- package/layerzero/tests/treasury/test_lz_token_fee_lib.cairo +63 -0
- package/layerzero/tests/treasury/test_treasury.cairo +458 -0
- package/layerzero/tests/treasury/utils.cairo +8 -0
- package/layerzero/tests/utils.cairo +48 -0
- package/layerzero/tests/workers/base/test_worker_base.cairo +1097 -0
- package/layerzero/tests/workers/base/utils.cairo +76 -0
- package/layerzero/tests/workers/dvn/fee_lib/test_dvn_fee_lib.cairo +361 -0
- package/layerzero/tests/workers/dvn/test_dvn.cairo +1101 -0
- package/layerzero/tests/workers/dvn/test_dvn_options.cairo +312 -0
- package/layerzero/tests/workers/dvn/utils.cairo +236 -0
- package/layerzero/tests/workers/executor/fee_lib/test_executor_fee_lib.cairo +223 -0
- package/layerzero/tests/workers/executor/test_decode.cairo +612 -0
- package/layerzero/tests/workers/executor/test_executor.cairo +1472 -0
- package/layerzero/tests/workers/executor/utils.cairo +296 -0
- package/layerzero/tests/workers/price_feed/test_price_feed.cairo +879 -0
- package/layerzero/tests/workers/price_feed/utils.cairo +37 -0
- package/libs/enumerable_set/Scarb.lock +24 -0
- package/libs/enumerable_set/Scarb.toml +17 -0
- package/libs/enumerable_set/src/enumerable_set.cairo +118 -0
- package/libs/enumerable_set/src/lib.cairo +4 -0
- package/libs/enumerable_set/tests/lib.cairo +5 -0
- package/libs/enumerable_set/tests/mocks/mock_enumerable_set.cairo +61 -0
- package/libs/enumerable_set/tests/test_enumerable_set.cairo +379 -0
- package/libs/lz_utils/Scarb.lock +24 -0
- package/libs/lz_utils/Scarb.toml +17 -0
- package/libs/lz_utils/src/bytes.cairo +33 -0
- package/libs/lz_utils/src/error.cairo +12 -0
- package/libs/lz_utils/src/keccak.cairo +28 -0
- package/libs/lz_utils/src/lib.cairo +3 -0
- package/libs/multisig/Scarb.lock +172 -0
- package/libs/multisig/Scarb.toml +23 -0
- package/libs/multisig/src/errors.cairo +84 -0
- package/libs/multisig/src/events.cairo +13 -0
- package/libs/multisig/src/interface.cairo +73 -0
- package/libs/multisig/src/lib.cairo +7 -0
- package/libs/multisig/src/multisig.cairo +241 -0
- package/libs/multisig/tests/lib.cairo +4 -0
- package/libs/multisig/tests/mocks/mock_multisig.cairo +57 -0
- package/libs/multisig/tests/test_multisig.cairo +452 -0
- package/package.json +41 -0
- package/src/scripts/build-abi.ts +51 -0
- package/target/CACHEDIR.TAG +3 -0
- package/target/dev/.fingerprint/alexandria_bytes-5ea6u5t70d7qi/alexandria_bytes +1 -0
- package/target/dev/.fingerprint/alexandria_data_structures-0aue3g6q80gs0/alexandria_data_structures +1 -0
- package/target/dev/.fingerprint/alexandria_math-h2fi7jdq4isuu/alexandria_math +1 -0
- package/target/dev/.fingerprint/core-lq3u730l5p1ag/core +1 -0
- package/target/dev/.fingerprint/core-vf7fc6rvic5vi/core +1 -0
- package/target/dev/.fingerprint/enumerable_set-eaerkg8njl85o/enumerable_set +1 -0
- package/target/dev/.fingerprint/enumerable_set-r54oje7t06ku8/enumerable_set +1 -0
- package/target/dev/.fingerprint/layerzero-oqgdqsaddpi2k/layerzero +1 -0
- package/target/dev/.fingerprint/lz_utils-kfkkeueiqg0pa/lz_utils +1 -0
- package/target/dev/.fingerprint/lz_utils-u4v1os6e7gkng/lz_utils +1 -0
- package/target/dev/.fingerprint/multisig-0fjetugejecge/multisig +1 -0
- package/target/dev/.fingerprint/multisig-6j5kqs436hm54/multisig +1 -0
- package/target/dev/.fingerprint/openzeppelin-ei1id1hu088lo/openzeppelin +1 -0
- package/target/dev/.fingerprint/openzeppelin-j9d5nd1qhfnu6/openzeppelin +1 -0
- package/target/dev/.fingerprint/openzeppelin_access-3oa41aikpaek0/openzeppelin_access +1 -0
- package/target/dev/.fingerprint/openzeppelin_access-p5h849v8so76q/openzeppelin_access +1 -0
- package/target/dev/.fingerprint/openzeppelin_account-4qhv5fks84g9u/openzeppelin_account +1 -0
- package/target/dev/.fingerprint/openzeppelin_account-hgbm8ln9ah7rm/openzeppelin_account +1 -0
- package/target/dev/.fingerprint/openzeppelin_finance-n70q9al0cps8i/openzeppelin_finance +1 -0
- package/target/dev/.fingerprint/openzeppelin_finance-nnd4f8703t3ak/openzeppelin_finance +1 -0
- package/target/dev/.fingerprint/openzeppelin_governance-3gnk21ubp5lis/openzeppelin_governance +1 -0
- package/target/dev/.fingerprint/openzeppelin_governance-rj1bfont4fij4/openzeppelin_governance +1 -0
- package/target/dev/.fingerprint/openzeppelin_introspection-3fja9hd1gvbcq/openzeppelin_introspection +1 -0
- package/target/dev/.fingerprint/openzeppelin_introspection-jc3nf5525eet6/openzeppelin_introspection +1 -0
- package/target/dev/.fingerprint/openzeppelin_merkle_tree-4en77ogr2r2l2/openzeppelin_merkle_tree +1 -0
- package/target/dev/.fingerprint/openzeppelin_merkle_tree-4t190frqs4db8/openzeppelin_merkle_tree +1 -0
- package/target/dev/.fingerprint/openzeppelin_presets-aqb0f6p9c0bp6/openzeppelin_presets +1 -0
- package/target/dev/.fingerprint/openzeppelin_presets-nseg8korhin8e/openzeppelin_presets +1 -0
- package/target/dev/.fingerprint/openzeppelin_security-g7p73ji1ih1qg/openzeppelin_security +1 -0
- package/target/dev/.fingerprint/openzeppelin_security-qp5328v80452u/openzeppelin_security +1 -0
- package/target/dev/.fingerprint/openzeppelin_token-jjf7tl9rphc6k/openzeppelin_token +1 -0
- package/target/dev/.fingerprint/openzeppelin_token-r6s43vlpj6rqk/openzeppelin_token +1 -0
- package/target/dev/.fingerprint/openzeppelin_upgrades-0dpbnre7engca/openzeppelin_upgrades +1 -0
- package/target/dev/.fingerprint/openzeppelin_upgrades-2sqgvbuv9s800/openzeppelin_upgrades +1 -0
- package/target/dev/.fingerprint/openzeppelin_utils-mj395ivff1ffo/openzeppelin_utils +1 -0
- package/target/dev/.fingerprint/openzeppelin_utils-oh1hse8sjumgm/openzeppelin_utils +1 -0
- package/target/dev/.fingerprint/starkware_utils-1qnnjnq0pf9u0/starkware_utils +1 -0
- package/target/dev/.fingerprint/starkware_utils-mh8e3te65lju4/starkware_utils +1 -0
- package/target/dev/enumerable_set.sierra.json +1 -0
- package/target/dev/incremental/alexandria_bytes-5ea6u5t70d7qi.bin +0 -0
- package/target/dev/incremental/alexandria_data_structures-0aue3g6q80gs0.bin +0 -0
- package/target/dev/incremental/alexandria_math-h2fi7jdq4isuu.bin +0 -0
- package/target/dev/incremental/core-lq3u730l5p1ag.bin +0 -0
- package/target/dev/incremental/core-vf7fc6rvic5vi.bin +0 -0
- package/target/dev/incremental/enumerable_set-eaerkg8njl85o.bin +0 -0
- package/target/dev/incremental/enumerable_set-r54oje7t06ku8.bin +0 -0
- package/target/dev/incremental/layerzero-oqgdqsaddpi2k.bin +0 -0
- package/target/dev/incremental/lz_utils-kfkkeueiqg0pa.bin +0 -0
- package/target/dev/incremental/lz_utils-u4v1os6e7gkng.bin +0 -0
- package/target/dev/incremental/multisig-0fjetugejecge.bin +0 -0
- package/target/dev/incremental/multisig-6j5kqs436hm54.bin +0 -0
- package/target/dev/incremental/openzeppelin-ei1id1hu088lo.bin +0 -0
- package/target/dev/incremental/openzeppelin-j9d5nd1qhfnu6.bin +0 -0
- package/target/dev/incremental/openzeppelin_access-3oa41aikpaek0.bin +0 -0
- package/target/dev/incremental/openzeppelin_access-p5h849v8so76q.bin +0 -0
- package/target/dev/incremental/openzeppelin_account-4qhv5fks84g9u.bin +0 -0
- package/target/dev/incremental/openzeppelin_account-hgbm8ln9ah7rm.bin +0 -0
- package/target/dev/incremental/openzeppelin_finance-n70q9al0cps8i.bin +0 -0
- package/target/dev/incremental/openzeppelin_finance-nnd4f8703t3ak.bin +0 -0
- package/target/dev/incremental/openzeppelin_governance-3gnk21ubp5lis.bin +0 -0
- package/target/dev/incremental/openzeppelin_governance-rj1bfont4fij4.bin +0 -0
- package/target/dev/incremental/openzeppelin_introspection-3fja9hd1gvbcq.bin +0 -0
- package/target/dev/incremental/openzeppelin_introspection-jc3nf5525eet6.bin +0 -0
- package/target/dev/incremental/openzeppelin_merkle_tree-4en77ogr2r2l2.bin +0 -0
- package/target/dev/incremental/openzeppelin_merkle_tree-4t190frqs4db8.bin +0 -0
- package/target/dev/incremental/openzeppelin_presets-aqb0f6p9c0bp6.bin +0 -0
- package/target/dev/incremental/openzeppelin_presets-nseg8korhin8e.bin +0 -0
- package/target/dev/incremental/openzeppelin_security-g7p73ji1ih1qg.bin +0 -0
- package/target/dev/incremental/openzeppelin_security-qp5328v80452u.bin +0 -0
- package/target/dev/incremental/openzeppelin_token-jjf7tl9rphc6k.bin +0 -0
- package/target/dev/incremental/openzeppelin_token-r6s43vlpj6rqk.bin +0 -0
- package/target/dev/incremental/openzeppelin_upgrades-0dpbnre7engca.bin +0 -0
- package/target/dev/incremental/openzeppelin_upgrades-2sqgvbuv9s800.bin +0 -0
- package/target/dev/incremental/openzeppelin_utils-mj395ivff1ffo.bin +0 -0
- package/target/dev/incremental/openzeppelin_utils-oh1hse8sjumgm.bin +0 -0
- package/target/dev/incremental/starkware_utils-1qnnjnq0pf9u0.bin +0 -0
- package/target/dev/incremental/starkware_utils-mh8e3te65lju4.bin +0 -0
- package/target/dev/layerzero.starknet_artifacts.json +1 -0
- package/target/dev/layerzero_BlockedMessageLib.compiled_contract_class.json +1 -0
- package/target/dev/layerzero_BlockedMessageLib.contract_class.json +1 -0
- package/target/dev/layerzero_Dvn.compiled_contract_class.json +1 -0
- package/target/dev/layerzero_Dvn.contract_class.json +1 -0
- package/target/dev/layerzero_DvnFeeLib.compiled_contract_class.json +1 -0
- package/target/dev/layerzero_DvnFeeLib.contract_class.json +1 -0
- package/target/dev/layerzero_Endpoint.compiled_contract_class.json +1 -0
- package/target/dev/layerzero_Endpoint.contract_class.json +1 -0
- package/target/dev/layerzero_Executor.compiled_contract_class.json +1 -0
- package/target/dev/layerzero_Executor.contract_class.json +1 -0
- package/target/dev/layerzero_ExecutorFeeLib.compiled_contract_class.json +1 -0
- package/target/dev/layerzero_ExecutorFeeLib.contract_class.json +1 -0
- package/target/dev/layerzero_OApp.compiled_contract_class.json +1 -0
- package/target/dev/layerzero_OApp.contract_class.json +1 -0
- package/target/dev/layerzero_OFT.compiled_contract_class.json +1 -0
- package/target/dev/layerzero_OFT.contract_class.json +1 -0
- package/target/dev/layerzero_OFTAdapter.compiled_contract_class.json +1 -0
- package/target/dev/layerzero_OFTAdapter.contract_class.json +1 -0
- package/target/dev/layerzero_OmniCounter.compiled_contract_class.json +1 -0
- package/target/dev/layerzero_OmniCounter.contract_class.json +1 -0
- package/target/dev/layerzero_PriceFeed.compiled_contract_class.json +1 -0
- package/target/dev/layerzero_PriceFeed.contract_class.json +1 -0
- package/target/dev/layerzero_SimpleMessageLib.compiled_contract_class.json +1 -0
- package/target/dev/layerzero_SimpleMessageLib.contract_class.json +1 -0
- package/target/dev/layerzero_Treasury.compiled_contract_class.json +1 -0
- package/target/dev/layerzero_Treasury.contract_class.json +1 -0
- package/target/dev/layerzero_UltraLightNode.compiled_contract_class.json +1 -0
- package/target/dev/layerzero_UltraLightNode.contract_class.json +1 -0
- package/target/dev/lz_utils.sierra.json +1 -0
- package/target/dev/multisig.sierra.json +1 -0
- package/tools/update_contracts.sh +19 -0
- package/tsconfig.json +20 -0
- package/tsup.config.ts +7 -0
|
@@ -0,0 +1,542 @@
|
|
|
1
|
+
//! OFT core component implementation
|
|
2
|
+
|
|
3
|
+
#[starknet::component]
|
|
4
|
+
pub mod OFTCoreComponent {
|
|
5
|
+
use core::num::traits::Pow;
|
|
6
|
+
use lz_utils::bytes::Bytes32;
|
|
7
|
+
use openzeppelin::access::ownable::OwnableComponent;
|
|
8
|
+
use openzeppelin::access::ownable::OwnableComponent::{
|
|
9
|
+
InternalImpl as OwnableInternalImpl, InternalTrait as OwnableInternalTrait,
|
|
10
|
+
};
|
|
11
|
+
use openzeppelin::token::erc20::interface::{IERC20Dispatcher, IERC20DispatcherTrait};
|
|
12
|
+
use starknet::storage::{StoragePointerReadAccess, StoragePointerWriteAccess};
|
|
13
|
+
use starknet::{ContractAddress, get_caller_address};
|
|
14
|
+
use starkware_utils::errors::assert_with_byte_array;
|
|
15
|
+
use crate::Origin;
|
|
16
|
+
use crate::common::constants::ZERO_ADDRESS;
|
|
17
|
+
use crate::common::structs::messaging::MessagingFee;
|
|
18
|
+
use crate::endpoint::messaging_composer::interface::{
|
|
19
|
+
IMessagingComposerDispatcher, IMessagingComposerDispatcherTrait,
|
|
20
|
+
};
|
|
21
|
+
use crate::oapps::common::oapp_options_type_3::interface::IOAppOptionsType3;
|
|
22
|
+
use crate::oapps::common::oapp_options_type_3::oapp_options_type_3::OAppOptionsType3Component;
|
|
23
|
+
use crate::oapps::message_inspector::interface::{
|
|
24
|
+
IMessageInspectorDispatcher, IMessageInspectorDispatcherTrait,
|
|
25
|
+
};
|
|
26
|
+
use crate::oapps::oapp::oapp_core::OAppCoreComponent;
|
|
27
|
+
use crate::oapps::oft::errors::{
|
|
28
|
+
err_amount_sd_overflowed, err_invalid_local_decimals, err_slippage_exceeded,
|
|
29
|
+
};
|
|
30
|
+
use crate::oapps::oft::events::{MsgInspectorSet, OFTReceived, OFTSent};
|
|
31
|
+
use crate::oapps::oft::interface::IOFT;
|
|
32
|
+
use crate::oapps::oft::oft_compose_msg_codec::OFTComposeMsgCodec;
|
|
33
|
+
use crate::oapps::oft::oft_msg_codec::OFTMsgCodec;
|
|
34
|
+
use crate::oapps::oft::structs::{
|
|
35
|
+
OFTDebit, OFTLimit, OFTMsgAndOptions, OFTQuote, OFTReceipt, OFTSendResult, OFTVersion,
|
|
36
|
+
SendParam,
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
// Constants
|
|
40
|
+
pub const SEND: u16 = 1;
|
|
41
|
+
pub const SEND_AND_CALL: u16 = 2;
|
|
42
|
+
|
|
43
|
+
#[storage]
|
|
44
|
+
pub struct Storage {
|
|
45
|
+
pub OFTCore_decimal_conversion_rate: u256,
|
|
46
|
+
pub OFTCore_msg_inspector: ContractAddress,
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
#[event]
|
|
50
|
+
#[derive(Drop, starknet::Event)]
|
|
51
|
+
pub enum Event {
|
|
52
|
+
OFTSent: OFTSent,
|
|
53
|
+
OFTReceived: OFTReceived,
|
|
54
|
+
MsgInspectorSet: MsgInspectorSet,
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/// Hooks for the OFT (Omnichain Fungible Token) contract
|
|
58
|
+
///
|
|
59
|
+
/// These hooks define the core token operations that must be implemented by any OFT contract.
|
|
60
|
+
/// They handle the actual token transfers, metadata, and approval requirements for cross-chain
|
|
61
|
+
/// operations.
|
|
62
|
+
pub trait IOFTHooks<TContractState> {
|
|
63
|
+
/// Debits tokens from the sender's account when initiating a cross-chain transfer
|
|
64
|
+
///
|
|
65
|
+
/// This function is called when a user sends tokens to another chain. It should:
|
|
66
|
+
/// - Remove the specified amount from the sender's balance
|
|
67
|
+
/// - Apply any fees or dust removal as needed
|
|
68
|
+
/// - Validate that the minimum amount requirements are met
|
|
69
|
+
/// - Return the actual amounts that were debited and will be received
|
|
70
|
+
///
|
|
71
|
+
/// # Arguments
|
|
72
|
+
/// * `from` - The address to debit tokens from (typically the caller)
|
|
73
|
+
/// * `amount` - The amount of tokens to debit (in local decimals)
|
|
74
|
+
/// * `min_amount` - The minimum amount that must be received after fees/dust removal
|
|
75
|
+
/// * `dst_eid` - The destination endpoint ID where tokens are being sent
|
|
76
|
+
///
|
|
77
|
+
/// # Returns
|
|
78
|
+
/// * `(amount_sent_ld, amount_received_ld)` - Tuple of actual amount debited and amount
|
|
79
|
+
/// that will be received
|
|
80
|
+
fn _debit(
|
|
81
|
+
ref self: ComponentState<TContractState>,
|
|
82
|
+
from: ContractAddress,
|
|
83
|
+
amount: u256,
|
|
84
|
+
min_amount: u256,
|
|
85
|
+
dst_eid: u32,
|
|
86
|
+
) -> OFTDebit;
|
|
87
|
+
|
|
88
|
+
/// Credits tokens to the recipient's account when receiving a cross-chain transfer
|
|
89
|
+
///
|
|
90
|
+
/// This function is called when tokens arrive from another chain. It should:
|
|
91
|
+
/// - Add the specified amount to the recipient's balance
|
|
92
|
+
/// - Handle any minting or token release logic as appropriate
|
|
93
|
+
/// - Return the actual amount that was credited (may differ from input due to fees)
|
|
94
|
+
///
|
|
95
|
+
/// # Arguments
|
|
96
|
+
/// * `to` - The address to credit tokens to
|
|
97
|
+
/// * `amount` - The amount of tokens to credit (in local decimals)
|
|
98
|
+
/// * `src_eid` - The source endpoint ID where tokens came from
|
|
99
|
+
///
|
|
100
|
+
/// # Returns
|
|
101
|
+
/// * `amount_received_ld` - The actual amount credited to the recipient's account
|
|
102
|
+
fn _credit(
|
|
103
|
+
ref self: ComponentState<TContractState>,
|
|
104
|
+
to: ContractAddress,
|
|
105
|
+
amount: u256,
|
|
106
|
+
src_eid: u32,
|
|
107
|
+
) -> u256;
|
|
108
|
+
|
|
109
|
+
/// Returns the underlying token contract address
|
|
110
|
+
///
|
|
111
|
+
/// For adapter OFTs, this returns the address of the existing ERC20 token.
|
|
112
|
+
/// For native OFTs, this typically returns the OFT contract's own address.
|
|
113
|
+
///
|
|
114
|
+
/// # Returns
|
|
115
|
+
/// * `ContractAddress` - The address of the underlying token contract
|
|
116
|
+
fn _token(self: @ComponentState<TContractState>) -> ContractAddress;
|
|
117
|
+
|
|
118
|
+
/// Indicates whether the OFT requires token approval before transfers
|
|
119
|
+
///
|
|
120
|
+
/// Returns true if users must approve the OFT contract to spend their tokens
|
|
121
|
+
/// before calling send(). This is typically true for adapter OFTs that wrap
|
|
122
|
+
/// existing tokens, and false for native OFTs where the contract owns the tokens.
|
|
123
|
+
///
|
|
124
|
+
/// # Returns
|
|
125
|
+
/// * `bool` - True if approval is required, false otherwise
|
|
126
|
+
fn _approval_required(self: @ComponentState<TContractState>) -> bool;
|
|
127
|
+
|
|
128
|
+
/// Returns the shared decimals of the OFT
|
|
129
|
+
///
|
|
130
|
+
/// # Returns
|
|
131
|
+
/// * `u8` - The shared decimals of the OFT
|
|
132
|
+
fn _shared_decimals(self: @ComponentState<TContractState>) -> u8;
|
|
133
|
+
|
|
134
|
+
/// Returns the OFT version
|
|
135
|
+
///
|
|
136
|
+
/// # Returns
|
|
137
|
+
/// * `OFTVersion` - The OFT version
|
|
138
|
+
/// * `interface_id` - The OFT onchain interface ID
|
|
139
|
+
/// * `version` - The OFT version compatible cross-chain
|
|
140
|
+
fn oft_version(
|
|
141
|
+
self: @ComponentState<TContractState>,
|
|
142
|
+
) -> OFTVersion {
|
|
143
|
+
OFTVersion { interface_id: 1, // Standard OFT interface ID
|
|
144
|
+
version: 1_u64 }
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
#[generate_trait]
|
|
149
|
+
pub impl InternalImpl<
|
|
150
|
+
TContractState,
|
|
151
|
+
+HasComponent<TContractState>,
|
|
152
|
+
impl IOFTHooks: IOFTHooks<TContractState>,
|
|
153
|
+
impl Ownable: OwnableComponent::HasComponent<TContractState>,
|
|
154
|
+
impl OAppOptionsType3: OAppOptionsType3Component::HasComponent<TContractState>,
|
|
155
|
+
impl OAppCore: OAppCoreComponent::HasComponent<TContractState>,
|
|
156
|
+
+Drop<TContractState>,
|
|
157
|
+
> of InternalTrait<TContractState> {
|
|
158
|
+
/// Initializes the OFT Core component with decimal configuration
|
|
159
|
+
///
|
|
160
|
+
/// Provides a conversion rate when swapping between denominations of SD and LD:
|
|
161
|
+
/// - shareDecimals == SD == shared Decimals
|
|
162
|
+
/// - localDecimals == LD == local decimals
|
|
163
|
+
///
|
|
164
|
+
/// Considers that tokens have different decimal amounts on various chains.
|
|
165
|
+
/// For a token:
|
|
166
|
+
/// - locally with 4 decimals --> 1.2345 => uint(12345)
|
|
167
|
+
/// - remotely with 2 decimals --> 1.23 => uint(123)
|
|
168
|
+
/// - The conversion rate would be 10 ** (4 - 2) = 100
|
|
169
|
+
///
|
|
170
|
+
/// If you want to send 1.2345 -> (uint 12345), you CANNOT represent that value on the
|
|
171
|
+
/// remote, you can only display 1.23 -> uint(123).
|
|
172
|
+
/// To preserve the dust that would otherwise be lost on that conversion,
|
|
173
|
+
/// we need to unify a denomination that can be represented on ALL chains inside of the OFT
|
|
174
|
+
/// mesh.
|
|
175
|
+
///
|
|
176
|
+
/// # Arguments
|
|
177
|
+
/// * `local_decimals` - The decimals of the token on the local chain (this chain)
|
|
178
|
+
///
|
|
179
|
+
/// # Panics
|
|
180
|
+
/// * If `local_decimals` is less than `shared_decimals` (would cause precision loss)
|
|
181
|
+
fn initializer(ref self: ComponentState<TContractState>, local_decimals: u8) {
|
|
182
|
+
let shared_decimals = self.shared_decimals();
|
|
183
|
+
assert_with_byte_array(
|
|
184
|
+
local_decimals >= shared_decimals,
|
|
185
|
+
err_invalid_local_decimals(local_decimals, shared_decimals),
|
|
186
|
+
);
|
|
187
|
+
|
|
188
|
+
// Calculate decimal conversion rate
|
|
189
|
+
let decimals_diff = local_decimals - shared_decimals;
|
|
190
|
+
let conversion_rate = 10_u256.pow(decimals_diff.into());
|
|
191
|
+
self.OFTCore_decimal_conversion_rate.write(conversion_rate);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/// Internal function to handle the receive on the LayerZero endpoint
|
|
195
|
+
///
|
|
196
|
+
/// The src sending chain doesn't know the address length on this chain (potentially
|
|
197
|
+
/// non-evm)
|
|
198
|
+
/// thus everything is bytes32() encoded in flight.
|
|
199
|
+
/// Credits the amountLD to the recipient and returns the ACTUAL amount the recipient
|
|
200
|
+
/// received in local decimals.
|
|
201
|
+
///
|
|
202
|
+
/// # Arguments
|
|
203
|
+
/// * `origin` - The origin information containing:
|
|
204
|
+
/// - src_eid: The source chain endpoint ID
|
|
205
|
+
/// - sender: The sender address from the src chain
|
|
206
|
+
/// - nonce: The nonce of the LayerZero message
|
|
207
|
+
/// * `guid` - The unique identifier for the received LayerZero message
|
|
208
|
+
/// * `message` - The encoded message
|
|
209
|
+
/// * `executor` - The address of the executor (unused in the default implementation)
|
|
210
|
+
/// * `value` - Native token value sent with the message (unused in the default
|
|
211
|
+
/// implementation)
|
|
212
|
+
/// * `extra_data` - Additional data (unused in the default implementation)
|
|
213
|
+
fn _lz_receive(
|
|
214
|
+
ref self: ComponentState<TContractState>,
|
|
215
|
+
origin: Origin,
|
|
216
|
+
guid: Bytes32,
|
|
217
|
+
message: ByteArray,
|
|
218
|
+
executor: ContractAddress,
|
|
219
|
+
value: u256,
|
|
220
|
+
extra_data: ByteArray,
|
|
221
|
+
) {
|
|
222
|
+
let Origin { src_eid, nonce, .. } = origin;
|
|
223
|
+
|
|
224
|
+
// Decode the OFT message
|
|
225
|
+
let to_bytes32 = OFTMsgCodec::send_to(@message);
|
|
226
|
+
let amount_sd = OFTMsgCodec::amount_sd(@message);
|
|
227
|
+
|
|
228
|
+
// Convert to local decimals
|
|
229
|
+
let amount_ld = self._to_ld(amount_sd);
|
|
230
|
+
|
|
231
|
+
// Convert recipient from bytes32 to address
|
|
232
|
+
let to_address = OFTMsgCodec::bytes32_to_address(to_bytes32).unwrap();
|
|
233
|
+
|
|
234
|
+
let amount_received_ld = IOFTHooks::_credit(ref self, to_address, amount_ld, src_eid);
|
|
235
|
+
|
|
236
|
+
// Handle compose messages - Proprietary composeMsg format for the OFT
|
|
237
|
+
if OFTMsgCodec::is_composed(@message) {
|
|
238
|
+
let compose_msg = OFTMsgCodec::compose_msg(@message);
|
|
239
|
+
|
|
240
|
+
let endpoint_dispatcher = IMessagingComposerDispatcher {
|
|
241
|
+
contract_address: get_dep_component!(@self, OAppCore).OAppCore_endpoint.read(),
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
// Stores the lz_compose payload that will be executed in a separate tx.
|
|
245
|
+
// Standardizes functionality for executing arbitrary contract invocation on some
|
|
246
|
+
// non-evm chains.
|
|
247
|
+
// The off-chain executor will listen and process the msg based on the
|
|
248
|
+
// src-chain-callers compose options passed.
|
|
249
|
+
// The index is used when a OApp needs to compose multiple msgs on lzReceive.
|
|
250
|
+
// For default OFT implementation there is only 1 compose msg per lzReceive, thus
|
|
251
|
+
// its always 0.
|
|
252
|
+
endpoint_dispatcher
|
|
253
|
+
.send_compose(
|
|
254
|
+
to_address,
|
|
255
|
+
guid,
|
|
256
|
+
0,
|
|
257
|
+
OFTComposeMsgCodec::encode(
|
|
258
|
+
nonce, src_eid, amount_received_ld, @compose_msg,
|
|
259
|
+
),
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
self.emit(OFTReceived { guid, src_eid, to: to_address, amount_received_ld });
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
/// Internal function to convert an amount from shared decimals into local decimals
|
|
267
|
+
///
|
|
268
|
+
/// # Arguments
|
|
269
|
+
/// * `amount_sd` - The amount in shared decimals
|
|
270
|
+
///
|
|
271
|
+
/// # Returns
|
|
272
|
+
/// * `u256` - The amount in local decimals
|
|
273
|
+
fn _to_ld(self: @ComponentState<TContractState>, amount_sd: u64) -> u256 {
|
|
274
|
+
let conversion_rate = self.OFTCore_decimal_conversion_rate.read();
|
|
275
|
+
amount_sd.into() * conversion_rate
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
/// Internal function to convert an amount from local decimals into shared decimals
|
|
279
|
+
///
|
|
280
|
+
/// # Arguments
|
|
281
|
+
/// * `amount_ld` - The amount in local decimals
|
|
282
|
+
///
|
|
283
|
+
/// # Returns
|
|
284
|
+
/// * `u64` - The amount in shared decimals
|
|
285
|
+
fn _to_sd(self: @ComponentState<TContractState>, amount_ld: u256) -> u64 {
|
|
286
|
+
let conversion_rate = self.OFTCore_decimal_conversion_rate.read();
|
|
287
|
+
let amount_sd_u256 = amount_ld / conversion_rate;
|
|
288
|
+
let converted = amount_sd_u256.try_into();
|
|
289
|
+
assert_with_byte_array(converted.is_some(), err_amount_sd_overflowed(amount_sd_u256));
|
|
290
|
+
converted.unwrap()
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/// Internal function to remove dust from the given local decimal amount
|
|
294
|
+
///
|
|
295
|
+
/// Prevents the loss of dust when moving amounts between chains with different decimals.
|
|
296
|
+
///
|
|
297
|
+
/// # Arguments
|
|
298
|
+
/// * `amount_ld` - The amount in local decimals
|
|
299
|
+
///
|
|
300
|
+
/// # Returns
|
|
301
|
+
/// * `u256` - The amount after removing dust
|
|
302
|
+
///
|
|
303
|
+
/// # Example
|
|
304
|
+
/// uint(123) with a conversion rate of 100 becomes uint(100)
|
|
305
|
+
fn _remove_dust(self: @ComponentState<TContractState>, amount_ld: u256) -> u256 {
|
|
306
|
+
let conversion_rate = self.OFTCore_decimal_conversion_rate.read();
|
|
307
|
+
(amount_ld / conversion_rate) * conversion_rate
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
/// Internal function to mock the amount mutation from a OFT debit() operation
|
|
311
|
+
///
|
|
312
|
+
/// This is where things like fees would be calculated and deducted from the amount to be
|
|
313
|
+
/// received on the remote.
|
|
314
|
+
///
|
|
315
|
+
/// # Arguments
|
|
316
|
+
/// * `amount_ld` - The amount to send in local decimals
|
|
317
|
+
/// * `min_amount_ld` - The minimum amount to send in local decimals
|
|
318
|
+
/// * `dst_eid` - The destination endpoint ID
|
|
319
|
+
///
|
|
320
|
+
/// # Returns
|
|
321
|
+
/// * `(u256, u256)` - Tuple of (amount_sent_ld, amount_received_ld)
|
|
322
|
+
/// - amount_sent_ld: The amount sent, in local decimals
|
|
323
|
+
/// - amount_received_ld: The amount to be received on the remote chain, in local decimals
|
|
324
|
+
///
|
|
325
|
+
/// # Panics
|
|
326
|
+
/// * If `amount_received_ld` is less than `min_amount_ld` (slippage exceeded)
|
|
327
|
+
fn _debit_view(
|
|
328
|
+
self: @ComponentState<TContractState>,
|
|
329
|
+
amount_ld: u256,
|
|
330
|
+
min_amount_ld: u256,
|
|
331
|
+
dst_eid: u32,
|
|
332
|
+
) -> OFTDebit {
|
|
333
|
+
// Removes the dust so nothing is lost on the conversion between chains with different
|
|
334
|
+
// decimals for the token.
|
|
335
|
+
let amount_sent_ld = self._remove_dust(amount_ld);
|
|
336
|
+
// The amount to send is the same as amount received in the default implementation.
|
|
337
|
+
let amount_received_ld = amount_sent_ld;
|
|
338
|
+
|
|
339
|
+
// Check for slippage
|
|
340
|
+
assert_with_byte_array(
|
|
341
|
+
amount_received_ld >= min_amount_ld,
|
|
342
|
+
err_slippage_exceeded(amount_received_ld, min_amount_ld),
|
|
343
|
+
);
|
|
344
|
+
|
|
345
|
+
OFTDebit { amount_sent_ld, amount_received_ld }
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
/// Internal function to build the message and options
|
|
349
|
+
///
|
|
350
|
+
/// This generated message has the msg.sender encoded into the payload so the remote knows
|
|
351
|
+
/// who the caller is.
|
|
352
|
+
/// Must include a non empty bytes if you want to compose, EVEN if you don't need it on the
|
|
353
|
+
/// remote.
|
|
354
|
+
/// EVEN if you don't require an arbitrary payload to be sent... eg. '0x01'
|
|
355
|
+
/// Changes the msg type depending if it's composed or not.
|
|
356
|
+
/// Combines the caller's _extraOptions with the enforced options via the OAppOptionsType3.
|
|
357
|
+
///
|
|
358
|
+
/// # Arguments
|
|
359
|
+
/// * `send_param` - The parameters for the send() operation
|
|
360
|
+
/// * `amount_ld` - The amount in local decimals
|
|
361
|
+
///
|
|
362
|
+
/// # Returns
|
|
363
|
+
/// * `(ByteArray, ByteArray)` - Tuple of (message, options)
|
|
364
|
+
/// - message: The encoded message
|
|
365
|
+
/// - options: The encoded options
|
|
366
|
+
fn _build_msg_and_options(
|
|
367
|
+
self: @ComponentState<TContractState>, send_param: @SendParam, amount_ld: u256,
|
|
368
|
+
) -> OFTMsgAndOptions {
|
|
369
|
+
let SendParam { to, compose_msg, extra_options, dst_eid, .. } = send_param;
|
|
370
|
+
|
|
371
|
+
// Convert amount to shared decimals
|
|
372
|
+
let amount_sd = self._to_sd(amount_ld);
|
|
373
|
+
|
|
374
|
+
// Encode OFT message
|
|
375
|
+
let (message, has_compose) = OFTMsgCodec::encode(*to, amount_sd, compose_msg);
|
|
376
|
+
|
|
377
|
+
let msg_type = if has_compose {
|
|
378
|
+
SEND_AND_CALL
|
|
379
|
+
} else {
|
|
380
|
+
SEND
|
|
381
|
+
};
|
|
382
|
+
|
|
383
|
+
let oapp_options_type_3 = get_dep_component!(self, OAppOptionsType3);
|
|
384
|
+
let options = oapp_options_type_3
|
|
385
|
+
.combine_options(*dst_eid, msg_type, extra_options.clone());
|
|
386
|
+
|
|
387
|
+
// Optionally inspect the message and options depending
|
|
388
|
+
// if the OApp owner has set a msg inspector.
|
|
389
|
+
// If it fails inspection, needs to revert in the implementation.
|
|
390
|
+
// ie. does not rely on return boolean
|
|
391
|
+
let msg_inspector = self.OFTCore_msg_inspector.read();
|
|
392
|
+
if msg_inspector != ZERO_ADDRESS {
|
|
393
|
+
let inspector_dispatcher = IMessageInspectorDispatcher {
|
|
394
|
+
contract_address: msg_inspector,
|
|
395
|
+
};
|
|
396
|
+
inspector_dispatcher.inspect_msg(message.clone(), options.clone());
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
OFTMsgAndOptions { message, options }
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
#[embeddable_as(OFTCoreImpl)]
|
|
404
|
+
impl OFT<
|
|
405
|
+
TContractState,
|
|
406
|
+
+HasComponent<TContractState>,
|
|
407
|
+
impl IOFTHooks: IOFTHooks<TContractState>,
|
|
408
|
+
impl Ownable: OwnableComponent::HasComponent<TContractState>,
|
|
409
|
+
impl OAppCore: OAppCoreComponent::HasComponent<TContractState>,
|
|
410
|
+
+OAppOptionsType3Component::HasComponent<TContractState>,
|
|
411
|
+
+Drop<TContractState>,
|
|
412
|
+
> of IOFT<ComponentState<TContractState>> {
|
|
413
|
+
fn oft_version(self: @ComponentState<TContractState>) -> OFTVersion {
|
|
414
|
+
IOFTHooks::oft_version(self)
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
fn token(self: @ComponentState<TContractState>) -> ContractAddress {
|
|
418
|
+
IOFTHooks::_token(self)
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
fn approval_required(self: @ComponentState<TContractState>) -> bool {
|
|
422
|
+
IOFTHooks::_approval_required(self)
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
fn shared_decimals(self: @ComponentState<TContractState>) -> u8 {
|
|
426
|
+
IOFTHooks::_shared_decimals(self)
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
fn decimal_conversion_rate(self: @ComponentState<TContractState>) -> u256 {
|
|
430
|
+
self.OFTCore_decimal_conversion_rate.read()
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
fn set_msg_inspector(
|
|
434
|
+
ref self: ComponentState<TContractState>, msg_inspector: ContractAddress,
|
|
435
|
+
) {
|
|
436
|
+
get_dep_component!(@self, Ownable).assert_only_owner();
|
|
437
|
+
|
|
438
|
+
self.OFTCore_msg_inspector.write(msg_inspector);
|
|
439
|
+
self.emit(MsgInspectorSet { msg_inspector });
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
fn msg_inspector(self: @ComponentState<TContractState>) -> ContractAddress {
|
|
443
|
+
self.OFTCore_msg_inspector.read()
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
fn quote_oft(self: @ComponentState<TContractState>, send_param: SendParam) -> OFTQuote {
|
|
447
|
+
let SendParam { dst_eid, amount_ld, min_amount_ld, .. } = send_param;
|
|
448
|
+
|
|
449
|
+
// Calculate amounts using debit view
|
|
450
|
+
let OFTDebit {
|
|
451
|
+
amount_sent_ld, amount_received_ld,
|
|
452
|
+
} = self._debit_view(amount_ld, min_amount_ld, dst_eid);
|
|
453
|
+
|
|
454
|
+
// Create limit using token total supply for max amount (mirror Solidity)
|
|
455
|
+
let oft_token_dispatcher = IERC20Dispatcher {
|
|
456
|
+
contract_address: IOFTHooks::_token(self),
|
|
457
|
+
};
|
|
458
|
+
let limit = OFTLimit {
|
|
459
|
+
min_amount_ld: 0, max_amount_ld: oft_token_dispatcher.total_supply(),
|
|
460
|
+
};
|
|
461
|
+
|
|
462
|
+
// No additional fees in default implementation
|
|
463
|
+
let oft_fee_details = array![];
|
|
464
|
+
|
|
465
|
+
// Create receipt
|
|
466
|
+
let receipt = OFTReceipt { amount_sent_ld, amount_received_ld };
|
|
467
|
+
|
|
468
|
+
OFTQuote { limit, oft_fee_details, receipt }
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
fn quote_send(
|
|
472
|
+
self: @ComponentState<TContractState>, send_param: SendParam, pay_in_lz_token: bool,
|
|
473
|
+
) -> MessagingFee {
|
|
474
|
+
let SendParam { dst_eid, amount_ld, min_amount_ld, .. } = send_param.clone();
|
|
475
|
+
// Get the amounts that would be debited/received
|
|
476
|
+
let OFTDebit {
|
|
477
|
+
amount_received_ld, ..,
|
|
478
|
+
} = self._debit_view(amount_ld, min_amount_ld, dst_eid);
|
|
479
|
+
|
|
480
|
+
// Build message and options
|
|
481
|
+
let OFTMsgAndOptions {
|
|
482
|
+
message, options,
|
|
483
|
+
} = self._build_msg_and_options(@send_param, amount_received_ld);
|
|
484
|
+
|
|
485
|
+
// Quote through OApp core
|
|
486
|
+
let oapp_core = get_dep_component!(self, OAppCore);
|
|
487
|
+
OAppCoreComponent::OAppSenderImpl::_quote(
|
|
488
|
+
oapp_core, dst_eid, message, options, pay_in_lz_token,
|
|
489
|
+
)
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
fn send(
|
|
493
|
+
ref self: ComponentState<TContractState>,
|
|
494
|
+
send_param: SendParam,
|
|
495
|
+
fee: MessagingFee,
|
|
496
|
+
refund_address: ContractAddress,
|
|
497
|
+
) -> OFTSendResult {
|
|
498
|
+
let SendParam { dst_eid, amount_ld, min_amount_ld, .. } = send_param.clone();
|
|
499
|
+
let from = get_caller_address();
|
|
500
|
+
|
|
501
|
+
// 1. Debit tokens from sender
|
|
502
|
+
let OFTDebit {
|
|
503
|
+
amount_sent_ld, amount_received_ld,
|
|
504
|
+
} =
|
|
505
|
+
IOFTHooks::_debit(
|
|
506
|
+
ref self,
|
|
507
|
+
from, // from - the address calling the send function
|
|
508
|
+
amount_ld,
|
|
509
|
+
min_amount_ld,
|
|
510
|
+
dst_eid,
|
|
511
|
+
);
|
|
512
|
+
|
|
513
|
+
// 2. Build message and options
|
|
514
|
+
let OFTMsgAndOptions {
|
|
515
|
+
message, options,
|
|
516
|
+
} = self._build_msg_and_options(@send_param, amount_received_ld);
|
|
517
|
+
|
|
518
|
+
// 3. Send message through LayerZero endpoint
|
|
519
|
+
let mut oapp_core = get_dep_component_mut!(ref self, OAppCore);
|
|
520
|
+
let message_receipt = OAppCoreComponent::OAppSenderImpl::_lz_send(
|
|
521
|
+
ref oapp_core, dst_eid, message, options, fee, refund_address,
|
|
522
|
+
);
|
|
523
|
+
|
|
524
|
+
// 4. Emit event
|
|
525
|
+
self
|
|
526
|
+
.emit(
|
|
527
|
+
OFTSent {
|
|
528
|
+
guid: message_receipt.guid,
|
|
529
|
+
dst_eid,
|
|
530
|
+
from,
|
|
531
|
+
amount_sent_ld,
|
|
532
|
+
amount_received_ld,
|
|
533
|
+
},
|
|
534
|
+
);
|
|
535
|
+
|
|
536
|
+
// 5. Return the result
|
|
537
|
+
OFTSendResult {
|
|
538
|
+
message_receipt, oft_receipt: OFTReceipt { amount_sent_ld, amount_received_ld },
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
}
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/// OFTMsgCodec - Cairo implementation of the Solidity OFTMsgCodec library
|
|
2
|
+
/// Handles encoding and decoding of OFT messages
|
|
3
|
+
pub mod OFTMsgCodec {
|
|
4
|
+
use alexandria_bytes::byte_array_ext::ByteArrayTraitExt;
|
|
5
|
+
use lz_utils::bytes::Bytes32;
|
|
6
|
+
use starknet::{ContractAddress, get_caller_address};
|
|
7
|
+
|
|
8
|
+
// Offset constants for encoding and decoding OFT messages
|
|
9
|
+
pub const SEND_TO_OFFSET: usize = 32;
|
|
10
|
+
pub const SEND_AMOUNT_SD_OFFSET: usize = 40;
|
|
11
|
+
|
|
12
|
+
/// Encodes an OFT LayerZero message.
|
|
13
|
+
///
|
|
14
|
+
/// # Arguments
|
|
15
|
+
/// * `send_to` - The recipient address as bytes32
|
|
16
|
+
/// * `amount_sd` - The amount in shared decimals (u64)
|
|
17
|
+
/// * `compose_msg` - The composed message
|
|
18
|
+
///
|
|
19
|
+
/// # Returns
|
|
20
|
+
/// * `(message, has_compose)` - The encoded message and whether it has compose
|
|
21
|
+
pub fn encode(send_to: Bytes32, amount_sd: u64, compose_msg: @ByteArray) -> (ByteArray, bool) {
|
|
22
|
+
let has_compose = compose_msg.len() > 0;
|
|
23
|
+
let mut message: ByteArray = Default::default();
|
|
24
|
+
|
|
25
|
+
// Encode send_to (32 bytes)
|
|
26
|
+
message.append_u256(send_to.value);
|
|
27
|
+
|
|
28
|
+
// Encode amount_sd (8 bytes)
|
|
29
|
+
message.append_u64(amount_sd);
|
|
30
|
+
|
|
31
|
+
if has_compose {
|
|
32
|
+
// For composed messages, include the caller (msg.sender equivalent)
|
|
33
|
+
let caller_bytes32: Bytes32 = get_caller_address().into();
|
|
34
|
+
message.append_u256(caller_bytes32.value);
|
|
35
|
+
message.append(compose_msg);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
(message, has_compose)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/// Checks if the OFT message is composed.
|
|
42
|
+
///
|
|
43
|
+
/// # Arguments
|
|
44
|
+
/// * `message` - The OFT message
|
|
45
|
+
///
|
|
46
|
+
/// # Returns
|
|
47
|
+
/// * `bool` - True if the message is composed
|
|
48
|
+
pub fn is_composed(message: @ByteArray) -> bool {
|
|
49
|
+
message.len() > SEND_AMOUNT_SD_OFFSET
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/// Retrieves the recipient address from the OFT message.
|
|
53
|
+
///
|
|
54
|
+
/// # Arguments
|
|
55
|
+
/// * `message` - The OFT message
|
|
56
|
+
///
|
|
57
|
+
/// # Returns
|
|
58
|
+
/// * `Bytes32` - The recipient address
|
|
59
|
+
pub fn send_to(message: @ByteArray) -> Bytes32 {
|
|
60
|
+
let (_, send_to_value) = message.read_u256(0);
|
|
61
|
+
Bytes32 { value: send_to_value }
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/// Retrieves the amount in shared decimals from the OFT message.
|
|
65
|
+
///
|
|
66
|
+
/// # Arguments
|
|
67
|
+
/// * `message` - The OFT message
|
|
68
|
+
///
|
|
69
|
+
/// # Returns
|
|
70
|
+
/// * `u64` - The amount in shared decimals
|
|
71
|
+
pub fn amount_sd(message: @ByteArray) -> u64 {
|
|
72
|
+
let (_, amount_value) = message.read_u64(SEND_TO_OFFSET);
|
|
73
|
+
amount_value
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/// Retrieves the composed message from the OFT message.
|
|
77
|
+
///
|
|
78
|
+
/// # Arguments
|
|
79
|
+
/// * `message` - The OFT message
|
|
80
|
+
///
|
|
81
|
+
/// # Returns
|
|
82
|
+
/// * `ByteArray` - The composed message
|
|
83
|
+
pub fn compose_msg(message: @ByteArray) -> ByteArray {
|
|
84
|
+
if message.len() > SEND_AMOUNT_SD_OFFSET {
|
|
85
|
+
let compose_length = message.len() - SEND_AMOUNT_SD_OFFSET;
|
|
86
|
+
let (_, compose_value) = message.read_bytes(SEND_AMOUNT_SD_OFFSET, compose_length);
|
|
87
|
+
compose_value
|
|
88
|
+
} else {
|
|
89
|
+
Default::default()
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/// Retrieves the sender address from a composed message.
|
|
94
|
+
/// Only valid for composed messages that include sender information.
|
|
95
|
+
///
|
|
96
|
+
/// # Arguments
|
|
97
|
+
/// * `message` - The OFT message
|
|
98
|
+
///
|
|
99
|
+
/// # Returns
|
|
100
|
+
/// * `Option<Bytes32>` - The sender address if available
|
|
101
|
+
pub fn composed_sender(message: @ByteArray) -> Option<Bytes32> {
|
|
102
|
+
if is_composed(message) && message.len() >= SEND_AMOUNT_SD_OFFSET + SEND_TO_OFFSET {
|
|
103
|
+
let (_, sender_value) = message.read_u256(SEND_AMOUNT_SD_OFFSET);
|
|
104
|
+
Option::Some(Bytes32 { value: sender_value })
|
|
105
|
+
} else {
|
|
106
|
+
Option::None
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/// Converts a ContractAddress to Bytes32.
|
|
111
|
+
///
|
|
112
|
+
/// # Arguments
|
|
113
|
+
/// * `addr` - The address to convert
|
|
114
|
+
///
|
|
115
|
+
/// # Returns
|
|
116
|
+
/// * `Bytes32` - The bytes32 representation
|
|
117
|
+
pub fn address_to_bytes32(addr: ContractAddress) -> Bytes32 {
|
|
118
|
+
addr.into()
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/// Converts Bytes32 to a ContractAddress.
|
|
122
|
+
///
|
|
123
|
+
/// # Arguments
|
|
124
|
+
/// * `b` - The bytes32 value to convert
|
|
125
|
+
///
|
|
126
|
+
/// # Returns
|
|
127
|
+
/// * `Option<ContractAddress>` - The address if valid
|
|
128
|
+
pub fn bytes32_to_address(b: Bytes32) -> Option<ContractAddress> {
|
|
129
|
+
b.try_into()
|
|
130
|
+
}
|
|
131
|
+
}
|