Skip to content

Commit

Permalink
Merge pull request #9 from mootz12/main
Browse files Browse the repository at this point in the history
Comet Feedback
  • Loading branch information
0xtempest authored Apr 30, 2024
2 parents dac8a38 + 05b4b7a commit b9bc3c9
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 14 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Stellar Expert WASM Release
on:
push:
tags:
- 'v*' # triggered whenever a new tag (previxed with "v") is pushed to the repository
jobs:
release-contract-governor:
uses: stellar-expert/soroban-build-workflow/.github/workflows/release.yml@main
with:
release_name: ${{ github.ref_name }}
release_description: 'Comet Factory Release'
relative_path: '["factory"]'
package: 'factory'
secrets:
release_token: ${{ secrets.GITHUB_TOKEN }}

release-contract-votes:
uses: stellar-expert/soroban-build-workflow/.github/workflows/release.yml@main
with:
release_name: ${{ github.ref_name }}
release_description: 'Comet Pool Release'
relative_path: '["contracts"]'
package: 'contracts'
secrets:
release_token: ${{ secrets.GITHUB_TOKEN }}
20 changes: 10 additions & 10 deletions contracts/src/c_pool/call_logic/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ pub fn execute_swap_exact_amount_in(
user: Address,
) -> (i128, i128) {
assert_with_error!(&e, !read_freeze(&e), Error::ErrFreezeOnlyWithdrawals);
assert_with_error!(&e, token_amount_in >= 0, Error::ErrNegative);
assert_with_error!(&e, token_amount_in > 0, Error::ErrNegativeOrZero);
assert_with_error!(&e, min_amount_out >= 0, Error::ErrNegative);
assert_with_error!(&e, max_price >= 0, Error::ErrNegative);

Expand All @@ -136,7 +136,7 @@ pub fn execute_swap_exact_amount_in(
token_amount_in
<= in_record
.balance
.fixed_mul_ceil(MAX_IN_RATIO, STROOP)
.fixed_mul_floor(MAX_IN_RATIO, STROOP)
.unwrap_optimized(),
Error::ErrMaxInRatio
);
Expand Down Expand Up @@ -217,8 +217,8 @@ pub fn execute_swap_exact_amount_out(
user: Address,
) -> (i128, i128) {
assert_with_error!(&e, !read_freeze(&e), Error::ErrFreezeOnlyWithdrawals);
assert_with_error!(&e, token_amount_out >= 0, Error::ErrNegative);
assert_with_error!(&e, max_amount_in >= 0, Error::ErrNegative);
assert_with_error!(&e, token_amount_out > 0, Error::ErrNegativeOrZero);
assert_with_error!(&e, max_amount_in > 0, Error::ErrNegativeOrZero);
assert_with_error!(&e, max_price >= 0, Error::ErrNegative);

let swap_fee = read_swap_fee(&e);
Expand All @@ -234,7 +234,7 @@ pub fn execute_swap_exact_amount_out(
token_amount_out
<= out_record
.balance
.fixed_mul_ceil(MAX_OUT_RATIO, STROOP)
.fixed_mul_floor(MAX_OUT_RATIO, STROOP)
.unwrap_optimized(),
Error::ErrMaxOutRatio
);
Expand Down Expand Up @@ -321,7 +321,7 @@ pub fn execute_dep_tokn_amt_in_get_lp_tokns_out(
token_amount_in
<= in_record
.balance
.fixed_mul_ceil(MAX_IN_RATIO, STROOP)
.fixed_mul_floor(MAX_IN_RATIO, STROOP)
.unwrap_optimized(),
Error::ErrMaxInRatio
);
Expand Down Expand Up @@ -392,7 +392,7 @@ pub fn execute_dep_lp_tokn_amt_out_get_tokn_in(
token_amount_in
<= in_record
.balance
.fixed_mul_ceil(MAX_IN_RATIO, STROOP)
.fixed_mul_floor(MAX_IN_RATIO, STROOP)
.unwrap_optimized(),
Error::ErrMaxInRatio
);
Expand Down Expand Up @@ -447,9 +447,9 @@ pub fn execute_wdr_tokn_amt_in_get_lp_tokns_out(
token_amount_out
<= out_record
.balance
.fixed_mul_ceil(MAX_OUT_RATIO, STROOP)
.fixed_mul_floor(MAX_OUT_RATIO, STROOP)
.unwrap_optimized(),
Error::ErrMaxInRatio
Error::ErrMaxOutRatio
);
assert_with_error!(
&e,
Expand Down Expand Up @@ -495,7 +495,7 @@ pub fn execute_wdr_tokn_amt_out_get_lp_tokns_in(
token_amount_out
<= out_record
.balance
.fixed_mul_ceil(MAX_OUT_RATIO, STROOP)
.fixed_mul_floor(MAX_OUT_RATIO, STROOP)
.unwrap_optimized(),
Error::ErrMaxOutRatio
);
Expand Down
4 changes: 2 additions & 2 deletions contracts/src/tests/c_pool_single_sided.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,12 +288,12 @@ fn test_single_sided_wdr() {
let bal_token_out_fixed = bal_token_out.to_i128(&7);
let under_out = bal_token_out_fixed - 1000;

// verify MAX_IN_RATIO
// verify MAX_OUT_RATIO
let result = comet.try_wdr_tokn_amt_in_get_lp_tokns_out(&token_1, &99_9999999, &0, &admin);
assert_eq!(
result.err(),
Some(Ok(Error::from_contract_error(
CometError::ErrMaxInRatio as u32
CometError::ErrMaxOutRatio as u32
)))
);

Expand Down
30 changes: 28 additions & 2 deletions contracts/src/tests/c_pool_swap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,16 @@ fn test_swap_out_given_in() {
assert_eq!(
result.err(),
Some(Ok(Error::from_contract_error(
CometError::ErrNegative as u32
CometError::ErrNegativeOrZero as u32
)))
);

// verify zero input
let result = comet.try_swap_exact_amount_in(&token_1, &0, &token_2, &0, &i128::MAX, &user);
assert_eq!(
result.err(),
Some(Ok(Error::from_contract_error(
CometError::ErrNegativeOrZero as u32
)))
);

Expand Down Expand Up @@ -228,7 +237,24 @@ fn test_swap_in_given_out() {
assert_eq!(
result.err(),
Some(Ok(Error::from_contract_error(
CometError::ErrNegative as u32
CometError::ErrNegativeOrZero as u32
)))
);

// verify zero input
let result =
comet.try_swap_exact_amount_out(&token_2, &i128::MAX, &token_1, &0, &i128::MAX, &user);
assert_eq!(
result.err(),
Some(Ok(Error::from_contract_error(
CometError::ErrNegativeOrZero as u32
)))
);
let result = comet.try_swap_exact_amount_out(&token_2, &0, &token_1, &1, &i128::MAX, &user);
assert_eq!(
result.err(),
Some(Ok(Error::from_contract_error(
CometError::ErrNegativeOrZero as u32
)))
);

Expand Down

0 comments on commit b9bc3c9

Please sign in to comment.