@strkfarm/sdk 1.0.35 → 1.0.37

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.
@@ -12954,13 +12954,30 @@ var VesuRebalance = class _VesuRebalance extends BaseStrategy {
12954
12954
  * - finalPools: Array of pool information after rebalance
12955
12955
  * @throws Error if rebalance is not possible while maintaining constraints
12956
12956
  */
12957
- async getRebalancedPositions() {
12958
- const { data: pools } = await this.getPools();
12959
- const totalAssets = (await this.getTVL()).amount;
12957
+ async getRebalancedPositions(_pools) {
12958
+ logger.verbose(`VesuRebalance: getRebalancedPositions`);
12959
+ if (!_pools) {
12960
+ const { data: _pools2 } = await this.getPools();
12961
+ _pools = _pools2;
12962
+ }
12963
+ const feeDeductions = await this.getFee(_pools);
12964
+ logger.verbose(`VesuRebalance: feeDeductions: ${JSON.stringify(feeDeductions)}`);
12965
+ const pools = _pools.map((p) => {
12966
+ const fee = feeDeductions.find((f) => p.v_token.eq(f.vToken))?.fee || Web3Number.fromWei("0", this.decimals());
12967
+ logger.verbose(`FeeAdjustment: ${p.pool_id} => ${fee.toString()}, amt: ${p.amount.toString()}`);
12968
+ return {
12969
+ ...p,
12970
+ amount: p.amount.minus(fee)
12971
+ };
12972
+ });
12973
+ let totalAssets = (await this.getTVL()).amount;
12960
12974
  if (totalAssets.eq(0)) return {
12961
12975
  changes: [],
12962
12976
  finalPools: []
12963
12977
  };
12978
+ feeDeductions.forEach((f) => {
12979
+ totalAssets = totalAssets.minus(f.fee);
12980
+ });
12964
12981
  const sumPools = pools.reduce((acc, curr) => acc.plus(curr.amount.toString()), Web3Number.fromWei("0", this.decimals()));
12965
12982
  logger.verbose(`Sum of pools: ${sumPools.toString()}`);
12966
12983
  logger.verbose(`Total assets: ${totalAssets.toString()}`);
@@ -12998,8 +13015,8 @@ var VesuRebalance = class _VesuRebalance extends BaseStrategy {
12998
13015
  const sumChanges = changes.reduce((sum, c) => sum.plus(c.changeAmt.toString()), Web3Number.fromWei("0", this.decimals()));
12999
13016
  const sumFinal = changes.reduce((sum, c) => sum.plus(c.finalAmt.toString()), Web3Number.fromWei("0", this.decimals()));
13000
13017
  const hasChanges = changes.some((c) => !c.changeAmt.eq(0));
13001
- if (!sumChanges.eq(0)) throw new Error("Sum of changes must be zero");
13002
13018
  logger.verbose(`Sum of changes: ${sumChanges.toString()}`);
13019
+ if (!sumChanges.eq(0)) throw new Error("Sum of changes must be zero");
13003
13020
  logger.verbose(`Sum of final: ${sumFinal.toString()}`);
13004
13021
  logger.verbose(`Total assets: ${totalAssets.toString()}`);
13005
13022
  if (!sumFinal.eq(totalAssets.toString())) throw new Error("Sum of final amounts must equal total assets");
@@ -13103,6 +13120,49 @@ var VesuRebalance = class _VesuRebalance extends BaseStrategy {
13103
13120
  ])
13104
13121
  ];
13105
13122
  }
13123
+ /**
13124
+ * Calculates the fees deducted in different vTokens based on the current and previous state.
13125
+ * @param previousTotalSupply - The total supply of the strategy token before the transaction
13126
+ * @returns {Promise<Array<{ vToken: ContractAddr, fee: Web3Number }>>} Array of fees deducted in different vTokens
13127
+ */
13128
+ async getFee(allowedPools) {
13129
+ const assets = Web3Number.fromWei((await this.contract.total_assets()).toString(), this.asset().decimals);
13130
+ const totalSupply = Web3Number.fromWei((await this.contract.total_supply()).toString(), this.asset().decimals);
13131
+ const prevIndex = Web3Number.fromWei((await this.contract.get_previous_index()).toString(), 18);
13132
+ const currIndex = new Web3Number(1, 18).multipliedBy(assets).dividedBy(totalSupply);
13133
+ logger.verbose(`Previous index: ${prevIndex.toString()}`);
13134
+ logger.verbose(`Assets: ${assets.toString()}`);
13135
+ logger.verbose(`Total supply: ${totalSupply.toString()}`);
13136
+ logger.verbose(`Current index: ${currIndex.toNumber()}`);
13137
+ if (currIndex.lt(prevIndex)) {
13138
+ logger.verbose(`getFee::Current index is less than previous index, no fees to be deducted`);
13139
+ return [];
13140
+ }
13141
+ const indexDiff = currIndex.minus(prevIndex);
13142
+ logger.verbose(`Index diff: ${indexDiff.toString()}`);
13143
+ const numerator = totalSupply.multipliedBy(indexDiff).multipliedBy(this.metadata.additionalInfo.feeBps);
13144
+ const denominator = 1e4;
13145
+ let fee = numerator.dividedBy(denominator);
13146
+ logger.verbose(`Fee: ${fee.toString()}`);
13147
+ if (fee.lte(0)) {
13148
+ return [];
13149
+ }
13150
+ const fees = [];
13151
+ let remainingFee = fee.plus(Web3Number.fromWei("100", this.asset().decimals));
13152
+ for (const pool of allowedPools) {
13153
+ const vToken = pool.v_token;
13154
+ const balance = pool.amount;
13155
+ if (remainingFee.lte(balance)) {
13156
+ fees.push({ vToken, fee: remainingFee });
13157
+ break;
13158
+ } else {
13159
+ fees.push({ vToken, fee: Web3Number.fromWei(balance.toString(), 18) });
13160
+ remainingFee = remainingFee.minus(Web3Number.fromWei(balance.toString(), 18));
13161
+ }
13162
+ }
13163
+ logger.verbose(`Fees: ${JSON.stringify(fees)}`);
13164
+ return fees;
13165
+ }
13106
13166
  };
