diff --git a/src/HoneyPot.sol b/src/HoneyPot.sol index 8a3c88e..4cb1863 100644 --- a/src/HoneyPot.sol +++ b/src/HoneyPot.sol @@ -15,16 +15,8 @@ contract HoneyPot is Ownable { IAggregatorV3Source public oracle; // OEV Share serving as a Chainlink oracle event OracleUpdated(address indexed newOracle); - event HoneyPotCreated( - address indexed creator, - int256 liquidationPrice, - uint256 initialBalance - ); - event HoneyPotEmptied( - address indexed honeyPotCreator, - address indexed trigger, - uint256 amount - ); + event HoneyPotCreated(address indexed creator, int256 liquidationPrice, uint256 initialBalance); + event HoneyPotEmptied(address indexed honeyPotCreator, address indexed trigger, uint256 amount); event PotReset(address indexed owner, uint256 amount); constructor(IAggregatorV3Source _oracle) { @@ -36,23 +28,18 @@ contract HoneyPot is Ownable { emit OracleUpdated(address(_oracle)); } - function createHoneyPot(int256 _liquidationPrice) external payable { - require( - honeyPots[msg.sender].liquidationPrice == 0, - "Liquidation price already set for this user" - ); - require(_liquidationPrice > 0, "Liquidation price cannot be zero"); + function createHoneyPot() external payable { + require(honeyPots[msg.sender].liquidationPrice == 0, "Liquidation price already set for this user"); - honeyPots[msg.sender].liquidationPrice = _liquidationPrice; + (, int256 currentPrice,,,) = oracle.latestRoundData(); + + honeyPots[msg.sender].liquidationPrice = currentPrice; honeyPots[msg.sender].balance = msg.value; - emit HoneyPotCreated(msg.sender, _liquidationPrice, msg.value); + emit HoneyPotCreated(msg.sender, currentPrice, msg.value); } - function _emptyPotForUser( - address honeyPotCreator, - address recipient - ) internal { + function _emptyPotForUser(address honeyPotCreator, address recipient) internal { HoneyPotDetails storage userPot = honeyPots[honeyPotCreator]; uint256 amount = userPot.balance; @@ -62,15 +49,12 @@ contract HoneyPot is Ownable { } function emptyHoneyPot(address honeyPotCreator) external { - (, int256 currentPrice, , , ) = oracle.latestRoundData(); + (, int256 currentPrice,,,) = oracle.latestRoundData(); require(currentPrice >= 0, "Invalid price from oracle"); HoneyPotDetails storage userPot = honeyPots[honeyPotCreator]; - require( - currentPrice != userPot.liquidationPrice, - "Liquidation price reached for this user" - ); + require(currentPrice != userPot.liquidationPrice, "Liquidation price reached for this user"); _emptyPotForUser(honeyPotCreator, msg.sender); emit HoneyPotEmptied(honeyPotCreator, msg.sender, userPot.balance); diff --git a/src/HoneyPotOEVShare.sol b/src/HoneyPotOEVShare.sol index 997a4cb..ff36da1 100644 --- a/src/HoneyPotOEVShare.sol +++ b/src/HoneyPotOEVShare.sol @@ -8,11 +8,7 @@ import {IAggregatorV3Source} from "oev-contracts/interfaces/chainlink/IAggregato import {IMedian} from "oev-contracts/interfaces/chronicle/IMedian.sol"; import {IPyth} from "oev-contracts/interfaces/pyth/IPyth.sol"; -contract HoneyPotOEVShare is - BaseController, - BoundedUnionSourceAdapter, - ChainlinkDestinationAdapter -{ +contract HoneyPotOEVShare is BaseController, BoundedUnionSourceAdapter, ChainlinkDestinationAdapter { constructor( address chainlinkSource, address chronicleSource, diff --git a/test/HoneyPot.sol b/test/HoneyPot.sol index 5d01bec..fb9fe55 100644 --- a/test/HoneyPot.sol +++ b/test/HoneyPot.sol @@ -10,12 +10,10 @@ import {HoneyPotOEVShare} from "../src/HoneyPotOEVShare.sol"; import {HoneyPot} from "../src/HoneyPot.sol"; contract HoneyPotTest is CommonTest { - IAggregatorV3Source chainlink = - IAggregatorV3Source(0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419); + IAggregatorV3Source chainlink = IAggregatorV3Source(0x5f4eC3Df9cbd43714FE2740f5E3616155c5b8419); IMedian chronicle = IMedian(0x64DE91F5A373Cd4c28de3600cB34C7C6cE410C85); IPyth pyth = IPyth(0x4305FB66699C3B2702D4d05CF36551390A4c69C6); - bytes32 pythPriceId = - 0xff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace; + bytes32 pythPriceId = 0xff61491a931112ddf1bd8147cd1b641375f79f5825126d665480874634fd0ace; HoneyPotOEVShare oevShare; HoneyPot honeyPot; @@ -48,13 +46,8 @@ contract HoneyPotTest is CommonTest { } function mockChainlinkPriceChange() public { - ( - uint80 roundId, - int256 answer, - uint256 startedAt, - uint256 updatedAt, - uint80 answeredInRound - ) = chainlink.latestRoundData(); + (uint80 roundId, int256 answer, uint256 startedAt, uint256 updatedAt, uint80 answeredInRound) = + chainlink.latestRoundData(); vm.mockCall( address(chainlink), abi.encodeWithSelector(chainlink.latestRoundData.selector), @@ -72,8 +65,7 @@ contract HoneyPotTest is CommonTest { uint256 balanceBefore = address(this).balance; // Create HoneyPot for the caller - (, int256 latestAnswer, , , ) = oevShare.latestRoundData(); - honeyPot.createHoneyPot{value: honeyPotBalance}(latestAnswer); + honeyPot.createHoneyPot{value: honeyPotBalance}(); (, uint256 testhoneyPotBalance) = honeyPot.honeyPots(address(this)); assertTrue(testhoneyPotBalance == honeyPotBalance); @@ -81,19 +73,14 @@ contract HoneyPotTest is CommonTest { // Reset HoneyPot for the caller honeyPot.resetPot(); - (, uint256 testhoneyPotBalanceReset) = honeyPot.honeyPots( - address(this) - ); + (, uint256 testhoneyPotBalanceReset) = honeyPot.honeyPots(address(this)); assertTrue(testhoneyPotBalanceReset == 0); assertTrue(address(this).balance == balanceBefore); } function testCrackHoneyPot() public { // Create HoneyPot for the caller - (, int256 latestAnswer, , , ) = oevShare.latestRoundData(); - honeyPot.createHoneyPot{value: honeyPotBalance}( - latestAnswer - ); + honeyPot.createHoneyPot{value: honeyPotBalance}(); (, uint256 testhoneyPotBalance) = honeyPot.honeyPots(address(this)); assertTrue(testhoneyPotBalance == honeyPotBalance); @@ -114,13 +101,10 @@ contract HoneyPotTest is CommonTest { uint256 liquidatorBalanceAfter = liquidator.balance; - assertTrue( - liquidatorBalanceAfter == liquidatorBalanceBefore + honeyPotBalance - ); + assertTrue(liquidatorBalanceAfter == liquidatorBalanceBefore + honeyPotBalance); // Create HoneyPot can be called again - (, int256 latestAnswerNew, , , ) = oevShare.latestRoundData(); - honeyPot.createHoneyPot{value: honeyPotBalance}(latestAnswerNew); + honeyPot.createHoneyPot{value: honeyPotBalance}(); (, uint256 testhoneyPotBalanceTwo) = honeyPot.honeyPots(address(this)); assertTrue(testhoneyPotBalanceTwo == honeyPotBalance); }