Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added only_admin anotation for Chain-Factory endpoints #200

Merged
merged 2 commits into from
Dec 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions chain-factory/src/factory.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use multiversx_sc::imports::*;
use multiversx_sc_modules::only_admin;
use proxies::{
chain_config_proxy::ChainConfigContractProxy,
enshrine_esdt_safe_proxy::EnshrineEsdtSafeProxy,
Expand All @@ -9,8 +10,8 @@ use transaction::StakeMultiArg;
multiversx_sc::derive_imports!();

#[multiversx_sc::module]
pub trait FactoryModule {
#[only_owner]
pub trait FactoryModule: only_admin::OnlyAdminModule {
#[only_admin]
#[endpoint(deploySovereignChainConfigContract)]
fn deploy_sovereign_chain_config_contract(
&self,
Expand Down Expand Up @@ -39,7 +40,7 @@ pub trait FactoryModule {
.sync_call()
}

#[only_owner]
#[only_admin]
#[endpoint(deployHeaderVerifier)]
fn deploy_header_verifier(
&self,
Expand All @@ -58,7 +59,7 @@ pub trait FactoryModule {
.sync_call()
}

#[only_owner]
#[only_admin]
#[endpoint(deployEnshrineEsdtSafe)]
fn deploy_enshrine_esdt_safe(
&self,
Expand All @@ -85,7 +86,7 @@ pub trait FactoryModule {
.sync_call()
}

#[only_owner]
#[only_admin]
#[endpoint(deployFeeMarket)]
fn deploy_fee_market(
&self,
Expand All @@ -105,7 +106,7 @@ pub trait FactoryModule {
.sync_call()
}

#[only_owner]
#[only_admin]
#[endpoint(completeSetupPhase)]
fn complete_setup_phase(&self, _contract_address: ManagedAddress) {
// TODO: will have to call each contract's endpoint to finish setup phase
Expand Down
9 changes: 8 additions & 1 deletion chain-factory/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,24 +1,31 @@
#![no_std]

use multiversx_sc_modules::only_admin;

multiversx_sc::imports!();

pub mod factory;

#[multiversx_sc::contract]
pub trait ChainFactoryContract: factory::FactoryModule + utils::UtilsModule {
pub trait ChainFactoryContract:
factory::FactoryModule + utils::UtilsModule + only_admin::OnlyAdminModule
{
#[init]
fn init(
&self,
sovereign_forge_address: ManagedAddress,
chain_config_template: ManagedAddress,
header_verifier_template: ManagedAddress,
cross_chain_operation_template: ManagedAddress,
fee_market_template: ManagedAddress,
) {
self.require_sc_address(&sovereign_forge_address);
self.require_sc_address(&chain_config_template);
self.require_sc_address(&header_verifier_template);
self.require_sc_address(&cross_chain_operation_template);
self.require_sc_address(&fee_market_template);

self.add_admin(sovereign_forge_address);
self.chain_config_template().set(chain_config_template);
self.header_verifier_template()
.set(header_verifier_template);
Expand Down
3 changes: 2 additions & 1 deletion chain-factory/tests/chain_factory_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ impl ChainFactoryTestState {
.from(OWNER)
.typed(ChainFactoryContractProxy)
.init(
CONFIG_ADDRESS,
CONFIG_ADDRESS,
FACTORY_ADDRESS,
FACTORY_ADDRESS,
Expand All @@ -88,7 +89,7 @@ impl ChainFactoryTestState {
let transaction = self
.world
.tx()
.from(OWNER)
.from(CONFIG_ADDRESS)
.to(FACTORY_ADDRESS)
.typed(ChainFactoryContractProxy)
.deploy_sovereign_chain_config_contract(
Expand Down
8 changes: 6 additions & 2 deletions chain-factory/wasm-chain-factory-full/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

// Init: 1
// Upgrade: 1
// Endpoints: 5
// Endpoints: 9
// Async Callback (empty): 1
// Total number of exported functions: 8
// Total number of exported functions: 12

#![no_std]

Expand All @@ -25,6 +25,10 @@ multiversx_sc_wasm_adapter::endpoints! {
deployEnshrineEsdtSafe => deploy_enshrine_esdt_safe
deployFeeMarket => deploy_fee_market
completeSetupPhase => complete_setup_phase
isAdmin => is_admin
addAdmin => add_admin
removeAdmin => remove_admin
getAdmins => admins
)
}

Expand Down
8 changes: 6 additions & 2 deletions chain-factory/wasm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

// Init: 1
// Upgrade: 1
// Endpoints: 5
// Endpoints: 9
// Async Callback (empty): 1
// Total number of exported functions: 8
// Total number of exported functions: 12

#![no_std]

Expand All @@ -25,6 +25,10 @@ multiversx_sc_wasm_adapter::endpoints! {
deployEnshrineEsdtSafe => deploy_enshrine_esdt_safe
deployFeeMarket => deploy_fee_market
completeSetupPhase => complete_setup_phase
isAdmin => is_admin
addAdmin => add_admin
removeAdmin => remove_admin
getAdmins => admins
)
}

Expand Down
59 changes: 55 additions & 4 deletions common/proxies/src/chain_factory_proxy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,19 @@ where
Arg1: ProxyArg<ManagedAddress<Env::Api>>,
Arg2: ProxyArg<ManagedAddress<Env::Api>>,
Arg3: ProxyArg<ManagedAddress<Env::Api>>,
Arg4: ProxyArg<ManagedAddress<Env::Api>>,
>(
self,
chain_config_template: Arg0,
header_verifier_template: Arg1,
cross_chain_operation_template: Arg2,
fee_market_template: Arg3,
sovereign_forge_address: Arg0,
chain_config_template: Arg1,
header_verifier_template: Arg2,
cross_chain_operation_template: Arg3,
fee_market_template: Arg4,
) -> TxTypedDeploy<Env, From, NotPayable, Gas, ()> {
self.wrapped_tx
.payment(NotPayable)
.raw_deploy()
.argument(&sovereign_forge_address)
.argument(&chain_config_template)
.argument(&header_verifier_template)
.argument(&cross_chain_operation_template)
Expand Down Expand Up @@ -179,4 +182,52 @@ where
.argument(&_contract_address)
.original_result()
}

pub fn is_admin<
Arg0: ProxyArg<ManagedAddress<Env::Api>>,
>(
self,
address: Arg0,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, bool> {
self.wrapped_tx
.payment(NotPayable)
.raw_call("isAdmin")
.argument(&address)
.original_result()
}

pub fn add_admin<
Arg0: ProxyArg<ManagedAddress<Env::Api>>,
>(
self,
address: Arg0,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, ()> {
self.wrapped_tx
.payment(NotPayable)
.raw_call("addAdmin")
.argument(&address)
.original_result()
}

pub fn remove_admin<
Arg0: ProxyArg<ManagedAddress<Env::Api>>,
>(
self,
address: Arg0,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, ()> {
self.wrapped_tx
.payment(NotPayable)
.raw_call("removeAdmin")
.argument(&address)
.original_result()
}

pub fn admins(
self,
) -> TxTypedCall<Env, From, To, NotPayable, Gas, MultiValueEncoded<Env::Api, ManagedAddress<Env::Api>>> {
self.wrapped_tx
.payment(NotPayable)
.raw_call("getAdmins")
.original_result()
}
}
1 change: 1 addition & 0 deletions token-handler/tests/token_handler_blackbox_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ impl TokenHandlerTestState {
FACTORY_ADDRESS,
FACTORY_ADDRESS,
FACTORY_ADDRESS,
FACTORY_ADDRESS,
)
.code(FACTORY_CODE_PATH)
.new_address(FACTORY_ADDRESS)
Expand Down
Loading