13107
13167
  var _description = "Automatically diversify {{TOKEN}} holdings into different Vesu pools while reducing risk and maximizing yield. Defi spring STRK Rewards are auto-compounded as well.";
13108
13168
  var _protocol = { name: "Vesu", logo: "https://static-assets-8zct.onrender.com/integrations/vesu/logo.png" };
package/dist/index.d.ts CHANGED
@@ -580,7 +580,7 @@ declare class VesuRebalance extends BaseStrategy<SingleTokenInfo, SingleActionAm
580
580
  * - finalPools: Array of pool information after rebalance
581
581
  * @throws Error if rebalance is not possible while maintaining constraints
582
582
  */
583
- getRebalancedPositions(): Promise<{
583
+ getRebalancedPositions(_pools?: PoolInfoFull[]): Promise<{
584
584
  changes: never[];
585
585
  finalPools: never[];
586
586
  isAnyPoolOverMaxWeight?: undefined;
@@ -597,6 +597,15 @@ declare class VesuRebalance extends BaseStrategy<SingleTokenInfo, SingleActionAm
597
597
  getRebalanceCall(pools: Awaited<ReturnType<typeof this.getRebalancedPositions>>['changes'], isOverWeightAdjustment: boolean): Promise<starknet.Call | null>;
598
598
  getInvestmentFlows(pools: PoolInfoFull[]): Promise<IInvestmentFlow[]>;
599
599
  harvest(acc: Account): Promise<starknet.Call[]>;
600
+ /**
601
+ * Calculates the fees deducted in different vTokens based on the current and previous state.
602
+ * @param previousTotalSupply - The total supply of the strategy token before the transaction
603
+ * @returns {Promise<Array<{ vToken: ContractAddr, fee: Web3Number }>>} Array of fees deducted in different vTokens
604
+ */
605
+ getFee(allowedPools: Array<PoolInfoFull>): Promise<Array<{
606
+ vToken: ContractAddr;
607
+ fee: Web3Number;
608
+ }>>;
600
609
  }
601
610
  /**
602
611
  * Represents the Vesu Rebalance Strategies.
package/dist/index.js CHANGED
@@ -13043,13 +13043,30 @@ var VesuRebalance = class _VesuRebalance extends BaseStrategy {
13043
13043
  * - finalPools: Array of pool information after rebalance
13044
13044
  * @throws Error if rebalance is not possible while maintaining constraints
13045
13045
  */
13046
- async getRebalancedPositions() {
13047
- const { data: pools } = await this.getPools();
13048
- const totalAssets = (await this.getTVL()).amount;
13046
+ async getRebalancedPositions(_pools) {
13047
+ logger.verbose(`VesuRebalance: getRebalancedPositions`);
13048
+ if (!_pools) {
13049
+ const { data: _pools2 } = await this.getPools();
13050
+ _pools = _pools2;
13051
+ }
13052
+ const feeDeductions = await this.getFee(_pools);
13053
+ logger.verbose(`VesuRebalance: feeDeductions: ${JSON.stringify(feeDeductions)}`);
13054
+ const pools = _pools.map((p) => {
13055
+ const fee = feeDeductions.find((f) => p.v_token.eq(f.vToken))?.fee || Web3Number.fromWei("0", this.decimals());
13056
+ logger.verbose(`FeeAdjustment: ${p.pool_id} => ${fee.toString()}, amt: ${p.amount.toString()}`);
13057
+ return {
13058
+ ...p,
13059
+ amount: p.amount.minus(fee)
13060
+ };
13061
+ });
13062
+ let totalAssets = (await this.getTVL()).amount;
13049
13063
  if (totalAssets.eq(0)) return {
13050
13064
  changes: [],
13051
13065
  finalPools: []
13052
13066
  };
13067
+ feeDeductions.forEach((f) => {
13068
+ totalAssets = totalAssets.minus(f.fee);
13069
+ });
13053
13070
  const sumPools = pools.reduce((acc, curr) => acc.plus(curr.amount.toString()), Web3Number.fromWei("0", this.decimals()));
13054
13071
  logger.verbose(`Sum of pools: ${sumPools.toString()}`);
13055
13072
  logger.verbose(`Total assets: ${totalAssets.toString()}`);
@@ -13087,8 +13104,8 @@ var VesuRebalance = class _VesuRebalance extends BaseStrategy {
13087
13104
  const sumChanges = changes.reduce((sum, c) => sum.plus(c.changeAmt.toString()), Web3Number.fromWei("0", this.decimals()));
13088
13105
  const sumFinal = changes.reduce((sum, c) => sum.plus(c.finalAmt.toString()), Web3Number.fromWei("0", this.decimals()));
13089
13106
  const hasChanges = changes.some((c) => !c.changeAmt.eq(0));
13090
- if (!sumChanges.eq(0)) throw new Error("Sum of changes must be zero");
13091
13107
  logger.verbose(`Sum of changes: ${sumChanges.toString()}`);
13108
+ if (!sumChanges.eq(0)) throw new Error("Sum of changes must be zero");
13092
13109
  logger.verbose(`Sum of final: ${sumFinal.toString()}`);
13093
13110
  logger.verbose(`Total assets: ${totalAssets.toString()}`);
13094
13111
  if (!sumFinal.eq(totalAssets.toString())) throw new Error("Sum of final amounts must equal total assets");
@@ -13192,6 +13209,49 @@ var VesuRebalance = class _VesuRebalance extends BaseStrategy {
13192
13209
  ])
13193
13210
  ];
13194
13211
  }
13212
+ /**
13213
+ * Calculates the fees deducted in different vTokens based on the current and previous state.
13214
+ * @param previousTotalSupply - The total supply of the strategy token before the transaction
13215
+ * @returns {Promise<Array<{ vToken: ContractAddr, fee: Web3Number }>>} Array of fees deducted in different vTokens
13216
+ */
13217
+ async getFee(allowedPools) {
13218
+ const assets = Web3Number.fromWei((await this.contract.total_assets()).toString(), this.asset().decimals);
13219
+ const totalSupply = Web3Number.fromWei((await this.contract.total_supply()).toString(), this.asset().decimals);
13220
+ const prevIndex = Web3Number.fromWei((await this.contract.get_previous_index()).toString(), 18);
13221
+ const currIndex = new Web3Number(1, 18).multipliedBy(assets).dividedBy(totalSupply);
13222
+ logger.verbose(`Previous index: ${prevIndex.toString()}`);
13223
+ logger.verbose(`Assets: ${assets.toString()}`);
13224
+ logger.verbose(`Total supply: ${totalSupply.toString()}`);
13225
+ logger.verbose(`Current index: ${currIndex.toNumber()}`);
13226
+ if (currIndex.lt(prevIndex)) {
13227
+ logger.verbose(`getFee::Current index is less than previous index, no fees to be deducted`);
13228
+ return [];
13229
+ }
13230
+ const indexDiff = currIndex.minus(prevIndex);
13231
+ logger.verbose(`Index diff: ${indexDiff.toString()}`);
13232
+ const numerator = totalSupply.multipliedBy(indexDiff).multipliedBy(this.metadata.additionalInfo.feeBps);
13233
+ const denominator = 1e4;
13234
+ let fee = numerator.dividedBy(denominator);
13235
+ logger.verbose(`Fee: ${fee.toString()}`);
13236
+ if (fee.lte(0)) {
13237
+ return [];
13238
+ }
13239
+ const fees = [];
13240
+ let remainingFee = fee.plus(Web3Number.fromWei("100", this.asset().decimals));
13241
+ for (const pool of allowedPools) {
13242
+ const vToken = pool.v_token;
13243
+ const balance = pool.amount;
13244
+ if (remainingFee.lte(balance)) {
13245
+ fees.push({ vToken, fee: remainingFee });
13246
+ break;
13247
+ } else {
13248
+ fees.push({ vToken, fee: Web3Number.fromWei(balance.toString(), 18) });
13249
+ remainingFee = remainingFee.minus(Web3Number.fromWei(balance.toString(), 18));
13250
+ }
13251
+ }
13252
+ logger.verbose(`Fees: ${JSON.stringify(fees)}`);
13253
+ return fees;
13254
+ }
13195
13255
  };
