@strkfarm/sdk 1.2.0 → 2.0.0-dev-strategy2.1

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.
Files changed (60) hide show
  1. package/dist/index.browser.global.js +76556 -66640
  2. package/dist/index.browser.mjs +34235 -24392
  3. package/dist/index.d.ts +2372 -793
  4. package/dist/index.js +31967 -22084
  5. package/dist/index.mjs +25545 -15719
  6. package/package.json +86 -76
  7. package/readme.md +56 -1
  8. package/src/data/extended-deposit.abi.json +3613 -0
  9. package/src/data/universal-vault.abi.json +135 -20
  10. package/src/dataTypes/_bignumber.ts +11 -0
  11. package/src/dataTypes/address.ts +7 -0
  12. package/src/global.ts +240 -193
  13. package/src/interfaces/common.tsx +26 -2
  14. package/src/modules/ExtendedWrapperSDk/index.ts +62 -0
  15. package/src/modules/ExtendedWrapperSDk/types.ts +311 -0
  16. package/src/modules/ExtendedWrapperSDk/wrapper.ts +448 -0
  17. package/src/modules/avnu.ts +17 -4
  18. package/src/modules/ekubo-quoter.ts +89 -10
  19. package/src/modules/erc20.ts +67 -21
  20. package/src/modules/harvests.ts +29 -43
  21. package/src/modules/index.ts +5 -1
  22. package/src/modules/lst-apr.ts +36 -0
  23. package/src/modules/midas.ts +159 -0
  24. package/src/modules/pricer-from-api.ts +2 -2
  25. package/src/modules/pricer-lst.ts +1 -1
  26. package/src/modules/pricer.ts +3 -38
  27. package/src/modules/token-market-data.ts +202 -0
  28. package/src/node/deployer.ts +1 -36
  29. package/src/strategies/autoCompounderStrk.ts +1 -1
  30. package/src/strategies/base-strategy.ts +20 -3
  31. package/src/strategies/btc-vesu-extended-strategy/core-strategy.tsx +1486 -0
  32. package/src/strategies/btc-vesu-extended-strategy/services/operationService.ts +32 -0
  33. package/src/strategies/btc-vesu-extended-strategy/utils/constants.ts +3 -0
  34. package/src/strategies/btc-vesu-extended-strategy/utils/helper.ts +396 -0
  35. package/src/strategies/btc-vesu-extended-strategy/utils/types.ts +5 -0
  36. package/src/strategies/ekubo-cl-vault.tsx +123 -306
  37. package/src/strategies/index.ts +7 -1
  38. package/src/strategies/svk-strategy.ts +247 -0
  39. package/src/strategies/universal-adapters/adapter-optimizer.ts +65 -0
  40. package/src/strategies/universal-adapters/adapter-utils.ts +5 -1
  41. package/src/strategies/universal-adapters/avnu-adapter.ts +432 -0
  42. package/src/strategies/universal-adapters/baseAdapter.ts +181 -153
  43. package/src/strategies/universal-adapters/common-adapter.ts +98 -77
  44. package/src/strategies/universal-adapters/extended-adapter.ts +976 -0
  45. package/src/strategies/universal-adapters/index.ts +7 -1
  46. package/src/strategies/universal-adapters/unused-balance-adapter.ts +109 -0
  47. package/src/strategies/universal-adapters/vesu-adapter.ts +230 -230
  48. package/src/strategies/universal-adapters/vesu-borrow-adapter.ts +1247 -0
  49. package/src/strategies/universal-adapters/vesu-multiply-adapter.ts +1306 -0
  50. package/src/strategies/universal-adapters/vesu-supply-only-adapter.ts +58 -51
  51. package/src/strategies/universal-lst-muliplier-strategy.tsx +716 -844
  52. package/src/strategies/universal-strategy.tsx +1103 -1181
  53. package/src/strategies/vesu-extended-strategy/services/operationService.ts +34 -0
  54. package/src/strategies/vesu-extended-strategy/types/transaction-metadata.ts +25 -0
  55. package/src/strategies/vesu-extended-strategy/utils/config.runtime.ts +77 -0
  56. package/src/strategies/vesu-extended-strategy/utils/constants.ts +50 -0
  57. package/src/strategies/vesu-extended-strategy/utils/helper.ts +367 -0
  58. package/src/strategies/vesu-extended-strategy/vesu-extended-strategy.tsx +1420 -0
  59. package/src/strategies/vesu-rebalance.tsx +16 -20
  60. package/src/utils/health-factor-math.ts +11 -5
