Skip to content

Commit

Permalink
Support slot and timestamp activation (MeteoraAg#96)
Browse files Browse the repository at this point in the history
* feat: sync program update to support slot and timestamp activation

* fix: sync cli update to support slot and timestamp activation

* feat: sync ts-sdk to support slot and timestamp activation

* fix: CI rust

* chore: update changelog

* fix: ts-sdk test

* fix: CI rust

* chore: regenerate deleted artifacts

* fix: rust swap quote
  • Loading branch information
codewithgun authored Aug 23, 2024
1 parent 3226ec0 commit 4a064a6
Show file tree
Hide file tree
Showing 43 changed files with 1,023 additions and 608 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/ci-pr-main-cli.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ jobs:
# Install rust + toolchain
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
toolchain: 1.76.0
override: true
components: clippy
# Cache rust, cargo
- uses: Swatinem/rust-cache@v1
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/ci-pr-main-market-making.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ jobs:
# Install rust + toolchain
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
toolchain: 1.76.0
override: true
components: clippy
# Cache rust, cargo
- uses: Swatinem/rust-cache@v1
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/ci-pr-main-program.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ jobs:
# Install rust + toolchain
- uses: actions-rs/toolchain@v1
with:
toolchain: stable
toolchain: 1.76.0
override: true
components: clippy
# Cache rust, cargo
- uses: Swatinem/rust-cache@v1
Expand Down
60 changes: 60 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,66 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Security

## lb_clmm [0.8.0] - PR #96

### Added

- Pool supports 2 modes now defined by `activation_type`. If `activation_type == 0`, activation is calculated based on slot. If `activation_type == 1`, activation is calculated based on timestamp.

### Changed

- Pool state added a new field `activation_type`
- Rename `pool.activation_slot` to `pool.activation_point`
- Rename `pool.pre_activation_slot_duration` to `pool.pre_activation_duration`
- Rename `pool.lock_duration_in_slot` to `pool.lock_duration`
- Rename `position.lock_release_slot` to `position.lock_release_point`

### Breaking Changes

- The activation condition for all endpoints will by validated by slot or timestamp based on `activation_type` in pool state
- All program endpoints to modify permissioned pool will migrate parameters with post_fix `_slot` to `_point`
- Rename endpoint `set_activation_slot` to `set_activation_point`
- Rename endpoint `set_pre_activation_slot_duration` to `set_pre_activation_duration`
- Rename endpoint `set_lock_release_slot` to `set_lock_release_point`
- Endpoint `initialize_permission_lb_pair` requires a new field `activation_type` in input parameters

### Removed

- `update_fee_owner` endpoint is removed

## common [0.3.0] - PR #96

### Changed

- `quote_exact_out` and `quote_exact_in` throw error when pool is disabled, or not activated for swap yet.

### Breaking Changes

- `quote_exact_out` and `quote_exact_in` require a new field `current_slot` in input parameters

## cli [0.3.0] - PR #96

### Removed

- `update_fee_owner` command is removed

### Breaking Changes

- Rename command `set_activation_slot` to `set_activation_point`
- Rename command `set_pre_activation_slot_duration` to `set_pre_activation_duration`
- Command `initialize_permission_lb_pair` require new `activation_type` parameter

## @meteora-ag/dlmm [1.0.55] - PR #96

### Changed

- `swapQuoteExactOut` and `swapQuote` throw error when pool is disabled, or not activated for swap yet.

### Breaking Changes

- Renamed `setActivationSlot` to `setActivationPoint`
- `createPermissionLbPair` require new `ActivationType` parameter

## @mercurial-finance/dynamic-amm-sdk [1.0.54] - PR #99

### Fixed
Expand Down
6 changes: 3 additions & 3 deletions Cargo.lock

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

Binary file modified artifacts/lb_clmm.so
Binary file not shown.
2 changes: 1 addition & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "cli"
version = "0.2.0"
version = "0.3.0"
edition = "2021"
description = "cli"
authors = ["tian <[email protected]>"]
Expand Down
20 changes: 9 additions & 11 deletions cli/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,9 @@ pub enum AdminCommand {
/// Base fee bps
base_fee_bps: u16,
/// Lock duration for bootstrap liquidity position
lock_duration_in_slot: u64,
lock_duration: u64,
/// Activation type
activation_type: u8,
},

/// Toggle pool status
Expand Down Expand Up @@ -315,22 +317,18 @@ pub enum AdminCommand {
max_price: f64,
},

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

WithdrawProtocolFee {
lb_pair: Pubkey,
amount_x: u64,
amount_y: u64,
},
UpdateFeeOwner {
lb_pair: Pubkey,
fee_owner: Pubkey,
},

InitializeReward {
lb_pair: Pubkey,
Expand Down Expand Up @@ -382,11 +380,11 @@ pub enum AdminCommand {
preset_parameter: Pubkey,
},

SetPreActivationSlotDuration {
SetPreActivationDuration {
/// Address of the pair
lb_pair: Pubkey,
/// Preactivation slot duration
pre_activation_slot_duration: u16,
/// Preactivation duration
pre_activation_duration: u16,
},

SetPreActivationSwapAddress {
Expand Down
9 changes: 6 additions & 3 deletions cli/src/instructions/initialize_permission_lb_pair.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ pub struct InitPermissionLbPairParameters {
pub initial_price: f64,
pub base_fee_bps: u16,
pub base_keypair: Keypair,
pub lock_duration_in_slot: u64,
pub lock_duration: u64,
pub activation_type: u8,
}

pub async fn initialize_permission_lb_pair<C: Deref<Target = impl Signer> + Clone>(
Expand All @@ -40,7 +41,8 @@ pub async fn initialize_permission_lb_pair<C: Deref<Target = impl Signer> + Clon
initial_price,
base_fee_bps,
base_keypair,
lock_duration_in_slot,
lock_duration,
activation_type,
} = params;

let token_mint_base: Mint = program.account(token_mint_x).await?;
Expand Down Expand Up @@ -95,7 +97,8 @@ pub async fn initialize_permission_lb_pair<C: Deref<Target = impl Signer> + Clon
base_factor: compute_base_factor_from_fee_bps(bin_step, base_fee_bps)?,
max_bin_id,
min_bin_id,
lock_duration_in_slot,
lock_duration,
activation_type,
},
};

Expand Down
5 changes: 2 additions & 3 deletions cli/src/instructions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,15 @@ pub mod list_all_binstep;
pub mod remove_liquidity;
pub mod remove_liquidity_by_price_range;
pub mod seed_liquidity;
pub mod set_activation_slot;
pub mod set_pre_activation_slot_duration;
pub mod set_activation_point;
pub mod set_pre_activation_duration;
pub mod set_pre_activation_swap_address;
pub mod show_pair;
pub mod simulate_swap_demand;
pub mod swap_exact_in;
pub mod swap_exact_out;
pub mod swap_with_price_impact;
pub mod toggle_pair_status;
pub mod update_fee_owner;
pub mod update_reward_duration;
pub mod update_reward_funder;
pub mod update_whitelisted_wallet;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,42 +8,42 @@ use anchor_lang::{InstructionData, ToAccountMetas};
use anyhow::*;

#[derive(Debug)]
pub struct SetActivationSlotParam {
pub struct SetActivationPointParam {
pub lb_pair: Pubkey,
pub activation_slot: u64,
pub activation_point: u64,
}

pub async fn set_activation_slot<C: Deref<Target = impl Signer> + Clone>(
params: SetActivationSlotParam,
pub async fn set_activation_point<C: Deref<Target = impl Signer> + Clone>(
params: SetActivationPointParam,
program: &Program<C>,
transaction_config: RpcSendTransactionConfig,
) -> Result<()> {
let SetActivationSlotParam {
let SetActivationPointParam {
lb_pair,
activation_slot,
activation_point,
} = params;

let accounts = lb_clmm::accounts::SetActivationSlot {
let accounts = lb_clmm::accounts::SetActivationPoint {
admin: program.payer(),
lb_pair,
}
.to_account_metas(None);

let ix_data = lb_clmm::instruction::SetActivationSlot { activation_slot }.data();
let ix_data = lb_clmm::instruction::SetActivationPoint { activation_point }.data();

let set_activation_slot_ix = Instruction {
let set_activation_point_ix = Instruction {
accounts,
data: ix_data,
program_id: lb_clmm::ID,
};

let request_builder = program.request();
let signature = request_builder
.instruction(set_activation_slot_ix)
.instruction(set_activation_point_ix)
.send_with_spinner_and_config(transaction_config)
.await;

println!("Set activation slot. Signature: {:#?}", signature);
println!("Set activation point. Signature: {:#?}", signature);

signature?;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ use anchor_lang::{InstructionData, ToAccountMetas};
use anyhow::*;

#[derive(Debug)]
pub struct SetPreactivationSlotParam {
pub struct SetPreactivationDurationParam {
pub lb_pair: Pubkey,
pub pre_activation_slot_duration: u16,
pub pre_activation_duration: u16,
}

pub async fn set_pre_activation_slot_duration<C: Deref<Target = impl Signer> + Clone>(
params: SetPreactivationSlotParam,
pub async fn set_pre_activation_duration<C: Deref<Target = impl Signer> + Clone>(
params: SetPreactivationDurationParam,
program: &Program<C>,
transaction_config: RpcSendTransactionConfig,
) -> Result<()> {
let SetPreactivationSlotParam {
let SetPreactivationDurationParam {
lb_pair,
pre_activation_slot_duration,
pre_activation_duration,
} = params;

let accounts = lb_clmm::accounts::SetPreActivationInfo {
Expand All @@ -29,8 +29,8 @@ pub async fn set_pre_activation_slot_duration<C: Deref<Target = impl Signer> + C
}
.to_account_metas(None);

let ix_data = lb_clmm::instruction::SetPreActivationSlotDuration {
pre_activation_slot_duration,
let ix_data = lb_clmm::instruction::SetPreActivationDuration {
pre_activation_duration,
}
.data();

Expand All @@ -47,10 +47,7 @@ pub async fn set_pre_activation_slot_duration<C: Deref<Target = impl Signer> + C
.send_with_spinner_and_config(transaction_config)
.await;

println!(
"Set pre activation slot duration. Signature: {:#?}",
signature
);
println!("Set pre activation duration. Signature: {:#?}", signature);

signature?;

Expand Down
22 changes: 10 additions & 12 deletions cli/src/instructions/swap_exact_in.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@ pub async fn swap<C: Deref<Target = impl Signer> + Clone>(

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

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

let (user_token_in, user_token_out) = if swap_for_y {
(
get_associated_token_address(&program.payer(), &lb_pair_state.token_x_mint),
Expand Down Expand Up @@ -87,15 +85,14 @@ pub async fn swap<C: Deref<Target = impl Signer> + Clone>(
.collect::<Option<HashMap<Pubkey, BinArray>>>()
.context("Failed to fetch bin arrays")?;

let current_timestamp =
program
.async_rpc()
.get_account(&Clock::id())
.await
.map(|account| {
let clock: Clock = bincode::deserialize(account.data.as_ref())?;
Ok(clock.unix_timestamp)
})??;
let clock = program
.async_rpc()
.get_account(&Clock::id())
.await
.map(|account| {
let clock: Clock = bincode::deserialize(account.data.as_ref())?;
Ok(clock)
})??;

let quote = quote_exact_in(
lb_pair,
Expand All @@ -104,7 +101,8 @@ pub async fn swap<C: Deref<Target = impl Signer> + Clone>(
swap_for_y,
bin_arrays,
bitmap_extension.as_ref(),
current_timestamp as u64,
clock.unix_timestamp as u64,
clock.slot,
)?;

let (event_authority, _bump) =
Expand Down
Loading

0 comments on commit 4a064a6

Please sign in to comment.