impermax-sdk 2.1.259 → 2.1.261
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/onchain/impermaxFactory/lendingPool/onchainBorrowable.d.ts +1 -22
- package/lib/onchain/impermaxFactory/lendingPool/onchainBorrowable.js +0 -68
- package/lib/onchain/impermaxFactory/lendingPool/onchainLendingPool.d.ts +0 -1
- package/lib/onchain/impermaxFactory/lendingPool/onchainLendingPool.js +0 -4
- package/lib/utils/borrowable/index.d.ts +39 -0
- package/lib/utils/borrowable/index.js +86 -0
- package/package.json +1 -1
|
@@ -6,13 +6,7 @@ import OffchainBorrowable from '../../../offchain/lendingPool/offchainBorrowable
|
|
|
6
6
|
export default abstract class OnchainBorrowable extends OnchainPoolToken {
|
|
7
7
|
protected readonly lendingPool: OnchainLendingPool;
|
|
8
8
|
protected readonly borrowable: Borrowable;
|
|
9
|
-
protected borrowableCache: {
|
|
10
|
-
borrowTracker?: Promise<Address>;
|
|
11
|
-
rewarder?: Promise<Contract>;
|
|
12
|
-
rewarderTokenSymbol?: Promise<string>;
|
|
13
|
-
farmingTokenSymbol?: Promise<string>;
|
|
14
|
-
rewardSpeed?: Promise<number>;
|
|
15
|
-
};
|
|
9
|
+
protected borrowableCache: {};
|
|
16
10
|
constructor(lendingPool: OnchainLendingPool, borrowable: Borrowable);
|
|
17
11
|
getLendingPool: () => OnchainLendingPool;
|
|
18
12
|
getBorrowableType: () => Borrowable;
|
|
@@ -25,19 +19,4 @@ export default abstract class OnchainBorrowable extends OnchainPoolToken {
|
|
|
25
19
|
protected initializeToken(): Promise<Contract>;
|
|
26
20
|
isETH(): Promise<boolean>;
|
|
27
21
|
getAvailableToBorrow(): Promise<number>;
|
|
28
|
-
/***
|
|
29
|
-
* TODO remove this part
|
|
30
|
-
**/
|
|
31
|
-
private initializeBorrowTracker;
|
|
32
|
-
getBorrowTracker(): Promise<string>;
|
|
33
|
-
hasFarming(): Promise<boolean>;
|
|
34
|
-
getImpermaxChef: () => any;
|
|
35
|
-
hasImpermaxChef(): Promise<boolean>;
|
|
36
|
-
private initializeFarmingTokenSymbol;
|
|
37
|
-
getFarmingTokenSymbol(): Promise<string>;
|
|
38
|
-
private initializeRewarder;
|
|
39
|
-
getRewarder(): Promise<any>;
|
|
40
|
-
hasRewarder(): Promise<boolean>;
|
|
41
|
-
private initializeRewarderTokenSymbol;
|
|
42
|
-
getRewarderTokenSymbol(): Promise<string>;
|
|
43
22
|
}
|
|
@@ -13,8 +13,6 @@ class OnchainBorrowable extends onchainPoolToken_1.default {
|
|
|
13
13
|
this.getBorrowableType = () => this.borrowable;
|
|
14
14
|
this.getContractHelper = () => this.lendingPool.getImpermaxFactory().getOnchain().getContractHelper();
|
|
15
15
|
this.getOffchainBorrowable = this.getOffchainPoolToken;
|
|
16
|
-
// Impermax Chef
|
|
17
|
-
this.getImpermaxChef = () => this.getContractHelper().impermaxChef;
|
|
18
16
|
this.lendingPool = lendingPool;
|
|
19
17
|
this.borrowable = borrowable;
|
|
20
18
|
}
|
|
@@ -40,71 +38,5 @@ class OnchainBorrowable extends onchainPoolToken_1.default {
|
|
|
40
38
|
async getAvailableToBorrow() {
|
|
41
39
|
return await this.getTotalBalance();
|
|
42
40
|
}
|
|
43
|
-
/***
|
|
44
|
-
* TODO remove this part
|
|
45
|
-
**/
|
|
46
|
-
// Farming Pool
|
|
47
|
-
async initializeBorrowTracker() {
|
|
48
|
-
const borrowable = await this.getPoolToken();
|
|
49
|
-
return borrowable.methods.borrowTracker().call();
|
|
50
|
-
}
|
|
51
|
-
async getBorrowTracker() {
|
|
52
|
-
if (!this.borrowableCache.borrowTracker)
|
|
53
|
-
this.borrowableCache.borrowTracker = this.initializeBorrowTracker();
|
|
54
|
-
return this.borrowableCache.borrowTracker;
|
|
55
|
-
}
|
|
56
|
-
async hasFarming() {
|
|
57
|
-
// remove old farming contracts, now it only has farming if it has the impermaxChef
|
|
58
|
-
return this.hasImpermaxChef();
|
|
59
|
-
}
|
|
60
|
-
async hasImpermaxChef() {
|
|
61
|
-
const borrowTracker = await this.getBorrowTracker();
|
|
62
|
-
return borrowTracker.toLowerCase() === (this.getImpermaxChef()._address ?? "").toLowerCase();
|
|
63
|
-
}
|
|
64
|
-
async initializeFarmingTokenSymbol() {
|
|
65
|
-
if (!await this.hasImpermaxChef())
|
|
66
|
-
return "";
|
|
67
|
-
const impermaxChef = await this.getImpermaxChef();
|
|
68
|
-
const farmingTokenAddress = await impermaxChef.methods.rewardToken().call();
|
|
69
|
-
return this.getContractHelper().newERC20(farmingTokenAddress).methods.symbol().call();
|
|
70
|
-
}
|
|
71
|
-
async getFarmingTokenSymbol() {
|
|
72
|
-
if (!this.borrowableCache.farmingTokenSymbol)
|
|
73
|
-
this.borrowableCache.farmingTokenSymbol = this.initializeFarmingTokenSymbol();
|
|
74
|
-
return this.borrowableCache.farmingTokenSymbol;
|
|
75
|
-
}
|
|
76
|
-
// Farming Pool Rewarder
|
|
77
|
-
async initializeRewarder() {
|
|
78
|
-
const poolTokenAddress = await this.getPoolTokenAddress();
|
|
79
|
-
try {
|
|
80
|
-
const { rewarder } = await this.getImpermaxChef().methods.poolInfo(poolTokenAddress).call();
|
|
81
|
-
if (rewarder == "0x0000000000000000000000000000000000000000")
|
|
82
|
-
return null;
|
|
83
|
-
return this.getContractHelper().newImpermaxChef(rewarder);
|
|
84
|
-
}
|
|
85
|
-
catch {
|
|
86
|
-
return null;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
async getRewarder() {
|
|
90
|
-
if (!this.borrowableCache.rewarder)
|
|
91
|
-
this.borrowableCache.rewarder = this.initializeRewarder();
|
|
92
|
-
return this.borrowableCache.rewarder;
|
|
93
|
-
}
|
|
94
|
-
async hasRewarder() {
|
|
95
|
-
return await this.getRewarder() !== null;
|
|
96
|
-
}
|
|
97
|
-
async initializeRewarderTokenSymbol() {
|
|
98
|
-
if (!await this.hasRewarder())
|
|
99
|
-
return "";
|
|
100
|
-
const rewarder = await this.getRewarder();
|
|
101
|
-
const rewardTokenAddress = await rewarder.methods.rewardToken().call();
|
|
102
|
-
return this.getContractHelper().newERC20(rewardTokenAddress).methods.symbol().call();
|
|
103
|
-
}
|
|
104
|
-
async getRewarderTokenSymbol() {
|
|
105
|
-
if (!this.borrowableCache.rewarderTokenSymbol)
|
|
106
|
-
this.borrowableCache.rewarderTokenSymbol = this.initializeRewarderTokenSymbol();
|
|
107
|
-
return this.borrowableCache.rewarderTokenSymbol;
|
|
108
|
-
}
|
|
109
41
|
}
|
|
110
42
|
exports.default = OnchainBorrowable;
|
|
@@ -52,9 +52,5 @@ class OnchainLendingPool {
|
|
|
52
52
|
return (await this.getLendingPoolAddresses()).borrowables[borrowable];
|
|
53
53
|
}
|
|
54
54
|
;
|
|
55
|
-
// Has Farming
|
|
56
|
-
async hasFarming() {
|
|
57
|
-
return await this.getBorrowableA().hasFarming() || await this.getBorrowableB().hasFarming();
|
|
58
|
-
}
|
|
59
55
|
}
|
|
60
56
|
exports.default = OnchainLendingPool;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
export interface BorrowableParams {
|
|
2
|
+
totalSupply: number;
|
|
3
|
+
totalBorrows: number;
|
|
4
|
+
kinkRate: number;
|
|
5
|
+
kinkUtilizationRate: number;
|
|
6
|
+
kinkMultiplier: number;
|
|
7
|
+
reserveFactor: number;
|
|
8
|
+
}
|
|
9
|
+
export declare class Borrowable {
|
|
10
|
+
totalSupply: number;
|
|
11
|
+
initialTotalSupply: number;
|
|
12
|
+
totalBorrows: number;
|
|
13
|
+
initialTotalBorrows: number;
|
|
14
|
+
kinkRate: number;
|
|
15
|
+
kinkUtilizationRate: number;
|
|
16
|
+
kinkMultiplier: number;
|
|
17
|
+
reserveFactor: number;
|
|
18
|
+
constructor(params: BorrowableParams);
|
|
19
|
+
/**
|
|
20
|
+
* PUBLIC GETTERS
|
|
21
|
+
*/
|
|
22
|
+
getInitialUtilizationRate(): number;
|
|
23
|
+
getUtilizationRate(): number;
|
|
24
|
+
getInitialAvailableToBorrow(): number;
|
|
25
|
+
getAvailableToBorrow(): number;
|
|
26
|
+
getInitialAvailableToWithdraw(): number;
|
|
27
|
+
getAvailableToWithdraw(): number;
|
|
28
|
+
getBorrowRate(): number;
|
|
29
|
+
getSupplyRate(): number;
|
|
30
|
+
getBorrowAPR(): number;
|
|
31
|
+
getSupplyAPR(): number;
|
|
32
|
+
/**
|
|
33
|
+
* PUBLIC SETTERS
|
|
34
|
+
*/
|
|
35
|
+
supply(amount: number): void;
|
|
36
|
+
withdraw(amount: number): void;
|
|
37
|
+
borrow(amount: number): void;
|
|
38
|
+
repay(amount: number): void;
|
|
39
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Borrowable = void 0;
|
|
4
|
+
const index_1 = require("../index");
|
|
5
|
+
class Borrowable {
|
|
6
|
+
constructor(params) {
|
|
7
|
+
this.totalSupply = params.totalSupply;
|
|
8
|
+
this.initialTotalSupply = params.totalSupply;
|
|
9
|
+
this.totalBorrows = params.totalBorrows;
|
|
10
|
+
this.initialTotalBorrows = params.totalBorrows;
|
|
11
|
+
this.kinkRate = params.kinkRate;
|
|
12
|
+
this.kinkUtilizationRate = params.kinkUtilizationRate;
|
|
13
|
+
this.kinkMultiplier = params.kinkMultiplier;
|
|
14
|
+
this.reserveFactor = params.reserveFactor;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* PUBLIC GETTERS
|
|
18
|
+
*/
|
|
19
|
+
getInitialUtilizationRate() {
|
|
20
|
+
if (this.initialTotalSupply === 0)
|
|
21
|
+
return 0;
|
|
22
|
+
return this.initialTotalBorrows / this.initialTotalSupply;
|
|
23
|
+
}
|
|
24
|
+
getUtilizationRate() {
|
|
25
|
+
if (this.totalSupply === 0)
|
|
26
|
+
return 0;
|
|
27
|
+
return this.totalBorrows / this.totalSupply;
|
|
28
|
+
}
|
|
29
|
+
getInitialAvailableToBorrow() {
|
|
30
|
+
return this.initialTotalSupply - this.initialTotalBorrows;
|
|
31
|
+
}
|
|
32
|
+
getAvailableToBorrow() {
|
|
33
|
+
return this.totalSupply - this.totalBorrows;
|
|
34
|
+
}
|
|
35
|
+
getInitialAvailableToWithdraw() {
|
|
36
|
+
return this.initialTotalSupply - this.initialTotalBorrows;
|
|
37
|
+
}
|
|
38
|
+
getAvailableToWithdraw() {
|
|
39
|
+
return this.totalSupply - this.totalBorrows;
|
|
40
|
+
}
|
|
41
|
+
getBorrowRate() {
|
|
42
|
+
const utilizationRate = this.getUtilizationRate();
|
|
43
|
+
if (utilizationRate <= this.kinkUtilizationRate) {
|
|
44
|
+
return this.kinkRate * utilizationRate / this.kinkUtilizationRate;
|
|
45
|
+
}
|
|
46
|
+
else {
|
|
47
|
+
const overUtil = (utilizationRate - this.kinkUtilizationRate) / (1 - this.kinkUtilizationRate);
|
|
48
|
+
return this.kinkRate * ((this.kinkMultiplier - 1) * overUtil + 1);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
getSupplyRate() {
|
|
52
|
+
return this.getBorrowRate() * this.getUtilizationRate() * (1 - this.reserveFactor);
|
|
53
|
+
}
|
|
54
|
+
getBorrowAPR() {
|
|
55
|
+
return (0, index_1.toAPR)(this.getBorrowRate());
|
|
56
|
+
}
|
|
57
|
+
getSupplyAPR() {
|
|
58
|
+
return (0, index_1.toAPR)(this.getSupplyRate());
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* PUBLIC SETTERS
|
|
62
|
+
*/
|
|
63
|
+
supply(amount) {
|
|
64
|
+
this.totalSupply = this.initialTotalSupply + amount;
|
|
65
|
+
}
|
|
66
|
+
withdraw(amount) {
|
|
67
|
+
if (amount > this.getInitialAvailableToWithdraw()) {
|
|
68
|
+
throw new Error("Trying to withdraw more than available liquidity");
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
this.totalSupply = this.initialTotalSupply - amount;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
borrow(amount) {
|
|
75
|
+
if (amount > this.getInitialAvailableToBorrow()) {
|
|
76
|
+
throw new Error("Trying to borrow more than available liquidity");
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
this.totalBorrows = this.initialTotalBorrows + amount;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
repay(amount) {
|
|
83
|
+
this.totalBorrows = Math.max(this.initialTotalBorrows - amount, 0);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
exports.Borrowable = Borrowable;
|