Skip to content

Commit 6ba41dc

Browse files
committed
Migrate BalancerV2Authorizer to alloy (cowprotocol#3789)
1 parent 55c35e6 commit 6ba41dc

File tree

7 files changed

+33
-28
lines changed

7 files changed

+33
-28
lines changed

crates/contracts/build.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,8 @@ fn main() {
3131
// - https://doc.rust-lang.org/cargo/reference/build-scripts.html#cargorerun-if-changedpath
3232
println!("cargo:rerun-if-changed=build.rs");
3333

34-
generate_contract_with_config("BalancerV2Authorizer", |builder| {
35-
builder.contract_mod_override("balancer_v2_authorizer")
36-
});
34+
// Balancer addresses can be obtained from:
35+
// <https://github.com/balancer/balancer-subgraph-v2/blob/master/networks.yaml>
3736
generate_contract_with_config("BalancerV2Vault", |builder| {
3837
builder
3938
.contract_mod_override("balancer_v2_vault")

crates/contracts/src/alloy.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ crate::bindings!(GnosisSafeCompatibilityFallbackHandler);
4646
crate::bindings!(GnosisSafeProxy);
4747
crate::bindings!(GnosisSafeProxyFactory);
4848

49+
crate::bindings!(BalancerV2Authorizer);
4950
crate::bindings!(BalancerV2BasePool);
5051
crate::bindings!(BalancerV2BasePoolFactory);
5152
crate::bindings!(BalancerV2WeightedPool);

crates/contracts/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ macro_rules! include_contracts {
4949
}
5050

5151
include_contracts! {
52-
BalancerV2Authorizer;
5352
BalancerV2Vault;
5453
BalancerV3Vault;
5554
BalancerV3WeightedPool;

crates/contracts/src/vault.rs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
//! contract.
33
44
use {
5-
crate::{BalancerV2Authorizer, BalancerV2Vault},
6-
ethcontract::{Bytes, H160, common::FunctionExt as _, errors::MethodError, web3::signing},
5+
crate::{BalancerV2Vault, alloy::BalancerV2Authorizer},
6+
alloy::primitives::Address,
7+
ethcontract::{Bytes, H160, common::FunctionExt as _, web3::signing},
78
};
89

910
fn role_id(target: H160, function_name: &str) -> Bytes<[u8; 32]> {
@@ -23,19 +24,21 @@ fn role_id(target: H160, function_name: &str) -> Bytes<[u8; 32]> {
2324
}
2425

2526
pub async fn grant_required_roles(
26-
authorizer: &BalancerV2Authorizer,
27+
authorizer: &BalancerV2Authorizer::Instance,
2728
vault: H160,
2829
vault_relayer: H160,
29-
) -> Result<(), MethodError> {
30+
) -> Result<(), alloy::contract::Error> {
3031
authorizer
31-
.grant_roles(
32+
.grantRoles(
3233
vec![
33-
role_id(vault, "manageUserBalance"),
34-
role_id(vault, "batchSwap"),
34+
role_id(vault, "manageUserBalance").0.into(),
35+
role_id(vault, "batchSwap").0.into(),
3536
],
36-
vault_relayer,
37+
Address::from(vault_relayer.0),
3738
)
3839
.send()
40+
.await?
41+
.watch()
3942
.await?;
4043
Ok(())
4144
}

crates/driver/src/tests/setup/blockchain.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -272,19 +272,19 @@ impl Blockchain {
272272
.unwrap();
273273

274274
// Set up the settlement contract and related contracts.
275-
let vault_authorizer = wait_for(
276-
&web3,
277-
contracts::BalancerV2Authorizer::builder(&web3, main_trader_account.address())
278-
.from(main_trader_account.clone())
279-
.deploy(),
275+
let vault_authorizer = contracts::alloy::BalancerV2Authorizer::Instance::deploy_builder(
276+
web3.alloy.clone(),
277+
main_trader_account.address().into_alloy(),
280278
)
279+
.from(main_trader_account.address().into_alloy())
280+
.deploy()
281281
.await
282282
.unwrap();
283283
let vault = wait_for(
284284
&web3,
285285
contracts::BalancerV2Vault::builder(
286286
&web3,
287-
vault_authorizer.address(),
287+
vault_authorizer.into_legacy(),
288288
weth.address(),
289289
0.into(),
290290
0.into(),

crates/e2e/src/setup/deploy.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
use {
22
crate::deploy,
33
contracts::{
4-
BalancerV2Authorizer,
54
BalancerV2Vault,
65
CowAmmLegacyHelper,
76
GPv2AllowListAuthentication,
87
GPv2Settlement,
98
WETH9,
109
alloy::{
10+
BalancerV2Authorizer,
1111
CoWSwapEthFlow,
1212
FlashLoanRouter,
1313
HooksTrampoline,
@@ -18,7 +18,7 @@ use {
1818
},
1919
},
2020
ethcontract::{Address, H256, U256, errors::DeployError},
21-
ethrpc::alloy::conversions::IntoAlloy,
21+
ethrpc::alloy::conversions::{IntoAlloy, IntoLegacy},
2222
model::DomainSeparator,
2323
shared::ethrpc::Web3,
2424
};
@@ -135,11 +135,14 @@ impl Contracts {
135135

136136
let weth = deploy!(web3, WETH9());
137137

138-
let balancer_authorizer = deploy!(web3, BalancerV2Authorizer(admin));
138+
let balancer_authorizer =
139+
BalancerV2Authorizer::Instance::deploy(web3.alloy.clone(), admin.into_alloy())
140+
.await
141+
.unwrap();
139142
let balancer_vault = deploy!(
140143
web3,
141144
BalancerV2Vault(
142-
balancer_authorizer.address(),
145+
balancer_authorizer.address().into_legacy(),
143146
weth.address(),
144147
U256::from(0),
145148
U256::from(0),

crates/liquidity-driver/src/tests/setup/blockchain.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -272,19 +272,19 @@ impl Blockchain {
272272
.unwrap();
273273

274274
// Set up the settlement contract and related contracts.
275-
let vault_authorizer = wait_for(
276-
&web3,
277-
contracts::BalancerV2Authorizer::builder(&web3, main_trader_account.address())
278-
.from(main_trader_account.clone())
279-
.deploy(),
275+
let vault_authorizer = contracts::alloy::BalancerV2Authorizer::Instance::deploy_builder(
276+
web3.alloy.clone(),
277+
main_trader_account.address().into_alloy(),
280278
)
279+
.from(main_trader_account.address().into_alloy())
280+
.deploy()
281281
.await
282282
.unwrap();
283283
let vault = wait_for(
284284
&web3,
285285
contracts::BalancerV2Vault::builder(
286286
&web3,
287-
vault_authorizer.address(),
287+
vault_authorizer.into_legacy(),
288288
weth.address(),
289289
0.into(),
290290
0.into(),

0 commit comments

Comments
 (0)