@strkfarm/sdk 1.1.33 → 1.1.35

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.
@@ -198,21 +198,7 @@ export class UniversalStrategy<
198
198
  };
199
199
  }
200
200
 
201
- /**
202
- * Calculates the weighted average APY across all pools based on USD value.
203
- * @returns {Promise<number>} The weighted average APY across all pools
204
- */
205
- async netAPY(): Promise<{ net: number, splits: { apy: number, id: string }[] }> {
206
- if (this.metadata.isPreview) {
207
- return { net: 0, splits: [{
208
- apy: 0, id: 'base'
209
- }, {
210
- apy: 0, id: 'defispring'
211
- }] };
212
- }
213
-
214
- const prevAUM = await this.getPrevAUM();
215
-
201
+ async getVesuAPYs() {
216
202
  // get Vesu pools, positions and APYs
217
203
  const vesuAdapters = this.getVesuAdapters();
218
204
  const allVesuPools = await VesuAdapter.getVesuPools();
@@ -247,15 +233,28 @@ export class UniversalStrategy<
247
233
 
248
234
  // Else further compute will fail
249
235
  assert(baseAPYs.length == positions.length, 'APYs and positions length mismatch');
236
+
237
+ return {
238
+ baseAPYs,
239
+ rewardAPYs,
240
+ positions
241
+ }
242
+ }
250
243
 
251
- // If no positions, return 0
252
- if (positions.every(p => p.amount.isZero())) {
244
+ /**
245
+ * Calculates the weighted average APY across all pools based on USD value.
246
+ * @returns {Promise<number>} The weighted average APY across all pools
247
+ */
248
+ async netAPY(): Promise<{ net: number, splits: { apy: number, id: string }[] }> {
249
+ if (this.metadata.isPreview) {
253
250
  return { net: 0, splits: [{
254
251
  apy: 0, id: 'base'
255
252
  }, {
256
253
  apy: 0, id: 'defispring'
257
- }]};
254
+ }] };
258
255
  }
256
+
257
+ const { positions, baseAPYs, rewardAPYs } = await this.getVesuAPYs();
259
258
 
260
259
  const unusedBalanceAPY = await this.getUnusedBalanceAPY();
261
260
  baseAPYs.push(...[unusedBalanceAPY.apy]);
@@ -264,6 +263,22 @@ export class UniversalStrategy<
264
263
  // Compute APy using weights
265
264
  const weights = positions.map((p, index) => p.usdValue * (index % 2 == 0 ? 1 : -1));
266
265
  weights.push(unusedBalanceAPY.weight);
266
+
267
+ return this.returnNetAPY(baseAPYs, rewardAPYs, weights);
268
+ }
269
+
270
+ protected async returnNetAPY(baseAPYs: number[], rewardAPYs: number[], weights: number[]) {
271
+ // If no positions, return 0
272
+ if (weights.every(p => p == 0)) {
273
+ return { net: 0, splits: [{
274
+ apy: 0, id: 'base'
275
+ }, {
276
+ apy: 0, id: 'defispring'
277
+ }]};
278
+ }
279
+
280
+ const prevAUM = await this.getPrevAUM();
281
+
267
282
  const price = await this.pricer.getPrice(this.metadata.depositTokens[0].symbol);
268
283
  const prevAUMUSD = prevAUM.multipliedBy(price.price);
269
284
  const baseAPY = this.computeAPY(baseAPYs, weights, prevAUMUSD);