Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bisection matching engine #331

Open
wants to merge 416 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
416 commits
Select commit Hold shift + click to select a range
7399929
w
Will-Smith11 Feb 10, 2025
c63a579
w
Will-Smith11 Feb 10, 2025
70d077c
w
Will-Smith11 Feb 10, 2025
d8940d5
block
Will-Smith11 Feb 10, 2025
128b94c
w
Will-Smith11 Feb 10, 2025
d8b2435
fix
Will-Smith11 Feb 10, 2025
6e18cd1
more ticks
Will-Smith11 Feb 10, 2025
465b6f6
w
Will-Smith11 Feb 10, 2025
3b7441a
w
Will-Smith11 Feb 10, 2025
ed7e854
w
Will-Smith11 Feb 10, 2025
ebb3458
w
Will-Smith11 Feb 10, 2025
5af42f2
w
Will-Smith11 Feb 10, 2025
6e77195
w
Will-Smith11 Feb 10, 2025
b85fe8f
w
Will-Smith11 Feb 10, 2025
216b792
fix
Will-Smith11 Feb 10, 2025
d02e1d2
w
Will-Smith11 Feb 10, 2025
428b0a1
w
Will-Smith11 Feb 10, 2025
7b867c6
w
Will-Smith11 Feb 10, 2025
3a7a2b2
properly add bid
Will-Smith11 Feb 11, 2025
0d4731f
w
Will-Smith11 Feb 11, 2025
cd4774c
fixo
Will-Smith11 Feb 11, 2025
b88612b
w
Will-Smith11 Feb 11, 2025
d9d1be9
fix
Will-Smith11 Feb 11, 2025
73b0309
w
Will-Smith11 Feb 11, 2025
d6bf174
w
Will-Smith11 Feb 11, 2025
5062b3e
only non zero for 1
Will-Smith11 Feb 11, 2025
84eca19
onlyIn
Will-Smith11 Feb 11, 2025
98130be
w
Will-Smith11 Feb 11, 2025
2b2e792
w
Will-Smith11 Feb 11, 2025
eddbcb9
w
Will-Smith11 Feb 11, 2025
ee86264
fix
Will-Smith11 Feb 11, 2025
261188a
fix?
Will-Smith11 Feb 11, 2025
d35f153
w
Will-Smith11 Feb 11, 2025
3caee07
w
Will-Smith11 Feb 11, 2025
a9b1655
w
Will-Smith11 Feb 11, 2025
a397de0
w
Will-Smith11 Feb 11, 2025
5bac417
w
Will-Smith11 Feb 11, 2025
03c91e0
fix
Will-Smith11 Feb 11, 2025
93fdc69
w
Will-Smith11 Feb 11, 2025
7bf115c
w
Will-Smith11 Feb 11, 2025
c4cc62d
w
Will-Smith11 Feb 11, 2025
810e9e6
w
Will-Smith11 Feb 11, 2025
ee59d85
gen properly
Will-Smith11 Feb 11, 2025
3e4f4ea
w
Will-Smith11 Feb 11, 2025
7e580ed
w
Will-Smith11 Feb 11, 2025
07106c8
w
Will-Smith11 Feb 11, 2025
02c417b
w
Will-Smith11 Feb 11, 2025
23145d7
w
Will-Smith11 Feb 11, 2025
149a825
w
Will-Smith11 Feb 11, 2025
e1f31a2
w
Will-Smith11 Feb 11, 2025
391ad8f
w
Will-Smith11 Feb 11, 2025
cc77dda
w
Will-Smith11 Feb 11, 2025
f75c6a7
fix
Will-Smith11 Feb 11, 2025
01b88a3
w
Will-Smith11 Feb 11, 2025
378d36d
wip
Will-Smith11 Feb 11, 2025
5cf7805
fix
Will-Smith11 Feb 11, 2025
c282a90
w
Will-Smith11 Feb 11, 2025
aa5e6c3
fix
Will-Smith11 Feb 11, 2025
706dfbf
Merge in Will's changes
Feb 11, 2025
597df44
Add logging to growthoutside
Feb 11, 2025
d8944a4
Fix start tick and liquidity generation
Feb 11, 2025
79b6d48
Fix start_tick to be closest tick to end
Feb 11, 2025
c780edd
Add logging for user order mapping
Feb 11, 2025
5fe3ec7
w
Will-Smith11 Feb 11, 2025
150f464
fix
Will-Smith11 Feb 11, 2025
81271af
Add logging for User order overrides and balance sums
Feb 11, 2025
0b06379
w
Will-Smith11 Feb 11, 2025
9b4b3a8
w
Will-Smith11 Feb 11, 2025
efa63f9
more fixo
Will-Smith11 Feb 11, 2025
20765fe
Fix rewards to always be T0
Feb 11, 2025
9057bcc
fix
Will-Smith11 Feb 11, 2025
261856a
w
Will-Smith11 Feb 11, 2025
4bb4ebc
w
Will-Smith11 Feb 11, 2025
8ab207f
w
Will-Smith11 Feb 11, 2025
1e43043
w
Will-Smith11 Feb 11, 2025
4537d8d
w
Will-Smith11 Feb 11, 2025
4cd7e6f
Fix comparison reversal
Feb 11, 2025
0f33781
w
Will-Smith11 Feb 11, 2025
b361fae
Cleaner and safer comparisons for ToB rewards
Feb 11, 2025
67837e6
fixes
Will-Smith11 Feb 11, 2025
7440822
cleanup
Will-Smith11 Feb 11, 2025
ca8e853
w
Will-Smith11 Feb 11, 2025
ffa968d
w
Will-Smith11 Feb 11, 2025
26f1c6e
remove unneeded logic
Will-Smith11 Feb 11, 2025
ef3fa2f
fix
Will-Smith11 Feb 11, 2025
2edf921
fix
Will-Smith11 Feb 11, 2025
0b3b99a
Fix up override logic
Feb 11, 2025
8a9abfd
dave fix
Will-Smith11 Feb 11, 2025
493b046
w
Will-Smith11 Feb 11, 2025
ced92ad
fix
Will-Smith11 Feb 11, 2025
c00de40
w
Will-Smith11 Feb 11, 2025
833d2aa
w
Will-Smith11 Feb 11, 2025
53185b1
make saturating
Will-Smith11 Feb 11, 2025
63a96e8
w
Will-Smith11 Feb 11, 2025
3aa5426
w
Will-Smith11 Feb 11, 2025
57c3ec4
remove unneeded logic
Will-Smith11 Feb 11, 2025
27e9c67
Clean up quantities and comments
Feb 11, 2025
de50310
Merge in Will's fixes
Feb 11, 2025
9d0b9ac
should fix
Will-Smith11 Feb 12, 2025
1fe2b28
w
Will-Smith11 Feb 12, 2025
92693bb
w
Will-Smith11 Feb 12, 2025
7ecf5f7
w
Will-Smith11 Feb 12, 2025
de21206
w
Will-Smith11 Feb 12, 2025
4540ca5
w
Will-Smith11 Feb 12, 2025
c51fadc
log builder
Will-Smith11 Feb 12, 2025
71c62c1
w
Will-Smith11 Feb 12, 2025
d48a078
no contract liq
Will-Smith11 Feb 12, 2025
1bbd9e9
assume right
Will-Smith11 Feb 12, 2025
fd13b35
hehe
Will-Smith11 Feb 12, 2025
ce9ec99
w
Will-Smith11 Feb 12, 2025
5e21549
Remove unused code
Feb 12, 2025
75d9e4e
w
Will-Smith11 Feb 12, 2025
d8eead5
w
Will-Smith11 Feb 12, 2025
e16aaa2
fix
Will-Smith11 Feb 12, 2025
6e7c4d5
wip
Will-Smith11 Feb 12, 2025
8088b57
Change ToBOutcome to be entirely u128
Feb 12, 2025
be844cc
w
Will-Smith11 Feb 12, 2025
ac2d854
w
Will-Smith11 Feb 12, 2025
491475d
w
Will-Smith11 Feb 12, 2025
7975912
w
Will-Smith11 Feb 12, 2025
1c0013d
w
Will-Smith11 Feb 12, 2025
2bb7846
undo log
Will-Smith11 Feb 12, 2025
4dd7123
cleanup
Will-Smith11 Feb 12, 2025
d1db43c
w
Will-Smith11 Feb 12, 2025
df85120
fix
Will-Smith11 Feb 12, 2025
ccf7ba0
w
Will-Smith11 Feb 12, 2025
350931b
default price is first step
Will-Smith11 Feb 12, 2025
61c3a65
w
Will-Smith11 Feb 12, 2025
f6fb589
w
Will-Smith11 Feb 12, 2025
f664abf
w
Will-Smith11 Feb 12, 2025
16fb08c
cleanup
Will-Smith11 Feb 12, 2025
39ef764
try 10
Will-Smith11 Feb 12, 2025
38c609c
More clarity into swap output
Feb 12, 2025
c60a854
w
Will-Smith11 Feb 12, 2025
afea623
w
Will-Smith11 Feb 12, 2025
1f705c3
w
Will-Smith11 Feb 12, 2025
b8486ac
fix
Will-Smith11 Feb 12, 2025
29455aa
w
Will-Smith11 Feb 12, 2025
6b8c478
Fix directional issues with PoolPriceVec donations
Feb 12, 2025
5d84a6d
w
Will-Smith11 Feb 12, 2025
c0a9725
w
Will-Smith11 Feb 12, 2025
86a73a6
merge dave
Will-Smith11 Feb 12, 2025
89c5799
w
Will-Smith11 Feb 12, 2025
4b98ef4
w
Will-Smith11 Feb 12, 2025
b758647
more
Will-Smith11 Feb 12, 2025
10bde8f
1mill
Will-Smith11 Feb 12, 2025
4eb9472
try
Will-Smith11 Feb 12, 2025
e53f7ed
fornow
Will-Smith11 Feb 12, 2025
4eed131
w
Will-Smith11 Feb 12, 2025
a71b94f
clean
Will-Smith11 Feb 12, 2025
966234f
w
Will-Smith11 Feb 12, 2025
1e32ce6
w
Will-Smith11 Feb 12, 2025
b102d90
cleanup
Will-Smith11 Feb 12, 2025
d5ff4fc
w
Will-Smith11 Feb 12, 2025
3c7d97c
w
Will-Smith11 Feb 12, 2025
ed7da21
w
Will-Smith11 Feb 12, 2025
58a8b15
Update pricing and rewards to hopefully fix it all
Feb 12, 2025
2dd0cf9
Account for tribute
Feb 13, 2025
a890213
w
Will-Smith11 Feb 13, 2025
dba2c65
merge dave
Will-Smith11 Feb 13, 2025
50f9a72
cleanup
Will-Smith11 Feb 13, 2025
03c3c9e
w
Will-Smith11 Feb 13, 2025
c677ac2
fixes
Will-Smith11 Feb 13, 2025
1819b39
fix min amounts
Will-Smith11 Feb 13, 2025
b02c224
add log
Will-Smith11 Feb 13, 2025
a769b05
fix
Will-Smith11 Feb 13, 2025
783eda3
Maximize rewards and try rounding fix
Feb 13, 2025
02b68ab
Have AssetBuilder take all extra liquidity as 'save'
Feb 13, 2025
af79e7c
Fix silly error in how I capped that off
Feb 13, 2025
01bd72c
Only save what we don't owe for settling
Feb 13, 2025
533979f
handle gas
Will-Smith11 Feb 13, 2025
42891cd
w
Will-Smith11 Feb 13, 2025
2883b56
merge dave
Will-Smith11 Feb 13, 2025
c12221c
w
Will-Smith11 Feb 13, 2025
d989411
w
Will-Smith11 Feb 13, 2025
82226e3
fix
Will-Smith11 Feb 13, 2025
62d2f99
w
Will-Smith11 Feb 13, 2025
55a0927
w
Will-Smith11 Feb 13, 2025
cb530b7
w
Will-Smith11 Feb 13, 2025
5bd348e
w
Will-Smith11 Feb 13, 2025
fb2d3d3
fixes
Will-Smith11 Feb 13, 2025
f0c7b88
cleanup
Will-Smith11 Feb 13, 2025
97d00bd
init
Will-Smith11 Feb 13, 2025
f500667
w
Will-Smith11 Feb 13, 2025
72e08b8
w
Will-Smith11 Feb 13, 2025
72c03fc
cleanup
Will-Smith11 Feb 13, 2025
0c31c13
cleanup
Will-Smith11 Feb 13, 2025
47fdc38
w
Will-Smith11 Feb 13, 2025
62011d2
fix
Will-Smith11 Feb 13, 2025
c43c3e5
w
Will-Smith11 Feb 13, 2025
d854971
Merge will's work
Feb 14, 2025
f26d6ae
Correct the way we build snapshots based on liq deltas
Feb 14, 2025
7bcae9c
Sort ticks for accuracy
Feb 14, 2025
639981b
don't double sim
Will-Smith11 Feb 19, 2025
201647e
add more tests for pool price vec
Will-Smith11 Feb 19, 2025
5557ab9
disable submission for now
Will-Smith11 Feb 19, 2025
5c412fb
less orders
Will-Smith11 Feb 19, 2025
e1311ac
tigher bound
Will-Smith11 Feb 19, 2025
20f87bc
tigher bound
Will-Smith11 Feb 19, 2025
c1dc5c2
use partial if last on side
Will-Smith11 Feb 19, 2025
6ae10c2
remove double cnt
Will-Smith11 Feb 19, 2025
3dda7c5
undo partial
Will-Smith11 Feb 19, 2025
e73b869
w
Will-Smith11 Feb 19, 2025
fa3dca0
fixes
Will-Smith11 Feb 19, 2025
6b35598
eliminate book
Will-Smith11 Feb 19, 2025
a8c510f
lots
Will-Smith11 Feb 19, 2025
1af75c8
pls
Will-Smith11 Feb 19, 2025
c2d4858
w
Will-Smith11 Feb 19, 2025
e442a62
simplify building
Will-Smith11 Feb 19, 2025
f82483c
w
Will-Smith11 Feb 19, 2025
2e810c4
w
Will-Smith11 Feb 19, 2025
dd7b8fa
w
Will-Smith11 Feb 19, 2025
4308242
t
Will-Smith11 Feb 19, 2025
05e01a1
w
Will-Smith11 Feb 19, 2025
6840725
w
Will-Smith11 Feb 19, 2025
34e7b97
check to make sure proper ordering
Will-Smith11 Feb 19, 2025
a7f21a5
fixes
Will-Smith11 Feb 19, 2025
ac13d61
do deltas
Will-Smith11 Feb 19, 2025
4e1df85
fixes
Will-Smith11 Feb 19, 2025
5e8469d
check order outcome
Will-Smith11 Feb 20, 2025
85fbe89
try no fee adjustment
Will-Smith11 Feb 20, 2025
73b0bba
w
Will-Smith11 Feb 20, 2025
f5ceac2
t
Will-Smith11 Feb 20, 2025
27f19c7
undo
Will-Smith11 Feb 20, 2025
6283347
closer
Will-Smith11 Feb 20, 2025
de862f2
w
Will-Smith11 Feb 20, 2025
4f2940c
optimize more
Will-Smith11 Feb 20, 2025
ed43ae4
w
Will-Smith11 Feb 20, 2025
f2ccf82
no partials for now
Will-Smith11 Feb 20, 2025
5835a24
w
Will-Smith11 Feb 20, 2025
4a1eac6
tryfaster
Will-Smith11 Feb 20, 2025
8c70501
fixes
Will-Smith11 Feb 20, 2025
25b6dbf
fix
Will-Smith11 Feb 20, 2025
e018706
w
Will-Smith11 Feb 20, 2025
234a725
some tmp fixes for dave
Will-Smith11 Feb 20, 2025
84c309b
Debugging adds
Feb 19, 2025
20862b4
Merge in Will's updates
Feb 20, 2025
7337f8b
Update tests, fix input/output calculations to hopefully align with
Feb 20, 2025
23afcb4
updates
Will-Smith11 Feb 21, 2025
97f0502
w
Will-Smith11 Feb 21, 2025
3cdeb91
move to named functions
Will-Smith11 Feb 21, 2025
829a266
w
Will-Smith11 Feb 21, 2025
e228afd
adjust amount mod
Will-Smith11 Feb 21, 2025
88d0bef
w
Will-Smith11 Feb 21, 2025
76bcc0c
closer range
Will-Smith11 Feb 21, 2025
ae5fe99
add printouts at every hop
Will-Smith11 Feb 21, 2025
e7441e7
add printouts at every hop
Will-Smith11 Feb 21, 2025
8dbfcb4
fix dave math
Will-Smith11 Feb 21, 2025
0940d85
oh my lord i am stupid
Will-Smith11 Feb 21, 2025
d078ff9
LFG IT WORKS NO WAYYY
Will-Smith11 Feb 21, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion bin/testnet/pool_key_config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@
# currency1 = "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"
fee = 0
tick_spacing = 60
liquidity = "34028236692"
liquidity = "34028236692221234111"
# weird bug were round down
tick = 100020
11 changes: 11 additions & 0 deletions bin/testnet/src/cli/compare_engines.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use clap::Parser;

