Skip to content

Commit f0006f5

Browse files
committed
sync modules
1 parent ab9b083 commit f0006f5

File tree

2 files changed

+46
-20
lines changed

2 files changed

+46
-20
lines changed

packages/layerzero-v2/initia/contracts/endpoint_v2/sources/admin.move

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,19 @@ module endpoint_v2::admin {
33
use std::signer::address_of;
44

55
use endpoint_v2::msglib_manager;
6+
use endpoint_v2_common::universal_config::assert_layerzero_admin;
67

78
/// Register new message library
89
/// A library must be registered to be called by this endpoint. Once registered, it cannot be unregistered. The
910
/// library must be connected to the router node before it can be registered
1011
public entry fun register_library(account: &signer, lib: address) {
11-
assert_admin(address_of(move account));
12+
assert_layerzero_admin(address_of(move account));
1213
msglib_manager::register_library(lib);
1314
}
1415

1516
/// Sets the default sending message library for the given destination EID
1617
public entry fun set_default_send_library(account: &signer, dst_eid: u32, lib: address) {
17-
assert_admin(address_of(move account));
18+
assert_layerzero_admin(address_of(move account));
1819
msglib_manager::set_default_send_library(dst_eid, lib);
1920
}
2021

@@ -25,7 +26,7 @@ module endpoint_v2::admin {
2526
lib: address,
2627
grace_period: u64,
2728
) {
28-
assert_admin(address_of(move account));
29+
assert_layerzero_admin(address_of(move account));
2930
msglib_manager::set_default_receive_library(src_eid, lib, grace_period);
3031
}
3132

@@ -38,17 +39,12 @@ module endpoint_v2::admin {
3839
fallback_lib: address,
3940
expiry: u64,
4041
) {
41-
assert_admin(address_of(move account));
42+
assert_layerzero_admin(address_of(move account));
4243
msglib_manager::set_default_receive_library_timeout(src_eid, fallback_lib, expiry);
4344
}
4445

4546
// ==================================================== Helpers ===================================================
4647

47-
/// Internal function to assert that the caller is the endpoint admin
48-
inline fun assert_admin(admin: address) {
49-
assert!(admin == @layerzero_admin, EUNAUTHORIZED);
50-
}
51-
5248
#[test_only]
5349
/// Test-only function to initialize the endpoint and EID
5450
public fun initialize_endpoint_for_test() {

packages/layerzero-v2/initia/contracts/endpoint_v2_common/sources/universal_config.move

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
/// This module provides a groud truth for EID and ZRO Metadata address
1+
/// This module provides a ground truth for EID and ZRO Metadata address
22
module endpoint_v2_common::universal_config {
3+
use std::account;
34
use std::event::emit;
45
use std::fungible_asset::{Self, FungibleAsset, Metadata};
56
use std::object::{Self, Object};
@@ -13,6 +14,8 @@ module endpoint_v2_common::universal_config {
1314
friend endpoint_v2_common::universal_config_tests;
1415

1516
struct UniversalStore has key {
17+
// The LayerZero admin account
18+
layerzero_admin: address,
1619
// The EID for this endpoint
1720
eid: u32,
1821
// The ZRO metadata if it has been set
@@ -23,13 +26,15 @@ module endpoint_v2_common::universal_config {
2326

2427
/// Initialize the UniversalStore must be called by endpoint_v2_common
2528
public entry fun initialize(admin: &signer, eid: u32) acquires UniversalStore {
26-
assert_admin(address_of(move admin));
29+
assert_layerzero_admin(address_of(move admin));
2730
assert!(universal_store().eid == 0, EALREADY_INITIALIZED);
2831
universal_store_mut().eid = eid;
2932
}
3033

3134
fun init_module(account: &signer) {
3235
move_to(account, UniversalStore {
36+
// The initial admin address is @layerzero_admin, which can be transferred
37+
layerzero_admin: @layerzero_admin,
3338
eid: 0,
3439
zro_data: option::none(),
3540
zro_locked: false,
@@ -48,11 +53,20 @@ module endpoint_v2_common::universal_config {
4853
universal_store().eid
4954
}
5055

56+
/// Transfer the LayerZero admin to a new LayerZero admin address
57+
public entry fun transfer_layerzero_admin(account: &signer, new_admin: address) acquires UniversalStore {
58+
assert_layerzero_admin(address_of(move account));
59+
assert!(account::exists_at(new_admin), EINVALID_ACCOUNT_ADDRESS);
60+
assert!(new_admin != universal_store().layerzero_admin, ENO_CHANGE);
61+
universal_store_mut().layerzero_admin = new_admin;
62+
emit(LayerZeroAdminTransferred { new_admin });
63+
}
64+
5165
/// Set the ZRO address
5266
/// @param account: The layerzero admin account signer
5367
/// @param zro_address: The address of the ZRO metadata (@0x0 to unset)
5468
public entry fun set_zro_address(account: &signer, zro_address: address) acquires UniversalStore {
55-
assert_admin(address_of(move account));
69+
assert_layerzero_admin(address_of(move account));
5670
assert!(!universal_store().zro_locked, EZRO_ADDRESS_LOCKED);
5771

5872
if (zro_address == @0x0) {
@@ -76,7 +90,7 @@ module endpoint_v2_common::universal_config {
7690

7791
/// Lock the ZRO address so it can no longer be set or unset
7892
public entry fun lock_zro_address(account: &signer) acquires UniversalStore {
79-
assert_admin(address_of(move account));
93+
assert_layerzero_admin(address_of(move account));
8094
assert!(!universal_store().zro_locked, ENO_CHANGE);
8195
assert!(option::is_some(&universal_store().zro_data), EZRO_ADDRESS_NOT_SET);
8296

@@ -123,12 +137,17 @@ module endpoint_v2_common::universal_config {
123137
metadata == get_zro_metadata()
124138
}
125139

126-
// ==================================================== Helpers ===================================================
140+
#[view]
141+
public fun layerzero_admin(): address acquires UniversalStore {
142+
universal_store().layerzero_admin
143+
}
127144

128-
inline fun assert_admin(admin: address) {
129-
assert!(admin == @layerzero_admin, EUNAUTHORIZED);
145+
public fun assert_layerzero_admin(admin: address) acquires UniversalStore {
146+
assert!(admin == universal_store().layerzero_admin, EUNAUTHORIZED);
130147
}
131148

149+
// ==================================================== Helpers ===================================================
150+
132151
inline fun universal_store(): &UniversalStore { borrow_global(@endpoint_v2_common) }
133152

134153
inline fun universal_store_mut(): &mut UniversalStore { borrow_global_mut(@endpoint_v2_common) }
@@ -138,6 +157,11 @@ module endpoint_v2_common::universal_config {
138157

139158
// ==================================================== Events ====================================================
140159

160+
#[event]
161+
struct LayerZeroAdminTransferred has drop, store {
162+
new_admin: address,
163+
}
164+
141165
#[event]
142166
struct ZroMetadataSet has drop, store {
143167
zro_address: address,
@@ -146,6 +170,11 @@ module endpoint_v2_common::universal_config {
146170
#[event]
147171
struct ZroMetadataLocked has drop, store {}
148172

173+
#[test_only]
174+
public fun layerzero_admin_transferred_event(new_admin: address): LayerZeroAdminTransferred {
175+
LayerZeroAdminTransferred { new_admin }
176+
}
177+
149178
#[test_only]
150179
public fun zro_metadata_set(zro_address: address): ZroMetadataSet {
151180
ZroMetadataSet { zro_address }
@@ -160,8 +189,9 @@ module endpoint_v2_common::universal_config {
160189

161190
const EALREADY_INITIALIZED: u64 = 1;
162191
const EUNAUTHORIZED: u64 = 2;
163-
const EINVALID_ZRO_ADDRESS: u64 = 3;
164-
const ENO_CHANGE: u64 = 4;
165-
const EZRO_ADDRESS_NOT_SET: u64 = 5;
166-
const EZRO_ADDRESS_LOCKED: u64 = 6;
192+
const EINVALID_ACCOUNT_ADDRESS: u64 = 3;
193+
const EINVALID_ZRO_ADDRESS: u64 = 4;
194+
const ENO_CHANGE: u64 = 5;
195+
const EZRO_ADDRESS_NOT_SET: u64 = 6;
196+
const EZRO_ADDRESS_LOCKED: u64 = 7;
167197
}

0 commit comments

Comments
 (0)