13196
13256
  var _description = "Automatically diversify {{TOKEN}} holdings into different Vesu pools while reducing risk and maximizing yield. Defi spring STRK Rewards are auto-compounded as well.";
13197
13257
  var _protocol = { name: "Vesu", logo: "https://static-assets-8zct.onrender.com/integrations/vesu/logo.png" };
package/dist/index.mjs CHANGED
@@ -12974,13 +12974,30 @@ var VesuRebalance = class _VesuRebalance extends BaseStrategy {
12974
12974
  * - finalPools: Array of pool information after rebalance
12975
12975
  * @throws Error if rebalance is not possible while maintaining constraints
12976
12976
  */
12977
- async getRebalancedPositions() {
12978
- const { data: pools } = await this.getPools();
12979
- const totalAssets = (await this.getTVL()).amount;
12977
+ async getRebalancedPositions(_pools) {
12978
+ logger.verbose(`VesuRebalance: getRebalancedPositions`);
12979
+ if (!_pools) {
12980
+ const { data: _pools2 } = await this.getPools();
12981
+ _pools = _pools2;
12982
+ }
12983
+ const feeDeductions = await this.getFee(_pools);
12984
+ logger.verbose(`VesuRebalance: feeDeductions: ${JSON.stringify(feeDeductions)}`);
12985
+ const pools = _pools.map((p) => {
12986
+ const fee = feeDeductions.find((f) => p.v_token.eq(f.vToken))?.fee || Web3Number.fromWei("0", this.decimals());
12987
+ logger.verbose(`FeeAdjustment: ${p.pool_id} => ${fee.toString()}, amt: ${p.amount.toString()}`);
12988
+ return {
12989
+ ...p,
12990
+ amount: p.amount.minus(fee)
12991
+ };
12992
+ });
12993
+ let totalAssets = (await this.getTVL()).amount;
12980
12994
  if (totalAssets.eq(0)) return {
12981
12995
  changes: [],
12982
12996
  finalPools: []
12983
12997
  };
12998
+ feeDeductions.forEach((f) => {
12999
+ totalAssets = totalAssets.minus(f.fee);
13000
+ });
12984
13001
  const sumPools = pools.reduce((acc, curr) => acc.plus(curr.amount.toString()), Web3Number.fromWei("0", this.decimals()));
12985
13002
  logger.verbose(`Sum of pools: ${sumPools.toString()}`);
12986
13003
  logger.verbose(`Total assets: ${totalAssets.toString()}`);
@@ -13018,8 +13035,8 @@ var VesuRebalance = class _VesuRebalance extends BaseStrategy {
13018
13035
  const sumChanges = changes.reduce((sum, c) => sum.plus(c.changeAmt.toString()), Web3Number.fromWei("0", this.decimals()));
13019
13036
  const sumFinal = changes.reduce((sum, c) => sum.plus(c.finalAmt.toString()), Web3Number.fromWei("0", this.decimals()));
13020
13037
  const hasChanges = changes.some((c) => !c.changeAmt.eq(0));
13021
- if (!sumChanges.eq(0)) throw new Error("Sum of changes must be zero");
13022
13038
  logger.verbose(`Sum of changes: ${sumChanges.toString()}`);
13039
+ if (!sumChanges.eq(0)) throw new Error("Sum of changes must be zero");
13023
13040
  logger.verbose(`Sum of final: ${sumFinal.toString()}`);
13024
13041
  logger.verbose(`Total assets: ${totalAssets.toString()}`);
13025
13042
  if (!sumFinal.eq(totalAssets.toString())) throw new Error("Sum of final amounts must equal total assets");
@@ -13123,6 +13140,49 @@ var VesuRebalance = class _VesuRebalance extends BaseStrategy {
13123
13140
  ])
13124
13141
  ];
13125
13142
  }
13143
+ /**
13144
+ * Calculates the fees deducted in different vTokens based on the current and previous state.
13145
+ * @param previousTotalSupply - The total supply of the strategy token before the transaction
13146
+ * @returns {Promise<Array<{ vToken: ContractAddr, fee: Web3Number }>>} Array of fees deducted in different vTokens
13147
+ */
13148
+ async getFee(allowedPools) {
13149
+ const assets = Web3Number.fromWei((await this.contract.total_assets()).toString(), this.asset().decimals);
13150
+ const totalSupply = Web3Number.fromWei((await this.contract.total_supply()).toString(), this.asset().decimals);
13151
+ const prevIndex = Web3Number.fromWei((await this.contract.get_previous_index()).toString(), 18);
13152
+ const currIndex = new Web3Number(1, 18).multipliedBy(assets).dividedBy(totalSupply);
13153
+ logger.verbose(`Previous index: ${prevIndex.toString()}`);
13154
+ logger.verbose(`Assets: ${assets.toString()}`);
13155
+ logger.verbose(`Total supply: ${totalSupply.toString()}`);
13156
+ logger.verbose(`Current index: ${currIndex.toNumber()}`);
13157
+ if (currIndex.lt(prevIndex)) {
13158
+ logger.verbose(`getFee::Current index is less than previous index, no fees to be deducted`);
13159
+ return [];
13160
+ }
13161
+ const indexDiff = currIndex.minus(prevIndex);
13162
+ logger.verbose(`Index diff: ${indexDiff.toString()}`);
13163
+ const numerator = totalSupply.multipliedBy(indexDiff).multipliedBy(this.metadata.additionalInfo.feeBps);
13164
+ const denominator = 1e4;
13165
+ let fee = numerator.dividedBy(denominator);
13166
+ logger.verbose(`Fee: ${fee.toString()}`);
13167
+ if (fee.lte(0)) {
13168
+ return [];
13169
+ }
13170
+ const fees = [];
13171
+ let remainingFee = fee.plus(Web3Number.fromWei("100", this.asset().decimals));
13172
+ for (const pool of allowedPools) {
13173
+ const vToken = pool.v_token;
13174
+ const balance = pool.amount;
13175
+ if (remainingFee.lte(balance)) {
13176
+ fees.push({ vToken, fee: remainingFee });
13177
+ break;
13178
+ } else {
13179
+ fees.push({ vToken, fee: Web3Number.fromWei(balance.toString(), 18) });
13180
+ remainingFee = remainingFee.minus(Web3Number.fromWei(balance.toString(), 18));
13181
+ }
13182
+ }
13183
+ logger.verbose(`Fees: ${JSON.stringify(fees)}`);
13184
+ return fees;
13185
+ }
13126
13186
  };
