Skip to content
Draft

Devnet #1850

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
198 commits
Select commit Hold shift + click to select a range
df3ab76
program: make lp shares reduce only
crispheaney Jul 16, 2025
fed9dc6
init
crispheaney Jul 19, 2025
e99ffa7
rm more fields
crispheaney Jul 19, 2025
25ab531
make tests build
crispheaney Jul 19, 2025
eba3f11
start sdk changes
crispheaney Jul 19, 2025
b58cda0
init new margin calc
crispheaney Jul 20, 2025
820c232
deposit and transfer into
crispheaney Jul 23, 2025
9efd808
add settle pnl
crispheaney Jul 23, 2025
75b92f8
program: add withdraw
crispheaney Jul 24, 2025
162fc23
add more ix
crispheaney Jul 24, 2025
82463f3
add new meets withdraw req fn
crispheaney Jul 26, 2025
fb57e5f
enter/exit liquidation logic
crispheaney Jul 27, 2025
4de579a
moar
crispheaney Jul 27, 2025
085e805
start liquidation logic
crispheaney Jul 30, 2025
4e7db0f
other liquidation fns
crispheaney Jul 30, 2025
8e89ef4
make build work
crispheaney Jul 30, 2025
8062d60
more updates
crispheaney Jul 31, 2025
991dda9
always calc isolated pos
crispheaney Aug 4, 2025
c627c1e
rm isolated position market index logic
crispheaney Aug 4, 2025
a00f3a9
moar
crispheaney Aug 5, 2025
d435dad
program: rm the isolated position market index
crispheaney Aug 5, 2025
ed76b47
some tweaks
crispheaney Aug 5, 2025
c13a605
rm some old margin code
crispheaney Aug 5, 2025
4a9aadc
tweak meets withdraw requirements
crispheaney Aug 5, 2025
0d56488
rm liquidation mode changing context
crispheaney Aug 6, 2025
584337b
handle liquidation id and bit flags
crispheaney Aug 7, 2025
15c05ee
more liquidation changes
crispheaney Aug 7, 2025
adc2815
clean
crispheaney Aug 8, 2025
0de7802
fix force cancel orders
crispheaney Aug 8, 2025
830c7c9
update validate liquidation
crispheaney Aug 8, 2025
5d09739
moar
crispheaney Aug 8, 2025
7392d3e
rename is_being_liquidated
crispheaney Aug 8, 2025
26960c8
start adding test
crispheaney Aug 15, 2025
2ab06e3
program: add validate for liq borrow for perp pnl
crispheaney Aug 15, 2025
9a56326
program: add test for isolated margin calc
crispheaney Aug 15, 2025
b171c23
is bankrupt test
crispheaney Aug 15, 2025
2821269
fix cancel orders
crispheaney Aug 19, 2025
424987f
fix set liquidation status
crispheaney Aug 19, 2025
b84daf1
more tweaks
crispheaney Aug 19, 2025
ea09842
clean up naming
crispheaney Aug 19, 2025
cc397f0
update last active slot for isolated position liq
crispheaney Aug 20, 2025
9833303
another liquidation review
crispheaney Aug 21, 2025
9cb040a
add test
crispheaney Aug 21, 2025
8177496
cargo fmt --
crispheaney Aug 21, 2025
9a8ec1a
tweak naming
crispheaney Aug 21, 2025
6ddbaf8
add test to make sure false liquidaiton wont be triggered
crispheaney Aug 25, 2025
2db2907
test meets withdraw
crispheaney Aug 25, 2025
8314bbe
change is bankrupt
crispheaney Aug 26, 2025
654683c
more
crispheaney Aug 26, 2025
4cab732
update uses of exit isolated liquidaiton
crispheaney Aug 26, 2025
6a6a150
moar
crispheaney Aug 26, 2025
7c46187
moar
crispheaney Aug 26, 2025
51ae2eb
reduce diff
crispheaney Aug 26, 2025
bae1b6b
moar
crispheaney Aug 26, 2025
d2f08ea
modularize some for tests
crispheaney Aug 26, 2025
ba8866a
add tests for the pnl for deposit liquidation
crispheaney Aug 27, 2025
9fa04fa
tests for isolated position transfer
crispheaney Aug 27, 2025
a732348
test for update spot balance
crispheaney Aug 28, 2025
91baee3
test for settle pnl
crispheaney Aug 28, 2025
101e311
add perp position max margin
crispheaney Sep 2, 2025
0bc6132
program: test for custom perp position margin ratio
crispheaney Sep 2, 2025
608928f
add test for margin calc for disable hlm
crispheaney Sep 2, 2025
fc6bebc
update test name
crispheaney Sep 2, 2025
5f3b7d0
make max margin ratio persist
crispheaney Sep 2, 2025
3c56869
add liquidation mode test
crispheaney Sep 2, 2025
bf2839e
more tests to make sure liqudiations dont bleed over
crispheaney Sep 2, 2025
eb60940
change test name
crispheaney Sep 2, 2025
5cef2f8
Bigz/init lp pool (#1884)
moosecat2 Sep 16, 2025
03b22b8
add vamm cache percent scalar (default is 100)
moosecat2 Sep 17, 2025
eecbe20
Merge pull request #1888 from drift-labs/nour/vamm-cache-percent
moosecat2 Sep 17, 2025
a2a0c52
program: add auto cancel reduce only tpsl
crispheaney Sep 17, 2025
db517d9
cargo test
crispheaney Sep 17, 2025
84803e6
cargo fmt --
crispheaney Sep 17, 2025
dc43396
aum cant go below zero (#1890)
moosecat2 Sep 17, 2025
d04e6fc
program: let anotehr signer deposit on user behalf
crispheaney Sep 17, 2025
497638d
reassing dlp taker bot wallet
moosecat2 Sep 18, 2025
6976e55
add event subscriber changes for dlp events
moosecat2 Sep 18, 2025
9d7a2b6
give permission for dlp taker bot to deposit withdraw from program va…
moosecat2 Sep 19, 2025
a814f7b
fix max withdrawals bug
moosecat2 Sep 19, 2025
e8708a8
Merge branch 'master' into crispheaney/isolated-position
crispheaney Sep 20, 2025
ba10482
fix broken cargo tests
crispheaney Sep 20, 2025
58df2ff
cargo fmt --
crispheaney Sep 20, 2025
5d61bd3
Merge branch 'master' into crispheaney/isolated-position
crispheaney Sep 20, 2025
dd49970
Merge branch 'master' into crispheaney/isolated-position
crispheaney Sep 20, 2025
71fcdfa
first ts test
crispheaney Sep 20, 2025
d1060ff
get max transfer bug fix
moosecat2 Sep 20, 2025
2db9320
merge master
moosecat2 Sep 20, 2025
7af9f65
isolatedPositionLiquidatePerp test
crispheaney Sep 21, 2025
e40563e
isolatedPositionLiquidatePerpwithFill test
crispheaney Sep 21, 2025
c643a50
fix expired position
crispheaney Sep 23, 2025
16bea30
cargo fmt --
crispheaney Sep 23, 2025
010c210
Wphan/merge-master (#1915)
wphan Sep 25, 2025
8757c93
add new bulk instruction packaging
moosecat2 Sep 29, 2025
e3d08a0
logging changes
moosecat2 Sep 29, 2025
ecd8d3a
Wphan/master-dlp (#1918)
wphan Sep 29, 2025
e6e3999
Merge remote-tracking branch 'origin/dlp' into devnet
wphan Sep 29, 2025
53a5009
borrow lend accounting (#1905)
moosecat2 Sep 29, 2025
8cd14cf
Merge branch 'dlp' into devnet
wphan Sep 29, 2025
88d1dc8
remove duplicate admin client funcs
moosecat2 Sep 29, 2025
6faf6a2
update idl
wphan Sep 29, 2025
71a823a
Merge branch 'dlp' into devnet
wphan Sep 29, 2025
f1a23d8
bump constituent map max size
moosecat2 Sep 30, 2025
cec4e6d
make working devcontainer and dockerfile
wphan Sep 30, 2025
54315e9
Merge remote-tracking branch 'origin/crispheaney/support-deposits-on-…
wphan Sep 30, 2025
f3a7e66
update idl
wphan Sep 30, 2025
61a5657
bug fixes
moosecat2 Sep 30, 2025
bcb5ded
bug fixes
moosecat2 Sep 30, 2025
025eaf3
add dev container
moosecat2 Sep 30, 2025
55b530d
fix node version
wphan Sep 30, 2025
91681ac
Merge branch 'dlp' into devnet
wphan Sep 30, 2025
dad1a54
update idl
wphan Sep 30, 2025
51e2e27
update dockerfile
moosecat2 Sep 30, 2025
dfec9a3
fixed idl
moosecat2 Sep 30, 2025
199f504
dockerfile and dev container working, and anchor build working
moosecat2 Sep 30, 2025
19efd62
add dev container.json and dockerfile
moosecat2 Sep 30, 2025
6913015
fix bug
crispheaney Oct 1, 2025
2df49ea
cargo fmt --
crispheaney Oct 1, 2025
9345a3e
Merge branch 'crispheaney/support-deposits-on-behalf-of-user' into de…
wphan Oct 1, 2025
c768376
update dlp types to include lp pool key
moosecat2 Oct 1, 2025
340b6c9
stable target base liquidity fix + cleanup
moosecat2 Oct 1, 2025
113ccf3
Merge branch 'dlp' into devnet
moosecat2 Oct 1, 2025
631c962
relax transfer from program lp invariant for devnet
moosecat2 Oct 1, 2025
8c96253
merge dlp
moosecat2 Oct 1, 2025
8f6f9bc
further restrict constituent max borrow
moosecat2 Oct 2, 2025
ede599b
give 1% flexilibity for race conditions on max transfer amount
moosecat2 Oct 2, 2025
2703a25
git merge max token amount changes
moosecat2 Oct 2, 2025
60a9231
introduce max borrow buffer
moosecat2 Oct 2, 2025
72a5e42
include new amm inventory limit (#1932)
moosecat2 Oct 3, 2025
bc1ae68
refactor amm cache
moosecat2 Oct 3, 2025
d6f5ff3
merge dlp
moosecat2 Oct 3, 2025
6f881ba
change amm cache pda seed for devnet reset
moosecat2 Oct 3, 2025
8b73b66
update sdk types file to be up to parity
moosecat2 Oct 6, 2025
41fbaa3
merge master into dlp
moosecat2 Oct 6, 2025
69afe90
clean up and guard against negative amm_inventory_limit
moosecat2 Oct 7, 2025
0cd3560
Target delay increases fees (#1943)
moosecat2 Oct 8, 2025
07f8bcf
Merge branch 'dlp' into devnet
moosecat2 Oct 8, 2025
84ce292
update idl
moosecat2 Oct 8, 2025
b8fc014
Merge branch 'crispheaney/isolated-position' into devnet
crispheaney Oct 14, 2025
2aa80ab
Merge branch 'crispheaney/auto-cancel-tpsl' into devnet
crispheaney Oct 14, 2025
a21a4cd
merge master
moosecat2 Oct 14, 2025
89d7880
add signer to deposit record
crispheaney Oct 14, 2025
290b7e9
merge master
moosecat2 Oct 15, 2025
0ca25a0
Moose review (#1948)
moosecat2 Oct 16, 2025
b295031
remove unnecessary admin func
moosecat2 Oct 16, 2025
453d93f
program: add transfer isolated pos deposit into swift (#1964)
crispheaney Oct 16, 2025
82fc87f
program: auto transfer to cross margin account (#1939)
crispheaney Oct 16, 2025
3eaff60
Merge branch 'crispheaney/isolated-position' into devnet
crispheaney Oct 16, 2025
81561dc
merge dlp and push
moosecat2 Oct 17, 2025
fe55733
sdk: release v2.142.0-beta.27
github-actions[bot] Oct 14, 2025
9e3e00a
CHANGELOG
crispheaney Oct 14, 2025
878e3ba
program: allow hot wallet to increase max spread and pause funding (#…
crispheaney Oct 14, 2025
08ff4cb
program: allow settling positive pnl expired pos during liquidation (…
crispheaney Oct 14, 2025
11e3680
v2.142.0
wphan Oct 15, 2025
7301396
sdk: release v2.143.0-beta.0
github-actions[bot] Oct 15, 2025
d6385c4
rm println (#1962)
jordy25519 Oct 15, 2025
84128af
fix: cleanup potential mem leaks on grpc v2 (#1963)
LukasDeco Oct 15, 2025
b767e18
sdk: release v2.143.0-beta.1
github-actions[bot] Oct 15, 2025
d4ad8db
Moose review (#1948)
moosecat2 Oct 16, 2025
5702b5e
remove unnecessary admin func
moosecat2 Oct 16, 2025
f3bd586
idl
moosecat2 Oct 17, 2025
9d7e7a0
delete unused errors
moosecat2 Oct 22, 2025
73a4d4f
Merge branch 'master' into dlp
moosecat2 Oct 22, 2025
309fa74
make linter happy
moosecat2 Oct 22, 2025
648bf33
fix all compiler warnings
moosecat2 Oct 22, 2025
28ed029
make build
crispheaney Oct 22, 2025
39c4d65
merge master
moosecat2 Oct 22, 2025
70c4a4d
merge master
moosecat2 Oct 22, 2025
1b19a32
merge in dlp
moosecat2 Oct 22, 2025
b0a2b67
isolated pos deposit sdk
crispheaney Oct 23, 2025
3bd6eeb
test working
crispheaney Oct 23, 2025
3bd7525
move the auto transfer
crispheaney Oct 23, 2025
283016a
Merge branch 'master' into crispheaney/isolated-position
crispheaney Oct 23, 2025
12fc68d
Merge branch 'crispheaney/isolated-position' into devnet
crispheaney Oct 23, 2025
5a8b7cb
merge master
moosecat2 Oct 24, 2025
b78695b
sync new oracle map
moosecat2 Oct 24, 2025
00139c4
Use lp pool id (#1992)
moosecat2 Oct 27, 2025
4baaa3b
merge dlp
moosecat2 Oct 27, 2025
8d3e848
address comments round 2
moosecat2 Oct 28, 2025
4b5735a
add additional settle pnl invariant check
moosecat2 Oct 28, 2025
71dd9c1
create separate hot wallet for lp pool
moosecat2 Oct 28, 2025
7e67ac8
Merge branch 'master' into dlp
moosecat2 Oct 28, 2025
3c6ad68
remove any unused fields
moosecat2 Oct 28, 2025
af376f2
add oracle map logging argument
moosecat2 Oct 28, 2025
447b707
merge in dlp
moosecat2 Oct 28, 2025
503fa41
generalize lp pool test failure
moosecat2 Oct 28, 2025
47702bf
Merge branch 'dlp' into devnet
moosecat2 Oct 28, 2025
e6dd77a
unified swap mode compatibility
moosecat2 Oct 28, 2025
d14dc14
clippy and whitelist changes
moosecat2 Oct 28, 2025
3cab1fc
Merge branch 'dlp' into devnet
moosecat2 Oct 28, 2025
54088e6
merge master
moosecat2 Oct 29, 2025
dac033a
merge devnet
moosecat2 Oct 29, 2025
d29166b
cargo tests pass
moosecat2 Oct 31, 2025
35c867c
Merge branch 'master' into dlp-refactor-amm-cache
moosecat2 Oct 31, 2025
e2fe3ab
refactor amm cache to only include collateralized markets
moosecat2 Nov 3, 2025
ce37116
fix anchor tests
moosecat2 Nov 3, 2025
1dffca7
update idl with delete func
moosecat2 Nov 3, 2025
3f6aef3
merge in dlp fix
moosecat2 Nov 3, 2025
21d35cc
merge master
moosecat2 Nov 12, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Features

### Fixes

### Breaking

## [2.142.0] - 2025-10-14

### Features

- program: add titan to whitelisted swap programs ([#1952](https://github.com/drift-labs/protocol-v2/pull/1952))
- program: allow hot wallet to increase max spread and pause funding ([#1957](https://github.com/drift-labs/protocol-v2/pull/1957))

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,4 @@
"supports-hyperlinks": "<4.1.1",
"has-ansi": "<6.0.1"
}
}
}
54 changes: 39 additions & 15 deletions programs/drift/src/controller/amm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ fn calculate_revenue_pool_transfer(
pub fn update_pool_balances(
market: &mut PerpMarket,
spot_market: &mut SpotMarket,
user_quote_position: &SpotPosition,
user_quote_token_amount: i128,
user_unsettled_pnl: i128,
now: i64,
) -> DriftResult<i128> {
Expand Down Expand Up @@ -743,12 +743,13 @@ pub fn update_pool_balances(
let pnl_to_settle_with_user = if user_unsettled_pnl > 0 {
min(user_unsettled_pnl, pnl_pool_token_amount.cast::<i128>()?)
} else {
let token_amount = user_quote_position.get_signed_token_amount(spot_market)?;

// dont settle negative pnl to spot borrows when utilization is high (> 80%)
let max_withdraw_amount =
-get_max_withdraw_for_market_with_token_amount(spot_market, token_amount, false)?
.cast::<i128>()?;
let max_withdraw_amount = -get_max_withdraw_for_market_with_token_amount(
spot_market,
user_quote_token_amount,
false,
)?
.cast::<i128>()?;

max_withdraw_amount.max(user_unsettled_pnl)
};
Expand Down Expand Up @@ -788,15 +789,15 @@ pub fn update_pool_balances(

pub fn update_pnl_pool_and_user_balance(
market: &mut PerpMarket,
bank: &mut SpotMarket,
quote_spot_market: &mut SpotMarket,
user: &mut User,
unrealized_pnl_with_fee: i128,
) -> DriftResult<i128> {
let pnl_to_settle_with_user = if unrealized_pnl_with_fee > 0 {
unrealized_pnl_with_fee.min(
get_token_amount(
market.pnl_pool.scaled_balance,
bank,
quote_spot_market,
market.pnl_pool.balance_type(),
)?
.cast()?,
Expand Down Expand Up @@ -827,14 +828,37 @@ pub fn update_pnl_pool_and_user_balance(
return Ok(0);
}

let user_spot_position = user.get_quote_spot_position_mut();
let is_isolated_position = user.get_perp_position(market.market_index)?.is_isolated();
if is_isolated_position {
let perp_position = user.force_get_isolated_perp_position_mut(market.market_index)?;
let perp_position_token_amount =
perp_position.get_isolated_token_amount(quote_spot_market)?;

if pnl_to_settle_with_user < 0 {
validate!(
perp_position_token_amount >= pnl_to_settle_with_user.unsigned_abs(),
ErrorCode::InsufficientCollateral,
"user has insufficient deposit for market {}",
market.market_index
)?;
}

transfer_spot_balances(
pnl_to_settle_with_user,
bank,
&mut market.pnl_pool,
user_spot_position,
)?;
transfer_spot_balances(
pnl_to_settle_with_user,
quote_spot_market,
&mut market.pnl_pool,
perp_position,
)?;
} else {
let user_spot_position = user.get_quote_spot_position_mut();

transfer_spot_balances(
pnl_to_settle_with_user,
quote_spot_market,
&mut market.pnl_pool,
user_spot_position,
)?;
}

Ok(pnl_to_settle_with_user)
}
Expand Down
Loading
Loading