@layerzerolabs/protocol-stellar-v2 0.2.15 → 0.2.19
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 +365 -297
- package/.turbo/turbo-lint.log +142 -110
- package/.turbo/turbo-test.log +1273 -1222
- package/Cargo.lock +20 -5
- package/Cargo.toml +4 -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 +181 -30
- package/contracts/common-macros/src/lz_contract.rs +83 -0
- 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 +2 -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} +3 -3
- 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__ttl_configurable__snapshot_generated_ttl_configurable_code.snap +7 -21
- package/contracts/common-macros/src/tests/snapshots/common_macros__tests__upgradeable__snapshot_generated_upgradeable_code.snap +2 -2
- package/contracts/common-macros/src/ttl_configurable.rs +19 -34
- package/contracts/common-macros/src/ttl_extendable.rs +36 -0
- package/contracts/common-macros/src/upgradeable.rs +5 -5
- 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 +38 -40
- 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_v2/pay_messaging_fees.rs +3 -3
- package/contracts/endpoint-v2/src/tests/endpoint_v2/quote.rs +1 -1
- package/contracts/endpoint-v2/src/tests/endpoint_v2/require_oapp_auth.rs +2 -2
- package/contracts/endpoint-v2/src/tests/endpoint_v2/send.rs +3 -3
- package/contracts/endpoint-v2/src/tests/endpoint_v2/set_zro.rs +4 -4
- package/contracts/endpoint-v2/src/tests/message_lib_manager/require_receive_lib_for_eid.rs +3 -3
- package/contracts/endpoint-v2/src/tests/message_lib_manager/require_registered.rs +1 -1
- package/contracts/endpoint-v2/src/tests/message_lib_manager/require_send_lib_for_eid.rs +3 -3
- package/contracts/endpoint-v2/src/tests/message_lib_manager/require_supported_eid.rs +1 -1
- package/contracts/endpoint-v2/src/tests/messaging_channel/clear_payload.rs +4 -4
- package/contracts/endpoint-v2/src/tests/messaging_channel/inbound.rs +1 -1
- package/contracts/layerzero-views/src/layerzero_view.rs +3 -6
- package/contracts/macro-integration-tests/tests/runtime/ownable/mod.rs +2 -2
- package/contracts/macro-integration-tests/tests/runtime/ownable/{only_owner_guard.rs → only_auth_guard.rs} +1 -1
- package/contracts/macro-integration-tests/tests/runtime/ttl_configurable/configuration.rs +1 -1
- package/contracts/macro-integration-tests/tests/runtime/ttl_configurable/freeze.rs +1 -1
- package/contracts/macro-integration-tests/tests/runtime/ttl_configurable/mod.rs +0 -1
- package/contracts/macro-integration-tests/tests/ui/ownable/fail/{only_owner_missing_env.rs → only_auth_missing_env.rs} +3 -3
- package/contracts/macro-integration-tests/tests/ui/ownable/fail/{only_owner_missing_env.stderr → only_auth_missing_env.stderr} +4 -4
- package/contracts/macro-integration-tests/tests/ui/ownable/pass/namespacing_and_imports.rs +2 -3
- package/contracts/macro-integration-tests/tests/ui/ownable/pass/{only_owner_env_param_variants.rs → only_auth_env_param_variants.rs} +9 -9
- package/contracts/macro-integration-tests/tests/ui/ttl_configurable/pass/minimal_contract.rs +6 -6
- 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 +3 -3
- package/contracts/message-libs/message-lib-common/src/tests/worker_options/append_lz_receive_option.rs +1 -2
- package/contracts/message-libs/message-lib-common/src/tests/worker_options/append_native_drop_option.rs +1 -2
- package/contracts/message-libs/message-lib-common/src/tests/worker_options/convert_legacy_options.rs +9 -9
- package/contracts/message-libs/message-lib-common/src/tests/worker_options/extract_type_3_options.rs +1 -1
- package/contracts/message-libs/message-lib-common/src/tests/worker_options/left_pad_to_bytes32.rs +1 -1
- package/contracts/message-libs/message-lib-common/src/tests/worker_options/split_worker_options.rs +2 -2
- package/contracts/message-libs/simple-message-lib/src/simple_message_lib.rs +7 -9
- package/contracts/message-libs/treasury/src/errors.rs +2 -2
- 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/storage.rs +1 -1
- package/contracts/message-libs/treasury/src/tests/treasury_tests.rs +1 -1
- package/contracts/message-libs/treasury/src/treasury.rs +14 -16
- package/contracts/message-libs/uln-302/src/receive_uln.rs +13 -2
- package/contracts/message-libs/uln-302/src/send_uln.rs +24 -4
- package/contracts/message-libs/uln-302/src/uln302.rs +6 -24
- 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.rs → setup_sml.rs} +48 -80
- 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 -43
- 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 +93 -78
- 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 -8
- package/contracts/oapps/oapp/src/tests/test_oapp_options_type3.rs +25 -17
- package/contracts/oapps/oapp/src/tests/test_oapp_receiver.rs +7 -7
- package/contracts/oapps/oapp/src/tests/test_oapp_sender.rs +14 -15
- package/contracts/oapps/oapp-macros/src/generators.rs +128 -0
- package/contracts/oapps/oapp-macros/src/lib.rs +113 -56
- package/contracts/oapps/oft/Cargo.toml +10 -7
- package/contracts/oapps/{oft-std → oft}/integration-tests/extensions/test_oft_fee.rs +3 -4
- package/contracts/oapps/{oft-std → oft}/integration-tests/extensions/test_pausable.rs +2 -3
- package/contracts/oapps/{oft-std → oft}/integration-tests/extensions/test_rate_limiter.rs +1 -1
- package/contracts/oapps/oft/integration-tests/mod.rs +1 -1
- package/contracts/oapps/oft/integration-tests/setup.rs +29 -110
- package/contracts/oapps/oft/integration-tests/utils.rs +254 -21
- package/contracts/oapps/oft/src/extensions/oft_fee.rs +13 -14
- package/contracts/oapps/oft/src/extensions/pausable.rs +4 -4
- package/contracts/oapps/oft/src/extensions/rate_limiter.rs +5 -5
- package/contracts/oapps/oft/src/lib.rs +11 -13
- package/contracts/oapps/oft/src/oft.rs +147 -225
- package/contracts/oapps/oft/src/oft_types/lock_unlock.rs +9 -13
- package/contracts/oapps/oft/src/oft_types/mint_burn.rs +31 -14
- package/contracts/oapps/oft/src/oft_types/mod.rs +13 -0
- package/contracts/oapps/{oft-std → oft-core}/Cargo.toml +6 -4
- package/contracts/oapps/{oft-std → oft-core}/integration-tests/mod.rs +1 -1
- package/contracts/oapps/{oft-std → oft-core}/integration-tests/setup.rs +129 -30
- package/contracts/oapps/{oft → oft-core}/integration-tests/test_with_sml.rs +3 -3
- package/contracts/oapps/oft-core/integration-tests/utils.rs +201 -0
- package/contracts/oapps/oft-core/src/errors.rs +13 -0
- package/contracts/oapps/oft-core/src/lib.rs +18 -0
- package/contracts/oapps/oft-core/src/oft_core.rs +439 -0
- package/contracts/oapps/{oft → oft-core}/src/storage.rs +2 -0
- package/contracts/oapps/{oft → oft-core}/src/tests/mod.rs +0 -2
- package/contracts/oapps/{oft → oft-core}/src/tests/test_decimals.rs +2 -2
- package/contracts/oapps/{oft → oft-core}/src/tests/test_lz_receive.rs +7 -7
- package/contracts/oapps/{oft → oft-core}/src/tests/test_oft_msg_codec.rs +4 -5
- package/contracts/oapps/{oft → oft-core}/src/tests/test_resolve_address.rs +3 -3
- package/contracts/oapps/{oft → oft-core}/src/tests/test_utils.rs +78 -37
- package/contracts/oapps/oft-core/src/types.rs +58 -0
- package/contracts/oapps/{oft → oft-core}/src/utils.rs +1 -1
- package/contracts/upgrader/src/lib.rs +4 -4
- package/contracts/utils/src/auth.rs +44 -0
- package/contracts/utils/src/errors.rs +31 -5
- package/contracts/utils/src/lib.rs +3 -0
- package/contracts/utils/src/multisig.rs +211 -0
- package/contracts/utils/src/ownable.rs +137 -13
- 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 +1 -0
- package/contracts/utils/src/tests/multisig.rs +731 -0
- package/contracts/utils/src/tests/option_ext.rs +2 -5
- package/contracts/utils/src/tests/ownable.rs +456 -7
- package/contracts/utils/src/tests/ttl_configurable.rs +27 -16
- package/contracts/utils/src/tests/upgradeable.rs +4 -2
- package/contracts/utils/src/ttl_configurable.rs +23 -8
- package/contracts/utils/src/ttl_extendable.rs +27 -0
- package/contracts/utils/src/upgradeable.rs +2 -0
- package/contracts/workers/dvn/Cargo.toml +1 -1
- package/contracts/workers/dvn/src/auth.rs +7 -7
- package/contracts/workers/dvn/src/dvn.rs +10 -38
- package/contracts/workers/dvn/src/errors.rs +0 -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 +1 -1
- package/contracts/workers/dvn-fee-lib/src/dvn_fee_lib.rs +3 -6
- package/contracts/workers/executor/src/auth.rs +80 -16
- package/contracts/workers/executor/src/executor.rs +5 -31
- 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/executor_fee_lib.rs +3 -6
- package/contracts/workers/executor-helper/Cargo.toml +1 -1
- package/contracts/workers/executor-helper/src/executor_helper.rs +53 -73
- package/contracts/workers/price-feed/Cargo.toml +1 -1
- package/contracts/workers/price-feed/src/price_feed.rs +7 -10
- package/contracts/workers/worker/src/errors.rs +4 -0
- package/contracts/workers/worker/src/tests/worker.rs +7 -6
- package/contracts/workers/worker/src/worker.rs +20 -16
- package/package.json +7 -5
- package/sdk/.turbo/turbo-build.log +1 -0
- package/sdk/.turbo/turbo-test.log +1019 -0
- package/sdk/dist/generated/bml.d.ts +95 -8
- package/sdk/dist/generated/bml.js +95 -36
- package/sdk/dist/generated/counter.d.ts +289 -44
- package/sdk/dist/generated/counter.js +119 -49
- package/sdk/dist/generated/dvn.d.ts +312 -229
- package/sdk/dist/generated/dvn.js +144 -83
- package/sdk/dist/generated/dvn_fee_lib.d.ts +258 -63
- package/sdk/dist/generated/dvn_fee_lib.js +95 -26
- package/sdk/dist/generated/endpoint.d.ts +219 -24
- package/sdk/dist/generated/endpoint.js +108 -41
- package/sdk/dist/generated/executor.d.ts +239 -87
- package/sdk/dist/generated/executor.js +135 -63
- package/sdk/dist/generated/executor_fee_lib.d.ts +278 -74
- package/sdk/dist/generated/executor_fee_lib.js +135 -59
- package/sdk/dist/generated/executor_helper.d.ts +163 -21
- package/sdk/dist/generated/executor_helper.js +124 -52
- package/sdk/dist/generated/oft.d.ts +1842 -0
- package/sdk/dist/generated/oft.js +345 -0
- package/sdk/dist/generated/price_feed.d.ts +258 -63
- package/sdk/dist/generated/price_feed.js +95 -26
- package/sdk/dist/generated/sml.d.ts +235 -34
- package/sdk/dist/generated/sml.js +126 -53
- package/sdk/dist/generated/treasury.d.ts +1016 -0
- package/sdk/dist/generated/treasury.js +248 -0
- package/sdk/dist/generated/uln302.d.ts +235 -34
- package/sdk/dist/generated/uln302.js +126 -53
- package/sdk/dist/generated/upgrader.d.ts +17 -2
- package/sdk/dist/generated/upgrader.js +19 -1
- package/sdk/dist/index.d.ts +2 -1
- package/sdk/dist/index.js +2 -1
- package/sdk/package.json +6 -3
- package/sdk/src/index.ts +2 -1
- 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} +196 -321
- package/sdk/test/suites/constants.ts +22 -2
- package/sdk/test/suites/globalSetup.ts +450 -0
- package/sdk/test/suites/localnet.ts +23 -6
- package/sdk/test/upgrader.test.ts +7 -16
- package/sdk/test/utils.ts +558 -85
- package/sdk/turbo.json +8 -0
- package/sdk/vitest.config.ts +21 -0
- package/tools/ts-bindings-gen/Cargo.toml +2 -0
- package/tools/ts-bindings-gen/src/main.rs +52 -4
- package/contracts/common-macros/src/contract_impl.rs +0 -52
- package/contracts/common-macros/src/ownable.rs +0 -41
- package/contracts/common-macros/src/tests/contract_impl.rs +0 -386
- package/contracts/common-macros/src/tests/snapshots/common_macros__tests__ownable__snapshot_generated_ownable_code.snap +0 -12
- package/contracts/macro-integration-tests/tests/runtime/ttl_configurable/extend_instance_ttl.rs +0 -50
- package/contracts/oapps/oapp-macros/src/oapp_core.rs +0 -41
- package/contracts/oapps/oapp-macros/src/oapp_full.rs +0 -21
- package/contracts/oapps/oapp-macros/src/oapp_options_type3.rs +0 -31
- package/contracts/oapps/oapp-macros/src/oapp_receiver.rs +0 -48
- package/contracts/oapps/oapp-macros/src/oapp_sender.rs +0 -21
- package/contracts/oapps/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 -152
- package/contracts/oapps/oft/src/errors.rs +0 -8
- package/contracts/oapps/oft/src/interfaces/mint_burn_token.rs +0 -23
- package/contracts/oapps/oft/src/interfaces/mod.rs +0 -3
- package/contracts/oapps/oft/src/tests/extensions/mod.rs +0 -11
- package/contracts/oapps/oft/src/tests/extensions/setup.rs +0 -903
- package/contracts/oapps/oft/src/tests/extensions/test_oft_fee.rs +0 -749
- package/contracts/oapps/oft/src/tests/extensions/test_pausable.rs +0 -432
- package/contracts/oapps/oft/src/tests/extensions/test_rate_limiter.rs +0 -1078
- package/contracts/oapps/oft/src/types.rs +0 -38
- package/contracts/oapps/oft-std/integration-tests/utils.rs +0 -427
- package/contracts/oapps/oft-std/src/lib.rs +0 -16
- package/contracts/oapps/oft-std/src/oft.rs +0 -156
- package/contracts/workers/dvn/src/interfaces/multisig.rs +0 -56
- package/contracts/workers/dvn/src/multisig.rs +0 -157
- package/sdk/dist/generated/oft_std.d.ts +0 -1544
- package/sdk/dist/generated/oft_std.js +0 -271
- package/sdk/test/index.test.ts +0 -375
- /package/contracts/oapps/{oft-std → oft}/integration-tests/extensions/mod.rs +0 -0
- /package/contracts/oapps/{oft → oft-core}/src/codec/mod.rs +0 -0
- /package/contracts/oapps/{oft → oft-core}/src/codec/oft_compose_msg_codec.rs +0 -0
- /package/contracts/oapps/{oft → oft-core}/src/codec/oft_msg_codec.rs +0 -0
- /package/contracts/oapps/{oft → oft-core}/src/events.rs +0 -0
- /package/contracts/oapps/{oft → oft-core}/src/tests/test_oft_compose_msg_codec.rs +0 -0
- /package/contracts/oapps/{oft → oft-core}/src/tests/test_oft_version.rs +0 -0
- /package/contracts/oapps/{oft → oft-core}/src/tests/test_quote_oft.rs +0 -0
- /package/contracts/oapps/{oft → oft-core}/src/tests/test_quote_send.rs +0 -0
- /package/contracts/oapps/{oft → oft-core}/src/tests/test_send.rs +0 -0
- /package/contracts/oapps/{oft → oft-core}/src/tests/test_token.rs +0 -0
- /package/sdk/test/suites/{testUpgradeable.ts → dummyContractClient.ts} +0 -0
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
use soroban_sdk::{contracttype, Bytes, BytesN};
|
|
2
|
-
|
|
3
|
-
/// Parameters for sending OFT tokens cross-chain
|
|
4
|
-
#[contracttype]
|
|
5
|
-
#[derive(Clone, PartialEq, Eq, Debug)]
|
|
6
|
-
pub struct SendParam {
|
|
7
|
-
pub dst_eid: u32,
|
|
8
|
-
pub to: BytesN<32>,
|
|
9
|
-
pub amount_ld: i128,
|
|
10
|
-
pub min_amount_ld: i128,
|
|
11
|
-
pub extra_options: Bytes,
|
|
12
|
-
pub compose_msg: Bytes,
|
|
13
|
-
pub oft_cmd: Bytes,
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
/// Transfer limits for OFT operations
|
|
17
|
-
#[contracttype]
|
|
18
|
-
#[derive(Clone, PartialEq, Eq, Debug)]
|
|
19
|
-
pub struct OFTLimit {
|
|
20
|
-
pub min_amount_ld: i128,
|
|
21
|
-
pub max_amount_ld: i128,
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/// Receipt containing amounts sent and received in an OFT transfer
|
|
25
|
-
#[contracttype]
|
|
26
|
-
#[derive(Clone, PartialEq, Eq, Debug)]
|
|
27
|
-
pub struct OFTReceipt {
|
|
28
|
-
pub amount_sent_ld: i128,
|
|
29
|
-
pub amount_received_ld: i128,
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/// Details about fees charged in an OFT operation
|
|
33
|
-
#[contracttype]
|
|
34
|
-
#[derive(Clone, PartialEq, Eq, Debug)]
|
|
35
|
-
pub struct OFTFeeDetail {
|
|
36
|
-
pub fee_amount_ld: i128,
|
|
37
|
-
pub description: Bytes,
|
|
38
|
-
}
|
|
@@ -1,427 +0,0 @@
|
|
|
1
|
-
//! Utility functions for OFT-STD integration tests.
|
|
2
|
-
|
|
3
|
-
use crate::integration_tests::setup::{decode_packet, ChainSetup};
|
|
4
|
-
use endpoint_v2::{MessagingFee, Origin, OutboundPacket};
|
|
5
|
-
use message_lib_common::packet_codec_v1;
|
|
6
|
-
use oft::extensions::rate_limiter::Direction;
|
|
7
|
-
use oft::types::{OFTFeeDetail, OFTLimit, OFTReceipt, SendParam};
|
|
8
|
-
use soroban_sdk::{
|
|
9
|
-
address_payload::AddressPayload,
|
|
10
|
-
testutils::{Events, Ledger, MockAuth, MockAuthInvoke},
|
|
11
|
-
token::StellarAssetClient,
|
|
12
|
-
xdr::ToXdr,
|
|
13
|
-
Address, Bytes, BytesN, Env, IntoVal, Map, Symbol, Val, Vec,
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
// ============================================================================
|
|
17
|
-
// Address Conversion Utilities
|
|
18
|
-
// ============================================================================
|
|
19
|
-
|
|
20
|
-
pub fn address_to_peer_bytes32(address: &Address) -> BytesN<32> {
|
|
21
|
-
match address.to_payload().unwrap() {
|
|
22
|
-
AddressPayload::ContractIdHash(payload) => payload,
|
|
23
|
-
AddressPayload::AccountIdPublicKeyEd25519(_) => panic!("peer must be a contract"),
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
pub fn peer_bytes32_to_address(env: &Env, bytes32: &BytesN<32>) -> Address {
|
|
28
|
-
AddressPayload::ContractIdHash(bytes32.clone()).to_address(env)
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
#[allow(dead_code)]
|
|
32
|
-
pub fn create_recipient_address(env: &Env) -> Address {
|
|
33
|
-
let bytes = BytesN::from_array(env, &[0u8; 32]);
|
|
34
|
-
peer_bytes32_to_address(env, &bytes)
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// ============================================================================
|
|
38
|
-
// OFT Core Operations
|
|
39
|
-
// ============================================================================
|
|
40
|
-
|
|
41
|
-
pub fn quote_oft(chain: &ChainSetup<'_>, send_param: &SendParam) -> (OFTLimit, Vec<OFTFeeDetail>, OFTReceipt) {
|
|
42
|
-
chain.oft.quote_oft(send_param)
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
pub fn quote_send(
|
|
46
|
-
env: &Env,
|
|
47
|
-
chain: &ChainSetup<'_>,
|
|
48
|
-
sender: &Address,
|
|
49
|
-
send_param: &SendParam,
|
|
50
|
-
pay_in_zro: bool,
|
|
51
|
-
) -> MessagingFee {
|
|
52
|
-
env.mock_auths(&[MockAuth {
|
|
53
|
-
address: sender,
|
|
54
|
-
invoke: &MockAuthInvoke {
|
|
55
|
-
contract: &chain.oft.address,
|
|
56
|
-
fn_name: "quote_send",
|
|
57
|
-
args: (sender, send_param, &pay_in_zro).into_val(env),
|
|
58
|
-
sub_invokes: &[],
|
|
59
|
-
},
|
|
60
|
-
}]);
|
|
61
|
-
chain.oft.quote_send(sender, send_param, &pay_in_zro)
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/// Send without fee (standard OFT send)
|
|
65
|
-
pub fn send(
|
|
66
|
-
env: &Env,
|
|
67
|
-
chain: &ChainSetup<'_>,
|
|
68
|
-
sender: &Address,
|
|
69
|
-
send_param: &SendParam,
|
|
70
|
-
fee: &MessagingFee,
|
|
71
|
-
refund_address: &Address,
|
|
72
|
-
oft_receipt: &OFTReceipt,
|
|
73
|
-
) {
|
|
74
|
-
env.mock_auths(&[MockAuth {
|
|
75
|
-
address: sender,
|
|
76
|
-
invoke: &MockAuthInvoke {
|
|
77
|
-
contract: &chain.oft.address,
|
|
78
|
-
fn_name: "send",
|
|
79
|
-
args: (sender, send_param, fee, refund_address).into_val(env),
|
|
80
|
-
sub_invokes: &[
|
|
81
|
-
MockAuthInvoke {
|
|
82
|
-
contract: &chain.native_token,
|
|
83
|
-
fn_name: "transfer",
|
|
84
|
-
args: (sender, &chain.endpoint.address, &fee.native_fee).into_val(env),
|
|
85
|
-
sub_invokes: &[],
|
|
86
|
-
},
|
|
87
|
-
MockAuthInvoke {
|
|
88
|
-
contract: &chain.oft_token,
|
|
89
|
-
fn_name: "burn",
|
|
90
|
-
args: (sender, &oft_receipt.amount_received_ld).into_val(env),
|
|
91
|
-
sub_invokes: &[],
|
|
92
|
-
},
|
|
93
|
-
],
|
|
94
|
-
},
|
|
95
|
-
}]);
|
|
96
|
-
chain.oft.send(sender, send_param, fee, refund_address);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
/// Send with fee (OFT fee extension enabled)
|
|
100
|
-
/// Order: transfer fee to deposit -> burn tokens -> transfer native fee
|
|
101
|
-
pub fn send_with_fee(
|
|
102
|
-
env: &Env,
|
|
103
|
-
chain: &ChainSetup<'_>,
|
|
104
|
-
sender: &Address,
|
|
105
|
-
send_param: &SendParam,
|
|
106
|
-
fee: &MessagingFee,
|
|
107
|
-
refund_address: &Address,
|
|
108
|
-
oft_receipt: &OFTReceipt,
|
|
109
|
-
fee_deposit_address: &Address,
|
|
110
|
-
) {
|
|
111
|
-
let fee_amount = oft_receipt.amount_sent_ld - oft_receipt.amount_received_ld;
|
|
112
|
-
env.mock_auths(&[MockAuth {
|
|
113
|
-
address: sender,
|
|
114
|
-
invoke: &MockAuthInvoke {
|
|
115
|
-
contract: &chain.oft.address,
|
|
116
|
-
fn_name: "send",
|
|
117
|
-
args: (sender, send_param, fee, refund_address).into_val(env),
|
|
118
|
-
sub_invokes: &[
|
|
119
|
-
MockAuthInvoke {
|
|
120
|
-
contract: &chain.oft_token,
|
|
121
|
-
fn_name: "transfer",
|
|
122
|
-
args: (sender, fee_deposit_address, &fee_amount).into_val(env),
|
|
123
|
-
sub_invokes: &[],
|
|
124
|
-
},
|
|
125
|
-
MockAuthInvoke {
|
|
126
|
-
contract: &chain.oft_token,
|
|
127
|
-
fn_name: "burn",
|
|
128
|
-
args: (sender, &oft_receipt.amount_received_ld).into_val(env),
|
|
129
|
-
sub_invokes: &[],
|
|
130
|
-
},
|
|
131
|
-
MockAuthInvoke {
|
|
132
|
-
contract: &chain.native_token,
|
|
133
|
-
fn_name: "transfer",
|
|
134
|
-
args: (sender, &chain.endpoint.address, &fee.native_fee).into_val(env),
|
|
135
|
-
sub_invokes: &[],
|
|
136
|
-
},
|
|
137
|
-
],
|
|
138
|
-
},
|
|
139
|
-
}]);
|
|
140
|
-
chain.oft.send(sender, send_param, fee, refund_address);
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
pub fn try_send(
|
|
144
|
-
env: &Env,
|
|
145
|
-
chain: &ChainSetup<'_>,
|
|
146
|
-
sender: &Address,
|
|
147
|
-
send_param: &SendParam,
|
|
148
|
-
fee: &MessagingFee,
|
|
149
|
-
refund_address: &Address,
|
|
150
|
-
oft_receipt: &OFTReceipt,
|
|
151
|
-
) -> bool {
|
|
152
|
-
env.mock_auths(&[MockAuth {
|
|
153
|
-
address: sender,
|
|
154
|
-
invoke: &MockAuthInvoke {
|
|
155
|
-
contract: &chain.oft.address,
|
|
156
|
-
fn_name: "send",
|
|
157
|
-
args: (sender, send_param, fee, refund_address).into_val(env),
|
|
158
|
-
sub_invokes: &[
|
|
159
|
-
MockAuthInvoke {
|
|
160
|
-
contract: &chain.native_token,
|
|
161
|
-
fn_name: "transfer",
|
|
162
|
-
args: (sender, &chain.endpoint.address, &fee.native_fee).into_val(env),
|
|
163
|
-
sub_invokes: &[],
|
|
164
|
-
},
|
|
165
|
-
MockAuthInvoke {
|
|
166
|
-
contract: &chain.oft_token,
|
|
167
|
-
fn_name: "burn",
|
|
168
|
-
args: (sender, &oft_receipt.amount_received_ld).into_val(env),
|
|
169
|
-
sub_invokes: &[],
|
|
170
|
-
},
|
|
171
|
-
],
|
|
172
|
-
},
|
|
173
|
-
}]);
|
|
174
|
-
chain.oft.try_send(sender, send_param, fee, refund_address).is_ok()
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
// ============================================================================
|
|
178
|
-
// Packet Handling
|
|
179
|
-
// ============================================================================
|
|
180
|
-
|
|
181
|
-
pub fn validate_packet(env: &Env, chain: &ChainSetup<'_>, packet_event: &(Bytes, Bytes, Address)) {
|
|
182
|
-
let packet = decode_packet(env, &packet_event.0);
|
|
183
|
-
let encoded_header = packet_codec_v1::encode_packet_header(env, &packet);
|
|
184
|
-
let payload_hash = packet_codec_v1::payload_hash(env, &packet);
|
|
185
|
-
|
|
186
|
-
env.mock_auths(&[MockAuth {
|
|
187
|
-
address: &chain.owner,
|
|
188
|
-
invoke: &MockAuthInvoke {
|
|
189
|
-
contract: &chain.sml.address,
|
|
190
|
-
fn_name: "validate_packet",
|
|
191
|
-
args: (&encoded_header, &payload_hash).into_val(env),
|
|
192
|
-
sub_invokes: &[],
|
|
193
|
-
},
|
|
194
|
-
}]);
|
|
195
|
-
chain.sml.validate_packet(&encoded_header, &payload_hash);
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
pub fn lz_receive(
|
|
199
|
-
env: &Env,
|
|
200
|
-
chain: &ChainSetup<'_>,
|
|
201
|
-
executor: &Address,
|
|
202
|
-
packet: &OutboundPacket,
|
|
203
|
-
recipient: &Address,
|
|
204
|
-
value: i128,
|
|
205
|
-
) {
|
|
206
|
-
let origin =
|
|
207
|
-
Origin { src_eid: packet.src_eid, sender: address_to_peer_bytes32(&packet.sender), nonce: packet.nonce };
|
|
208
|
-
let extra_options = recipient.to_xdr(env);
|
|
209
|
-
|
|
210
|
-
env.mock_auths(&[MockAuth {
|
|
211
|
-
address: executor,
|
|
212
|
-
invoke: &MockAuthInvoke {
|
|
213
|
-
contract: &chain.oft.address,
|
|
214
|
-
fn_name: "lz_receive",
|
|
215
|
-
args: (executor, &origin, &packet.guid, &packet.message, &extra_options, &value).into_val(env),
|
|
216
|
-
sub_invokes: &[],
|
|
217
|
-
},
|
|
218
|
-
}]);
|
|
219
|
-
endpoint_v2::LayerZeroReceiverClient::new(env, &chain.oft.address).lz_receive(
|
|
220
|
-
executor,
|
|
221
|
-
&origin,
|
|
222
|
-
&packet.guid,
|
|
223
|
-
&packet.message,
|
|
224
|
-
&extra_options,
|
|
225
|
-
&value,
|
|
226
|
-
);
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
pub fn try_lz_receive(
|
|
230
|
-
env: &Env,
|
|
231
|
-
chain: &ChainSetup<'_>,
|
|
232
|
-
executor: &Address,
|
|
233
|
-
packet: &OutboundPacket,
|
|
234
|
-
recipient: &Address,
|
|
235
|
-
value: i128,
|
|
236
|
-
) -> bool {
|
|
237
|
-
let origin =
|
|
238
|
-
Origin { src_eid: packet.src_eid, sender: address_to_peer_bytes32(&packet.sender), nonce: packet.nonce };
|
|
239
|
-
let extra_options = recipient.to_xdr(env);
|
|
240
|
-
|
|
241
|
-
env.mock_auths(&[MockAuth {
|
|
242
|
-
address: executor,
|
|
243
|
-
invoke: &MockAuthInvoke {
|
|
244
|
-
contract: &chain.oft.address,
|
|
245
|
-
fn_name: "lz_receive",
|
|
246
|
-
args: (executor, &origin, &packet.guid, &packet.message, &extra_options, &value).into_val(env),
|
|
247
|
-
sub_invokes: &[],
|
|
248
|
-
},
|
|
249
|
-
}]);
|
|
250
|
-
endpoint_v2::LayerZeroReceiverClient::new(env, &chain.oft.address)
|
|
251
|
-
.try_lz_receive(executor, &origin, &packet.guid, &packet.message, &extra_options, &value)
|
|
252
|
-
.is_ok()
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
// returns (encoded_payload, options, send_library)
|
|
256
|
-
pub fn scan_packet_sent_event(env: &Env, endpoint: &Address) -> Option<(Bytes, Bytes, Address)> {
|
|
257
|
-
let mut packet = None;
|
|
258
|
-
for (emitter, topics, data) in env.events().all() {
|
|
259
|
-
let packet_sent_symbol = Symbol::new(env, "packet_sent").to_val();
|
|
260
|
-
if emitter == *endpoint && topics.contains(packet_sent_symbol) {
|
|
261
|
-
let map: Map<Symbol, Val> = data.into_val(env);
|
|
262
|
-
|
|
263
|
-
let encoded_payload: Bytes = map.get(Symbol::new(env, "encoded_packet")).unwrap().into_val(env);
|
|
264
|
-
let options: Bytes = map.get(Symbol::new(env, "options")).unwrap().into_val(env);
|
|
265
|
-
let send_library: Address = map.get(Symbol::new(env, "send_library")).unwrap().into_val(env);
|
|
266
|
-
|
|
267
|
-
packet = Some((encoded_payload, options, send_library));
|
|
268
|
-
}
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
packet
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
// ============================================================================
|
|
275
|
-
// Token Operations
|
|
276
|
-
// ============================================================================
|
|
277
|
-
|
|
278
|
-
pub fn mint_to(env: &Env, owner: &Address, token: &Address, to: &Address, amount: i128) {
|
|
279
|
-
env.mock_auths(&[MockAuth {
|
|
280
|
-
address: owner,
|
|
281
|
-
invoke: &MockAuthInvoke {
|
|
282
|
-
contract: token,
|
|
283
|
-
fn_name: "mint",
|
|
284
|
-
args: (to, amount).into_val(env),
|
|
285
|
-
sub_invokes: &[],
|
|
286
|
-
},
|
|
287
|
-
}]);
|
|
288
|
-
|
|
289
|
-
let sac = StellarAssetClient::new(env, token);
|
|
290
|
-
sac.mint(to, &amount);
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
pub fn transfer_sac_admin(env: &Env, owner: &Address, token: &Address, new_admin: &Address) {
|
|
294
|
-
env.mock_auths(&[MockAuth {
|
|
295
|
-
address: owner,
|
|
296
|
-
invoke: &MockAuthInvoke {
|
|
297
|
-
contract: token,
|
|
298
|
-
fn_name: "set_admin",
|
|
299
|
-
args: (new_admin,).into_val(env),
|
|
300
|
-
sub_invokes: &[],
|
|
301
|
-
},
|
|
302
|
-
}]);
|
|
303
|
-
StellarAssetClient::new(env, token).set_admin(new_admin);
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
pub fn token_balance(env: &Env, token: &Address, account: &Address) -> i128 {
|
|
307
|
-
soroban_sdk::token::TokenClient::new(env, token).balance(account)
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
// ============================================================================
|
|
311
|
-
// Pausable Extension Operations
|
|
312
|
-
// ============================================================================
|
|
313
|
-
|
|
314
|
-
pub fn set_paused(env: &Env, chain: &ChainSetup<'_>, paused: bool) {
|
|
315
|
-
env.mock_auths(&[MockAuth {
|
|
316
|
-
address: &chain.owner,
|
|
317
|
-
invoke: &MockAuthInvoke {
|
|
318
|
-
contract: &chain.oft.address,
|
|
319
|
-
fn_name: "set_paused",
|
|
320
|
-
args: (&paused,).into_val(env),
|
|
321
|
-
sub_invokes: &[],
|
|
322
|
-
},
|
|
323
|
-
}]);
|
|
324
|
-
chain.oft.set_paused(&paused);
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
pub fn is_paused(chain: &ChainSetup<'_>) -> bool {
|
|
328
|
-
chain.oft.is_paused()
|
|
329
|
-
}
|
|
330
|
-
|
|
331
|
-
// ============================================================================
|
|
332
|
-
// OFT Fee Extension Operations
|
|
333
|
-
// ============================================================================
|
|
334
|
-
|
|
335
|
-
pub fn set_fee_deposit_address(env: &Env, chain: &ChainSetup<'_>, deposit_address: &Address) {
|
|
336
|
-
env.mock_auths(&[MockAuth {
|
|
337
|
-
address: &chain.owner,
|
|
338
|
-
invoke: &MockAuthInvoke {
|
|
339
|
-
contract: &chain.oft.address,
|
|
340
|
-
fn_name: "set_fee_deposit_address",
|
|
341
|
-
args: (deposit_address,).into_val(env),
|
|
342
|
-
sub_invokes: &[],
|
|
343
|
-
},
|
|
344
|
-
}]);
|
|
345
|
-
chain.oft.set_fee_deposit_address(deposit_address);
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
pub fn set_default_fee_bps(env: &Env, chain: &ChainSetup<'_>, fee_bps: u64) {
|
|
349
|
-
env.mock_auths(&[MockAuth {
|
|
350
|
-
address: &chain.owner,
|
|
351
|
-
invoke: &MockAuthInvoke {
|
|
352
|
-
contract: &chain.oft.address,
|
|
353
|
-
fn_name: "set_default_fee_bps",
|
|
354
|
-
args: (&fee_bps,).into_val(env),
|
|
355
|
-
sub_invokes: &[],
|
|
356
|
-
},
|
|
357
|
-
}]);
|
|
358
|
-
chain.oft.set_default_fee_bps(&fee_bps);
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
pub fn set_fee_bps(env: &Env, chain: &ChainSetup<'_>, dst_eid: u32, fee_bps: u64) {
|
|
362
|
-
env.mock_auths(&[MockAuth {
|
|
363
|
-
address: &chain.owner,
|
|
364
|
-
invoke: &MockAuthInvoke {
|
|
365
|
-
contract: &chain.oft.address,
|
|
366
|
-
fn_name: "set_fee_bps",
|
|
367
|
-
args: (&dst_eid, &fee_bps).into_val(env),
|
|
368
|
-
sub_invokes: &[],
|
|
369
|
-
},
|
|
370
|
-
}]);
|
|
371
|
-
chain.oft.set_fee_bps(&dst_eid, &fee_bps);
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
// ============================================================================
|
|
375
|
-
// Rate Limiter Extension Operations
|
|
376
|
-
// ============================================================================
|
|
377
|
-
|
|
378
|
-
pub fn set_rate_limit(env: &Env, chain: &ChainSetup<'_>, direction: &Direction, dst_eid: u32, limit: i128, window_seconds: u64) {
|
|
379
|
-
env.mock_auths(&[MockAuth {
|
|
380
|
-
address: &chain.owner,
|
|
381
|
-
invoke: &MockAuthInvoke {
|
|
382
|
-
contract: &chain.oft.address,
|
|
383
|
-
fn_name: "set_rate_limit",
|
|
384
|
-
args: (direction, &dst_eid, &limit, &window_seconds).into_val(env),
|
|
385
|
-
sub_invokes: &[],
|
|
386
|
-
},
|
|
387
|
-
}]);
|
|
388
|
-
chain.oft.set_rate_limit(direction, &dst_eid, &limit, &window_seconds);
|
|
389
|
-
}
|
|
390
|
-
|
|
391
|
-
pub fn rate_limit_capacity(chain: &ChainSetup<'_>, direction: &Direction, eid: u32) -> i128 {
|
|
392
|
-
chain.oft.rate_limit_capacity(direction, &eid)
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
pub fn rate_limit_in_flight(chain: &ChainSetup<'_>, direction: &Direction, eid: u32) -> i128 {
|
|
396
|
-
chain.oft.rate_limit_in_flight(direction, &eid)
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
// ============================================================================
|
|
400
|
-
// Time Utilities
|
|
401
|
-
// ============================================================================
|
|
402
|
-
|
|
403
|
-
pub fn advance_time(env: &Env, seconds: u64) {
|
|
404
|
-
let current = env.ledger().timestamp();
|
|
405
|
-
env.ledger().set_timestamp(current + seconds);
|
|
406
|
-
}
|
|
407
|
-
|
|
408
|
-
#[allow(dead_code)]
|
|
409
|
-
pub fn set_timestamp(env: &Env, timestamp: u64) {
|
|
410
|
-
env.ledger().set_timestamp(timestamp);
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
// ============================================================================
|
|
414
|
-
// SendParam Builder
|
|
415
|
-
// ============================================================================
|
|
416
|
-
|
|
417
|
-
pub fn create_send_param(env: &Env, dst_eid: u32, amount_ld: i128, min_amount_ld: i128, to: &BytesN<32>) -> SendParam {
|
|
418
|
-
SendParam {
|
|
419
|
-
dst_eid,
|
|
420
|
-
to: to.clone(),
|
|
421
|
-
amount_ld,
|
|
422
|
-
min_amount_ld,
|
|
423
|
-
extra_options: Bytes::new(env),
|
|
424
|
-
compose_msg: Bytes::new(env),
|
|
425
|
-
oft_cmd: Bytes::new(env),
|
|
426
|
-
}
|
|
427
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
#![no_std]
|
|
2
|
-
|
|
3
|
-
pub mod oft;
|
|
4
|
-
|
|
5
|
-
#[cfg(test)]
|
|
6
|
-
#[path = "../integration-tests/mod.rs"]
|
|
7
|
-
pub mod integration_tests;
|
|
8
|
-
|
|
9
|
-
pub use oft::*;
|
|
10
|
-
|
|
11
|
-
// Re-export extension types from the oft crate for convenience
|
|
12
|
-
pub use ::oft::extensions::{
|
|
13
|
-
oft_fee::{OFTFee, OFTFeeError},
|
|
14
|
-
pausable::{OFTPausable, OFTPausableError},
|
|
15
|
-
rate_limiter::{Direction, RateLimit, RateLimiter, RateLimitError},
|
|
16
|
-
};
|
|
@@ -1,156 +0,0 @@
|
|
|
1
|
-
use common_macros::{contract_impl, storage};
|
|
2
|
-
use oapp_macros::oapp;
|
|
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
|
-
}
|
|
29
|
-
|
|
30
|
-
#[storage]
|
|
31
|
-
enum OFTStdStorage {
|
|
32
|
-
#[instance(OFTMode)]
|
|
33
|
-
Mode,
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
#[oapp]
|
|
37
|
-
pub struct OFTStd;
|
|
38
|
-
|
|
39
|
-
#[contract_impl]
|
|
40
|
-
impl OFTStd {
|
|
41
|
-
pub fn __constructor(
|
|
42
|
-
env: &Env,
|
|
43
|
-
token: &Address,
|
|
44
|
-
owner: &Address,
|
|
45
|
-
endpoint: &Address,
|
|
46
|
-
delegate: &Option<Address>,
|
|
47
|
-
shared_decimals: u32,
|
|
48
|
-
mode: OFTMode,
|
|
49
|
-
) {
|
|
50
|
-
oft_initialize::<Self>(env, owner, token, endpoint, delegate, shared_decimals);
|
|
51
|
-
OFTStdStorage::set_mode(env, &mode);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/// Returns the mode of operation for this OFT (LockUnlock or MintBurn)
|
|
55
|
-
pub fn mode(env: &Env) -> OFTMode {
|
|
56
|
-
OFTStdStorage::mode(env).unwrap()
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/// OFT trait implementation for standard OFT with extensions
|
|
61
|
-
#[contract_impl(contracttrait)]
|
|
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
|
-
}
|
|
76
|
-
|
|
77
|
-
/// OFT behavior for standard OFT with extension hooks
|
|
78
|
-
impl OFTInternal for OFTStd {
|
|
79
|
-
fn __debit(env: &Env, sender: &Address, amount_ld: i128, min_amount_ld: i128, dst_eid: u32) -> OFTReceipt {
|
|
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
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
fn __credit(env: &Env, to: &Address, amount_ld: i128, src_eid: u32) -> i128 {
|
|
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 }
|
|
132
|
-
}
|
|
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 {}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
use soroban_sdk::{contractclient, BytesN, Env, Vec};
|
|
2
|
-
|
|
3
|
-
/// Length of an ECDSA signature (64 bytes) plus recovery ID (1 byte).
|
|
4
|
-
pub const SIGNATURE_LENGTH: usize = 65;
|
|
5
|
-
|
|
6
|
-
/// Multisig interface for threshold-based signature verification.
|
|
7
|
-
///
|
|
8
|
-
/// Provides functionality to manage signers and verify that a sufficient
|
|
9
|
-
/// number of valid signatures (meeting the threshold) have signed a message.
|
|
10
|
-
#[contractclient(name = "MultiSigClient")]
|
|
11
|
-
pub trait IMultisig {
|
|
12
|
-
/// Adds or removes a signer from the multisig.
|
|
13
|
-
///
|
|
14
|
-
/// # Arguments
|
|
15
|
-
/// * `signer` - The 20-byte signer address (derived from secp256k1 public key)
|
|
16
|
-
/// * `active` - `true` to add, `false` to remove
|
|
17
|
-
fn set_signer(env: &Env, signer: &BytesN<20>, active: bool);
|
|
18
|
-
|
|
19
|
-
/// Returns all registered signers.
|
|
20
|
-
fn get_signers(env: &Env) -> Vec<BytesN<20>>;
|
|
21
|
-
|
|
22
|
-
/// Returns the total number of registered signers.
|
|
23
|
-
fn total_signers(env: &Env) -> u32;
|
|
24
|
-
|
|
25
|
-
/// Checks if an address is a registered signer.
|
|
26
|
-
fn is_signer(env: &Env, signer: &BytesN<20>) -> bool;
|
|
27
|
-
|
|
28
|
-
/// Returns the current signature threshold (quorum).
|
|
29
|
-
fn threshold(env: &Env) -> u32;
|
|
30
|
-
|
|
31
|
-
/// Sets the signature threshold (quorum).
|
|
32
|
-
///
|
|
33
|
-
/// The threshold must be greater than 0 and not exceed total signers.
|
|
34
|
-
fn set_threshold(env: &Env, threshold: u32);
|
|
35
|
-
|
|
36
|
-
/// Verifies signatures against the configured threshold.
|
|
37
|
-
///
|
|
38
|
-
/// # Arguments
|
|
39
|
-
/// * `hash` - The 32-byte message hash that was signed
|
|
40
|
-
/// * `signatures` - List of signatures to verify
|
|
41
|
-
///
|
|
42
|
-
/// # Panics
|
|
43
|
-
/// If fewer than `threshold` valid signatures from registered signers are provided.
|
|
44
|
-
fn verify_signatures(env: &Env, hash: &BytesN<32>, signatures: &Vec<BytesN<SIGNATURE_LENGTH>>);
|
|
45
|
-
|
|
46
|
-
/// Verifies signatures against a custom threshold.
|
|
47
|
-
///
|
|
48
|
-
/// # Arguments
|
|
49
|
-
/// * `hash` - The 32-byte message hash that was signed
|
|
50
|
-
/// * `signatures` - List of signatures to verify
|
|
51
|
-
/// * `threshold` - Custom threshold to use instead of the configured one
|
|
52
|
-
///
|
|
53
|
-
/// # Panics
|
|
54
|
-
/// If fewer than `threshold` valid signatures from registered signers are provided.
|
|
55
|
-
fn verify_n_signatures(env: &Env, hash: &BytesN<32>, signatures: &Vec<BytesN<SIGNATURE_LENGTH>>, threshold: u32);
|
|
56
|
-
}
|