@strkfarm/sdk 1.1.72 → 2.0.0-dev.10

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 (51) hide show
  1. package/dist/index.browser.global.js +58203 -50929
  2. package/dist/index.browser.mjs +26163 -18879
  3. package/dist/index.d.ts +2020 -798
  4. package/dist/index.js +30543 -23235
  5. package/dist/index.mjs +30397 -23130
  6. package/package.json +80 -76
  7. package/src/data/extended-deposit.abi.json +3613 -0
  8. package/src/data/universal-vault.abi.json +135 -20
  9. package/src/dataTypes/address.ts +7 -0
  10. package/src/global.ts +240 -193
  11. package/src/interfaces/common.tsx +26 -2
  12. package/src/modules/ExtendedWrapperSDk/index.ts +62 -0
  13. package/src/modules/ExtendedWrapperSDk/types.ts +311 -0
  14. package/src/modules/ExtendedWrapperSDk/wrapper.ts +395 -0
  15. package/src/modules/avnu.ts +17 -4
  16. package/src/modules/ekubo-quoter.ts +87 -10
  17. package/src/modules/erc20.ts +67 -21
  18. package/src/modules/harvests.ts +29 -43
  19. package/src/modules/index.ts +5 -1
  20. package/src/modules/lst-apr.ts +36 -0
  21. package/src/modules/midas.ts +159 -0
  22. package/src/modules/pricer-from-api.ts +2 -2
  23. package/src/modules/pricer-lst.ts +1 -1
  24. package/src/modules/pricer.ts +3 -38
  25. package/src/modules/token-market-data.ts +202 -0
  26. package/src/node/deployer.ts +1 -36
  27. package/src/strategies/autoCompounderStrk.ts +1 -1
  28. package/src/strategies/base-strategy.ts +20 -3
  29. package/src/strategies/ekubo-cl-vault.tsx +123 -306
  30. package/src/strategies/index.ts +4 -1
  31. package/src/strategies/svk-strategy.ts +247 -0
  32. package/src/strategies/universal-adapters/adapter-optimizer.ts +65 -0
  33. package/src/strategies/universal-adapters/adapter-utils.ts +5 -1
  34. package/src/strategies/universal-adapters/avnu-adapter.ts +415 -0
  35. package/src/strategies/universal-adapters/baseAdapter.ts +181 -153
  36. package/src/strategies/universal-adapters/common-adapter.ts +98 -77
  37. package/src/strategies/universal-adapters/extended-adapter.ts +972 -0
  38. package/src/strategies/universal-adapters/index.ts +5 -1
  39. package/src/strategies/universal-adapters/unused-balance-adapter.ts +109 -0
  40. package/src/strategies/universal-adapters/vesu-adapter.ts +221 -221
  41. package/src/strategies/universal-adapters/vesu-multiply-adapter.ts +1306 -0
  42. package/src/strategies/universal-adapters/vesu-supply-only-adapter.ts +58 -51
  43. package/src/strategies/universal-lst-muliplier-strategy.tsx +716 -844
  44. package/src/strategies/universal-strategy.tsx +1103 -1180
  45. package/src/strategies/vesu-extended-strategy/services/operationService.ts +34 -0
  46. package/src/strategies/vesu-extended-strategy/utils/config.runtime.ts +77 -0
  47. package/src/strategies/vesu-extended-strategy/utils/constants.ts +50 -0
  48. package/src/strategies/vesu-extended-strategy/utils/helper.ts +370 -0
  49. package/src/strategies/vesu-extended-strategy/vesu-extended-strategy.tsx +1410 -0
  50. package/src/strategies/vesu-rebalance.tsx +16 -19
  51. package/src/utils/health-factor-math.ts +11 -5
@@ -1,4 +1,8 @@
1
1
  export * from "./baseAdapter";
2
2
  export * from "./common-adapter";
3
3
  export * from "./vesu-adapter";
