Skip to content

Commit 802b045

Browse files
committed
test - working uniswap v3 swap test with tick batch request
1 parent b3fc653 commit 802b045

1 file changed

Lines changed: 3 additions & 33 deletions

File tree

src/amm/uniswap_v3/mod.rs

Lines changed: 3 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use alloy::{
1818
use alloy_chains::NamedChain;
1919
use async_recursion::async_recursion;
2020
use async_trait::async_trait;
21-
use batch_request::UniswapV3TickData;
2221
use db::models::{NewDbPool, NewDbUniV3Pool};
2322
use futures::{stream::FuturesOrdered, StreamExt};
2423
use num_bigfloat::BigFloat;
@@ -1534,20 +1533,18 @@ mod test {
15341533
..Default::default()
15351534
};
15361535

1537-
let creation_block = 12369620;
15381536
pool.tick_spacing = pool.get_tick_spacing(provider.clone()).await?;
15391537
let synced_block = provider.get_block_number().await?;
15401538

15411539
pool.populate_data(Some(synced_block), provider.clone())
15421540
.await?;
15431541
let current_tick = pool.tick;
1544-
let tick_start = current_tick - 10;
1545-
let num_ticks = 20;
1542+
let num_ticks = 500 * pool.tick_spacing;
1543+
let tick_start = current_tick - num_ticks / 2;
15461544

15471545
let (tick_data, _) = get_uniswap_v3_tick_data_batch_request(
15481546
&pool,
15491547
tick_start,
1550-
true,
15511548
num_ticks,
15521549
Some(synced_block),
15531550
provider.clone(),
@@ -1556,10 +1553,6 @@ mod test {
15561553

15571554
pool.populate_ticks_from_tick_data(tick_data);
15581555

1559-
let synced_block = pool
1560-
.populate_tick_data(creation_block, provider.clone())
1561-
.await?;
1562-
15631556
Ok((pool, synced_block))
15641557
}
15651558

@@ -1643,7 +1636,7 @@ mod test {
16431636
amount_out_1, expected_amount_out_1.amountOut
16441637
);
16451638

1646-
let amount_in_2 = U256::from(10000000000000_u128); // 10_000_000 USDC
1639+
let amount_in_2 = U256::from(1000000000000_u128); // 1_000_000 USDC
16471640
let amount_out_2 = pool
16481641
.simulate_swap(pool.token_a, amount_in_2, pool.token_b)
16491642
.unwrap();
@@ -1665,29 +1658,6 @@ mod test {
16651658
"invalid amount_out_2: {}, expected_amount_out_2: {}",
16661659
amount_out_2, expected_amount_out_2.amountOut
16671660
);
1668-
1669-
let amount_in_3 = U256::from(100000000000000_u128); // 100_000_000 USDC
1670-
let amount_out_3 = pool
1671-
.simulate_swap(pool.token_a, amount_in_3, pool.token_b)
1672-
.unwrap();
1673-
let expected_amount_out_3 = quoter
1674-
.quoteExactInputSingle(
1675-
pool.token_a,
1676-
pool.token_b,
1677-
U24::from(pool.fee),
1678-
amount_in_3,
1679-
U160::ZERO,
1680-
)
1681-
.block(synced_block.into())
1682-
.call()
1683-
.await
1684-
.unwrap();
1685-
1686-
assert_eq!(
1687-
amount_out_3, expected_amount_out_3.amountOut,
1688-
"invalid amount_out_3: {}, expected_amount_out_3: {}",
1689-
amount_out_3, expected_amount_out_3.amountOut
1690-
);
16911661
}
16921662

16931663
#[tokio::test]

0 commit comments

Comments
 (0)