Skip to content

Commit

Permalink
Merge pull request #79 from SundaeSwap-finance/pi/minimum-deposit
Browse files Browse the repository at this point in the history
Prevent execution of a deposit that would mint 0 LP tokens
  • Loading branch information
Quantumplation authored Apr 12, 2024
2 parents d4896d1 + 05bafe7 commit a4d38bb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:

- uses: aiken-lang/[email protected]
with:
version: v1.0.24-alpha
version: v1.0.26-alpha

- run: |
# Run the tests
Expand Down
3 changes: 3 additions & 0 deletions lib/calculation/deposit.ak
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,9 @@ pub fn do_deposit(
let issued_lp_tokens =
deposited_a * pool_state.quantity_lp.3rd / pool_state.quantity_a.3rd

// Make sure we don't ever allow this to round to zero, which would just eat some of the users assets
expect issued_lp_tokens > 0

// Calculate what assets we expect on at the destination;
// i.e. it should be whatever assets were on the inputs, minus the amount that was deposited, minus the fee,
// plus the relevant LP tokens
Expand Down
13 changes: 12 additions & 1 deletion lib/tests/aiken/deposit.ak
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ test deposit_test() {
)
}

test deposit_test_minimum() fail {
deposit_test_schema(
661_278_808_416,
188_253_559_159_646,
153_000_000,
150,
151_171_875,
150,
value.from_lovelace(152_000_000)
)
}

fn deposit_test_schema(qa: Int, qb: Int, has_a: Int, has_b: Int, gives_a: Int, gives_b: Int, out_value: value.Value) {
let addr =
Address(
Expand Down Expand Up @@ -80,4 +92,3 @@ fn deposit_test_schema(qa: Int, qb: Int, has_a: Int, has_b: Int, gives_a: Int, g
// Test should pass as long as do_deposit didn't throw
True
}

0 comments on commit a4d38bb

Please sign in to comment.