Skip to content

Commit

Permalink
Add encoding handlers for ManagerWithMerkleVerification ABI
Browse files Browse the repository at this point in the history
  • Loading branch information
cbrit committed Nov 14, 2024
1 parent 1c8d39b commit 8a2a4f5
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/cellars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ pub type CachePriceRouterArgs = (bool, u32, Option<String>);

pub(crate) mod aave_v2_stablecoin;
pub(crate) mod adaptors;
pub(crate) mod boring_vault_manager_with_merkle_verification;
pub(crate) mod cellar_v1;
pub(crate) mod cellar_v2;
pub(crate) mod cellar_v2_2;
Expand Down
56 changes: 56 additions & 0 deletions src/cellars/boring_vault_manager_with_merkle_verification.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
use ethers::{abi::AbiEncode, contract::EthCall};
use steward_proto::proto::boring_vault_manager_with_merkle_verification::Function;

use crate::{
abi::adaptors::boring_vault::manager_with_merkle_verification::{
ManagerWithMerkleVerificationCalls, PauseCall, SetManageRootCall, UnpauseCall,
},
error::{Error, ErrorKind},
utils::sp_call_parse_address,
};

use super::log_cellar_call;

const CELLAR_NAME: &str = "ManagerWithMerkleVerification";

pub fn get_encoded_call(function: Function, cellar_id: String) -> Result<Vec<u8>, Error> {
get_call(function, cellar_id).map(|call| call.encode())
}

pub fn get_call(
function: Function,
cellar_id: String,
) -> Result<ManagerWithMerkleVerificationCalls, Error> {
match function {
Function::SetManageRoot(params) => {
log_cellar_call(CELLAR_NAME, &SetManageRootCall::function_name(), &cellar_id);

let strategist = sp_call_parse_address(params.strategist)?;
let manage_root = hex::decode(params.manage_root)
.map_err(|e| {
ErrorKind::SPCallError.context(format!("failed to decode manage_root: {e}"))
})?
.try_into()
.map_err(|_| {
ErrorKind::SPCallError.context("manage_root must be 32 bytes".to_string())
})?;

let call = SetManageRootCall {
strategist,
manage_root,
};

Ok(ManagerWithMerkleVerificationCalls::SetManageRoot(call))
}
Function::Pause(_) => {
log_cellar_call(CELLAR_NAME, &PauseCall::function_name(), &cellar_id);
let call = PauseCall {};
Ok(ManagerWithMerkleVerificationCalls::Pause(call))
}
Function::Unpause(_) => {
log_cellar_call(CELLAR_NAME, &UnpauseCall::function_name(), &cellar_id);
let call = UnpauseCall {};
Ok(ManagerWithMerkleVerificationCalls::Unpause(call))
}
}
}
15 changes: 14 additions & 1 deletion src/cork.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ use tonic::{self, async_trait, Code, Request, Response, Status};
use crate::cellars::to_checksum_address;
use crate::server::handle_authorization;
use crate::{
cellars::{self, aave_v2_stablecoin, cellar_v1, cellar_v2, cellar_v2_2, cellar_v2_5},
cellars::{
self, aave_v2_stablecoin, boring_vault_manager_with_merkle_verification, cellar_v1,
cellar_v2, cellar_v2_2, cellar_v2_5,
},
error::{
Error,
ErrorKind::{self, *},
Expand Down Expand Up @@ -147,6 +150,16 @@ pub fn get_encoded_call(request: ScheduleRequest) -> Result<Vec<u8>, Error> {

cellar_v2_5::get_encoded_call(call.call_type.unwrap(), request.cellar_id)
}
BoringVaultManagerWithMerkleVerification(call) => {
if call.function.is_none() {
return Err(ErrorKind::Http.context("empty function data").into());
}

boring_vault_manager_with_merkle_verification::get_encoded_call(
call.function.unwrap(),
request.cellar_id,
)
}
}
}

Expand Down

0 comments on commit 8a2a4f5

Please sign in to comment.