4
- export * from "./adapter-utils";
4
+ export * from "./vesu-supply-only-adapter";
5
+ export * from "./vesu-multiply-adapter";
6
+ export * from "./extended-adapter";
7
+ export * from "./adapter-utils";
8
+ export * from "./unused-balance-adapter";
@@ -0,0 +1,109 @@
1
+ import { ContractAddr, Web3Number } from "@/dataTypes";
2
+ import { APYType, BaseAdapter, BaseAdapterConfig, DepositParams, ManageCall, PositionAmount, PositionAPY, PositionInfo, SupportedPosition, WithdrawParams } from "./baseAdapter";
3
+ import { Contract, uint256 } from "starknet";
4
+ import erc20Abi from "@/data/erc20.abi.json";
5
+ import { ERC20, TokenMarketData } from "@/modules";
6
+ import { Protocols } from "@/interfaces";
7
+
8
+ export interface UnusedBalanceAdapterConfig extends BaseAdapterConfig {}
9
+
10
+ export class UnusedBalanceAdapter extends BaseAdapter<DepositParams, WithdrawParams> {
11
+ readonly config: UnusedBalanceAdapterConfig;
12
+ readonly tokenMarketData: TokenMarketData;
13
+
14
+ constructor(config: UnusedBalanceAdapterConfig) {
15
+ super(config, UnusedBalanceAdapter.name, Protocols.NONE);
16
+ this.config = config;
17
+ this.tokenMarketData = new TokenMarketData(this.config.pricer, this.config.networkConfig);
18
+ }
19
+
20
+ protected async getAPY(_supportedPosition: SupportedPosition): Promise<PositionAPY> {
21
+ const isSupported = this.tokenMarketData.isAPYSupported(this.config.baseToken);
22
+ const apy = isSupported ? await this.tokenMarketData.getAPY(this.config.baseToken) : 0;
23
+ return { apy: apy, type: isSupported ? APYType.LST : APYType.BASE };
24
+ }
25
+
26
+ protected async getPosition(supportedPosition: SupportedPosition): Promise<PositionAmount> {
27
+ try {
28
+ const balance = await (new ERC20(this.config.networkConfig)).balanceOf(supportedPosition.asset.address, this.config.vaultAllocator.address, supportedPosition.asset.decimals);
29
+ return {
30
+ amount: balance,
31
+ remarks: "Unused balance"
32
+ }
33
+ } catch (_e) {
34
+ throw new Error(`${UnusedBalanceAdapter.name}: Failed to get position for ${supportedPosition.asset.symbol}`);
35
+ }
36
+ }
37
+
38
+ async maxDeposit(amount?: Web3Number): Promise<PositionInfo> {
39
+ const baseToken = this.config.baseToken;
40
+ if (!amount) {
41
+ const infinite = new Web3Number('999999999999999999999999999', baseToken.decimals);
42
+ return {
43
+ tokenInfo: baseToken,
44
+ amount: infinite,
45
+ usdValue: Number.POSITIVE_INFINITY,
46
+ remarks: "Max deposit (infinity)",
47
+ apy: await this.getAPY({ asset: baseToken, isDebt: false }),
48
+ protocol: this.protocol
49
+ };
50
+ }
51
+ const usdValue = await this.getUSDValue(baseToken, amount);
52
+ return {
53
+ tokenInfo: baseToken,
54
+ amount,
55
+ usdValue,
56
+ remarks: "Deposit amount",
57
+ apy: await this.getAPY({ asset: baseToken, isDebt: false }),
58
+ protocol: this.protocol
59
+ };
60
+ }
61
+
62
+ async maxWithdraw(): Promise<PositionInfo> {
63
+ const baseToken = this.config.baseToken;
64
+ const current = await this.getPosition({ asset: baseToken, isDebt: false });
65
+ const usdValue = await this.getUSDValue(baseToken, current.amount);
66
+ return {
67
+ tokenInfo: baseToken,
68
+ amount: current.amount,
69
+ usdValue,
70
+ remarks: "Max withdraw",
71
+ apy: await this.getAPY({ asset: baseToken, isDebt: false }),
72
+ protocol: this.protocol
73
+ };
74
+ }
75
+
76
+ protected _getDepositLeaf(): {
77
+ target: ContractAddr,
78
+ method: string,
79
+ packedArguments: bigint[];
80
+ sanitizer: ContractAddr,
81
+ id: string
82
+ }[] {
83
+ return [];
84
+ }
85
+
86
+ protected _getWithdrawLeaf(): {
87
+ target: ContractAddr,
88
+ method: string,
89
+ packedArguments: bigint[];
90
+ sanitizer: ContractAddr,
91
+ id: string
92
+ }[] {
93
+ return [];
94
+ }
95
+
96
+ async getHealthFactor(): Promise<number> {
97
+ return Promise.resolve(10);
98
+ }
99
+
100
+ getDepositCall(params: DepositParams): Promise<ManageCall[]> {
101
+ return Promise.resolve([]);
102
+ }
103
+
104
+ getWithdrawCall(params: WithdrawParams): Promise<ManageCall[]> {
105
+ return Promise.resolve([]);
106
+ }
107
+ }
108
+
109
+
@@ -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,7 @@ 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'),
237
238
  }
