Comment on page
Developer docs
[Legacy] TrueFi DAO pools contracts
Below is a brief guide to TrueFi lending pool contracts.
Contract Name | Address |
---|---|
tfUSDC | |
tfUSDT | |
tfTUSD | |
tfBUSD |
- TrueFiPool2: lenders provide and withdraw liquidity to the pool, and can get lending pool details, such as pool value, pool token price, etc. from this contract
- TrueLender2: implements the lending strategy for the TrueFi pool, i.e. how loans are approved and funded
The
TrueFiPool2
contract is used by TrueFi DAO lending pools -- tfUSDC / tfUSDT / tfBUSD / tfTUSD. This contract enables accounts to pool tokens with the goal of earning yields on underlying tokens. Contract Name | Address |
---|---|
TrueFiPool2 |
Method | Notes |
---|---|
Lends a certain amount of underlying tokens to the portfolio, and mints and transfers corresponding amount of ERC-20 lending pool ("LP") tokens to the lender. | |
Withdraws liquidity from the lending pool. Lender transfers pool tokens to pool and receives underlying token, but with a small penalty for liquidity as calculated by liquidExitPenalty() described below. |
To calculate the price of the lending pool token ("LP token"), take
poolValue()
divided by totalSupply()
.To calculate yield for a pool, one must calculate the weighted average of rates across each active loan in the pool and idle funds held in the pool.
pool_apy = SUM(loan_1_amount
*loan_1_apy + ... + loan_n_amount*loan_n_value) / poolValue()
Method | Notes |
---|---|
Returns pool value in underlying token. This is the virtual price of the entire pool, including values for loan tokens and liquid underlying tokens held by the pool. Note: this assumes defaulted loans are worth their full value. | |
Returns virtual value of liquid assets in the pool. | |
totalSupply() | Returns total number of pool LP tokens. |
liquidRatio() | Ratio of liquid assets in the pool to the pool value, in basis points. For example, 4683 => 46.83%. |
utilization() | Returns utilization in basis points. For example, 5316 => 53.16%. Calculated as 1 - liquidRatio() . |
Calculates lender will pay to withdraw liquid funds from the pool. This returns a proportion to be applied if liquidExit() is performed with the given amount of LP tokens. For example, when a pool is at ~75% utilization a small withdrawal would return liquidExitPenalty = ~0.9980, meaning that the lender would pay an exit penalty of ~0.20% (20 bps) to withdraw from the pool. | |
averageExitPenalty(uint256 from, uint256 to) | Internal function for calculating exit penalty. |
Method | Notes |
---|---|
Calls SAFU function to liquidate bad debt. Liquidates a defaulted Loan, withdraws a portion of TRU from staking pool then tries to cover the loan with own funds, to compensate lending pool. Loan must be in defaulted state. If SAFU does not have enough funds, deficit is saved to be redeemed later. | |
reclaimDeficit(ILoanToken2 loan, uint256 amount) | After a defaulted loan's debt has been redeemed by the SAFU, the lending pool can reclaim call this function to redeem "deficiency claim" tokens for underlying tokens held in the SAFU. |
Implements the lending strategy for the TrueFi pool, i.e. how loans are approved and funded.
Contract Name | Address |
---|---|
TrueLender2 |
Method | Notes |
---|---|
When called, sends funds from the pool to the loan token contract. Pool receives and holds loan tokens. Must be called by the loan borrower. | |
loanIsCredible(uint256 yesVotes, uint256 noVotes) | Checks whether loan receives sufficient votes via stkTRU rating to be funded. Checks whether loan receives minimum ratio of yes to no votes and hits threshold of minimum votes set by owner. |
reclaim(ILoanToken2 loanToken, bytes calldata data) | Redeems LoanTokens held by the pool for underlying funds held in the loan token. Loan token must be settled before calling this function. |
reclaimDeficit(ILoanToken2 loan, uint256 amount) | After a defaulted loan's debt has been redeemed by the SAFU, the lending pool can reclaim call this function to redeem "deficiency claim" tokens for underlying tokens held in the SAFU. |
Contract Name | Address |
---|---|
LoanFactory2 |
Each LoanToken has the following parameters:
borrower()
: address of borroweramount()
: principal amount of fixed term loanterm()
: loan term in secondsapy()
: loan APR in basis points (i.e. 971 = 9.71%)status()
: returns loan's status, which progresses through the following states:0
-->Awaiting:
Waiting for funding to meet capital requirements1
-->Funded:
Capital requirements met, borrower can withdraw2
-->Withdrawn:
Borrower withdraws money, loan waiting to be repaid3
-->Settled:
Loan has been paid back in full with interest4
-->Defaulted:
Loan has not been paid back in full5
-->Liquidated:
Loan has Defaulted and stakers have been Liquidated
canTransfer()
: returns LoanTokens are non-transferable except for whitelisted addressesdebt()
: returnsamount
+interest
. Note that this does not take into account whether the loan has been repaid.isRepaid()
: returns boolean value, indicating whether a loan has been repaid in full.profit()
: returns difference betweendebt()
andamount()
, the anticipated interest to be paid on the loan
Method | Notes |
---|---|
fund() | Transfers tokens to loan token contract from pool. Can be called only by lender contract. Sets status to Funded, start time, lender. |
withdraw(address _beneficiary) | Borrower calls this function to withdraw funds to address provided. This sets the status of the loan to Withdrawn . |
repayInFull(address _sender) | Function for borrower to repay all of the remaining loan balance. Borrower should use this to ensure full repayment. |
_repay(address _sender, uint256 _amount) | Internal function for loan repayment. If _amount is sufficient, then this also settles the loan. |
settle() | Moves loan to status = 'settled' if loan is fully repaid. |
reclaim() | Function for borrower to reclaim any underlying currency stuck in the loan token contract. Only the borrower can call this function after the loan has been settled, defaulted, or liquidated. |
Repaying loans to lending pools has two steps:
- 1.Borrower repays funds to loan token
- 2.
reclaim()
function is called on loan token, which burns the loan token and pays out fees to stkTRU.
As described here, the
TrueRatingAgencyV2
contract determines whether a loan request should be funded by TrueLender2
.Contract Name | Address |
---|---|
TrueRatingAgencyV2 |
stkTRU holders can vote
yes()
or no()
on each loan. The TrueLender2
contract then checks to see if each loan satisfies threshold conditions in order to be funded.stkTRU voters receive rewards in the form of TRU tokens for voting on loan requests.
claimable()
reward tokens are calculated as follows:claimable() = (# TRU voted by user / # total TRU votes) * (Total TRU Reward)
, whereTotal TRU Reward = (Loan interest * TRU distribution factor * rewardMultiplier)
- where
Loan interest = (loan APR * term in days * principal) /365
. Loan APR, term, and principal can be obtained from the respective loan token contract TRU distribution factor
is calculated asremaining
divided byamount
from the RatingAgencyV2Distributor contract
Contract Name | Address |
---|---|
TrueMultiFarm | |
LinearTrueDistributor |
- Total TRU emissions per day can be calculated using
totalAmount()
andduration()
found on the distributor contract:TRU distribution per day = (totalAmount/10^8) / (duration/(24*3600))
- To calculate farm rates for each token, use the formula below:
TRU rewards per farm per day = TRU distribution per day * getShare(IERC20 token) / shares()
as described below
Method | Notes |
---|---|
stake(IERC20 token, uint256 amount) | Stake tokens to the farm. Upon staking, this will claim any claimable rewards. |
unstake(IERC20 token, uint256 amount) | Remove staked tokens |
claim(IERC20[] calldata tokens) | Claim TRU rewards |
exit(IERC20[] calldata tokens) | Unstake amount and claim rewards |
claimable(IERC20 token, address account) | Returns the claimable TRU reward for an account that is staking tokens. |
shares() | Returns denominator for total farm rewards rate |
getShare(IERC20 token) | Returns numerator for LP token's share of farm rewards |
Last modified 3mo ago