Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: remove argument from createHoneyPot #2

Merged
merged 1 commit into from
Oct 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 11 additions & 27 deletions src/HoneyPot.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
Expand All @@ -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);
Expand Down
6 changes: 1 addition & 5 deletions src/HoneyPotOEVShare.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
34 changes: 9 additions & 25 deletions test/HoneyPot.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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),
Expand All @@ -72,28 +65,22 @@ 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);
assertTrue(address(this).balance == balanceBefore - honeyPotBalance);

// 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);

Expand All @@ -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);
}
Expand Down
Loading