Skip to content

Commit

Permalink
Merge pull request #201 from overlay-market/arthurka/split-update_BAC…
Browse files Browse the repository at this point in the history
…-47_part_2

feat(market): emit Update event on every action
  • Loading branch information
TomasCImach authored May 20, 2024
2 parents e9ae89c + 17af1ac commit cc33d51
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
5 changes: 5 additions & 0 deletions contracts/OverlayV1Market.sol
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ contract OverlayV1Market is IOverlayV1Market, Pausable {
/// @param newDpUpperLimit new value for dpUpperLimit
event CacheRiskCalc(uint256 newDpUpperLimit);

/// @param oiLong oiLong after public update
/// @param oiShort oiShort after public update
event Update(uint256 oiLong, uint256 oiShort);

constructor() {
(address _ov, address _feed, address _factory) =
IOverlayV1Deployer(msg.sender).parameters();
Expand Down Expand Up @@ -529,6 +533,7 @@ contract OverlayV1Market is IOverlayV1Market, Pausable {
Oracle.Data memory data = IOverlayV1Feed(feed).latest();
require(dataIsValid(data), "OVV1:!data");

emit Update(oiLong, oiShort);
// return the latest data from feed
return data;
}
Expand Down
30 changes: 30 additions & 0 deletions tests/OverlayV1Market.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -171,4 +171,34 @@ contract MarketTest is Test {

assertEq(ov.balanceOf(address(market)), 0);
}

event Update(uint256 oiLong, uint256 oiShort);

function testUpdateEventEmitting() public {
vm.startPrank(USER);

ov.approve(address(market), type(uint256).max);
market.build(1e18, 1e18, true, type(uint256).max);

uint256 oiLong = market.oiLong();
uint256 oiShort = market.oiShort();
uint256 timeElapsed = block.timestamp - market.timestampUpdateLast();
bool isLongOverweight = oiLong > oiShort;
uint256 oiOverweight = isLongOverweight ? oiLong : oiShort;
uint256 oiUnderweight = isLongOverweight ? oiShort : oiLong;

(oiOverweight, oiUnderweight) =
market.oiAfterFunding(oiOverweight, oiUnderweight, timeElapsed);
uint256 newoiLong = isLongOverweight ? oiOverweight : oiUnderweight;
uint256 newoiShort = isLongOverweight ? oiUnderweight : oiOverweight;

vm.expectEmit(false, false, false, true);
emit Update(newoiLong, newoiShort);
market.update();

vm.stopPrank();

assertEq(market.oiLong(), newoiLong);
assertEq(market.oiShort(), newoiShort);
}
}

0 comments on commit cc33d51

Please sign in to comment.