Skip to content

Commit

Permalink
feat: update G3M pool config, add computeWeights
Browse files Browse the repository at this point in the history
  • Loading branch information
clemlak committed Dec 7, 2023
1 parent e3b61e0 commit 823974e
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 10 deletions.
59 changes: 50 additions & 9 deletions contracts/strategies/G3MStrategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,22 @@ contract G3MStrategy is IG3MStrategy {
uint64 poolId,
bytes calldata strategyArgs
) external returns (bool success) {
(address controller, uint256 weightX) =
abi.decode(strategyArgs, (address, uint256));
configs[poolId] = Config({ weightX: weightX, controller: controller });
(
address controller,
uint256 startWeightX,
uint256 endWeightX,
uint256 startUpdate,
uint256 endUpdate
) = abi.decode(
strategyArgs, (address, uint256, uint256, uint256, uint256)
);
configs[poolId] = Config({
controller: controller,
startWeightX: startWeightX,
endWeightX: endWeightX,
startUpdate: startUpdate,
endUpdate: endUpdate
});
return true;
}

Expand All @@ -42,7 +55,7 @@ contract G3MStrategy is IG3MStrategy {
override
returns (bool)
{
return configs[poolId].weightX != 0;
return configs[poolId].startWeightX != 0;
}

error NotController();
Expand Down Expand Up @@ -217,13 +230,41 @@ contract G3MStrategy is IG3MStrategy {
pure
returns (bytes memory strategyData, uint256 initialX, uint256 initialY)
{
(address controller, uint256 reserveX, uint256 weightX, uint256 price) =
abi.decode(data, (address, uint256, uint256, uint256));

strategyData = abi.encode(controller, weightX);
(
address controller,
uint256 reserveX,
uint256 startWeightX,
uint256 endWeightX,
uint256 startUpdate,
uint256 endUpdate,
uint256 price
) = abi.decode(data, (address, uint256, uint256, uint256));

strategyData = abi.encode(
controller, startWeightX, endWeightX, startUpdate, endUpdate
);
initialX = reserveX;
initialY = G3MStrategyLib.computeReserveInGivenPrice(
price, reserveX, FixedPointMathLib.WAD - weightX, weightX
price, reserveX, FixedPointMathLib.WAD - startWeightX, startWeightX
);
}

function computeWeights(uint64 poolId)
internal
returns (uint256, uint256)
{
PortfolioPool memory pool = IPortfolioStruct(portfolio).pools(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(pool.startWeightX);
uint256 fw1 = G3MStrategyLib.computeISFunction(pool.endWeightX);

uint256 weightX = G3MStrategyLib.computeSFunction(t, fw1 - fw0, fw0);
uint256 weightY = WAD - weightX;

return (weightX, weightY);
}
}
5 changes: 4 additions & 1 deletion contracts/strategies/IG3MStrategy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ interface IG3MStrategy is IStrategy {
error NotPortfolio();

struct Config {
uint256 weightX;
address controller;
uint256 startWeightX;
uint256 endWeightX;
uint256 startUpdate;
uint256 endUpdate;
}
}

0 comments on commit 823974e

Please sign in to comment.