PoolCore

Main point of interaction with an ParaSpace protocol's market

  • Users can:

    • Supply

    • Withdraw

    • Borrow

    • Repay

    • Liquidate positions

To be covered by a proxy contract, owned by the PoolAddressesProvider of the specific market All admin functions are callable by the PoolConfigurator contract defined also in the PoolAddressesProvider

POOL_REVISION

uint256 POOL_REVISION

ADDRESSES_PROVIDER

contract IPoolAddressesProvider ADDRESSES_PROVIDER

Returns the PoolAddressesProvider connected to this contract

Return Values

getRevision

function getRevision() internal pure virtual returns (uint256)

Returns the revision number of the contract

Needs to be defined in the inherited class as a constant.

Return Values

Name
Type
Description

[0]

uint256

The revision number

constructor

constructor(contract IPoolAddressesProvider provider) public

Constructor.

Parameters

Name
Type
Description

provider

contract IPoolAddressesProvider

The address of the PoolAddressesProvider contract

initialize

function initialize(contract IPoolAddressesProvider provider) external virtual

Initializes the Pool.

Function is invoked by the proxy contract when the Pool contract is added to the PoolAddressesProvider of the market. Caching the address of the PoolAddressesProvider in order to reduce gas consumption on subsequent operations

Parameters

Name
Type
Description

provider

contract IPoolAddressesProvider

The address of the PoolAddressesProvider

supply

function supply(address asset, uint256 amount, address onBehalfOf, uint16 referralCode) external virtual

Supplies an amount of underlying asset into the reserve, receiving in return overlying xTokens.

  • E.g. User supplies 100 USDC and gets in return 100 pUSDC

Parameters

Name
Type
Description

asset

address

The address of the underlying asset to supply

amount

uint256

The amount to be supplied

onBehalfOf

address

The address that will receive the xTokens, same as msg.sender if the user wants to receive them on his own wallet, or a different address if the beneficiary of xTokens is a different wallet

referralCode

uint16

Code used to register the integrator originating the operation, for potential rewards. 0 if the action is executed directly by the user, without any middle-man

supplyERC721

function supplyERC721(address asset, struct DataTypes.ERC721SupplyParams[] tokenData, address onBehalfOf, uint16 referralCode) external virtual

Supplies multiple tokenIds of underlying ERC721 asset into the reserve, receiving in return overlying nTokens.

  • E.g. User supplies 2 BAYC and gets in return 2 nBAYC

Parameters

Name
Type
Description

asset

address

The address of the underlying asset to supply

tokenData

struct DataTypes.ERC721SupplyParams[]

The list of tokenIds and their collateral configs to be supplied

onBehalfOf

address

The address that will receive the xTokens, same as msg.sender if the user wants to receive them on his own wallet, or a different address if the beneficiary of xTokens is a different wallet

referralCode

uint16

Code used to register the integrator originating the operation, for potential rewards. 0 if the action is executed directly by the user, without any middle-man

supplyERC721FromNToken

function supplyERC721FromNToken(address asset, struct DataTypes.ERC721SupplyParams[] tokenData, address onBehalfOf) external virtual

Same as supplyERC721 but this can only be called by NToken contract and doesn't require sending the underlying asset.

Parameters

Name
Type
Description

asset

address

The address of the underlying asset to supply

tokenData

struct DataTypes.ERC721SupplyParams[]

The list of tokenIds and their collateral configs to be supplied

onBehalfOf

address

The address that will receive the xTokens

supplyWithPermit

function supplyWithPermit(address asset, uint256 amount, address onBehalfOf, uint16 referralCode, uint256 deadline, uint8 permitV, bytes32 permitR, bytes32 permitS) external virtual

Supply with transfer approval of asset to be supplied done via permit function see: https://eips.ethereum.org/EIPS/eip-2612 and https://eips.ethereum.org/EIPS/eip-713

Parameters

Name
Type
Description

asset

address

The address of the underlying asset to supply

amount

uint256

The amount to be supplied

onBehalfOf

address

The address that will receive the xTokens, same as msg.sender if the user wants to receive them on his own wallet, or a different address if the beneficiary of xTokens is a different wallet

referralCode

uint16

Code used to register the integrator originating the operation, for potential rewards. 0 if the action is executed directly by the user, without any middle-man

deadline

uint256

The deadline timestamp that the permit is valid

permitV

uint8

The V parameter of ERC712 permit sig

permitR

bytes32

The R parameter of ERC712 permit sig

permitS

bytes32

The S parameter of ERC712 permit sig

withdraw

