PrimaryLendingPlatformV2Core
Overview
License: MIT
Core contract for the Primary Lending Platform V2.
Abstract contract that defines the core functionality of the primary lending platform.
Structs info
Ratio
ProjectTokenInfo
LendingTokenInfo
BorrowPosition
Events info
Deposit
Emitted when a user deposits project tokens.
Parameters:
who
address
The address of the user who deposited the tokens.
tokenPrj
address
The address of the project token that was deposited.
prjDepositAmount
uint256
The amount of project tokens that were deposited.
beneficiary
address
The address of the beneficiary who will receive the deposited tokens.
Withdraw
Emitted when a user withdraws project tokens.
Parameters:
who
address
The address of the user who withdrew the tokens.
tokenPrj
address
The address of the project token that was withdrawn.
lendingToken
address
The address of the lending token that was used as collateral.
prjWithdrawAmount
uint256
The amount of project tokens that were withdrawn.
beneficiary
address
The address of the beneficiary who will receive the withdrawn tokens.
Supply
Emitted when a user supplies lending tokens.
Parameters:
who
address
The address of the user who supplied the tokens.
supplyToken
address
The address of the token that was supplied.
supplyAmount
uint256
The amount of tokens that were supplied.
supplyBToken
address
The address of the bToken that was received in exchange for the supplied tokens.
amountSupplyBTokenReceived
uint256
The amount of bTokens that were received in exchange for the supplied tokens.
Redeem
Emitted when a user redeems bTokens for the underlying token.
Parameters:
who
address
The address of the user who redeemed the tokens.
redeemToken
address
The address of the token that was redeemed.
redeemBToken
address
The address of the bToken that was redeemed.
redeemAmount
uint256
The amount of bTokens that were redeemed.
RedeemUnderlying
Emitted when a user redeems underlying token for the bToken.
Parameters:
who
address
The address of the user who redeemed the tokens.
redeemToken
address
The address of the token that was redeemed.
redeemBToken
address
The address of the bToken that was redeemed.
redeemAmountUnderlying
uint256
The amount of underlying tokens that were redeemed.
Borrow
Emitted when a user borrows lending tokens.
Parameters:
who
address
The address of the user who borrowed the tokens.
borrowToken
address
The address of the token that was borrowed.
borrowAmount
uint256
The amount of tokens that were borrowed.
prjAddress
address
The address of the project token that was used as collateral.
prjAmount
uint256
The amount of project tokens that were used as collateral.
RepayBorrow
Emitted when a user repays borrowed lending tokens.
Parameters:
who
address
The address of the user who repaid the tokens.
borrowToken
address
The address of the token that was repaid.
borrowAmount
uint256
The amount of tokens that were repaid.
prjAddress
address
The address of the project token that was used as collateral.
isPositionFullyRepaid
bool
A boolean indicating whether the entire borrow position was repaid.
SetModeratorContract
Emitted when the moderator contract address is updated.
Parameters:
newAddress
address
The address of the new moderator contract.
Constants info
MODERATOR_ROLE (0x797669c9)
State variables info
priceOracle (0x2630c12f)
projectTokens (0xb269449f)
projectTokenInfo (0x85f4da5c)
lendingTokens (0x6f5f74f2)
lendingTokenInfo (0x3299093b)
totalDepositedProjectToken (0xef867f0f)
borrowPosition (0xa9ce9417)
totalBorrow (0xb090cf22)
borrowLimitPerCollateral (0x739d7547)
totalBorrowPerLendingToken (0xc3ee8b6f)
borrowLimitPerLendingToken (0x9f9184db)
isRelatedContract (0x25de3084)
primaryLendingPlatformLeverage (0x10c0bbed)
primaryLendingPlatformModerator (0xf32d0f2f)
Modifiers info
onlyAdmin
Modifier that allows only the admin to call the function.
isProjectTokenListed
Modifier that requires the project token to be listed.
Parameters:
projectToken
address
The address of the project token.
isLendingTokenListed
Modifier that requires the lending token to be listed.
Parameters:
lendingToken
address
The address of the lending token.
onlyRelatedContracts
Modifier that allows only related contracts to call the function.
onlyModeratorContract
Modifier that allows only the moderator contract to call the function.
Functions info
initialize (0x8129fc1c)
Initializes the contract and sets the name, symbol, and default roles.
setPrimaryLendingPlatformModerator (0x4123cf11)
Sets the address of the new moderator contract for the Primary Lending Platform.
Requirements:
newModeratorContract
cannot be the zero address.Only the admin can call this function.
Parameters:
newModeratorContract
address
The address of the new moderator contract.
setPriceOracle (0x530e784f)
Sets the price oracle contract address.
Requirements:
Only the moderator contract can call this function.
Parameters:
newPriceOracle
address
The address of the new price oracle contract.
setPrimaryLendingPlatformLeverage (0xa1ab5419)
Sets the address of the new primary index token leverage contract by the moderator contract.
Requirements:
Only the moderator contract can call this function.
Parameters:
newPrimaryLendingPlatformLeverage
address
The address of the new primary index token leverage contract.
setRelatedContract (0xdcb4252a)
Sets the related contract status for a given contract address.
Requirements:
The caller must be the moderator contract.
Parameters:
relatedContract
address
The address of the contract to set the related status for.
isRelated
bool
The related status to set for the contract.
removeProjectToken (0x3af44bfa)
Removes a project token from the platform.
Requirements:
The caller must be the moderator contract.
The project token must exist in the platform.
Parameters:
projectTokenId
uint256
The ID of the project token to remove.
projectToken
address
The address of the project token to remove.
removeLendingToken (0xc1ab02ee)
Removes a lending token from the platform.
Requirements:
The caller must be the moderator contract.
The lending token address must be valid.
Parameters:
lendingTokenId
uint256
The ID of the lending token to be removed.
lendingToken
address
The address of the lending token to be removed.
setBorrowLimitPerCollateralAsset (0x8e85cdfa)
Sets the borrow limit for a specific collateral asset.
Requirements:
The caller must be the moderator contract.
Parameters:
projectToken
address
The address of the collateral asset.
newBorrowLimit
uint256
The new borrow limit for the collateral asset.
setBorrowLimitPerLendingAsset (0x92a39190)
Sets the borrow limit for a specific lending asset.
Requirements:
The caller must be the moderator contract.
Parameters:
lendingToken
address
The address of the lending asset.
newBorrowLimit
uint256
The new borrow limit for the lending asset.
setProjectTokenInfo (0x4a5333bc)
Sets the information of a project token.
Requirements:
The caller must be the moderator contract.
Parameters:
projectToken
address
The address of the project token.
isDepositPaused
bool
A boolean indicating whether deposit is paused for the project token.
isWithdrawPaused
bool
A boolean indicating whether withdraw is paused for the project token.
loanToValueRatioNumerator
uint8
The numerator of the loan-to-value ratio for the project token.
loanToValueRatioDenominator
uint8
The denominator of the loan-to-value ratio for the project token.
setLendingTokenInfo (0x821363a0)
Sets the lending token information for a given lending token.
Requirements:
The caller must be the moderator contract.
Parameters:
lendingToken
address
The address of the lending token.
bLendingToken
address
The address of the corresponding bLending token.
isPaused
bool
A boolean indicating whether the lending token is paused or not.
loanToValueRatioNumerator
uint8
The numerator of the loan-to-value ratio for the lending token.
loanToValueRatioDenominator
uint8
The denominator of the loan-to-value ratio for the lending token.
deposit (0x47e7ef24)
Deposits project tokens into the platform.
Deposits project tokens and calculates the deposit position.
Requirements:
The project token must be listed.
The project token must not be paused for deposits.
The project token amount must be greater than 0.
Effects:
Transfers the project tokens from the user to the contract.
Calculates the deposit position for the user.
Parameters:
projectToken
address
The address of the project token to be deposited.
projectTokenAmount
uint256
The amount of project tokens to be deposited.
depositFromRelatedContracts (0xbf423b75)
Deposits project tokens from related contracts into the platform.
Requirements:
The project token must be listed.
Caller must be a related contract.
The project token must not be paused for deposits.
The project token amount must be greater than 0.
Effects:
Transfers the project tokens from the user to the contract.
Calculates the deposit position for the user.
Parameters:
projectToken
address
The address of the project token being deposited.
projectTokenAmount
uint256
The amount of project tokens being deposited.
user
address
The address of the user depositing the tokens.
beneficiary
address
The address of the beneficiary receiving the tokens.
calcAndTransferDepositPosition (0x556d4704)
Calculates and transfers the deposit position of a user for a specific project token.
Requirements:
The project token must be listed.
Called by a related contract.
Effects:
Decreases the deposited project token amount in the user's deposit position.
Decreases the total deposited project token amount.
Transfers the project tokens to the receiver.
Parameters:
projectToken
address
The address of the project token.
projectTokenAmount
uint256
The amount of project token to transfer.
user
address
The address of the user whose deposit position is being transferred.
receiver
address
The address of the receiver of the project token.
Return values:
[0]
uint256
The amount of project token transferred.
calcDepositPosition (0xdf5e6bed)
Calculates the deposit position for a user based on the project token, project token amount and user address.
Requirements:
The project token must be listed.
Called by a related contract.
Parameters:
projectToken
address
The address of the project token.
projectTokenAmount
uint256
The amount of project token.
user
address
The address of the user.
getCollateralAvailableToWithdraw (0x72620613)
Calculates the amount of collateral available to withdraw for a given account, project token and lending token.
Parameters:
account
address
The address of the account.
projectToken
address
The address of the project token.
lendingToken
address
The address of the lending token.
Return values:
collateralProjectToWithdraw
uint256
The amount of collateral available to withdraw.
calcBorrowPosition (0x2dfee307)
Allows a related contract to calculate the new borrow position of a user.
Requirements:
The project token must be listed.
The lending token must be listed.
Called by a related contract.
Parameters:
borrower
address
The address of the user for whom the borrow position is being calculated.
projectToken
address
The address of the project token being used as collateral.
lendingToken
address
The address of the lending token being borrowed.
lendingTokenAmount
uint256
The amount of lending tokens being borrowed.
currentLendingToken
address
The address of the current lending token being used as collateral.
getLendingAvailableToBorrow (0x07445b52)
Calculates the lending token available amount for borrowing.
Parameters:
account
address
Address of the user.
projectToken
address
Address of the project token.
lendingToken
address
Address of the lending token.
Return values:
availableToBorrow
uint256
The amount of lending token available amount for borrowing.
repay (0x1da649cf)
Repays a specified amount of lendingToken for a given project token and lending token.
Allows a borrower to repay their outstanding loan for a given project token and lending token.
Requirements:
The project token must be listed.
The lending token must be listed.
The lending amount must be greater than 0.
The borrower must have an outstanding loan for the given project and lending token before.
Effects: Updates the interest in the borrower's borrow positions for the given lendingToken
.
Repays the specified
lendingTokenAmount
towards the borrower's loan.May fully or partially repay the borrow position, depending on the repayment amount and outstanding loan.
Parameters:
projectToken
address
The project token's address.
lendingToken
address
The lending token's address.
lendingTokenAmount
uint256
The amount of lending tokens to repay.
Return values:
[0]
uint256
amount of lending tokens actually repaid.
repayFromRelatedContract (0xf432e4e2)
Allows a related contract to repay the outstanding loan for a given borrower's project token and lending token.
Requirements:
The project token must be listed.
The lending token must be listed.
Called by a related contract.
The lending amount must be greater than 0.
The borrower must have an outstanding loan for the given project and lending token before.
Effects: Updates the interest in the borrower's borrow positions for the given lendingToken
.
Repays the specified
lendingTokenAmount
towards the borrower's loan.May fully or partially repay the borrow position, depending on the repayment amount and outstanding loan.
Parameters:
projectToken
address
The project token's address.
lendingToken
address
The lending token's address.
lendingTokenAmount
uint256
The amount of lending tokens to repay.
repairer
address
The address that initiated the repair transaction.
borrower
address
The borrower's address.
Return values:
[0]
uint256
amount of lending tokens actually repaid.
updateInterestInBorrowPositions (0x9a812edd)
This function is called to update the interest in a borrower's borrow position.
Parameters:
account
address
Address of the borrower.
lendingToken
address
Address of the lending token.
getTokensUpdateFinalPrices (0xef290120)
This function is called when performing operations using token prices, to determine which tokens will need to update their final price.
Parameters:
projectToken
address
Address of the project token.
actualLendingToken
address
Address of the lending token.
isBorrow
bool
Whether getting the list of tokens for updateFinalPrices is related to the borrowing operation or not.
Return values:
tokens
address[]
Array of tokens that need to update final price.
pit (0x72d456af)
Returns the PIT (primary index token) value for a given account and position after a position is opened.
Formula: pit = $ * LVR of position.
Parameters:
account
address
Address of the account.
projectToken
address
Address of the project token.
lendingToken
address
Address of the lending token.
Return values:
[0]
uint256
The PIT value.
pitCollateral (0x1893be9f)
Returns the PIT (primary index token) value for a given account and collateral before a position is opened.
Formula: pit = $ * LVR of project token.
Parameters:
account
address
Address of the account.
projectToken
address
Address of the project token.
Return values:
[0]
uint256
The PIT value.
getLendingToken (0x2ce36230)
Returns the actual lending token of a user's borrow position for a specific project token.
Parameters:
user
address
The address of the user's borrow position.
projectToken
address
The address of the project token.
Return values:
actualLendingToken
address
The address of the actual lending token.
pitRemaining (0xd1a3d2ae)
Returns the remaining PIT (primary index token) of a user's borrow position.
Parameters:
account
address
The address of the user's borrow position.
projectToken
address
The address of the project token.
lendingToken
address
The address of the lending token.
Return values:
remaining
uint256
The remaining PIT of the user's borrow position.
totalOutstanding (0xac15382f)
Returns the total outstanding amount of a user's borrow position for a specific project token and lending token.
Parameters:
account
address
The address of the user's borrow position.
projectToken
address
The address of the project token.
lendingToken
address
The address of the lending token.
Return values:
[0]
uint256
total outstanding amount of the user's borrow position.
healthFactor (0xcc224bff)
Returns the health factor of a user's borrow position for a specific project token and lending token.
Parameters:
account
address
The address of the user's borrow position.
projectToken
address
The address of the project token.
lendingToken
address
The address of the lending token.
Return values:
numerator
uint256
The numerator of the health factor.
denominator
uint256
The denominator of the health factor.
getTokenEvaluation (0x3598a7a9)
Returns the price of a specific token amount in USD.
Parameters:
token
address
The address of the token to evaluate.
tokenAmount
uint256
The amount of the token to evaluate.
Return values:
collateralEvaluation
uint256
the USD evaluation of token by its tokenAmount
in collateral price
capitalEvaluation
uint256
the USD evaluation of token by its tokenAmount
in capital price
lendingTokensLength (0x2412b575)
Returns the length of the lending tokens array.
Return values:
[0]
uint256
The length of the lending tokens array.
projectTokensLength (0x4a41d29e)
Returns the length of the project tokens array.
Return values:
[0]
uint256
The length of the project tokens array.
getPosition (0x713390f5)
Returns the details of a user's borrow position for a specific project token and lending token.
Parameters:
account
address
The address of the user's borrow position.
projectToken
address
The address of the project token.
lendingToken
address
The address of the lending token.
Return values:
depositedProjectTokenAmount
uint256
The amount of project tokens deposited by the user.
loanBody
uint256
The amount of the lending token borrowed by the user.
accrual
uint256
The accrued interest of the borrow position.
healthFactorNumerator
uint256
The numerator of the health factor.
healthFactorDenominator
uint256
The denominator of the health factor.
getDepositedAmount (0x0fefc251)
Returns the amount of project tokens deposited by a user for a specific project token and collateral token.
Parameters:
projectToken
address
The address of the project token.
user
address
The address of the user.
Return values:
[0]
uint256
amount of project tokens deposited by the user.
getRelatedContract (0x2060128e)
Returns whether an address is a related contract or not.
Parameters:
relatedContract
address
The address of the contract to check.
Return values:
[0]
bool
isRelated Boolean indicating whether the contract is related or not.
getTotalBorrowPerCollateral (0x65647a59)
Gets total borrow amount in USD per collateral for a specific project token.
Parameters:
projectToken
address
The address of the project token.
Return values:
[0]
uint256
The total borrow amount in USD.
getTotalBorrowPerLendingToken (0x961540e1)
Gets total borrow amount in USD for a specific lending token.
Parameters:
lendingToken
address
The address of the lending token.
Return values:
amountInUSD
uint256
The total borrow amount in USD.
totalOutstandingInUSD (0xb189b70a)
Converts the total outstanding amount of a user's borrow position to USD.
Parameters:
account
address
The address of the user account.
projectToken
address
The address of the project token.
lendingToken
address
The address of the lending token.
Return values:
amountInUSD
uint256
The total outstanding amount in USD.
getLoanToValueRatio (0xe84dc1b3)
Gets the loan to value ratio of a position made by a project token and a lending token.
Parameters:
projectToken
address
The address of the project token.
lendingToken
address
The address of the lending token.
Return values:
lvrNumerator
uint256
The numerator of the loan to value ratio.
lvrDenominator
uint256
The denominator of the loan to value ratio.
Last updated