Published
Edited
Apr 22, 2022
Fork of ETHRISE
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
getBorrowRate = function getBorrowRate(utilizationRate, interestRateSlope1, interestRateSlope2, utilizationRateOptimal) {
// Get interest rate
let interestRate = 0;
if(utilizationRate <= utilizationRateOptimal) {
interestRate = (utilizationRate/utilizationRateOptimal)*interestRateSlope1;
} else {
// TODO: when implement in solidity handle utilizationRate should not greater or equal to 1
interestRate = interestRateSlope1 + (((utilizationRate-utilizationRateOptimal)/(1-utilizationRate))*interestRateSlope2)
}

return interestRate;
}
Insert cell
getBorrowAPY = function getBorrowAPY(utilizationRate, interestRateSlope1, interestRateSlope2, utilizationRateOptimal) {
// Calculate APY
// APY= (1 + r/n )^n – 1
let daysPerYear = 365;
let secondsPerDay = 86400;
let secondsPerYear = secondsPerDay * daysPerYear;
let interestRate = getBorrowRate(utilizationRate, interestRateSlope1, interestRateSlope2, utilizationRateOptimal);
let interestRatePerSeconds = interestRate / secondsPerYear;
let APY = (Math.pow((interestRatePerSeconds*secondsPerDay) + 1,daysPerYear) - 1) * 100;
return APY
}
Insert cell
getBorrowAPR = function getBorrowAPR(utilizationRate, interestRateSlope1, interestRateSlope2, utilizationRateOptimal) {
// Calculate APR
// APR = ((Interest + Fees / Loan amount) / Number of days in loan term)) x 365 x 100
let loanAmount = 100;
let interestRate = getBorrowRate(utilizationRate, interestRateSlope1, interestRateSlope2, utilizationRateOptimal);
let interest = (loanAmount * interestRate);
let APR = ((interest/loanAmount)/365)*365*100;
return APR
}
Insert cell
getSupplyRate = function getSupplyRate(utilizationRate, interestRateSlope1, interestRateSlope2, utilizationRateOptimal) {
// Calculate APY
// Supply APY = Ut*It*(1-r)
let reserveFactor = 0.01;
let interestRate = getBorrowRate(utilizationRate, interestRateSlope1, interestRateSlope2, utilizationRateOptimal);
let supplyRate = utilizationRate * interestRate * (1-reserveFactor);
return supplyRate
}
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more