impermax-sdk 2.1.85 → 2.1.87
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.
|
@@ -18,6 +18,7 @@ export default class OnchainNftlpUniswapV3 extends OnchainNftlp {
|
|
|
18
18
|
protected initializeNftlp(): any;
|
|
19
19
|
protected initializeUniswapV3Pool(fee: number): Promise<Contract | null>;
|
|
20
20
|
getUniswapV3Pool(fee: number): Promise<any>;
|
|
21
|
+
private priceAdjustment;
|
|
21
22
|
protected initializeMarketPrice(): Promise<number>;
|
|
22
23
|
protected initializeOraclePrice(): Promise<number>;
|
|
23
24
|
tickToPrice(tick: number): Promise<number>;
|
|
@@ -56,15 +56,24 @@ class OnchainNftlpUniswapV3 extends onchainNftlp_1.default {
|
|
|
56
56
|
return this.cache.uniswapV3Pools[fee];
|
|
57
57
|
});
|
|
58
58
|
}
|
|
59
|
+
priceAdjustment() {
|
|
60
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
61
|
+
const decimalA = yield this.getLendingPool().getBorrowableA().getDecimals();
|
|
62
|
+
const decimalB = yield this.getLendingPool().getBorrowableB().getDecimals();
|
|
63
|
+
const netDecimal = decimalA - decimalB;
|
|
64
|
+
return Math.pow(10, netDecimal);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
59
67
|
initializeMarketPrice() {
|
|
60
68
|
return __awaiter(this, void 0, void 0, function* () {
|
|
61
69
|
let priceCumulative = 0;
|
|
62
70
|
let liquidityCumulative = 0;
|
|
71
|
+
const priceAdjustment = yield this.priceAdjustment();
|
|
63
72
|
for (const fee of FEES) {
|
|
64
73
|
const pool = yield this.getUniswapV3Pool(fee);
|
|
65
74
|
if (!pool)
|
|
66
75
|
continue;
|
|
67
|
-
const price = Math.pow(((yield pool.methods.slot0().call()).sqrtPriceX96 / Math.pow(2, 96)), 2);
|
|
76
|
+
const price = Math.pow(((yield pool.methods.slot0().call()).sqrtPriceX96 / Math.pow(2, 96)), 2) * priceAdjustment;
|
|
68
77
|
const liquidity = (yield pool.methods.liquidity().call()) * 1;
|
|
69
78
|
priceCumulative += price * liquidity;
|
|
70
79
|
liquidityCumulative += liquidity;
|
|
@@ -75,24 +84,21 @@ class OnchainNftlpUniswapV3 extends onchainNftlp_1.default {
|
|
|
75
84
|
initializeOraclePrice() {
|
|
76
85
|
return __awaiter(this, void 0, void 0, function* () {
|
|
77
86
|
const nftlp = yield this.getNftlp();
|
|
78
|
-
|
|
87
|
+
const priceAdjustment = yield this.priceAdjustment();
|
|
88
|
+
return Math.pow(((yield nftlp.methods.oraclePriceSqrtX96().call()) / Math.pow(2, 96)), 2) * priceAdjustment;
|
|
79
89
|
});
|
|
80
90
|
}
|
|
81
91
|
tickToPrice(tick) {
|
|
82
92
|
return __awaiter(this, void 0, void 0, function* () {
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
const netDecimal = decimalA - decimalB;
|
|
86
|
-
return Math.pow(1.0001, tick) * Math.pow(10, netDecimal);
|
|
93
|
+
const priceAdjustment = yield this.priceAdjustment();
|
|
94
|
+
return Math.pow(1.0001, tick) * priceAdjustment;
|
|
87
95
|
});
|
|
88
96
|
}
|
|
89
97
|
priceToTick(price) {
|
|
90
98
|
return __awaiter(this, void 0, void 0, function* () {
|
|
91
|
-
const
|
|
92
|
-
const decimalB = yield this.getLendingPool().getBorrowableB().getDecimals();
|
|
93
|
-
const netDecimal = decimalA - decimalB;
|
|
99
|
+
const priceAdjustment = yield this.priceAdjustment();
|
|
94
100
|
// TODO round to tick precision
|
|
95
|
-
return Math.log(price /
|
|
101
|
+
return Math.log(price / priceAdjustment) / Math.log(1.0001);
|
|
96
102
|
});
|
|
97
103
|
}
|
|
98
104
|
}
|