Skip to content

Commit

Permalink
chore: format
Browse files Browse the repository at this point in the history
  • Loading branch information
losman0s committed Nov 22, 2023
1 parent f1e431c commit 06e6057
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions packages/marginfi-client-v2/src/models/account/pure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,15 +254,17 @@ class MarginfiAccount {
MarginRequirementType.Initial
);

// ----------------------------------------------------------------------------------------------------------------- //
// isolated bank (=> init weight = maint weight = 0) or collateral bank with 0-weights (does not happen in practice) //
// ----------------------------------------------------------------------------------------------------------------- //
// -------------------------------------------------- //
// isolated bank (=> init weight = maint weight = 0) //
// or collateral bank with 0-weights (does not happen //
// in practice) //
// -------------------------------------------------- //

if (bank.config.riskTier === RiskTier.Isolated || (initAssetWeight.isZero() && maintAssetWeight.isZero())) {
if (freeCollateral.isZero() && !liabilitiesInit.isZero()) {
// if account is already below init requirements and has active debt, prevent any withdrawal even if those don't count as collateral
// inefficient, but reflective of contract which does not look at action delta, but only end state atm
return new BigNumber(0);
return new BigNumber(0);
} else {
return entireBalance;
}
Expand Down Expand Up @@ -293,22 +295,22 @@ class MarginfiAccount {
// ------------------------------------- //
// collateral bank with positive weights //
// ------------------------------------- //
console.log("here")
console.log("here");
// bypass volatility factor if no liabilities or if all collateral is untied
if (liabilitiesInit.isZero() || initCollateralForBank.lte(freeCollateral)) {
console.log("aqui")
console.log("aqui");
return entireBalance;
}

// apply volatility factor to avoid failure due to price volatility / slippage
const initUntiedCollateralForBank = freeCollateral.times(_volatilityFactor);
console.log("initUntiedCollateralForBank", initUntiedCollateralForBank.toFixed(6))
console.log("initUntiedCollateralForBank", initUntiedCollateralForBank.toFixed(6));
const priceLowestBias = bank.getPrice(priceInfo, PriceBias.Lowest);
console.log("priceLowestBias", priceLowestBias.toFixed(6))
console.log("priceLowestBias", priceLowestBias.toFixed(6));
const initWeightedPrice = priceLowestBias.times(initAssetWeight);
console.log("initWeightedPrice", initWeightedPrice.toFixed(6))
console.log("initWeightedPrice", initWeightedPrice.toFixed(6));
const maxWithdraw = initUntiedCollateralForBank.div(initWeightedPrice);
console.log("maxWithdraw", maxWithdraw.toFixed(6))
console.log("maxWithdraw", maxWithdraw.toFixed(6));

return maxWithdraw;
}
Expand Down

0 comments on commit 06e6057

Please sign in to comment.