13127
13187
  var _description = "Automatically diversify {{TOKEN}} holdings into different Vesu pools while reducing risk and maximizing yield. Defi spring STRK Rewards are auto-compounded as well.";
13128
13188
  var _protocol = { name: "Vesu", logo: "https://static-assets-8zct.onrender.com/integrations/vesu/logo.png" };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strkfarm/sdk",
3
- "version": "1.0.35",
3
+ "version": "1.0.37",
4
4
  "description": "STRKFarm TS SDK (Meant for our internal use, but feel free to use it)",
5
5
  "typings": "dist/index.d.ts",
6
6
  "types": "dist/index.d.ts",
@@ -65,7 +65,6 @@
65
65
  "inquirer": "^10.1.2",
66
66
  "node-telegram-bot-api": "^0.66.0",
67
67
  "proxy-from-env": "^1.1.0",
68
- "puppeteer": "^24.4.0",
69
68
  "redis": "^4.7.0",
70
69
  "stacktrace-js": "^2.0.2",
71
70
  "starknet": "^6.11.0",
@@ -393,13 +393,34 @@ export class VesuRebalance extends BaseStrategy<SingleTokenInfo, SingleActionAmo
393
393
  * - finalPools: Array of pool information after rebalance
394
394
  * @throws Error if rebalance is not possible while maintaining constraints
