@layerzerolabs/protocol-stellar-v2 0.2.12 → 0.2.15
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 +384 -278
- package/.turbo/turbo-lint.log +110 -78
- package/.turbo/turbo-test.log +1248 -1014
- package/Cargo.lock +130 -3
- package/Cargo.toml +2 -1
- package/contracts/common-macros/src/contract_impl.rs +6 -1
- package/contracts/common-macros/src/lib.rs +47 -8
- package/contracts/common-macros/src/ownable.rs +7 -25
- package/contracts/common-macros/src/storage.rs +1 -1
- package/contracts/common-macros/src/tests/contract_impl.rs +5 -0
- package/contracts/common-macros/src/tests/mod.rs +1 -0
- package/contracts/common-macros/src/tests/snapshots/common_macros__tests__contract_impl__snapshot_generated_contract_impl_code.snap +23 -7
- package/contracts/common-macros/src/tests/snapshots/common_macros__tests__ownable__snapshot_generated_ownable_code.snap +5 -25
- 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 +5 -25
- 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 +14 -44
- package/contracts/common-macros/src/upgradeable.rs +76 -0
- package/contracts/endpoint-v2/src/endpoint_v2.rs +25 -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 +61 -9
- 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 +3 -5
- 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 +15 -1
- 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 +229 -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_owner_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/extend_instance_ttl.rs +50 -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 +3 -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_owner_missing_env.rs +22 -0
- package/contracts/macro-integration-tests/tests/ui/ownable/fail/only_owner_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 +22 -0
- package/contracts/macro-integration-tests/tests/ui/ownable/pass/only_owner_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/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 +50 -0
- package/contracts/message-libs/message-lib-common/src/tests/worker_options/append_native_drop_option.rs +74 -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 +2 -2
- package/contracts/message-libs/treasury/src/errors.rs +0 -1
- package/contracts/message-libs/treasury/src/lib.rs +3 -3
- package/contracts/message-libs/treasury/src/storage.rs +2 -0
- package/contracts/message-libs/treasury/src/treasury.rs +12 -13
- 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 +24 -54
- package/contracts/message-libs/uln-302/src/send_uln.rs +89 -135
- 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 +8 -5
- package/contracts/oapps/counter/src/counter.rs +0 -1
- package/contracts/oapps/oapp/src/macro_tests/test_macros.rs +306 -224
- package/contracts/oapps/oapp/src/tests/test_oapp_core.rs +0 -1
- package/contracts/oapps/oapp/src/tests/test_oapp_options_type3.rs +0 -1
- package/contracts/oapps/oapp/src/tests/test_oapp_receiver.rs +0 -1
- package/contracts/oapps/oapp/src/tests/test_oapp_sender.rs +0 -1
- package/contracts/{oapp-macros → oapps/oapp-macros}/src/oapp_core.rs +1 -0
- package/contracts/oapps/oft/integration-tests/setup.rs +10 -3
- package/contracts/oapps/oft/integration-tests/utils.rs +1 -1
- package/contracts/oapps/oft/src/default_oft_impl.rs +9 -3
- package/contracts/oapps/oft/src/extensions/oft_fee.rs +5 -5
- package/contracts/oapps/oft/src/extensions/pausable.rs +1 -1
- package/contracts/oapps/oft/src/extensions/rate_limiter.rs +18 -18
- package/contracts/oapps/oft/src/oft.rs +9 -9
- package/contracts/oapps/oft/src/oft_types/lock_unlock.rs +1 -1
- package/contracts/oapps/oft/src/tests/extensions/setup.rs +26 -11
- package/contracts/oapps/oft/src/tests/extensions/test_rate_limiter.rs +1 -1
- package/contracts/oapps/oft/src/tests/test_send.rs +4 -4
- package/contracts/oapps/oft/src/tests/test_utils.rs +93 -74
- 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/oft-std/integration-tests/setup.rs +245 -0
- 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 +122 -25
- 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/errors.rs +6 -1
- package/contracts/utils/src/lib.rs +2 -1
- package/contracts/utils/src/ownable.rs +49 -61
- package/contracts/utils/src/tests/mod.rs +3 -1
- package/contracts/utils/src/tests/option_ext.rs +21 -0
- package/contracts/utils/src/tests/ownable.rs +10 -69
- package/contracts/utils/src/tests/ttl_configurable.rs +596 -0
- package/contracts/utils/src/tests/upgradeable.rs +288 -0
- package/contracts/utils/src/{ttl.rs → ttl_configurable.rs} +67 -52
- package/contracts/utils/src/upgradeable.rs +54 -0
- package/contracts/workers/dvn/Cargo.toml +1 -1
- package/contracts/workers/dvn/src/auth.rs +21 -32
- package/contracts/workers/dvn/src/dvn.rs +40 -3
- package/contracts/workers/dvn/src/errors.rs +1 -0
- package/contracts/workers/dvn/src/multisig.rs +10 -6
- package/contracts/workers/dvn/src/tests/multisig/set_threshold.rs +2 -2
- package/contracts/workers/dvn/src/tests/multisig/verify_signatures.rs +4 -4
- package/contracts/workers/dvn-fee-lib/Cargo.toml +1 -2
- package/contracts/workers/dvn-fee-lib/src/dvn_fee_lib.rs +46 -14
- 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/executor.rs +16 -2
- package/contracts/workers/executor-fee-lib/src/errors.rs +9 -7
- package/contracts/workers/executor-fee-lib/src/executor_fee_lib.rs +154 -119
- package/contracts/workers/executor-helper/Cargo.toml +0 -5
- package/contracts/workers/executor-helper/src/lib.rs +1 -7
- package/contracts/workers/price-feed/Cargo.toml +0 -1
- 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 +39 -17
- package/contracts/workers/worker/Cargo.toml +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 +501 -0
- package/contracts/workers/worker/src/worker.rs +10 -16
- package/package.json +3 -3
- package/sdk/dist/generated/bml.d.ts +40 -30
- package/sdk/dist/generated/bml.js +16 -11
- package/sdk/dist/generated/counter.d.ts +168 -134
- package/sdk/dist/generated/counter.js +26 -21
- package/sdk/dist/generated/dvn.d.ts +1932 -0
- package/sdk/dist/generated/dvn.js +288 -0
- package/sdk/dist/generated/dvn_fee_lib.d.ts +615 -0
- package/sdk/dist/generated/dvn_fee_lib.js +123 -0
- package/sdk/dist/generated/endpoint.d.ts +75 -41
- package/sdk/dist/generated/endpoint.js +22 -17
- package/sdk/dist/generated/executor.d.ts +1809 -0
- package/sdk/dist/generated/executor.js +269 -0
- package/sdk/dist/generated/executor_fee_lib.d.ts +999 -0
- package/sdk/dist/generated/executor_fee_lib.js +208 -0
- package/sdk/dist/generated/executor_helper.d.ts +869 -0
- package/sdk/dist/generated/executor_helper.js +187 -0
- package/sdk/dist/generated/oft_std.d.ts +1544 -0
- package/sdk/dist/generated/oft_std.js +271 -0
- package/sdk/dist/generated/price_feed.d.ts +1002 -0
- package/sdk/dist/generated/price_feed.js +170 -0
- package/sdk/dist/generated/sml.d.ts +75 -41
- package/sdk/dist/generated/sml.js +22 -17
- package/sdk/dist/generated/uln302.d.ts +79 -60
- package/sdk/dist/generated/uln302.js +37 -37
- package/sdk/dist/generated/upgrader.d.ts +70 -0
- package/sdk/dist/generated/upgrader.js +19 -0
- package/sdk/dist/index.d.ts +8 -0
- package/sdk/dist/index.js +11 -0
- package/sdk/package.json +4 -3
- package/sdk/src/index.ts +13 -0
- package/sdk/test/index.test.ts +0 -1
- package/sdk/test/oft.test.ts +12 -23
- package/sdk/test/suites/testUpgradeable.ts +169 -0
- package/sdk/test/upgrader.test.ts +309 -0
- package/tools/ts-bindings-gen/src/main.rs +11 -1
- 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/utils/src/tests/ttl.rs +0 -421
- /package/contracts/{oapp-macros → oapps/oapp-macros}/Cargo.toml +0 -0
- /package/contracts/{oapp-macros → oapps/oapp-macros}/src/lib.rs +0 -0
- /package/contracts/{oapp-macros → oapps/oapp-macros}/src/oapp_full.rs +0 -0
- /package/contracts/{oapp-macros → oapps/oapp-macros}/src/oapp_options_type3.rs +0 -0
- /package/contracts/{oapp-macros → oapps/oapp-macros}/src/oapp_receiver.rs +0 -0
- /package/contracts/{oapp-macros → oapps/oapp-macros}/src/oapp_sender.rs +0 -0
- /package/contracts/{oapp-macros → oapps/oapp-macros}/src/util.rs +0 -0
|
@@ -1,14 +1,36 @@
|
|
|
1
1
|
use common_macros::{contract_impl, storage};
|
|
2
2
|
use oapp_macros::oapp;
|
|
3
|
-
use oft::
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
use oft::{
|
|
4
|
+
default_oft_impl::{default_quote_oft, default_quote_send},
|
|
5
|
+
errors::OFTError,
|
|
6
|
+
extensions::{
|
|
7
|
+
oft_fee::{OFTFee, OFTFeeInternal},
|
|
8
|
+
pausable::{OFTPausable, OFTPausableInternal},
|
|
9
|
+
rate_limiter::{Direction, RateLimiter, RateLimiterInternal},
|
|
10
|
+
},
|
|
11
|
+
oft::{oft_initialize, OFTInternal, OFT},
|
|
12
|
+
oft_types::{lock_unlock, mint_burn},
|
|
13
|
+
storage::OFTStorage,
|
|
14
|
+
types::{OFTFeeDetail, OFTLimit, OFTReceipt, SendParam},
|
|
15
|
+
utils::remove_dust,
|
|
16
|
+
};
|
|
17
|
+
use soroban_sdk::{assert_with_error, contracttype, Address, Env, Vec};
|
|
18
|
+
|
|
19
|
+
/// The mode of operation for the OFT contract
|
|
20
|
+
#[contracttype]
|
|
21
|
+
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
|
|
22
|
+
#[repr(u8)]
|
|
23
|
+
pub enum OFTMode {
|
|
24
|
+
/// Lock tokens on send, unlock on receive
|
|
25
|
+
LockUnlock = 0,
|
|
26
|
+
/// Burn tokens on send, mint on receive
|
|
27
|
+
MintBurn = 1,
|
|
28
|
+
}
|
|
7
29
|
|
|
8
30
|
#[storage]
|
|
9
31
|
enum OFTStdStorage {
|
|
10
|
-
#[instance(
|
|
11
|
-
|
|
32
|
+
#[instance(OFTMode)]
|
|
33
|
+
Mode,
|
|
12
34
|
}
|
|
13
35
|
|
|
14
36
|
#[oapp]
|
|
@@ -23,37 +45,112 @@ impl OFTStd {
|
|
|
23
45
|
endpoint: &Address,
|
|
24
46
|
delegate: &Option<Address>,
|
|
25
47
|
shared_decimals: u32,
|
|
26
|
-
|
|
48
|
+
mode: OFTMode,
|
|
27
49
|
) {
|
|
28
50
|
oft_initialize::<Self>(env, owner, token, endpoint, delegate, shared_decimals);
|
|
29
|
-
OFTStdStorage::
|
|
51
|
+
OFTStdStorage::set_mode(env, &mode);
|
|
30
52
|
}
|
|
31
53
|
|
|
32
|
-
///
|
|
33
|
-
pub fn
|
|
34
|
-
OFTStdStorage::
|
|
54
|
+
/// Returns the mode of operation for this OFT (LockUnlock or MintBurn)
|
|
55
|
+
pub fn mode(env: &Env) -> OFTMode {
|
|
56
|
+
OFTStdStorage::mode(env).unwrap()
|
|
35
57
|
}
|
|
36
58
|
}
|
|
37
59
|
|
|
38
|
-
/// OFT trait implementation for standard OFT
|
|
60
|
+
/// OFT trait implementation for standard OFT with extensions
|
|
39
61
|
#[contract_impl(contracttrait)]
|
|
40
|
-
impl OFT for OFTStd {
|
|
62
|
+
impl OFT for OFTStd {
|
|
63
|
+
fn quote_oft(env: &Env, send_param: &SendParam) -> (OFTLimit, Vec<OFTFeeDetail>, OFTReceipt) {
|
|
64
|
+
Self::__assert_not_paused(env);
|
|
65
|
+
let (_, fee_details, oft_receipt) = default_quote_oft::<Self>(env, send_param);
|
|
66
|
+
let capacity = Self::rate_limit_capacity(env, &Direction::Outbound, send_param.dst_eid);
|
|
67
|
+
let oft_limit = OFTLimit { min_amount_ld: 0, max_amount_ld: capacity };
|
|
68
|
+
(oft_limit, fee_details, oft_receipt)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
fn quote_send(env: &Env, sender: &Address, send_param: &SendParam, pay_in_zro: bool) -> endpoint_v2::MessagingFee {
|
|
72
|
+
Self::__assert_not_paused(env);
|
|
73
|
+
default_quote_send::<Self>(env, sender, send_param, pay_in_zro)
|
|
74
|
+
}
|
|
75
|
+
}
|
|
41
76
|
|
|
42
|
-
/// OFT behavior for standard OFT
|
|
43
|
-
impl
|
|
77
|
+
/// OFT behavior for standard OFT with extension hooks
|
|
78
|
+
impl OFTInternal for OFTStd {
|
|
44
79
|
fn __debit(env: &Env, sender: &Address, amount_ld: i128, min_amount_ld: i128, dst_eid: u32) -> OFTReceipt {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
80
|
+
// 1. Pausable check
|
|
81
|
+
Self::__assert_not_paused(env);
|
|
82
|
+
|
|
83
|
+
// 2. Core debit logic (based on mode)
|
|
84
|
+
let oft_receipt = match Self::mode(env) {
|
|
85
|
+
OFTMode::LockUnlock => lock_unlock::debit::<Self>(env, sender, amount_ld, min_amount_ld, dst_eid),
|
|
86
|
+
OFTMode::MintBurn => mint_burn::debit::<Self>(env, sender, amount_ld, min_amount_ld, dst_eid),
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
// 3. Rate limit checks (using amount_received_ld - the actual cross-chain amount)
|
|
90
|
+
Self::__consume_rate_limit_capacity(env, &Direction::Outbound, dst_eid, oft_receipt.amount_received_ld);
|
|
91
|
+
Self::__release_rate_limit_capacity(env, &Direction::Inbound, dst_eid, oft_receipt.amount_received_ld);
|
|
92
|
+
|
|
93
|
+
// 4. Charge fee (amount_sent_ld - amount_received_ld)
|
|
94
|
+
Self::__charge_fee(env, &Self::token(env), sender, oft_receipt.amount_sent_ld - oft_receipt.amount_received_ld);
|
|
95
|
+
|
|
96
|
+
oft_receipt
|
|
50
97
|
}
|
|
51
98
|
|
|
52
99
|
fn __credit(env: &Env, to: &Address, amount_ld: i128, src_eid: u32) -> i128 {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
100
|
+
// 1. Pausable check
|
|
101
|
+
Self::__assert_not_paused(env);
|
|
102
|
+
|
|
103
|
+
// 2. Core credit logic (based on mode)
|
|
104
|
+
let amount_credited = match Self::mode(env) {
|
|
105
|
+
OFTMode::LockUnlock => lock_unlock::credit::<Self>(env, to, amount_ld, src_eid),
|
|
106
|
+
OFTMode::MintBurn => mint_burn::credit::<Self>(env, to, amount_ld, src_eid),
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
// 3. Rate limit checks (using amount_credited - the actual credited amount)
|
|
110
|
+
Self::__consume_rate_limit_capacity(env, &Direction::Inbound, src_eid, amount_credited);
|
|
111
|
+
Self::__release_rate_limit_capacity(env, &Direction::Outbound, src_eid, amount_credited);
|
|
112
|
+
|
|
113
|
+
amount_credited
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
fn __debit_view(env: &Env, amount_ld: i128, min_amount_ld: i128, dst_eid: u32) -> OFTReceipt {
|
|
117
|
+
let conversion_rate = OFTStorage::decimal_conversion_rate(env).unwrap();
|
|
118
|
+
|
|
119
|
+
// CRITICAL: Apply fee first, then remove dust
|
|
120
|
+
let amount_after_fee = Self::__fee_view(env, dst_eid, amount_ld);
|
|
121
|
+
let amount_received_ld = remove_dust(amount_after_fee, conversion_rate);
|
|
122
|
+
|
|
123
|
+
// amount_sent_ld logic:
|
|
124
|
+
// - If no fee: amount_sent_ld = amount_received_ld (both reduced by dust)
|
|
125
|
+
// - If fee applied: amount_sent_ld = original amount_ld (unchanged)
|
|
126
|
+
// This is to align the behavior with the fee extensions on other VMs
|
|
127
|
+
let amount_sent_ld = if amount_after_fee == amount_ld { amount_received_ld } else { amount_ld };
|
|
128
|
+
|
|
129
|
+
assert_with_error!(env, amount_received_ld >= min_amount_ld, OFTError::SlippageExceeded);
|
|
130
|
+
|
|
131
|
+
OFTReceipt { amount_sent_ld, amount_received_ld }
|
|
58
132
|
}
|
|
59
133
|
}
|
|
134
|
+
|
|
135
|
+
// ==================== Extension Trait Implementations ====================
|
|
136
|
+
|
|
137
|
+
/// Pausable extension - allows pausing/unpausing the OFT
|
|
138
|
+
/// Default state: unpaused (all operations allowed)
|
|
139
|
+
#[contract_impl(contracttrait)]
|
|
140
|
+
impl OFTPausable for OFTStd {}
|
|
141
|
+
|
|
142
|
+
impl OFTPausableInternal for OFTStd {}
|
|
143
|
+
|
|
144
|
+
/// OFT Fee extension - allows collecting fees on transfers
|
|
145
|
+
/// Default state: 0 BPS (no fee collected)
|
|
146
|
+
#[contract_impl(contracttrait)]
|
|
147
|
+
impl OFTFee for OFTStd {}
|
|
148
|
+
|
|
149
|
+
impl OFTFeeInternal for OFTStd {}
|
|
150
|
+
|
|
151
|
+
/// Rate Limiter extension - allows rate limiting transfers
|
|
152
|
+
/// Default state: not set (rate_limit_capacity returns i128::MAX)
|
|
153
|
+
#[contract_impl(contracttrait)]
|
|
154
|
+
impl RateLimiter for OFTStd {}
|
|
155
|
+
|
|
156
|
+
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 ownership checks. When you call `upgrader.upgrade()`, the target
|
|
14
|
+
//! contract's `#[only_owner]` guard ensures only the target's owner 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 owner of the target contract.
|
|
57
|
+
/// This is enforced by the target contract's `#[only_owner]` 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
|
+
}
|
|
@@ -12,7 +12,7 @@ pub enum BufferWriterError {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
#[contract_error]
|
|
15
|
-
pub enum
|
|
15
|
+
pub enum TtlConfigurableError {
|
|
16
16
|
InvalidTtlConfig = 1200,
|
|
17
17
|
TtlConfigFrozen,
|
|
18
18
|
TtlConfigAlreadyFrozen,
|
|
@@ -28,3 +28,8 @@ pub enum OwnableError {
|
|
|
28
28
|
pub enum BytesExtError {
|
|
29
29
|
LengthMismatch = 1400,
|
|
30
30
|
}
|
|
31
|
+
|
|
32
|
+
#[contract_error]
|
|
33
|
+
pub enum UpgradeableError {
|
|
34
|
+
MigrationNotAllowed = 1500,
|
|
35
|
+
}
|
|
@@ -1,47 +1,11 @@
|
|
|
1
1
|
use crate::errors::OwnableError;
|
|
2
2
|
use crate::option_ext::OptionExt;
|
|
3
3
|
use common_macros::storage;
|
|
4
|
-
use soroban_sdk::{assert_with_error,
|
|
4
|
+
use soroban_sdk::{assert_with_error, contractevent, contracttrait, Address, Env};
|
|
5
5
|
|
|
6
|
-
//
|
|
7
|
-
// Ownable
|
|
8
|
-
//
|
|
9
|
-
|
|
10
|
-
/// Trait for initializing contract ownership.
|
|
11
|
-
pub trait OwnableInitializer {
|
|
12
|
-
/// Initializes the owner. Should only be called once at contract initialization.
|
|
13
|
-
fn init_owner(env: &Env, owner: &Address);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
// ============================================
|
|
17
|
-
// Ownable Interface
|
|
18
|
-
// ============================================
|
|
19
|
-
|
|
20
|
-
/// Trait for contracts with single-owner access control.
|
|
21
|
-
#[contractclient(name = "OwnableClient")]
|
|
22
|
-
pub trait Ownable {
|
|
23
|
-
/// Returns the current owner address, or None if no owner is set.
|
|
24
|
-
fn owner(env: &Env) -> Option<Address>;
|
|
25
|
-
|
|
26
|
-
/// Transfers ownership to a new address. Requires current owner authorization.
|
|
27
|
-
fn transfer_ownership(env: &Env, new_owner: &Address);
|
|
28
|
-
|
|
29
|
-
/// Permanently renounces ownership. Requires current owner authorization.
|
|
30
|
-
fn renounce_ownership(env: &Env);
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/// Enforces owner authorization and returns the owner address.
|
|
34
|
-
/// Panics if no owner is set or authorization fails.
|
|
35
|
-
pub fn enforce_owner_auth<T: Ownable>(env: &Env) -> Address {
|
|
36
|
-
let owner = T::owner(env).unwrap_or_panic(env, OwnableError::OwnerNotSet);
|
|
37
|
-
owner.require_auth();
|
|
38
|
-
owner
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/// Enforces owner authorization without returning the address.
|
|
42
|
-
pub fn require_owner_auth<T: Ownable>(env: &Env) {
|
|
43
|
-
let _ = enforce_owner_auth::<T>(env);
|
|
44
|
-
}
|
|
6
|
+
// ===========================================================================
|
|
7
|
+
// Ownable events
|
|
8
|
+
// ===========================================================================
|
|
45
9
|
|
|
46
10
|
/// Event emitted when ownership is transferred.
|
|
47
11
|
#[contractevent]
|
|
@@ -58,41 +22,65 @@ pub struct OwnershipRenounced {
|
|
|
58
22
|
pub old_owner: Address,
|
|
59
23
|
}
|
|
60
24
|
|
|
61
|
-
//
|
|
62
|
-
//
|
|
63
|
-
//
|
|
64
|
-
|
|
65
|
-
/// Default implementation of the Ownable trait using instance storage.
|
|
66
|
-
pub struct DefaultOwnable;
|
|
25
|
+
// ===========================================================================
|
|
26
|
+
// Ownable storage for default implementation
|
|
27
|
+
// ===========================================================================
|
|
67
28
|
|
|
68
|
-
/// Storage keys for
|
|
29
|
+
/// Storage keys for Ownable.
|
|
69
30
|
#[storage]
|
|
70
|
-
pub enum
|
|
31
|
+
pub enum OwnableStorage {
|
|
71
32
|
#[instance(Address)]
|
|
72
33
|
Owner,
|
|
73
34
|
}
|
|
74
35
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
36
|
+
// ===========================================================================
|
|
37
|
+
// Ownable trait with default implementation
|
|
38
|
+
// ===========================================================================
|
|
39
|
+
|
|
40
|
+
/// Trait for contracts with single-owner access control.
|
|
41
|
+
#[contracttrait]
|
|
42
|
+
pub trait Ownable: Sized {
|
|
43
|
+
/// Returns the current owner address, or None if no owner is set.
|
|
44
|
+
fn owner(env: &soroban_sdk::Env) -> Option<soroban_sdk::Address> {
|
|
45
|
+
OwnableStorage::owner(env)
|
|
78
46
|
}
|
|
79
47
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
48
|
+
/// Transfers ownership to a new address. Requires current owner authorization.
|
|
49
|
+
fn transfer_ownership(env: &soroban_sdk::Env, new_owner: &soroban_sdk::Address) {
|
|
50
|
+
let old_owner = enforce_owner_auth::<Self>(env);
|
|
51
|
+
OwnableStorage::set_owner(env, new_owner);
|
|
83
52
|
OwnershipTransferred { old_owner, new_owner: new_owner.clone() }.publish(env);
|
|
84
53
|
}
|
|
85
54
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
55
|
+
/// Permanently renounces ownership. Requires current owner authorization.
|
|
56
|
+
fn renounce_ownership(env: &soroban_sdk::Env) {
|
|
57
|
+
let old_owner = enforce_owner_auth::<Self>(env);
|
|
58
|
+
OwnableStorage::remove_owner(env);
|
|
89
59
|
OwnershipRenounced { old_owner }.publish(env);
|
|
90
60
|
}
|
|
91
61
|
}
|
|
92
62
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
63
|
+
/// Trait for initializing the owner of the contract.
|
|
64
|
+
pub trait OwnableInitializer {
|
|
65
|
+
fn init_owner(env: &soroban_sdk::Env, owner: &soroban_sdk::Address) {
|
|
66
|
+
assert_with_error!(env, !OwnableStorage::has_owner(env), OwnableError::OwnerAlreadySet);
|
|
67
|
+
OwnableStorage::set_owner(env, owner);
|
|
97
68
|
}
|
|
98
69
|
}
|
|
70
|
+
|
|
71
|
+
// ===========================================================================
|
|
72
|
+
// Ownable helper functions
|
|
73
|
+
// ===========================================================================
|
|
74
|
+
|
|
75
|
+
/// Enforces owner authorization and returns the owner address.
|
|
76
|
+
/// Panics if no owner is set or authorization fails.
|
|
77
|
+
pub fn enforce_owner_auth<T: Ownable>(env: &Env) -> Address {
|
|
78
|
+
let owner = T::owner(env).unwrap_or_panic(env, OwnableError::OwnerNotSet);
|
|
79
|
+
owner.require_auth();
|
|
80
|
+
owner
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/// Enforces owner authorization without returning the address.
|
|
84
|
+
pub fn require_owner_auth<T: Ownable>(env: &Env) {
|
|
85
|
+
let _ = enforce_owner_auth::<T>(env);
|
|
86
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
use soroban_sdk::Env;
|
|
2
|
+
|
|
3
|
+
use crate::{errors::OwnableError, option_ext::OptionExt};
|
|
4
|
+
|
|
5
|
+
use crate::tests::test_helper::assert_panics_contains;
|
|
6
|
+
|
|
7
|
+
#[test]
|
|
8
|
+
fn unwrap_or_panic_some_returns_value() {
|
|
9
|
+
let env = Env::default();
|
|
10
|
+
let got = Some(123u32).unwrap_or_panic(&env, OwnableError::OwnerNotSet);
|
|
11
|
+
assert_eq!(got, 123);
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
#[test]
|
|
15
|
+
fn unwrap_or_panic_none_panics_with_error() {
|
|
16
|
+
const EXPECTED: &str = "Error(Contract, #1301)";
|
|
17
|
+
assert_panics_contains("none unwrap_or_panic", EXPECTED, || {
|
|
18
|
+
let env = Env::default();
|
|
19
|
+
let _got: u32 = None::<u32>.unwrap_or_panic(&env, OwnableError::OwnerNotSet);
|
|
20
|
+
});
|
|
21
|
+
}
|