Skip to content

Commit

Permalink
fix: configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurka-o committed Oct 16, 2024
1 parent fcfbcbe commit 3fd9960
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion config/frontrun.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"blockTime": 26,
"blockTime": 2,
"frontrunCollateral": 50000000000000000000,
"frontrunLeverage": 2000000000000000000,
"initialBalance": 1000000000000000000000,
Expand Down
2 changes: 1 addition & 1 deletion contracts/mocks/AggregatorMock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ contract AggregatorMock is AggregatorV3Interface {
}

function decimals() public pure override returns (uint8) {
return 8;
return 18;
}

function setData(uint80 _roundId, int256 answer) external {
Expand Down
15 changes: 10 additions & 5 deletions tests/frontrun/Frontrun.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {AggregatorMock} from "contracts/mocks/AggregatorMock.sol";
import {OverlayV1ChainlinkFeed} from "contracts/feeds/chainlink/OverlayV1ChainlinkFeed.sol";
import {OverlayV1ChainlinkFeedFactory} from
"contracts/feeds/chainlink/OverlayV1ChainlinkFeedFactory.sol";
import "contracts/libraries/Oracle.sol";

contract FrontrunTest is Test {
bytes32 constant ADMIN_ROLE = 0x00;
Expand All @@ -27,7 +28,7 @@ contract FrontrunTest is Test {
}

struct JsonConfig {
// Blockchain's block time times 10. Ethereum = 120, Arbitrum = 26.
// Blockchain's block time times 10. Ethereum = 120, Arbitrum = 2.
// We have to multiple by ten so we can save precision.
uint256 blockTime;
uint256 frontrunCollateral;
Expand Down Expand Up @@ -71,7 +72,7 @@ contract FrontrunTest is Test {
}

function testFuzz_FrontrunAttempt(uint256 waitBlocks) public {
// Limit waitBlock values from 1 to 100
// Limit waitBlock values from 1 to 500
waitBlocks = bound(waitBlocks, 1, 500);

// Initialize market with two positions
Expand Down Expand Up @@ -118,11 +119,15 @@ contract FrontrunTest is Test {
vm.prank(USER1);
market.unwind(positionId, 1e18, 0);

Oracle.Data memory data2 = feed.latest();
console2.log("priceOverMicroWindow", int256(data2.priceOverMicroWindow));
console2.log("priceOverMacroWindow", int256(data2.priceOverMacroWindow));

// Profit
uint256 finalBalance = ov.balanceOf(USER1);
int256 profit = int256(finalBalance) - int256(initialBalance);

console2.log("Unwound at block:", block.number);
console2.log("Unwound at block time:", block.timestamp);
console2.log("Profit:", profit);

// Write data into `frontrun_results.csv`
Expand Down Expand Up @@ -176,7 +181,7 @@ contract FrontrunTest is Test {
setupInitialPrices();

feedFactory = new OverlayV1ChainlinkFeedFactory(address(ov), 600, 3600);
feed = OverlayV1ChainlinkFeed(feedFactory.deployFeed(address(aggregator), 60 minutes));
feed = OverlayV1ChainlinkFeed(feedFactory.deployFeed(address(aggregator), 120 minutes));
ov.grantRole(GOVERNOR_ROLE, GOVERNOR);
}

Expand All @@ -190,7 +195,7 @@ contract FrontrunTest is Test {
function updateAggregatorPrice(uint80 roundId, uint256 price) private {
aggregator.setData(roundId, int256(price));
vm.roll(block.number + 1);
vm.warp(block.timestamp + (config.blockTime / BLOCK_TIME_MULTIPLIER));
vm.warp(block.timestamp + 1);
}

function setUpConfig() private {
Expand Down

0 comments on commit 3fd9960

Please sign in to comment.