Developer
Last updated
0xc7ea756470f72ae761b7986e4ed6fd409aad183b1b2d3d2f674d979852f45c4b const POOL_TYPE_PIECEWISE:u8 = 3; // V1 type
const POOL_TYPE_SS2:u8 = 4; // V2 type
const POOL_TYPE_SS3_ABEL:u8 = 6; // V3 type
/*
Execute 1 swap action
Swaps X to Y
so X,Y,Z are arranged in swap order, not pool order
*/
public entry fun one_step_route_script<X, Y>(
sender: &signer,
first_pool_type: u8,
first_is_x_to_y: bool, // whether first trade uses normal order
x_in: u64,
y_min_out: u64,
) {}
/*
Execute 2 swap actions back-to-back.
Swaps X to Y to Z
so X,Y,Z are arranged in swap order, not pool order
*/
public entry fun two_step_route_script<X, Y, Z>(
sender: &signer,
first_pool_type: u8,
first_is_x_to_y: bool, // whether first trade uses normal order
second_pool_type: u8,
second_is_x_to_y: bool, // whether second trade uses normal order
x_in: u64,
z_min_out: u64,
) {}
/*
Execute 3 swap actions back-to-back.
Swaps X to Y to Z to A
so X,Y,Z are arranged in swap order, not pool order
*/
public entry fun three_step_route_script<X, Y, Z, A>(
sender: &signer,
first_pool_type: u8,
first_is_x_to_y: bool, // whether first trade uses normal order
second_pool_type: u8,
second_is_x_to_y: bool, // whehter second trade uses normal order
third_pool_type: u8,
third_is_x_to_y: bool, // whether third trade uses normal order
x_in: u64,
a_min_out: u64,
) {}public entry fun swap_script<X, Y>(
sender: &signer,
x_in: u64,
y_in: u64,
x_min_out: u64,
y_min_out: u64,
) {
assert!(!(x_in > 0 && y_in > 0), E_SWAP_ONLY_ONE_IN_ALLOWED);
assert!(!(x_min_out > 0 && y_min_out > 0), E_SWAP_ONLY_ONE_OUT_ALLOWED);
// X to Y
if (x_in > 0) {
let y_out = piece_swap::swap_x_to_y<X, Y>(sender, x_in);
assert!(y_out >= y_min_out, E_OUTPUT_LESS_THAN_MIN);
}
else if (y_in > 0) {
let x_out = piece_swap::swap_y_to_x<X, Y>(sender, y_in);
assert!(x_out >= x_min_out, E_OUTPUT_LESS_THAN_MIN);
}
else {
assert!(false, E_SWAP_NONZERO_INPUT_REQUIRED);
}
}public entry fun swap_x_to_y<X, Y>(user: &signer, amount: u64, min_out: u64) {
let input_x = coin::withdraw<X>(user, amount);
let output_y = ssswap2::swap_x_to_y<X, Y>(input_x);
assert!(coin::value(&output_y) >= min_out, ERR_OUTPUT_NOT_ENOUGH);
check_and_deposit(user, output_y);
}
public entry fun swap_y_to_x<X, Y>(user: &signer, amount: u64, min_out: u64) {
let input_y = coin::withdraw<Y>(user, amount);
let output_x = ssswap2::swap_y_to_x<X, Y>(input_y);
assert!(coin::value(&output_x) >= min_out, ERR_OUTPUT_NOT_ENOUGH);
check_and_deposit(user, output_x);
}public entry fun swap_x_to_y<X, Y>(user: &signer, amount: u64, min_out: u64){
let input_x = coin::withdraw<X>(user, amount);
let output_y = ss3swapAbel::swap_x_to_y<X, Y>(input_x);
assert!(coin::value(&output_y) >= min_out, ERR_OUTPUT_NOT_ENOUGH);
check_and_deposit(user, output_y);
}
public entry fun swap_y_to_x<X, Y>(user: &signer, amount: u64, min_out: u64){
let input_y = coin::withdraw<Y>(user, amount);
let output_x = ss3swapAbel::swap_y_to_x<X, Y>(input_y);
assert!(coin::value(&output_x) >= min_out, ERR_OUTPUT_NOT_ENOUGH);
check_and_deposit(user, output_x);
}public fun swap_x_to_y_direct<X, Y>(coin_x: coin::Coin<X>): coin::Coin<Y> {}
public fun swap_y_to_x_direct<X, Y>(coin_y: coin::Coin<Y>): coin::Coin<X> {}public fun swap_x_to_y<X, Y>(input_x: coin::Coin<X>): coin::Coin<Y> {}
public fun swap_y_to_x<X, Y>(input_y: coin::Coin<Y>): coin::Coin<X> {}public fun swap_x_to_y<X, Y>(input_x: coin::Coin<X>): coin::Coin<Y> {}
public fun swap_y_to_x<X, Y>(input_y: coin::Coin<Y>): coin::Coin<X> {}export const PROGRAM_IDS = {
V2: new PublicKey('EaBNtqenvVqpMoXAjYH6H91jLfVSiygczCCDDufwoVop'),
V3: new PublicKey('BYxcSnZ1HEPGHaQ9RNaoGmzdzDBRWWnp9W553vjM7PGP'),
}