View Source: contracts/mixins/LiquidationHelper.sol
↗ Extends: State ↘ Derived Contracts: LoanClosingsLiquidation, LoanClosingsRollover, LoanMaintenance
This contract code comes from bZx. bZx is a protocol for tokenized margin trading and lending https://bzx.network similar to the dYdX protocol.
- This contract computes the liquidation amount.
Compute how much needs to be liquidated in order to restore the desired margin (maintenance + 5%). *
function _getLiquidationAmounts(uint256 principal, uint256 collateral, uint256 currentMargin, uint256 maintenanceMargin, uint256 collateralToLoanRate) internal view
returns(maxLiquidatable uint256, maxSeizable uint256, incentivePercent uint256)
Arguments
Name | Type | Description |
---|---|---|
principal | uint256 | The total borrowed amount (in loan tokens). |
collateral | uint256 | The collateral (in collateral tokens). |
currentMargin | uint256 | The current margin. |
maintenanceMargin | uint256 | The maintenance (minimum) margin. |
collateralToLoanRate | uint256 | The exchange rate from collateral to loan tokens. * |
Returns
maxLiquidatable The collateral you can get liquidating.
Source Code
function _getLiquidationAmounts(
uint256 principal,
uint256 collateral,
uint256 currentMargin,
uint256 maintenanceMargin,
uint256 collateralToLoanRate
)
internal
view
returns (
uint256 maxLiquidatable,
uint256 maxSeizable,
uint256 incentivePercent
)
{
incentivePercent = liquidationIncentivePercent;
if (currentMargin > maintenanceMargin || collateralToLoanRate == 0) {
return (maxLiquidatable, maxSeizable, incentivePercent);
} else if (currentMargin <= incentivePercent) {
return (principal, collateral, currentMargin);
}
/// 5 percentage points above maintenance.
uint256 desiredMargin = maintenanceMargin.add(5 ether);
/// maxLiquidatable = ((1 + desiredMargin)*principal - collateralToLoanRate*collateral) / (desiredMargin - 0.05)
maxLiquidatable = desiredMargin.add(10**20).mul(principal).div(10**20);
maxLiquidatable = maxLiquidatable.sub(collateral.mul(collateralToLoanRate).div(10**18));
maxLiquidatable = maxLiquidatable.mul(10**20).div(desiredMargin.sub(incentivePercent));
if (maxLiquidatable > principal) {
maxLiquidatable = principal;
}
/// maxSeizable = maxLiquidatable * (1 + incentivePercent) / collateralToLoanRate
maxSeizable = maxLiquidatable.mul(incentivePercent.add(10**20));
maxSeizable = maxSeizable.div(collateralToLoanRate).div(100);
if (maxSeizable > collateral) {
maxSeizable = collateral;
}
return (maxLiquidatable, maxSeizable, incentivePercent);
}
- Address
- Administered
- AdminRole
- AdvancedToken
- AdvancedTokenStorage
- Affiliates
- AffiliatesEvents
- ApprovalReceiver
- BProPriceFeed
- CheckpointsShared
- Constants
- Context
- DevelopmentFund
- DummyContract
- EnumerableAddressSet
- EnumerableBytes32Set
- EnumerableBytes4Set
- ERC20
- ERC20Detailed
- ErrorDecoder
- Escrow
- EscrowReward
- FeedsLike
- FeesEvents
- FeeSharingCollector
- FeeSharingCollectorProxy
- FeeSharingCollectorStorage
- FeesHelper
- FourYearVesting
- FourYearVestingFactory
- FourYearVestingLogic
- FourYearVestingStorage
- GenericTokenSender
- GovernorAlpha
- GovernorVault
- IApproveAndCall
- IChai
- IContractRegistry
- IConverterAMM
- IERC1820Registry
- IERC20_
- IERC20
- IERC777
- IERC777Recipient
- IERC777Sender
- IFeeSharingCollector
- IFourYearVesting
- IFourYearVestingFactory
- IFunctionsList
- ILiquidityMining
- ILiquidityPoolV1Converter
- ILoanPool
- ILoanToken
- ILoanTokenLogicBeacon
- ILoanTokenLogicModules
- ILoanTokenLogicProxy
- ILoanTokenModules
- ILoanTokenWRBTC
- ILockedSOV
- IMoCState
- IModulesProxyRegistry
- Initializable
- InterestUser
- IPot
- IPriceFeeds
- IPriceFeedsExt
- IProtocol
- IRSKOracle
- ISovryn
- ISovrynSwapNetwork
- IStaking
- ISwapsImpl
- ITeamVesting
- ITimelock
- IV1PoolOracle
- IVesting
- IVestingFactory
- IVestingRegistry
- IWrbtc
- IWrbtcERC20
- LenderInterestStruct
- LiquidationHelper
- LiquidityMining
- LiquidityMiningConfigToken
- LiquidityMiningProxy
- LiquidityMiningStorage
- LoanClosingsEvents
- LoanClosingsLiquidation
- LoanClosingsRollover
- LoanClosingsShared
- LoanClosingsWith
- LoanClosingsWithoutInvariantCheck
- LoanInterestStruct
- LoanMaintenance
- LoanMaintenanceEvents
- LoanOpenings
- LoanOpeningsEvents
- LoanParamsStruct
- LoanSettings
- LoanSettingsEvents
- LoanStruct
- LoanToken
- LoanTokenBase
- LoanTokenLogicBeacon
- LoanTokenLogicLM
- LoanTokenLogicProxy
- LoanTokenLogicStandard
- LoanTokenLogicStorage
- LoanTokenLogicWrbtc
- LoanTokenSettingsLowerAdmin
- LockedSOV
- MarginTradeStructHelpers
- Medianizer
- ModuleCommonFunctionalities
- ModulesCommonEvents
- ModulesProxy
- ModulesProxyRegistry
- MultiSigKeyHolders
- MultiSigWallet
- Mutex
- Objects
- OrderStruct
- OrigingVestingCreator
- OriginInvestorsClaim
- Ownable
- Pausable
- PausableOz
- PreviousLoanToken
- PreviousLoanTokenSettingsLowerAdmin
- PriceFeedRSKOracle
- PriceFeeds
- PriceFeedsLocal
- PriceFeedsMoC
- PriceFeedV1PoolOracle
- ProtocolAffiliatesInterface
- ProtocolLike
- ProtocolSettings
- ProtocolSettingsEvents
- ProtocolSettingsLike
- ProtocolSwapExternalInterface
- ProtocolTokenUser
- Proxy
- ProxyOwnable
- ReentrancyGuard
- RewardHelper
- RSKAddrValidator
- SafeERC20
- SafeMath
- SafeMath96
- setGet
- SharedReentrancyGuard
- SignedSafeMath
- SOV
- sovrynProtocol
- StakingAdminModule
- StakingGovernanceModule
- StakingInterface
- StakingProxy
- StakingRewards
- StakingRewardsProxy
- StakingRewardsStorage
- StakingShared
- StakingStakeModule
- StakingStorageModule
- StakingStorageShared
- StakingVestingModule
- StakingWithdrawModule
- State
- SwapsEvents
- SwapsExternal
- SwapsImplLocal
- SwapsImplSovrynSwap
- SwapsUser
- TeamVesting
- Timelock
- TimelockHarness
- TimelockInterface
- TokenSender
- UpgradableProxy
- USDTPriceFeed
- Utils
- VaultController
- Vesting
- VestingCreator
- VestingFactory
- VestingLogic
- VestingRegistry
- VestingRegistry2
- VestingRegistry3
- VestingRegistryLogic
- VestingRegistryProxy
- VestingRegistryStorage
- VestingStorage
- WeightedStakingModule
- WRBTC