feat: Add ChainId model
Remove to_chain_id helper method --- don't change below this line --- ENG-4081 Took 28 minutes
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
use std::{str::FromStr, sync::Arc};
|
||||
|
||||
use alloy::{
|
||||
primitives::{aliases::U48, Address, Bytes as AlloyBytes, ChainId, TxKind, U160, U256},
|
||||
primitives::{aliases::U48, Address, Bytes as AlloyBytes, TxKind, U160, U256},
|
||||
providers::{Provider, RootProvider},
|
||||
rpc::types::{TransactionInput, TransactionRequest},
|
||||
signers::{local::PrivateKeySigner, SignerSync},
|
||||
@@ -20,7 +20,8 @@ use crate::encoding::{
|
||||
errors::EncodingError,
|
||||
evm::{
|
||||
approvals::protocol_approvals_manager::get_client,
|
||||
utils::{biguint_to_u256, bytes_to_address, encode_input, to_chain_id},
|
||||
models::ChainId,
|
||||
utils::{biguint_to_u256, bytes_to_address, encode_input},
|
||||
},
|
||||
};
|
||||
|
||||
@@ -62,7 +63,7 @@ sol! {
|
||||
#[allow(dead_code)]
|
||||
impl Permit2 {
|
||||
pub fn new(signer_pk: String, chain: Chain) -> Result<Self, EncodingError> {
|
||||
let chain_id = to_chain_id(chain)?;
|
||||
let chain_id = ChainId::from(chain);
|
||||
let runtime = Runtime::new()
|
||||
.map_err(|_| EncodingError::FatalError("Failed to create runtime".to_string()))?;
|
||||
let client = runtime.block_on(get_client())?;
|
||||
@@ -145,7 +146,7 @@ impl Permit2 {
|
||||
|
||||
let domain = eip712_domain! {
|
||||
name: "Permit2",
|
||||
chain_id: self.chain_id,
|
||||
chain_id: self.chain_id.id(),
|
||||
verifying_contract: self.address,
|
||||
};
|
||||
let hash = permit_single.eip712_signing_hash(&domain);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
pub mod approvals;
|
||||
mod models;
|
||||
mod router_encoder;
|
||||
mod strategy_encoder;
|
||||
mod swap_encoder;
|
||||
|
||||
20
src/encoding/evm/models.rs
Normal file
20
src/encoding/evm/models.rs
Normal file
@@ -0,0 +1,20 @@
|
||||
use tycho_core::models::Chain;
|
||||
|
||||
pub struct ChainId(u64);
|
||||
|
||||
impl ChainId {
|
||||
pub fn id(&self) -> u64 {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Chain> for ChainId {
|
||||
fn from(chain: Chain) -> Self {
|
||||
match chain {
|
||||
Chain::Ethereum => ChainId(1),
|
||||
Chain::ZkSync => ChainId(324),
|
||||
Chain::Arbitrum => ChainId(42161),
|
||||
Chain::Starknet => ChainId(0),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
use alloy_primitives::{aliases::U24, Address, Keccak256, U256};
|
||||
use alloy_sol_types::SolValue;
|
||||
use num_bigint::BigUint;
|
||||
use tycho_core::{models::Chain, Bytes};
|
||||
use tycho_core::Bytes;
|
||||
|
||||
use crate::encoding::errors::EncodingError;
|
||||
|
||||
@@ -65,10 +65,3 @@ pub fn percentage_to_uint24(percentage: f64) -> U24 {
|
||||
let scaled = (percentage / 100.0) * (MAX_UINT24 as f64);
|
||||
U24::from(scaled.round())
|
||||
}
|
||||
|
||||
pub fn to_chain_id(chain: Chain) -> Result<u64, EncodingError> {
|
||||
match chain {
|
||||
Chain::Ethereum => Ok(1),
|
||||
_ => Err(EncodingError::FatalError("Unsupported chain".to_string())),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user