Skip to content

Commit

Permalink
no need for db modifications now
Browse files Browse the repository at this point in the history
  • Loading branch information
1010adigupta committed Mar 27, 2024
1 parent 3c01577 commit 5d5a6e7
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use std::{
str::{from_utf8, FromStr},
str::from_utf8,
sync::Arc,
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
use std::sync::Arc;
use std::{
str::{from_utf8, FromStr},
sync::Arc,
};

use alloy_primitives::{hex, Bytes, FixedBytes, U256};
use alloy_sol_macro::sol;
use alloy_sol_types::SolCall;
use brontes_types::traits::TracingProvider;
use futures::TryFutureExt;
use reth_primitives::U256;
use reth_primitives::{Address, Bytecode, StorageValue};
use reth_rpc_types::{request::TransactionInput, TransactionRequest};

use super::CurvePool;
Expand Down Expand Up @@ -33,6 +37,24 @@ sol!(
address[] memory base_pools) returns(PoolData[]);
);

// Positions of stable pool immutables in the bytecode
const BASE_POOL_RANGE: std::ops::Range<usize> = "4542..4542 + 40";
const ORIGINAL_RATES_RANGE: std::ops::Range<usize> = "9128..9128 + 40";

pub fn extract_curve_stable_pool_immutables(bytecode: Bytes) -> (Address, Vec<U256>) {
// Slices
let base_pool_slice = &bytecode[BASE_POOL_RANGE];
let original_rates_slice = &bytecode[ORIGINAL_RATES_RANGE];

let base_pool = from_utf8(base_pool_slice).unwrap();
let original_rates = from_utf8(original_rates_slice).unwrap();

let base_pool = Address::from_str(base_pool).unwrap();
let original_pool_rates = U256::from_str_radix(future_a_gamma_time, 16).unwrap();

(base_pool, original_pool_rates)
}

fn populate_pool_data(mut pool: CurvePool, pool_data: PoolData) -> CurvePool {
pool.tokens = pool_data.tokens;
pool.token_decimals = pool_data.tokenDecimals;
Expand All @@ -49,6 +71,18 @@ pub async fn get_curve_pool_data_batch_request<M: TracingProvider>(
block: Option<u64>,
middleware: Arc<M>,
) -> Result<(), AmmError> {

// Fetch pool bytecode
let pool_bytecode: Option<Bytecode> =
middleware.get_bytecode(block, pool.address).await?;

// Extract base_pool, original_pool_rates from bytecode
if let Some(pool_bytecode) = pool_bytecode {
let pool_bytecode = Bytes::from(hex::encode_prefixed(pool_bytecode.bytecode.as_ref()));
let (base_pool, original_pool_rates) = extract_curve_stable_pool_immutables(pool_bytecode);
pool.base_pool = base_pool;
pool.rates = original_pool_rates;
}
let mut bytecode = IGetCurveV2MetapoolDataBatchRequest::BYTECODE.to_vec();
data_constructorCall::new((
vec![pool.address],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,7 @@ impl CurvePool {
fee: U256::ZERO,
admin_fee: U256::ZERO,
a_value: U256::ZERO,
base_pool: pool_details.curve_base_pool.unwrap_or_default(),
rates: pool_details.curve_original_pool_rates.unwrap_or_default(),
rates: Vec::new(),
..Default::default()
};

Expand Down

0 comments on commit 5d5a6e7

Please sign in to comment.