Skip to content

Commit

Permalink
Withdrawal Timestamp added to indexer
Browse files Browse the repository at this point in the history
  • Loading branch information
akshay111meher committed Dec 17, 2024
1 parent fac7b51 commit c375a1e
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 2 deletions.
1 change: 1 addition & 0 deletions matching_engine/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ actix-web = {version = "4.5.1", features = ["rustls"] }
anyhow = "1.0.86"
bindings = { path = "../bindings", package = "foundry-contracts" }
binding_patches = { path = "../binding_patches", package = "binding_patches"}
derivative = "2.2"
dotenv = "0.15.0"
ecies = {version = "0.2.6", features = ["std"]}
env_logger = "0.11.3"
Expand Down
8 changes: 7 additions & 1 deletion matching_engine/src/generator_lib/generator_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,12 +318,18 @@ pub struct SlashingRecord {
pub source: super::delegation::Source,
}

#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Hash)]
use derivative::Derivative; // way to exclude timestamp from calculations
#[derive(Debug, Clone, Serialize, Deserialize, PartialOrd, Derivative)]
#[derivative(Hash, PartialEq, Eq)]
pub struct WithdrawlRequest {
pub account: Address,
pub token: Address,
pub amount: U256,
pub index: U256,

// Exclude `timestamp` from `Hash` and `PartialEq`
#[derivative(Hash = "ignore", PartialEq = "ignore")]
pub timestamp: U256,
}

#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Clone)]
Expand Down
2 changes: 1 addition & 1 deletion matching_engine/src/jobs/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ impl LogParser {
time_since_last_backup.as_secs_f64()
);

if time_since_last_backup > tokio::time::Duration::from_secs(100) {
if time_since_last_backup > tokio::time::Duration::from_secs(300) {
// make backup here
let market_store = self.shared_market_store.read().await;
let ask_store = self.shared_local_ask_store.read().await;
Expand Down
26 changes: 26 additions & 0 deletions matching_engine/src/log_processor/ns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,18 @@ pub async fn process_native_staking_logs(
log::warn!("pausing all assignments across all markets");
log::warn!("will be unpaused once the request if fully withdrawn");

let withdrawal_request_time = match native_staking
.withdrawal_requests(account, address, index)
.call()
.await
{
Ok(data) => data.2,
Err(err) => {
log::error!("Failed Querying withdrawal request timestamp: {}", err);
0.into()
}
};

generator_store.pause_assignments_across_all_markets(&address);

log::warn!("Setting new utilization to same value");
Expand All @@ -144,6 +156,7 @@ pub async fn process_native_staking_logs(
index,
token,
amount,
timestamp: withdrawal_request_time,
},
);
return Ok(());
Expand Down Expand Up @@ -172,6 +185,18 @@ pub async fn process_native_staking_logs(
.await
.unwrap_or_default();

let withdrawal_request_time = match native_staking
.withdrawal_requests(account, address, index)
.call()
.await
{
Ok(data) => data.2,
Err(err) => {
log::error!("Failed Querying withdrawal request timestamp: {}", err);
0.into()
}
};

generator_store.remove_stake(
&address,
&token_address,
Expand All @@ -192,6 +217,7 @@ pub async fn process_native_staking_logs(
index,
token: token_address,
amount,
timestamp: withdrawal_request_time,
},
);

Expand Down
3 changes: 3 additions & 0 deletions matching_engine/src/routes/ui_routes/single_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ pub struct WithdrawRequest {
token: String,
amount: String,
index: String,
withdrawal_timestamp: String,
}

#[derive(Serialize, Deserialize, Debug, Clone)]
Expand Down Expand Up @@ -235,6 +236,7 @@ pub async fn withdrawal_request(
index: a.index.to_string(),
token: address_to_string(&a.token),
amount: a.amount.to_string(),
withdrawal_timestamp: a.timestamp.to_string(),
})
.collect::<Vec<WithdrawRequest>>();

Expand Down Expand Up @@ -577,6 +579,7 @@ async fn recompute_single_generator_response<'a>(
index: a.index.to_string(),
token: address_to_string(&a.token),
amount: a.amount.to_string(),
withdrawal_timestamp: a.timestamp.to_string(),
})
.collect(),
compute_break_down: ComputeBreakDown {
Expand Down

0 comments on commit c375a1e

Please sign in to comment.