forked from alpaca-finance/bsc-alpaca-contract
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTripleSlopeModel.test.ts
65 lines (54 loc) · 2.99 KB
/
TripleSlopeModel.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import { ethers, upgrades, waffle } from "hardhat";
import { Signer, BigNumberish, utils, Wallet } from "ethers";
import chai, { expect } from "chai";
import { solidity } from "ethereum-waffle";
import "@openzeppelin/test-helpers";
import {
TripleSlopeModel,
TripleSlopeModel__factory
} from '../typechain'
import * as TestHelpers from "./helpers/assert";
describe("TripleSlopeModel", () => {
let tripleSlopeModel: TripleSlopeModel
let deployer: Signer;
beforeEach(async () => {
[deployer] = await ethers.getSigners();
const TripleSlopeModel = (await ethers.getContractFactory('TripleSlopeModel', deployer)) as TripleSlopeModel__factory
tripleSlopeModel = await TripleSlopeModel.deploy()
});
it('should returns ~12% APR when utilization 30%', async () => {
const interestPerSec = await tripleSlopeModel.getInterestRate('30','70')
const interestPerYear = interestPerSec.mul(60).mul(60).mul(24).mul(365)
TestHelpers.assertAlmostEqual(interestPerYear.toString(), ethers.utils.parseEther('0.12').toString())
});
it('should returns ~20% APR when utilization 50%', async () => {
const interestPerSec = await tripleSlopeModel.getInterestRate('50','50')
const interestPerYear = interestPerSec.mul(60).mul(60).mul(24).mul(365)
TestHelpers.assertAlmostEqual(interestPerYear.toString(), ethers.utils.parseEther('0.20').toString())
});
it('should returns ~20% APR when utilization 89%', async () => {
const interestPerSec = await tripleSlopeModel.getInterestRate('89','11')
const interestPerYear = interestPerSec.mul(60).mul(60).mul(24).mul(365)
TestHelpers.assertAlmostEqual(interestPerYear.toString(), ethers.utils.parseEther('0.20').toString())
});
it('should returns ~85% APR when utilization 95%', async () => {
const interestPerSec = await tripleSlopeModel.getInterestRate('95','5')
const interestPerYear = interestPerSec.mul(60).mul(60).mul(24).mul(365)
TestHelpers.assertAlmostEqual(interestPerYear.toString(), ethers.utils.parseEther('0.85').toString())
});
it('should returns ~117.5% APR when utilization 97.5%', async () => {
const interestPerSec = await tripleSlopeModel.getInterestRate('975','25')
const interestPerYear = interestPerSec.mul(60).mul(60).mul(24).mul(365)
TestHelpers.assertAlmostEqual(interestPerYear.toString(), ethers.utils.parseEther('1.175').toString())
});
it('should returns ~137% APR when utilization 99%', async () => {
const interestPerSec = await tripleSlopeModel.getInterestRate('99','1')
const interestPerYear = interestPerSec.mul(60).mul(60).mul(24).mul(365)
TestHelpers.assertAlmostEqual(interestPerYear.toString(), ethers.utils.parseEther('1.37').toString())
});
it('should returns ~150% APR when utilization 100%', async () => {
const interestPerSec = await tripleSlopeModel.getInterestRate('100','0')
const interestPerYear = interestPerSec.mul(60).mul(60).mul(24).mul(365)
TestHelpers.assertAlmostEqual(interestPerYear.toString(), ethers.utils.parseEther('1.5').toString())
});
});