Skip to content

Commit

Permalink
Update volatility factor and compute max withdraw
Browse files Browse the repository at this point in the history
for bank
  • Loading branch information
jkbpvsc authored and chambaz committed Dec 13, 2023
1 parent 0a192ea commit 89680f6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 4 additions & 1 deletion packages/marginfi-client-v2/src/models/account/pure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,10 @@ class MarginfiAccount {
}

// apply volatility factor to avoid failure due to price volatility / slippage
const initUntiedCollateralForBank = freeCollateral.times(_volatilityFactor);
// initCollateralForBank > freeCollateral, so volatilityBuffer > 0
const volatilityBuffer = (initCollateralForBank.minus(freeCollateral)).times(1 - _volatilityFactor);
const initUntiedCollateralForBank = freeCollateral.minus(volatilityBuffer);

const priceLowestBias = bank.getPrice(priceInfo, PriceBias.Lowest);
const initWeightedPrice = priceLowestBias.times(initAssetWeight);
const maxWithdraw = initUntiedCollateralForBank.div(initWeightedPrice);
Expand Down
4 changes: 2 additions & 2 deletions packages/marginfi-v2-ui-state/src/lib/mrgnlend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { Connection, PublicKey, SystemProgram } from "@solana/web3.js";
import BN from "bn.js";

const FEE_MARGIN = 0.01;
const VOLATILITY_FACTOR = 0.98;
const VOLATILITY_FACTOR = 0.975;

const DEFAULT_ACCOUNT_SUMMARY = {
healthFactor: 0,
Expand Down Expand Up @@ -347,7 +347,7 @@ function makeExtendedBankInfo(

const maxWithdraw = floor(
Math.min(
marginfiAccount.computeMaxWithdrawForBank(bank.address).toNumber(),
marginfiAccount.computeMaxWithdrawForBank(bank.address, { volatilityFactor: VOLATILITY_FACTOR }).toNumber(),
bankInfo.availableLiquidity
),
bankInfo.mintDecimals
Expand Down

3 comments on commit 89680f6

@vercel
Copy link

@vercel vercel bot commented on 89680f6 Dec 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

marginfi-landing-page – ./apps/marginfi-landing-page

marginfi-landing-page.vercel.app
marginfi-landing-page-mrgn.vercel.app
www.marginfi.com
marginfi-landing-page-git-production-mrgn.vercel.app
marginfi.com

@vercel
Copy link

@vercel vercel bot commented on 89680f6 Dec 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

omni – ./apps/omni

omni-mrgn.vercel.app
omni-git-production-mrgn.vercel.app
omni-one.vercel.app
omni.marginfi.com

@vercel
Copy link

@vercel vercel bot commented on 89680f6 Dec 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.