Skip to content

Commit

Permalink
refactor: fix rust swap quote and test after switch to dlmm interface
Browse files Browse the repository at this point in the history
  • Loading branch information
codewithgun committed Dec 23, 2024
1 parent 7b0a112 commit 0b1570c
Show file tree
Hide file tree
Showing 29 changed files with 1,561 additions and 316 deletions.
93 changes: 8 additions & 85 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 26 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,40 @@ resolver = "2"
anchor-lang = "0.28.0"
anchor-spl = "0.28.0"
anchor-client = "0.28.0"
clap = "4.3.3"
anyhow = "1.0.71"
shellexpand = "3.1.0"
rust_decimal = "1.31.0"

solana-sdk = "1.16.0"
spl-associated-token-account = "1"
mpl-token-metadata = "3.0.1"
rand = "0.8.5"
tokio = "~1.14.1"
solana-transaction-status = "1.16.0"

serde_json = "1.0.48"
serde = "1.0.104"
solana-transaction-status = "1.16.12"
bincode = "1.3.3"
bs58 = "0.5.0"

clap = "4.3.3"
shellexpand = "3.1.0"

env_logger = "0.9.0"
log = "0.4.17"
bs58 = "0.5.0"
chrono = "0.4.31"

rust_decimal = "1.31.0"
ruint = "1.3.0"
num-integer = "0.1.45"
num-traits = "0.2.16"

hyper = "0.14.17"
routerify = "3"

tokio = "~1.14.1"

anyhow = "1.0.71"

rand = "0.8.5"

chrono = "0.4.31"

ureq = "2.0.0"
bincode = "1.3.3"

commons = { path = "./commons" }

[profile.release]
Expand Down
3 changes: 1 addition & 2 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ clap = { workspace = true, features = ["derive"] }
anyhow = { workspace = true }
shellexpand = { workspace = true }
rust_decimal = { workspace = true, features = ["maths"] }
lb_clmm = { path = "../programs/lb_clmm", features = ["cpi"] }
dlmm_interface = { path = "../dlmm_interface" }
spl-associated-token-account = { workspace = true }
mpl-token-metadata = { workspace = true }
rand = { workspace = true }
tokio = { workspace = true, features = ["full", "parking_lot"] }
bincode = { workspace = true }
Expand Down
13 changes: 7 additions & 6 deletions commons/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,17 @@ authors = ["tian <[email protected]>"]
[dependencies]
anchor-client = { workspace = true, features = ["async"] }
anyhow = { workspace = true }
lb_clmm = { path = "../programs/lb_clmm", features = ["cpi"] }
dlmm_interface = { path = "../dlmm_interface" }
tokio = { workspace = true, features = ["full", "parking_lot"] }
bincode = "1.3.3"
bincode = { workspace = true }
solana-sdk = { workspace = true }
ruint = { workspace = true }
num-traits = { workspace = true }
num-integer = { workspace = true }

[dev-dependencies]
anchor-lang = { workspace = true }
anchor-spl = { workspace = true }
spl-associated-token-account = { workspace = true }
solana-program-test = "1.16.0"
solana-sdk = "1.16.0"
async-trait = "0.1.52"
assert_matches = "1.5.0"
spl-associated-token-account = { workspace = true }
solana-program = "1.16.0"
76 changes: 76 additions & 0 deletions commons/src/constants.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
pub const BASIS_POINT_MAX: i32 = 10000;

/// Maximum number of bin a bin array able to contains.
pub const MAX_BIN_PER_ARRAY: usize = 70;

/// Default number of bin per position contains.
pub const DEFAULT_BIN_PER_POSITION: usize = 70;

/// Max resize length allowed
pub const MAX_RESIZE_LENGTH: usize = 70;

/// Maximum number of bin per position contains.
pub const POSITION_MAX_LENGTH: usize = 1400;

/// Minimum bin ID supported. Computed based on 1 bps.
pub const MIN_BIN_ID: i32 = -443636;

/// Maximum bin ID supported. Computed based on 1 bps.
pub const MAX_BIN_ID: i32 = 443636;

/// Maximum fee rate. 10%
pub const MAX_FEE_RATE: u64 = 100_000_000;

