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

Add enum for -Infinity and NaN tests cases #209

Open
dubzn opened this issue Jan 8, 2024 · 0 comments
Open

Add enum for -Infinity and NaN tests cases #209

dubzn opened this issue Jan 8, 2024 · 0 comments
Labels

Comments

@dubzn
Copy link
Contributor

dubzn commented Jan 8, 2024

Description

Currently, we use felts for cases where the results of dividing amount_delta_0 and amount_delta_1 are border cases (0/0 or -x/0).

# file /tests/utils/swap_helper.cairo (line 178-190)

fn calculate_execution_price(
    token_0_swapped_amount: u256, token_1_swapped_amount: u256
) -> u256 {
    if token_0_swapped_amount == 0
        && token_1_swapped_amount == 0 { xxxxxxxxxxxxx
        'NaN'.into()
    } else if token_0_swapped_amount == 0 {
        // Since uniswap divides deltas to calculate exec_price, all prices are multiplied by -1 so that all prices are > 0.
        // Therefore, this value ends up as -Infinity
        '-Infinity'.into()
    } else { //this is every other case, price = 0/x = 0, or price = x/y = z
        (token_1_swapped_amount * pow(2, 96)) / token_0_swapped_amount
    }
}

We should change what this function returns, and the obtained value should be an enum ExecutionPriceEdgeCases.

The modifications should be made in the previously mentioned function and in the SwapExpectedResults files wherever 'NaN' and '-Infinity' are found.

Pool N° Error type
Pool 8 NaN
Pool 9 NaN
Pool 10 -Infinity
Pool 11 NaN
Pool 12 -Infinity & NaN
Pool 14 NaN
@dubzn dubzn added the refactor label Jan 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant