Skip to content

Commit

Permalink
Merge branch 'master' into crispheaney/quick-pause-withdraws
Browse files Browse the repository at this point in the history
  • Loading branch information
crispheaney committed Jan 2, 2025
2 parents 37c8c17 + 41f8743 commit dc6537f
Show file tree
Hide file tree
Showing 39 changed files with 1,770 additions and 1,165 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,14 @@ jobs:
run: npm publish --access=public
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
- name: Notify Slack on failure
if: failure()
uses: slackapi/[email protected]
env:
SLACK_BOT_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
with:
channel-id: '#code-review'
slack-message: '<!here> ❌ Deployment failed! Check the logs: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}'
emit-dispatch-events:
runs-on: ubicloud
needs: [release, check-for-sdk-changes]
Expand Down
12 changes: 11 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Features

### Fixes

### Breaking

## [2.104.0] - 2024-12-23

### Features

- program: pyth lazer integration ([#1361](https://github.com/drift-labs/protocol-v2/pull/1361))
- program: add ix to log user balances ([#1366](https://github.com/drift-labs/protocol-v2/pull/1366))

### Fixes

program: fix force delete user for token 2022 ([#1358](https://github.com/drift-labs/protocol-v2/pull/1358))
- program: fix force delete user for token 2022 ([#1358](https://github.com/drift-labs/protocol-v2/pull/1358))
- program: fix liquidating dust prediction mkt position ([#1397](https://github.com/drift-labs/protocol-v2/pull/1397))
- program: spot market decimals under 6 precision fixes ([#1399](https://github.com/drift-labs/protocol-v2/pull/1399))

### Breaking

Expand Down
23 changes: 7 additions & 16 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion deps/configs/pyth_lazer_storage.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"account": {
"lamports": 1461600,
"data": [
"0XX/ucSvRAkL/td28gTUmmjn6CkzKyvYXJOMcup4pEKu3cXcP7cvDAH2UhC+5Pz1sc7h5Tf6vP2VAQKXZTuUrwTUVPxHPpSDT+g2BnoAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==",
"0XX/ucSvRAkL/td28gTUmmjn6CkzKyvYXJOMcup4pEKu3cXcP7cvDAv+13byBNSaaOfoKTMrK9hck4xy6nikQq7dxdw/ty8MAQAAAAAAAAAB9lIQvuT89bHO4eU3+rz9lQECl2U7lK8E1FT8Rz6Ug0/oNgZ6AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"base64"
],
"owner": "pytd2yyk641x7ak7mkaasSJVXh6YYZnC7wTmtgAyxPt",
Expand Down
4 changes: 2 additions & 2 deletions programs/drift/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "drift"
version = "2.103.0"
version = "2.104.0"
description = "Created with Anchor"
edition = "2018"

Expand All @@ -22,7 +22,7 @@ anchor-lang = "0.29.0"
solana-program = "1.16"
anchor-spl = "0.29.0"
pyth-client = "0.2.2"
pyth-lazer-sdk = { git = "https://github.com/drift-labs/pyth-crosschain", rev = "776b6f772ba8ae49f26d16d04649073c3d6f77cf"}
pyth-lazer-solana-contract = { git = "https://github.com/drift-labs/pyth-crosschain", rev = "57ed54b2e0b1ce74a6d99c95302fec8752d7108f", features = ["no-entrypoint"]}
pythnet-sdk = { git = "https://github.com/drift-labs/pyth-crosschain", rev = "3e8a24ecd0bcf22b787313e2020f4186bb22c729"}
pyth-solana-receiver-sdk = { git = "https://github.com/drift-labs/pyth-crosschain", rev = "3e8a24ecd0bcf22b787313e2020f4186bb22c729"}
bytemuck = { version = "1.4.0" }
Expand Down
63 changes: 44 additions & 19 deletions programs/drift/src/controller/liquidation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,14 @@ pub fn liquidate_perp(
let quote_oracle_price = oracle_map
.get_price_data(&quote_spot_market.oracle_id())?
.price;
let liquidator_fee = market.liquidator_fee;

let liquidator_fee = get_liquidation_fee(
market.liquidator_fee,
market.get_max_liquidation_fee()?,
user.last_active_slot,
slot,
)?;

let if_liquidation_fee = calculate_perp_if_fee(
intermediate_margin_calculation.tracked_market_margin_shortage(margin_shortage)?,
user_base_asset_amount,
Expand All @@ -353,17 +360,24 @@ pub fn liquidate_perp(
quote_oracle_price,
market.if_liquidation_fee,
)?;
let base_asset_amount_to_cover_margin_shortage = standardize_base_asset_amount_ceil(

let mut base_asset_amount_to_cover_margin_shortage =
calculate_base_asset_amount_to_cover_margin_shortage(
margin_shortage,
margin_ratio_with_buffer,
liquidator_fee,
if_liquidation_fee,
oracle_price,
quote_oracle_price,
)?,
market.amm.order_step_size,
)?;
)?;

if base_asset_amount_to_cover_margin_shortage != u64::MAX {
base_asset_amount_to_cover_margin_shortage = standardize_base_asset_amount_ceil(
base_asset_amount_to_cover_margin_shortage,
market.amm.order_step_size,
)?;
}

drop(market);
drop(quote_spot_market);

Expand Down Expand Up @@ -407,21 +421,32 @@ pub fn liquidate_perp(

// Make sure liquidator enters at better than limit price
if let Some(limit_price) = limit_price {
// calculate fee in price terms
let oracle_price_u128 = oracle_price.cast::<u128>()?;
let fee = oracle_price_u128
.safe_mul(liquidator_fee.cast()?)?
.safe_div(LIQUIDATION_FEE_PRECISION_U128)?;
match user.perp_positions[position_index].get_direction() {
PositionDirection::Long => validate!(
oracle_price <= limit_price.cast()?,
ErrorCode::LiquidationDoesntSatisfyLimitPrice,
"limit price ({}) > oracle price ({})",
limit_price,
oracle_price
)?,
PositionDirection::Short => validate!(
oracle_price >= limit_price.cast()?,
ErrorCode::LiquidationDoesntSatisfyLimitPrice,
"limit price ({}) < oracle price ({})",
limit_price,
oracle_price
)?,
PositionDirection::Long => {
let transfer_price = oracle_price_u128.safe_sub(fee)?;
validate!(
transfer_price <= limit_price.cast()?,
ErrorCode::LiquidationDoesntSatisfyLimitPrice,
"limit price ({}) > transfer price ({})",
limit_price,
transfer_price
)?
}
PositionDirection::Short => {
let transfer_price = oracle_price_u128.safe_add(fee)?;
validate!(
transfer_price >= limit_price.cast()?,
ErrorCode::LiquidationDoesntSatisfyLimitPrice,
"limit price ({}) < transfer price ({})",
limit_price,
transfer_price
)?
}
}
}

Expand Down
Loading

0 comments on commit dc6537f

Please sign in to comment.