Skip to content

Commit

Permalink
Add tests for unprofitable osmosis arbs.
Browse files Browse the repository at this point in the history
  • Loading branch information
dowlandaiello committed Oct 18, 2024
1 parent 6d05a26 commit fda5eac
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 2 deletions.
50 changes: 50 additions & 0 deletions local-interchaintest/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,56 @@ fn main() -> Result<(), Box<dyn StdError + Send + Sync>> {
.with_test(Box::new(tests::test_unprofitable_arb) as TestFn)
.build()?,
)?
// Test case unprofitable osmo arb:
//
// - Astro: untrn-bruhtoken @ 1.5 bruhtoken/untrn
// - Osmo: bruhtoken-uosmo @ 0.001 uosmo/bruhtoken
// - Astro: uosmo-untrn @ 1 untrn/uosmo
.run(
TestBuilder::default()
.with_name("Osmosis Arb")
.with_description("The arbitrage bot not execute an unprofitable arb on Osmosis")
.with_denom(untrn_osmo.clone(), 100000000000)
.with_denom(uosmo.clone(), 100000000000)
.with_denom(bruhtoken.clone(), 100000000000)
.with_denom(untrn.clone(), 100000000000)
.with_denom(bruhtoken_osmo.clone(), 100000000000)
.with_pool(
untrn.clone(),
uosmo_ntrn.clone(),
Pool::Astroport(
AstroportPoolBuilder::default()
.with_balance_asset_a(10000000u128)
.with_balance_asset_b(15000000u128)
.build()?,
),
)
.with_pool(
uosmo.clone(),
bruhtoken_osmo.clone(),
Pool::Osmosis(
OsmosisPoolBuilder::default()
.with_funds(bruhtoken_osmo.clone(), 100000000u128)
.with_funds(uosmo.clone(), 100000u128)
.with_weight(bruhtoken_osmo.clone(), 100u128)
.with_weight(uosmo.clone(), 1u128)
.build(),
),
)
.with_pool(
untrn.clone(),
bruhtoken.clone(),
Pool::Auction(
AuctionPoolBuilder::default()
.with_balance_offer_asset(10000000u128)
.with_price(Decimal::percent(10))
.build()?,
),
)
.with_arbbot()
.with_test(Box::new(tests::test_unprofitable_osmo_arb) as TestFn)
.build()?,
)?
// Test case (astro -> osmo arb):
//
// - Astro: untrn-bruhtoken @ 1.5 bruhtoken/untrn
Expand Down
52 changes: 50 additions & 2 deletions local-interchaintest/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,54 @@ pub fn test_unprofitable_arb() -> Result<(), Box<dyn Error + Send + Sync + 'stat
Ok(())
}

pub fn test_unprofitable_osmo_arb() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
let conn = sqlite::open(ARBFILE_PATH).expect("failed to open db");

let profit = {
let query = "SELECT SUM(o.realized_profit) AS total_profit FROM orders o";

let mut statement = conn.prepare(query).unwrap();

statement
.next()
.ok()
.and_then(|_| statement.read::<i64, _>("total_profit").ok())
.unwrap_or_default()
};

let auction_profit = {
let query = "SELECT SUM(order_profit) AS total_profit FROM (SELECT MAX(o.realized_profit) AS order_profit FROM orders o INNER JOIN legs l ON o.uid = l.order_uid WHERE l.kind = 'auction' GROUP BY o.uid)";
let mut statement = conn.prepare(query).unwrap();

statement
.next()
.ok()
.and_then(|_| statement.read::<i64, _>("total_profit").ok())
.unwrap_or_default()
};

let osmo_profit = {
let query = "SELECT SUM(order_profit) AS total_profit FROM (SELECT MAX(o.realized_profit) AS order_profit FROM orders o INNER JOIN legs l ON o.uid = l.order_uid WHERE l.kind = 'osmosis' GROUP BY o.uid)";
let mut statement = conn.prepare(query).unwrap();

statement
.next()
.ok()
.and_then(|_| statement.read::<i64, _>("total_profit").ok())
.unwrap_or_default()
};

println!("ARB BOT PROFIT: {profit}");
println!("AUCTION BOT PROFIT: {auction_profit}");
println!("OSMOSIS BOT PROFIT: {osmo_profit}");

util::assert_err("profit == 0", profit == 0, true)?;
util::assert_err("osmo_profit == 0", osmo_profit == 0, true)?;
util::assert_err("auction_profit == 0", auction_profit == 0, true)?;

Ok(())
}

pub fn test_osmo_arb() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
let conn = sqlite::open(ARBFILE_PATH).expect("failed to open db");

Expand All @@ -105,7 +153,7 @@ pub fn test_osmo_arb() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
};

let auction_profit = {
let query = "SELECT SUM(order_profit) AS total_profit FROM (SELECT MAX(o.realized_profit) AS order_profit FROM orders o WHERE l.kind = 'auction' INNER JOIN legs l ON o.uid == l.order_uid GROUP BY o.uid)";
let query = "SELECT SUM(order_profit) AS total_profit FROM (SELECT MAX(o.realized_profit) AS order_profit FROM orders o INNER JOIN legs l ON o.uid = l.order_uid WHERE l.kind = 'auction' GROUP BY o.uid)";
let mut statement = conn.prepare(query).unwrap();

statement
Expand All @@ -116,7 +164,7 @@ pub fn test_osmo_arb() -> Result<(), Box<dyn Error + Send + Sync + 'static>> {
};

let osmo_profit = {
let query = "SELECT SUM(order_profit) AS total_profit FROM (SELECT MAX(o.realized_profit) AS order_profit FROM orders o WHERE l.kind = 'osmosis' INNER JOIN legs l ON o.uid == l.order_uid GROUP BY o.uid)";
let query = "SELECT SUM(order_profit) AS total_profit FROM (SELECT MAX(o.realized_profit) AS order_profit FROM orders o INNER JOIN legs l ON o.uid = l.order_uid WHERE l.kind = 'osmosis' GROUP BY o.uid)";
let mut statement = conn.prepare(query).unwrap();

statement
Expand Down

0 comments on commit fda5eac

Please sign in to comment.