Skip to content

Commit

Permalink
update precision 18
Browse files Browse the repository at this point in the history
  • Loading branch information
dpinones committed Jan 3, 2024
1 parent 1f0f369 commit 6e81f51
Show file tree
Hide file tree
Showing 15 changed files with 30 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ mod PoolCase0 {

use debug::PrintTrait;

const PRECISION: u256 = 45;
const PRECISION: u256 = 18;

#[test]
#[available_gas(200000000000)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ mod PoolCase1 {
use yas_core::tests::utils::pool_1::{SWAP_CASES_POOL_1, SWAP_EXPECTED_RESULTS_POOL_1};
use yas_core::tests::utils::swap_cases::SwapTestHelper::POOL_CASES;

const PRECISION: u256 = 45;
const PRECISION: u256 = 18;

#[test]
#[available_gas(200000000000)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ mod PoolCase10 {
use yas_core::tests::utils::pool_10::{SWAP_CASES_POOL_10, SWAP_EXPECTED_RESULTS_POOL_10};
use yas_core::tests::utils::swap_cases::SwapTestHelper::POOL_CASES;

const PRECISION: u256 = 45;
const PRECISION: u256 = 18;

#[test]
#[available_gas(200000000000)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ mod PoolCase11 {
use yas_core::tests::utils::pool_11::{SWAP_CASES_POOL_11, SWAP_EXPECTED_RESULTS_POOL_11};
use yas_core::tests::utils::swap_cases::SwapTestHelper::POOL_CASES;

const PRECISION: u256 = 45;
const PRECISION: u256 = 18;

#[test]
#[available_gas(200000000000)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ mod PoolCase12 {
use yas_core::tests::utils::pool_12::{SWAP_CASES_POOL_12, SWAP_EXPECTED_RESULTS_POOL_12};
use yas_core::tests::utils::swap_cases::SwapTestHelper::POOL_CASES;

const PRECISION: u256 = 45;
const PRECISION: u256 = 18;

#[test]
#[available_gas(200000000000)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ mod PoolCase13 {
use yas_core::tests::utils::pool_13::{SWAP_CASES_POOL_13, SWAP_EXPECTED_RESULTS_POOL_13};
use yas_core::tests::utils::swap_cases::SwapTestHelper::{POOL_CASES};

const PRECISION: u256 = 45;
const PRECISION: u256 = 18;

#[test]
#[available_gas(200000000000)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ mod PoolCase14 {
use yas_core::tests::utils::pool_14::{SWAP_CASES_POOL_14, SWAP_EXPECTED_RESULTS_POOL_14};
use yas_core::tests::utils::swap_cases::SwapTestHelper::{POOL_CASES};

const PRECISION: u256 = 45;
const PRECISION: u256 = 18;

#[test]
#[available_gas(200000000000)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ mod PoolCase2 {
use yas_core::tests::utils::pool_2::{SWAP_CASES_POOL_2, SWAP_EXPECTED_RESULTS_POOL_2};
use yas_core::tests::utils::swap_cases::SwapTestHelper::POOL_CASES;

const PRECISION: u256 = 45;
const PRECISION: u256 = 18;

#[test]
#[available_gas(200000000000)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ mod PoolCase4 {
use yas_core::tests::utils::pool_4::{SWAP_CASES_POOL_4, SWAP_EXPECTED_RESULTS_POOL_4};
use yas_core::tests::utils::swap_cases::SwapTestHelper::POOL_CASES;

const PRECISION: u256 = 45;
const PRECISION: u256 = 18;

#[test]
#[available_gas(200000000000)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ mod PoolCase5 {
use yas_core::tests::utils::pool_5::{SWAP_CASES_POOL_5, SWAP_EXPECTED_RESULTS_POOL_5};
use yas_core::tests::utils::swap_cases::SwapTestHelper::POOL_CASES;

const PRECISION: u256 = 45;
const PRECISION: u256 = 18;

#[test]
#[available_gas(200000000000)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ mod PoolCase6 {
use yas_core::tests::utils::pool_6::{SWAP_CASES_POOL_6, SWAP_EXPECTED_RESULTS_POOL_6};
use yas_core::tests::utils::swap_cases::SwapTestHelper::POOL_CASES;

const PRECISION: u256 = 45;
const PRECISION: u256 = 18;

#[test]
#[available_gas(200000000000)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ mod PoolCase7 {
use yas_core::tests::utils::pool_7::{SWAP_CASES_POOL_7, SWAP_EXPECTED_RESULTS_POOL_7};
use yas_core::tests::utils::swap_cases::SwapTestHelper::POOL_CASES;

const PRECISION: u256 = 45;
const PRECISION: u256 = 18;

#[test]
#[available_gas(200000000000)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ mod PoolCase8 {
use yas_core::tests::utils::swap_cases::SwapTestHelper::POOL_CASES;
use debug::PrintTrait;

const PRECISION: u256 = 45;
const PRECISION: u256 = 18;

#[test]
#[available_gas(200000000000)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ mod PoolCase9 {
use yas_core::tests::utils::pool_9::{SWAP_CASES_POOL_9, SWAP_EXPECTED_RESULTS_POOL_9};
use yas_core::tests::utils::swap_cases::SwapTestHelper::POOL_CASES;

const PRECISION: u256 = 45;
const PRECISION: u256 = 18;

#[test]
#[available_gas(200000000000)]
Expand Down
19 changes: 16 additions & 3 deletions crates/yas_core/src/tests/utils/swap_helper.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ mod SwapTestHelper {
use starknet::{ContractAddress, ClassHash, SyscallResultTrait};
use starknet::testing::{set_contract_address, set_caller_address};

use debug::PrintTrait;

fn test_pool(
pool_case: @PoolTestCase,
expected_cases: Array<SwapExpectedResults>,
Expand Down Expand Up @@ -146,13 +148,24 @@ mod SwapTestHelper {
assert(actual.amount_1_delta == *expected.amount_1_delta, 'wrong amount_1_delta');

// 10 significant_figures in x96 is way more accurate than uniswap precision
let SIGNIFICANT_FIGURES = 10;
// let SIGNIFICANT_FIGURES = 10;
'actual'.print();
let a = get_significant_figures(
actual.execution_price, precision
);
a.print();

'expected'.print();
let e = get_significant_figures(*expected.execution_price, precision);
e.print();

assert(
get_significant_figures(
actual.execution_price, SIGNIFICANT_FIGURES
) == get_significant_figures(*expected.execution_price, SIGNIFICANT_FIGURES),
actual.execution_price, precision
) == get_significant_figures(*expected.execution_price, precision),
'wrong execution_price'
);
'ok'.print();

assert(
actual.fee_growth_global_0_X128_delta == *expected.fee_growth_global_0_X128_delta,
Expand Down

0 comments on commit 6e81f51

Please sign in to comment.