use super::testnet::TestnetCli;

#[derive(Debug, Clone, Parser)]
pub struct CompareEnginesCli {
#[arg(short = 'z', default_value_t = false)]
pub include_amm: bool,
#[clap(flatten)]
pub testnet_config: TestnetCli
}
51 changes: 35 additions & 16 deletions bin/testnet/src/cli/mod.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
pub mod compare_engines;
pub mod devnet;
pub mod e2e_orders;
pub mod testnet;
use angstrom_metrics::{initialize_prometheus_metrics, METRICS_ENABLED};
use clap::{ArgAction, Parser, Subcommand};
use compare_engines::CompareEnginesCli;
use devnet::DevnetCli;
use e2e_orders::End2EndOrdersCli;
use reth_tasks::TaskExecutor;
Expand All @@ -13,7 +15,10 @@ use tracing_subscriber::{
filter, layer::SubscriberExt, util::SubscriberInitExt, EnvFilter, Layer, Registry
};

use crate::{run_devnet, run_testnet, simulations::e2e_orders::run_e2e_orders};
use crate::{
run_devnet, run_testnet,
simulations::{e2e_orders::run_e2e_orders, matching_comp::compare_matching_engines}
};

#[derive(Parser)]
pub struct AngstromTestnetCli {
Expand Down Expand Up @@ -70,15 +75,18 @@ pub enum TestnetSubcommmand {
#[command(name = "devnet")]
Devnet(DevnetCli),
#[command(name = "e2e")]
End2EndOrders(End2EndOrdersCli)
End2EndOrders(End2EndOrdersCli),
#[command(name = "engine-sim")]
Compare(CompareEnginesCli)
}

impl TestnetSubcommmand {
async fn run_command(self, executor: TaskExecutor) -> eyre::Result<()> {
match self {
TestnetSubcommmand::Testnet(testnet_cli) => run_testnet(executor, testnet_cli).await,
TestnetSubcommmand::Devnet(devnet_cli) => run_devnet(executor, devnet_cli).await,
TestnetSubcommmand::End2EndOrders(e2e_cli) => run_e2e_orders(executor, e2e_cli).await
TestnetSubcommmand::End2EndOrders(e2e_cli) => run_e2e_orders(executor, e2e_cli).await,
TestnetSubcommmand::Compare(cli) => compare_matching_engines(executor, cli).await
}
}
}
Expand All @@ -92,20 +100,31 @@ pub fn init_tracing(verbosity: u8) {
_ => Level::TRACE
};

let layers = vec![
layer_builder(format!("testnet={level}")),
layer_builder(format!("devnet={level}")),
layer_builder(format!("angstrom_rpc={level}")),
layer_builder(format!("angstrom={level}")),
layer_builder(format!("testing_tools={level}")),
layer_builder(format!("matching_engine={level}")),
layer_builder(format!("uniswap_v4={level}")),
layer_builder(format!("consensus={level}")),
layer_builder(format!("validation={level}")),
layer_builder(format!("order_pool={level}")),
];
let envfilter = filter::EnvFilter::builder().try_from_env().ok();
let format = tracing_subscriber::fmt::layer()
.with_ansi(true)
.with_target(true);

tracing_subscriber::registry().with(layers).init();
if let Some(f) = envfilter {
tracing_subscriber::registry().with(format).with(f).init();
} else {
let filter = filter::Targets::new()
.with_target("testnet", level)
.with_target("devnet", level)
.with_target("angstrom_rpc", level)
.with_target("angstrom", level)
.with_target("testing_tools", level)
.with_target("angstrom_eth", level)
.with_target("matching_engine", level)
.with_target("uniswap_v4", level)
.with_target("consensus", level)
.with_target("validation", level)
.with_target("order_pool", level);
tracing_subscriber::registry()
.with(format)
.with(filter)
.init();
}
}