@@ -4,7 +4,7 @@ import { SIMPLE_SANITIZER, SIMPLE_SANITIZER_V2, SIMPLE_SANITIZER_VESU_V1_DELEGAT
4
4
  import { ContractAddr, Web3Number } from "@/dataTypes";
5
5
  import { AdapterLeafType, BaseAdapter, GenerateCallFn, LeafAdapterFn, ManageCall } from "./baseAdapter";
6
6
  import VesuSingletonAbi from '../../data/vesu-singleton.abi.json';
7
- import { getMainnetConfig, IConfig, TokenInfo, VaultPosition } from "@/interfaces";
7
+ import { getMainnetConfig, IConfig, Protocols, TokenInfo, VaultPosition } from "@/interfaces";
8
8
  import { PricerBase } from "@/modules/pricerBase";
9
9
  import VesuPoolIDs from "@/data/vesu_pools.json";
10
10
  import { getAPIUsingHeadlessBrowser } from "@/node/headless";
@@ -15,6 +15,7 @@ import VesuMultiplyAbi from '@/data/vesu-multiple.abi.json';
15
15
  import { EkuboPoolKey } from "../ekubo-cl-vault";
16
16
  import VesuPoolV2Abi from '@/data/vesu-pool-v2.abi.json';
17
17
  import VesuExtensionAbi from '@/data/vesu-extension.abi.json';
18
+ import { CacheClass } from "@/utils/cacheClass";
18
19
 
19
20
  interface VesuPoolsInfo { pools: any[]; isErrorPoolsAPI: boolean };
20
21
 
@@ -233,7 +234,8 @@ export const VesuPools = {
233
234
  Genesis: ContractAddr.from('0x4dc4f0ca6ea4961e4c8373265bfd5317678f4fe374d76f3fd7135f57763bf28'),
234
235
  Re7xSTRK: ContractAddr.from('0x052fb52363939c3aa848f8f4ac28f0a51379f8d1b971d8444de25fbd77d8f161'),
235
236
  Re7xBTC: ContractAddr.from('0x3a8416bf20d036df5b1cf3447630a2e1cb04685f6b0c3a70ed7fb1473548ecf'),
236
- Prime: ContractAddr.from('0x451fe483d5921a2919ddd81d0de6696669bccdacd859f72a4fba7656b97c3b5'),
237
+ Re7USDCPrime: ContractAddr.from('0x02eef0c13b10b487ea5916b54c0a7f98ec43fb3048f60fdeedaf5b08f6f88aaf'),
238
+ Re7USDCCore: ContractAddr.from('0x03976cac265a12609934089004df458ea29c776d77da423c96dc761d09d24124'),
237
239
  }
238
240
 
239
241
  export const extensionMap: {[key: string]: ContractAddr} = {};
@@ -247,7 +249,7 @@ export function getVesuSingletonAddress(vesuPool: ContractAddr) {
247
249
  return {addr: vesuPool, isV2: true}; // Vesu v2
248
250
  }
249
251
 
250
- export class VesuAdapter extends BaseAdapter {
252
+ export class VesuAdapter extends CacheClass {
251
253
  VESU_MULTIPLY_V1 = ContractAddr.from('0x3630f1f8e5b8f5c4c4ae9b6620f8a570ae55cddebc0276c37550e7c118edf67');
252
254
  VESU_MULTIPLY = ContractAddr.from('0x027fef272d0a9a3844767c851a64b36fe4f0115141d81134baade95d2b27b781');
253
255
  config: VesuAdapterConfig;
@@ -259,184 +261,184 @@ export class VesuAdapter extends BaseAdapter {
259
261
  this.config = config;
260
262
  }
261
263
 
262
- getModifyPosition = (): AdapterLeafType<VesuModifyPositionCallParams> => {
263
- const positionData: bigint[] = [0n];
264
- const { addr, isV2 } = getVesuSingletonAddress(this.config.poolId);
265
- const commonPackedData: bigint[] = [
266
- toBigInt(this.config.collateral.address.toString()), // collateral
267
- toBigInt(this.config.debt.address.toString()), // debt
268
- toBigInt(this.config.vaultAllocator.toString()), // vault allocator
269
- ];
270
- const packedArguments: bigint[] = isV2 ? [
271
- ...commonPackedData
272
- ] : [
273
- toBigInt(this.config.poolId.toString()), // pool id
274
- ...commonPackedData,
275
- toBigInt(positionData.length),
276
- ...positionData
277
- ];
278
- const output = this.constructSimpleLeafData({
279
- id: this.config.id,
280
- target: addr,
281
- method: 'modify_position',
282
- packedArguments
283
- }, isV2 ? VESU_V2_MODIFY_POSITION_SANITIZER : SIMPLE_SANITIZER);
284
-
285
- return { leaf: output, callConstructor: this.getModifyPositionCall.bind(this) };
286
- }
287
-
288
- static getDefaultModifyPositionCallParams(params: {
289
- collateralAmount: Web3Number,
290
- isAddCollateral: boolean,
291
- debtAmount: Web3Number,
292
- isBorrow: boolean
293
- }) {
294
- return {
295
- collateralAmount: {
296
- amount_type: VesuAmountType.Delta,
297
- denomination: VesuAmountDenomination.Assets,
298
- value: {
299
- abs: params.collateralAmount,
300
- is_negative: !params.isAddCollateral
301
- }
302
- },
303
- debtAmount: {
304
- amount_type: VesuAmountType.Delta,
305
- denomination: VesuAmountDenomination.Assets,
306
- value: {
307
- abs: params.debtAmount,
308
- is_negative: !params.isBorrow
309
- }
310
- }
311
- }
312
- }
313
-
314
- getModifyPositionCall = (params: VesuModifyPositionCallParams): ManageCall => {
315
- // pub pool_id: felt252,
316
- // pub collateral_asset: ContractAddress,
317
- // pub debt_asset: ContractAddress,
318
- // pub user: ContractAddress,
319
- // pub collateral: Amount,
320
- // pub debt: Amount,
321
- // pub data: Span<felt252>,
322
- const _collateral = {
323
- amount_type: this.formatAmountTypeEnum(params.collateralAmount.amount_type),
324
- denomination: this.formatAmountDenominationEnum(params.collateralAmount.denomination),
325
- value: {
326
- abs: uint256.bnToUint256(params.collateralAmount.value.abs.toWei()),
327
- is_negative: params.collateralAmount.value.abs.isZero() ? false: params.collateralAmount.value.is_negative
328
- }
329
- };
330
- logger.verbose(`VesuAdapter::ConstructingModify::Collateral::${JSON.stringify(_collateral)}`)
331
- const _debt = {
332
- amount_type: this.formatAmountTypeEnum(params.debtAmount.amount_type),
333
- denomination: this.formatAmountDenominationEnum(params.debtAmount.denomination),
334
- value: {
335
- abs: uint256.bnToUint256(params.debtAmount.value.abs.toWei()),
336
- is_negative: params.debtAmount.value.abs.isZero() ? false: params.debtAmount.value.is_negative
337
- }
338
- };
339
- logger.verbose(`VesuAdapter::ConstructingModify::Debt::${JSON.stringify(_debt)}`)
340
- const { contract, isV2 } = this.getVesuSingletonContract(getMainnetConfig(), this.config.poolId);
341
- const call = contract.populate('modify_position', {
342
- params: isV2 ? {
343
- collateral_asset: this.config.collateral.address.toBigInt(),
344
- debt_asset: this.config.debt.address.toBigInt(),
345
- user: this.config.vaultAllocator.toBigInt(),
346
- collateral: _collateral,
347
- debt: _debt,
348
- } : {
349
- pool_id: this.config.poolId.toBigInt(),
350
- collateral_asset: this.config.collateral.address.toBigInt(),
351
- debt_asset: this.config.debt.address.toBigInt(),
352
- user: this.config.vaultAllocator.toBigInt(),
353
- collateral: _collateral,
354
- debt: _debt,
355
- data: [0]
356
- }
357
- });
358
- return {
359
- sanitizer: isV2 ? VESU_V2_MODIFY_POSITION_SANITIZER : SIMPLE_SANITIZER,
360
- call: {
361
- contractAddress: ContractAddr.from(contract.address),
362
- selector: hash.getSelectorFromName('modify_position'),
363
- calldata: [
364
- ...call.calldata as bigint[]
365
- ]
366
- }
367
- }
368
- }
369
-
370
- getMultiplyAdapter = (id: string): LeafAdapterFn<VesuMultiplyCallParams> => {
371
- return () => {
372
- const packedArguments: bigint[] = [
373
- toBigInt(this.config.poolId.toString()), // pool id
374
- toBigInt(this.config.collateral.address.toString()), // collateral
375
- toBigInt(this.config.debt.address.toString()), // debt
376
- toBigInt(this.config.vaultAllocator.toString()), // vault allocator
377
- ];
378
- const { isV2 } = getVesuSingletonAddress(this.config.poolId);
379
- const output = this.constructSimpleLeafData({
380
- id: id,
381
- target: isV2 ? this.VESU_MULTIPLY : this.VESU_MULTIPLY_V1,
382
- method: 'modify_lever',
383
- packedArguments
384
- }, SIMPLE_SANITIZER_V2);
385
-
386
- return { leaf: output, callConstructor: this.getMultiplyCall.bind(this) };
387
- }
388
- }
389
-
390
- getMultiplyCall = (params: VesuMultiplyCallParams): ManageCall => {
391
- const isIncrease = params.isIncrease;
392
- const multiplyParams = isIncrease ? params.increaseParams : params.decreaseParams;
393
- if (!multiplyParams) {
394
- throw new Error('Multiply params are not provided');
395
- }
396
- const { isV2 } = getVesuSingletonAddress(this.config.poolId);
397
- const VESU_MULTIPLY = isV2 ? this.VESU_MULTIPLY : this.VESU_MULTIPLY_V1;
398
- const multiplyContract = new Contract({abi: VesuMultiplyAbi, address: VESU_MULTIPLY.toString(), providerOrAccount: new RpcProvider({nodeUrl: ''})});
399
- const call = multiplyContract.populate('modify_lever', {
400
- modify_lever_params: getVesuMultiplyParams(isIncrease, {
401
- ...multiplyParams,
402
- user: this.config.vaultAllocator,
403
- pool_id: this.config.poolId,
404
- collateral_asset: this.config.collateral.address,
405
- debt_asset: this.config.debt.address,
406
- recipient: this.config.vaultAllocator
407
- })
408
- });
409
- return {
410
- sanitizer: SIMPLE_SANITIZER_V2,
411
- call: {
412
- contractAddress: VESU_MULTIPLY,
413
- selector: hash.getSelectorFromName('modify_lever'),
414
- calldata: [
415
- ...call.calldata as bigint[]
416
- ]
417
- }
418
- }
419
- }
420
-
421
- getVesuModifyDelegationAdapter = (id: string): LeafAdapterFn<VesuModifyDelegationCallParams> => {
422
- return () => {
423
- const { addr: VESU_SINGLETON, isV2 } = getVesuSingletonAddress(this.config.poolId);
424
- const packedArguments: bigint[] = isV2 ? [
425
- toBigInt(this.VESU_MULTIPLY.toString()), // v2
426
- ] : [
427
- this.config.poolId.toBigInt(),
428
- toBigInt(this.VESU_MULTIPLY_V1.toString()), // v1
429
- ];
430
- const output = this.constructSimpleLeafData({
431
- id: id,
432
- target: VESU_SINGLETON,
433
- method: 'modify_delegation',
434
- packedArguments
435
- }, isV2 ? SIMPLE_SANITIZER_V2 : SIMPLE_SANITIZER_VESU_V1_DELEGATIONS);
436
-
437
- return { leaf: output, callConstructor: this.getVesuModifyDelegationCall.bind(this) };
438
- }
439
- }
264
+ // getModifyPosition = (): AdapterLeafType<VesuModifyPositionCallParams> => {
265
+ // const positionData: bigint[] = [0n];
266
+ // const { addr, isV2 } = getVesuSingletonAddress(this.config.poolId);
267
+ // const commonPackedData: bigint[] = [
268
+ // toBigInt(this.config.collateral.address.toString()), // collateral
269
+ // toBigInt(this.config.debt.address.toString()), // debt
270
+ // toBigInt(this.config.vaultAllocator.toString()), // vault allocator
271
+ // ];
272
+ // const packedArguments: bigint[] = isV2 ? [
273
+ // ...commonPackedData
274
+ // ] : [
275
+ // toBigInt(this.config.poolId.toString()), // pool id
276
+ // ...commonPackedData,
277
+ // toBigInt(positionData.length),
278
+ // ...positionData
279
+ // ];
280
+ // const output = this.constructSimpleLeafData({
281
+ // id: this.config.id,
282
+ // target: addr,
283
+ // method: 'modify_position',
284
+ // packedArguments
285
+ // }, isV2 ? VESU_V2_MODIFY_POSITION_SANITIZER : SIMPLE_SANITIZER);
286
+
287
+ // return { leaf: output, callConstructor: this.getModifyPositionCall.bind(this) };
288
+ // }
289
+
290
+ // static getDefaultModifyPositionCallParams(params: {
291
+ // collateralAmount: Web3Number,
292
+ // isAddCollateral: boolean,
293
+ // debtAmount: Web3Number,
294
+ // isBorrow: boolean
295
+ // }) {
296
+ // return {
297
+ // collateralAmount: {
298
+ // amount_type: VesuAmountType.Delta,
299
+ // denomination: VesuAmountDenomination.Assets,
300
+ // value: {
301
+ // abs: params.collateralAmount,
302
+ // is_negative: !params.isAddCollateral
303
+ // }
304
+ // },
305
+ // debtAmount: {
306
+ // amount_type: VesuAmountType.Delta,
307
+ // denomination: VesuAmountDenomination.Assets,
308
+ // value: {
309
+ // abs: params.debtAmount,
310
+ // is_negative: !params.isBorrow
311
+ // }
312
+ // }
313
+ // }
314
+ // }
315
+
316
+ // getModifyPositionCall = (params: VesuModifyPositionCallParams): ManageCall => {
317
+ // // pub pool_id: felt252,
318
+ // // pub collateral_asset: ContractAddress,
319
+ // // pub debt_asset: ContractAddress,
320
+ // // pub user: ContractAddress,
321
+ // // pub collateral: Amount,
322
+ // // pub debt: Amount,
323
+ // // pub data: Span<felt252>,
324
+ // const _collateral = {
325
+ // amount_type: this.formatAmountTypeEnum(params.collateralAmount.amount_type),
326
+ // denomination: this.formatAmountDenominationEnum(params.collateralAmount.denomination),
327
+ // value: {
328
+ // abs: uint256.bnToUint256(params.collateralAmount.value.abs.toWei()),
329
+ // is_negative: params.collateralAmount.value.abs.isZero() ? false: params.collateralAmount.value.is_negative
330
+ // }
331
+ // };
332
+ // logger.verbose(`VesuAdapter::ConstructingModify::Collateral::${JSON.stringify(_collateral)}`)
333
+ // const _debt = {
334
+ // amount_type: this.formatAmountTypeEnum(params.debtAmount.amount_type),
335
+ // denomination: this.formatAmountDenominationEnum(params.debtAmount.denomination),
336
+ // value: {
337
+ // abs: uint256.bnToUint256(params.debtAmount.value.abs.toWei()),
338
+ // is_negative: params.debtAmount.value.abs.isZero() ? false: params.debtAmount.value.is_negative
339
+ // }
340
+ // };
341
+ // logger.verbose(`VesuAdapter::ConstructingModify::Debt::${JSON.stringify(_debt)}`)
342
+ // const { contract, isV2 } = this.getVesuSingletonContract(getMainnetConfig(), this.config.poolId);
343
+ // const call = contract.populate('modify_position', {
344
+ // params: isV2 ? {
345
+ // collateral_asset: this.config.collateral.address.toBigInt(),
346
+ // debt_asset: this.config.debt.address.toBigInt(),
347
+ // user: this.config.vaultAllocator.toBigInt(),
348
+ // collateral: _collateral,
349
+ // debt: _debt,
350
+ // } : {
351
+ // pool_id: this.config.poolId.toBigInt(),
352
+ // collateral_asset: this.config.collateral.address.toBigInt(),
353
+ // debt_asset: this.config.debt.address.toBigInt(),
354
+ // user: this.config.vaultAllocator.toBigInt(),
355
+ // collateral: _collateral,
356
+ // debt: _debt,
357
+ // data: [0]
358
+ // }
359
+ // });
360
+ // return {
361
+ // sanitizer: isV2 ? VESU_V2_MODIFY_POSITION_SANITIZER : SIMPLE_SANITIZER,
362
+ // call: {
363
+ // contractAddress: ContractAddr.from(contract.address),
364
+ // selector: hash.getSelectorFromName('modify_position'),
365
+ // calldata: [
366
+ // ...call.calldata as bigint[]
367
+ // ]
368
+ // }
369
+ // }
370
+ // }
371
+
372
+ // getMultiplyAdapter = (id: string): LeafAdapterFn<VesuMultiplyCallParams> => {
373
+ // return () => {
374
+ // const packedArguments: bigint[] = [
375
+ // toBigInt(this.config.poolId.toString()), // pool id
376
+ // toBigInt(this.config.collateral.address.toString()), // collateral
377
+ // toBigInt(this.config.debt.address.toString()), // debt
378
+ // toBigInt(this.config.vaultAllocator.toString()), // vault allocator
379
+ // ];
380
+ // const { isV2 } = getVesuSingletonAddress(this.config.poolId);
381
+ // const output = this.constructSimpleLeafData({
382
+ // id: id,
383
+ // target: isV2 ? this.VESU_MULTIPLY : this.VESU_MULTIPLY_V1,
384
+ // method: 'modify_lever',
385
+ // packedArguments
386
+ // }, SIMPLE_SANITIZER_V2);
387
+
388
+ // return { leaf: output, callConstructor: this.getMultiplyCall.bind(this) };
389
+ // }
390
+ // }
391
+
392
+ // getMultiplyCall = (params: VesuMultiplyCallParams): ManageCall => {
393
+ // const isIncrease = params.isIncrease;
394
+ // const multiplyParams = isIncrease ? params.increaseParams : params.decreaseParams;
395
+ // if (!multiplyParams) {
396
+ // throw new Error('Multiply params are not provided');
397
+ // }
398
+ // const { isV2 } = getVesuSingletonAddress(this.config.poolId);
399
+ // const VESU_MULTIPLY = isV2 ? this.VESU_MULTIPLY : this.VESU_MULTIPLY_V1;
400
+ // const multiplyContract = new Contract({abi: VesuMultiplyAbi, address: VESU_MULTIPLY.toString(), providerOrAccount: new RpcProvider({nodeUrl: ''})});
401
+ // const call = multiplyContract.populate('modify_lever', {
402
+ // modify_lever_params: getVesuMultiplyParams(isIncrease, {
403
+ // ...multiplyParams,
404
+ // user: this.config.vaultAllocator,
405
+ // pool_id: this.config.poolId,
406
+ // collateral_asset: this.config.collateral.address,
407
+ // debt_asset: this.config.debt.address,
408
+ // recipient: this.config.vaultAllocator
409
+ // })
410
+ // });
411
+ // return {
412
+ // sanitizer: SIMPLE_SANITIZER_V2,
413
+ // call: {
414
+ // contractAddress: VESU_MULTIPLY,
415
+ // selector: hash.getSelectorFromName('modify_lever'),
416
+ // calldata: [
417
+ // ...call.calldata as bigint[]
418
+ // ]
419
+ // }
420
+ // }
421
+ // }
422
+
423
+ // getVesuModifyDelegationAdapter = (id: string): LeafAdapterFn<VesuModifyDelegationCallParams> => {
424
+ // return () => {
425
+ // const { addr: VESU_SINGLETON, isV2 } = getVesuSingletonAddress(this.config.poolId);
426
+ // const packedArguments: bigint[] = isV2 ? [
427
+ // toBigInt(this.VESU_MULTIPLY.toString()), // v2
428
+ // ] : [
429
+ // this.config.poolId.toBigInt(),
430
+ // toBigInt(this.VESU_MULTIPLY_V1.toString()), // v1
431
+ // ];
432
+ // const output = this.constructSimpleLeafData({
433
+ // id: id,
434
+ // target: VESU_SINGLETON,
435
+ // method: 'modify_delegation',
436
+ // packedArguments
437
+ // }, isV2 ? SIMPLE_SANITIZER_V2 : SIMPLE_SANITIZER_VESU_V1_DELEGATIONS);
438
+
439
+ // return { leaf: output, callConstructor: this.getVesuModifyDelegationCall.bind(this) };
440
+ // }
441
+ // }
440
442
 
441
443
  getVesuModifyDelegationCall = (params: VesuModifyDelegationCallParams): ManageCall => {
442
444
  const VESU_SINGLETON = getVesuSingletonAddress(this.config.poolId).addr;
@@ -461,38 +463,38 @@ export class VesuAdapter extends BaseAdapter {
461
463
  }
462
464
  }
463
465
 
464
- getDefispringRewardsAdapter = (id: string): () => AdapterLeafType<VesuDefiSpringRewardsCallParams> => {
465
- return () => {
466
- const packedArguments: bigint[] = [];
467
- const output = {
468
- id: BigInt(num.getDecimalString(shortString.encodeShortString(id))),
469
- readableId: id,
470
- data: [
471
- SIMPLE_SANITIZER.toBigInt(), // sanitizer address
472
- VESU_REWARDS_CONTRACT.toBigInt(), // contract
473
- toBigInt(hash.getSelectorFromName("claim")), // method name
474
- BigInt(packedArguments.length),
475
- ...packedArguments
476
- ]
477
- };
478
- return { leaf: output, callConstructor: this.getDefiSpringClaimCall().bind(this) };
479
- }
480
- }
481
-
482
- getDefiSpringClaimCall = (): GenerateCallFn<VesuDefiSpringRewardsCallParams> => {
483
- return (params: VesuDefiSpringRewardsCallParams) => ({
484
- sanitizer: SIMPLE_SANITIZER,
485
- call: {
486
- contractAddress: VESU_REWARDS_CONTRACT,
487
- selector: hash.getSelectorFromName('claim'),
488
- calldata: [
489
- BigInt(params.amount.toWei()),
490
- BigInt(params.proofs.length),
491
- ...params.proofs.map(proof => BigInt(num.hexToDecimalString(proof)))
492
- ]
493
- }
494
- })
495
- }
466
+ // getDefispringRewardsAdapter = (id: string): () => AdapterLeafType<VesuDefiSpringRewardsCallParams> => {
467
+ // return () => {
468
+ // const packedArguments: bigint[] = [];
469
+ // const output = {
470
+ // id: BigInt(num.getDecimalString(shortString.encodeShortString(id))),
471
+ // readableId: id,
472
+ // data: [
473
+ // SIMPLE_SANITIZER.toBigInt(), // sanitizer address
474
+ // VESU_REWARDS_CONTRACT.toBigInt(), // contract
475
+ // toBigInt(hash.getSelectorFromName("claim")), // method name
476
+ // BigInt(packedArguments.length),
477
+ // ...packedArguments
478
+ // ]
479
+ // };
480
+ // return { leaf: output, callConstructor: this.getDefiSpringClaimCall().bind(this) };
481
+ // }
482
+ // }
483
+
484
+ // getDefiSpringClaimCall = (): GenerateCallFn<VesuDefiSpringRewardsCallParams> => {
485
+ // return (params: VesuDefiSpringRewardsCallParams) => ({
486
+ // sanitizer: SIMPLE_SANITIZER,
487
+ // call: {
488
+ // contractAddress: VESU_REWARDS_CONTRACT,
489
+ // selector: hash.getSelectorFromName('claim'),
490
+ // calldata: [
491
+ // BigInt(params.amount.toWei()),
492
+ // BigInt(params.proofs.length),
493
+ // ...params.proofs.map(proof => BigInt(num.hexToDecimalString(proof)))
494
+ // ]
495
+ // }
496
+ // })
497
+ // }
496
498
 
497
499
  formatAmountTypeEnum(amountType: VesuAmountType) {
498
500
  switch(amountType) {
@@ -588,8 +590,7 @@ export class VesuAdapter extends BaseAdapter {
588
590
  const assetConfig = isV2 ? _assetConfig : _assetConfig['0'];
589
591
  const timeDelta = assetConfig.last_updated;
590
592
  const lastFullUtilizationRate = assetConfig.last_full_utilization_rate;
591
- const debtSharePrice = Web3Number.fromWei(assetConfig.last_rate_accumulator, 18);
592
- const currentDebt = (new Web3Number((Number(assetConfig.total_nominal_debt) / 1e18).toFixed(9), asset.decimals)).multipliedBy(debtSharePrice);
593
+ const currentDebt = new Web3Number((Number(assetConfig.total_nominal_debt) / 1e18).toFixed(9), asset.decimals);
593
594
  const totalSupply = currentDebt.plus(Web3Number.fromWei(assetConfig.reserve, asset.decimals));
594
595
 
595
596
  const ratePerSecond = BigInt(Math.round(maxBorrowAPY / 365 / 24 / 60 / 60 * Number(SCALE)));
@@ -598,11 +599,11 @@ export class VesuAdapter extends BaseAdapter {
598
599
 
599
600
  const maxDebtToHave = totalSupply.multipliedBy(Number(maxUtilisation) / 1e18);
600
601
  logger.verbose(`${asset.symbol}::VesuAdapter::getMaxBorrowableByInterestRate currentDebt: ${currentDebt.toString()}, maxDebtToHave: ${maxDebtToHave.toString()}`);
601
- return {maxDebtToHave: maxDebtToHave.minus(currentDebt), currentDebt: currentDebt, totalSupply: totalSupply};
602
+ return maxDebtToHave.minus(currentDebt);
602
603
  }
603
604
 
604
605
  async getLTVConfig(config: IConfig, blockNumber: BlockIdentifier = 'latest') {
605
- const CACHE_KEY = `ltv_config_${blockNumber}`;
606
+ const CACHE_KEY = `ltv_config_${blockNumber}_${this.config.poolId.shortString()}_${this.config.collateral.symbol}_${this.config.debt.symbol}`;
606
607
  const cacheData = this.getCache<number>(CACHE_KEY);
607
608
  if (cacheData) {
608
609
  return cacheData as number;
@@ -628,11 +629,11 @@ export class VesuAdapter extends BaseAdapter {
628
629
  throw new Error('Pricer is not initialized');
629
630
  }
630
631
  // { '0': { collateral_shares: 0n, nominal_debt: 0n }, '1': 0n, '2': 0n }
631
- const CACHE_KEY = `positions_${blockNumber}`;
632
- const cacheData = this.getCache<VaultPosition[]>(CACHE_KEY);
633
- if (cacheData) {
634
- return cacheData;
635
- }
632
+ // const CACHE_KEY = `positions_${blockNumber}_${this.config.poolId.shortString()}_${this.config.collateral.symbol}_${this.config.debt.symbol}`;
633
+ // const cacheData = this.getCache<VaultPosition[]>(CACHE_KEY);
634
+ // if (cacheData) {
635
+ // return cacheData;
636
+ // }
636
637
 
637
638
  const { contract, isV2} = this.getVesuSingletonContract(config, this.config.poolId);
638
639
  const output: any = await contract
@@ -642,8 +643,7 @@ export class VesuAdapter extends BaseAdapter {
642
643
  this.config.debt.address.address,
643
644
  this.config.vaultAllocator.address
644
645
  ], { blockIdentifier: blockNumber });
645
-
646
- console.log(output)
646
+
647
647
  const token1Price = await this.pricer.getPrice(this.config.collateral.symbol);
648
648
  const token2Price = await this.pricer.getPrice(this.config.debt.symbol);
649
649
  logger.verbose(`VesuAdapter::getPositions token1Price: ${token1Price.price}, token2Price: ${token2Price.price}`);
@@ -661,8 +661,8 @@ export class VesuAdapter extends BaseAdapter {
661
661
  usdValue: debtAmount.multipliedBy(token2Price.price).toNumber(),
662
662
  remarks: "Debt"
663
663
  }];
664
- this.setCache(CACHE_KEY, value, 60000); // ttl: 1min
665
- return value;
664
+ //this.setCache(CACHE_KEY, value, 60000); // ttl: 1min
665
+ return value.map(v => ({ ...v, protocol: Protocols.VESU }));
666
666
  }
667
667
 
668
668
  async getCollateralization(config: IConfig, blockNumber: BlockIdentifier = 'latest'): Promise<Omit<VaultPosition, 'amount'>[]> {
@@ -670,7 +670,7 @@ export class VesuAdapter extends BaseAdapter {
670
670
  throw new Error('Pricer is not initialized');
671
671
  }
672
672
  // { '0': bool, '1': 0n, '2': 0n }
673
- const CACHE_KEY = `collateralization_${blockNumber}`;
673
+ const CACHE_KEY = `collateralization_${blockNumber}_${this.config.poolId.shortString()}_${this.config.collateral.symbol}_${this.config.debt.symbol}`;
674
674
  const cacheData = this.getCache<Omit<VaultPosition, 'amount'>[]>(CACHE_KEY);
675
675
  if (cacheData) {
676
676
  return cacheData;
@@ -698,7 +698,7 @@ export class VesuAdapter extends BaseAdapter {
698
698
  remarks: "Debt"
699
699
  }];
700
700
  this.setCache(CACHE_KEY, value, 60000); // ttl: 1min
701
- return value;
701
+ return value.map(v => ({ ...v, protocol: Protocols.VESU }));
702
702
  }
703
703
 
704
704
  async getAssetPrices() {
@@ -711,11 +711,11 @@ export class VesuAdapter extends BaseAdapter {
711
711
 
712
712
  const collateralTokenAmount = positions[0].amount;
713
713
  const collateralUSDAmount = collateralization[0].usdValue;
714
- const collateralPrice = collateralUSDAmount / collateralTokenAmount.toNumber();
714
+ const collateralPrice = await this.pricer?.getPrice(this.config.collateral.symbol);
715
715
 
716
716
  const debtTokenAmount = positions[1].amount;
717
717
  const debtUSDAmount = collateralization[1].usdValue;
718
- const debtPrice = debtUSDAmount / debtTokenAmount.toNumber();
718
+ const debtPrice = await this.pricer?.getPrice(this.config.debt.symbol);
719
719
 
720
720
  return {
721
721
  collateralTokenAmount,