238
239
 
239
240
  export const extensionMap: {[key: string]: ContractAddr} = {};
@@ -247,7 +248,7 @@ export function getVesuSingletonAddress(vesuPool: ContractAddr) {
247
248
  return {addr: vesuPool, isV2: true}; // Vesu v2
248
249
  }
249
250
 
250
- export class VesuAdapter extends BaseAdapter {
251
+ export class VesuAdapter extends CacheClass {
251
252
  VESU_MULTIPLY_V1 = ContractAddr.from('0x3630f1f8e5b8f5c4c4ae9b6620f8a570ae55cddebc0276c37550e7c118edf67');
252
253
  VESU_MULTIPLY = ContractAddr.from('0x027fef272d0a9a3844767c851a64b36fe4f0115141d81134baade95d2b27b781');
253
254
  config: VesuAdapterConfig;
@@ -259,184 +260,184 @@ export class VesuAdapter extends BaseAdapter {
259
260
  this.config = config;
260
261
  }
261
262
 
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
- }
263
+ // getModifyPosition = (): AdapterLeafType<VesuModifyPositionCallParams> => {
264
+ // const positionData: bigint[] = [0n];
265
+ // const { addr, isV2 } = getVesuSingletonAddress(this.config.poolId);
266
+ // const commonPackedData: bigint[] = [
267
+ // toBigInt(this.config.collateral.address.toString()), // collateral
268
+ // toBigInt(this.config.debt.address.toString()), // debt
269
+ // toBigInt(this.config.vaultAllocator.toString()), // vault allocator
270
+ // ];
271
+ // const packedArguments: bigint[] = isV2 ? [
272
+ // ...commonPackedData
273
+ // ] : [
274
+ // toBigInt(this.config.poolId.toString()), // pool id
275
+ // ...commonPackedData,
276
+ // toBigInt(positionData.length),
277
+ // ...positionData
278
+ // ];
279
+ // const output = this.constructSimpleLeafData({
280
+ // id: this.config.id,
281
+ // target: addr,
282
+ // method: 'modify_position',
283
+ // packedArguments
284
+ // }, isV2 ? VESU_V2_MODIFY_POSITION_SANITIZER : SIMPLE_SANITIZER);
285
+
286
+ // return { leaf: output, callConstructor: this.getModifyPositionCall.bind(this) };
287
+ // }
288
+
289
+ // static getDefaultModifyPositionCallParams(params: {
290
+ // collateralAmount: Web3Number,
291
+ // isAddCollateral: boolean,
292
+ // debtAmount: Web3Number,
293
+ // isBorrow: boolean
294
+ // }) {
295
+ // return {
296
+ // collateralAmount: {
297
+ // amount_type: VesuAmountType.Delta,
298
+ // denomination: VesuAmountDenomination.Assets,
299
+ // value: {
300
+ // abs: params.collateralAmount,
301
+ // is_negative: !params.isAddCollateral
302
+ // }
303
+ // },
304
+ // debtAmount: {
305
+ // amount_type: VesuAmountType.Delta,
306
+ // denomination: VesuAmountDenomination.Assets,
307
+ // value: {
308
+ // abs: params.debtAmount,
309
+ // is_negative: !params.isBorrow
310
+ // }
311
+ // }
312
+ // }
313
+ // }
314
+
315
+ // getModifyPositionCall = (params: VesuModifyPositionCallParams): ManageCall => {
316
+ // // pub pool_id: felt252,
317
+ // // pub collateral_asset: ContractAddress,
318
+ // // pub debt_asset: ContractAddress,
319
+ // // pub user: ContractAddress,
320
+ // // pub collateral: Amount,
321
+ // // pub debt: Amount,
322
+ // // pub data: Span<felt252>,
323
+ // const _collateral = {
324
+ // amount_type: this.formatAmountTypeEnum(params.collateralAmount.amount_type),
325
+ // denomination: this.formatAmountDenominationEnum(params.collateralAmount.denomination),
326
+ // value: {
327
+ // abs: uint256.bnToUint256(params.collateralAmount.value.abs.toWei()),
328
+ // is_negative: params.collateralAmount.value.abs.isZero() ? false: params.collateralAmount.value.is_negative
329
+ // }
330
+ // };
331
+ // logger.verbose(`VesuAdapter::ConstructingModify::Collateral::${JSON.stringify(_collateral)}`)
332
+ // const _debt = {
333
+ // amount_type: this.formatAmountTypeEnum(params.debtAmount.amount_type),
334
+ // denomination: this.formatAmountDenominationEnum(params.debtAmount.denomination),
335
+ // value: {
336
+ // abs: uint256.bnToUint256(params.debtAmount.value.abs.toWei()),
337
+ // is_negative: params.debtAmount.value.abs.isZero() ? false: params.debtAmount.value.is_negative
338
+ // }
339
+ // };
340
+ // logger.verbose(`VesuAdapter::ConstructingModify::Debt::${JSON.stringify(_debt)}`)
341
+ // const { contract, isV2 } = this.getVesuSingletonContract(getMainnetConfig(), this.config.poolId);
342
+ // const call = contract.populate('modify_position', {
343
+ // params: isV2 ? {
344
+ // collateral_asset: this.config.collateral.address.toBigInt(),
345
+ // debt_asset: this.config.debt.address.toBigInt(),
346
+ // user: this.config.vaultAllocator.toBigInt(),
347
+ // collateral: _collateral,
348
+ // debt: _debt,
349
+ // } : {
350
+ // pool_id: this.config.poolId.toBigInt(),
351
+ // collateral_asset: this.config.collateral.address.toBigInt(),
352
+ // debt_asset: this.config.debt.address.toBigInt(),
353
+ // user: this.config.vaultAllocator.toBigInt(),
354
+ // collateral: _collateral,
355
+ // debt: _debt,
356
+ // data: [0]
357
+ // }
358
+ // });
359
+ // return {
360
+ // sanitizer: isV2 ? VESU_V2_MODIFY_POSITION_SANITIZER : SIMPLE_SANITIZER,
361
+ // call: {
362
+ // contractAddress: ContractAddr.from(contract.address),
363
+ // selector: hash.getSelectorFromName('modify_position'),
364
+ // calldata: [
365
+ // ...call.calldata as bigint[]
366
+ // ]
367
+ // }
368
+ // }
369
+ // }
370
+
371
+ // getMultiplyAdapter = (id: string): LeafAdapterFn<VesuMultiplyCallParams> => {
372
+ // return () => {
373
+ // const packedArguments: bigint[] = [
374
+ // toBigInt(this.config.poolId.toString()), // pool id
375
+ // toBigInt(this.config.collateral.address.toString()), // collateral
376
+ // toBigInt(this.config.debt.address.toString()), // debt
377
+ // toBigInt(this.config.vaultAllocator.toString()), // vault allocator
378
+ // ];
379
+ // const { isV2 } = getVesuSingletonAddress(this.config.poolId);
380
+ // const output = this.constructSimpleLeafData({
381
+ // id: id,
382
+ // target: isV2 ? this.VESU_MULTIPLY : this.VESU_MULTIPLY_V1,
383
+ // method: 'modify_lever',
384
+ // packedArguments
385
+ // }, SIMPLE_SANITIZER_V2);
386
+
387
+ // return { leaf: output, callConstructor: this.getMultiplyCall.bind(this) };
388
+ // }
389
+ // }
390
+
391
+ // getMultiplyCall = (params: VesuMultiplyCallParams): ManageCall => {
392
+ // const isIncrease = params.isIncrease;
393
+ // const multiplyParams = isIncrease ? params.increaseParams : params.decreaseParams;
394
+ // if (!multiplyParams) {
395
+ // throw new Error('Multiply params are not provided');
396
+ // }
397
+ // const { isV2 } = getVesuSingletonAddress(this.config.poolId);
398
+ // const VESU_MULTIPLY = isV2 ? this.VESU_MULTIPLY : this.VESU_MULTIPLY_V1;
399
+ // const multiplyContract = new Contract({abi: VesuMultiplyAbi, address: VESU_MULTIPLY.toString(), providerOrAccount: new RpcProvider({nodeUrl: ''})});
400
+ // const call = multiplyContract.populate('modify_lever', {
401
+ // modify_lever_params: getVesuMultiplyParams(isIncrease, {
402
+ // ...multiplyParams,
403
+ // user: this.config.vaultAllocator,
404
+ // pool_id: this.config.poolId,
405
+ // collateral_asset: this.config.collateral.address,
406
+ // debt_asset: this.config.debt.address,
407
+ // recipient: this.config.vaultAllocator
408
+ // })
409
+ // });
410
+ // return {
411
+ // sanitizer: SIMPLE_SANITIZER_V2,
412
+ // call: {
413
+ // contractAddress: VESU_MULTIPLY,
414
+ // selector: hash.getSelectorFromName('modify_lever'),
415
+ // calldata: [
416
+ // ...call.calldata as bigint[]
417
+ // ]
418
+ // }
419
+ // }
420
+ // }
421
+
422
+ // getVesuModifyDelegationAdapter = (id: string): LeafAdapterFn<VesuModifyDelegationCallParams> => {
423
+ // return () => {
424
+ // const { addr: VESU_SINGLETON, isV2 } = getVesuSingletonAddress(this.config.poolId);
425
+ // const packedArguments: bigint[] = isV2 ? [
426
+ // toBigInt(this.VESU_MULTIPLY.toString()), // v2
427
+ // ] : [
428
+ // this.config.poolId.toBigInt(),
429
+ // toBigInt(this.VESU_MULTIPLY_V1.toString()), // v1
430
+ // ];
431
+ // const output = this.constructSimpleLeafData({
432
+ // id: id,
433
+ // target: VESU_SINGLETON,
434
+ // method: 'modify_delegation',
435
+ // packedArguments
436
+ // }, isV2 ? SIMPLE_SANITIZER_V2 : SIMPLE_SANITIZER_VESU_V1_DELEGATIONS);
437
+
438
+ // return { leaf: output, callConstructor: this.getVesuModifyDelegationCall.bind(this) };
439
+ // }
440
+ // }
440
441
 
441
442
  getVesuModifyDelegationCall = (params: VesuModifyDelegationCallParams): ManageCall => {
442
443
  const VESU_SINGLETON = getVesuSingletonAddress(this.config.poolId).addr;
@@ -461,38 +462,38 @@ export class VesuAdapter extends BaseAdapter {
461
462
  }
462
463
  }
463
464
 
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
- }
465
+ // getDefispringRewardsAdapter = (id: string): () => AdapterLeafType<VesuDefiSpringRewardsCallParams> => {
466
+ // return () => {
467
+ // const packedArguments: bigint[] = [];
468
+ // const output = {
469
+ // id: BigInt(num.getDecimalString(shortString.encodeShortString(id))),
470
+ // readableId: id,
471
+ // data: [
472
+ // SIMPLE_SANITIZER.toBigInt(), // sanitizer address
473
+ // VESU_REWARDS_CONTRACT.toBigInt(), // contract
474
+ // toBigInt(hash.getSelectorFromName("claim")), // method name
475
+ // BigInt(packedArguments.length),
476
+ // ...packedArguments
477
+ // ]
478
+ // };
479
+ // return { leaf: output, callConstructor: this.getDefiSpringClaimCall().bind(this) };
480
+ // }
481
+ // }
482
+
483
+ // getDefiSpringClaimCall = (): GenerateCallFn<VesuDefiSpringRewardsCallParams> => {
484
+ // return (params: VesuDefiSpringRewardsCallParams) => ({
485
+ // sanitizer: SIMPLE_SANITIZER,
486
+ // call: {
487
+ // contractAddress: VESU_REWARDS_CONTRACT,
488
+ // selector: hash.getSelectorFromName('claim'),
489
+ // calldata: [
490
+ // BigInt(params.amount.toWei()),
491
+ // BigInt(params.proofs.length),
492
+ // ...params.proofs.map(proof => BigInt(num.hexToDecimalString(proof)))
493
+ // ]
494
+ // }
495
+ // })
496
+ // }
496
497
 
