@layerzerolabs/protocol-stellar-v2 0.2.13 → 0.2.18
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 +484 -337
- package/.turbo/turbo-lint.log +126 -56
- package/.turbo/turbo-test.log +1403 -984
- package/Cargo.lock +142 -3
- package/Cargo.toml +5 -1
- package/contracts/ERROR_SPEC.md +44 -0
- package/contracts/common-macros/src/auth.rs +113 -0
- package/contracts/common-macros/src/contract_ttl.rs +84 -0
- package/contracts/common-macros/src/lib.rs +219 -29
- package/contracts/common-macros/src/lz_contract.rs +83 -0
- package/contracts/common-macros/src/storage.rs +1 -1
- package/contracts/common-macros/src/tests/{ownable.rs → auth.rs} +48 -15
- package/contracts/common-macros/src/tests/contract_ttl.rs +662 -0
- package/contracts/common-macros/src/tests/mod.rs +3 -2
- package/contracts/common-macros/src/tests/snapshots/common_macros__tests__auth__snapshot_generated_multisig_code.snap +20 -0
- package/contracts/common-macros/src/tests/snapshots/common_macros__tests__auth__snapshot_generated_ownable_code.snap +24 -0
- package/contracts/common-macros/src/tests/snapshots/{common_macros__tests__ownable__snapshot_only_owner_preserves_function_signature.snap → common_macros__tests__auth__snapshot_only_auth_preserves_function_signature.snap} +4 -4
- package/contracts/common-macros/src/tests/snapshots/{common_macros__tests__contract_impl__snapshot_generated_contract_impl_code.snap → common_macros__tests__contract_ttl__snapshot_generated_contractimpl_code.snap} +26 -10
- package/contracts/common-macros/src/tests/snapshots/common_macros__tests__contract_ttl__snapshot_generated_contracttrait_code.snap +69 -0
- package/contracts/common-macros/src/tests/snapshots/common_macros__tests__storage__snapshot_generated_storage_code.snap +48 -48
- package/contracts/common-macros/src/tests/snapshots/common_macros__tests__ttl_configurable__snapshot_generated_ttl_configurable_code.snap +7 -41
- package/contracts/common-macros/src/tests/snapshots/common_macros__tests__upgradeable__snapshot_generated_upgradeable_code.snap +21 -0
- package/contracts/common-macros/src/tests/upgradeable.rs +31 -0
- package/contracts/common-macros/src/ttl_configurable.rs +21 -66
- package/contracts/common-macros/src/ttl_extendable.rs +36 -0
- package/contracts/common-macros/src/upgradeable.rs +76 -0
- package/contracts/common-macros/src/utils.rs +9 -0
- package/contracts/endpoint-v2/src/constants.rs +4 -4
- package/contracts/endpoint-v2/src/endpoint_v2.rs +58 -36
- package/contracts/endpoint-v2/src/errors.rs +4 -3
- package/contracts/endpoint-v2/src/events.rs +1 -1
- package/contracts/endpoint-v2/src/message_lib_manager.rs +18 -5
- package/contracts/endpoint-v2/src/messaging_channel.rs +11 -1
- package/contracts/endpoint-v2/src/messaging_composer.rs +11 -1
- package/contracts/endpoint-v2/src/storage.rs +1 -1
- package/contracts/endpoint-v2/src/tests/endpoint_setup.rs +175 -8
- package/contracts/endpoint-v2/src/tests/endpoint_v2/build_outbound_packet.rs +76 -0
- package/contracts/endpoint-v2/src/tests/endpoint_v2/clear.rs +342 -159
- package/contracts/endpoint-v2/src/tests/endpoint_v2/delegate.rs +3 -15
- package/contracts/endpoint-v2/src/tests/endpoint_v2/initializable.rs +20 -31
- package/contracts/endpoint-v2/src/tests/endpoint_v2/lz_receive_alert.rs +126 -164
- package/contracts/endpoint-v2/src/tests/endpoint_v2/mod.rs +1 -0
- package/contracts/endpoint-v2/src/tests/endpoint_v2/native_token.rs +0 -1
- package/contracts/endpoint-v2/src/tests/endpoint_v2/owner.rs +0 -1
- package/contracts/endpoint-v2/src/tests/endpoint_v2/pay_messaging_fees.rs +311 -304
- package/contracts/endpoint-v2/src/tests/endpoint_v2/quote.rs +423 -96
- package/contracts/endpoint-v2/src/tests/endpoint_v2/recover_token.rs +1 -1
- package/contracts/endpoint-v2/src/tests/endpoint_v2/require_oapp_auth.rs +47 -20
- package/contracts/endpoint-v2/src/tests/endpoint_v2/send.rs +373 -403
- package/contracts/endpoint-v2/src/tests/endpoint_v2/set_delegate.rs +96 -22
- package/contracts/endpoint-v2/src/tests/endpoint_v2/set_zro.rs +62 -10
- package/contracts/endpoint-v2/src/tests/endpoint_v2/transfer_ownership.rs +4 -4
- package/contracts/endpoint-v2/src/tests/endpoint_v2/ttl_config.rs +8 -11
- package/contracts/endpoint-v2/src/tests/endpoint_v2/verifiable.rs +81 -30
- package/contracts/endpoint-v2/src/tests/endpoint_v2/verify.rs +209 -76
- package/contracts/endpoint-v2/src/tests/endpoint_v2/zro.rs +0 -1
- package/contracts/endpoint-v2/src/tests/message_lib_manager/default_receive_library.rs +24 -0
- package/contracts/endpoint-v2/src/tests/message_lib_manager/default_receive_library_timeout.rs +40 -0
- package/contracts/endpoint-v2/src/tests/message_lib_manager/default_send_library.rs +24 -0
- package/contracts/endpoint-v2/src/tests/message_lib_manager/get_config.rs +108 -0
- package/contracts/endpoint-v2/src/tests/message_lib_manager/get_library_index.rs +52 -0
- package/contracts/endpoint-v2/src/tests/message_lib_manager/get_receive_library.rs +92 -0
- package/contracts/endpoint-v2/src/tests/message_lib_manager/get_registered_libraries.rs +74 -0
- package/contracts/endpoint-v2/src/tests/message_lib_manager/get_send_library.rs +83 -0
- package/contracts/endpoint-v2/src/tests/message_lib_manager/is_registered_library.rs +32 -0
- package/contracts/endpoint-v2/src/tests/message_lib_manager/is_supported_eid.rs +28 -0
- package/contracts/endpoint-v2/src/tests/message_lib_manager/is_valid_receive_library.rs +261 -0
- package/contracts/endpoint-v2/src/tests/message_lib_manager/mod.rs +16 -0
- package/contracts/endpoint-v2/src/tests/message_lib_manager/receive_library_timeout.rs +62 -0
- package/contracts/endpoint-v2/src/tests/message_lib_manager/register_library.rs +65 -43
- package/contracts/endpoint-v2/src/tests/message_lib_manager/registered_libraries_count.rs +42 -0
- package/contracts/endpoint-v2/src/tests/message_lib_manager/require_receive_lib_for_eid.rs +61 -0
- package/contracts/endpoint-v2/src/tests/message_lib_manager/require_registered.rs +4 -6
- package/contracts/endpoint-v2/src/tests/message_lib_manager/require_send_lib_for_eid.rs +59 -0
- package/contracts/endpoint-v2/src/tests/message_lib_manager/require_supported_eid.rs +16 -2
- package/contracts/endpoint-v2/src/tests/message_lib_manager/set_config.rs +155 -51
- package/contracts/endpoint-v2/src/tests/message_lib_manager/set_default_receive_lib_timeout.rs +114 -92
- package/contracts/endpoint-v2/src/tests/message_lib_manager/set_default_receive_library.rs +235 -132
- package/contracts/endpoint-v2/src/tests/message_lib_manager/set_default_send_library.rs +93 -87
- package/contracts/endpoint-v2/src/tests/message_lib_manager/set_receive_library.rs +346 -245
- package/contracts/endpoint-v2/src/tests/message_lib_manager/set_receive_library_timeout.rs +406 -60
- package/contracts/endpoint-v2/src/tests/message_lib_manager/set_send_library.rs +252 -78
- package/contracts/endpoint-v2/src/tests/message_lib_manager/timeout.rs +102 -0
- package/contracts/endpoint-v2/src/tests/messaging_channel/burn.rs +212 -273
- package/contracts/endpoint-v2/src/tests/messaging_channel/clear_payload.rs +203 -0
- package/contracts/endpoint-v2/src/tests/messaging_channel/inbound.rs +94 -0
- package/contracts/endpoint-v2/src/tests/messaging_channel/inbound_nonce.rs +78 -248
- package/contracts/endpoint-v2/src/tests/messaging_channel/inbound_payload_hash.rs +7 -282
- package/contracts/endpoint-v2/src/tests/messaging_channel/lazy_inbound_nonce.rs +6 -274
- package/contracts/endpoint-v2/src/tests/messaging_channel/mod.rs +3 -2
- package/contracts/endpoint-v2/src/tests/messaging_channel/next_guid.rs +86 -178
- package/contracts/endpoint-v2/src/tests/messaging_channel/nilify.rs +328 -212
- package/contracts/endpoint-v2/src/tests/messaging_channel/outbound.rs +68 -0
- package/contracts/endpoint-v2/src/tests/messaging_channel/outbound_nonce.rs +6 -209
- package/contracts/endpoint-v2/src/tests/messaging_channel/skip.rs +207 -159
- package/contracts/endpoint-v2/src/tests/messaging_composer/clear_compose.rs +142 -153
- package/contracts/endpoint-v2/src/tests/messaging_composer/compose_queue.rs +6 -179
- package/contracts/endpoint-v2/src/tests/messaging_composer/lz_compose_alert.rs +163 -221
- package/contracts/endpoint-v2/src/tests/messaging_composer/send_compose.rs +90 -121
- package/contracts/endpoint-v2/src/tests/mock.rs +18 -4
- package/contracts/endpoint-v2/src/tests/util/build_payload.rs +4 -70
- package/contracts/endpoint-v2/src/tests/util/compute_guid.rs +2 -1
- package/contracts/endpoint-v2/src/tests/util/keccak256.rs +17 -106
- package/contracts/layerzero-views/Cargo.toml +35 -0
- package/contracts/layerzero-views/src/errors.rs +10 -0
- package/contracts/layerzero-views/src/layerzero_view.rs +226 -0
- package/contracts/layerzero-views/src/lib.rs +38 -0
- package/contracts/layerzero-views/src/storage.rs +18 -0
- package/contracts/layerzero-views/src/tests/layerzero_view_tests.rs +423 -0
- package/contracts/layerzero-views/src/tests/mod.rs +4 -0
- package/contracts/layerzero-views/src/tests/setup.rs +377 -0
- package/contracts/layerzero-views/src/types.rs +50 -0
- package/contracts/macro-integration-tests/Cargo.toml +30 -0
- package/contracts/macro-integration-tests/src/lib.rs +1 -0
- package/contracts/macro-integration-tests/tests/runtime/ownable/initialization.rs +62 -0
- package/contracts/macro-integration-tests/tests/runtime/ownable/mod.rs +22 -0
- package/contracts/macro-integration-tests/tests/runtime/ownable/only_auth_guard.rs +97 -0
- package/contracts/macro-integration-tests/tests/runtime/ownable/ownership_transfer.rs +101 -0
- package/contracts/macro-integration-tests/tests/runtime/storage/keyed_roundtrip.rs +225 -0
- package/contracts/macro-integration-tests/tests/runtime/storage/mod.rs +4 -0
- package/contracts/macro-integration-tests/tests/runtime/storage/name_override_runtime.rs +52 -0
- package/contracts/macro-integration-tests/tests/runtime/storage/ttl_extension.rs +261 -0
- package/contracts/macro-integration-tests/tests/runtime/storage/unkeyed_roundtrip.rs +137 -0
- package/contracts/macro-integration-tests/tests/runtime/ttl_configurable/configuration.rs +113 -0
- package/contracts/macro-integration-tests/tests/runtime/ttl_configurable/freeze.rs +139 -0
- package/contracts/macro-integration-tests/tests/runtime/ttl_configurable/mod.rs +2 -0
- package/contracts/macro-integration-tests/tests/runtime.rs +5 -0
- package/contracts/macro-integration-tests/tests/ui/error/fail/attr_not_empty.rs +12 -0
- package/contracts/macro-integration-tests/tests/ui/error/fail/attr_not_empty.stderr +7 -0
- package/contracts/macro-integration-tests/tests/ui/error/fail/decreasing_discriminant.rs +12 -0
- package/contracts/macro-integration-tests/tests/ui/error/fail/decreasing_discriminant.stderr +7 -0
- package/contracts/macro-integration-tests/tests/ui/error/fail/non_int_discriminant.rs +21 -0
- package/contracts/macro-integration-tests/tests/ui/error/fail/non_int_discriminant.stderr +7 -0
- package/contracts/macro-integration-tests/tests/ui/error/fail/non_unit_variant.rs +13 -0
- package/contracts/macro-integration-tests/tests/ui/error/fail/non_unit_variant.stderr +7 -0
- package/contracts/macro-integration-tests/tests/ui/error/pass/attr_on_variant_allowed.rs +20 -0
- package/contracts/macro-integration-tests/tests/ui/error/pass/basic_auto_discriminants.rs +15 -0
- package/contracts/macro-integration-tests/tests/ui/error/pass/mixed_discriminants.rs +16 -0
- package/contracts/macro-integration-tests/tests/ui/ownable/fail/only_auth_missing_env.rs +22 -0
- package/contracts/macro-integration-tests/tests/ui/ownable/fail/only_auth_missing_env.stderr +16 -0
- package/contracts/macro-integration-tests/tests/ui/ownable/pass/minimal_contract.rs +26 -0
- package/contracts/macro-integration-tests/tests/ui/ownable/pass/namespacing_and_imports.rs +21 -0
- package/contracts/macro-integration-tests/tests/ui/ownable/pass/only_auth_env_param_variants.rs +46 -0
- package/contracts/macro-integration-tests/tests/ui/storage/fail/invalid_storage_type_param.rs +13 -0
- package/contracts/macro-integration-tests/tests/ui/storage/fail/invalid_storage_type_param.stderr +7 -0
- package/contracts/macro-integration-tests/tests/ui/storage/fail/missing_storage_type_param.rs +13 -0
- package/contracts/macro-integration-tests/tests/ui/storage/fail/missing_storage_type_param.stderr +7 -0
- package/contracts/macro-integration-tests/tests/ui/storage/fail/multiple_storage_kinds.rs +10 -0
- package/contracts/macro-integration-tests/tests/ui/storage/fail/multiple_storage_kinds.stderr +7 -0
- package/contracts/macro-integration-tests/tests/ui/storage/fail/multiple_type_params.rs +12 -0
- package/contracts/macro-integration-tests/tests/ui/storage/fail/multiple_type_params.stderr +7 -0
- package/contracts/macro-integration-tests/tests/ui/storage/fail/no_ttl_extension_on_non_persistent.rs +10 -0
- package/contracts/macro-integration-tests/tests/ui/storage/fail/no_ttl_extension_on_non_persistent.stderr +7 -0
- package/contracts/macro-integration-tests/tests/ui/storage/fail/non_enum_input.rs +10 -0
- package/contracts/macro-integration-tests/tests/ui/storage/fail/non_enum_input.stderr +7 -0
- package/contracts/macro-integration-tests/tests/ui/storage/fail/storage_attr_rejects_args.rs +12 -0
- package/contracts/macro-integration-tests/tests/ui/storage/fail/storage_attr_rejects_args.stderr +7 -0
- package/contracts/macro-integration-tests/tests/ui/storage/fail/tuple_variant_rejected.rs +13 -0
- package/contracts/macro-integration-tests/tests/ui/storage/fail/tuple_variant_rejected.stderr +7 -0
- package/contracts/macro-integration-tests/tests/ui/storage/fail/unknown_variant_attr.rs +13 -0
- package/contracts/macro-integration-tests/tests/ui/storage/fail/unknown_variant_attr.stderr +7 -0
- package/contracts/macro-integration-tests/tests/ui/storage/pass/default_value_on_variant.rs +14 -0
- package/contracts/macro-integration-tests/tests/ui/storage/pass/enum_instance_unit_basic.rs +14 -0
- package/contracts/macro-integration-tests/tests/ui/storage/pass/enum_persistent_named_fields_keyed.rs +16 -0
- package/contracts/macro-integration-tests/tests/ui/storage/pass/enum_temporary_unit_option.rs +15 -0
- package/contracts/macro-integration-tests/tests/ui/storage/pass/name_override.rs +14 -0
- package/contracts/macro-integration-tests/tests/ui/storage/pass/no_auto_ttl_extension.rs +19 -0
- package/contracts/macro-integration-tests/tests/ui/storage/pass/ttl_provider_basic.rs +15 -0
- package/contracts/macro-integration-tests/tests/ui/ttl_configurable/pass/minimal_contract.rs +44 -0
- package/contracts/macro-integration-tests/tests/ui_error.rs +11 -0
- package/contracts/macro-integration-tests/tests/ui_ownable.rs +11 -0
- package/contracts/macro-integration-tests/tests/ui_storage.rs +11 -0
- package/contracts/macro-integration-tests/tests/ui_ttl_configurable.rs +12 -0
- package/contracts/message-libs/blocked-message-lib/src/lib.rs +17 -17
- package/contracts/message-libs/message-lib-common/src/errors.rs +7 -2
- package/contracts/message-libs/message-lib-common/src/tests/packet_codec_v1/decode_packet_header.rs +64 -0
- package/contracts/message-libs/message-lib-common/src/tests/packet_codec_v1/encode_packet.rs +58 -0
- package/contracts/message-libs/message-lib-common/src/tests/packet_codec_v1/encode_packet_header.rs +138 -0
- package/contracts/message-libs/message-lib-common/src/tests/packet_codec_v1/mod.rs +6 -0
- package/contracts/message-libs/message-lib-common/src/tests/packet_codec_v1/payload.rs +30 -0
- package/contracts/message-libs/message-lib-common/src/tests/packet_codec_v1/payload_hash.rs +15 -0
- package/contracts/message-libs/message-lib-common/src/tests/packet_codec_v1/test_helper.rs +39 -0
- package/contracts/message-libs/message-lib-common/src/tests/worker_options/append_dvn_option.rs +57 -0
- package/contracts/message-libs/message-lib-common/src/tests/worker_options/append_lz_receive_option.rs +49 -0
- package/contracts/message-libs/message-lib-common/src/tests/worker_options/append_native_drop_option.rs +73 -0
- package/contracts/message-libs/message-lib-common/src/tests/worker_options/convert_legacy_options.rs +280 -0
- package/contracts/message-libs/message-lib-common/src/tests/worker_options/extract_type_3_options.rs +126 -0
- package/contracts/message-libs/message-lib-common/src/tests/worker_options/left_pad_to_bytes32.rs +48 -0
- package/contracts/message-libs/message-lib-common/src/tests/worker_options/mod.rs +7 -0
- package/contracts/message-libs/message-lib-common/src/tests/worker_options/split_worker_options.rs +139 -0
- package/contracts/message-libs/message-lib-common/src/worker_options.rs +31 -1
- package/contracts/message-libs/simple-message-lib/src/simple_message_lib.rs +7 -9
- package/contracts/message-libs/treasury/src/errors.rs +2 -3
- package/contracts/message-libs/treasury/src/events.rs +1 -1
- package/contracts/message-libs/treasury/src/interfaces/zro_fee_lib.rs +2 -2
- package/contracts/message-libs/treasury/src/lib.rs +3 -3
- package/contracts/message-libs/treasury/src/storage.rs +3 -1
- package/contracts/message-libs/treasury/src/tests/treasury_tests.rs +1 -1
- package/contracts/message-libs/treasury/src/treasury.rs +23 -26
- package/contracts/message-libs/uln-302/Cargo.toml +1 -1
- package/contracts/message-libs/uln-302/src/errors.rs +0 -5
- package/contracts/message-libs/uln-302/src/events.rs +5 -6
- package/contracts/message-libs/uln-302/src/receive_uln.rs +37 -56
- package/contracts/message-libs/uln-302/src/send_uln.rs +112 -138
- package/contracts/message-libs/uln-302/src/storage.rs +5 -5
- package/contracts/message-libs/uln-302/src/tests/receive_uln302/effective_receive_uln_config.rs +5 -7
- package/contracts/message-libs/uln-302/src/tests/receive_uln302/set_default_receive_uln_configs.rs +3 -3
- package/contracts/message-libs/uln-302/src/tests/send_uln302/effective_send_uln_config.rs +6 -9
- package/contracts/message-libs/uln-302/src/tests/send_uln302/set_default_executor_configs.rs +2 -2
- package/contracts/message-libs/uln-302/src/tests/send_uln302/set_default_send_uln_configs.rs +3 -3
- package/contracts/message-libs/uln-302/src/tests/setup.rs +9 -0
- package/contracts/message-libs/uln-302/src/tests/testing_utils.rs +5 -0
- package/contracts/message-libs/uln-302/src/tests/uln302/get_app_receive_uln_config.rs +1 -2
- package/contracts/message-libs/uln-302/src/tests/uln302/get_app_send_uln_config.rs +1 -2
- package/contracts/message-libs/uln-302/src/tests/uln302/set_config.rs +37 -55
- package/contracts/message-libs/uln-302/src/uln302.rs +10 -25
- package/contracts/oapps/counter/Cargo.toml +14 -1
- package/contracts/oapps/counter/integration_tests/mod.rs +4 -1
- package/contracts/oapps/counter/integration_tests/setup_sml.rs +169 -0
- package/contracts/oapps/counter/integration_tests/setup_uln.rs +997 -0
- package/contracts/oapps/counter/integration_tests/signing.rs +62 -0
- package/contracts/oapps/counter/integration_tests/test_with_sml.rs +24 -55
- package/contracts/oapps/counter/integration_tests/test_with_uln.rs +314 -0
- package/contracts/oapps/counter/integration_tests/utils.rs +196 -53
- package/contracts/oapps/counter/src/counter.rs +67 -44
- package/contracts/oapps/counter/src/tests/mod.rs +0 -13
- package/contracts/oapps/counter/src/tests/test_counter.rs +5 -7
- package/contracts/oapps/oapp/src/errors.rs +5 -1
- package/contracts/oapps/oapp/src/macro_tests/test_macros.rs +318 -221
- package/contracts/oapps/oapp/src/oapp_core.rs +36 -21
- package/contracts/oapps/oapp/src/oapp_options_type3.rs +48 -12
- package/contracts/oapps/oapp/src/oapp_receiver.rs +106 -41
- package/contracts/oapps/oapp/src/oapp_sender.rs +26 -34
- package/contracts/oapps/oapp/src/tests/test_oapp_core.rs +9 -9
- package/contracts/oapps/oapp/src/tests/test_oapp_options_type3.rs +25 -18
- package/contracts/oapps/oapp/src/tests/test_oapp_receiver.rs +7 -8
- package/contracts/oapps/oapp/src/tests/test_oapp_sender.rs +14 -16
- package/contracts/oapps/oapp-macros/src/generators.rs +128 -0
- package/contracts/oapps/oapp-macros/src/lib.rs +211 -0
- package/contracts/oapps/oft/integration-tests/setup.rs +34 -9
- package/contracts/oapps/oft/integration-tests/utils.rs +1 -1
- package/contracts/oapps/oft/src/errors.rs +6 -1
- package/contracts/oapps/oft/src/extensions/oft_fee.rs +13 -13
- package/contracts/oapps/oft/src/extensions/pausable.rs +5 -5
- package/contracts/oapps/oft/src/extensions/rate_limiter.rs +23 -23
- package/contracts/oapps/oft/src/lib.rs +4 -2
- package/contracts/oapps/oft/src/oft.rs +31 -71
- package/contracts/oapps/oft/src/oft_impl.rs +201 -0
- package/contracts/oapps/oft/src/oft_types/lock_unlock.rs +2 -4
- package/contracts/oapps/oft/src/oft_types/mint_burn.rs +1 -4
- package/contracts/oapps/oft/src/storage.rs +2 -0
- package/contracts/oapps/oft/src/tests/extensions/setup.rs +60 -31
- package/contracts/oapps/oft/src/tests/extensions/test_oft_fee.rs +5 -3
- package/contracts/oapps/oft/src/tests/extensions/test_pausable.rs +5 -3
- package/contracts/oapps/oft/src/tests/extensions/test_rate_limiter.rs +6 -4
- package/contracts/oapps/oft/src/tests/test_decimals.rs +2 -2
- package/contracts/oapps/oft/src/tests/test_oft_msg_codec.rs +1 -2
- package/contracts/oapps/oft/src/tests/test_send.rs +4 -4
- package/contracts/oapps/oft/src/tests/test_utils.rs +122 -81
- package/contracts/oapps/oft/src/types.rs +20 -0
- package/contracts/oapps/oft-std/Cargo.toml +6 -0
- package/contracts/oapps/oft-std/integration-tests/extensions/mod.rs +3 -0
- package/contracts/oapps/oft-std/integration-tests/extensions/test_oft_fee.rs +157 -0
- package/contracts/oapps/oft-std/integration-tests/extensions/test_pausable.rs +162 -0
- package/contracts/oapps/oft-std/integration-tests/extensions/test_rate_limiter.rs +186 -0
- package/contracts/oapps/oft-std/integration-tests/mod.rs +3 -0
- package/contracts/oapps/{counter/integration_tests → oft-std/integration-tests}/setup.rs +76 -30
- package/contracts/oapps/oft-std/integration-tests/utils.rs +427 -0
- package/contracts/oapps/oft-std/src/lib.rs +12 -1
- package/contracts/oapps/oft-std/src/oft.rs +141 -26
- package/contracts/upgrader/Cargo.toml +19 -0
- package/contracts/upgrader/src/lib.rs +96 -0
- package/contracts/upgrader/src/tests/mod.rs +1 -0
- package/contracts/upgrader/src/tests/test_data/test_upgradeable_contract1.wasm +0 -0
- package/contracts/upgrader/src/tests/test_data/test_upgradeable_contract2.wasm +0 -0
- package/contracts/upgrader/src/tests/test_upgrader.rs +120 -0
- package/contracts/utils/src/auth.rs +44 -0
- package/contracts/utils/src/errors.rs +32 -5
- package/contracts/utils/src/lib.rs +5 -1
- package/contracts/utils/src/multisig.rs +211 -0
- package/contracts/utils/src/ownable.rs +50 -60
- package/contracts/utils/src/tests/buffer_reader.rs +6 -6
- package/contracts/utils/src/tests/buffer_writer.rs +6 -6
- package/contracts/utils/src/tests/bytes_ext.rs +2 -4
- package/contracts/utils/src/tests/mod.rs +4 -1
- package/contracts/utils/src/tests/multisig.rs +731 -0
- package/contracts/utils/src/tests/option_ext.rs +18 -0
- package/contracts/utils/src/tests/ownable.rs +22 -70
- package/contracts/utils/src/tests/ttl_configurable.rs +607 -0
- package/contracts/utils/src/tests/upgradeable.rs +290 -0
- package/contracts/utils/src/ttl_configurable.rs +153 -0
- package/contracts/utils/src/ttl_extendable.rs +27 -0
- package/contracts/utils/src/upgradeable.rs +56 -0
- package/contracts/workers/dvn/Cargo.toml +2 -2
- package/contracts/workers/dvn/src/auth.rs +24 -35
- package/contracts/workers/dvn/src/dvn.rs +23 -14
- package/contracts/workers/dvn/src/errors.rs +1 -7
- package/contracts/workers/dvn/src/events.rs +1 -14
- package/contracts/workers/dvn/src/interfaces/dvn.rs +2 -2
- package/contracts/workers/dvn/src/interfaces/mod.rs +0 -2
- package/contracts/workers/dvn/src/storage.rs +3 -13
- package/contracts/workers/dvn/src/tests/auth.rs +4 -4
- package/contracts/workers/dvn/src/tests/dvn.rs +1 -2
- package/contracts/workers/dvn/src/tests/multisig/set_signer.rs +7 -8
- package/contracts/workers/dvn/src/tests/multisig/set_threshold.rs +11 -8
- package/contracts/workers/dvn/src/tests/multisig/verify_signatures.rs +11 -12
- package/contracts/workers/dvn/src/tests/setup.rs +5 -5
- package/contracts/workers/dvn-fee-lib/Cargo.toml +0 -1
- package/contracts/workers/dvn-fee-lib/src/dvn_fee_lib.rs +45 -16
- package/contracts/workers/dvn-fee-lib/src/errors.rs +3 -2
- package/contracts/workers/dvn-fee-lib/src/lib.rs +5 -11
- package/contracts/workers/dvn-fee-lib/src/tests/dvn_fee_lib.rs +30 -16
- package/contracts/workers/executor/src/auth.rs +80 -16
- package/contracts/workers/executor/src/executor.rs +17 -29
- package/contracts/workers/executor/src/storage.rs +2 -9
- package/contracts/workers/executor-fee-lib/Cargo.toml +1 -1
- package/contracts/workers/executor-fee-lib/src/errors.rs +9 -7
- package/contracts/workers/executor-fee-lib/src/executor_fee_lib.rs +153 -121
- package/contracts/workers/executor-helper/Cargo.toml +1 -6
- package/contracts/workers/executor-helper/src/executor_helper.rs +53 -73
- package/contracts/workers/executor-helper/src/lib.rs +1 -7
- package/contracts/workers/price-feed/Cargo.toml +1 -2
- package/contracts/workers/price-feed/src/errors.rs +3 -2
- package/contracts/workers/price-feed/src/lib.rs +5 -6
- package/contracts/workers/price-feed/src/price_feed.rs +42 -23
- package/contracts/workers/worker/Cargo.toml +4 -0
- package/contracts/workers/worker/src/errors.rs +4 -0
- package/contracts/workers/worker/src/interfaces/price_feed.rs +3 -3
- package/contracts/workers/worker/src/lib.rs +2 -2
- package/contracts/workers/worker/src/tests/mod.rs +4 -0
- package/contracts/workers/worker/src/tests/setup.rs +147 -0
- package/contracts/workers/worker/src/tests/worker.rs +502 -0
- package/contracts/workers/worker/src/worker.rs +28 -30
- package/package.json +8 -5
- package/sdk/.turbo/turbo-build.log +1 -0
- package/sdk/.turbo/turbo-test.log +1009 -0
- package/sdk/dist/generated/bml.d.ts +104 -37
- package/sdk/dist/generated/bml.js +83 -42
- package/sdk/dist/generated/counter.d.ts +334 -175
- package/sdk/dist/generated/counter.js +109 -63
- package/sdk/dist/generated/dvn.d.ts +1985 -0
- package/sdk/dist/generated/dvn.js +326 -0
- package/sdk/dist/generated/dvn_fee_lib.d.ts +690 -0
- package/sdk/dist/generated/dvn_fee_lib.js +163 -0
- package/sdk/dist/generated/endpoint.d.ts +155 -46
- package/sdk/dist/generated/endpoint.js +93 -50
- package/sdk/dist/generated/executor.d.ts +1841 -0
- package/sdk/dist/generated/executor.js +312 -0
- package/sdk/dist/generated/executor_fee_lib.d.ts +1083 -0
- package/sdk/dist/generated/executor_fee_lib.js +255 -0
- package/sdk/dist/generated/executor_helper.d.ts +981 -0
- package/sdk/dist/generated/executor_helper.js +236 -0
- package/sdk/dist/generated/oft_std.d.ts +1722 -0
- package/sdk/dist/generated/oft_std.js +316 -0
- package/sdk/dist/generated/price_feed.d.ts +1077 -0
- package/sdk/dist/generated/price_feed.js +210 -0
- package/sdk/dist/generated/sml.d.ts +171 -56
- package/sdk/dist/generated/sml.js +111 -62
- package/sdk/dist/generated/treasury.d.ts +896 -0
- package/sdk/dist/generated/treasury.js +219 -0
- package/sdk/dist/generated/uln302.d.ts +175 -75
- package/sdk/dist/generated/uln302.js +126 -82
- package/sdk/dist/generated/upgrader.d.ts +70 -0
- package/sdk/dist/generated/upgrader.js +19 -0
- package/sdk/dist/index.d.ts +10 -0
- package/sdk/dist/index.js +14 -0
- package/sdk/dist/wasm/blocked-message-lib.d.ts +1 -0
- package/sdk/dist/wasm/blocked-message-lib.js +2 -0
- package/sdk/dist/wasm/counter.d.ts +1 -0
- package/sdk/dist/wasm/counter.js +2 -0
- package/sdk/dist/wasm/dvn-fee-lib.d.ts +1 -0
- package/sdk/dist/wasm/dvn-fee-lib.js +2 -0
- package/sdk/dist/wasm/dvn.d.ts +1 -0
- package/sdk/dist/wasm/dvn.js +2 -0
- package/sdk/dist/wasm/endpoint-v2.d.ts +1 -0
- package/sdk/dist/wasm/endpoint-v2.js +2 -0
- package/sdk/dist/wasm/executor-fee-lib.d.ts +1 -0
- package/sdk/dist/wasm/executor-fee-lib.js +2 -0
- package/sdk/dist/wasm/executor-helper.d.ts +1 -0
- package/sdk/dist/wasm/executor-helper.js +2 -0
- package/sdk/dist/wasm/executor.d.ts +1 -0
- package/sdk/dist/wasm/executor.js +2 -0
- package/sdk/dist/wasm/layerzero-views.d.ts +1 -0
- package/sdk/dist/wasm/layerzero-views.js +2 -0
- package/sdk/dist/wasm/oft-std.d.ts +1 -0
- package/sdk/dist/wasm/oft-std.js +2 -0
- package/sdk/dist/wasm/price-feed.d.ts +1 -0
- package/sdk/dist/wasm/price-feed.js +2 -0
- package/sdk/dist/wasm/simple-message-lib.d.ts +1 -0
- package/sdk/dist/wasm/simple-message-lib.js +2 -0
- package/sdk/dist/wasm/treasury.d.ts +1 -0
- package/sdk/dist/wasm/treasury.js +2 -0
- package/sdk/dist/wasm/uln302.d.ts +1 -0
- package/sdk/dist/wasm/uln302.js +2 -0
- package/sdk/dist/wasm/upgrader.d.ts +1 -0
- package/sdk/dist/wasm/upgrader.js +2 -0
- package/sdk/dist/wasm.d.ts +15 -0
- package/sdk/dist/wasm.js +15 -0
- package/sdk/package.json +7 -4
- package/sdk/src/index.ts +17 -0
- package/sdk/test/counter-sml.test.ts +376 -0
- package/sdk/test/counter-uln.test.ts +493 -0
- package/sdk/test/{oft.test.ts → oft-sml.test.ts} +187 -323
- package/sdk/test/suites/constants.ts +22 -2
- package/sdk/test/suites/dummyContractClient.ts +169 -0
- package/sdk/test/suites/globalSetup.ts +450 -0
- package/sdk/test/suites/localnet.ts +23 -6
- package/sdk/test/upgrader.test.ts +300 -0
- package/sdk/test/utils.ts +558 -85
- package/sdk/vitest.config.ts +21 -0
- package/tools/ts-bindings-gen/src/main.rs +12 -1
- package/turbo.json +2 -0
- package/contracts/common-macros/src/contract_impl.rs +0 -47
- package/contracts/common-macros/src/ownable.rs +0 -59
- package/contracts/common-macros/src/tests/contract_impl.rs +0 -381
- package/contracts/common-macros/src/tests/snapshots/common_macros__tests__ownable__snapshot_generated_ownable_code.snap +0 -32
- package/contracts/endpoint-v2/src/tests/messaging_channel/clear.rs +0 -316
- package/contracts/endpoint-v2/src/tests/messaging_channel/internal.rs +0 -388
- package/contracts/message-libs/message-lib-common/src/tests/packet_codec_v1.rs +0 -162
- package/contracts/message-libs/message-lib-common/src/tests/worker_options.rs +0 -319
- package/contracts/oapp-macros/src/lib.rs +0 -154
- package/contracts/oapp-macros/src/oapp_core.rs +0 -40
- package/contracts/oapp-macros/src/oapp_full.rs +0 -21
- package/contracts/oapp-macros/src/oapp_options_type3.rs +0 -31
- package/contracts/oapp-macros/src/oapp_receiver.rs +0 -48
- package/contracts/oapp-macros/src/oapp_sender.rs +0 -21
- package/contracts/oapp-macros/src/util.rs +0 -107
- package/contracts/oapps/oft/src/constants.rs +0 -5
- package/contracts/oapps/oft/src/default_oft_impl.rs +0 -146
- package/contracts/utils/src/tests/ttl.rs +0 -421
- package/contracts/utils/src/ttl.rs +0 -123
- package/contracts/workers/dvn/src/interfaces/multisig.rs +0 -56
- package/contracts/workers/dvn/src/multisig.rs +0 -153
- package/sdk/test/index.test.ts +0 -376
- /package/contracts/{oapp-macros → oapps/oapp-macros}/Cargo.toml +0 -0
|
@@ -1,14 +1,39 @@
|
|
|
1
1
|
use common_macros::{contract_impl, storage};
|
|
2
|
+
use endpoint_v2::Origin;
|
|
3
|
+
use oapp::oapp_receiver::LzReceiveInternal;
|
|
2
4
|
use oapp_macros::oapp;
|
|
3
|
-
use oft::
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
use oft::{
|
|
6
|
+
errors::OFTError,
|
|
7
|
+
extensions::{
|
|
8
|
+
oft_fee::{OFTFee, OFTFeeInternal},
|
|
9
|
+
pausable::{OFTPausable, OFTPausableInternal},
|
|
10
|
+
rate_limiter::{Direction, RateLimiter, RateLimiterInternal},
|
|
11
|
+
},
|
|
12
|
+
initialize_oft,
|
|
13
|
+
oft::{OFTInternal, OFT},
|
|
14
|
+
oft_impl,
|
|
15
|
+
oft_types::{lock_unlock, mint_burn},
|
|
16
|
+
storage::OFTStorage,
|
|
17
|
+
types::{OFTFeeDetail, OFTLimit, OFTReceipt, SendParam},
|
|
18
|
+
utils::remove_dust,
|
|
19
|
+
};
|
|
20
|
+
use soroban_sdk::{assert_with_error, contracttype, Address, Bytes, BytesN, Env, Vec};
|
|
21
|
+
|
|
22
|
+
/// The mode of operation for the OFT contract
|
|
23
|
+
#[contracttype]
|
|
24
|
+
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
|
25
|
+
#[repr(u8)]
|
|
26
|
+
pub enum OFTMode {
|
|
27
|
+
/// Lock tokens on send, unlock on receive
|
|
28
|
+
LockUnlock = 0,
|
|
29
|
+
/// Burn tokens on send, mint on receive
|
|
30
|
+
MintBurn = 1,
|
|
31
|
+
}
|
|
7
32
|
|
|
8
33
|
#[storage]
|
|
9
34
|
enum OFTStdStorage {
|
|
10
|
-
#[instance(
|
|
11
|
-
|
|
35
|
+
#[instance(OFTMode)]
|
|
36
|
+
Mode,
|
|
12
37
|
}
|
|
13
38
|
|
|
14
39
|
#[oapp]
|
|
@@ -23,37 +48,127 @@ impl OFTStd {
|
|
|
23
48
|
endpoint: &Address,
|
|
24
49
|
delegate: &Option<Address>,
|
|
25
50
|
shared_decimals: u32,
|
|
26
|
-
|
|
51
|
+
mode: OFTMode,
|
|
27
52
|
) {
|
|
28
|
-
|
|
29
|
-
OFTStdStorage::
|
|
53
|
+
initialize_oft::<Self>(env, owner, token, endpoint, delegate, shared_decimals);
|
|
54
|
+
OFTStdStorage::set_mode(env, &mode);
|
|
30
55
|
}
|
|
31
56
|
|
|
32
|
-
///
|
|
33
|
-
pub fn
|
|
34
|
-
OFTStdStorage::
|
|
57
|
+
/// Returns the mode of operation for this OFT (LockUnlock or MintBurn)
|
|
58
|
+
pub fn mode(env: &Env) -> OFTMode {
|
|
59
|
+
OFTStdStorage::mode(env).unwrap()
|
|
35
60
|
}
|
|
36
61
|
}
|
|
37
62
|
|
|
38
|
-
///
|
|
63
|
+
/// LzReceiveInternal implementation using default OFT receive logic
|
|
64
|
+
impl LzReceiveInternal for OFTStd {
|
|
65
|
+
fn __lz_receive(
|
|
66
|
+
env: &Env,
|
|
67
|
+
origin: &Origin,
|
|
68
|
+
guid: &BytesN<32>,
|
|
69
|
+
message: &Bytes,
|
|
70
|
+
extra_data: &Bytes,
|
|
71
|
+
executor: &Address,
|
|
72
|
+
value: i128,
|
|
73
|
+
) {
|
|
74
|
+
oft_impl::lz_receive::<Self>(env, executor, origin, guid, message, extra_data, value)
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/// OFT trait implementation for standard OFT with extensions
|
|
39
79
|
#[contract_impl(contracttrait)]
|
|
40
|
-
impl OFT for OFTStd {
|
|
80
|
+
impl OFT for OFTStd {
|
|
81
|
+
fn quote_oft(env: &Env, send_param: &SendParam) -> (OFTLimit, Vec<OFTFeeDetail>, OFTReceipt) {
|
|
82
|
+
Self::__assert_not_paused(env);
|
|
83
|
+
let (_, fee_details, oft_receipt) = oft_impl::quote_oft::<Self>(env, send_param);
|
|
84
|
+
let capacity = Self::rate_limit_capacity(env, &Direction::Outbound, send_param.dst_eid);
|
|
85
|
+
let oft_limit = OFTLimit { min_amount_ld: 0, max_amount_ld: capacity };
|
|
86
|
+
(oft_limit, fee_details, oft_receipt)
|
|
87
|
+
}
|
|
41
88
|
|
|
42
|
-
|
|
43
|
-
|
|
89
|
+
fn quote_send(env: &Env, sender: &Address, send_param: &SendParam, pay_in_zro: bool) -> endpoint_v2::MessagingFee {
|
|
90
|
+
Self::__assert_not_paused(env);
|
|
91
|
+
oft_impl::quote_send::<Self>(env, sender, send_param, pay_in_zro)
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/// OFT behavior for standard OFT with extension hooks
|
|
96
|
+
impl OFTInternal for OFTStd {
|
|
44
97
|
fn __debit(env: &Env, sender: &Address, amount_ld: i128, min_amount_ld: i128, dst_eid: u32) -> OFTReceipt {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
98
|
+
// 1. Pausable check
|
|
99
|
+
Self::__assert_not_paused(env);
|
|
100
|
+
|
|
101
|
+
// 2. Core debit logic (based on mode)
|
|
102
|
+
let oft_receipt = match Self::mode(env) {
|
|
103
|
+
OFTMode::LockUnlock => lock_unlock::debit::<Self>(env, sender, amount_ld, min_amount_ld, dst_eid),
|
|
104
|
+
OFTMode::MintBurn => mint_burn::debit::<Self>(env, sender, amount_ld, min_amount_ld, dst_eid),
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
// 3. Rate limit checks (using amount_received_ld - the actual cross-chain amount)
|
|
108
|
+
Self::__consume_rate_limit_capacity(env, &Direction::Outbound, dst_eid, oft_receipt.amount_received_ld);
|
|
109
|
+
Self::__release_rate_limit_capacity(env, &Direction::Inbound, dst_eid, oft_receipt.amount_received_ld);
|
|
110
|
+
|
|
111
|
+
// 4. Charge fee (amount_sent_ld - amount_received_ld)
|
|
112
|
+
Self::__charge_fee(env, &Self::token(env), sender, oft_receipt.amount_sent_ld - oft_receipt.amount_received_ld);
|
|
113
|
+
|
|
114
|
+
oft_receipt
|
|
50
115
|
}
|
|
51
116
|
|
|
52
117
|
fn __credit(env: &Env, to: &Address, amount_ld: i128, src_eid: u32) -> i128 {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
118
|
+
// 1. Pausable check
|
|
119
|
+
Self::__assert_not_paused(env);
|
|
120
|
+
|
|
121
|
+
// 2. Core credit logic (based on mode)
|
|
122
|
+
let amount_credited = match Self::mode(env) {
|
|
123
|
+
OFTMode::LockUnlock => lock_unlock::credit::<Self>(env, to, amount_ld, src_eid),
|
|
124
|
+
OFTMode::MintBurn => mint_burn::credit::<Self>(env, to, amount_ld, src_eid),
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
// 3. Rate limit checks (using amount_credited - the actual credited amount)
|
|
128
|
+
Self::__consume_rate_limit_capacity(env, &Direction::Inbound, src_eid, amount_credited);
|
|
129
|
+
Self::__release_rate_limit_capacity(env, &Direction::Outbound, src_eid, amount_credited);
|
|
130
|
+
|
|
131
|
+
amount_credited
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
fn __debit_view(env: &Env, amount_ld: i128, min_amount_ld: i128, dst_eid: u32) -> OFTReceipt {
|
|
135
|
+
let conversion_rate = OFTStorage::decimal_conversion_rate(env).unwrap();
|
|
136
|
+
|
|
137
|
+
// CRITICAL: Apply fee first, then remove dust
|
|
138
|
+
let amount_after_fee = Self::__fee_view(env, dst_eid, amount_ld);
|
|
139
|
+
let amount_received_ld = remove_dust(amount_after_fee, conversion_rate);
|
|
140
|
+
|
|
141
|
+
// amount_sent_ld logic:
|
|
142
|
+
// - If no fee: amount_sent_ld = amount_received_ld (both reduced by dust)
|
|
143
|
+
// - If fee applied: amount_sent_ld = original amount_ld (unchanged)
|
|
144
|
+
// This is to align the behavior with the fee extensions on other VMs
|
|
145
|
+
let amount_sent_ld = if amount_after_fee == amount_ld { amount_received_ld } else { amount_ld };
|
|
146
|
+
|
|
147
|
+
assert_with_error!(env, amount_received_ld >= min_amount_ld, OFTError::SlippageExceeded);
|
|
148
|
+
|
|
149
|
+
OFTReceipt { amount_sent_ld, amount_received_ld }
|
|
58
150
|
}
|
|
59
151
|
}
|
|
152
|
+
|
|
153
|
+
// ==================== Extension Trait Implementations ====================
|
|
154
|
+
|
|
155
|
+
/// Pausable extension - allows pausing/unpausing the OFT
|
|
156
|
+
/// Default state: unpaused (all operations allowed)
|
|
157
|
+
#[contract_impl(contracttrait)]
|
|
158
|
+
impl OFTPausable for OFTStd {}
|
|
159
|
+
|
|
160
|
+
impl OFTPausableInternal for OFTStd {}
|
|
161
|
+
|
|
162
|
+
/// OFT Fee extension - allows collecting fees on transfers
|
|
163
|
+
/// Default state: 0 BPS (no fee collected)
|
|
164
|
+
#[contract_impl(contracttrait)]
|
|
165
|
+
impl OFTFee for OFTStd {}
|
|
166
|
+
|
|
167
|
+
impl OFTFeeInternal for OFTStd {}
|
|
168
|
+
|
|
169
|
+
/// Rate Limiter extension - allows rate limiting transfers
|
|
170
|
+
/// Default state: not set (rate_limit_capacity returns i128::MAX)
|
|
171
|
+
#[contract_impl(contracttrait)]
|
|
172
|
+
impl RateLimiter for OFTStd {}
|
|
173
|
+
|
|
174
|
+
impl RateLimiterInternal for OFTStd {}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
[package]
|
|
2
|
+
name = "upgrader"
|
|
3
|
+
version.workspace = true
|
|
4
|
+
edition.workspace = true
|
|
5
|
+
license.workspace = true
|
|
6
|
+
publish = false
|
|
7
|
+
|
|
8
|
+
[lib]
|
|
9
|
+
crate-type = ["cdylib", "rlib"]
|
|
10
|
+
doctest = false
|
|
11
|
+
|
|
12
|
+
[dependencies]
|
|
13
|
+
soroban-sdk = { workspace = true }
|
|
14
|
+
utils = { workspace = true }
|
|
15
|
+
common-macros = { workspace = true }
|
|
16
|
+
|
|
17
|
+
[dev-dependencies]
|
|
18
|
+
soroban-sdk = { workspace = true, features = ["testutils"] }
|
|
19
|
+
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
#![no_std]
|
|
2
|
+
|
|
3
|
+
//! # Upgrader Contract
|
|
4
|
+
//!
|
|
5
|
+
//! A stateless utility contract for performing upgrade and migrate operations on upgradeable contracts.
|
|
6
|
+
//!
|
|
7
|
+
//! This contract provides a convenient way to upgrade other contracts, especially useful for
|
|
8
|
+
//! performing upgrade+migrate atomically in a single transaction.
|
|
9
|
+
//!
|
|
10
|
+
//! ## Security Model
|
|
11
|
+
//!
|
|
12
|
+
//! The Upgrader is a permissionless utility - anyone can call it, but security is enforced
|
|
13
|
+
//! by the target contract's authorization checks. When you call `upgrader.upgrade()`, the target
|
|
14
|
+
//! contract's `#[only_auth]` guard ensures only the target's authorizer can successfully upgrade it.
|
|
15
|
+
//!
|
|
16
|
+
//! ## Usage
|
|
17
|
+
//!
|
|
18
|
+
//! Deploy this contract once, then anyone can use it to upgrade contracts they own.
|
|
19
|
+
//!
|
|
20
|
+
//! ```ignore
|
|
21
|
+
//! // Deploy upgrader (no initialization needed)
|
|
22
|
+
//! let upgrader_id = env.register(Upgrader, ());
|
|
23
|
+
//! let upgrader = UpgraderClient::new(&env, &upgrader_id);
|
|
24
|
+
//!
|
|
25
|
+
//! // Upgrade a contract (you must be the target contract's owner)
|
|
26
|
+
//! upgrader.upgrade(&target_contract, &new_wasm_hash);
|
|
27
|
+
//!
|
|
28
|
+
//! // Or upgrade and migrate in one transaction
|
|
29
|
+
//! let migration_data = vec![&env, val1, val2];
|
|
30
|
+
//! upgrader.upgrade_and_migrate(&target_contract, &new_wasm_hash, migration_data);
|
|
31
|
+
//! ```
|
|
32
|
+
|
|
33
|
+
use soroban_sdk::{contract, contractclient, contractimpl, symbol_short, Address, BytesN, Env, Symbol, Vec};
|
|
34
|
+
|
|
35
|
+
/// Symbol for the migrate function call
|
|
36
|
+
pub const MIGRATE: Symbol = symbol_short!("migrate");
|
|
37
|
+
|
|
38
|
+
/// Trait representing an upgradeable contract's interface
|
|
39
|
+
#[contractclient(name = "UpgradeableContractClient")]
|
|
40
|
+
pub trait UpgradeableContract {
|
|
41
|
+
/// Upgrades the contract to new WASM bytecode
|
|
42
|
+
fn upgrade(env: &Env, new_wasm_hash: BytesN<32>);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/// Upgrader contract for managing upgrades of other contracts.
|
|
46
|
+
///
|
|
47
|
+
/// This is a stateless utility contract that anyone can use.
|
|
48
|
+
/// Security is enforced by the target contract's ownership checks.
|
|
49
|
+
#[contract]
|
|
50
|
+
pub struct Upgrader;
|
|
51
|
+
|
|
52
|
+
#[contractimpl]
|
|
53
|
+
impl Upgrader {
|
|
54
|
+
/// Upgrade a target contract and run its migration in a single transaction
|
|
55
|
+
///
|
|
56
|
+
/// The caller must be authorized as the authorizer of the target contract.
|
|
57
|
+
/// This is enforced by the target contract's `#[only_auth]` check.
|
|
58
|
+
///
|
|
59
|
+
/// This is useful for atomic upgrades where you want to ensure the migration
|
|
60
|
+
/// happens immediately after the upgrade, or the entire operation fails.
|
|
61
|
+
///
|
|
62
|
+
/// # Arguments
|
|
63
|
+
/// * `contract_address` - The address of the contract to upgrade
|
|
64
|
+
/// * `wasm_hash` - The hash of the new WASM bytecode
|
|
65
|
+
/// * `migration_data` - A vector of values to pass to the migrate function.
|
|
66
|
+
/// The types of these values depend on the target contract's MigrationData type.
|
|
67
|
+
///
|
|
68
|
+
/// # Example
|
|
69
|
+
/// ```ignore
|
|
70
|
+
/// // For a contract with MigrationData = (u32, bool)
|
|
71
|
+
/// let migration_data = vec![
|
|
72
|
+
/// &env,
|
|
73
|
+
/// 42u32.into_val(&env),
|
|
74
|
+
/// true.into_val(&env),
|
|
75
|
+
/// ];
|
|
76
|
+
/// upgrader.upgrade_and_migrate(&contract_addr, &wasm_hash, migration_data);
|
|
77
|
+
/// ```
|
|
78
|
+
pub fn upgrade_and_migrate(
|
|
79
|
+
env: &Env,
|
|
80
|
+
contract_address: &Address,
|
|
81
|
+
wasm_hash: BytesN<32>,
|
|
82
|
+
migration_data: Vec<soroban_sdk::Val>,
|
|
83
|
+
) {
|
|
84
|
+
let contract_client = UpgradeableContractClient::new(env, contract_address);
|
|
85
|
+
|
|
86
|
+
// First upgrade the contract
|
|
87
|
+
contract_client.upgrade(&wasm_hash);
|
|
88
|
+
|
|
89
|
+
// Then call migrate with the provided data
|
|
90
|
+
// We use invoke_contract because the migration data type is unknown to this contract
|
|
91
|
+
env.invoke_contract::<()>(contract_address, &MIGRATE, migration_data);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
#[cfg(test)]
|
|
96
|
+
mod tests;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
pub mod test_upgrader;
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
extern crate std;
|
|
2
|
+
|
|
3
|
+
use soroban_sdk::{contractclient, testutils::Address as _, Address, BytesN, Env, TryIntoVal};
|
|
4
|
+
|
|
5
|
+
use crate::{Upgrader, UpgraderClient};
|
|
6
|
+
|
|
7
|
+
#[allow(dead_code)]
|
|
8
|
+
#[contractclient(name = "TestUpgradeableContractClient")]
|
|
9
|
+
trait TestUpgradeableContract {
|
|
10
|
+
fn counter(env: &Env) -> u32;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
#[allow(dead_code)]
|
|
14
|
+
#[contractclient(name = "TestUpgradeableContractClient2")]
|
|
15
|
+
trait TestUpgradeableContract2 {
|
|
16
|
+
fn counter2(env: &Env) -> u32;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
mod contract_v1 {
|
|
20
|
+
// #[contract]
|
|
21
|
+
// #[upgradeable]
|
|
22
|
+
// #[ownable]
|
|
23
|
+
// pub struct TestUpgradeableContract;
|
|
24
|
+
|
|
25
|
+
// impl UpgradeableInternal for TestUpgradeableContract {
|
|
26
|
+
// type MigrationData = ();
|
|
27
|
+
|
|
28
|
+
// fn _migrate(env: &Env, _migration_data: &Self::MigrationData) {
|
|
29
|
+
// env.storage().instance().set(&Symbol::new(env, "counter"), &2);
|
|
30
|
+
// }
|
|
31
|
+
// }
|
|
32
|
+
|
|
33
|
+
// #[contractclient(name = "TestUpgradeableClient")]
|
|
34
|
+
// trait TestUpgradeable {
|
|
35
|
+
// fn counter(env: &Env) -> u32;
|
|
36
|
+
// }
|
|
37
|
+
|
|
38
|
+
// #[contract_impl]
|
|
39
|
+
// impl TestUpgradeable for TestUpgradeableContract {
|
|
40
|
+
// fn counter(env: &Env) -> u32 {
|
|
41
|
+
// env.storage().instance().get(&Symbol::new(env, "counter")).unwrap_or(0)
|
|
42
|
+
// }
|
|
43
|
+
// }
|
|
44
|
+
|
|
45
|
+
// #[contract_impl]
|
|
46
|
+
// impl TestUpgradeableContract {
|
|
47
|
+
// pub fn __constructor(env: &Env, owner: &Address) {
|
|
48
|
+
// Self::init_owner(env, owner);
|
|
49
|
+
// env.storage().instance().set(&Symbol::new(env, "counter"), &1_u32);
|
|
50
|
+
// }
|
|
51
|
+
// }
|
|
52
|
+
use super::MigrationData;
|
|
53
|
+
soroban_sdk::contractimport!(file = "./src/tests/test_data/test_upgradeable_contract1.wasm");
|
|
54
|
+
}
|
|
55
|
+
mod contract_v2 {
|
|
56
|
+
// #[contract]
|
|
57
|
+
// #[upgradeable]
|
|
58
|
+
// #[ownable]
|
|
59
|
+
// pub struct TestUpgradeableContract;
|
|
60
|
+
|
|
61
|
+
// impl UpgradeableInternal for TestUpgradeableContract {
|
|
62
|
+
// type MigrationData = ();
|
|
63
|
+
|
|
64
|
+
// fn _migrate(env: &Env, _migration_data: &Self::MigrationData) {
|
|
65
|
+
// env.storage().instance().set(&Symbol::new(env, "counter2"), &2_u32);
|
|
66
|
+
// }
|
|
67
|
+
// }
|
|
68
|
+
|
|
69
|
+
// #[contractclient(name = "TestUpgradeableClient")]
|
|
70
|
+
// trait TestUpgradeable {
|
|
71
|
+
// fn counter(env: &Env) -> u32;
|
|
72
|
+
// fn counter2(env: &Env) -> u32;
|
|
73
|
+
// }
|
|
74
|
+
|
|
75
|
+
// #[contract_impl]
|
|
76
|
+
// impl TestUpgradeable for TestUpgradeableContract {
|
|
77
|
+
// fn counter(env: &Env) -> u32 {
|
|
78
|
+
// env.storage().instance().get(&Symbol::new(env, "counter")).unwrap_or(0)
|
|
79
|
+
// }
|
|
80
|
+
|
|
81
|
+
// fn counter2(env: &Env) -> u32 {
|
|
82
|
+
// env.storage().instance().get(&Symbol::new(env, "counter2")).unwrap_or(0)
|
|
83
|
+
// }
|
|
84
|
+
// }
|
|
85
|
+
use super::MigrationData;
|
|
86
|
+
soroban_sdk::contractimport!(file = "./src/tests/test_data/test_upgradeable_contract2.wasm");
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
fn install_new_wasm(e: &Env) -> BytesN<32> {
|
|
90
|
+
e.deployer().upload_contract_wasm(contract_v2::WASM)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
#[allow(dead_code)]
|
|
94
|
+
type MigrationData = ();
|
|
95
|
+
|
|
96
|
+
#[test]
|
|
97
|
+
fn test_upgrade_with_upgrader() {
|
|
98
|
+
let e = Env::default();
|
|
99
|
+
e.mock_all_auths_allowing_non_root_auth();
|
|
100
|
+
|
|
101
|
+
let owner = Address::generate(&e);
|
|
102
|
+
let contract_id = e.register(contract_v1::WASM, (&owner,));
|
|
103
|
+
let client_v1 = TestUpgradeableContractClient::new(&e, &contract_id);
|
|
104
|
+
assert_eq!(client_v1.counter(), 1);
|
|
105
|
+
|
|
106
|
+
let upgrader = e.register(Upgrader, ());
|
|
107
|
+
let upgrader_client = UpgraderClient::new(&e, &upgrader);
|
|
108
|
+
|
|
109
|
+
let new_wasm_hash = install_new_wasm(&e);
|
|
110
|
+
|
|
111
|
+
upgrader_client.upgrade_and_migrate(
|
|
112
|
+
&contract_id,
|
|
113
|
+
&new_wasm_hash,
|
|
114
|
+
&soroban_sdk::vec![&e, ().try_into_val(&e).unwrap()],
|
|
115
|
+
);
|
|
116
|
+
|
|
117
|
+
let client_v2 = TestUpgradeableContractClient2::new(&e, &contract_id);
|
|
118
|
+
|
|
119
|
+
assert_eq!(client_v2.counter2(), 2);
|
|
120
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
//! Base authorization trait for owner-protected operations.
|
|
2
|
+
//!
|
|
3
|
+
//! The `Auth` trait provides a common interface for authorization that can be
|
|
4
|
+
//! implemented by different access control patterns (e.g., single owner, multisig).
|
|
5
|
+
|
|
6
|
+
use soroban_sdk::{contractclient, Address, Env};
|
|
7
|
+
|
|
8
|
+
// ===========================================================================
|
|
9
|
+
// Auth trait
|
|
10
|
+
// ===========================================================================
|
|
11
|
+
|
|
12
|
+
/// Base trait for authorization.
|
|
13
|
+
///
|
|
14
|
+
/// Provides the authorizer address for owner-protected operations. This trait
|
|
15
|
+
/// is implemented by both `Ownable` (external owner) and `Multisig` (self-owning).
|
|
16
|
+
#[contractclient(name = "AuthClient")]
|
|
17
|
+
pub trait Auth: Sized {
|
|
18
|
+
/// Returns the address that authorizes owner-protected operations.
|
|
19
|
+
///
|
|
20
|
+
/// For `Ownable` contracts, this returns the stored owner address.
|
|
21
|
+
/// For `Multisig` contracts, this returns the contract's own address
|
|
22
|
+
/// (self-owning pattern).
|
|
23
|
+
fn authorizer(env: &Env) -> Address;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// ===========================================================================
|
|
27
|
+
// Auth helper functions
|
|
28
|
+
// ===========================================================================
|
|
29
|
+
|
|
30
|
+
/// Enforces authorization from the authorizer and returns the authorizer address.
|
|
31
|
+
///
|
|
32
|
+
/// Panics if the authorizer has not provided authorization for this invocation.
|
|
33
|
+
pub fn enforce_auth<T: Auth>(env: &Env) -> Address {
|
|
34
|
+
let authorizer = T::authorizer(env);
|
|
35
|
+
authorizer.require_auth();
|
|
36
|
+
authorizer
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/// Requires authorization from the authorizer.
|
|
40
|
+
///
|
|
41
|
+
/// Panics if the authorizer has not provided authorization for this invocation.
|
|
42
|
+
pub fn require_auth<T: Auth>(env: &Env) {
|
|
43
|
+
let _ = enforce_auth::<T>(env);
|
|
44
|
+
}
|
|
@@ -1,30 +1,57 @@
|
|
|
1
1
|
use common_macros::contract_error;
|
|
2
2
|
|
|
3
|
+
// Utils library error codes: 1000-1099
|
|
4
|
+
// See ERROR_SPEC.md for allocation rules
|
|
5
|
+
|
|
6
|
+
/// BufferReaderError: 1000-1009
|
|
3
7
|
#[contract_error]
|
|
4
8
|
pub enum BufferReaderError {
|
|
5
9
|
InvalidLength = 1000,
|
|
6
10
|
InvalidAddressPayload,
|
|
7
11
|
}
|
|
8
12
|
|
|
13
|
+
/// BufferWriterError: 1010-1019
|
|
9
14
|
#[contract_error]
|
|
10
15
|
pub enum BufferWriterError {
|
|
11
|
-
InvalidAddressPayload =
|
|
16
|
+
InvalidAddressPayload = 1010,
|
|
12
17
|
}
|
|
13
18
|
|
|
19
|
+
/// TtlConfigurableError: 1020-1029
|
|
14
20
|
#[contract_error]
|
|
15
|
-
pub enum
|
|
16
|
-
InvalidTtlConfig =
|
|
21
|
+
pub enum TtlConfigurableError {
|
|
22
|
+
InvalidTtlConfig = 1020,
|
|
17
23
|
TtlConfigFrozen,
|
|
18
24
|
TtlConfigAlreadyFrozen,
|
|
19
25
|
}
|
|
20
26
|
|
|
27
|
+
/// OwnableError: 1030-1039
|
|
21
28
|
#[contract_error]
|
|
22
29
|
pub enum OwnableError {
|
|
23
|
-
OwnerAlreadySet =
|
|
30
|
+
OwnerAlreadySet = 1030,
|
|
24
31
|
OwnerNotSet,
|
|
25
32
|
}
|
|
26
33
|
|
|
34
|
+
/// BytesExtError: 1040-1049
|
|
27
35
|
#[contract_error]
|
|
28
36
|
pub enum BytesExtError {
|
|
29
|
-
LengthMismatch =
|
|
37
|
+
LengthMismatch = 1040,
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/// UpgradeableError: 1050-1059
|
|
41
|
+
#[contract_error]
|
|
42
|
+
pub enum UpgradeableError {
|
|
43
|
+
MigrationNotAllowed = 1050,
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/// MultisigError: 1060-1069
|
|
47
|
+
#[contract_error]
|
|
48
|
+
pub enum MultisigError {
|
|
49
|
+
AlreadyInitialized = 1060,
|
|
50
|
+
InvalidSigner,
|
|
51
|
+
SignatureError,
|
|
52
|
+
SignerAlreadyExists,
|
|
53
|
+
SignerNotFound,
|
|
54
|
+
TotalSignersLessThanThreshold,
|
|
55
|
+
UnsortedSigners,
|
|
56
|
+
ZeroThreshold,
|
|
30
57
|
}
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
#![no_std]
|
|
2
2
|
|
|
3
|
+
pub mod auth;
|
|
3
4
|
pub mod buffer_reader;
|
|
4
5
|
pub mod buffer_writer;
|
|
5
6
|
pub mod bytes_ext;
|
|
6
7
|
pub mod errors;
|
|
8
|
+
pub mod multisig;
|
|
7
9
|
pub mod option_ext;
|
|
8
10
|
pub mod ownable;
|
|
9
|
-
pub mod
|
|
11
|
+
pub mod ttl_configurable;
|
|
12
|
+
pub mod ttl_extendable;
|
|
13
|
+
pub mod upgradeable;
|
|
10
14
|
|
|
11
15
|
#[cfg(test)]
|
|
12
16
|
mod tests;
|