feat: Add evm feature gate
- Move all evm code inside evm directory - StrategyEncoder: - Kept StrategyEncoder trait but created a new one: EVMStrategyEncoder to implement encode_protocol_header (that is evm specific). - All StrategyEncoders implement both traits now - Renamed DefaultStrategySelector -> EVMStrategySelector - RouterEncoder: - Created a RouterEncoder trait and a EVMRouterEncoder that implements it - Moved utils inside evm directory as well - Renamed config.json -> executor_addresses.json and moved it to a higher config directory - Make alloy optional and dependent on the evm feature gate --- don't change below this line --- ENG-4075 <#DTT#>
This commit is contained in:
49
src/encoding/evm/approvals/protocol_approvals_manager.rs
Normal file
49
src/encoding/evm/approvals/protocol_approvals_manager.rs
Normal file
@@ -0,0 +1,49 @@
|
||||
use std::{env, sync::Arc};
|
||||
|
||||
use alloy::{
|
||||
providers::{ProviderBuilder, RootProvider},
|
||||
transports::BoxTransport,
|
||||
};
|
||||
use alloy_primitives::Address;
|
||||
use dotenv::dotenv;
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub struct ProtocolApprovalsManager {
|
||||
client: Arc<RootProvider<BoxTransport>>,
|
||||
}
|
||||
impl ProtocolApprovalsManager {
|
||||
pub fn new() -> Self {
|
||||
Self { client: get_client() }
|
||||
}
|
||||
pub async fn approval_needed(
|
||||
&self,
|
||||
_token: Address,
|
||||
_spender_address: Address,
|
||||
_router_address: Address,
|
||||
) -> bool {
|
||||
todo!()
|
||||
// should be something like
|
||||
// let allowance = self
|
||||
// .client
|
||||
// .call(token, "allowance(address,address)(uint256)", (router_address,
|
||||
// spender_address)) .await;
|
||||
//
|
||||
// allowance == U256::ZERO // If allowance is 0, approval is needed
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_client() -> Arc<RootProvider<BoxTransport>> {
|
||||
dotenv().ok();
|
||||
let eth_rpc_url = env::var("ETH_RPC_URL").expect("Missing ETH_RPC_URL in environment");
|
||||
let runtime = tokio::runtime::Handle::try_current()
|
||||
.is_err()
|
||||
.then(|| tokio::runtime::Runtime::new().unwrap())
|
||||
.unwrap();
|
||||
let client = runtime.block_on(async {
|
||||
ProviderBuilder::new()
|
||||
.on_builtin(ð_rpc_url)
|
||||
.await
|
||||
.unwrap()
|
||||
});
|
||||
Arc::new(client)
|
||||
}
|
||||
Reference in New Issue
Block a user