Controller

The Controller allows users to get the list of deployed PalPools & PalTokens, and also to check if a Withdraw or a Borrow is possible on a given Pool without asking the Pool directly, and hooks called by some PalPool’s method to verify that an action (Deposit, Withdraw, Borrow, …) executed correctly.

The Controller is composed of 2 smart contracts, working in a Proxy & Implementation system. The Implementation can be changed to upgrade the Controller, and add more functions to it.

Users can also stake their PalTokens in the PaladinController, to take part in the Liquidity Mining program. Rewards distribution is different for the Supply side and the Borrow side :

  • For the Supply side, each PalPool gets a supplySpeed, representing the number of PAL distributed to stakers each block (for PalPool with no rewards, the supplySpeed is set as 0).

  • For the Borrow side, PalPools get a borrowRatio, use to reward borrowers depending on how much fees were used by their PalLoans (for PalPool with no rewards, the borrowRatio is set as 0). For example, on a PalPool with a borrowRatio of 0.75, a PalLoan that paid 70 TOKEN of fees, but only used 50 TOKEN of those fees at closing, will receive a reward of 37.5 PAL.

All Supply Rewards are accrued to a claimable balance for the user, allowing to claim it all at any point.

For the Borrow Rewards, some are directly accrued to the same claimable balance than the Supply Rewards, but for some PalPools (all the Pools having autoBorrowRewards set as false), users will have to manually claim rewards for each of their PalLoan.

Methods :

Events :

NewPalPool

event NewPalPool(address palPool);

When a new Pool is added to the Controller List

RemovePalPool

event RemovePalPool(address palPool, address palToken);

When a new Pool is removed to the Controller List

Deposit

event Deposit(address indexed user, address palToken, uint amount);

When an user deposits PalTokens in the Controller for Supply Rewards

Withdraw

event Withdraw(address indexed user, address palToken, uint amount);

When an user withdraws PalTokens from the Controller

ClaimRewards

event ClaimRewards(address indexed user, uint amount);

When an user claimed its reward tokens

PoolRewardsUpdated

event PoolRewardsUpdated(address palPool, uint newSupplySpeed, uint newBorrowRatio, bool autoBorrowReward);

When a PalPool Rewards parameters (Speed, Ratio or both) were updated by the admin

NewPendingImplementation

event NewPendingImplementation(address oldPendingImplementation, address newPendingImplementation);

When a new Implementation was proposed to the Proxy

NewImplementation

event NewImplementation(address oldImplementation, address newImplementation);

When the pending Implementation was accepted for the Proxy

Useful methods :

isPalPool

function isPalPool(address _pool) external view returns(bool);

Returns 'true' if the given address is a PalPool listed in the Controller

getPalTokens

function getPalTokens() external view returns(address[] memory);

Returns the list of PalTokens stored by the Controller

getPalPools

function getPalPools() external view returns(address[] memory);

Returns the list of PalPools stored by the Controller

palTokenToPalPool

function palTokenToPalPool(address palToken) external view returns(address);

Returns the PalPool associated to the given PalToken

rewardTokenAddress

function rewardTokenAddress() external view returns(address);

Returns the reward Token (PAL token)

supplyRewardState

function supplyRewardState(address palPool) external view returns(supplyRewardState);

Returns the current SupplyRewardState for a given PalPool

SupplyRewardState struct :

name

type

desc

index

uint224

Current rewards index, from last update

blockNumber

uint32

Last block this state was updated

supplySpeeds

function supplySpeeds(address palPool) external view returns(uint);

Returns the Supply Speed for a given PalPool

supplierDeposits

function supplierDeposits(address palPool, address user) external view returns(uint);

Returns the amount of palToken deposited for a given PalPool by a given user

totalSupplierDeposits

function totalSupplierDeposits(address palPool) external view returns(uint);

Returns the total amount of PalTokens deposited fir the given PalPool

borrowRatios

function borrowRatios(address palPool) external view returns(uint);

Returns the Borrow Ratio for the given PalPool

autoBorrowRewards

function autoBorrowRewards(address palPool) external view returns(bool);

Returns 'true' if the PalPool is auto-accruing Borrow Rewards to the user claimable amount. If 'false', users need to claim Borrow Rewards manually

isLoanRewardClaimed

function isLoanRewardClaimed(address palLoan) external view returns(bool);

Returns 'true' if the PalLoan rewards were already claimed or distributed

withdrawPossible

function withdrawPossible(address palPool, uint amount) external view returns(bool);

Check if a withdraw is possible on a given PalPool

Parameters :

name

type

desc

palPool

address

the Pool to withdraw from

amount

uint

the amount to withdraw

borrowPossible

function borrowPossible(address palPool, uint amount) external view returns(bool);

Check if a borrow is possible on a given PalPool

Parameters :

name

type

desc

palPool

address

the Pool to borrow from

amount

uint

the amount to withdraw

deposit

function deposit(address palToken, uint amount) external returns(bool);

Deposit PalTokens in the Controller to receive Supply Rewards

Parameters :

name

type

desc

palToken

address

Address of the PalToken

amount

uint

amount of PalToken to deposit

withdraw

function withdraw(address palToken, uint amount) external returns(bool);

Withdraw PalTokens staked in the Controller

Parameters :

name

type

desc

palToken

address

Address of the PalToken

amount

uint

amount of PalTokens to withdraw

claimable

function claimable(address user) external view returns(uint);

Return the amount of reward tokens accrued from last user state update

estimateClaimable

function estimateClaimable(address user) external view returns(uint);

Return the amount of reward tokens accrued from last user state update + an estimation of rewards to be accrued from last PalPools States updates (that are not accrued into the user claimable amount without an update of the user state)

claim

function claim(address user) external;

Update the user Reward State and claim all accrued rewards

updateUserRewards

function updateUserRewards(address user) external;

Updates the user Reward States for all PalPools the user is staking PalTokens.

claimableLoanRewards

function claimableLoanRewards(address palPool, address loanAddress) external view returns(uint);

Return the amount of reward tokens the user could claim for their PalLoan.

Return 0 if :

  • PalLoan is not Closed/Killed yet

  • PalPool has the auto-accruing rewards system (no need to manually claim, rewards are already distributed)

  • Rewards were already claimed for that PalLoan

Parameters :

name

type

desc

palPool

address

address fo the PalPool that issued the PalLoan

loanAddress

address

address of the PalLoan to claim rewards for

claimLoanRewards

function claimLoanRewards(address palPool, address loanAddress) external;

Claim the potential rewards for a PalLoan

Fails if :

  • PalLoan is not Closed/Killed yet

  • PalPool has the auto-accruing rewards system (no need to manually claim, rewards are already distributed)

  • Rewards were already claimed for that PalLoan

Parameters :

name

type

desc

palPool

address

address fo the PalPool that issued the PalLoan

loanAddress

address

address of the PalLoan to claim rewards for

Last updated