395
395
  */
396
- async getRebalancedPositions() {
397
- const { data: pools } = await this.getPools();
398
- const totalAssets = (await this.getTVL()).amount;
396
+ async getRebalancedPositions(_pools?: PoolInfoFull[]) {
397
+ logger.verbose(`VesuRebalance: getRebalancedPositions`);
398
+ if (!_pools) {
399
+ const { data: _pools2 } = await this.getPools();
400
+ _pools = _pools2;
401
+ }
402
+ const feeDeductions = await this.getFee(_pools);
403
+ logger.verbose(`VesuRebalance: feeDeductions: ${JSON.stringify(feeDeductions)}`);
404
+
405
+ // remove fee from pools
406
+ const pools = _pools.map((p) => {
407
+ const fee = feeDeductions.find((f) => p.v_token.eq(f.vToken))?.fee || Web3Number.fromWei("0", this.decimals());
408
+ logger.verbose(`FeeAdjustment: ${p.pool_id} => ${fee.toString()}, amt: ${p.amount.toString()}`);
409
+ return {
410
+ ...p,
411
+ amount: p.amount.minus(fee),
412
+ }
413
+ });
414
+ let totalAssets = (await this.getTVL()).amount;
399
415
  if (totalAssets.eq(0)) return {
400
416
  changes: [],
401
417
  finalPools: [],
402
418
  }
419
+ // deduct fee from total assets
420
+ feeDeductions.forEach((f) => {
421
+ totalAssets = totalAssets.minus(f.fee);
422
+ });
423
+
403
424
 
404
425
  // assert sum of pools.amount <= totalAssets
405
426
  const sumPools = pools.reduce((acc, curr) => acc.plus(curr.amount.toString()), Web3Number.fromWei("0", this.decimals()));
@@ -449,8 +470,8 @@ export class VesuRebalance extends BaseStrategy<SingleTokenInfo, SingleActionAmo
449
470
  const sumFinal = changes.reduce((sum, c) => sum.plus(c.finalAmt.toString()), Web3Number.fromWei("0", this.decimals()));
450
471
  const hasChanges = changes.some(c => !c.changeAmt.eq(0));
451
472
 
452
- if (!sumChanges.eq(0)) throw new Error('Sum of changes must be zero');
453
473
  logger.verbose(`Sum of changes: ${sumChanges.toString()}`);
474
+ if (!sumChanges.eq(0)) throw new Error('Sum of changes must be zero');
454
475
  logger.verbose(`Sum of final: ${sumFinal.toString()}`);
455
476
  logger.verbose(`Total assets: ${totalAssets.toString()}`);
456
477
  if (!sumFinal.eq(totalAssets.toString())) throw new Error('Sum of final amounts must equal total assets');
@@ -565,6 +586,59 @@ export class VesuRebalance extends BaseStrategy<SingleTokenInfo, SingleActionAmo
565
586
  ])
