@strkfarm/sdk 2.0.0-dev.27 → 2.0.0-dev.28
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/cli.js +190 -36
- package/dist/cli.mjs +188 -34
- package/dist/index.browser.global.js +79130 -49357
- package/dist/index.browser.mjs +18039 -11434
- package/dist/index.d.ts +2869 -898
- package/dist/index.js +19036 -12210
- package/dist/index.mjs +18942 -12161
- package/package.json +1 -1
- package/src/data/avnu.abi.json +840 -0
- package/src/data/ekubo-price-fethcer.abi.json +265 -0
- package/src/dataTypes/_bignumber.ts +13 -4
- package/src/dataTypes/index.ts +3 -2
- package/src/dataTypes/mynumber.ts +141 -0
- package/src/global.ts +76 -41
- package/src/index.browser.ts +2 -1
- package/src/interfaces/common.tsx +167 -2
- package/src/modules/ExtendedWrapperSDk/types.ts +26 -4
- package/src/modules/ExtendedWrapperSDk/wrapper.ts +110 -67
- package/src/modules/apollo-client-config.ts +28 -0
- package/src/modules/avnu.ts +4 -4
- package/src/modules/ekubo-pricer.ts +79 -0
- package/src/modules/ekubo-quoter.ts +46 -30
- package/src/modules/erc20.ts +17 -0
- package/src/modules/harvests.ts +43 -29
- package/src/modules/pragma.ts +23 -8
- package/src/modules/pricer-from-api.ts +156 -15
- package/src/modules/pricer-lst.ts +1 -1
- package/src/modules/pricer.ts +40 -4
- package/src/modules/pricerBase.ts +2 -1
- package/src/node/deployer.ts +36 -1
- package/src/node/pricer-redis.ts +2 -1
- package/src/strategies/base-strategy.ts +78 -10
- package/src/strategies/ekubo-cl-vault.tsx +906 -347
- package/src/strategies/factory.ts +159 -0
- package/src/strategies/index.ts +6 -1
- package/src/strategies/registry.ts +239 -0
- package/src/strategies/sensei.ts +335 -7
- package/src/strategies/svk-strategy.ts +97 -27
- package/src/strategies/types.ts +4 -0
- package/src/strategies/universal-adapters/adapter-utils.ts +2 -1
- package/src/strategies/universal-adapters/avnu-adapter.ts +177 -268
- package/src/strategies/universal-adapters/baseAdapter.ts +263 -251
- package/src/strategies/universal-adapters/common-adapter.ts +206 -203
- package/src/strategies/universal-adapters/extended-adapter.ts +155 -336
- package/src/strategies/universal-adapters/index.ts +9 -8
- package/src/strategies/universal-adapters/token-transfer-adapter.ts +200 -0
- package/src/strategies/universal-adapters/usdc<>usdce-adapter.ts +200 -0
- package/src/strategies/universal-adapters/vesu-adapter.ts +110 -75
- package/src/strategies/universal-adapters/vesu-modify-position-adapter.ts +476 -0
- package/src/strategies/universal-adapters/vesu-multiply-adapter.ts +762 -844
- package/src/strategies/universal-adapters/vesu-position-common.ts +251 -0
- package/src/strategies/universal-adapters/vesu-supply-only-adapter.ts +18 -3
- package/src/strategies/universal-lst-muliplier-strategy.tsx +396 -204
- package/src/strategies/universal-strategy.tsx +1426 -1178
- package/src/strategies/vesu-extended-strategy/services/executionService.ts +2251 -0
- package/src/strategies/vesu-extended-strategy/services/extended-vesu-state-manager.ts +2941 -0
- package/src/strategies/vesu-extended-strategy/services/operationService.ts +12 -1
- package/src/strategies/vesu-extended-strategy/types/transaction-metadata.ts +52 -0
- package/src/strategies/vesu-extended-strategy/utils/config.runtime.ts +1 -0
- package/src/strategies/vesu-extended-strategy/utils/constants.ts +2 -0
- package/src/strategies/vesu-extended-strategy/utils/helper.ts +158 -124
- package/src/strategies/vesu-extended-strategy/vesu-extended-strategy.tsx +377 -1788
- package/src/strategies/vesu-rebalance.tsx +255 -152
- package/src/utils/health-factor-math.ts +4 -1
- package/src/utils/index.ts +2 -1
- package/src/utils/logger.browser.ts +22 -4
- package/src/utils/logger.node.ts +259 -24
- package/src/utils/starknet-call-parser.ts +1036 -0
- package/src/utils/strategy-utils.ts +61 -0
- package/src/strategies/universal-adapters/unused-balance-adapter.ts +0 -109
|
@@ -16,6 +16,7 @@ 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
18
|
import { CacheClass } from "@/utils/cacheClass";
|
|
19
|
+
import { PricerFromApi } from "@/modules";
|
|
19
20
|
|
|
20
21
|
interface VesuPoolsInfo { pools: any[]; isErrorPoolsAPI: boolean };
|
|
21
22
|
|
|
@@ -178,7 +179,7 @@ function getVesuMultiplyParams(isIncrease: boolean, params: IncreaseLeverParams
|
|
|
178
179
|
}
|
|
179
180
|
}
|
|
180
181
|
|
|
181
|
-
const _params = params as DecreaseLeverParams;
|
|
182
|
+
const _params = params as DecreaseLeverParams;
|
|
182
183
|
return {
|
|
183
184
|
action: new CairoCustomEnum({ DecreaseLever: {
|
|
184
185
|
pool_id: _params.pool_id.toBigInt(),
|
|
@@ -235,6 +236,29 @@ export const VesuPools = {
|
|
|
235
236
|
Re7xSTRK: ContractAddr.from('0x052fb52363939c3aa848f8f4ac28f0a51379f8d1b971d8444de25fbd77d8f161'),
|
|
236
237
|
Re7xBTC: ContractAddr.from('0x3a8416bf20d036df5b1cf3447630a2e1cb04685f6b0c3a70ed7fb1473548ecf'),
|
|
237
238
|
Re7USDCPrime: ContractAddr.from('0x02eef0c13b10b487ea5916b54c0a7f98ec43fb3048f60fdeedaf5b08f6f88aaf'),
|
|
239
|
+
Prime: ContractAddr.from('0x451fe483d5921a2919ddd81d0de6696669bccdacd859f72a4fba7656b97c3b5'),
|
|
240
|
+
Re7STRK: ContractAddr.from('0x01fcdacc1d8184eca7b472b5acbaf1500cec9d5683ca95fede8128b46c8f9cc2'),
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
export const VesuPoolMetadata = {
|
|
244
|
+
[VesuPools.Genesis.address]: {
|
|
245
|
+
name: 'Genesis',
|
|
246
|
+
},
|
|
247
|
+
[VesuPools.Re7xSTRK.address]: {
|
|
248
|
+
name: 'Re7 xSTRK',
|
|
249
|
+
},
|
|
250
|
+
[VesuPools.Re7xBTC.address]: {
|
|
251
|
+
name: 'Re7 xBTC',
|
|
252
|
+
},
|
|
253
|
+
[VesuPools.Prime.address]: {
|
|
254
|
+
name: 'Prime',
|
|
255
|
+
},
|
|
256
|
+
[VesuPools.Re7STRK.address]: {
|
|
257
|
+
name: 'Re7 STRK',
|
|
258
|
+
},
|
|
259
|
+
[VesuPools.Re7USDCPrime.address]: {
|
|
260
|
+
name: 'Re7 USDC Prime',
|
|
261
|
+
},
|
|
238
262
|
}
|
|
239
263
|
|
|
240
264
|
export const extensionMap: {[key: string]: ContractAddr} = {};
|
|
@@ -251,6 +275,7 @@ export function getVesuSingletonAddress(vesuPool: ContractAddr) {
|
|
|
251
275
|
export class VesuAdapter extends CacheClass {
|
|
252
276
|
VESU_MULTIPLY_V1 = ContractAddr.from('0x3630f1f8e5b8f5c4c4ae9b6620f8a570ae55cddebc0276c37550e7c118edf67');
|
|
253
277
|
VESU_MULTIPLY = ContractAddr.from('0x027fef272d0a9a3844767c851a64b36fe4f0115141d81134baade95d2b27b781');
|
|
278
|
+
VESU_WITHDRAW_SWAP_FIXED_MULTIPLIER = ContractAddr.from('0xd2b0006de39992e78d457b7607a606c00bd6b601e9d9a77a8e1870c5e19e73');
|
|
254
279
|
config: VesuAdapterConfig;
|
|
255
280
|
networkConfig: IConfig | undefined;
|
|
256
281
|
pricer: PricerBase | undefined;
|
|
@@ -286,31 +311,31 @@ export class VesuAdapter extends CacheClass {
|
|
|
286
311
|
// return { leaf: output, callConstructor: this.getModifyPositionCall.bind(this) };
|
|
287
312
|
// }
|
|
288
313
|
|
|
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
|
+
static getDefaultModifyPositionCallParams(params: {
|
|
315
|
+
collateralAmount: Web3Number,
|
|
316
|
+
isAddCollateral: boolean,
|
|
317
|
+
debtAmount: Web3Number,
|
|
318
|
+
isBorrow: boolean
|
|
319
|
+
}) {
|
|
320
|
+
return {
|
|
321
|
+
collateralAmount: {
|
|
322
|
+
amount_type: VesuAmountType.Delta,
|
|
323
|
+
denomination: VesuAmountDenomination.Assets,
|
|
324
|
+
value: {
|
|
325
|
+
abs: params.collateralAmount,
|
|
326
|
+
is_negative: !params.isAddCollateral
|
|
327
|
+
}
|
|
328
|
+
},
|
|
329
|
+
debtAmount: {
|
|
330
|
+
amount_type: VesuAmountType.Delta,
|
|
331
|
+
denomination: VesuAmountDenomination.Assets,
|
|
332
|
+
value: {
|
|
333
|
+
abs: params.debtAmount,
|
|
334
|
+
is_negative: !params.isBorrow
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
}
|
|
338
|
+
}
|
|
314
339
|
|
|
315
340
|
// getModifyPositionCall = (params: VesuModifyPositionCallParams): ManageCall => {
|
|
316
341
|
// // pub pool_id: felt252,
|
|
@@ -439,29 +464,31 @@ export class VesuAdapter extends CacheClass {
|
|
|
439
464
|
// }
|
|
440
465
|
// }
|
|
441
466
|
|
|
442
|
-
getVesuModifyDelegationCall = (
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
467
|
+
getVesuModifyDelegationCall = (delegatee: ContractAddr) => {
|
|
468
|
+
return (params: VesuModifyDelegationCallParams) => {
|
|
469
|
+
const VESU_SINGLETON = getVesuSingletonAddress(this.config.poolId).addr;
|
|
470
|
+
const { contract, isV2 } = this.getVesuSingletonContract(getMainnetConfig(), this.config.poolId);
|
|
471
|
+
const call = contract.populate('modify_delegation', isV2 ? {
|
|
472
|
+
delegatee: delegatee.toBigInt(),
|
|
473
|
+
delegation: params.delegation,
|
|
474
|
+
} : {
|
|
475
|
+
pool_id: this.config.poolId.toBigInt(),
|
|
476
|
+
delegatee: delegatee.toBigInt(),
|
|
477
|
+
delegation: params.delegation,
|
|
478
|
+
});
|
|
479
|
+
return {
|
|
480
|
+
sanitizer: isV2 ? SIMPLE_SANITIZER_V2 : SIMPLE_SANITIZER_VESU_V1_DELEGATIONS,
|
|
481
|
+
call: {
|
|
482
|
+
contractAddress: VESU_SINGLETON,
|
|
483
|
+
selector: hash.getSelectorFromName('modify_delegation'),
|
|
484
|
+
calldata: [
|
|
485
|
+
...call.calldata as bigint[]
|
|
486
|
+
]
|
|
487
|
+
}
|
|
461
488
|
}
|
|
462
489
|
}
|
|
463
490
|
}
|
|
464
|
-
|
|
491
|
+
|
|
465
492
|
// getDefispringRewardsAdapter = (id: string): () => AdapterLeafType<VesuDefiSpringRewardsCallParams> => {
|
|
466
493
|
// return () => {
|
|
467
494
|
// const packedArguments: bigint[] = [];
|
|
@@ -538,7 +565,7 @@ export class VesuAdapter extends CacheClass {
|
|
|
538
565
|
}
|
|
539
566
|
const output: any = await contract.call('pair_config', [this.config.collateral.address.address, this.config.debt.address.address]);
|
|
540
567
|
logger.verbose(`${this.config.debt.symbol}::VesuAdapter::getDebtCap debt_cap: ${output.debt_cap.toString()}`);
|
|
541
|
-
|
|
568
|
+
|
|
542
569
|
if (!isV2) {
|
|
543
570
|
throw new Error('getDebtCap is not supported for v1');
|
|
544
571
|
}
|
|
@@ -568,7 +595,7 @@ export class VesuAdapter extends CacheClass {
|
|
|
568
595
|
|
|
569
596
|
}
|
|
570
597
|
const _interestRateConfig: any = await interestRateConfigContract.call(
|
|
571
|
-
'interest_rate_config',
|
|
598
|
+
'interest_rate_config',
|
|
572
599
|
isV2 ? [this.config.debt.address.address] : [this.config.poolId.address, this.config.debt.address.address]
|
|
573
600
|
);
|
|
574
601
|
const interestRateConfig: InterestRateConfig = {
|
|
@@ -581,24 +608,25 @@ export class VesuAdapter extends CacheClass {
|
|
|
581
608
|
min_full_utilization_rate: _interestRateConfig.min_full_utilization_rate,
|
|
582
609
|
max_full_utilization_rate: _interestRateConfig.max_full_utilization_rate,
|
|
583
610
|
};
|
|
584
|
-
|
|
611
|
+
|
|
585
612
|
const _assetConfig: any = await contract.call(
|
|
586
|
-
isV2 ? 'asset_config' : 'asset_config_unsafe',
|
|
613
|
+
isV2 ? 'asset_config' : 'asset_config_unsafe',
|
|
587
614
|
isV2 ? [asset.address.address] : [this.config.poolId.address, asset.address.address]
|
|
588
615
|
);
|
|
589
616
|
const assetConfig = isV2 ? _assetConfig : _assetConfig['0'];
|
|
590
617
|
const timeDelta = assetConfig.last_updated;
|
|
591
618
|
const lastFullUtilizationRate = assetConfig.last_full_utilization_rate;
|
|
592
|
-
const
|
|
619
|
+
const debtSharePrice = Web3Number.fromWei(assetConfig.last_rate_accumulator, 18);
|
|
620
|
+
const currentDebt = (new Web3Number((Number(assetConfig.total_nominal_debt) / 1e18).toFixed(9), asset.decimals)).multipliedBy(debtSharePrice);
|
|
593
621
|
const totalSupply = currentDebt.plus(Web3Number.fromWei(assetConfig.reserve, asset.decimals));
|
|
594
622
|
|
|
595
623
|
const ratePerSecond = BigInt(Math.round(maxBorrowAPY / 365 / 24 / 60 / 60 * Number(SCALE)));
|
|
596
624
|
const maxUtilisation = this.getMaxUtilizationGivenRatePerSecond(interestRateConfig, ratePerSecond, timeDelta, lastFullUtilizationRate);
|
|
597
625
|
logger.verbose(`${asset.symbol}::VesuAdapter::getMaxBorrowableByInterestRate maxUtilisation: ${Number(maxUtilisation) / 1e18}, totalSupply: ${totalSupply.toString()}`);
|
|
598
|
-
|
|
626
|
+
|
|
599
627
|
const maxDebtToHave = totalSupply.multipliedBy(Number(maxUtilisation) / 1e18);
|
|
600
628
|
logger.verbose(`${asset.symbol}::VesuAdapter::getMaxBorrowableByInterestRate currentDebt: ${currentDebt.toString()}, maxDebtToHave: ${maxDebtToHave.toString()}`);
|
|
601
|
-
return maxDebtToHave.minus(currentDebt);
|
|
629
|
+
return {maxDebtToHave: maxDebtToHave.minus(currentDebt), currentDebt: currentDebt, totalSupply: totalSupply};
|
|
602
630
|
}
|
|
603
631
|
|
|
604
632
|
async getLTVConfig(config: IConfig, blockNumber: BlockIdentifier = 'latest') {
|
|
@@ -636,30 +664,29 @@ export class VesuAdapter extends CacheClass {
|
|
|
636
664
|
|
|
637
665
|
const { contract, isV2} = this.getVesuSingletonContract(config, this.config.poolId);
|
|
638
666
|
const output: any = await contract
|
|
639
|
-
.call(isV2 ? 'position' : 'position_unsafe', [...(isV2 ?
|
|
667
|
+
.call(isV2 ? 'position' : 'position_unsafe', [...(isV2 ?
|
|
640
668
|
[]: [this.config.poolId.address]), // exclude pool id in v2
|
|
641
669
|
this.config.collateral.address.address,
|
|
642
670
|
this.config.debt.address.address,
|
|
643
671
|
this.config.vaultAllocator.address
|
|
644
672
|
], { blockIdentifier: blockNumber });
|
|
645
673
|
|
|
646
|
-
console.log(output)
|
|
647
674
|
const token1Price = await this.pricer.getPrice(this.config.collateral.symbol);
|
|
648
675
|
const token2Price = await this.pricer.getPrice(this.config.debt.symbol);
|
|
649
676
|
logger.verbose(`VesuAdapter::getPositions token1Price: ${token1Price.price}, token2Price: ${token2Price.price}`);
|
|
650
|
-
|
|
677
|
+
|
|
651
678
|
const collateralAmount = Web3Number.fromWei(output['1'].toString(), this.config.collateral.decimals);
|
|
652
679
|
const debtAmount = Web3Number.fromWei(output['2'].toString(), this.config.debt.decimals);
|
|
653
680
|
const value = [{
|
|
654
681
|
amount: collateralAmount,
|
|
655
682
|
token: this.config.collateral,
|
|
656
683
|
usdValue: collateralAmount.multipliedBy(token1Price.price).toNumber(),
|
|
657
|
-
remarks:
|
|
684
|
+
remarks: `Collateral - ${VesuPoolMetadata[this.config.poolId.address].name} pool`
|
|
658
685
|
}, {
|
|
659
686
|
amount: debtAmount,
|
|
660
687
|
token: this.config.debt,
|
|
661
688
|
usdValue: debtAmount.multipliedBy(token2Price.price).toNumber(),
|
|
662
|
-
remarks:
|
|
689
|
+
remarks: `Debt - ${VesuPoolMetadata[this.config.poolId.address].name} pool`
|
|
663
690
|
}];
|
|
664
691
|
// this.setCache(CACHE_KEY, value, 60000); // ttl: 1min
|
|
665
692
|
return value.map(v => ({ ...v, protocol: Protocols.VESU }));
|
|
@@ -678,7 +705,7 @@ export class VesuAdapter extends CacheClass {
|
|
|
678
705
|
const { contract, isV2 } = this.getVesuSingletonContract(config, this.config.poolId);
|
|
679
706
|
const output: any = await contract
|
|
680
707
|
.call(isV2 ? 'check_collateralization' : 'check_collateralization_unsafe', [
|
|
681
|
-
...(isV2 ?
|
|
708
|
+
...(isV2 ?
|
|
682
709
|
[]: [this.config.poolId.address]), // exclude pool id in v2
|
|
683
710
|
this.config.collateral.address.address,
|
|
684
711
|
this.config.debt.address.address,
|
|
@@ -711,12 +738,20 @@ export class VesuAdapter extends CacheClass {
|
|
|
711
738
|
|
|
712
739
|
const collateralTokenAmount = positions[0].amount;
|
|
713
740
|
const collateralUSDAmount = collateralization[0].usdValue;
|
|
714
|
-
|
|
741
|
+
let collateralPrice = collateralUSDAmount / collateralTokenAmount.toNumber();
|
|
715
742
|
|
|
716
743
|
const debtTokenAmount = positions[1].amount;
|
|
717
744
|
const debtUSDAmount = collateralization[1].usdValue;
|
|
718
|
-
|
|
719
|
-
|
|
745
|
+
let debtPrice = debtUSDAmount / debtTokenAmount.toNumber();
|
|
746
|
+
if (isNaN(collateralPrice)) {
|
|
747
|
+
const pricer = new PricerFromApi(this.networkConfig!, Global.getDefaultTokens())
|
|
748
|
+
collateralPrice = (await pricer.getPrice(this.config.collateral.priceProxySymbol || this.config.collateral.symbol)).price;
|
|
749
|
+
}
|
|
750
|
+
if (isNaN(debtPrice)) {
|
|
751
|
+
const pricer = new PricerFromApi(this.networkConfig!, Global.getDefaultTokens())
|
|
752
|
+
debtPrice = (await pricer.getPrice(this.config.debt.priceProxySymbol || this.config.debt.symbol)).price;
|
|
753
|
+
}
|
|
754
|
+
logger.verbose(`VesuAdapter::getAssetPrices collateralPrice: ${collateralPrice}, debtPrice: ${debtPrice}`);
|
|
720
755
|
return {
|
|
721
756
|
collateralTokenAmount,
|
|
722
757
|
collateralUSDAmount,
|
|
@@ -747,7 +782,7 @@ export class VesuAdapter extends CacheClass {
|
|
|
747
782
|
let pools: any[] = [];
|
|
748
783
|
try {
|
|
749
784
|
const data = await getAPIUsingHeadlessBrowser(
|
|
750
|
-
`${ENDPOINTS.
|
|
785
|
+
`${ENDPOINTS.VESU_BASE}/pools`
|
|
751
786
|
);
|
|
752
787
|
pools = data.data;
|
|
753
788
|
|
|
@@ -792,11 +827,11 @@ export class VesuAdapter extends CacheClass {
|
|
|
792
827
|
min_full_utilization_rate,
|
|
793
828
|
max_full_utilization_rate,
|
|
794
829
|
} = interestRateConfig;
|
|
795
|
-
|
|
830
|
+
|
|
796
831
|
const halfLifeScaled = rate_half_life * SCALE;
|
|
797
|
-
|
|
832
|
+
|
|
798
833
|
let nextFullUtilizationRate: bigint;
|
|
799
|
-
|
|
834
|
+
|
|
800
835
|
if (utilization < min_target_utilization) {
|
|
801
836
|
const utilizationDelta =
|
|
802
837
|
((min_target_utilization - utilization) * SCALE) / min_target_utilization;
|
|
@@ -811,7 +846,7 @@ export class VesuAdapter extends CacheClass {
|
|
|
811
846
|
} else {
|
|
812
847
|
nextFullUtilizationRate = fullUtilizationRate;
|
|
813
848
|
}
|
|
814
|
-
|
|
849
|
+
|
|
815
850
|
if (nextFullUtilizationRate > max_full_utilization_rate) {
|
|
816
851
|
return max_full_utilization_rate;
|
|
817
852
|
} else if (nextFullUtilizationRate < min_full_utilization_rate) {
|
|
@@ -831,26 +866,26 @@ export class VesuAdapter extends CacheClass {
|
|
|
831
866
|
lastFullUtilizationRate: bigint
|
|
832
867
|
): { newRatePerSecond: bigint; nextFullUtilizationRate: bigint } {
|
|
833
868
|
const scaledUtilization = utilization / UTILIZATION_SCALE_TO_SCALE;
|
|
834
|
-
|
|
869
|
+
|
|
835
870
|
const {
|
|
836
871
|
target_utilization,
|
|
837
872
|
zero_utilization_rate,
|
|
838
873
|
target_rate_percent,
|
|
839
874
|
} = interestRateConfig;
|
|
840
|
-
|
|
875
|
+
|
|
841
876
|
const nextFullUtilizationRate = this.fullUtilizationRate(
|
|
842
877
|
interestRateConfig,
|
|
843
878
|
timeDelta,
|
|
844
879
|
scaledUtilization,
|
|
845
880
|
lastFullUtilizationRate
|
|
846
881
|
);
|
|
847
|
-
|
|
882
|
+
|
|
848
883
|
const targetRate =
|
|
849
884
|
(((nextFullUtilizationRate - zero_utilization_rate) * target_rate_percent) / SCALE) +
|
|
850
885
|
zero_utilization_rate;
|
|
851
|
-
|
|
886
|
+
|
|
852
887
|
let newRatePerSecond: bigint;
|
|
853
|
-
|
|
888
|
+
|
|
854
889
|
if (scaledUtilization < target_utilization) {
|
|
855
890
|
newRatePerSecond =
|
|
856
891
|
zero_utilization_rate +
|
|
@@ -863,10 +898,10 @@ export class VesuAdapter extends CacheClass {
|
|
|
863
898
|
(nextFullUtilizationRate - targetRate)) /
|
|
864
899
|
(UTILIZATION_SCALE - target_utilization);
|
|
865
900
|
}
|
|
866
|
-
|
|
901
|
+
|
|
867
902
|
return { newRatePerSecond, nextFullUtilizationRate };
|
|
868
903
|
}
|
|
869
|
-
|
|
904
|
+
|
|
870
905
|
/**
|
|
871
906
|
* Calculates utilization given a specific rate per second.
|
|
872
907
|
* This is an inverse function of the piecewise interest rate formula above.
|
|
@@ -893,4 +928,4 @@ export class VesuAdapter extends CacheClass {
|
|
|
893
928
|
}
|
|
894
929
|
throw new Error('Max utilization not found');
|
|
895
930
|
}
|
|
896
|
-
}
|
|
931
|
+
}
|