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:
2
src/encoding/evm/approvals/mod.rs
Normal file
2
src/encoding/evm/approvals/mod.rs
Normal file
@@ -0,0 +1,2 @@
|
||||
pub mod permit2;
|
||||
pub mod protocol_approvals_manager;
|
||||
42
src/encoding/evm/approvals/permit2.rs
Normal file
42
src/encoding/evm/approvals/permit2.rs
Normal file
@@ -0,0 +1,42 @@
|
||||
use std::str::FromStr;
|
||||
|
||||
use alloy_primitives::U256;
|
||||
use tycho_core::Bytes;
|
||||
|
||||
use crate::encoding::user_approvals_manager::{Approval, UserApprovalsManager};
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub struct Permit2 {
|
||||
pub address: Bytes,
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
impl Permit2 {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
address: Bytes::from_str("0x000000000022D473030F116dDEE9F6B43aC78BA3")
|
||||
.expect("Permit2 address not valid"),
|
||||
}
|
||||
}
|
||||
fn get_allowance_data(
|
||||
&self,
|
||||
_user: Bytes,
|
||||
_router_address: Bytes,
|
||||
_token: Bytes,
|
||||
) -> (U256, u64, U256) {
|
||||
// get allowance data (if it exists) and the nonce
|
||||
// returns permitAmount, expiration, nonce
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
impl UserApprovalsManager for Permit2 {
|
||||
fn encode_approvals(&self, _approvals: Vec<Approval>) -> Vec<u8> {
|
||||
// calls get_allowance_data to get nonce
|
||||
// checks if we are not permitted already
|
||||
// puts data into a permitSingle struct if there is only 1 PermitDetails, if there are
|
||||
// several, use PermitBatch adds the nonce and the expiration (uniswap recommends
|
||||
// 30 days for expiration) signs data
|
||||
// returns encoded data
|
||||
todo!()
|
||||
}
|
||||
}
|
||||
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