impermax-sdk 2.1.303 → 2.1.304
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.
|
@@ -31,6 +31,7 @@ export default class OffchainNftlpUniswapV3 extends OffchainNftlp {
|
|
|
31
31
|
tvlUsd: number;
|
|
32
32
|
}>;
|
|
33
33
|
getFullRangeRate(fee: number): Promise<number>;
|
|
34
|
+
getGlobalTvl(fee: number): Promise<number>;
|
|
34
35
|
getWeightedAvgFullRangeRate(): Promise<number>;
|
|
35
36
|
getTotalAPR(): Promise<number>;
|
|
36
37
|
}
|
|
@@ -68,16 +68,19 @@ class OffchainNftlpUniswapV3 extends offchainNftlp_1.default {
|
|
|
68
68
|
}
|
|
69
69
|
// thorugh the fullRangeRate we can calculate the rate of all ranges
|
|
70
70
|
async getFullRangeRateAndTvl(fee) {
|
|
71
|
+
const zero = { fullRangeRate: 0, tvlUsd: 0 };
|
|
71
72
|
// get a pool or return 0
|
|
72
73
|
const pool = await this.getUniswapV3Pool(fee);
|
|
73
74
|
if (!pool.address)
|
|
74
|
-
return
|
|
75
|
+
return zero;
|
|
75
76
|
// use llama API to get the APR based on last 7 days fees
|
|
76
77
|
// the APR is calculated as: total reward / tvl
|
|
77
78
|
const offchain = this.getLendingPool().getOffchain();
|
|
78
79
|
const { apyBase, volumeUsd1d, volumeUsd7d, tvlUsd, } = await offchain.getAPRHelper().getLlamaYieldsUniswapV3(pool.address, offchain.network);
|
|
79
|
-
|
|
80
|
-
|
|
80
|
+
if (tvlUsd === 0)
|
|
81
|
+
return zero;
|
|
82
|
+
//const llamaApyBase = apyBase / 100;
|
|
83
|
+
//const apr1dFees = volumeUsd1d * fee * 365 / tvlUsd;
|
|
81
84
|
const apr7dFees = volumeUsd7d * fee / 7 * 365 / tvlUsd;
|
|
82
85
|
// convert llama apy to rate
|
|
83
86
|
const avgRate = apr7dFees / utils_1.SECONDS_IN_YEAR;
|
|
@@ -87,6 +90,8 @@ class OffchainNftlpUniswapV3 extends offchainNftlp_1.default {
|
|
|
87
90
|
const baseLiquidityPrice = Math.sqrt(priceA * priceB) * 2;
|
|
88
91
|
// baseLiqudiityUsd -> how much the liquidity would be worth if it wasn't concentrated
|
|
89
92
|
const baseLiquidityUsd = pool.liquidity * baseLiquidityPrice;
|
|
93
|
+
if (baseLiquidityUsd === 0)
|
|
94
|
+
return zero;
|
|
90
95
|
const avgConcentrationFactor = baseLiquidityUsd / tvlUsd;
|
|
91
96
|
const fullRangeRate = avgRate / avgConcentrationFactor;
|
|
92
97
|
return { fullRangeRate, tvlUsd };
|
|
@@ -94,6 +99,9 @@ class OffchainNftlpUniswapV3 extends offchainNftlp_1.default {
|
|
|
94
99
|
async getFullRangeRate(fee) {
|
|
95
100
|
return (await this.getFullRangeRateAndTvl(fee)).fullRangeRate;
|
|
96
101
|
}
|
|
102
|
+
async getGlobalTvl(fee) {
|
|
103
|
+
return (await this.getFullRangeRateAndTvl(fee)).tvlUsd;
|
|
104
|
+
}
|
|
97
105
|
// calculate apr based on the weighted avg of all the available fees
|
|
98
106
|
async getWeightedAvgFullRangeRate() {
|
|
99
107
|
let totalTvl = 0;
|
|
@@ -80,11 +80,9 @@ class UniswapV3Position extends genericPosition_1.default {
|
|
|
80
80
|
return this.getInitialRealY() + this.initialUnclaimedFeesY;
|
|
81
81
|
}
|
|
82
82
|
getDepositedX() {
|
|
83
|
-
console.log("getDepositedX", this.getRealX() + this.unclaimedFeesX, this.getRealX(), this.unclaimedFeesX);
|
|
84
83
|
return this.getRealX() + this.unclaimedFeesX;
|
|
85
84
|
}
|
|
86
85
|
getDepositedY() {
|
|
87
|
-
console.log("getDepositedY", this.getRealY() + this.unclaimedFeesY, this.getRealY(), this.unclaimedFeesY);
|
|
88
86
|
return this.getRealY() + this.unclaimedFeesY;
|
|
89
87
|
}
|
|
90
88
|
getBaseRate() {
|