PrimaryLendingPlatformLeverageCore

Overview

License: MIT

abstract contract PrimaryLendingPlatformLeverageCore is Initializable, AccessControlUpgradeable, ReentrancyGuardUpgradeable

The PrimaryLendingPlatformLeverageCore contract is the core contract for the leverage functionality of the primary lending platform.

Contract that allows users to leverage their positions using the exchange aggregator.

Enums info

LeverageType

enum LeverageType {
	 AMPLIFY,
	 MARGIN_TRADE
}

Structs info

Ratio

struct Ratio {
	uint8 numerator;
	uint8 denominator;
}

Events info

SetExchangeAggregator

event SetExchangeAggregator(address indexed exchangeAggregator, address indexed registryAggregator)

Emitted when the exchange aggregator and registry aggregator addresses are set.

Parameters:

LeveragedBorrow

event LeveragedBorrow(address user, address projectToken, address lendingToken, uint256 notionalExposure, uint256 lendingAmount, uint256 margin, uint256 addingAmount, uint256 totalDepositedAmount, uint256 amountReceive)

Emitted when a user leverages their borrowing position.

Parameters:

SetPrimaryLendingPlatform

event SetPrimaryLendingPlatform(address indexed newPrimaryLendingPlatform)

Emitted when the primary lending platform address is set.

Parameters:

Constants info

MODERATOR_ROLE (0x797669c9)

bytes32 constant MODERATOR_ROLE = keccak256("MODERATOR_ROLE")

BUFFER_PERCENTAGE (0x952038c2)

uint16 constant BUFFER_PERCENTAGE = 500

State variables info

isLeveragePosition (0x3226d284)

mapping(address => mapping(address => bool)) isLeveragePosition

primaryLendingPlatform (0x92641a7c)

contract IPrimaryLendingPlatform primaryLendingPlatform

exchangeAggregator (0x60df4f35)

address exchangeAggregator

registryAggregator (0xf38cb29a)

address registryAggregator

typeOfLeveragePosition (0x4118a1bd)

mapping(address => mapping(address => enum PrimaryLendingPlatformLeverageCore.LeverageType)) typeOfLeveragePosition

Modifiers info

onlyModerator

modifier onlyModerator()

Modifier to restrict access to only the contract moderator.

isProjectTokenListed

modifier isProjectTokenListed(address projectToken)

Modifier to check if the given project token is listed on the primary lending platform.

Parameters:

isLendingTokenListed

modifier isLendingTokenListed(address lendingToken)

Modifier to check if the given lending token is listed on the primary lending platform.

Parameters:

isPrimaryLendingPlatform

modifier isPrimaryLendingPlatform()

Modifier to check if the caller is the primary lending platform contract.

onlyRelatedContracts

modifier onlyRelatedContracts()

Modifier to check if the caller is a related contract of the primary lending platform.

Functions info

initialize (0xc4d66de8)

function initialize(address pit) public initializer

Initializes the contract with the given parameters. This function is called only once when deploying the contract.

Parameters:

setExchangeAggregator (0x3c4841b4)

function setExchangeAggregator(
    address exchangeAggregatorAddress,
    address registryAggregatorAddress
) external onlyModerator

Updates the Exchange Aggregator contract and registry contract addresses.

Requirements:

  • The caller must be the moderator.

  • exchangeAggregatorAddress must not be the zero address.

  • registryAggregatorAddress must be a valid Augustus contract if it is not the zero address.

Parameters:

setPrimaryLendingPlatformAddress (0xcec5a0b0)

function setPrimaryLendingPlatformAddress(
    address newPrimaryLendingPlatform
) external onlyModerator

Sets the address of the primary lending platform contract.

Requirements:

  • Only the moderator can call this function.

  • The new primary lending platform address cannot be the zero address.

Parameters:

getTokenPrice (0xd02641a0)

function getTokenPrice(
    address token
) public view returns (uint256 collateralPrice, uint256 capitalPrice)

Returns the price of a given token in USD.

Parameters:

Return values:

calculateLendingTokenCount (0xcc65e637)

function calculateLendingTokenCount(
    address lendingToken,
    uint256 notionalValue
) public view returns (uint256 lendingTokenCount)

Calculates the lending token count for a given notional value.

Parameters:

Return values:

deleteLeveragePosition (0x0614a25a)

function deleteLeveragePosition(
    address user,
    address projectToken
) external isPrimaryLendingPlatform

Deletes a leverage position for a user and project token. The caller must be the primary lending platform.

Parameters:

calculateAddingAmount (0x545c5699)

function calculateAddingAmount(
    address user,
    address projectToken,
    uint256 marginCollateralCount
) public view returns (uint256 addingAmount)

Calculates the additional collateral amount needed for the specified user and project token.

Parameters:

Return values:

getLeverageType (0x68faa77f)

function getLeverageType(
    address borrower,
    address projectToken
) public view returns (uint8)

Gets type of Leverage Position for given borrower and projectToken.

Parameters:

Return values:

Last updated