Skip to content

Wphan/builder codes #1805

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
010e8a3
add RevenueShare and RevenueShareEscrow accounts an init ixs
wphan Aug 1, 2025
dfe4330
fix multiple array zc account, and handling different message types i…
wphan Aug 4, 2025
aa88106
decoding error
wphan Aug 5, 2025
6afc60c
recording orders in RevenueShareEscrow workin
wphan Aug 5, 2025
e93bc21
cancel and fill orders
wphan Aug 6, 2025
2e247b5
Merge remote-tracking branch 'origin/master' into wphan/builder_codes
wphan Aug 6, 2025
35486e9
idl
wphan Aug 6, 2025
35350ba
fix sdk build
wphan Aug 6, 2025
f0e06af
fix math
wphan Aug 6, 2025
2ef60ce
update RevenueShareOrder bitflags, store builder_idx instead of pubkey
wphan Aug 7, 2025
57e335d
merge RevenueShareOrders on add
wphan Aug 8, 2025
b2fe670
remove builder accounts from cancel ixs, wip settle impl
wphan Aug 12, 2025
7b688ad
dont fail settlpnl if no builder users provided
wphan Aug 12, 2025
d11de9e
finish settle, rename RevenueShare->Builder, RevenueShareEscrow->Buil…
wphan Aug 13, 2025
464ff9b
add more bankrun tests, clean up
wphan Aug 14, 2025
97ef7f7
Merge branch 'master' into wphan/builder_codes
wphan Aug 14, 2025
8ffb821
clean up, fix tests
wphan Aug 14, 2025
7971ab5
why test fail
wphan Aug 14, 2025
28860b1
add subaccountid to BuilderOrder
wphan Aug 14, 2025
e4aafb0
reduce diff
wphan Aug 14, 2025
fabe2ff
add referrals
wphan Aug 15, 2025
84e7c46
add test can fill settle user with no builderescrow
wphan Aug 15, 2025
29fb679
add referral builder feature flag and referral migration method
wphan Aug 15, 2025
8870bad
fix cargo tests, try fix bankrun test timing issue
wphan Aug 15, 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
19 changes: 19 additions & 0 deletions programs/drift/src/controller/liquidation.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::ops::{Deref, DerefMut};

use crate::msg;
use crate::state::builder::RevenueShareEscrowZeroCopyMut;
use anchor_lang::prelude::*;

use crate::controller::amm::get_fee_pool_tokens;
Expand Down Expand Up @@ -91,6 +92,7 @@ pub fn liquidate_perp(
slot: u64,
now: i64,
state: &State,
revenue_escrow: &mut Option<&mut RevenueShareEscrowZeroCopyMut>,
) -> DriftResult {
let liquidation_margin_buffer_ratio = state.liquidation_margin_buffer_ratio;
let initial_pct_to_liquidate = state.initial_pct_to_liquidate as u128;
Expand Down Expand Up @@ -199,6 +201,7 @@ pub fn liquidate_perp(
None,
None,
None,
revenue_escrow,
)?;

let mut market = perp_market_map.get_ref_mut(&market_index)?;
Expand Down Expand Up @@ -746,6 +749,7 @@ pub fn liquidate_perp_with_fill(
oracle_map: &mut OracleMap,
clock: &Clock,
state: &State,
revenue_escrow: &mut Option<&mut RevenueShareEscrowZeroCopyMut>,
) -> DriftResult {
let now = clock.unix_timestamp;
let slot = clock.slot;
Expand Down Expand Up @@ -850,6 +854,7 @@ pub fn liquidate_perp_with_fill(
None,
None,
None,
revenue_escrow,
)?;

let mut market = perp_market_map.get_ref_mut(&market_index)?;
Expand Down Expand Up @@ -1083,6 +1088,7 @@ pub fn liquidate_perp_with_fill(
clock,
order_params,
PlaceOrderOptions::default().explanation(OrderActionExplanation::Liquidation),
&mut None,
)?;

drop(user);
Expand All @@ -1103,11 +1109,17 @@ pub fn liquidate_perp_with_fill(
None,
clock,
FillMode::Liquidation,
revenue_escrow,
)?;

let mut user = load_mut!(user_loader)?;

if let Ok(order_index) = user.get_order_index(order_id) {
let mut revenue_escrow_order = if let Some(ref mut revenue_escrow) = revenue_escrow {
revenue_escrow.find_order(user.orders[order_index].order_id)
} else {
None
};
cancel_order(
order_index,
&mut user,
Expand All @@ -1121,6 +1133,7 @@ pub fn liquidate_perp_with_fill(
Some(liquidator_key),
0,
false,
&mut revenue_escrow_order,
)?;
}

Expand Down Expand Up @@ -1458,6 +1471,7 @@ pub fn liquidate_spot(
None,
None,
None,
&mut None,
)?;

// check if user exited liquidation territory
Expand Down Expand Up @@ -1986,6 +2000,7 @@ pub fn liquidate_spot_with_swap_begin(
None,
None,
None,
&mut None,
)?;

// check if user exited liquidation territory
Expand Down Expand Up @@ -2345,6 +2360,7 @@ pub fn liquidate_borrow_for_perp_pnl(
liquidation_margin_buffer_ratio: u32,
initial_pct_to_liquidate: u128,
liquidation_duration: u128,
revenue_escrow: &mut Option<&mut RevenueShareEscrowZeroCopyMut>,
) -> DriftResult {
// liquidator takes over a user borrow in exchange for that user's positive perpetual pnl
// can only be done once a user's perpetual position size is 0
Expand Down Expand Up @@ -2564,6 +2580,7 @@ pub fn liquidate_borrow_for_perp_pnl(
None,
None,
None,
revenue_escrow,
)?;

// check if user exited liquidation territory
Expand Down Expand Up @@ -2822,6 +2839,7 @@ pub fn liquidate_perp_pnl_for_deposit(
liquidation_margin_buffer_ratio: u32,
initial_pct_to_liquidate: u128,
liquidation_duration: u128,
revenue_escrow: &mut Option<&mut RevenueShareEscrowZeroCopyMut>,
) -> DriftResult {
// liquidator takes over remaining negative perpetual pnl in exchange for a user deposit
// can only be done once the perpetual position's size is 0
Expand Down Expand Up @@ -3049,6 +3067,7 @@ pub fn liquidate_perp_pnl_for_deposit(
None,
None,
None,
revenue_escrow,
)?;

let (safest_tier_spot_liability, safest_tier_perp_liability) =
Expand Down
Loading
Loading