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

Revert 2 revert 1 lyra #12579

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
70 changes: 70 additions & 0 deletions contracts/src/v0.8/dev/LyraAutomator.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.6;

import "../interfaces/AutomationCompatibleInterface.sol";
import "../ConfirmedOwner.sol";
import "./OptionMarketInterface.sol";

contract LyraAutomator is AutomationCompatibleInterface, ConfirmedOwner {
OptionMarketInterface public s_optionMarket;
uint256 public s_maxExpiryNum;

event BoardExpired(uint256 indexed boardId, uint256 blocknumber);
event SettlementFailed(uint256 indexed boardId, bytes lowLevelData);

constructor(OptionMarketInterface optionMarket, uint8 maxExpiryNum) ConfirmedOwner(msg.sender) {
s_optionMarket = optionMarket;
s_maxExpiryNum = maxExpiryNum;
}

function setOptionMarket(OptionMarketInterface optionMarket) external onlyOwner {
s_optionMarket = optionMarket;
}

function setMaxExpiryNum(uint256 maxExpiryNum) external onlyOwner {
s_maxExpiryNum = maxExpiryNum;
}

function checkUpkeep(bytes calldata checkData)
external
override
returns (bool upkeepNeeded, bytes memory performData)
{
uint256[] memory liveBoards = s_optionMarket.getLiveBoards();
uint256 index = 0;

for (uint256 i = 0; i < liveBoards.length; i++) {
uint256 boardId = liveBoards[i];
OptionBoard memory board = s_optionMarket.getOptionBoard(boardId);
if (board.expiry < block.timestamp) {
liveBoards[index++] = boardId;
if (index == s_maxExpiryNum) {
break;
}
}
}

if (index > 0) {
return (true, abi.encode(index, liveBoards));
}

return (false, "");
}

function performUpkeep(bytes calldata performData) external override {
(uint256 index, uint256[] memory boardIds) = abi.decode(performData, (uint256, uint256[]));
if (index == 0) {
return;
}

for (uint256 i = 0; i < index; i++) {
uint256 boardId = boardIds[i];

try s_optionMarket.settleExpiredBoard(boardId) {
emit BoardExpired(boardId, block.number);
} catch (bytes memory lowLevelData) {
emit SettlementFailed(boardId, lowLevelData);
}
}
}
}
23 changes: 23 additions & 0 deletions contracts/src/v0.8/dev/OptionMarketInterface.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.6;

struct OptionBoard {
// board identifier
uint256 id;
// expiry of all strikes belonging to board
uint256 expiry;
// volatility component specific to board (boardIv * skew = vol of strike)
uint256 iv;
// admin settable flag blocking all trading on this board
bool frozen;
// list of all strikes belonging to this board
uint256[] strikeIds;
}

interface OptionMarketInterface {
function getLiveBoards() external view returns (uint256[] memory _liveBoards);

function getOptionBoard(uint256 boardId) external view returns (OptionBoard memory);

function settleExpiredBoard(uint256 boardId) external;
}