@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.
- package/dist/index.browser.global.js +76556 -66640
- package/dist/index.browser.mjs +34235 -24392
- package/dist/index.d.ts +2372 -793
- package/dist/index.js +31967 -22084
- package/dist/index.mjs +25545 -15719
- package/package.json +86 -76
- package/readme.md +56 -1
- package/src/data/extended-deposit.abi.json +3613 -0
- package/src/data/universal-vault.abi.json +135 -20
- package/src/dataTypes/_bignumber.ts +11 -0
- package/src/dataTypes/address.ts +7 -0
- package/src/global.ts +240 -193
- package/src/interfaces/common.tsx +26 -2
- package/src/modules/ExtendedWrapperSDk/index.ts +62 -0
- package/src/modules/ExtendedWrapperSDk/types.ts +311 -0
- package/src/modules/ExtendedWrapperSDk/wrapper.ts +448 -0
- package/src/modules/avnu.ts +17 -4
- package/src/modules/ekubo-quoter.ts +89 -10
- package/src/modules/erc20.ts +67 -21
- package/src/modules/harvests.ts +29 -43
- package/src/modules/index.ts +5 -1
- package/src/modules/lst-apr.ts +36 -0
- package/src/modules/midas.ts +159 -0
- package/src/modules/pricer-from-api.ts +2 -2
- package/src/modules/pricer-lst.ts +1 -1
- package/src/modules/pricer.ts +3 -38
- package/src/modules/token-market-data.ts +202 -0
- package/src/node/deployer.ts +1 -36
- package/src/strategies/autoCompounderStrk.ts +1 -1
- package/src/strategies/base-strategy.ts +20 -3
- package/src/strategies/btc-vesu-extended-strategy/core-strategy.tsx +1486 -0
- package/src/strategies/btc-vesu-extended-strategy/services/operationService.ts +32 -0
- package/src/strategies/btc-vesu-extended-strategy/utils/constants.ts +3 -0
- package/src/strategies/btc-vesu-extended-strategy/utils/helper.ts +396 -0
- package/src/strategies/btc-vesu-extended-strategy/utils/types.ts +5 -0
- package/src/strategies/ekubo-cl-vault.tsx +123 -306
- package/src/strategies/index.ts +7 -1
- package/src/strategies/svk-strategy.ts +247 -0
- package/src/strategies/universal-adapters/adapter-optimizer.ts +65 -0
- package/src/strategies/universal-adapters/adapter-utils.ts +5 -1
- package/src/strategies/universal-adapters/avnu-adapter.ts +432 -0
- package/src/strategies/universal-adapters/baseAdapter.ts +181 -153
- package/src/strategies/universal-adapters/common-adapter.ts +98 -77
- package/src/strategies/universal-adapters/extended-adapter.ts +976 -0
- package/src/strategies/universal-adapters/index.ts +7 -1
- package/src/strategies/universal-adapters/unused-balance-adapter.ts +109 -0
- package/src/strategies/universal-adapters/vesu-adapter.ts +230 -230
- package/src/strategies/universal-adapters/vesu-borrow-adapter.ts +1247 -0
- package/src/strategies/universal-adapters/vesu-multiply-adapter.ts +1306 -0
- package/src/strategies/universal-adapters/vesu-supply-only-adapter.ts +58 -51
- package/src/strategies/universal-lst-muliplier-strategy.tsx +716 -844
- package/src/strategies/universal-strategy.tsx +1103 -1181
- package/src/strategies/vesu-extended-strategy/services/operationService.ts +34 -0
- package/src/strategies/vesu-extended-strategy/types/transaction-metadata.ts +25 -0
- package/src/strategies/vesu-extended-strategy/utils/config.runtime.ts +77 -0
- package/src/strategies/vesu-extended-strategy/utils/constants.ts +50 -0
- package/src/strategies/vesu-extended-strategy/utils/helper.ts +367 -0
- package/src/strategies/vesu-extended-strategy/vesu-extended-strategy.tsx +1420 -0
- package/src/strategies/vesu-rebalance.tsx +16 -20
- 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
|
-
|
|
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
|
|
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
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
}
|
|
287
|
-
|
|
288
|
-
static getDefaultModifyPositionCallParams(params: {
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
}) {
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
getModifyPositionCall = (params: VesuModifyPositionCallParams): ManageCall => {
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
getMultiplyAdapter = (id: string): LeafAdapterFn<VesuMultiplyCallParams> => {
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
getMultiplyCall = (params: VesuMultiplyCallParams): ManageCall => {
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
}
|
|
420
|
-
|
|
421
|
-
getVesuModifyDelegationAdapter = (id: string): LeafAdapterFn<VesuModifyDelegationCallParams> => {
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
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
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
}
|
|
481
|
-
|
|
482
|
-
getDefiSpringClaimCall = (): GenerateCallFn<VesuDefiSpringRewardsCallParams> => {
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
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
|
|
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
|
|
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
|
-
|
|
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 =
|
|
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 =
|
|
718
|
+
const debtPrice = await this.pricer?.getPrice(this.config.debt.symbol);
|
|
719
719
|
|
|
720
720
|
return {
|
|
721
721
|
collateralTokenAmount,
|