pub const FEE_PRECISION: u64 = 1_000_000_000;

/// Maximum protocol share of the fee. 25%
pub const MAX_PROTOCOL_SHARE: u16 = 2_500;

/// Host fee. 20%
pub const HOST_FEE_BPS: u16 = 2_000;

// Number of rewards supported by pool
pub const NUM_REWARDS: usize = 2;

// Minimum reward duration
pub const MIN_REWARD_DURATION: u64 = 1;

pub const MAX_REWARD_DURATION: u64 = 31536000; // 1 year = 365 * 24 * 3600

pub const DEFAULT_OBSERVATION_LENGTH: u64 = 100;

pub const SAMPLE_LIFETIME: u64 = 120; // 2

pub const EXTENSION_BINARRAY_BITMAP_SIZE: usize = 12;

pub const BIN_ARRAY_BITMAP_SIZE: i32 = 512;

pub const MAX_BASE_FACTOR_STEP: u16 = 100; // 100 bps, 1%

pub const MAX_FEE_UPDATE_WINDOW: i64 = 0;

pub const MAX_REWARD_BIN_SPLIT: usize = 15;

pub const SLOT_BUFFER: u64 = 9000;

pub const TIME_BUFFER: u64 = 3600;

pub const MAX_ACTIVATION_SLOT_DURATION: u64 = SLOT_BUFFER * 24 * 31; // 31 days

pub const MAX_ACTIVATION_TIME_DURATION: u64 = TIME_BUFFER * 24 * 31; // 31 days

pub const FIVE_MINUTES_SLOT_BUFFER: u64 = SLOT_BUFFER / 12; // 5 minutes

pub const FIVE_MINUTES_TIME_BUFFER: u64 = TIME_BUFFER / 12; // 5 minutes

// ILM token launch protocol fee
pub const ILM_PROTOCOL_SHARE: u16 = 2000; // 20%

/// Maximum bin step
pub const MAX_BIN_STEP: u16 = 400;

/// Maximum base fee, base_fee / 10^9 = fee_in_percentage
pub const MAX_BASE_FEE: u128 = 100_000_000; // 10% (10^9 * 10 / 100)

/// Minimum base fee
pub const MIN_BASE_FEE: u128 = 100_000; // 0.01% (10^9 * 0.01 / 100)
24 changes: 24 additions & 0 deletions commons/src/conversions/activation_type.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
use dlmm_interface::ActivationType;
use std::ops::Deref;

pub struct ActivationTypeWrapper(ActivationType);

impl Deref for ActivationTypeWrapper {
type Target = ActivationType;

fn deref(&self) -> &Self::Target {
&self.0
}
}

impl TryFrom<u8> for ActivationTypeWrapper {
type Error = anyhow::Error;

fn try_from(value: u8) -> Result<Self, Self::Error> {
match value {
0 => Ok(ActivationTypeWrapper(ActivationType::Slot)),
1 => Ok(ActivationTypeWrapper(ActivationType::Timestamp)),
_ => Err(anyhow::anyhow!("Invalid ActivationType value: {}", value)),
}
}
}
8 changes: 8 additions & 0 deletions commons/src/conversions/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
pub mod status;
pub use status::*;

pub mod pair_type;
pub use pair_type::*;

pub mod activation_type;
pub use activation_type::*;
25 changes: 25 additions & 0 deletions commons/src/conversions/pair_type.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
use dlmm_interface::PairType;
use std::ops::Deref;

pub struct PairTypeWrapper(PairType);

impl Deref for PairTypeWrapper {
type Target = PairType;

fn deref(&self) -> &Self::Target {
&self.0
}
}

impl TryFrom<u8> for PairTypeWrapper {
type Error = anyhow::Error;

fn try_from(value: u8) -> Result<Self, Self::Error> {
match value {
0 => Ok(PairTypeWrapper(PairType::Permissionless)),
1 => Ok(PairTypeWrapper(PairType::Permission)),
2 => Ok(PairTypeWrapper(PairType::CustomizablePermissionless)),
_ => Err(anyhow::anyhow!("Invalid PairType value: {}", value)),
}
}
}
Loading

0 comments on commit 0b1570c

Please sign in to comment.