impermax-sdk 2.1.80 → 2.1.82
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/account/lendingPool/nftlp/onchainAccountNftlpUniswapV3.d.ts +2 -1
- package/lib/onchain/account/lendingPool/nftlp/onchainAccountNftlpUniswapV3.js +5 -4
- package/lib/onchain/impermaxFactory/lendingPool/nftlp/onchainNftlpUniswapV3.d.ts +2 -0
- package/lib/onchain/impermaxFactory/lendingPool/nftlp/onchainNftlpUniswapV3.js +16 -0
- package/lib/onchain/interactions/lendingPool/nftlp/onchainInteractionsNftlpUniswapV3.js +7 -1
- package/package.json +1 -1
|
@@ -19,6 +19,7 @@ export default class OnchainAccountNftlpUniswapV3 extends OnchainAccountNftlp {
|
|
|
19
19
|
[keys in number]: Promise<UniswapV3Position>;
|
|
20
20
|
};
|
|
21
21
|
};
|
|
22
|
+
getNftlp: () => any;
|
|
22
23
|
protected initializePositionData(tokenId: number): Promise<PositionData>;
|
|
23
24
|
protected getPositionData(tokenId: number): Promise<PositionData>;
|
|
24
25
|
getFee(tokenId: number): Promise<number>;
|
|
@@ -28,7 +29,7 @@ export default class OnchainAccountNftlpUniswapV3 extends OnchainAccountNftlp {
|
|
|
28
29
|
getPriceB(tokenId: number): Promise<number>;
|
|
29
30
|
getLiquidity(tokenId: number): Promise<number>;
|
|
30
31
|
createPositionObject(tokenId: number, lockStateChange?: boolean): Promise<UniswapV3Position>;
|
|
31
|
-
createNewPositionObject(fee: number,
|
|
32
|
+
createNewPositionObject(fee: number, priceA: number, priceB: number, lockStateChange?: boolean): Promise<UniswapV3Position>;
|
|
32
33
|
getPositionObject(tokenId: number): Promise<UniswapV3Position>;
|
|
33
34
|
}
|
|
34
35
|
export {};
|
|
@@ -18,6 +18,7 @@ class OnchainAccountNftlpUniswapV3 extends onchainAccountNftlp_1.default {
|
|
|
18
18
|
constructor() {
|
|
19
19
|
super(...arguments);
|
|
20
20
|
this.cache = {};
|
|
21
|
+
this.getNftlp = () => this.getLendingPool().getLendingPool().getNftlp();
|
|
21
22
|
}
|
|
22
23
|
initializePositionData(tokenId) {
|
|
23
24
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -51,12 +52,12 @@ class OnchainAccountNftlpUniswapV3 extends onchainAccountNftlp_1.default {
|
|
|
51
52
|
}
|
|
52
53
|
getPriceA(tokenId) {
|
|
53
54
|
return __awaiter(this, void 0, void 0, function* () {
|
|
54
|
-
return
|
|
55
|
+
return this.getNftlp().tickToPrice(yield this.getTickLower(tokenId));
|
|
55
56
|
});
|
|
56
57
|
}
|
|
57
58
|
getPriceB(tokenId) {
|
|
58
59
|
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
-
return
|
|
60
|
+
return this.getNftlp().tickToPrice(yield this.getTickUpper(tokenId));
|
|
60
61
|
});
|
|
61
62
|
}
|
|
62
63
|
getLiquidity(tokenId) {
|
|
@@ -69,9 +70,9 @@ class OnchainAccountNftlpUniswapV3 extends onchainAccountNftlp_1.default {
|
|
|
69
70
|
return new uniswapV3Position_1.default(yield this.getLiquidity(tokenId), yield this.getLendingPool().getBorrowableA().getBorrowed(tokenId), yield this.getLendingPool().getBorrowableB().getBorrowed(tokenId), yield this.getNftlp().getMarketPrice(), yield this.getNftlp().getOraclePrice(), yield this.getPriceA(tokenId), yield this.getPriceB(tokenId), yield this.getLendingPool().getSafetyMargin(), yield this.getLendingPool().getLiquidationPenalty(), lockStateChange);
|
|
70
71
|
});
|
|
71
72
|
}
|
|
72
|
-
createNewPositionObject(fee,
|
|
73
|
+
createNewPositionObject(fee, priceA, priceB, lockStateChange = false) {
|
|
73
74
|
return __awaiter(this, void 0, void 0, function* () {
|
|
74
|
-
return new uniswapV3Position_1.default(0, 0, 0, yield this.getNftlp().getMarketPrice(), yield this.getNftlp().getOraclePrice(),
|
|
75
|
+
return new uniswapV3Position_1.default(0, 0, 0, yield this.getNftlp().getMarketPrice(), yield this.getNftlp().getOraclePrice(), priceA, priceB, yield this.getLendingPool().getSafetyMargin(), yield this.getLendingPool().getLiquidationPenalty(), lockStateChange);
|
|
75
76
|
});
|
|
76
77
|
}
|
|
77
78
|
getPositionObject(tokenId) {
|
|
@@ -20,4 +20,6 @@ export default class OnchainNftlpUniswapV3 extends OnchainNftlp {
|
|
|
20
20
|
getUniswapV3Pool(fee: number): Promise<any>;
|
|
21
21
|
protected initializeMarketPrice(): Promise<number>;
|
|
22
22
|
protected initializeOraclePrice(): Promise<number>;
|
|
23
|
+
tickToPrice(tick: number): Promise<number>;
|
|
24
|
+
priceToTick(price: number): Promise<number>;
|
|
23
25
|
}
|
|
@@ -78,5 +78,21 @@ class OnchainNftlpUniswapV3 extends onchainNftlp_1.default {
|
|
|
78
78
|
return Math.pow((nftlp.methods.oraclePriceSqrtX96().call() / Math.pow(2, 96)), 2);
|
|
79
79
|
});
|
|
80
80
|
}
|
|
81
|
+
tickToPrice(tick) {
|
|
82
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
83
|
+
const decimalA = yield this.getLendingPool().getBorrowableA().getDecimals();
|
|
84
|
+
const decimalB = yield this.getLendingPool().getBorrowableB().getDecimals();
|
|
85
|
+
const netDecimal = decimalA - decimalB;
|
|
86
|
+
return Math.pow(1.0001, tick) * Math.pow(10, netDecimal);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
priceToTick(price) {
|
|
90
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
91
|
+
const decimalA = yield this.getLendingPool().getBorrowableA().getDecimals();
|
|
92
|
+
const decimalB = yield this.getLendingPool().getBorrowableB().getDecimals();
|
|
93
|
+
const netDecimal = decimalA - decimalB;
|
|
94
|
+
return Math.log(price / Math.pow(10, netDecimal)) / Math.log(1.0001);
|
|
95
|
+
});
|
|
96
|
+
}
|
|
81
97
|
}
|
|
82
98
|
exports.default = OnchainNftlpUniswapV3;
|
|
@@ -38,7 +38,9 @@ class OnchainInteractionsNftlpUniswapV3 extends onchainInteractionsNftlp_1.defau
|
|
|
38
38
|
borrowBDelta < 0)
|
|
39
39
|
throw new Error("Unexpected negative inputs");
|
|
40
40
|
const actionsGetter = this.getActionsGetter();
|
|
41
|
-
const
|
|
41
|
+
const priceA = yield this.getNftlp().tickToPrice(tickLower);
|
|
42
|
+
const priceB = yield this.getNftlp().tickToPrice(tickUpper);
|
|
43
|
+
const result = yield this._getUpdatePositionActions(-1, yield this.getAccountNftlp().createNewPositionObject(fee, priceA, priceB), depositADelta, depositBDelta, borrowADelta, borrowBDelta);
|
|
42
44
|
// TODO check fee and ticks encoding
|
|
43
45
|
result.actions.unshift(yield actionsGetter.methods.getMintUniV3EmptyAction(fee.toString(), tickLower.toString(), tickUpper.toString()).call());
|
|
44
46
|
return result;
|
|
@@ -113,6 +115,10 @@ class OnchainInteractionsNftlpUniswapV3 extends onchainInteractionsNftlp_1.defau
|
|
|
113
115
|
}
|
|
114
116
|
// Mint
|
|
115
117
|
if (depositADelta > 0 || depositBDelta > 0) {
|
|
118
|
+
console.log(depositADelta, depositBDelta);
|
|
119
|
+
console.log(yield borrowableA.toBigNumber(depositADelta), yield borrowableB.toBigNumber(depositBDelta), yield borrowableA.toBigNumber(depositADelta / this.getUiMargin()), yield borrowableB.toBigNumber(depositBDelta / this.getUiMargin()));
|
|
120
|
+
console.log(yield actionsGetter.methods.getMintUniV3Action(yield borrowableA.toBigNumber(depositADelta), yield borrowableB.toBigNumber(depositBDelta), yield borrowableA.toBigNumber(depositADelta / this.getUiMargin()), yield borrowableB.toBigNumber(depositBDelta / this.getUiMargin())).call());
|
|
121
|
+
console.log(actions);
|
|
116
122
|
actions.push(yield actionsGetter.methods.getMintUniV3Action(yield borrowableA.toBigNumber(depositADelta), yield borrowableB.toBigNumber(depositBDelta), yield borrowableA.toBigNumber(depositADelta / this.getUiMargin()), yield borrowableB.toBigNumber(depositBDelta / this.getUiMargin())).call());
|
|
117
123
|
if (isEthA) {
|
|
118
124
|
ethValue += depositADelta;
|