function withdraw(address asset, uint256 amount, address to) external virtual returns (uint256)

Withdraws an amount of underlying asset from the reserve, burning the equivalent xTokens owned E.g. User has 100 pUSDC, calls withdraw() and receives 100 USDC, burning the 100 pUSDC

Parameters

Name
Type
Description

asset

address

The address of the underlying asset to withdraw

amount

uint256

The underlying amount to be withdrawn - Send the value type(uint256).max in order to withdraw the whole xToken balance

to

address

The address that will receive the underlying, same as msg.sender if the user wants to receive it on his own wallet, or a different address if the beneficiary is a different wallet

Return Values

Name
Type
Description

[0]

uint256

The final amount withdrawn

withdrawERC721

function withdrawERC721(address asset, uint256[] tokenIds, address to) external virtual returns (uint256)

Withdraws multiple tokenIds of underlying ERC721 asset from the reserve, burning the equivalent nTokens owned E.g. User has 2 nBAYC, calls withdraw() and receives 2 BAYC, burning the 2 nBAYC

Parameters

Name
Type
Description

asset

address

The address of the underlying asset to withdraw

tokenIds

uint256[]

The underlying tokenIds to be withdrawn - Send the value type(uint256).max in order to withdraw the whole xToken balance

to

address

The address that will receive the underlying, same as msg.sender if the user wants to receive it on his own wallet, or a different address if the beneficiary is a different wallet

Return Values

Name
Type
Description

[0]

uint256

The final amount withdrawn

decreaseUniswapV3Liquidity

function decreaseUniswapV3Liquidity(address asset, uint256 tokenId, uint128 liquidityDecrease, uint256 amount0Min, uint256 amount1Min, bool receiveEthAsWeth) external virtual

Decreases liquidity for underlying Uniswap V3 NFT LP and validates that the user respects liquidation checks.

Parameters

Name
Type
Description

asset

address

The asset address of uniswapV3

tokenId

uint256

The id of the erc721 token

liquidityDecrease

uint128

The amount of liquidity to remove of LP

amount0Min

uint256

The minimum amount to remove of token0

amount1Min

uint256

The minimum amount to remove of token1

receiveEthAsWeth

bool

If convert weth to ETH

borrow

function borrow(address asset, uint256 amount, uint16 referralCode, address onBehalfOf) external virtual

Allows users to borrow a specific amount of the reserve underlying asset, provided that the borrower already supplied enough collateral, or he was given enough allowance by a credit delegator on the corresponding debt token (VariableDebtToken)

  • E.g. User borrows 100 USDC passing as onBehalfOf his own address, receiving the 100 USDC in his wallet and 100 stable/variable debt tokens

Parameters

Name
Type
Description

asset

address

The address of the underlying asset to borrow

amount

uint256

The amount to be borrowed

referralCode

uint16

The code used to register the integrator originating the operation, for potential rewards. 0 if the action is executed directly by the user, without any middle-man

onBehalfOf

address

The address of the user who will receive the debt. Should be the address of the borrower itself calling the function if he wants to borrow against his own collateral, or the address of the credit delegator if he has been given credit delegation allowance

repay

function repay(address asset, uint256 amount, address onBehalfOf) external virtual returns (uint256)

Repays a borrowed amount on a specific reserve, burning the equivalent debt tokens owned

  • E.g. User repays 100 USDC, burning 100 variable/stable debt tokens of the onBehalfOf address

Parameters

Name
Type
Description

asset

address

The address of the borrowed underlying asset previously borrowed

amount

uint256

The amount to repay - Send the value type(uint256).max in order to repay the whole debt for asset on the specific debtMode

onBehalfOf

address

The address of the user who will get his debt reduced/removed. Should be the address of the user calling the function if he wants to reduce/remove his own debt, or the address of any other other borrower whose debt should be removed

Return Values

Name
Type
Description

[0]

uint256

The final amount repaid

repayWithPTokens

function repayWithPTokens(address asset, uint256 amount) external virtual returns (uint256)

Repays a borrowed amount on a specific reserve using the reserve xTokens, burning the equivalent debt tokens

  • E.g. User repays 100 USDC using 100 pUSDC, burning 100 variable/stable debt tokens

Passing uint256.max as amount will clean up any residual xToken dust balance, if the user xToken balance is not enough to cover the whole debt

Parameters

Name
Type
Description

asset

address

The address of the borrowed underlying asset previously borrowed

amount

uint256

The amount to repay - Send the value type(uint256).max in order to repay the whole debt for asset on the specific debtMode

Return Values

