Skip to content

Commit 113ccf3

Browse files
committed
Merge branch 'dlp' into devnet
2 parents 9345a3e + 340b6c9 commit 113ccf3

File tree

10 files changed

+137
-105
lines changed

10 files changed

+137
-105
lines changed

.devcontainer/Dockerfile

Lines changed: 48 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,56 @@
11
#
2-
# Docker image to generate deterministic, verifiable builds of Anchor programs.
3-
# This must be run *after* a given ANCHOR_CLI version is published and a git tag
4-
# is released on GitHub.
2+
# Drift Protocol Dev Container
53
#
64

75
FROM --platform=linux/amd64 rust:1.70.0
86

97
ARG DEBIAN_FRONTEND=noninteractive
10-
118
ARG SOLANA_CLI="1.16.27"
129
ARG ANCHOR_CLI="0.29.0"
13-
ARG NODE_VERSION="20.19.5"
14-
15-
# Create a non-root user
16-
ARG USERNAME=vscode
17-
ARG USER_UID=1000
18-
ARG USER_GID=$USER_UID
19-
20-
RUN groupadd --gid $USER_GID $USERNAME \
21-
&& useradd --uid $USER_UID --gid $USER_GID -m $USERNAME \
22-
&& apt-get update \
23-
&& apt-get install -y sudo \
24-
&& apt-get install -y bash \
25-
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME \
26-
&& chmod 0440 /etc/sudoers.d/$USERNAME
27-
28-
ENV HOME="/home/$USERNAME"
29-
ENV PATH="${HOME}/.cargo/bin:${PATH}"
30-
ENV PATH="${HOME}/.local/share/solana/install/active_release/bin:${PATH}"
31-
32-
# Install base utilities.
33-
RUN mkdir -p /workdir && mkdir -p /tmp && \
34-
apt-get update -qq && apt-get upgrade -qq && apt-get install -qq \
35-
build-essential git curl wget jq pkg-config python3-pip \
36-
libssl-dev libudev-dev
37-
38-
# libssl1.1 is not needed for newer versions
39-
40-
# Install rust.
41-
RUN curl "https://sh.rustup.rs" -sfo rustup.sh && \
42-
sh rustup.sh -y && \
43-
rustup component add rustfmt clippy
44-
45-
# Install node / npm / yarn.
46-
RUN curl -fsSL https://deb.nodesource.com/setup_${NODE_VERSION} | bash - \
47-
&& apt-get install -y nodejs \
48-
&& apt-get install -y npm \
49-
&& npm install -g yarn ts-mocha typescript mocha
50-
51-
# Install Solana tools (x86_64 version).
52-
RUN curl -sSfL https://github.com/solana-labs/solana/releases/download/v${SOLANA_CLI}/solana-release-x86_64-unknown-linux-gnu.tar.bz2 | tar -xjC /tmp && \
53-
mv /tmp/solana-release/bin/* /usr/local/bin/ && \
54-
rm -rf /tmp/solana-release
55-
56-
# Install anchor.
57-
RUN cargo install --git https://github.com/coral-xyz/anchor --tag v${ANCHOR_CLI} anchor-cli --locked
58-
59-
# Switch to the non-root user for the remaining setup
60-
USER $USERNAME
61-
62-
RUN solana-keygen new --no-bip39-passphrase
63-
64-
# Set up Solana config for local development
65-
RUN solana config set --url localhost
66-
67-
# Create necessary directories
68-
RUN mkdir -p $HOME/.config/solana
69-
70-
WORKDIR /workdir
10+
ARG NODE_VERSION="20.18.1"
11+
12+
ENV HOME="/root"
13+
ENV PATH="/usr/local/cargo/bin:${PATH}"
14+
ENV PATH="/root/.local/share/solana/install/active_release/bin:${PATH}"
15+
16+
RUN mkdir -p /workdir /tmp \
17+
&& apt-get update -qq \
18+
&& apt-get upgrade -qq \
19+
&& apt-get install -y --no-install-recommends \
20+
build-essential git curl wget jq pkg-config python3-pip xz-utils ca-certificates \
21+
libssl-dev libudev-dev bash software-properties-common \
22+
&& add-apt-repository 'deb http://deb.debian.org/debian bookworm main' \
23+
&& apt-get update -qq \
24+
&& apt-get install -y libc6 libc6-dev \
25+
&& rm -rf /var/lib/apt/lists/*
26+
27+
RUN rustup component add rustfmt
28+
29+
RUN rustup install 1.78.0 \
30+
&& rustup component add rustfmt clippy --toolchain 1.78.0
31+
32+
RUN curl -fsSL "https://nodejs.org/dist/v${NODE_VERSION}/node-v${NODE_VERSION}-linux-x64.tar.xz" -o /tmp/node.tar.xz \
33+
&& tar -xJf /tmp/node.tar.xz -C /usr/local --strip-components=1 \
34+
&& rm /tmp/node.tar.xz \
35+
&& corepack enable \
36+
&& npm install -g ts-mocha typescript mocha \
37+
&& node -v && npm -v && yarn -v
38+
39+
# Solana CLI (x86_64 build)
40+
RUN curl -sSfL "https://github.com/solana-labs/solana/releases/download/v${SOLANA_CLI}/solana-release-x86_64-unknown-linux-gnu.tar.bz2" \
41+
| tar -xjC /tmp \
42+
&& mv /tmp/solana-release/bin/* /usr/local/bin/ \
43+
&& rm -rf /tmp/solana-release
44+
45+
# Anchor CLI
46+
RUN cargo install --git https://github.com/coral-xyz/anchor --tag "v${ANCHOR_CLI}" anchor-cli --locked
47+
48+
# Set up Solana key + config for root
49+
RUN solana-keygen new --no-bip39-passphrase --force \
50+
&& solana config set --url localhost
51+
52+
RUN apt-get update && apt-get install -y zsh curl git \
53+
&& sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended \
54+
&& chsh -s /usr/bin/zsh root
55+
56+
WORKDIR /workdir

.devcontainer/devcontainer.json

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
"platform": "linux/amd64"
66
},
77
"workspaceFolder": "/workdir",
8-
"remoteUser": "vscode",
8+
"remoteUser": "root",
99
"mounts": [
1010
"source=${localWorkspaceFolder},target=/workdir,type=bind,consistency=cached",
1111
"source=drift-target,target=/workdir/target,type=volume,consistency=delegated"
1212
],
13-
"postCreateCommand": "sudo chown -R vscode:vscode /workdir/target 2>/dev/null || true && echo 'Dev container ready! You can now run: anchor build, anchor test, cargo build, etc.' && echo 'To run tests: bash test-scripts/run-anchor-tests.sh'",
13+
"postCreateCommand": "yarn config set ignore-package-manager true && echo 'Dev container ready! You can now run: anchor build, anchor test, cargo build, etc.'",
1414
"customizations": {
1515
"vscode": {
1616
"extensions": [
@@ -19,13 +19,24 @@
1919
"tamasfe.even-better-toml"
2020
],
2121
"settings": {
22+
"rust-analyzer.cachePriming.numThreads": 1,
2223
"rust-analyzer.cargo.buildScripts.enable": true,
2324
"rust-analyzer.procMacro.enable": true,
24-
"terminal.integrated.defaultProfile.linux": "bash"
25+
"rust-analyzer.checkOnSave": true,
26+
"rust-analyzer.check.command": "clippy",
27+
"rust-analyzer.server.extraEnv": {
28+
"NODE_OPTIONS": "--max-old-space-size=4096",
29+
"RUSTUP_TOOLCHAIN": "1.78.0-x86_64-unknown-linux-gnu"
30+
},
31+
"editor.formatOnSave": true,
32+
"git.ignoreLimitWarning": true
2533
}
2634
}
2735
},
28-
"forwardPorts": [8899, 8900],
36+
"forwardPorts": [
37+
8899,
38+
8900
39+
],
2940
"portsAttributes": {
3041
"8899": {
3142
"label": "Solana Test Validator",
@@ -37,7 +48,7 @@
3748
}
3849
},
3950
"containerEnv": {
40-
"ANCHOR_WALLET": "/home/vscode/.config/solana/id.json",
51+
"ANCHOR_WALLET": "/root/.config/solana/id.json",
4152
"RUST_LOG": "solana_runtime::message_processor::stable_log=debug"
4253
}
4354
}

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,5 +94,6 @@
9494
"chalk-template": "<1.1.1",
9595
"supports-hyperlinks": "<4.1.1",
9696
"has-ansi": "<6.0.1"
97-
}
98-
}
97+
},
98+
"packageManager": "[email protected]+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
99+
}

programs/drift/src/instructions/keeper.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3333,6 +3333,7 @@ pub fn handle_settle_perp_to_lp_pool<'c: 'info, 'info>(
33333333
ctx.accounts.amm_cache.load_zc_mut()?;
33343334
let quote_market = &mut ctx.accounts.quote_market.load_mut()?;
33353335
let mut quote_constituent = ctx.accounts.constituent.load_mut()?;
3336+
let lp_pool_key = ctx.accounts.lp_pool.key();
33363337
let mut lp_pool = ctx.accounts.lp_pool.load_mut()?;
33373338

33383339
let remaining_accounts_iter = &mut ctx.remaining_accounts.iter().peekable();
@@ -3486,6 +3487,7 @@ pub fn handle_settle_perp_to_lp_pool<'c: 'info, 'info>(
34863487
.cast::<i64>()?,
34873488
lp_aum: lp_pool.last_aum,
34883489
lp_price: lp_pool.get_price(lp_pool.token_supply)?,
3490+
lp_pool: lp_pool_key,
34893491
});
34903492

34913493
// Calculate new quote owed amount

programs/drift/src/instructions/lp_pool.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -223,10 +223,7 @@ pub fn handle_update_lp_pool_aum<'c: 'info, 'info>(
223223

224224
// Set USDC stable weight
225225
msg!("aum: {}", aum);
226-
let total_stable_target_base = aum
227-
.cast::<i128>()?
228-
.safe_sub(crypto_delta.abs())?
229-
.max(0_i128);
226+
let total_stable_target_base = aum.cast::<i128>()?.safe_sub(crypto_delta)?;
230227
constituent_target_base
231228
.get_mut(lp_pool.quote_consituent_index as u32)
232229
.target_base = total_stable_target_base.cast::<i64>()?;
@@ -483,6 +480,7 @@ pub fn handle_lp_pool_swap<'c: 'info, 'info>(
483480
out_market_target_weight: out_target_weight,
484481
in_swap_id,
485482
out_swap_id,
483+
lp_pool: lp_pool_key,
486484
})?;
487485

488486
receive(
@@ -848,6 +846,7 @@ pub fn handle_lp_pool_add_liquidity<'c: 'info, 'info>(
848846
lp_pool.last_aum,
849847
)?,
850848
in_market_target_weight: in_target_weight,
849+
lp_pool: lp_pool_key,
851850
})?;
852851

853852
Ok(())
@@ -859,7 +858,6 @@ pub fn handle_view_lp_pool_add_liquidity_fees<'c: 'info, 'info>(
859858
in_amount: u128,
860859
) -> Result<()> {
861860
let slot = Clock::get()?.slot;
862-
let now = Clock::get()?.unix_timestamp;
863861
let state = &ctx.accounts.state;
864862
let lp_pool = ctx.accounts.lp_pool.load()?;
865863

@@ -1041,7 +1039,7 @@ pub fn handle_lp_pool_remove_liquidity<'c: 'info, 'info>(
10411039
out_spot_market.get_max_confidence_interval_multiplier()?,
10421040
0,
10431041
)?;
1044-
let out_oracle = out_oracle.clone();
1042+
let out_oracle = *out_oracle;
10451043

10461044
// TODO: check self.aum validity
10471045

@@ -1230,6 +1228,7 @@ pub fn handle_lp_pool_remove_liquidity<'c: 'info, 'info>(
12301228
lp_pool.last_aum,
12311229
)?,
12321230
in_market_target_weight: out_target_weight,
1231+
lp_pool: lp_pool_key,
12331232
})?;
12341233

12351234
Ok(())
@@ -1244,7 +1243,6 @@ pub fn handle_view_lp_pool_remove_liquidity_fees<'c: 'info, 'info>(
12441243
lp_to_burn: u64,
12451244
) -> Result<()> {
12461245
let slot = Clock::get()?.slot;
1247-
let now = Clock::get()?.unix_timestamp;
12481246
let state = &ctx.accounts.state;
12491247
let lp_pool = ctx.accounts.lp_pool.load()?;
12501248

@@ -1371,6 +1369,7 @@ pub fn handle_deposit_to_program_vault<'c: 'info, 'info>(
13711369
let remaining_accounts = &mut ctx.remaining_accounts.iter().peekable();
13721370

13731371
let mut constituent = ctx.accounts.constituent.load_mut()?;
1372+
let lp_pool_key = constituent.lp_pool;
13741373

13751374
if amount == 0 {
13761375
return Err(ErrorCode::InsufficientDeposit.into());
@@ -1478,6 +1477,7 @@ pub fn handle_deposit_to_program_vault<'c: 'info, 'info>(
14781477
last_token_balance: constituent.last_spot_balance_token_amount,
14791478
interest_accrued_token_amount,
14801479
amount_deposit_withdraw: amount,
1480+
lp_pool: lp_pool_key,
14811481
});
14821482
constituent.last_spot_balance_token_amount = new_token_balance;
14831483
constituent.cumulative_spot_interest_accrued_token_amount = constituent
@@ -1515,7 +1515,7 @@ pub fn handle_withdraw_from_program_vault<'c: 'info, 'info>(
15151515

15161516
controller::spot_balance::update_spot_market_cumulative_interest(
15171517
&mut spot_market,
1518-
Some(&oracle_data),
1518+
Some(oracle_data),
15191519
clock.unix_timestamp,
15201520
)?;
15211521
let token_balance_after_cumulative_interest_update = constituent
@@ -1561,6 +1561,7 @@ pub fn handle_withdraw_from_program_vault<'c: 'info, 'info>(
15611561
last_token_balance: constituent.last_spot_balance_token_amount,
15621562
interest_accrued_token_amount,
15631563
amount_deposit_withdraw: amount,
1564+
lp_pool: constituent.lp_pool,
15641565
});
15651566
constituent.last_spot_balance_token_amount = new_token_balance;
15661567
constituent.cumulative_spot_interest_accrued_token_amount = constituent

programs/drift/src/math/lp_pool.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub mod perp_lp_pool_settlement {
1010
state::{amm_cache::CacheInfo, perp_market::PerpMarket, spot_market::SpotMarket},
1111
*,
1212
};
13-
use anchor_spl::token_interface::{Mint, TokenAccount, TokenInterface};
13+
use anchor_spl::token_interface::{TokenAccount, TokenInterface};
1414

1515
#[derive(Debug, Clone, Copy)]
1616
pub struct SettlementResult {
@@ -55,7 +55,7 @@ pub mod perp_lp_pool_settlement {
5555
ctx: &SettlementContext,
5656
result: &SettlementResult,
5757
) -> Result<()> {
58-
if result.amount_transferred > ctx.max_settle_quote_amount as u64 {
58+
if result.amount_transferred > ctx.max_settle_quote_amount {
5959
msg!(
6060
"Amount to settle exceeds maximum allowed, {} > {}",
6161
result.amount_transferred,
@@ -94,7 +94,8 @@ pub mod perp_lp_pool_settlement {
9494
}
9595

9696
fn calculate_perp_to_lp_settlement(ctx: &SettlementContext) -> Result<SettlementResult> {
97-
let amount_to_send = (ctx.quote_owed_from_lp.abs() as u64).min(ctx.max_settle_quote_amount);
97+
let amount_to_send =
98+
(ctx.quote_owed_from_lp.abs().cast::<u64>()?).min(ctx.max_settle_quote_amount);
9899

99100
if ctx.fee_pool_balance >= amount_to_send as u128 {
100101
// Fee pool can cover entire amount

programs/drift/src/state/events.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -790,6 +790,8 @@ pub struct LPSettleRecord {
790790
pub lp_aum: u128,
791791
// current mint price of lp
792792
pub lp_price: u128,
793+
// lp pool pubkey
794+
pub lp_pool: Pubkey,
793795
}
794796

795797
#[event]
@@ -831,10 +833,12 @@ pub struct LPSwapRecord {
831833
pub out_market_target_weight: i64,
832834
pub in_swap_id: u64,
833835
pub out_swap_id: u64,
836+
// lp pool pubkey
837+
pub lp_pool: Pubkey,
834838
}
835839

836840
impl Size for LPSwapRecord {
837-
const SIZE: usize = 376;
841+
const SIZE: usize = 408;
838842
}
839843

840844
#[event]
@@ -869,10 +873,12 @@ pub struct LPMintRedeemRecord {
869873
/// PERCENTAGE_PRECISION
870874
pub in_market_current_weight: i64,
871875
pub in_market_target_weight: i64,
876+
// lp pool pubkey
877+
pub lp_pool: Pubkey,
872878
}
873879

874880
impl Size for LPMintRedeemRecord {
875-
const SIZE: usize = 328;
881+
const SIZE: usize = 360;
876882
}
877883

878884
#[event]
@@ -887,8 +893,9 @@ pub struct LPBorrowLendDepositRecord {
887893
pub last_token_balance: i64,
888894
pub interest_accrued_token_amount: i64,
889895
pub amount_deposit_withdraw: u64,
896+
pub lp_pool: Pubkey,
890897
}
891898

892899
impl Size for LPBorrowLendDepositRecord {
893-
const SIZE: usize = 72;
900+
const SIZE: usize = 104;
894901
}

0 commit comments

Comments
 (0)