From 38151aab7cc48df242ef2e057b384df568ebf9d7 Mon Sep 17 00:00:00 2001 From: clemlak Date: Fri, 8 Dec 2023 12:08:54 +0400 Subject: [PATCH] feat: update computeWeights function --- contracts/strategies/G3MStrategy.sol | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/contracts/strategies/G3MStrategy.sol b/contracts/strategies/G3MStrategy.sol index f4724a7e..0ea826f8 100644 --- a/contracts/strategies/G3MStrategy.sol +++ b/contracts/strategies/G3MStrategy.sol @@ -248,14 +248,19 @@ contract G3MStrategy is IG3MStrategy { { Config memory config = configs[poolId]; - uint256 duration = - configs[poolId].endUpdate - configs[poolId].startUpdate; - uint256 timeElapsed = block.timestamp - configs[poolId].startUpdate; - uint256 t = timeElapsed * WAD / duration; - uint256 fw0 = G3MStrategyLib.computeISFunction(config.startWeightX); - uint256 fw1 = G3MStrategyLib.computeISFunction(config.endWeightX); - - weightX = G3MStrategyLib.computeSFunction(t, fw1 - fw0, fw0); - weightY = WAD - weightX; + if (block.timestamp >= config.endUpdate) { + weightX = config.endWeightX; + weightY = WAD - config.endWeightX; + } else { + uint256 duration = + configs[poolId].endUpdate - configs[poolId].startUpdate; + uint256 timeElapsed = block.timestamp - configs[poolId].startUpdate; + uint256 t = timeElapsed * WAD / duration; + uint256 fw0 = G3MStrategyLib.computeISFunction(config.startWeightX); + uint256 fw1 = G3MStrategyLib.computeISFunction(config.endWeightX); + + weightX = G3MStrategyLib.computeSFunction(t, fw1 - fw0, fw0); + weightY = WAD - weightX; + } } }