Skip to content

Commit

Permalink
add swap
Browse files Browse the repository at this point in the history
  • Loading branch information
liyuliang committed Aug 30, 2022
1 parent 675f160 commit 5c3d19c
Show file tree
Hide file tree
Showing 8 changed files with 1,484 additions and 23 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build/
2 changes: 1 addition & 1 deletion Move.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ rev = 'a58060f88d66b90a0548a506e22270b04a328db3'
subdir = 'aptos-move/framework/aptos-framework'

[addresses]
cetus_amm = "0x1"
cetus_amm = "_"
7 changes: 7 additions & 0 deletions sources/amm_config.move
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module cetus_amm::config {
//

const ECONFIG_NOT_HAS_PRIVILEGE: u64 = 1001;
const ECONFIG_POOL_PAUSE: u64 = 1002;

struct PoolFeeConfig has key {
trade_fee_numerator: u64,
Expand Down Expand Up @@ -84,5 +85,11 @@ module cetus_amm::config {
error::invalid_argument(ECONFIG_NOT_HAS_PRIVILEGE));
}

public fun assert_pause() acquires PoolPauseStatus {
assert!(
!get_pool_pause(),
error::invalid_argument(ECONFIG_POOL_PAUSE));
}


}
2 changes: 1 addition & 1 deletion sources/amm_math.move
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module cetus_amm::amm_math {
public fun safe_compare_mul_u128(a1: u128, b1: u128, a2: u128, b2: u128): u8 {
let left = u256::mul(u256::from_u128(a1), u256::from_u128(b1));
let right = u256::mul(u256::from_u128(a2), u256::from_u128(b2));
u256::compare(left, right)
u256::compare(&left, &right)
}

public fun safe_mul_div_u128(x: u128, y: u128, z: u128): u128 {
Expand Down
43 changes: 33 additions & 10 deletions sources/amm_script.move
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,27 @@ module cetus_amm::amm_script {
use cetus_amm::config;
use cetus_amm::amm_swap;

public entry fun init_fee_config() {

public entry fun set_pool_fee_config(
account: signer,
trade_fee_numerator: u64,
trade_fee_denominator: u64,
protocol_fee_numerator: u64,
protocol_fee_denominator: u64
) {
config::set_pool_fee_config(
&account,
trade_fee_numerator,
trade_fee_denominator,
protocol_fee_numerator,
protocol_fee_denominator,
)
}

public entry fun register_pool<CoinTypeA, CoinTypeB>(account: signer) {

public entry fun init_pool<CoinTypeA, CoinTypeB>(account: signer, protocol_fee_to: address) {
amm_swap::init_pool<CoinTypeA, CoinTypeB> (
&account,
protocol_fee_to,
)
}

/// Add liquidity for user
Expand Down Expand Up @@ -38,23 +53,31 @@ module cetus_amm::amm_script {
amount_b_min);
}

public entry fun swap_exact_token_for_token<CoinTypeA, CoinTypeB>(
public entry fun swap_exact_coin_for_coin<CoinTypeA, CoinTypeB>(
signer: signer,
amount_a_in: u128,
amount_b_out_min: u128,
) {

amm_swap::swap_exact_coin_for_coin<CoinTypeA, CoinTypeB> (
&signer,
amount_a_in,
amount_b_out_min,
)
}

public entry fun swap_token_for_exact_token<CoinTypeX, CoinTypeY>(
public entry fun swap_coin_for_exact_coin<CoinTypeA, CoinTypeB>(
signer: signer,
amount_a_in_max: u128,
amount_b_out: u128,
) {

amm_swap::swap_coin_for_exact_coin<CoinTypeA, CoinTypeB> (
&signer,
amount_a_in_max,
amount_b_out,
)
}

public entry fun set_pause_status(status:bool) {

public entry fun set_pause_status(account: signer, pause:bool) {
config::set_pool_pause(&account, pause)
}
}
Loading

0 comments on commit 5c3d19c

Please sign in to comment.