Skip to content

Commit

Permalink
fix: assert add liquidity when create token pair (#3214)
Browse files Browse the repository at this point in the history
  • Loading branch information
mx819812523 authored Jan 21, 2025
1 parent f3f6a76 commit 0679eb9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
18 changes: 12 additions & 6 deletions apps/rooch_dex/sources/route.move
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,25 @@ module rooch_dex::router {
const ErrorInsufficientXAmount: u64 = 3;
const ErrorInsufficientYAmount: u64 = 4;
const ErrorTokenPairNotExist: u64 = 5;
const ErrorTokenPairAlreadyExist: u64 = 6;


public entry fun create_token_pair<X:key+store, Y:key+store>(
sender: &signer,
amount_x_desired: u64,
amount_y_desired: u64,
amount_x_min: u64,
amount_y_min: u64,
) {
assert!(!(swap::is_pair_created<X, Y>() || swap::is_pair_created<Y, X>()), ErrorTokenPairAlreadyExist);
if (swap_utils::sort_token_type<X, Y>()) {
swap::create_pair<X, Y>(sender);
let coin_info_id = swap::create_pair<X, Y>(sender);
add_liquidity<X, Y>(sender, amount_x_desired, amount_y_desired, amount_x_min, amount_y_min, coin_info_id);
} else {
swap::create_pair<Y, X>(sender);
}
let coin_info_id = swap::create_pair<Y, X>(sender);
add_liquidity<Y, X>(sender, amount_x_desired, amount_y_desired, amount_x_min, amount_y_min, coin_info_id);
};

}


Expand All @@ -35,9 +44,6 @@ module rooch_dex::router {
amount_y_min: u64,
coin_info: ObjectID,
) {
if (!(swap::is_pair_created<X, Y>() || swap::is_pair_created<Y, X>())) {
create_token_pair<X, Y>(sender);
};

let amount_x;
let amount_y;
Expand Down
4 changes: 3 additions & 1 deletion apps/rooch_dex/sources/swap.move
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ module rooch_dex::swap {
/// Create the specified coin pair
public(friend) fun create_pair<X:key+store, Y:key+store>(
sender: &signer,
) {
): ObjectID {
assert!(!is_pair_created<X, Y>(), ErrorAlreadyExists);

let sender_addr = signer::address_of(sender);
Expand All @@ -140,6 +140,7 @@ module rooch_dex::swap {
8,
);

let coin_info_id = object::id(&coin_info);
account::move_resource_to<TokenPairReserve<X, Y>>(
&resource_signer,
TokenPairReserve {
Expand Down Expand Up @@ -174,6 +175,7 @@ module rooch_dex::swap {
);

object::to_shared(coin_info);
return coin_info_id
}


Expand Down

0 comments on commit 0679eb9

Please sign in to comment.