Skip to content

Commit

Permalink
set treasury handler resource with signature
Browse files Browse the repository at this point in the history
  • Loading branch information
salman01zp committed Feb 5, 2024
1 parent a0aae3f commit 8140e1f
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 60 deletions.
41 changes: 0 additions & 41 deletions evm-test-utils/src/deployement_args.rs
Original file line number Diff line number Diff line change
@@ -1,42 +1 @@
use std::collections::HashMap;

use webb::evm::{
contract::protocol_solidity::{
erc20_preset_minter_pauser::ERC20PresetMinterPauserContract,
fungible_token_wrapper::FungibleTokenWrapperContract,
},
ethers::{signers::LocalWallet, types::Address},
};
use webb_proposals::TypedChainId;

#[derive(Clone, Debug, typed_builder::TypedBuilder)]
pub struct TokenConfig {
pub name: String,
pub symbol: String,
}

#[derive(Clone, Debug, typed_builder::TypedBuilder)]
pub struct ZkComponents {
pub wasm: Vec<u8>,
pub zkey: Vec<u8>,
pub witness_calculator: Vec<u8>,
}

#[derive(typed_builder::TypedBuilder)]
pub struct VAnchorBridgeDeploymentArgs<M> {
pub chain_ids: Vec<TypedChainId>,
#[builder(default)]
pub token_configs: HashMap<TypedChainId, TokenConfig>,
#[builder(default)]
pub webb_tokens: HashMap<TypedChainId, FungibleTokenWrapperContract<M>>,
pub vanchor_inputs: HashMap<TypedChainId, Address>,
pub deployers: HashMap<TypedChainId, LocalWallet>,
pub initial_governors: HashMap<TypedChainId, Address>,
}

#[derive(typed_builder::TypedBuilder)]
pub struct VBridgeDeploymentArgs<M> {
pub chains: Vec<crate::LocalEvmChain>,
pub tokens: Vec<ERC20PresetMinterPauserContract<M>>,
pub deployers: Vec<LocalWallet>,
}
12 changes: 11 additions & 1 deletion evm-test-utils/src/errors.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use webb::evm::ethers;
use webb::evm::ethers::{self, signers::WalletError};

#[derive(Debug, thiserror::Error)]
pub enum Error {
Expand Down Expand Up @@ -27,12 +27,22 @@ pub enum Error {
>,
>,
),
/// Wallet error.
#[error(transparent)]
WalletError(#[from] WalletError),
/// Initial Governor not defined for given chain
#[error("Initial Governor not defined for: {:?}", chain_id)]
NoInitialGovernor {
/// The chain id of the bridge.
chain_id: u32,
},

/// Deployer not set for given chain
#[error("Deployer wallet not set for: {:?}", chain_id)]
NoDeployer {
/// The chain id of the bridge.
chain_id: u32,
},
}

pub type Result<T> = std::result::Result<T, Error>;
58 changes: 40 additions & 18 deletions evm-test-utils/src/v_bridge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,19 @@ use std::collections::HashMap;

use webb::evm::{
contract::protocol_solidity::{
erc20_preset_minter_pauser::ERC20PresetMinterPauserContract,
fungible_token_wrapper::FungibleTokenWrapperContract, signature_bridge,
},
ethers::{contract::EthCall, signers::LocalWallet, types::Address},
ethers::{
contract::EthCall,
signers::{LocalWallet, Signer},
types::Address,
},
};

use crate::errors::{self, Result};
use webb_proposals::{
FunctionSignature, ResourceId, TargetSystem, TypedChainId,
evm::SetTreasuryHandlerProposal, FunctionSignature, Nonce, ProposalHeader,
ProposalTrait, ResourceId, TargetSystem, TypedChainId,
};

#[derive(Clone, Debug, typed_builder::TypedBuilder)]
Expand Down Expand Up @@ -44,6 +48,11 @@ impl<M> VAnchorBridgeDeployment<M> {
let chain_id = chain.chain_id();
let typed_chain_id = TypedChainId::Evm(chain_id);

let deployer = self
.deployers
.get(&typed_chain_id)
.ok_or_else(|| errors::Error::NoDeployer { chain_id })?;

let initial_governor = self
.initial_governors
.get(&typed_chain_id)
Expand All @@ -69,24 +78,37 @@ impl<M> VAnchorBridgeDeployment<M> {
chain.deploy_treasury(treasury_handler.address()).await?;

// Set treasury handler
let target_system = TargetSystem::ContractAddress(
treasury_handler.address().to_fixed_bytes(),
let bridge_target_system = TargetSystem::ContractAddress(
bridge.address().to_fixed_bytes(),
);
let resource = ResourceId::new(target_system, typed_chain_id);
let function_signature_bytes =
signature_bridge::AdminSetResourceWithSignatureCall::selector()
let resource_id =
ResourceId::new(bridge_target_system, typed_chain_id);
let function_sig_bytes =
signature_bridge::ExecuteProposalWithSignatureCall::selector()
.to_vec();
let mut buf = [0u8; 4];
buf.copy_from_slice(&function_signature_bytes);
let function_signature = FunctionSignature::from(buf);
bridge.admin_set_resource_with_signature(
resource_id,
function_sig,
nonce,
new_resource_id,
handler_address,
sig,
)
buf.copy_from_slice(&function_sig_bytes);
let function_sig = FunctionSignature::from(buf);
let nonce = bridge
.proposal_nonce()
.await?
.checked_add(1u64.into())
.unwrap_or_default();
let nonce = Nonce(nonce.as_u32());
let header = ProposalHeader::new(resource_id, function_sig, nonce);
let proposal = SetTreasuryHandlerProposal::new(
header,
treasury_handler.address().into(),
);

let signature = deployer.sign_message(proposal.to_vec()).await?;

bridge
.execute_proposal_with_signature(
proposal.to_vec().into(),
signature.to_vec().into(),
)
.await?;
}

Ok(())
Expand Down

0 comments on commit 8140e1f

Please sign in to comment.