Name
Type
Description

[0]

uint256

The final amount repaid

repayWithPermit

function repayWithPermit(address asset, uint256 amount, address onBehalfOf, uint256 deadline, uint8 permitV, bytes32 permitR, bytes32 permitS) external virtual returns (uint256)

Repay with transfer approval of asset to be repaid done via permit function see: https://eips.ethereum.org/EIPS/eip-2612 and https://eips.ethereum.org/EIPS/eip-713

Parameters

Name
Type
Description

asset

address

The address of the borrowed underlying asset previously borrowed

amount

uint256

The amount to repay - Send the value type(uint256).max in order to repay the whole debt for asset on the specific debtMode

onBehalfOf

address

Address of the user who will get his debt reduced/removed. Should be the address of the user calling the function if he wants to reduce/remove his own debt, or the address of any other other borrower whose debt should be removed

deadline

uint256

The deadline timestamp that the permit is valid

permitV

uint8

The V parameter of ERC712 permit sig

permitR

bytes32

The R parameter of ERC712 permit sig

permitS

bytes32

The S parameter of ERC712 permit sig

Return Values

Name
Type
Description

[0]

uint256

The final amount repaid

setUserUseERC20AsCollateral

function setUserUseERC20AsCollateral(address asset, bool useAsCollateral) external virtual

Allows suppliers to enable/disable a specific supplied asset as collateral

Parameters

Name
Type
Description

asset

address

The address of the underlying asset supplied

useAsCollateral

bool

True if the user wants to use the supply as collateral, false otherwise

setUserUseERC721AsCollateral

function setUserUseERC721AsCollateral(address asset, uint256[] tokenIds, bool useAsCollateral) external virtual

Allows suppliers to enable/disable a specific supplied ERC721 asset with a tokenID as collateral

Parameters

Name
Type
Description

asset

address

The address of the underlying asset supplied

tokenIds

uint256[]

the ids of the supplied ERC721 token

useAsCollateral

bool

True if the user wants to use the supply as collateral, false otherwise

liquidateERC20

function liquidateERC20(address collateralAsset, address liquidationAsset, address borrower, uint256 liquidationAmount, bool receivePToken) external payable virtual

Function to liquidate a non-healthy position collateral-wise, with Health Factor below 1

  • The caller (liquidator) covers liquidationAmount amount of debt of the user getting liquidated, and receives a proportionally amount of the collateralAsset plus a bonus to cover market risk

Parameters

Name
Type
Description

collateralAsset

address

The address of the underlying asset used as collateral, to receive as result of the liquidation

liquidationAsset

address

The address of the underlying borrowed asset to be repaid with the liquidation

borrower

address

liquidationAmount

uint256

The debt amount of borrowed asset the liquidator wants to cover

receivePToken

bool

True if the liquidators wants to receive the collateral xTokens, false if he wants to receive the underlying collateral asset directly

liquidateERC721

function liquidateERC721(address collateralAsset, address borrower, uint256 collateralTokenId, uint256 maxLiquidationAmount, bool receiveNToken) external payable virtual

startAuction

function startAuction(address user, address collateralAsset, uint256 collateralTokenId) external

Start the auction on user's specific NFT collateral

Parameters

Name
Type
Description

user

address

The address of the user

collateralAsset

address

The address of the NFT collateral

collateralTokenId

uint256

The tokenId of the NFT collateral

endAuction

function endAuction(address user, address collateralAsset, uint256 collateralTokenId) external

End specific user's auction

Parameters

Name
Type
Description

user

address

The address of the user

collateralAsset

address

The address of the NFT collateral

collateralTokenId

uint256

The tokenId of the NFT collateral

flashClaim

function flashClaim(address receiverAddress, address nftAsset, uint256[] nftTokenIds, bytes params) external virtual

_Allows smart contracts to access the tokens within one transaction, as long as the tokens taken is returned.

Requirements:

  • nftTokenIds must exist._

Parameters

Name
Type
Description

receiverAddress

address

The address of the contract receiving the tokens, implementing the IFlashClaimReceiver interface

nftAsset

address

address of the underlying asset of NFT

nftTokenIds

uint256[]

token ids of the underlying asset

params

bytes

Variadic packed params to pass to the receiver as extra information

getReserveData

function getReserveData(address asset) external view virtual returns (struct DataTypes.ReserveData)

Returns the state and configuration of the reserve

Parameters

Name
Type
Description

asset

address

The address of the underlying asset of the reserve

Return Values

Name
Type
Description

[0]

struct DataTypes.ReserveData

