impermax-sdk 2.1.358 → 2.1.360

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.
@@ -201,10 +201,10 @@ class OffchainNftlpUniswapV3 extends offchainNftlp_1.default {
201
201
  }
202
202
  return bestRate;
203
203
  }
204
- // calculate the pair APR assuming a +-15% price range
204
+ // calculate the pair APR assuming a +-8% price range
205
205
  async getTotalAPR() {
206
206
  const fullRangeAPR = await this.getBestFullRangeRate() * utils_1.SECONDS_IN_YEAR;
207
- return fullRangeAPR * (0, uniswapV3General_1.uniV3ConcentrationFactor)(1 / 1.15, 1.15);
207
+ return fullRangeAPR * (0, uniswapV3General_1.uniV3ConcentrationFactor)(1 / 1.08, 1.08);
208
208
  }
209
209
  }
210
210
  exports.default = OffchainNftlpUniswapV3;
@@ -107,23 +107,70 @@ class OffchainAPRHelper {
107
107
  // Initializes all our chain tvl and borrows from llama
108
108
  async initializeTvls() {
109
109
  try {
110
- const response = await fetch("https://api.llama.fi/protocol/impermax-finance").then((i) => i.json());
111
- // Simple TVL of all chains
112
- const currentChainTvls = response.currentChainTvls;
113
- // For charts of our tvl and tvl by chains
114
- const chainTvlCharts = response.chainTvls;
115
- const protocolTvlChart = response.tvl;
116
- // Get the chain tvls
117
- this.chainTvls = Object.entries(currentChainTvls).reduce((acc, [chain, tvl]) => {
110
+ const [v2Response, v3Response, impermaxAll] = await Promise.all([
111
+ fetch("https://api.llama.fi/protocol/impermax-v2").then(i => i.json()),
112
+ fetch("https://api.llama.fi/protocol/impermax-v3").then(i => i.json()),
113
+ fetch("https://api.llama.fi/protocol/impermax-finance").then(i => i.json())
114
+ ]);
115
+ // Combine chain TVLs from both versions
116
+ const v2ChainTvls = v2Response.currentChainTvls || {};
117
+ const v3ChainTvls = v3Response.currentChainTvls || {};
118
+ // Initialize with v2 chain TVLs
119
+ this.chainTvls = Object.entries(v2ChainTvls).reduce((acc, [chain, tvl]) => {
118
120
  acc[chain.toLowerCase()] = tvl;
119
121
  return acc;
120
122
  }, {});
123
+ // Add or update with v3 chain TVLs
124
+ Object.entries(v3ChainTvls).forEach(([chain, tvl]) => {
125
+ this.chainTvls[chain.toLowerCase()] = (this.chainTvls[chain.toLowerCase()] || 0) + Number(tvl);
126
+ });
127
+ // For charts of our tvl and tvl by chains
128
+ const chainTvlCharts = impermaxAll.chainTvls;
121
129
  // Get the chain tvls day data to build charts
122
130
  this.chainTvlCharts = Object.entries(chainTvlCharts).reduce((acc, [chain, dayData]) => {
123
131
  acc[chain.toLowerCase()] = dayData.tvl;
124
132
  return acc;
125
133
  }, {});
126
- this.protocolTvlChart = protocolTvlChart;
134
+ const normalizedTvlByDate = new Map();
135
+ // Process v2 data with normalized dates
136
+ v2Response.tvl.forEach(item => {
137
+ // Convert timestamp to milliseconds and create Date
138
+ const date = new Date(item.date * 1000);
139
+ // Normalize to start of day
140
+ date.setHours(0, 0, 0, 0);
141
+ // Convert back to seconds for consistency
142
+ const normalizedTimestamp = Math.floor(date.getTime() / 1000);
143
+ normalizedTvlByDate.set(normalizedTimestamp, {
144
+ date: normalizedTimestamp,
145
+ totalLiquidityUSD: item.totalLiquidityUSD
146
+ });
147
+ });
148
+ // Process v3 data and add to existing entries
149
+ v3Response.tvl.forEach(item => {
150
+ if (Number(item.date) === 1743552000)
151
+ return;
152
+ // Convert timestamp to milliseconds and create Date
153
+ const date = new Date(item.date * 1000);
154
+ // Normalize to start of day
155
+ date.setHours(0, 0, 0, 0);
156
+ // Convert back to seconds for consistency
157
+ const normalizedTimestamp = Math.floor(date.getTime() / 1000);
158
+ if (normalizedTvlByDate.has(normalizedTimestamp)) {
159
+ // Add v3 TVL to existing v2 TVL for this date
160
+ const existingEntry = normalizedTvlByDate.get(normalizedTimestamp);
161
+ existingEntry.totalLiquidityUSD += item.totalLiquidityUSD;
162
+ }
163
+ else {
164
+ // This date only exists in v3, add it as new
165
+ normalizedTvlByDate.set(normalizedTimestamp, {
166
+ date: normalizedTimestamp,
167
+ totalLiquidityUSD: item.totalLiquidityUSD
168
+ });
169
+ }
170
+ });
171
+ // Convert map back to sorted array
172
+ this.protocolTvlChart = Array.from(normalizedTvlByDate.values())
173
+ .sort((a, b) => a.date - b.date);
127
174
  }
128
175
  catch (err) {
129
176
  console.warn("The llamas TVL down?");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "impermax-sdk",
3
- "version": "2.1.358",
3
+ "version": "2.1.360",
4
4
  "description": "",
5
5
  "main": "./lib/index.js",
6
6
  "module": "./lib/index.js",