Developer docs
[Legacy] TrueFi DAO pools contracts
Below is a brief guide to TrueFi lending pool contracts.
For detailed questions, please reach out to the Discord #dev channel.
Lending pool addresses
Contract Name | Address |
---|---|
tfUSDC | |
tfUSDT | |
tfTUSD | |
tfBUSD |
TrueFi DAO Pool contracts
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
LoanFactory2: deploys LoanTokens, which represent details of each loan on-chain
TrueRatingAgencyV2: loan applications are rated and approved by TRU stakers
TrueMultiFarm: lenders can stake lending pool tokens to earn TRU rewards (read more here)
SAFU: handles bad debt in TrueFi lending pools (read more here)
TrueFiPool2 contract
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 |
Lending & Withdrawing methods
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
|
Determining pool values
Calculating LP token price
To calculate the price of the lending pool token ("LP token"), take poolValue()
divided by totalSupply()
.
Calculating pool APY
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()
For an example of how this can be done via SQL, see this Dune query.
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. | |
| Returns total number of pool LP tokens. |
| Ratio of liquid assets in the pool to the pool value, in basis points. For example, 4683 => 46.83%. |
| Returns utilization in basis points. For example, 5316 => 53.16%. Calculated as |
Calculates lender will pay to withdraw liquid funds from the pool. This returns a proportion to be applied if For example, when a pool is at ~75% utilization a small withdrawal would return For more detail on liquid exit and how the penalty is calculated, see here. | |
| Internal function for calculating exit penalty. |
Default handling
Read more about default handling in SAFU default handling
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 | |
| 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. |
TrueLender2 contract
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. | |
| 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. |
| Redeems LoanTokens held by the pool for underlying funds held in the loan token. Loan token must be settled before calling this function. |
| 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. |
Loan Token contracts
Loan tokens are created by LoanFactory2.
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 |
---|---|
| Transfers tokens to loan token contract from pool. Can be called only by lender contract. Sets status to Funded, start time, lender. |
| Borrower calls this function to withdraw funds to address provided. This sets the status of the loan to |
| Function for borrower to repay all of the remaining loan balance. Borrower should use this to ensure full repayment. |
| Internal function for loan repayment. If |
| Moves loan to status = 'settled' if loan is fully repaid. |
| 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:
Borrower repays funds to loan token
reclaim()
function is called on loan token, which burns the loan token and pays out fees to stkTRU.
TrueRatingAgencyV2
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)
, where
Total 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 contractrewardMultiplier
can be found from the TrueRatingAgencyV2 contractTRU distribution factor
is calculated asremaining
divided byamount
from the RatingAgencyV2Distributor contract
TrueMultiFarm
As described here, lenders can stake LP tokens into the TrueMultiFarm contract to get TRU rewards.
Contract Name | Address |
---|---|
TrueMultiFarm | |
LinearTrueDistributor |
How to calculate lender emissions per day
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 tokens to the farm. Upon staking, this will claim any claimable rewards. |
| Remove staked tokens |
| Claim TRU rewards |
| Unstake amount and claim rewards |
| Returns the claimable TRU reward for an account that is staking tokens. |
| Returns denominator for total farm rewards rate |
| Returns numerator for LP token's share of farm rewards |
Last updated