-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
commit ab487f4 Author: MartinquaXD <[email protected]> Date: Sat Jun 1 08:44:04 2024 +0200 Fix clippy warning commit 576cf19 Author: MartinquaXD <[email protected]> Date: Sat Jun 1 08:39:19 2024 +0200 Implemented suggested changes commit 60650da Author: Mateo <[email protected]> Date: Fri May 31 18:22:47 2024 +0200 Remove log from the mock solver commit 859380a Author: Mateo <[email protected]> Date: Fri May 31 15:37:34 2024 +0200 Linter commit 4a67faf Author: Mateo <[email protected]> Date: Fri May 31 15:22:14 2024 +0200 Implement e2e tests for JIT orders commit debfa39 Author: Dusan Stanivukovic <[email protected]> Date: Fri May 31 09:37:51 2024 +0200 Circuit breaker remove solver (#2705) # Description Related to #2667 POC implementation for using "Roles" safe module to grant special role to an EOA to sign and execute "removeSolver" function on behalf of the gpv2_authenticator manager/owner safe. Need to add tests to see if this actually works. # Changes <!-- List of detailed changes (how the change is accomplished) --> - [ ] Added `Roles` smart contract - [ ] Added EOA account as configuration - [ ] Implemented `remove_solver` function ## How to test todo --------- Co-authored-by: Mateo <[email protected]> Co-authored-by: Mateo-mro <[email protected]>
- Loading branch information
1 parent
6c0e8ff
commit bbebb5e
Showing
15 changed files
with
591 additions
and
32 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
use { | ||
crate::{ | ||
domain::{self, eth}, | ||
infra::blockchain::{ | ||
contracts::{deployment_address, Contracts}, | ||
ChainId, | ||
}, | ||
}, | ||
ethcontract::{dyns::DynWeb3, GasPrice}, | ||
}; | ||
|
||
#[allow(dead_code)] | ||
#[derive(Debug, Clone)] | ||
pub struct Manager { | ||
/// The authenticator contract that decides which solver is allowed to | ||
/// submit settlements. | ||
authenticator: contracts::GPv2AllowListAuthentication, | ||
/// The safe module that is used to provide special role to EOA. | ||
authenticator_role: contracts::Roles, | ||
/// The EOA that is allowed to remove solvers. | ||
authenticator_eoa: ethcontract::Account, | ||
} | ||
|
||
impl Manager { | ||
/// Creates an authenticator which can remove solvers from the allow-list | ||
pub async fn new( | ||
web3: DynWeb3, | ||
chain: ChainId, | ||
contracts: Contracts, | ||
authenticator_pk: eth::H256, | ||
) -> Self { | ||
let authenticator_role = contracts::Roles::at( | ||
&web3, | ||
deployment_address(contracts::Roles::raw_contract(), &chain).expect("roles address"), | ||
); | ||
|
||
Self { | ||
authenticator: contracts.authenticator().clone(), | ||
authenticator_role, | ||
authenticator_eoa: ethcontract::Account::Offline( | ||
ethcontract::PrivateKey::from_raw(authenticator_pk.0).unwrap(), | ||
None, | ||
), | ||
} | ||
} | ||
|
||
/// Fire and forget: Removes solver from the allow-list in the authenticator | ||
/// contract. This solver will no longer be able to settle. | ||
#[allow(dead_code)] | ||
fn remove_solver(&self, solver: domain::eth::Address) { | ||
let calldata = self | ||
.authenticator | ||
.methods() | ||
.remove_solver(solver.into()) | ||
.tx | ||
.data | ||
.expect("missing calldata"); | ||
let authenticator_eoa = self.authenticator_eoa.clone(); | ||
let authenticator_address = self.authenticator.address(); | ||
let authenticator_role = self.authenticator_role.clone(); | ||
tokio::task::spawn(async move { | ||
// This value comes from the TX posted in the issue: https://github.com/cowprotocol/services/issues/2667 | ||
let mut byte_array = [0u8; 32]; | ||
byte_array[31] = 1; | ||
authenticator_role | ||
.methods() | ||
.exec_transaction_with_role( | ||
authenticator_address, | ||
0.into(), | ||
ethcontract::Bytes(calldata.0), | ||
0, | ||
ethcontract::Bytes(byte_array), | ||
true, | ||
) | ||
.from(authenticator_eoa) | ||
.gas_price(GasPrice::Eip1559 { | ||
// These are arbitrary high numbers that should be enough for a tx to be settled | ||
// anytime. | ||
max_fee_per_gas: 1000.into(), | ||
max_priority_fee_per_gas: 5.into(), | ||
}) | ||
.send() | ||
.await | ||
.inspect_err(|err| tracing::error!(?solver, ?err, "failed to remove the solver")) | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.