From 0d7a8e4814c6b186c9fe297c4cd94dbecde678d2 Mon Sep 17 00:00:00 2001 From: JulesCrown Date: Fri, 7 Jun 2024 12:33:20 +0200 Subject: [PATCH] enforce oracle check --- onchain/src/BaseLineLP.sol | 6 ++--- onchain/src/Stake.sol | 46 ++++++++++++++++++++------------------ 2 files changed, 27 insertions(+), 25 deletions(-) diff --git a/onchain/src/BaseLineLP.sol b/onchain/src/BaseLineLP.sol index 99703bb..93a2829 100644 --- a/onchain/src/BaseLineLP.sol +++ b/onchain/src/BaseLineLP.sol @@ -347,7 +347,7 @@ contract BaseLineLP { } - function _checkPriceStability(int24 currentTick) internal view returns (bool) { + function _isPriceStable(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 @@ -366,7 +366,7 @@ contract BaseLineLP { // Fetch the current tick from the Uniswap V3 pool (uint160 sqrtPriceX96, int24 currentTick, , , , , ) = pool.slot0(); // check slippage with oracle - _checkPriceStability(currentTick); + require(_isPriceStable(currentTick), "price deviated from oracle"); // ## check price moved up { @@ -423,7 +423,7 @@ contract BaseLineLP { // Fetch the current tick from the Uniswap V3 pool (uint160 sqrtPriceX96, int24 currentTick, , , , , ) = pool.slot0(); // check slippage with oracle - _checkPriceStability(currentTick); + require(_isPriceStable(currentTick), "price deviated from oracle"); // ## check price moved down if (positions[Stage.ANCHOR].liquidity > 0) { diff --git a/onchain/src/Stake.sol b/onchain/src/Stake.sol index a63b0fd..e6a1bbb 100644 --- a/onchain/src/Stake.sol +++ b/onchain/src/Stake.sol @@ -116,31 +116,33 @@ contract Stake is IStake { // TODO: check that position size is multiple of minStake uint256 smallestPositionShare = totalSupply; - - // run through all suggested positions to snatch - for (uint256 i = 0; i < positionsToSnatch.length - 1; i++) { - StakingPosition storage pos = positions[positionsToSnatch[i]]; - if (pos.creationTime == 0) { - //TODO: - revert PositionNotFound(); - } - // check that tax lower - if (taxRate <= pos.taxRate) { - revert TaxTooLow(receiver, taxRate, pos.taxRate, i); - } - if (pos.share < smallestPositionShare) { - smallestPositionShare = pos.share; - } - // dissolve position - // TODO: what if someone calls payTax and exitPosition in the same transaction? - _payTax(positionsToSnatch[i], pos, 0); - _exitPosition(positionsToSnatch[i], pos); - } - uint256 availableStake = authorizedStake() - outstandingStake; - // handle last position if (positionsToSnatch.length > 0) { + // run through all suggested positions to snatch + for (uint256 i = 0; i < positionsToSnatch.length - 1; i++) { + StakingPosition storage pos = positions[positionsToSnatch[i]]; + if (pos.creationTime == 0) { + //TODO: + revert PositionNotFound(); + } + // check that tax lower + if (taxRate <= pos.taxRate) { + revert TaxTooLow(receiver, taxRate, pos.taxRate, i); + } + if (pos.share < smallestPositionShare) { + smallestPositionShare = pos.share; + } + // dissolve position + // TODO: what if someone calls payTax and exitPosition in the same transaction? + _payTax(positionsToSnatch[i], pos, 0); + _exitPosition(positionsToSnatch[i], pos); + } + + availableStake = authorizedStake() - outstandingStake; + + // handle last position + uint256 index = positionsToSnatch.length - 1; StakingPosition storage pos = positions[positionsToSnatch[index]]; if (pos.creationTime == 0) {