Skip to content

Commit a79be53

Browse files
authored
Merge pull request #5 from simtopia/update
simulation records returned as a json object
2 parents d0a5d03 + 9e2fa12 commit a79be53

File tree

6 files changed

+151
-37
lines changed

6 files changed

+151
-37
lines changed

Cargo.lock

Lines changed: 90 additions & 24 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,8 @@ rand_distr = "0.4.3"
1515

1616
funty = "2.0.0"
1717
clap = { version = "4.5.1", features = ["derive"] }
18+
serde = "1.0.198"
19+
serde_json = "1.0.116"
20+
rayon = "1.10.0"
21+
features = "0.10.0"
22+
kdam = { version = "0.5.1", features = ["rayon"] }

src/aave/agents/borrow_agent.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ impl Agent for BorrowAgent {
6161
self.address,
6262
self.pool_address,
6363
self.supply_token_address,
64-
U256::from(10_u128.pow(20)),
64+
U256::from(10_u128.pow(18)),
6565
);
6666
self.has_supplied = true;
6767

@@ -79,7 +79,7 @@ impl Agent for BorrowAgent {
7979

8080
let exp = U256::from(10u128).pow(self.borrow_token_decimals - U256::from(4u128));
8181
// Agent borrows a random fraction of the available to borrow amount
82-
let u = U256::from(rng.gen_range(9000..10000));
82+
let u = U256::from(rng.gen_range(8000..9000));
8383
let available_borrow = exp * available_borrow_base * u / borrow_asset_price;
8484

8585
if available_borrow > U256::ZERO {

src/aave/agents/mod.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@ mod borrow_agent;
22
mod liquidation_agent;
33
mod uniswap_agent;
44
mod uniswap_noise_agent;
5+
56
use super::types::UserData;
67
use alloy_primitives::U256;
78
pub use borrow_agent::BorrowAgent;
89
pub use liquidation_agent::LiquidationAgent;
910
use rand::RngCore;
11+
use serde::{Deserialize, Serialize};
1012
pub use uniswap_agent::UniswapPriceAgent;
1113
pub use uniswap_noise_agent::UniswapNoiseAgent;
1214
use verbs_rs::agent::{AgentSet, AgentVec, SimState, SingletonAgent};
@@ -21,3 +23,12 @@ pub struct AgentStates {
2123
pub uniswap_price_agent: SingletonAgent<(i128, i128), UniswapPriceAgent>,
2224
pub uniswap_noise_agents: AgentVec<U256, UniswapNoiseAgent>,
2325
}
26+
27+
#[derive(Debug, Serialize, Deserialize)]
28+
pub struct SimData {
29+
pub seed: u64,
30+
pub borrow_agents: Vec<Vec<U256>>,
31+
pub liquidation_agents: Vec<Vec<UserData>>,
32+
pub uniswap_price_agent: Vec<(i128, i128)>,
33+
pub uniswap_noise_agents: Vec<Vec<U256>>,
34+
}

src/aave/mod.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ mod initialisation;
66
mod protocol;
77
pub mod types;
88

9+
pub use agents::SimData;
910
use verbs_rs::env::GasPriorityValidator;
10-
use verbs_rs::sim_runner;
11+
use verbs_rs::{agent::RecordedAgentSet, sim_runner};
1112

1213
use self::initialisation::initialise_sim;
1314

@@ -16,7 +17,7 @@ pub fn aave_sim_from_fork(
1617
n_steps: usize,
1718
params: types::ForkedSimParameters,
1819
alchemy_key: String,
19-
) {
20+
) -> SimData {
2021
println!("Initialising Simulation");
2122

2223
let validator = GasPriorityValidator {};
@@ -27,11 +28,25 @@ pub fn aave_sim_from_fork(
2728
println!("Running");
2829

2930
sim_runner::run(&mut env, &mut agent_sets, seed, n_steps);
31+
SimData {
32+
seed,
33+
borrow_agents: agent_sets.borrow_agents.take_records(),
34+
liquidation_agents: agent_sets.liquidation_agents.take_records(),
35+
uniswap_price_agent: agent_sets.uniswap_price_agent.take_records(),
36+
uniswap_noise_agents: agent_sets.uniswap_noise_agents.take_records(),
37+
}
3038
}
3139

32-
pub fn aave_sim(seed: u64, n_steps: usize, params: types::SimParameters) {
40+
pub fn aave_sim(seed: u64, n_steps: usize, params: types::SimParameters) -> SimData {
3341
let validator = GasPriorityValidator {};
3442
let (mut env, mut agent_sets, _, _, _) = initialise_sim(params, validator);
3543

3644
sim_runner::run(&mut env, &mut agent_sets, seed, n_steps);
45+
SimData {
46+
seed,
47+
borrow_agents: agent_sets.borrow_agents.take_records(),
48+
liquidation_agents: agent_sets.liquidation_agents.take_records(),
49+
uniswap_price_agent: agent_sets.uniswap_price_agent.take_records(),
50+
uniswap_noise_agents: agent_sets.uniswap_noise_agents.take_records(),
51+
}
3752
}

0 commit comments

Comments
 (0)