diff --git a/apps/rooch_dex/sources/route.move b/apps/rooch_dex/sources/route.move index 08a086b3cc..5818c4a811 100644 --- a/apps/rooch_dex/sources/route.move +++ b/apps/rooch_dex/sources/route.move @@ -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( sender: &signer, + amount_x_desired: u64, + amount_y_desired: u64, + amount_x_min: u64, + amount_y_min: u64, ) { + assert!(!(swap::is_pair_created() || swap::is_pair_created()), ErrorTokenPairAlreadyExist); if (swap_utils::sort_token_type()) { - swap::create_pair(sender); + let coin_info_id = swap::create_pair(sender); + add_liquidity(sender, amount_x_desired, amount_y_desired, amount_x_min, amount_y_min, coin_info_id); } else { - swap::create_pair(sender); - } + let coin_info_id = swap::create_pair(sender); + add_liquidity(sender, amount_x_desired, amount_y_desired, amount_x_min, amount_y_min, coin_info_id); + }; + } @@ -35,9 +44,6 @@ module rooch_dex::router { amount_y_min: u64, coin_info: ObjectID, ) { - if (!(swap::is_pair_created() || swap::is_pair_created())) { - create_token_pair(sender); - }; let amount_x; let amount_y; diff --git a/apps/rooch_dex/sources/swap.move b/apps/rooch_dex/sources/swap.move index b45e7b75db..63f90d5122 100644 --- a/apps/rooch_dex/sources/swap.move +++ b/apps/rooch_dex/sources/swap.move @@ -116,7 +116,7 @@ module rooch_dex::swap { /// Create the specified coin pair public(friend) fun create_pair( sender: &signer, - ) { + ): ObjectID { assert!(!is_pair_created(), ErrorAlreadyExists); let sender_addr = signer::address_of(sender); @@ -140,6 +140,7 @@ module rooch_dex::swap { 8, ); + let coin_info_id = object::id(&coin_info); account::move_resource_to>( &resource_signer, TokenPairReserve { @@ -174,6 +175,7 @@ module rooch_dex::swap { ); object::to_shared(coin_info); + return coin_info_id }