Skip to content

Commit

Permalink
Merge branch 'master' into crispheaney/accelerate-margin-free
Browse files Browse the repository at this point in the history
  • Loading branch information
crispheaney committed Nov 14, 2023
2 parents f21f5ad + 9754ba1 commit 53b096b
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 4 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixes

- program: allow amm to fill step size ([#672](https://github.com/drift-labs/protocol-v2/pull/672))
- program: add add update_liquidation_margin_buffer_ratio ([#695](https://github.com/drift-labs/protocol-v2/pull/695))
- program: account for fee pool when settling positive pnl ([#687](https://github.com/drift-labs/protocol-v2/pull/687))
- sdk: fix bug which incorrectly calculated leverage after trade for a market with no position but short orders open

Expand Down
12 changes: 10 additions & 2 deletions programs/drift/src/controller/orders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1735,14 +1735,14 @@ pub fn fulfill_perp_order_with_amm(
liquidity_split: AMMLiquiditySplit,
) -> DriftResult<(u64, u64)> {
let position_index = get_position_index(&user.perp_positions, market.market_index)?;
let existing_base_asset_amount = user.perp_positions[position_index].base_asset_amount;

// Determine the base asset amount the market can fill
let (base_asset_amount, limit_price, fill_price) = match override_base_asset_amount {
Some(override_base_asset_amount) => {
(override_base_asset_amount, limit_price, override_fill_price)
}
None => {
let existing_base_asset_amount = user.perp_positions[position_index].base_asset_amount;
let (base_asset_amount, limit_price) = calculate_base_asset_amount_for_amm_to_fulfill(
&user.orders[order_index],
market,
Expand All @@ -1761,7 +1761,15 @@ pub fn fulfill_perp_order_with_amm(
}
};

if base_asset_amount < market.amm.min_order_size {
// if user position is less than min order size, step size is the threshold
let amm_size_threshold =
if existing_base_asset_amount.unsigned_abs() > market.amm.min_order_size {
market.amm.min_order_size
} else {
market.amm.order_step_size
};

if base_asset_amount < amm_size_threshold {
// if is an actual swap (and not amm jit order) then msg!
if override_base_asset_amount.is_none() {
msg!(
Expand Down
8 changes: 8 additions & 0 deletions programs/drift/src/instructions/admin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1937,6 +1937,14 @@ pub fn handle_update_liquidation_duration(
Ok(())
}

pub fn handle_update_liquidation_margin_buffer_ratio(
ctx: Context<AdminUpdateState>,
liquidation_margin_buffer_ratio: u32,
) -> Result<()> {
ctx.accounts.state.liquidation_margin_buffer_ratio = liquidation_margin_buffer_ratio;
Ok(())
}

pub fn handle_update_oracle_guard_rails(
ctx: Context<AdminUpdateState>,
oracle_guard_rails: OracleGuardRails,
Expand Down
7 changes: 7 additions & 0 deletions programs/drift/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,13 @@ pub mod drift {
handle_update_liquidation_duration(ctx, liquidation_duration)
}

pub fn update_liquidation_margin_buffer_ratio(
ctx: Context<AdminUpdateState>,
liquidation_margin_buffer_ratio: u32,
) -> Result<()> {
handle_update_liquidation_margin_buffer_ratio(ctx, liquidation_margin_buffer_ratio)
}

pub fn update_oracle_guard_rails(
ctx: Context<AdminUpdateState>,
oracle_guard_rails: OracleGuardRails,
Expand Down
2 changes: 1 addition & 1 deletion sdk/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.43.0-beta.15
2.43.0-beta.16
2 changes: 1 addition & 1 deletion sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@drift-labs/sdk",
"version": "2.43.0-beta.15",
"version": "2.43.0-beta.16",
"main": "lib/index.js",
"types": "lib/index.d.ts",
"author": "crispheaney",
Expand Down
14 changes: 14 additions & 0 deletions sdk/src/adminClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,20 @@ export class AdminClient extends DriftClient {
);
}

public async updateLiquidationMarginBufferRatio(
updateLiquidationMarginBufferRatio: number
): Promise<TransactionSignature> {
return await this.program.rpc.updateLiquidationMarginBufferRatio(
updateLiquidationMarginBufferRatio,
{
accounts: {
admin: this.wallet.publicKey,
state: await this.getStatePublicKey(),
},
}
);
}

public async updateOracleGuardRails(
oracleGuardRails: OracleGuardRails
): Promise<TransactionSignature> {
Expand Down
21 changes: 21 additions & 0 deletions sdk/src/idl/drift.json
Original file line number Diff line number Diff line change
Expand Up @@ -4098,6 +4098,27 @@
}
]
},
{
"name": "updateLiquidationMarginBufferRatio",
"accounts": [
{
"name": "admin",
"isMut": false,
"isSigner": true
},
{
"name": "state",
"isMut": true,
"isSigner": false
}
],
"args": [
{
"name": "liquidationMarginBufferRatio",
"type": "u32"
}
]
},
{
"name": "updateOracleGuardRails",
"accounts": [
Expand Down

0 comments on commit 53b096b

Please sign in to comment.