566
587
  ]
567
588
  }
589
+
590
+ /**
591
+ * Calculates the fees deducted in different vTokens based on the current and previous state.
592
+ * @param previousTotalSupply - The total supply of the strategy token before the transaction
593
+ * @returns {Promise<Array<{ vToken: ContractAddr, fee: Web3Number }>>} Array of fees deducted in different vTokens
594
+ */
595
+ async getFee(allowedPools: Array<PoolInfoFull>): Promise<Array<{ vToken: ContractAddr, fee: Web3Number }>> {
596
+ const assets = Web3Number.fromWei((await this.contract.total_assets()).toString(), this.asset().decimals);
597
+ const totalSupply = Web3Number.fromWei((await this.contract.total_supply()).toString(), this.asset().decimals);
598
+ const prevIndex = Web3Number.fromWei((await this.contract.get_previous_index()).toString(), 18);
599
+ const currIndex = (new Web3Number(1, 18)).multipliedBy(assets).dividedBy(totalSupply);
600
+
601
+ logger.verbose(`Previous index: ${prevIndex.toString()}`);
602
+ logger.verbose(`Assets: ${assets.toString()}`);
603
+ logger.verbose(`Total supply: ${totalSupply.toString()}`);
604
+ logger.verbose(`Current index: ${currIndex.toNumber()}`);
605
+
606
+ if (currIndex.lt(prevIndex)) {
607
+ logger.verbose(`getFee::Current index is less than previous index, no fees to be deducted`);
608
+ return [];
609
+ }
610
+
611
+ const indexDiff = currIndex.minus(prevIndex);
612
+ logger.verbose(`Index diff: ${indexDiff.toString()}`);
613
+ const numerator = totalSupply.multipliedBy(indexDiff).multipliedBy(this.metadata.additionalInfo.feeBps);
614
+ const denominator = 10000;
615
+ let fee = numerator.dividedBy(denominator);
616
+ logger.verbose(`Fee: ${fee.toString()}`);
617
+
618
+ if (fee.lte(0)) {
619
+ return [];
620
+ }
621
+
622
+ const fees: Array<{ vToken: ContractAddr, fee: Web3Number }> = [];
623
+ let remainingFee = fee.plus(Web3Number.fromWei("100", this.asset().decimals));
624
+
625
+ for (const pool of allowedPools) {
626
+ const vToken = pool.v_token;
627
+ const balance = pool.amount;
628
+
629
+ if (remainingFee.lte(balance)) {
630
+ fees.push({ vToken, fee: remainingFee });
631
+ break;
632
+ } else {
633
+ fees.push({ vToken, fee: Web3Number.fromWei(balance.toString(), 18) });
634
+ remainingFee = remainingFee.minus(Web3Number.fromWei(balance.toString(), 18));
635
+ }
636
+ }
637
+
638
+ logger.verbose(`Fees: ${JSON.stringify(fees)}`);
639
+
640
+ return fees;
641
+ }
568
642
  }
