Skip to content

Commit

Permalink
program: do imf size discount for maintainance spot asset weight (#343)
Browse files Browse the repository at this point in the history
* bigz/size-discount-maint-ast-wgt

* rm deps/serum-dex

* add changelog

* Revert "rm deps/serum-dex"

This reverts commit 73a4a3d.

* revet deps/serum-dex

---------

Co-authored-by: Chris Heaney <[email protected]>
  • Loading branch information
0xbigz and crispheaney committed Feb 3, 2023
1 parent 8a7d488 commit 1c14532
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]

### Features
- program: do imf size discount for maintainance spot asset weight ([#343](https://github.com/drift-labs/protocol-v2/pull/343))

- ts-sdk: new liquidation price to account for delta neutral strategies ([#340](https://github.com/drift-labs/protocol-v2/pull/340))
- ts-sdk: add txParams to all instructions, bump @solana/web3.js ([#344](https://github.com/drift-labs/protocol-v2/pull/344))
Expand Down
18 changes: 12 additions & 6 deletions programs/drift/src/state/spot_market.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,20 @@ impl SpotMarket {
} else {
(size * AMM_RESERVE_PRECISION) / size_precision
};
let asset_weight = match margin_requirement_type {
MarginRequirementType::Initial => calculate_size_discount_asset_weight(
size_in_amm_reserve_precision,
self.imf_factor,
self.initial_asset_weight,
)?,

let default_asset_weight = match margin_requirement_type {
MarginRequirementType::Initial => self.initial_asset_weight,
MarginRequirementType::Maintenance => self.maintenance_asset_weight,
};

let size_based_asset_weight = calculate_size_discount_asset_weight(
size_in_amm_reserve_precision,
self.imf_factor,
default_asset_weight,
)?;

let asset_weight = size_based_asset_weight.min(default_asset_weight);

Ok(asset_weight)
}

Expand Down
6 changes: 5 additions & 1 deletion sdk/src/math/spotBalance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,11 @@ export function calculateAssetWeight(
);
break;
case 'Maintenance':
assetWeight = new BN(spotMarket.maintenanceAssetWeight);
assetWeight = calculateSizeDiscountAssetWeight(
sizeInAmmReservePrecision,
new BN(spotMarket.imfFactor),
new BN(spotMarket.maintenanceAssetWeight)
);
break;
default:
assetWeight = new BN(spotMarket.initialAssetWeight);
Expand Down

0 comments on commit 1c14532

Please sign in to comment.