@layerzerolabs/protocol-stellar-v2 0.2.48 → 0.2.49
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 +236 -239
- package/.turbo/turbo-lint.log +97 -304
- package/.turbo/turbo-test.log +1986 -1766
- package/contracts/common-macros/src/rbac.rs +1 -1
- package/contracts/common-macros/src/tests/rbac.rs +123 -20
- package/contracts/common-macros/src/tests/snapshots/common_macros__tests__rbac__snapshot_authorizer_role.snap +21 -0
- package/contracts/common-macros/src/tests/snapshots/common_macros__tests__rbac__snapshot_preserve_function_signature.snap +6 -2
- package/contracts/macro-integration-tests/tests/runtime/oapp/mod.rs +1 -22
- package/contracts/macro-integration-tests/tests/runtime/oapp/oapp_core.rs +1 -3
- package/contracts/macro-integration-tests/tests/runtime/oapp/options_type3.rs +1 -4
- package/contracts/macro-integration-tests/tests/runtime/oapp/receiver.rs +1 -5
- package/contracts/macro-integration-tests/tests/runtime/oapp/sender.rs +0 -1
- package/contracts/macro-integration-tests/tests/ui/rbac/pass/basic.rs +9 -0
- package/contracts/oapps/counter/integration_tests/utils.rs +1 -3
- package/contracts/oapps/counter/src/tests/mod.rs +1 -17
- package/contracts/oapps/counter/src/tests/test_counter.rs +0 -2
- package/contracts/oapps/oapp/src/oapp_core.rs +5 -8
- package/contracts/oapps/oapp/src/oapp_options_type3.rs +4 -4
- package/contracts/oapps/oapp/src/tests/mod.rs +0 -21
- package/contracts/oapps/oapp/src/tests/oapp_core.rs +0 -1
- package/contracts/oapps/oapp/src/tests/oapp_options_type3.rs +0 -1
- package/contracts/oapps/oapp/src/tests/oapp_receiver.rs +0 -1
- package/contracts/oapps/oapp/src/tests/oapp_sender.rs +0 -1
- package/contracts/oapps/oft/integration-tests/setup.rs +1 -17
- package/contracts/oapps/oft/integration-tests/utils.rs +5 -18
- package/contracts/oapps/oft/src/extensions/oft_fee.rs +8 -8
- package/contracts/oapps/oft/src/tests/extensions/oft_fee.rs +3 -3
- package/contracts/oapps/oft-core/integration-tests/setup.rs +1 -22
- package/contracts/oapps/oft-core/src/oft_core.rs +5 -5
- package/contracts/oapps/oft-core/src/tests/test_msg_inspector.rs +3 -3
- package/contracts/oapps/oft-core/src/tests/test_utils.rs +1 -28
- package/contracts/utils/src/rbac.rs +13 -3
- package/contracts/utils/src/tests/rbac.rs +1 -1
- package/package.json +4 -4
- package/sdk/.turbo/turbo-test.log +278 -290
- package/sdk/dist/generated/counter.d.ts +6 -6
- package/sdk/dist/generated/counter.js +6 -6
- package/sdk/dist/generated/oft.d.ts +11 -11
- package/sdk/dist/generated/oft.js +10 -10
- package/sdk/dist/generated/sac_manager.d.ts +3 -3
- package/sdk/dist/generated/sac_manager.js +3 -3
- package/sdk/package.json +1 -1
- package/sdk/test/counter-sml.test.ts +0 -18
- package/sdk/test/counter-uln.test.ts +0 -18
- package/sdk/test/oft-sml.test.ts +0 -20
|
@@ -10,13 +10,12 @@ use crate::{
|
|
|
10
10
|
oft_types::OftType,
|
|
11
11
|
};
|
|
12
12
|
use endpoint_v2::{EndpointV2, EndpointV2Client};
|
|
13
|
-
use oapp::oapp_core::OAPP_MANAGER_ROLE;
|
|
14
13
|
use simple_message_lib::{SimpleMessageLib, SimpleMessageLibClient};
|
|
15
14
|
use soroban_sdk::{
|
|
16
15
|
contract, contractimpl, contracttype, log,
|
|
17
16
|
testutils::{Address as _, MockAuth, MockAuthInvoke},
|
|
18
17
|
token::{StellarAssetClient, TokenClient},
|
|
19
|
-
Address, BytesN, Env, IntoVal,
|
|
18
|
+
Address, BytesN, Env, IntoVal,
|
|
20
19
|
};
|
|
21
20
|
|
|
22
21
|
// ============================================================================
|
|
@@ -214,22 +213,7 @@ pub fn wire_oft(env: &Env, chains: &[&ChainSetup<'_>]) {
|
|
|
214
213
|
}
|
|
215
214
|
}
|
|
216
215
|
|
|
217
|
-
fn grant_oapp_admin(env: &Env, contract: &Address, owner: &Address) {
|
|
218
|
-
let role = Symbol::new(env, OAPP_MANAGER_ROLE);
|
|
219
|
-
env.mock_auths(&[MockAuth {
|
|
220
|
-
address: owner,
|
|
221
|
-
invoke: &MockAuthInvoke {
|
|
222
|
-
contract,
|
|
223
|
-
fn_name: "grant_role",
|
|
224
|
-
args: (owner, &role, owner).into_val(env),
|
|
225
|
-
sub_invokes: &[],
|
|
226
|
-
},
|
|
227
|
-
}]);
|
|
228
|
-
utils::rbac::RoleBasedAccessControlClient::new(env, contract).grant_role(owner, &role, owner);
|
|
229
|
-
}
|
|
230
|
-
|
|
231
216
|
pub fn set_peer(env: &Env, owner: &Address, oft: &OFTClient<'_>, dst_eid: u32, peer: &BytesN<32>) {
|
|
232
|
-
grant_oapp_admin(env, &oft.address, owner);
|
|
233
217
|
|
|
234
218
|
let peer_option = Some(peer.clone());
|
|
235
219
|
env.mock_auths(&[MockAuth {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
//! Utility functions for OFT-STD integration tests.
|
|
2
2
|
|
|
3
3
|
use crate::extensions::rate_limiter::{Direction, Mode, RateLimitConfig, RATE_LIMITER_MANAGER_ROLE};
|
|
4
|
-
use crate::extensions::oft_fee::
|
|
4
|
+
use crate::extensions::oft_fee::FEE_CONFIG_MANAGER_ROLE;
|
|
5
5
|
use crate::extensions::pausable::{PAUSER_ROLE, UNPAUSER_ROLE};
|
|
6
6
|
use crate::integration_tests::setup::{decode_packet, ChainSetup};
|
|
7
7
|
use crate::MintableClient;
|
|
@@ -406,19 +406,6 @@ pub fn is_paused(chain: &ChainSetup<'_>) -> bool {
|
|
|
406
406
|
// ============================================================================
|
|
407
407
|
|
|
408
408
|
pub fn set_fee_deposit_address(env: &Env, chain: &ChainSetup<'_>, deposit_address: &Address) {
|
|
409
|
-
// `set_fee_deposit_address` is protected by RBAC (`FEE_MANAGER_ROLE`). Grant it to owner for tests.
|
|
410
|
-
let role = Symbol::new(env, FEE_MANAGER_ROLE);
|
|
411
|
-
env.mock_auths(&[MockAuth {
|
|
412
|
-
address: &chain.owner,
|
|
413
|
-
invoke: &MockAuthInvoke {
|
|
414
|
-
contract: &chain.oft.address,
|
|
415
|
-
fn_name: "grant_role",
|
|
416
|
-
args: (&chain.owner, &role, &chain.owner).into_val(env),
|
|
417
|
-
sub_invokes: &[],
|
|
418
|
-
},
|
|
419
|
-
}]);
|
|
420
|
-
chain.oft.grant_role(&chain.owner, &role, &chain.owner);
|
|
421
|
-
|
|
422
409
|
let deposit_address_opt = Some(deposit_address.clone());
|
|
423
410
|
env.mock_auths(&[MockAuth {
|
|
424
411
|
address: &chain.owner,
|
|
@@ -433,8 +420,8 @@ pub fn set_fee_deposit_address(env: &Env, chain: &ChainSetup<'_>, deposit_addres
|
|
|
433
420
|
}
|
|
434
421
|
|
|
435
422
|
pub fn set_default_fee_bps(env: &Env, chain: &ChainSetup<'_>, fee_bps: u32) {
|
|
436
|
-
// `set_default_fee_bps` is protected by RBAC (`
|
|
437
|
-
let role = Symbol::new(env,
|
|
423
|
+
// `set_default_fee_bps` is protected by RBAC (`FEE_CONFIG_MANAGER_ROLE`). Grant it to owner for tests.
|
|
424
|
+
let role = Symbol::new(env, FEE_CONFIG_MANAGER_ROLE);
|
|
438
425
|
env.mock_auths(&[MockAuth {
|
|
439
426
|
address: &chain.owner,
|
|
440
427
|
invoke: &MockAuthInvoke {
|
|
@@ -460,8 +447,8 @@ pub fn set_default_fee_bps(env: &Env, chain: &ChainSetup<'_>, fee_bps: u32) {
|
|
|
460
447
|
}
|
|
461
448
|
|
|
462
449
|
pub fn set_fee_bps(env: &Env, chain: &ChainSetup<'_>, dst_eid: u32, fee_bps: u32) {
|
|
463
|
-
// `set_fee_bps` is protected by RBAC (`
|
|
464
|
-
let role = Symbol::new(env,
|
|
450
|
+
// `set_fee_bps` is protected by RBAC (`FEE_CONFIG_MANAGER_ROLE`). Grant it to owner for tests.
|
|
451
|
+
let role = Symbol::new(env, FEE_CONFIG_MANAGER_ROLE);
|
|
465
452
|
env.mock_auths(&[MockAuth {
|
|
466
453
|
address: &chain.owner,
|
|
467
454
|
invoke: &MockAuthInvoke {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
use common_macros::{contract_error, contract_trait, only_role, storage};
|
|
2
2
|
use soroban_sdk::{assert_with_error, contractevent, token::TokenClient, Address, Env};
|
|
3
|
-
use utils::{option_ext::OptionExt, rbac::RoleBasedAccessControl};
|
|
3
|
+
use utils::{option_ext::OptionExt, rbac::{RoleBasedAccessControl, AUTHORIZER}};
|
|
4
4
|
|
|
5
5
|
/// Role for fee configuration (set_default_fee_bps, set_fee_bps, set_fee_deposit_address).
|
|
6
|
-
pub const
|
|
6
|
+
pub const FEE_CONFIG_MANAGER_ROLE: &str = "FEE_CONFIG_MANAGER_ROLE";
|
|
7
7
|
|
|
8
8
|
/// Base fee in basis points (10,000 BPS = 100%)
|
|
9
9
|
/// Used as denominator in fee calculations
|
|
@@ -82,8 +82,8 @@ pub trait OFTFee: OFTFeeInternal + RoleBasedAccessControl {
|
|
|
82
82
|
/// - `Some(n)`: sets the default fee to `n` basis points (must be >0 and <=10,000).
|
|
83
83
|
/// - `Some(0)`: rejected — use `None` to remove the default fee instead.
|
|
84
84
|
/// - `None`: removes the default fee (effective rate becomes 0).
|
|
85
|
-
/// * `operator` - The address that must have
|
|
86
|
-
#[only_role(operator,
|
|
85
|
+
/// * `operator` - The address that must have FEE_CONFIG_MANAGER_ROLE
|
|
86
|
+
#[only_role(operator, FEE_CONFIG_MANAGER_ROLE)]
|
|
87
87
|
fn set_default_fee_bps(env: &soroban_sdk::Env, default_fee_bps: &Option<u32>, operator: &soroban_sdk::Address) {
|
|
88
88
|
Self::__set_default_fee_bps(env, default_fee_bps);
|
|
89
89
|
}
|
|
@@ -96,8 +96,8 @@ pub trait OFTFee: OFTFeeInternal + RoleBasedAccessControl {
|
|
|
96
96
|
/// # Arguments
|
|
97
97
|
/// * `dst_eid` - The destination endpoint ID
|
|
98
98
|
/// * `fee_bps` - The fee rate (0-10,000), or None to remove the fee configuration
|
|
99
|
-
/// * `operator` - The address that must have
|
|
100
|
-
#[only_role(operator,
|
|
99
|
+
/// * `operator` - The address that must have FEE_CONFIG_MANAGER_ROLE
|
|
100
|
+
#[only_role(operator, FEE_CONFIG_MANAGER_ROLE)]
|
|
101
101
|
fn set_fee_bps(env: &soroban_sdk::Env, dst_eid: u32, fee_bps: &Option<u32>, operator: &soroban_sdk::Address) {
|
|
102
102
|
Self::__set_fee_bps(env, dst_eid, fee_bps);
|
|
103
103
|
}
|
|
@@ -106,8 +106,8 @@ pub trait OFTFee: OFTFeeInternal + RoleBasedAccessControl {
|
|
|
106
106
|
///
|
|
107
107
|
/// # Arguments
|
|
108
108
|
/// * `fee_deposit_address` - The address to deposit fees to, or None to remove the fee deposit address
|
|
109
|
-
/// * `operator` - The address
|
|
110
|
-
#[only_role(operator,
|
|
109
|
+
/// * `operator` - The authorizer address
|
|
110
|
+
#[only_role(operator, AUTHORIZER)]
|
|
111
111
|
fn set_fee_deposit_address(
|
|
112
112
|
env: &soroban_sdk::Env,
|
|
113
113
|
fee_deposit_address: &Option<soroban_sdk::Address>,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
extern crate std;
|
|
2
2
|
|
|
3
3
|
use crate::extensions::oft_fee::{OFTFee, OFTFeeError, OFTFeeInternal};
|
|
4
|
-
use crate::extensions::oft_fee::
|
|
4
|
+
use crate::extensions::oft_fee::FEE_CONFIG_MANAGER_ROLE;
|
|
5
5
|
use soroban_sdk::{
|
|
6
6
|
contract, contractimpl,
|
|
7
7
|
testutils::{Address as _, MockAuth, MockAuthInvoke},
|
|
@@ -34,10 +34,10 @@ impl RoleBasedAccessControl for FeeTestContract {}
|
|
|
34
34
|
|
|
35
35
|
#[contractimpl]
|
|
36
36
|
impl FeeTestContract {
|
|
37
|
-
/// Test-only: grants
|
|
37
|
+
/// Test-only: grants FEE_CONFIG_MANAGER_ROLE to the contract.
|
|
38
38
|
pub fn init_roles(env: Env) {
|
|
39
39
|
let contract_id = env.current_contract_address();
|
|
40
|
-
grant_role_no_auth(&env, &contract_id, &Symbol::new(&env,
|
|
40
|
+
grant_role_no_auth(&env, &contract_id, &Symbol::new(&env, FEE_CONFIG_MANAGER_ROLE), &contract_id);
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
pub fn fee_view(env: Env, dst_eid: u32, amount_ld: i128) -> i128 {
|
|
@@ -18,10 +18,8 @@ use soroban_sdk::{
|
|
|
18
18
|
contract, contractimpl, contracttype, log, symbol_short,
|
|
19
19
|
testutils::{Address as _, MockAuth, MockAuthInvoke},
|
|
20
20
|
token::{StellarAssetClient, TokenClient},
|
|
21
|
-
Address, Bytes, BytesN, Env, IntoVal,
|
|
21
|
+
Address, Bytes, BytesN, Env, IntoVal,
|
|
22
22
|
};
|
|
23
|
-
use oapp::oapp_core::OAPP_MANAGER_ROLE;
|
|
24
|
-
use utils::rbac::grant_role_no_auth;
|
|
25
23
|
|
|
26
24
|
// ============================================================================
|
|
27
25
|
// Test OFT Contract
|
|
@@ -182,10 +180,6 @@ fn setup_chain<'a>(env: &Env) -> ChainSetup<'a> {
|
|
|
182
180
|
let shared_decimals: u32 = 6; // Default shared decimals
|
|
183
181
|
let oft_address = env.register(TestOFT, (&oft_token, &owner, &endpoint_address, &delegate, &shared_decimals));
|
|
184
182
|
|
|
185
|
-
// Grant OAPP_MANAGER_ROLE to owner so they can call set_peer, set_delegate, set_msg_inspector, etc.
|
|
186
|
-
env.as_contract(&oft_address, || {
|
|
187
|
-
grant_role_no_auth(env, &owner, &Symbol::new(env, OAPP_MANAGER_ROLE), &owner);
|
|
188
|
-
});
|
|
189
183
|
let composer_address = env.register(DummyComposer, (&endpoint_address,));
|
|
190
184
|
|
|
191
185
|
let endpoint = EndpointV2Client::new(env, &endpoint_address);
|
|
@@ -263,22 +257,7 @@ pub fn wire_oft(env: &Env, chains: &[&ChainSetup<'_>]) {
|
|
|
263
257
|
}
|
|
264
258
|
}
|
|
265
259
|
|
|
266
|
-
fn grant_oapp_admin(env: &Env, contract: &Address, owner: &Address) {
|
|
267
|
-
let role = soroban_sdk::Symbol::new(env, oapp::oapp_core::OAPP_MANAGER_ROLE);
|
|
268
|
-
env.mock_auths(&[MockAuth {
|
|
269
|
-
address: owner,
|
|
270
|
-
invoke: &MockAuthInvoke {
|
|
271
|
-
contract,
|
|
272
|
-
fn_name: "grant_role",
|
|
273
|
-
args: (owner, &role, owner).into_val(env),
|
|
274
|
-
sub_invokes: &[],
|
|
275
|
-
},
|
|
276
|
-
}]);
|
|
277
|
-
utils::rbac::RoleBasedAccessControlClient::new(env, contract).grant_role(owner, &role, owner);
|
|
278
|
-
}
|
|
279
|
-
|
|
280
260
|
pub fn set_peer(env: &Env, owner: &Address, oft: &OFTClient<'_>, dst_eid: u32, peer: &BytesN<32>) {
|
|
281
|
-
grant_oapp_admin(env, &oft.address, owner);
|
|
282
261
|
|
|
283
262
|
let peer_option = Some(peer.clone());
|
|
284
263
|
env.mock_auths(&[MockAuth {
|
|
@@ -58,14 +58,14 @@ use crate::{
|
|
|
58
58
|
use common_macros::{contract_trait, only_role};
|
|
59
59
|
use endpoint_v2::{MessagingComposerClient, MessagingFee, MessagingReceipt};
|
|
60
60
|
use oapp::{
|
|
61
|
-
oapp_core::
|
|
61
|
+
oapp_core::init_ownable_oapp,
|
|
62
62
|
oapp_options_type3::OAppOptionsType3,
|
|
63
63
|
oapp_receiver::OAppReceiver,
|
|
64
64
|
oapp_sender::{FeePayer, OAppSenderInternal},
|
|
65
65
|
OAppMsgInspectorClient,
|
|
66
66
|
};
|
|
67
67
|
use soroban_sdk::{assert_with_error, token::TokenClient, vec, Address, Bytes, Env, Vec};
|
|
68
|
-
use utils::{option_ext::OptionExt, ownable::OwnableInitializer};
|
|
68
|
+
use utils::{option_ext::OptionExt, ownable::OwnableInitializer, rbac::AUTHORIZER};
|
|
69
69
|
|
|
70
70
|
// ===========================================================================
|
|
71
71
|
// OFTInternal Trait (NOT exposed as contract entrypoints)
|
|
@@ -448,12 +448,12 @@ pub trait OFTCore: OFTInternal {
|
|
|
448
448
|
/// Pass `None` to remove the inspector and disable outbound validation.
|
|
449
449
|
///
|
|
450
450
|
/// # Authorization
|
|
451
|
-
/// Requires the caller to
|
|
451
|
+
/// Requires the caller to be the authorizer.
|
|
452
452
|
///
|
|
453
453
|
/// # Arguments
|
|
454
454
|
/// * `inspector` - Address of the inspector contract, or `None` to remove it
|
|
455
|
-
/// * `operator` - The address
|
|
456
|
-
#[only_role(operator,
|
|
455
|
+
/// * `operator` - The authorizer address
|
|
456
|
+
#[only_role(operator, AUTHORIZER)]
|
|
457
457
|
fn set_msg_inspector(
|
|
458
458
|
env: &soroban_sdk::Env,
|
|
459
459
|
inspector: &Option<soroban_sdk::Address>,
|
|
@@ -60,7 +60,7 @@ fn test_set_msg_inspector() {
|
|
|
60
60
|
// Deploy a passing inspector
|
|
61
61
|
let inspector_address = env.register(PassingInspector, ());
|
|
62
62
|
|
|
63
|
-
// Owner (
|
|
63
|
+
// Owner (authorizer) sets the inspector
|
|
64
64
|
env.mock_auths(&[MockAuth {
|
|
65
65
|
address: &setup.owner,
|
|
66
66
|
invoke: &MockAuthInvoke {
|
|
@@ -127,7 +127,7 @@ fn test_set_msg_inspector_requires_owner() {
|
|
|
127
127
|
// Deploy a passing inspector
|
|
128
128
|
let inspector_address = env.register(PassingInspector, ());
|
|
129
129
|
|
|
130
|
-
// Non-owner (
|
|
130
|
+
// Non-owner (not the authorizer) tries to set the inspector
|
|
131
131
|
let non_owner = Address::generate(&env);
|
|
132
132
|
env.mock_auths(&[MockAuth {
|
|
133
133
|
address: &non_owner,
|
|
@@ -139,7 +139,7 @@ fn test_set_msg_inspector_requires_owner() {
|
|
|
139
139
|
},
|
|
140
140
|
}]);
|
|
141
141
|
|
|
142
|
-
// This should panic because non_owner
|
|
142
|
+
// This should panic because non_owner is not the authorizer
|
|
143
143
|
setup.oft.set_msg_inspector(&Some(inspector_address), &non_owner);
|
|
144
144
|
}
|
|
145
145
|
|
|
@@ -8,7 +8,7 @@ use crate::{
|
|
|
8
8
|
types::{OFTReceipt, SendParam},
|
|
9
9
|
};
|
|
10
10
|
use endpoint_v2::{LayerZeroReceiverClient, MessagingFee, MessagingParams, MessagingReceipt, Origin};
|
|
11
|
-
use oapp::oapp_core::
|
|
11
|
+
use oapp::oapp_core::OAppCoreClient;
|
|
12
12
|
use soroban_sdk::{
|
|
13
13
|
address_payload::AddressPayload,
|
|
14
14
|
bytes, contract, contractimpl, log, symbol_short,
|
|
@@ -16,7 +16,6 @@ use soroban_sdk::{
|
|
|
16
16
|
token::{StellarAssetClient, TokenClient},
|
|
17
17
|
Address, Bytes, BytesN, Env, IntoVal, String, Symbol,
|
|
18
18
|
};
|
|
19
|
-
use utils::rbac::grant_role_no_auth;
|
|
20
19
|
|
|
21
20
|
// ==================== Constants ====================
|
|
22
21
|
|
|
@@ -100,20 +99,6 @@ pub fn create_origin(src_eid: u32, sender: &BytesN<32>, nonce: u64) -> Origin {
|
|
|
100
99
|
Origin { src_eid, sender: sender.clone(), nonce }
|
|
101
100
|
}
|
|
102
101
|
|
|
103
|
-
fn grant_oapp_admin(env: &Env, contract: &Address, owner: &Address) {
|
|
104
|
-
let role = Symbol::new(env, oapp::oapp_core::OAPP_MANAGER_ROLE);
|
|
105
|
-
env.mock_auths(&[MockAuth {
|
|
106
|
-
address: owner,
|
|
107
|
-
invoke: &MockAuthInvoke {
|
|
108
|
-
contract,
|
|
109
|
-
fn_name: "grant_role",
|
|
110
|
-
args: (owner, &role, owner).into_val(env),
|
|
111
|
-
sub_invokes: &[],
|
|
112
|
-
},
|
|
113
|
-
}]);
|
|
114
|
-
utils::rbac::RoleBasedAccessControlClient::new(env, contract).grant_role(owner, &role, owner);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
102
|
// ==================== Test OFT Contracts ====================
|
|
118
103
|
|
|
119
104
|
mod test_mint_burn_oft {
|
|
@@ -613,16 +598,6 @@ impl<'a> OFTTestSetupBuilder<'a> {
|
|
|
613
598
|
OFTTestSetup::mint_to(env, &owner, &native_token, &owner, INITIAL_MINT_AMOUNT);
|
|
614
599
|
OFTTestSetup::mint_to(env, &owner, &zro_token, &owner, INITIAL_MINT_AMOUNT);
|
|
615
600
|
|
|
616
|
-
// Grant OAPP_MANAGER_ROLE to owner so they can call set_peer, set_delegate, set_msg_inspector, etc.
|
|
617
|
-
env.as_contract(&oft_address, || {
|
|
618
|
-
grant_role_no_auth(
|
|
619
|
-
env,
|
|
620
|
-
&owner,
|
|
621
|
-
&Symbol::new(env, OAPP_MANAGER_ROLE),
|
|
622
|
-
&owner,
|
|
623
|
-
);
|
|
624
|
-
});
|
|
625
|
-
|
|
626
601
|
// Setup based on OFT type
|
|
627
602
|
match oft_type {
|
|
628
603
|
OFTType::MintBurn => {
|
|
@@ -676,8 +651,6 @@ impl<'a> OFTTestSetup<'a> {
|
|
|
676
651
|
}
|
|
677
652
|
|
|
678
653
|
pub fn set_peer(&self, eid: u32, peer: &BytesN<32>) {
|
|
679
|
-
grant_oapp_admin(self.env, &self.oft.address, &self.owner);
|
|
680
|
-
|
|
681
654
|
let peer_option = Some(peer.clone());
|
|
682
655
|
self.env.mock_auths(&[MockAuth {
|
|
683
656
|
address: &self.owner,
|
|
@@ -14,6 +14,9 @@ use soroban_sdk::{assert_with_error, contractevent, Address, Env, Symbol, Vec};
|
|
|
14
14
|
/// Maximum number of roles that can exist simultaneously.
|
|
15
15
|
pub const MAX_ROLES: u32 = 256;
|
|
16
16
|
|
|
17
|
+
/// Role representing the contract's authorizer.
|
|
18
|
+
pub const AUTHORIZER: &str = "AUTHORIZER";
|
|
19
|
+
|
|
17
20
|
// ===========================================================================
|
|
18
21
|
// Events
|
|
19
22
|
// ===========================================================================
|
|
@@ -225,14 +228,21 @@ pub trait RoleBasedAccessControl: Auth {
|
|
|
225
228
|
|
|
226
229
|
/// Ensures the caller has the specified role.
|
|
227
230
|
///
|
|
231
|
+
/// When `role` matches [`AUTHORIZER`], verifies that `caller` is the contract's
|
|
232
|
+
/// authorizer (via [`Auth::authorizer`]) instead of checking RBAC storage.
|
|
233
|
+
///
|
|
228
234
|
/// # Arguments
|
|
229
235
|
/// * `role` - The role to check the caller for.
|
|
230
236
|
/// * `caller` - The account that is being checked. Must have the role.
|
|
231
237
|
///
|
|
232
238
|
/// # Errors
|
|
233
|
-
/// * `Unauthorized` - If the caller does not have the role.
|
|
234
|
-
pub fn ensure_role(env: &Env, role: &Symbol, caller: &Address) {
|
|
235
|
-
|
|
239
|
+
/// * `Unauthorized` - If the caller does not have the role (or is not the authorizer).
|
|
240
|
+
pub fn ensure_role<T: RoleBasedAccessControl>(env: &Env, role: &Symbol, caller: &Address) {
|
|
241
|
+
if *role == Symbol::new(env, AUTHORIZER) {
|
|
242
|
+
assert_with_error!(env, T::authorizer(env).as_ref() == Some(caller), RbacError::Unauthorized);
|
|
243
|
+
} else {
|
|
244
|
+
assert_with_error!(env, T::has_role(env, caller, role).is_some(), RbacError::Unauthorized);
|
|
245
|
+
}
|
|
236
246
|
}
|
|
237
247
|
|
|
238
248
|
/// Grants a role to an account without auth check.
|
|
@@ -37,7 +37,7 @@ impl RbacTestContract {
|
|
|
37
37
|
// ----------------------------
|
|
38
38
|
|
|
39
39
|
pub fn rbac_ensure_role(env: &Env, role: Symbol, caller: Address) {
|
|
40
|
-
ensure_role(env, &role, &caller);
|
|
40
|
+
ensure_role::<Self>(env, &role, &caller);
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
pub fn rbac_rm_role_admin_no_auth(env: &Env, role: Symbol) {
|
package/package.json
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@layerzerolabs/protocol-stellar-v2",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.49",
|
|
4
4
|
"private": false,
|
|
5
5
|
"license": "LZBL-1.2",
|
|
6
6
|
"devDependencies": {
|
|
7
7
|
"@types/node": "^22.18.6",
|
|
8
8
|
"tsx": "^4.19.3",
|
|
9
9
|
"typescript": "^5.8.2",
|
|
10
|
-
"@layerzerolabs/stellar-ts-bindings-gen": "0.2.
|
|
11
|
-
"@layerzerolabs/common-node-utils": "0.2.
|
|
12
|
-
"@layerzerolabs/vm-tooling-stellar": "0.2.
|
|
10
|
+
"@layerzerolabs/stellar-ts-bindings-gen": "0.2.49",
|
|
11
|
+
"@layerzerolabs/common-node-utils": "0.2.49",
|
|
12
|
+
"@layerzerolabs/vm-tooling-stellar": "0.2.49"
|
|
13
13
|
},
|
|
14
14
|
"publishConfig": {
|
|
15
15
|
"access": "restricted",
|