MCDEXLemma

Smart contract wrapper for the MCDEX derivatives exchange

This contract interacts with the MCDEX derivatives exchange to open and close the short position. It implements the IPerpetualDexWrapper interface, which is a more general wrapper for all derivative dexes Lemma is integrated with.

Public Functions

getCollateralAmountGivenUnderlyingAssetAmount

function getCollateralAmountGivenUnderlyingAssetAmount(
    uint256 amount, 
    bool isShorting) public returns (uint256 collateralAmountRequired)

Function purpose: given an amount of USDL to be minted or redeemed, returns how much WETH is required or that will be received.

ParametersDescriptionAttribute

amount

USDL amount to be minted or redeemed.

USD, 18 decimals

isShorting

True, if minting USDL. False, if redeeming USDL.

Boolean

collateralAmountRequired

Amount of WETH required to mint given USDL amount or WETH to be received when redeeming given amount of USDL.

WETH, 18 decimals

getFundingPNL

function getFundingPNL() public view returns (int256 fundingPNL)

Function purpose: get total funding PnL for MCDEXLemma address from inception till now.

ParametersDescriptionAttribute

fundingPNL

Total funding PnL for MCDEXLemma address from inception till now.

WETH, 18 decimals

getAmountInCollateralDecimals

function getAmountInCollateralDecimals(
    uint256 amount, 
    bool roundUp) 
    public view returns (uint256)

Function purpose: given an asset type (eg. WETH, WBTC...) and an 18 decimal amount, return the amount in the appropriate decimal amount for the asset type. Currently, this function is not useful since the only available collateral asset is WETH which is 18 decimals.

ParametersDescriptionAttribute

amount

Amount of asset type.

WETH, 18 decimals

roundUp

True, if you would like to round up upon conversion. False, if not.

Boolean

settle

function settle()

Function purpose: if MCDEX ever executes a "forced settlement" of perpetuals, this function can be called by anyone to send all of the WETH used as collateral on the dex back to the MCDEXLemma contract.

sendMCBToTreasury

function sendMCBToTreasury()

Function purpose: Sends all collected MCB tokens to the Lemma treasury.

USDLemma Restricted Functions

The restricted functions below can only be called by the USDLemma contract.

open

function open(uint256 amount, uint256 collateralAmountRequired)

This function allows the USDLemma contract to deposit WETH collateral and open a corresponding short position on MCDEX.

close

function close(uint256 amount, uint256 collateralAmountToGetBack)

This function allows the USDLemma contract to close a short position and withdraw the corresponding WETH collateral on MCDEX.

reBalance

function reBalance(
        address _reBalancer,
        int256 amount,
        bytes calldata data)

This function allows the USDLemma contract to execute the rebalancing mechanism.

Owner Restricted Functions

The restricted functions below can only be called by owner of the contract, which will be a multi sig.

setUSDLemma

function setUSDLemma(address _usdlemma)

This function allows Lemma to set the USDLemma (core contract) address.

setReferrer

function setReferrer(address _referrer)

This function allows Lemma to set the referrer address. Referrers on MCDEX receive rebates and MCB tokens. It will be set to the Lemma treasury address.

setReBalancer

function setReBalancer(address _reBalancer)

This function allows Lemma to whitelist an address to give them the permission to execute the rebalancing mechanism.

setMaxPosition

function setMaxPosition(uint256 _maxPosition)

This function allows Lemma to set the max amount of USDL that can be minted on this derivative dex (ie. setting a debt ceiling).

depositKeeperGasReward

function depositKeeperGasReward()

This function allows Lemma to transfer WETH from its treasury to MCDEX in order to reward keepers for certain actions (required by MCDEX).

Last updated