Fees Manager
One place to get the current rate of any pool based on its rate settings.
One place to get the current rate of any pool based on its rate settings.
One thing that is not immediately obvious is how the initial rates are passed into the contract. This is done in the setPoolRates
method which accepts bytes32
. Only two contracts can set the rates, PoolFactory
on construction of the pool and the lending pool itself. To reduce the amount of variables passed to the factory on pool deployment we wrap them all into bytes32
. Also if we ever need to pass additional variables to FeeManager
we will not need to update the PoolFactory
. Read more on this encoding here.
All fee rates on Vendor are stored as uint48
with 4 decimals of precision. That meaning that 1% is stored as 1_0000 and 100% as 100_0000.
Term Rate - aka effective rate is the rate that the borrower would be charged at the time of borrow.
APR - is the annualized term rate. Calculated by multiplying the term rate by the amount of such terms left in a year. Ex: if we have a pool with 1 month expiry and 1% term rate, then APR will be 12%.
Here is the TS code you could use in order to obtain the bytes for desired configuration:
There are different types of fee rate behaviors that the lenders can choose from. We might add more in the future, but here are the once that are currently supported:
With fixed rate lender chooses one flat term rate for the whole term of the loan. No matter at what time during the life of the pool will borrower try to borrow, borrower will be charged that flat rate. We need to pass the fixed rate in the auction start rate
of the bytes32
variable.
Example:
Lender wants to set fixed rate of 5% for the whole term of the loan. In that case he would pass the following bytes:
0x010000000000000000000000000000000000000000000007A120000000000000
Here the 01
on the left stands for Fixed Rate and 7A12
in the position of auction start rate is the 50000 in hex.
With this type of fee lenders can have a full control over how the fee rate for that pool decays. Here are some of the behaviors that are achievable. You can see the way an effective rate will behave in order to achieve different APR behavior as the loan progresses over time.
1) Let's start with a simple example and then extend it as we go. First use case for this type is to use it as a constant APR (first row of plots). This way the effective rate that the borrower would be charged on borrow will decrease as the remainder of the loan decreases approaching expiry, ensuring that when annualized, annualized rate or APR stays constant. In order to ensure such effect you will need to set the parameters in the following way:
Here is an example byte32
that one would need to pass to make a pool with such rate behavior that starts on December 1st, expires on December 31st and holds the constant APR of 5%:
0x0200000000000000000000000000000000000000000000000007A12000000007A12
We will set both start and end rate to 5% or 500000 or 7A12
. You can then completely disregard any dates and just leave them blank no matter when the pool starts or expires.
2) A second example is the case where the pool will start with a constant APR for some time, will then start an auction. Lastly it will keep the final constant APR after the auction end. Row 2 of the plots.
Here is an example byte32
that one would need to pass to make a pool with such rate behavior that starts on December 1st, expires on December 31st. It will hold the 10% APR for 7 days till December 8th, and then will lover it linearly to 5% till December 21st. It will hold 5% APR till expiry or December 31st.
0x020000000000000000000006391375E000063A25ADE0000000186A0000000007A12
Here the 6391375E
represents the timestamp of the auction start in hex (December 8th). 63A25ADE
represents the timestamp of auction end date or December 21st in hex. 186A0
is the auction start rate of 10% APR or 100000. Finally 7A12
is the 5% end rate or 50000.
Those are just two examples of how this mode could be used, but you could create more different configurations for how the rate will behave.
Bytes | Name | Purpose |
---|---|---|
Type | Encoding in bytes32 |
---|---|
Parameter | Value |
---|---|
Parameter | Value |
---|---|
0-5
Auction End Rate
Rate at which the auction ends. Rate for any timestamp past the auction end rate will be equal to this value. Passed in hex.
6-11
Auction Start Rate
Rate at which the auction starts. Rate for any timestamp before the auction start rate will be equal to this value. Passed in hex.
12-17
Auction End Date
Time at which the auction decay rate will stop.
18-23
Auction Start Date
Time at which the auction decay rate will start.
24-30
Free Space
Can be used for passing more info if ever required.
31
Fee Type
Type of the fee rate behavior.
Fixed Rate
01
Linear Decay With Auction
02
Auction Start Date
Can be left blank.
Auction End Date
Can be left blank.
Auction Start Rate
APR user would like to use.
Auction End Rate
APR user would like to use. Same as start rate.
Auction Start Date
A date when lender would like the APR to start decaying.
Auction End Date
A date by which the APR decay should stop at the minimum allowed APR.
Auction Start Rate
The initial APR, will be maintained till the auction start.
Auction End Rate
The final APR, will be maintained after the auction end.