569
643
 
570
644
  const _description = "Automatically diversify {{TOKEN}} holdings into different Vesu pools while reducing risk and maximizing yield. Defi spring STRK Rewards are auto-compounded as well."
@@ -1,36 +0,0 @@
1
- const puppeteer = require('puppeteer');
2
-
3
- export async function getAPIUsingHeadlessBrowser(
4
- url: string
5
- ) {
6
-
7
- try {
8
- // Launch a headless browser
9
- const browser = await puppeteer.launch({ headless: true });
10
- const page = await browser.newPage();
11
-
12
- // Set a realistic User-Agent to avoid suspicion
13
- await page.setUserAgent(
14
- 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36'
15
- );
16
-
17
- // Go to the API endpoint
18
- await page.goto(url, {
19
- waitUntil: 'networkidle2', // Wait until the page fully loads (including JS challenge)
20
- });
21
-
22
- // If the API returns JSON, extract it
23
- const jsonData = await page.evaluate(() => {
24
- const pre = document.querySelector('pre'); // Adjust based on how the API response is formatted
25
- return pre && pre.textContent ? JSON.parse(pre.textContent) : null;
26
- });
27
-
28
- // Clean up
29
- await browser.close();
30
- return jsonData;
31
- } catch (error) {
32
- console.error('Error:', error);
33
- return null;
34
- }
35
- }
36
-