The state and configuration data of the reserve

getConfiguration

function getConfiguration(address asset) external view virtual returns (struct DataTypes.ReserveConfigurationMap)

Returns the configuration of the reserve

Parameters

Name
Type
Description

asset

address

The address of the underlying asset of the reserve

Return Values

Name
Type
Description

[0]

struct DataTypes.ReserveConfigurationMap

The configuration of the reserve

getUserConfiguration

function getUserConfiguration(address user) external view virtual returns (struct DataTypes.UserConfigurationMap)

Returns the configuration of the user across all the reserves

Parameters

Name
Type
Description

user

address

The user address

Return Values

Name
Type
Description

[0]

struct DataTypes.UserConfigurationMap

The configuration of the user

getReserveNormalizedIncome

function getReserveNormalizedIncome(address asset) external view virtual returns (uint256)

Returns the normalized income normalized income of the reserve

Parameters

Name
Type
Description

asset

address

The address of the underlying asset of the reserve

Return Values

Name
Type
Description

[0]

uint256

The reserve's normalized income

getReserveNormalizedVariableDebt

function getReserveNormalizedVariableDebt(address asset) external view virtual returns (uint256)

Returns the normalized variable debt per unit of asset

Parameters

Name
Type
Description

asset

address

The address of the underlying asset of the reserve

Return Values

Name
Type
Description

[0]

uint256

The reserve normalized variable debt

getReservesList

function getReservesList() external view virtual returns (address[])

Returns the list of the underlying assets of all the initialized reserves

It does not include dropped reserves

Return Values

Name
Type
Description

[0]

address[]

The addresses of the underlying assets of the initialized reserves

getReserveAddressById

function getReserveAddressById(uint16 id) external view returns (address)

Returns the address of the underlying asset of a reserve by the reserve id as stored in the DataTypes.ReserveData struct

Parameters

Name
Type
Description

id

uint16

The id of the reserve as stored in the DataTypes.ReserveData struct

Return Values

Name
Type
Description

[0]

address

The address of the reserve associated with id

MAX_NUMBER_RESERVES

function MAX_NUMBER_RESERVES() external view virtual returns (uint16)

Returns the maximum number of reserves supported to be listed in this Pool

Return Values

Name
Type
Description

[0]

uint16

The maximum number of reserves supported

AUCTION_RECOVERY_HEALTH_FACTOR

function AUCTION_RECOVERY_HEALTH_FACTOR() external view virtual returns (uint64)

Returns the auction recovery health factor

Return Values

Name
Type
Description

[0]

uint64

The auction recovery health factor

finalizeTransfer

function finalizeTransfer(address asset, address from, address to, bool usedAsCollateral, uint256 amount, uint256 balanceFromBefore, uint256 balanceToBefore) external virtual

Validates and finalizes an PToken transfer

Only callable by the overlying xToken of the asset

Parameters

Name
Type
Description

asset

address

The address of the underlying asset of the xToken

from

address

The user from which the xTokens are transferred

to

address

The user receiving the xTokens

usedAsCollateral

bool

amount

uint256

The amount being transferred/withdrawn

balanceFromBefore

uint256

The xToken balance of the from user before the transfer

balanceToBefore

uint256

The xToken balance of the to user before the transfer

finalizeTransferERC721

function finalizeTransferERC721(address asset, uint256 tokenId, address from, address to, bool usedAsCollateral, uint256 balanceFromBefore, uint256 balanceToBefore) external virtual

Validates and finalizes an NToken transfer

Only callable by the overlying xToken of the asset

Parameters

Name
Type
Description

asset

address

The address of the underlying asset of the xToken

tokenId

uint256

The tokenId of the ERC721 asset

from

address

The user from which the xTokens are transferred

to

address

The user receiving the xTokens

usedAsCollateral

bool

balanceFromBefore

uint256

The xToken balance of the from user before the transfer

balanceToBefore

uint256

The xToken balance of the to user before the transfer

getAuctionData

function getAuctionData(address ntokenAsset, uint256 tokenId) external view virtual returns (struct DataTypes.AuctionData auctionData)

Returns the auction related data of specific asset collection and token id.

Parameters

Name
Type
Description

ntokenAsset

address

The address of ntoken

tokenId

uint256

The token id which is currently auctioned for liquidation

Return Values

Name
Type
Description

auctionData

struct DataTypes.AuctionData

The auction related data of the corresponding (ntokenAsset, tokenId)

onERC721Received

function onERC721Received(address, address, uint256, bytes) external virtual returns (bytes4)

receive

receive() external payable