Skip to content

Commit

Permalink
Initialize permission pair (#44)
Browse files Browse the repository at this point in the history
* prepara lfg permissionless

* fix mm bot unreachable string parsing;

* fix cli
  • Loading branch information
codewithgun authored Apr 9, 2024
1 parent ae7118b commit 59e5b6b
Show file tree
Hide file tree
Showing 39 changed files with 9,962 additions and 772 deletions.
7 changes: 5 additions & 2 deletions Anchor.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ seeds = false
skip-lint = false

[programs.localnet]
lb_clmm = { address = "GrAkKfEpTKQuVHG2Y97Y2FF4i7y7Q5AHLK94JBy7Y5yv", idl = "target/idl/id.json" }
lb_clmm = { address = "GrAkKfEpTKQuVHG2Y97Y2FF4i7y7Q5AHLK94JBy7Y5yv", idl = "target/idl/id.json" }

[registry]
url = "https://api.apr.dev"
Expand All @@ -27,4 +27,7 @@ build-local = "anchor build"
deploy-local = "solana program deploy target/deploy/lb_clmm.so --keypair keys/localnet/admin-bossj3JvwiNK7pvjr149DqdtJxf2gdygbcmEPTkb2F1.json --program-id keys/localnet/program-LbVRzDTvBDEcrthxfZ4RL6yiq3uZw8bS6MwtdY6UhFQ.json"

[[test.validator.account_dir]]
directory = "./artifacts/alpha-access"
directory = "./artifacts/alpha-access"

[test]
startup_wait = 50000
Binary file modified artifacts/lb_clmm.so
Binary file not shown.
94 changes: 37 additions & 57 deletions cli/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,6 @@ pub enum Command {
token_mint_y: Pubkey,
/// The initial price of the liquidity pair. Eg: 24123.12312412 USDC per 1 BTC.
initial_price: f64,
/// Permission
#[clap(short, long)]
permission: bool,
},
/// Initialize bin array for the given liquidity pair. Use InitializeBinArrayWithPriceRange or InitializeBinArrayWithBinRange for a more user friendly version.
InitializeBinArray {
Expand Down Expand Up @@ -293,94 +290,77 @@ pub struct Cli {

#[derive(Debug, Parser)]
pub enum AdminCommand {
/// Enable or disable a permission pool
TogglePoolStatus {
/// Address of the pair
lb_pair: Pubkey,
},

/// Enable or disable a permission pool
TogglePoolStatus2 {
/// bin step
/// Create a new permission liquidity pair. It allow liquidity fragmentation with exact bin step.
InitializePermissionPair {
/// Bin step of the liquidity pair. It decide the bps when between bins.
bin_step: u16,
/// Token X mint of the liquidity pair. Eg: BTC. This should be the base token.
token_mint_x: Pubkey,
/// Token Y mint of the liquidity pair. Eg: USDC. This should be the quote token.
token_mint_y: Pubkey,
/// permission:
#[clap(short, long)]
permission: bool,
/// The initial price of the liquidity pair. Eg: 24123.12312412 USDC per 1 BTC.
initial_price: f64,
/// Base keypair path
base_keypair_path: String,
/// Base fee bps
base_fee_bps: u16,
/// Lock duration for bootstrap liquidity position
lock_duration_in_slot: u64,
},

UpdateWhitelistedWallet2 {
/// bin step
bin_step: u16,
/// Token X mint of the liquidity pair. Eg: BTC. This should be the base token.
token_mint_x: Pubkey,
/// Token Y mint of the liquidity pair. Eg: USDC. This should be the quote token.
token_mint_y: Pubkey,
/// permission:
#[clap(short, long)]
permission: bool,
/// Index of the wallet to be updated
idx: u8,
/// Wallet address to be whitelisted
wallet_address: Pubkey,
/// Toggle pool status
TogglePoolStatus {
/// Address of the pair
lb_pair: Pubkey,
},

/// Seed liquidity
SeedLiquidity {
/// base key for pool
bin_step: u16,
/// permission:
#[clap(short, long)]
permission: bool,
// base position path
/// Address of the pair
lb_pair: Pubkey,
/// Base position path
base_position_path: String,
/// Token X mint of the liquidity pair. Eg: BTC. This should be the base token.
token_mint_x: Pubkey,
/// Token Y mint of the liquidity pair. Eg: USDC. This should be the quote token.
token_mint_y: Pubkey,
/// amount of x
amount: u64,
/// min price
min_price: f64,
/// max price
max_price: f64,
},

/// Remove liquidity by price range
RemoveLiquidityByPriceRange {
/// base key for pool
bin_step: u16,
/// permission:
#[clap(short, long)]
permission: bool,
/// Address of the pair
lb_pair: Pubkey,
// base position path
base_position_key: Pubkey,
/// Token X mint of the liquidity pair. Eg: BTC. This should be the base token.
token_mint_x: Pubkey,
/// Token Y mint of the liquidity pair. Eg: USDC. This should be the quote token.
token_mint_y: Pubkey,
/// min price
min_price: f64,
/// max price
max_price: f64,
},

CheckMyBalance {
/// base key for pool
bin_step: u16,
/// permission:
#[clap(short, long)]
permission: bool,
/// Address of the pair
lb_pair: Pubkey,
// base position path
base_position_key: Pubkey,
/// Token X mint of the liquidity pair. Eg: BTC. This should be the base token.
token_mint_x: Pubkey,
/// Token Y mint of the liquidity pair. Eg: USDC. This should be the quote token.
token_mint_y: Pubkey,
/// min price
min_price: f64,
/// max price
max_price: f64,
},

SetActivationSlot {
/// Address of the pair
lb_pair: Pubkey,
/// Activation slot
activation_slot: u64,
},

SetSwapCapAmount {
lb_pair: Pubkey,
swap_cap_amount: u64,
swap_cap_deactivate_slot: u64,
},
}
22 changes: 5 additions & 17 deletions cli/src/instructions/check_my_balance.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::math::get_id_from_price;
use crate::math::price_per_token_to_per_lamport;
use anchor_client::{solana_sdk::pubkey::Pubkey, solana_sdk::signer::Signer, Program};
use anchor_spl::token::TokenAccount;
use anchor_spl::token_interface::Mint;
use anyhow::*;
use lb_clmm::constants::{MAX_BIN_PER_ARRAY, MAX_BIN_PER_POSITION};
Expand All @@ -18,11 +17,8 @@ use std::ops::Deref;
use std::result::Result::Ok;
#[derive(Debug)]
pub struct CheckMyBalanceParameters {
pub bin_step: u16,
pub permission: bool,
pub lb_pair: Pubkey,
pub base_position_key: Pubkey,
pub token_mint_x: Pubkey,
pub token_mint_y: Pubkey,
pub min_price: f64,
pub max_price: f64,
}
Expand All @@ -32,18 +28,15 @@ pub async fn check_my_balance<C: Deref<Target = impl Signer> + Clone>(
program: &Program<C>,
) -> Result<()> {
let CheckMyBalanceParameters {
bin_step,
permission,
lb_pair,
base_position_key,
token_mint_x,
token_mint_y,
min_price,
max_price,
} = params;
let (lb_pair, _bump) = derive_lb_pair_pda(token_mint_x, token_mint_y, bin_step, permission);
let lb_pair_state = program.account::<LbPair>(lb_pair).await?;

let token_mint_base: Mint = program.account(token_mint_x).await?;
let token_mint_quote: Mint = program.account(token_mint_y).await?;
let token_mint_base: Mint = program.account(lb_pair_state.token_x_mint).await?;
let token_mint_quote: Mint = program.account(lb_pair_state.token_y_mint).await?;

let lb_pair_state: LbPair = program.account(lb_pair).await?;

Expand Down Expand Up @@ -104,8 +97,6 @@ pub async fn check_my_balance<C: Deref<Target = impl Signer> + Clone>(
let (amount_x, amount_y) = bin.calculate_out_amount(share)?;
total_amount_x = total_amount_x.safe_add(amount_x).unwrap();
total_amount_y = total_amount_y.safe_add(amount_y).unwrap();

// println!("bin: {bin_id} amount_x: {amount_x} amount_y: {amount_y}");
}

let (fee_x_pending, fee_y_pending) =
Expand All @@ -126,9 +117,6 @@ pub async fn check_my_balance<C: Deref<Target = impl Signer> + Clone>(
let total_fee_y_pending =
total_fee_y_pending as f64 / (10u64.pow(token_mint_quote.decimals as u32) as f64);

let reserve_x: TokenAccount = program.account(lb_pair_state.reserve_x).await.unwrap();
println!("{}", reserve_x.amount);

println!(
"amount_x {total_amount_x} amount_y {total_amount_y} fee_x_pending {total_fee_x_pending} fee_y_pending {total_fee_y_pending}"
);
Expand Down
Loading

0 comments on commit 59e5b6b

Please sign in to comment.