497
498
  formatAmountTypeEnum(amountType: VesuAmountType) {
498
499
  switch(amountType) {
@@ -588,8 +589,7 @@ export class VesuAdapter extends BaseAdapter {
588
589
  const assetConfig = isV2 ? _assetConfig : _assetConfig['0'];
589
590
  const timeDelta = assetConfig.last_updated;
590
591
  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);
592
+ const currentDebt = new Web3Number((Number(assetConfig.total_nominal_debt) / 1e18).toFixed(9), asset.decimals);
593
593
  const totalSupply = currentDebt.plus(Web3Number.fromWei(assetConfig.reserve, asset.decimals));
594
594
 
595
595
  const ratePerSecond = BigInt(Math.round(maxBorrowAPY / 365 / 24 / 60 / 60 * Number(SCALE)));
@@ -598,11 +598,11 @@ export class VesuAdapter extends BaseAdapter {
598
598
 
599
599
  const maxDebtToHave = totalSupply.multipliedBy(Number(maxUtilisation) / 1e18);
600
600
  logger.verbose(`${asset.symbol}::VesuAdapter::getMaxBorrowableByInterestRate currentDebt: ${currentDebt.toString()}, maxDebtToHave: ${maxDebtToHave.toString()}`);
601
- return {maxDebtToHave: maxDebtToHave.minus(currentDebt), currentDebt: currentDebt, totalSupply: totalSupply};
601
+ return maxDebtToHave.minus(currentDebt);
602
602
  }
603
603
 
604
604
  async getLTVConfig(config: IConfig, blockNumber: BlockIdentifier = 'latest') {
605
- const CACHE_KEY = `ltv_config_${blockNumber}`;
605
+ const CACHE_KEY = `ltv_config_${blockNumber}_${this.config.poolId.shortString()}_${this.config.collateral.symbol}_${this.config.debt.symbol}`;
606
606
  const cacheData = this.getCache<number>(CACHE_KEY);
607
607
  if (cacheData) {
608
608
  return cacheData as number;
@@ -628,7 +628,7 @@ export class VesuAdapter extends BaseAdapter {
628
628
  throw new Error('Pricer is not initialized');
629
629
  }
630
630
  // { '0': { collateral_shares: 0n, nominal_debt: 0n }, '1': 0n, '2': 0n }
631
- const CACHE_KEY = `positions_${blockNumber}`;
631
+ const CACHE_KEY = `positions_${blockNumber}_${this.config.poolId.shortString()}_${this.config.collateral.symbol}_${this.config.debt.symbol}`;
632
632
  const cacheData = this.getCache<VaultPosition[]>(CACHE_KEY);
633
633
  if (cacheData) {
634
634
  return cacheData;
@@ -662,7 +662,7 @@ export class VesuAdapter extends BaseAdapter {
662
662
  remarks: "Debt"
663
663
  }];
664
664
  this.setCache(CACHE_KEY, value, 60000); // ttl: 1min
665
- return value;
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() {