fn layer_builder(filter_str: String) -> Box<dyn Layer<Registry> + Send + Sync> {
Expand Down
4 changes: 2 additions & 2 deletions bin/testnet/src/simulations/e2e_orders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ fn end_to_end_agent<'a>(
let mut generator = OrderGenerator::new(
agent_config.uniswap_pools.clone(),
agent_config.current_block,
7..10,
0.1..0.6
5..10,
0.1..0.9
);

let mut stream =
Expand Down
217 changes: 217 additions & 0 deletions bin/testnet/src/simulations/matching_comp.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
use std::{pin::Pin, sync::atomic::AtomicBool};

use alloy_primitives::{FixedBytes, U256};
use angstrom_eth::manager::ChainExt;
use angstrom_types::{
matching::Ray,
orders::{OrderId, OrderOrigin, OrderPriorityData},
sol_bindings::{
grouped_orders::{AllOrders, OrderWithStorageData},
RawPoolOrder
},
testnet::InitialTestnetState
};
use futures::{Future, StreamExt};
use matching_engine::{
book::{sort::SortStrategy, BookOrder, OrderBook},
matcher::binary_search::BinarySearchMatcher,
strategy::{MatchingStrategy, SimpleCheckpointStrategy}
};
use reth_provider::{noop::NoopProvider, CanonStateSubscriptions};
use reth_tasks::TaskExecutor;
use testing_tools::{
agents::AgentConfig,
controllers::enviroments::AngstromTestnet,
order_generator::{self, GeneratedPoolOrders, OrderGenerator},
types::{
actions::WithAction, checked_actions::WithCheckedAction, checks::WithCheck,
config::DevnetConfig
}
};
use tracing::{debug, info, span, Instrument, Level};

use crate::cli::compare_engines::CompareEnginesCli;

static USE_AMM: AtomicBool = AtomicBool::new(false);

pub async fn compare_matching_engines(
executor: TaskExecutor,
cli: CompareEnginesCli
) -> eyre::Result<()> {
let config = cli.testnet_config.make_config()?;
USE_AMM.store(cli.include_amm, std::sync::atomic::Ordering::SeqCst);

let agents = vec![cmp_agent];
tracing::info!("spinning up e2e nodes for angstrom");

// spawn testnet
let testnet = AngstromTestnet::spawn_testnet(NoopProvider::default(), config, agents).await?;
tracing::info!("e2e testnet is alive");

executor
.spawn_critical_blocking("testnet", testnet.run_to_completion(executor.clone()))
.await?;
Ok(())
}

fn cmp_agent<'a>(
_: &'a InitialTestnetState,
agent_config: AgentConfig
) -> Pin<Box<dyn Future<Output = eyre::Result<()>> + Send + 'a>> {
Box::pin(async move {
let mut generator = OrderGenerator::new(
agent_config.uniswap_pools.clone(),
agent_config.current_block,
10..12,
0.2..0.6
);

let mut stream =
agent_config
.state_provider
.canonical_state_stream()
.map(|node| match node {
reth_provider::CanonStateNotification::Commit { new }
| reth_provider::CanonStateNotification::Reorg { new, .. } => new.tip_number()
});

tokio::spawn(
async move {
tracing::info!("waiting for new block");
let use_amm = USE_AMM.load(std::sync::atomic::Ordering::SeqCst);

while let Some(block) = stream.next().await {
generator.new_block(block);
let new_orders = generator.generate_orders();
for orders in new_orders {
let GeneratedPoolOrders { pool_id, tob, book } = orders;
let pool = agent_config.uniswap_pools.get(&pool_id).unwrap();
let (_, _, amm) = pool.read().unwrap().fetch_pool_snapshot().unwrap();
let asks =
book.iter()
.filter(|f| !f.is_bid())
.map(|ask| {
OrderWithStorageData {
invalidates: vec![],
order: ask.clone(),
priority_data: OrderPriorityData {
price: *ask.price(),
volume: ask.amount(),
gas: U256::ZERO,
gas_units: 0
},
is_bid: false,
is_valid: true,
is_currently_valid: true,
order_id: OrderId {
flash_block: None,
reuse_avoidance: angstrom_types::sol_bindings::RespendAvoidanceMethod::Block(0),
hash: ask.order_hash(),
address: Default::default(),
deadline: None,
pool_id,
location: angstrom_types::orders::OrderLocation::Limit
},
pool_id,
valid_block: 0,
tob_reward: U256::ZERO
}
})
.collect::<Vec<BookOrder>>();
let bids =
book.iter()
.filter(|f| f.is_bid())
.map(|bid| {
OrderWithStorageData {
invalidates: vec![],
order: bid.clone(),
priority_data: OrderPriorityData {
price: *bid.price(),
volume: bid.amount(),
gas: U256::ZERO,
gas_units: 0
},
is_bid: true,
is_valid: true,
is_currently_valid: true,
order_id: OrderId {
flash_block: None,
reuse_avoidance: angstrom_types::sol_bindings::RespendAvoidanceMethod::Block(0),
hash: bid.order_hash(),
address: Default::default(),
deadline: None,
pool_id,
location: angstrom_types::orders::OrderLocation::Limit
},
pool_id,
valid_block: 0,
tob_reward: U256::ZERO
}
})
.collect::<Vec<BookOrder>>();

let book = OrderBook::new(
pool_id,
use_amm.then_some(amm),
bids,
asks,
Some(SortStrategy::ByPriceByVolume)
);

let tob = OrderWithStorageData {
invalidates: vec![],
order: tob.clone(),
priority_data: OrderPriorityData {
price: tob.limit_price(),
volume: tob.amount(),
gas: U256::ZERO,
gas_units: 0
},
is_bid: tob.is_bid(),
is_valid: true,
is_currently_valid: true,
order_id: OrderId {
flash_block: None,
reuse_avoidance:
angstrom_types::sol_bindings::RespendAvoidanceMethod::Block(0),
hash: tob.order_hash(),
address: Default::default(),
deadline: None,
pool_id,
location: angstrom_types::orders::OrderLocation::Limit
},
pool_id,
valid_block: 0,
tob_reward: U256::ZERO
};

let debt_engine = SimpleCheckpointStrategy::run(&book)
.unwrap()
.solution(Some(tob.clone()));

let bisection = BinarySearchMatcher::new(&book, Some(tob.clone()))
.solution(Some(tob.clone()));

if debt_engine.ucp != bisection.ucp {
// lets save the book
book.save(bisection.ucp, debt_engine.ucp).unwrap();

let r = BinarySearchMatcher::new(&book, Some(tob.clone()))
.calculate_solver_move(debt_engine.ucp);
println!("\n\n\n\n\n when using the debt engine ucp, we get: {:#?}", r);
}

if bisection != debt_engine {
println!(
"\n\n\n\n bisection_results:{:#?}\n\n debt_results:{:#?} ",
bisection, debt_engine,
);
}
}
}
}
.instrument(span!(Level::ERROR, "matching engine cmp", ?agent_config.agent_id))
);
Ok(())
})
}
1 change: 1 addition & 0 deletions bin/testnet/src/simulations/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pub mod e2e_orders;
pub mod matching_comp;
Loading
Loading