added price oracle
This commit is contained in:
parent
5d209e5e19
commit
ec71bcd287
3 changed files with 83 additions and 7 deletions
|
|
@ -24,6 +24,7 @@ contract BaseLineLP {
|
|||
int24 constant TICK_SPACING = 200;
|
||||
int24 constant ANCHOR_SPACING = 5 * TICK_SPACING;
|
||||
int24 constant DISCOVERY_SPACING = 11000;
|
||||
int24 constant MAX_TICK_DEVIATION = 50;
|
||||
// default fee of 1%
|
||||
uint24 constant FEE = uint24(10_000);
|
||||
// uint256 constant FLOOR = 0;
|
||||
|
|
@ -345,12 +346,27 @@ contract BaseLineLP {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
function _checkPriceStability(int24 currentTick) internal view returns (bool) {
|
||||
uint32 timeInterval = 300; // 5 minutes in seconds
|
||||
uint32[] memory secondsAgo = new uint32[](2);
|
||||
secondsAgo[0] = timeInterval; // 5 minutes ago
|
||||
secondsAgo[1] = 0; // current block timestamp
|
||||
|
||||
(int56[] memory tickCumulatives,) = pool.observe(secondsAgo);
|
||||
int56 tickCumulativeDiff = tickCumulatives[1] - tickCumulatives[0];
|
||||
int24 averageTick = int24(tickCumulativeDiff / int56(int32(timeInterval)));
|
||||
|
||||
return (currentTick >= averageTick - MAX_TICK_DEVIATION && currentTick <= averageTick + MAX_TICK_DEVIATION);
|
||||
}
|
||||
|
||||
// call this function when price has moved up 15%
|
||||
function shift() external {
|
||||
require(positions[Stage.ANCHOR].liquidity > 0, "Not initialized");
|
||||
// Fetch the current tick from the Uniswap V3 pool
|
||||
(uint160 sqrtPriceX96, int24 currentTick, , , , , ) = pool.slot0();
|
||||
// TODO: check slippage with oracle
|
||||
// check slippage with oracle
|
||||
_checkPriceStability(currentTick);
|
||||
|
||||
// ## check price moved up
|
||||
{
|
||||
|
|
@ -406,7 +422,8 @@ contract BaseLineLP {
|
|||
function slide() external {
|
||||
// Fetch the current tick from the Uniswap V3 pool
|
||||
(uint160 sqrtPriceX96, int24 currentTick, , , , , ) = pool.slot0();
|
||||
// TODO: check slippage with oracle
|
||||
// check slippage with oracle
|
||||
_checkPriceStability(currentTick);
|
||||
|
||||
// ## check price moved down
|
||||
if (positions[Stage.ANCHOR].liquidity > 0) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue