Skip to content

Commit a4d38bb

Browse files
Merge pull request #79 from SundaeSwap-finance/pi/minimum-deposit
Prevent execution of a deposit that would mint 0 LP tokens
2 parents d4896d1 + 05bafe7 commit a4d38bb

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313

1414
- uses: aiken-lang/[email protected]
1515
with:
16-
version: v1.0.24-alpha
16+
version: v1.0.26-alpha
1717

1818
- run: |
1919
# Run the tests

lib/calculation/deposit.ak

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,9 @@ pub fn do_deposit(
9494
let issued_lp_tokens =
9595
deposited_a * pool_state.quantity_lp.3rd / pool_state.quantity_a.3rd
9696

97+
// Make sure we don't ever allow this to round to zero, which would just eat some of the users assets
98+
expect issued_lp_tokens > 0
99+
97100
// Calculate what assets we expect on at the destination;
98101
// i.e. it should be whatever assets were on the inputs, minus the amount that was deposited, minus the fee,
99102
// plus the relevant LP tokens

lib/tests/aiken/deposit.ak

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,18 @@ test deposit_test() {
2121
)
2222
}
2323

24+
test deposit_test_minimum() fail {
25+
deposit_test_schema(
26+
661_278_808_416,
27+
188_253_559_159_646,
28+
153_000_000,
29+
150,
30+
151_171_875,
31+
150,
32+
value.from_lovelace(152_000_000)
33+
)
34+
}
35+
2436
fn deposit_test_schema(qa: Int, qb: Int, has_a: Int, has_b: Int, gives_a: Int, gives_b: Int, out_value: value.Value) {
2537
let addr =
2638
Address(
@@ -80,4 +92,3 @@ fn deposit_test_schema(qa: Int, qb: Int, has_a: Int, has_b: Int, gives_a: Int, g
8092
// Test should pass as long as do_deposit didn't throw
8193
True
8294
}
83-

0 commit comments

Comments
 (0)