impermax-sdk 2.1.549 → 2.1.551
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/offchain/account/lendingPool/nftlp/offchainAccountNftlpGenericCL.js +2 -2
- package/lib/offchain/account/lendingPool/offchainAccountBorrowable.js +1 -1
- package/lib/offchain/lendingPool/offchainBorrowable.d.ts +1 -1
- package/lib/offchain/lendingPool/offchainBorrowable.js +2 -2
- package/lib/onchain/impermaxFactory/lendingPool/onchainBorrowable.js +1 -1
- package/lib/utils/borrowable/borrowableEntity/index.d.ts +2 -0
- package/lib/utils/borrowable/borrowableEntity/index.js +9 -3
- package/lib/utils/vault/lendingVaultEntity/index.js +22 -2
- package/package.json +1 -1
|
@@ -81,8 +81,8 @@ class OffchainAccountNftlpGenericCL extends offchainAccountNftlp_1.default {
|
|
|
81
81
|
priceB: await this.getPriceB(tokenId),
|
|
82
82
|
safetyMargin: await this.getLendingPool().getSafetyMargin(),
|
|
83
83
|
liquidationPenalty: await this.getLendingPool().getLiquidationPenalty(),
|
|
84
|
-
borrowableX: await this.getNftlp().getLendingPool().getBorrowableA().createBorrowableObject(),
|
|
85
|
-
borrowableY: await this.getNftlp().getLendingPool().getBorrowableB().createBorrowableObject(),
|
|
84
|
+
borrowableX: await this.getNftlp().getLendingPool().getBorrowableA().createBorrowableObject(false, true),
|
|
85
|
+
borrowableY: await this.getNftlp().getLendingPool().getBorrowableB().createBorrowableObject(false, true),
|
|
86
86
|
fullRangeRate: await this.getNftlp().getFullRangeRate(await this.getTickSpacing(tokenId)),
|
|
87
87
|
cumulativeDepositX: await this.getCumulativeDeposit0(tokenId),
|
|
88
88
|
cumulativeDepositY: await this.getCumulativeDeposit1(tokenId),
|
|
@@ -57,7 +57,7 @@ class OffchainAccountBorrowable extends offchainAccountPoolToken_1.default {
|
|
|
57
57
|
async createBorrowablePositionObject(lockStateChange = false) {
|
|
58
58
|
return new borrowablePosition_1.BorrowablePosition({
|
|
59
59
|
amount: await this.getAmount(),
|
|
60
|
-
borrowable: await this.getPoolToken().createBorrowableObject(lockStateChange),
|
|
60
|
+
borrowable: await this.getPoolToken().createBorrowableObject(lockStateChange, true),
|
|
61
61
|
lockStateChange,
|
|
62
62
|
});
|
|
63
63
|
}
|
|
@@ -7,7 +7,7 @@ import { OffchainLendingVault } from "../vault";
|
|
|
7
7
|
export default class OffchainBorrowable extends OffchainPoolToken {
|
|
8
8
|
protected readonly lendingPool: OffchainLendingPool;
|
|
9
9
|
protected readonly borrowable: Borrowable;
|
|
10
|
-
createBorrowableObject(lockStateChange?: boolean): Promise<BorrowableEntity>;
|
|
10
|
+
createBorrowableObject(lockStateChange?: boolean, useMaxFlashAllocate?: boolean): Promise<BorrowableEntity>;
|
|
11
11
|
private _accrueInterest;
|
|
12
12
|
private _calculateBorrowRate;
|
|
13
13
|
constructor(lendingPool: OffchainLendingPool, borrowable: Borrowable);
|
|
@@ -7,9 +7,9 @@ const utils_1 = require("../../utils");
|
|
|
7
7
|
const offchainPoolToken_1 = __importDefault(require("../offchainPoolToken"));
|
|
8
8
|
const borrowableEntity_1 = require("../../utils/borrowable/borrowableEntity");
|
|
9
9
|
class OffchainBorrowable extends offchainPoolToken_1.default {
|
|
10
|
-
async createBorrowableObject(lockStateChange = false) {
|
|
10
|
+
async createBorrowableObject(lockStateChange = false, useMaxFlashAllocate = false) {
|
|
11
11
|
const { kinkBorrowRate } = await this._calculateBorrowRate();
|
|
12
|
-
const maxFlashAllocate = await this.getMaxFlashAllocate();
|
|
12
|
+
const maxFlashAllocate = useMaxFlashAllocate ? await this.getMaxFlashAllocate() : null;
|
|
13
13
|
return new borrowableEntity_1.BorrowableEntity({
|
|
14
14
|
totalSupply: await this.getSupply(),
|
|
15
15
|
totalBorrows: await this.getTotalBorrows(),
|
|
@@ -38,7 +38,7 @@ class OnchainBorrowable extends onchainPoolToken_1.default {
|
|
|
38
38
|
return (underlying.toLowerCase() === weths_1.WETH[this.getLendingPool().getImpermaxFactory().getOnchain().network].toLowerCase());
|
|
39
39
|
}
|
|
40
40
|
async createBorrowableObject(lockStateChange = false) {
|
|
41
|
-
return (await this.getOffchainBorrowable()).createBorrowableObject(lockStateChange);
|
|
41
|
+
return (await this.getOffchainBorrowable()).createBorrowableObject(lockStateChange, true);
|
|
42
42
|
}
|
|
43
43
|
async getAvailableToBorrow() {
|
|
44
44
|
return await this.getTotalBalance();
|
|
@@ -31,6 +31,8 @@ export declare class BorrowableEntity {
|
|
|
31
31
|
getAvailableToBorrow(): number;
|
|
32
32
|
getInitialAvailableToWithdraw(): number;
|
|
33
33
|
getAvailableToWithdraw(): number;
|
|
34
|
+
calculateBorrowRateForUtilization(utilizationRate: number): number;
|
|
35
|
+
calculateSupplyRateForUtilization(utilizationRate: number): number;
|
|
34
36
|
getBorrowRate(): number;
|
|
35
37
|
getSupplyRate(): number;
|
|
36
38
|
getBorrowAPR(): number;
|
|
@@ -49,8 +49,7 @@ class BorrowableEntity {
|
|
|
49
49
|
getAvailableToWithdraw() {
|
|
50
50
|
return Math.max(this.totalSupply - this.totalBorrows, 0);
|
|
51
51
|
}
|
|
52
|
-
|
|
53
|
-
const utilizationRate = this.getUtilizationRate();
|
|
52
|
+
calculateBorrowRateForUtilization(utilizationRate) {
|
|
54
53
|
if (utilizationRate <= this.kinkUtilizationRate) {
|
|
55
54
|
return this.kinkBorrowRate * utilizationRate / this.kinkUtilizationRate;
|
|
56
55
|
}
|
|
@@ -59,8 +58,15 @@ class BorrowableEntity {
|
|
|
59
58
|
return this.kinkBorrowRate * ((this.kinkMultiplier - 1) * overUtil + 1);
|
|
60
59
|
}
|
|
61
60
|
}
|
|
61
|
+
calculateSupplyRateForUtilization(utilizationRate) {
|
|
62
|
+
const borrowRate = this.calculateBorrowRateForUtilization(utilizationRate);
|
|
63
|
+
return borrowRate * utilizationRate * (1 - this.reserveFactor);
|
|
64
|
+
}
|
|
65
|
+
getBorrowRate() {
|
|
66
|
+
return this.calculateBorrowRateForUtilization(this.getUtilizationRate());
|
|
67
|
+
}
|
|
62
68
|
getSupplyRate() {
|
|
63
|
-
return this.
|
|
69
|
+
return this.calculateSupplyRateForUtilization(this.getUtilizationRate());
|
|
64
70
|
}
|
|
65
71
|
getBorrowAPR() {
|
|
66
72
|
return (0, index_1.toAPR)(this.getBorrowRate());
|
|
@@ -133,9 +133,29 @@ class LendingVaultEntity {
|
|
|
133
133
|
}
|
|
134
134
|
getMaxFlashAllocate(borrowable) {
|
|
135
135
|
// TODO dynamically calculate this
|
|
136
|
-
|
|
137
|
-
return (this.getAvailableLiquidity() - amountToExclude) * 0.99;
|
|
136
|
+
//let amountToExclude = this.positions[borrowable].getInitialAvailableToWithdraw();
|
|
137
|
+
//return (this.getAvailableLiquidity() - amountToExclude) * 0.99;
|
|
138
138
|
// TODO questa è l'aggiunta, ma devo callare sommando anche initial amount... mmmmh
|
|
139
|
+
let maxFlashAllocate = 0;
|
|
140
|
+
const maxRate = this.positions[borrowable].borrowable.calculateSupplyRateForUtilization(1);
|
|
141
|
+
for (let i = 0; i < this.positions.length; i++) {
|
|
142
|
+
if (i === borrowable)
|
|
143
|
+
continue;
|
|
144
|
+
const b = this.positions[i].borrowable;
|
|
145
|
+
const maxWithdrawable = this.positions[i].getInitialAvailableToWithdraw();
|
|
146
|
+
const targetUtilizationRate = b.calculateUtilizationForRate(maxRate);
|
|
147
|
+
if (targetUtilizationRate > 1) {
|
|
148
|
+
maxFlashAllocate += maxWithdrawable;
|
|
149
|
+
continue;
|
|
150
|
+
}
|
|
151
|
+
const targetSupply = b.initialTotalBorrows / targetUtilizationRate;
|
|
152
|
+
// notice: supply delta CAN be negative
|
|
153
|
+
// in this case we have to consider that the vault will have to deposit
|
|
154
|
+
// liquidity in this pool instead of withdrawing it
|
|
155
|
+
const supplyDelta = b.totalSupply - targetSupply;
|
|
156
|
+
maxFlashAllocate += Math.min(maxWithdrawable, supplyDelta);
|
|
157
|
+
}
|
|
158
|
+
return Math.max(maxFlashAllocate * 0.99, 0);
|
|
139
159
|
}
|
|
140
160
|
}
|
|
141
161
|
exports.LendingVaultEntity = LendingVaultEntity;
|