Skip to content

Commit

Permalink
Merge pull request invariant-labs#20 from invariant-labs/include-chec…
Browse files Browse the repository at this point in the history
…king-outdated-state

Add check if ticks accounts are outdated in quote
  • Loading branch information
wojciech-cichocki authored Mar 5, 2024
2 parents 91ddecd + 98d2862 commit e0e0d11
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
20 changes: 10 additions & 10 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ jobs:
cargo build --verbose
cargo test --verbose
rust-nightly:
runs-on: ubuntu-latest
container: rustlang/rust:nightly
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Build and test with Rust nightly
run: |
cargo build --verbose
cargo test --verbose
# rust-nightly:
# runs-on: ubuntu-latest
# container: rustlang/rust:nightly
# steps:
# - name: Checkout code
# uses: actions/checkout@v2
# - name: Build and test with Rust nightly
# run: |
# cargo build --verbose
# cargo test --verbose
8 changes: 8 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ impl Amm for JupiterInvariant {
}

fn quote(&self, quote_params: &QuoteParams) -> anyhow::Result<Quote> {
let accounts_outdated = self.ticks_accounts_outdated();
if accounts_outdated {
return Ok(Quote {
not_enough_liquidity: true,
..Quote::default()
});
}

let invariant_simulation_params = self.quote_to_invariant_params(quote_params)?;
let simulation_result = self.simulate_invariant_swap(&invariant_simulation_params);

Expand Down
2 changes: 1 addition & 1 deletion src/swap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ impl JupiterInvariant {
by_amount_in,
} = *invariant_simulation_params;

let (mut pool, ticks, tickmap, starting_sqrt_price) = (
let (pool, ticks, tickmap, starting_sqrt_price) = (
&mut self.pool.clone(),
&self.ticks.clone(),
&self.tickmap.clone(),
Expand Down

0 comments on commit e0e0d11

Please sign in to comment.