Skip to main content

Mate2Liquidator.sol

Mate2Liquidator

A contract that handles the liquidation and claiming of positions in Chromatic markets. It implements the ILiquidator and the IMate2Automation interface.

DEFAULT_UPKEEP_GAS_LIMIT

uint32 DEFAULT_UPKEEP_GAS_LIMIT

DEFAULT_WAIT_POSITION_CLAIM

uint256 DEFAULT_WAIT_POSITION_CLAIM

automate

contract IMate2AutomationRegistry1_1 automate

upkeepGasLimit

uint32 upkeepGasLimit

waitPositionClaim

uint256 waitPositionClaim

UpkeepType

enum UpkeepType {
LiquidatePosition,
ClaimPosition
}

UpkeepGasLimitUpdated

event UpkeepGasLimitUpdated(uint32 gasLimitOld, uint32 gasLimitNew)

WaitPositionClaimUpdated

event WaitPositionClaimUpdated(uint256 waitPositionClaimOld, uint256 waitPositionClaimNew)

constructor

constructor(contract IChromaticMarketFactory _factory, address _automate) public

Constructor function.

  • Parameters:

    NameTypeDescription
    _factorycontract IChromaticMarketFactoryThe address of the Chromatic Market Factory contract.
    _automateaddressThe address of the Mate2 Automate contract.

createLiquidationTask

function createLiquidationTask(uint256 positionId) external

Creates a liquidation task for a given position.

Can only be called by a registered market.

  • Parameters:

    NameTypeDescription
    positionIduint256The ID of the position to be liquidated.

cancelLiquidationTask

function cancelLiquidationTask(uint256 positionId) external

Cancels a liquidation task for a given position.

Can only be called by a registered market.

  • Parameters:

    NameTypeDescription
    positionIduint256The ID of the position for which to cancel the liquidation task.

resolveLiquidation

function resolveLiquidation(address _market, uint256 positionId, bytes extraData) public view returns (bool canExec, bytes execPayload)

Resolves the liquidation of a position.

This function is called by the automation system.

  • Parameters:

    NameTypeDescription
    _marketaddress
    positionIduint256The ID of the position to be liquidated.
    extraDatabytespassed by keeper for passing offchain data
  • Return Values:

    NameTypeDescription
    canExecboolWhether the liquidation can be executed.
    execPayloadbytesThe encoded function call to execute the liquidation.

createClaimPositionTask

function createClaimPositionTask(uint256 positionId) external

Creates a claim position task for a given position.

Can only be called by a registered market.

  • Parameters:

    NameTypeDescription
    positionIduint256The ID of the position to be claimed.

cancelClaimPositionTask

function cancelClaimPositionTask(uint256 positionId) external

Cancels a claim position task for a given position.

Can only be called by a registered market.

  • Parameters:

    NameTypeDescription
    positionIduint256The ID of the position for which to cancel the claim position task.

resolveClaimPosition

function resolveClaimPosition(address _market, uint256 positionId, bytes extraData) public view returns (bool canExec, bytes execPayload)

Resolves the claim of a position.

This function is called by the automation system.

  • Parameters:

    NameTypeDescription
    _marketaddress
    positionIduint256The ID of the position to be claimed.
    extraDatabytespassed by keeper for passing offchain data
  • Return Values:

    NameTypeDescription
    canExecboolWhether the claim can be executed.
    execPayloadbytesThe encoded function call to execute the claim.

_registerUpkeep

function _registerUpkeep(mapping(address => mapping(uint256 => uint256)) registry, uint256 positionId, enum Mate2Liquidator.UpkeepType upkeepType, uint256 executableTime) internal

Internal function to create a Mate2 upkeep for liquidation or claim position.

  • Parameters:

    NameTypeDescription
    registrymapping(address => mapping(uint256 => uint256))The mapping to store task IDs.
    positionIduint256The ID of the position.
    upkeepTypeenum Mate2Liquidator.UpkeepType
    executableTimeuint256The upkeep executable time.

_cancelUpkeep

function _cancelUpkeep(mapping(address => mapping(uint256 => uint256)) registry, uint256 positionId) internal

Internal function to cancel a Mate2 upkeep.

  • Parameters:

    NameTypeDescription
    registrymapping(address => mapping(uint256 => uint256))The mapping storing task IDs.
    positionIduint256The ID of the position.

checkUpkeep

function checkUpkeep(bytes checkData, bytes extraData) external view returns (bool upkeepNeeded, bytes performData)

method that is simulated by the keepers to see if any work actually needs to be performed. This method does does not actually need to be executable, and since it is only ever simulated it can consume lots of gas.

To ensure that it is never called, you may want to add the cannotExecute modifier from KeeperBase to your implementation of this method.

  • Parameters:

    NameTypeDescription
    checkDatabytesspecified in the upkeep registration so it is always the same for a registered upkeep. This can easily be broken down into specific arguments using abi.decode, so multiple upkeeps can be registered on the same contract and easily differentiated by the contract.
    extraDatabytespassed by keeper for passing offchain data
  • Return Values:

    NameTypeDescription
    upkeepNeededboolboolean to indicate whether the keeper should call performUpkeep or not.
    performDatabytesbytes that the keeper should call performUpkeep with, if upkeep is needed. If you would like to encode data to decode later, try abi.encode.

performUpkeep

function performUpkeep(bytes performData) external

method that is actually executed by the keepers, via the registry. The data returned by the checkUpkeep simulation will be passed into this method to actually be executed.

The input to this method should not be trusted, and the caller of the method should not even be restricted to any single registry. Anyone should be able call it, and the input should be validated, there is no guarantee that the data passed in is the performData returned from checkUpkeep. This could happen due to malicious keepers, racing keepers, or simply a state change while the performUpkeep transaction is waiting for confirmation. Always validate the data passed in.

  • Parameters:

    NameTypeDescription
    performDatabytesis the data which was passed back from the checkData simulation. If it is encoded, it can easily be decoded into other types by calling abi.decode. This data should not be trusted, and should be validated against the contract's current state.

getLiquidationTaskId

function getLiquidationTaskId(address market, uint256 positionId) external view returns (bytes32 taskId)

getLiquidationUpkeepId

function getLiquidationUpkeepId(address market, uint256 positionId) public view returns (uint256 upkeepId)

getClaimPositionTaskId

function getClaimPositionTaskId(address market, uint256 positionId) external view returns (bytes32 taskId)

getClaimPositionUpkeepId

function getClaimPositionUpkeepId(address market, uint256 positionId) public view returns (uint256 upkeepId)

_getFeeInfo

function _getFeeInfo() internal view returns (uint256 fee, address feePayee)

cancelUpkeep

function cancelUpkeep(uint256 upkeepId) external

updateUpkeepGasLimit

function updateUpkeepGasLimit(uint32 gasLimit) external

updateWaitPositionClaim

function updateWaitPositionClaim(uint256 _waitPositionClaim) external