-
Notifications
You must be signed in to change notification settings - Fork 1
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
Fix Review #1
base: main
Are you sure you want to change the base?
Fix Review #1
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,16 +2,17 @@ | |
pragma solidity ^0.8.19; | ||
|
||
import "./IAutomation.sol"; | ||
import "../oracle/IPythRelay.sol"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to gfx-labs/oku-custom-order-types#1. Fixes issues: #796, #763, #115, #589, #731, #700, #161, #789, #726, #109, #449, #761, #542, #24, #810, #202, #421, #429, #331, #357, #277, #64, #424, #745, #72, #146, #896, #904, #901, #900, #62, #267, #406, #486, #502, #604, #708, #771, #821, #871 |
||
import "../libraries/ArrayMutation.sol"; | ||
import "../interfaces/openzeppelin/Ownable.sol"; | ||
import "../interfaces/openzeppelin/ERC20.sol"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to gfx-labs/oku-custom-order-types#1. Fixes issues: #796, #763, #115, #589, #731, #700, #161, #789, #726, #109, #449, #761, #542, #24, #810, #202, #421, #429, #331, #357, #277, #64, #424, #745, #72, #146, #896, #904, #901, #900, #62, #267, #406, #486, #502, #604, #708, #771, #821, #871 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to gfx-labs/oku-custom-order-types#1. Fixes issues: #796, #763, #115, #589, #731, #700, #161, #789, #726, #109, #449, #761, #542, #24, #810, #202, #421, #429, #331, #357, #277, #64, #424, #745, #72, #146, #896, #904, #901, #900, #62, #267, #406, #486, #502, #604, #708, #771, #821, #871 |
||
import "../interfaces/openzeppelin/IERC20.sol"; | ||
import "../interfaces/openzeppelin/SafeERC20.sol"; | ||
import "../oracle/IPythRelay.sol"; | ||
import "../interfaces/openzeppelin/Pausable.sol"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to gfx-labs/oku-custom-order-types#1. Fixes issues: #796, #763, #115, #589, #731, #700, #161, #789, #726, #109, #449, #761, #542, #24, #810, #202, #421, #429, #331, #357, #277, #64, #424, #745, #72, #146, #896, #904, #901, #900, #62, #267, #406, #486, #502, #604, #708, #771, #821, #871 |
||
|
||
Comment on lines
+11
to
12
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to gfx-labs/oku-custom-order-types#1. Fixes issues: #796, #763, #115, #589, #731, #700, #161, #789, #726, #109, #449, #761, #542, #24, #810, #202, #421, #429, #331, #357, #277, #64, #424, #745, #72, #146, #896, #904, #901, #900, #62, #267, #406, #486, #502, #604, #708, #771, #821, #871 |
||
///@notice This contract owns and handles all of the settings and accounting logic for automated swaps | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to gfx-labs/oku-custom-order-types#1. Fixes issues: #796, #763, #115, #589, #731, #700, #161, #789, #726, #109, #449, #761, #542, #24, #810, #202, #421, #429, #331, #357, #277, #64, #424, #745, #72, #146, #896, #904, #901, #900, #62, #267, #406, #486, #502, #604, #708, #771, #821, #871 |
||
///@notice This contract should not hold any user funds, only collected fees | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to gfx-labs/oku-custom-order-types#1. Fixes issues: #796, #763, #115, #589, #731, #700, #161, #789, #726, #109, #449, #761, #542, #24, #810, #202, #421, #429, #331, #357, #277, #64, #424, #745, #72, #146, #896, #904, #901, #900, #62, #267, #406, #486, #502, #604, #708, #771, #821, #871 |
||
contract AutomationMaster is IAutomationMaster, Ownable { | ||
contract AutomationMaster is IAutomationMaster, Ownable, Pausable { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to gfx-labs/oku-custom-order-types#1. Fixes issues: #796, #763, #115, #589, #731, #700, #161, #789, #726, #109, #449, #761, #542, #24, #810, #202, #421, #429, #331, #357, #277, #64, #424, #745, #72, #146, #896, #904, #901, #900, #62, #267, #406, #486, #502, #604, #708, #771, #821, #871 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to gfx-labs/oku-custom-order-types#1. Fixes issues: #796, #763, #115, #589, #731, #700, #161, #789, #726, #109, #449, #761, #542, #24, #810, #202, #421, #429, #331, #357, #277, #64, #424, #745, #72, #146, #896, #904, #901, #900, #62, #267, #406, #486, #502, #604, #708, #771, #821, #871 |
||
using SafeERC20 for IERC20; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to gfx-labs/oku-custom-order-types#1. Fixes issues: #796, #763, #115, #589, #731, #700, #161, #789, #726, #109, #449, #761, #542, #24, #810, #202, #421, #429, #331, #357, #277, #64, #424, #745, #72, #146, #896, #904, #901, #900, #62, #267, #406, #486, #502, #604, #708, #771, #821, #871 |
||
|
||
///@notice maximum pending orders that may exist at a time, limiting the compute requriement for checkUpkeep | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to gfx-labs/oku-custom-order-types#1. Fixes issues: #796, #763, #115, #589, #731, #700, #161, #789, #726, #109, #449, #761, #542, #24, #810, #202, #421, #429, #331, #357, #277, #64, #424, #745, #72, #146, #896, #904, #901, #900, #62, #267, #406, #486, #502, #604, #708, #771, #821, #871 |
||
|
@@ -27,6 +28,25 @@ contract AutomationMaster is IAutomationMaster, Ownable { | |
///each token must have a registered oracle in order to be tradable | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to gfx-labs/oku-custom-order-types#1. Fixes issues: #796, #763, #115, #589, #731, #700, #161, #789, #726, #109, #449, #761, #542, #24, #810, #202, #421, #429, #331, #357, #277, #64, #424, #745, #72, #146, #896, #904, #901, #900, #62, #267, #406, #486, #502, #604, #708, #771, #821, #871 |
||
mapping(IERC20 => IPythRelay) public oracles; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to gfx-labs/oku-custom-order-types#1. Fixes issues: #796, #763, #115, #589, #731, #700, #161, #789, #726, #109, #449, #761, #542, #24, #810, #202, #421, #429, #331, #357, #277, #64, #424, #745, #72, #146, #896, #904, #901, #900, #62, #267, #406, #486, #502, #604, #708, #771, #821, #871 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to gfx-labs/oku-custom-order-types#1. Fixes issues: #796, #763, #115, #589, #731, #700, #161, #789, #726, #109, #449, #761, #542, #24, #810, #202, #421, #429, #331, #357, #277, #64, #424, #745, #72, #146, #896, #904, #901, #900, #62, #267, #406, #486, #502, #604, #708, #771, #821, #871 |
||
mapping(IERC20 => bytes32) public pythIds; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to gfx-labs/oku-custom-order-types#1. Fixes issues: #796, #763, #115, #589, #731, #700, #161, #789, #726, #109, #449, #761, #542, #24, #810, #202, #421, #429, #331, #357, #277, #64, #424, #745, #72, #146, #896, #904, #901, #900, #62, #267, #406, #486, #502, #604, #708, #771, #821, #871 |
||
mapping(address => uint96) private nonces; | ||
|
||
Comment on lines
+31
to
+32
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to gfx-labs/oku-custom-order-types#1. Fixes issues: #796, #763, #115, #589, #731, #700, #161, #789, #726, #109, #449, #761, #542, #24, #810, #202, #421, #429, #331, #357, #277, #64, #424, #745, #72, #146, #896, #904, #901, #900, #62, #267, #406, #486, #502, #604, #708, #771, #821, #871 |
||
constructor(address owner){ | ||
_transferOwnership(owner); | ||
} | ||
|
||
Comment on lines
+33
to
+36
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to gfx-labs/oku-custom-order-types#1. Fixes issues: #796, #763, #115, #589, #731, #700, #161, #789, #726, #109, #449, #761, #542, #24, #810, #202, #421, #429, #331, #357, #277, #64, #424, #745, #72, #146, #896, #904, #901, #900, #62, #267, #406, #486, #502, #604, #708, #771, #821, #871 |
||
function pauseAll( | ||
bool pause, | ||
IOracleLess oracleLessContract | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to gfx-labs/oku-custom-order-types#1. Fixes issues: #796, #763, #115, #589, #731, #700, #161, #789, #726, #109, #449, #761, #542, #24, #810, #202, #421, #429, #331, #357, #277, #64, #424, #745, #72, #146, #896, #904, #901, #900, #62, #267, #406, #486, #502, #604, #708, #771, #821, #871 |
||
) external override onlyOwner { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to gfx-labs/oku-custom-order-types#1. Fixes issues: #796, #763, #115, #589, #731, #700, #161, #789, #726, #109, #449, #761, #542, #24, #810, #202, #421, #429, #331, #357, #277, #64, #424, #745, #72, #146, #896, #904, #901, #900, #62, #267, #406, #486, #502, #604, #708, #771, #821, #871 |
||
if (pause) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to gfx-labs/oku-custom-order-types#1. Fixes issues: #796, #763, #115, #589, #731, #700, #161, #789, #726, #109, #449, #761, #542, #24, #810, #202, #421, #429, #331, #357, #277, #64, #424, #745, #72, #146, #896, #904, #901, #900, #62, #267, #406, #486, #502, #604, #708, #771, #821, #871 |
||
_pause(); | ||
} else { | ||
Comment on lines
+42
to
+43
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to gfx-labs/oku-custom-order-types#1. Fixes issues: #796, #763, #115, #589, #731, #700, #161, #789, #726, #109, #449, #761, #542, #24, #810, #202, #421, #429, #331, #357, #277, #64, #424, #745, #72, #146, #896, #904, #901, #900, #62, #267, #406, #486, #502, #604, #708, #771, #821, #871 |
||
_unpause(); | ||
} | ||
STOP_LIMIT_CONTRACT.pause(pause); | ||
BRACKET_CONTRACT.pause(pause); | ||
oracleLessContract.pause(pause); | ||
} | ||
Comment on lines
+37
to
+49
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to gfx-labs/oku-custom-order-types#1. Fixes issues: #796, #763, #115, #589, #731, #700, #161, #789, #726, #109, #449, #761, #542, #24, #810, #202, #421, #429, #331, #357, #277, #64, #424, #745, #72, #146, #896, #904, #901, #900, #62, #267, #406, #486, #502, #604, #708, #771, #821, #871
Comment on lines
+47
to
+49
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to gfx-labs/oku-custom-order-types#1. Fixes issues: #796, #763, #115, #589, #731, #700, #161, #789, #726, #109, #449, #761, #542, #24, #810, #202, #421, #429, #331, #357, #277, #64, #424, #745, #72, #146, #896, #904, #901, #900, #62, #267, #406, #486, #502, #604, #708, #771, #821, #871 |
||
|
||
///@notice register Stop Limit and Bracket order contracts | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to gfx-labs/oku-custom-order-types#1. Fixes issues: #796, #763, #115, #589, #731, #700, #161, #789, #726, #109, #449, #761, #542, #24, #810, #202, #421, #429, #331, #357, #277, #64, #424, #745, #72, #146, #896, #904, #901, #900, #62, #267, #406, #486, #502, #604, #708, #771, #821, #871 |
||
function registerSubKeepers( | ||
|
@@ -38,13 +58,26 @@ contract AutomationMaster is IAutomationMaster, Ownable { | |
} | ||
|
||
///@notice Registered Oracles are expected to return the USD price in 1e8 terms | ||
///@notice to delist a token, the oracle address in the array should be set to address(0x0) | ||
function registerOracle( | ||
IERC20[] calldata _tokens, | ||
IPythRelay[] calldata _oracles | ||
) external onlyOwner { | ||
require(_tokens.length == _oracles.length, "Array Length Mismatch"); | ||
for (uint i = 0; i < _tokens.length; i++) { | ||
oracles[_tokens[i]] = _oracles[i]; | ||
|
||
for (uint256 i = 0; i < _tokens.length; i++) { | ||
IERC20 token = _tokens[i]; | ||
IPythRelay oracle = _oracles[i]; | ||
|
||
oracles[token] = oracle; | ||
|
||
if (address(oracle) == address(0x0)) { | ||
// Remove the token from the unique set if oracle is address(0x0) | ||
uniqueTokens.remove(address(token)); | ||
} else { | ||
// Add the token to the unique set otherwise | ||
uniqueTokens.add(address(token)); | ||
} | ||
} | ||
} | ||
|
||
|
@@ -61,8 +94,35 @@ contract AutomationMaster is IAutomationMaster, Ownable { | |
///@notice sweep the entire balance of @param token to the owner | ||
///@notice this contract should not hold funds other than collected fees, | ||
///which are forwarded here after each transaction | ||
function sweep(IERC20 token) external onlyOwner { | ||
token.safeTransfer(owner(), token.balanceOf(address(this))); | ||
function sweep(IERC20 token, address recipient) external onlyOwner { | ||
token.safeTransfer(recipient, token.balanceOf(address(this))); | ||
} | ||
|
||
function sweepEther(address payable recipient) external onlyOwner { | ||
uint256 balance = address(this).balance; | ||
require(balance > 0, "No Ether to withdraw"); | ||
require( | ||
recipient != address(0), | ||
"Recipient cannot be the zero address" | ||
); | ||
|
||
(bool success, ) = recipient.call{value: balance}(""); | ||
|
||
require(success, "Ether transfer failed"); | ||
} | ||
|
||
///@notice returns an array of each unique registered token | ||
function getRegisteredTokens() | ||
external | ||
view | ||
override | ||
returns (IERC20[] memory tokens) | ||
{ | ||
uint256 length = uniqueTokens.length(); | ||
tokens = new IERC20[](length); | ||
for (uint256 i = 0; i < length; i++) { | ||
tokens[i] = IERC20(uniqueTokens.at(i)); | ||
} | ||
} | ||
|
||
///@notice Registered Oracles are expected to return the USD price in 1e8 terms | ||
|
@@ -87,9 +147,14 @@ contract AutomationMaster is IAutomationMaster, Ownable { | |
} | ||
|
||
///@notice generate a random and unique order id | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to gfx-labs/oku-custom-order-types#1. Fixes issues: #796, #763, #115, #589, #731, #700, #161, #789, #726, #109, #449, #761, #542, #24, #810, #202, #421, #429, #331, #357, #277, #64, #424, #745, #72, #146, #896, #904, #901, #900, #62, #267, #406, #486, #502, #604, #708, #771, #821, #871 |
||
function generateOrderId(address sender) external view override returns (uint96) { | ||
function generateOrderId( | ||
address sender | ||
) external override returns (uint96) { | ||
uint96 nonce = nonces[sender]++; | ||
Comment on lines
+150
to
+153
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to gfx-labs/oku-custom-order-types#1. Fixes issues: #796, #763, #115, #589, #731, #700, #161, #789, #726, #109, #449, #761, #542, #24, #810, #202, #421, #429, #331, #357, #277, #64, #424, #745, #72, #146, #896, #904, #901, #900, #62, #267, #406, #486, #502, #604, #708, #771, #821, #871 |
||
uint256 hashedValue = uint256( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to gfx-labs/oku-custom-order-types#1. Fixes issues: #796, #763, #115, #589, #731, #700, #161, #789, #726, #109, #449, #761, #542, #24, #810, #202, #421, #429, #331, #357, #277, #64, #424, #745, #72, #146, #896, #904, #901, #900, #62, #267, #406, #486, #502, #604, #708, #771, #821, #871 |
||
keccak256(abi.encodePacked(sender, block.timestamp)) | ||
keccak256( | ||
abi.encodePacked(sender, nonce, blockhash(block.number - 1)) | ||
) | ||
Comment on lines
+155
to
+157
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to gfx-labs/oku-custom-order-types#1. Fixes issues: #796, #763, #115, #589, #731, #700, #161, #789, #726, #109, #449, #761, #542, #24, #810, #202, #421, #429, #331, #357, #277, #64, #424, #745, #72, #146, #896, #904, #901, #900, #62, #267, #406, #486, #502, #604, #708, #771, #821, #871 |
||
); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to gfx-labs/oku-custom-order-types#1. Fixes issues: #796, #763, #115, #589, #731, #700, #161, #789, #726, #109, #449, #761, #542, #24, #810, #202, #421, #429, #331, #357, #277, #64, #424, #745, #72, #146, #896, #904, #901, #900, #62, #267, #406, #486, #502, #604, #708, #771, #821, #871 |
||
return uint96(hashedValue); | ||
} | ||
|
@@ -141,7 +206,10 @@ contract AutomationMaster is IAutomationMaster, Ownable { | |
|
||
///@notice determine if a new order meets the minimum order size requirement | ||
///Value of @param amountIn of @param tokenIn must meed the minimum USD value | ||
Comment on lines
207
to
208
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to gfx-labs/oku-custom-order-types#1. Fixes issues: #796, #763, #115, #589, #731, #700, #161, #789, #726, #109, #449, #761, #542, #24, #810, #202, #421, #429, #331, #357, #277, #64, #424, #745, #72, #146, #896, #904, #901, #900, #62, #267, #406, #486, #502, #604, #708, #771, #821, #871 |
||
function checkMinOrderSize(IERC20 tokenIn, uint256 amountIn) external view override { | ||
function checkMinOrderSize( | ||
IERC20 tokenIn, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to gfx-labs/oku-custom-order-types#1. Fixes issues: #796, #763, #115, #589, #731, #700, #161, #789, #726, #109, #449, #761, #542, #24, #810, #202, #421, #429, #331, #357, #277, #64, #424, #745, #72, #146, #896, #904, #901, #900, #62, #267, #406, #486, #502, #604, #708, #771, #821, #871 |
||
uint256 amountIn | ||
) external view override { | ||
Comment on lines
+209
to
+212
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to gfx-labs/oku-custom-order-types#1. Fixes issues: #796, #763, #115, #589, #731, #700, #161, #789, #726, #109, #449, #761, #542, #24, #810, #202, #421, #429, #331, #357, #277, #64, #424, #745, #72, #146, #896, #904, #901, #900, #62, #267, #406, #486, #502, #604, #708, #771, #821, #871 |
||
uint256 currentPrice = oracles[tokenIn].currentValue(); | ||
uint256 usdValue = (currentPrice * amountIn) / | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to gfx-labs/oku-custom-order-types#1. Fixes issues: #796, #763, #115, #589, #731, #700, #161, #789, #726, #109, #449, #761, #542, #24, #810, #202, #421, #429, #331, #357, #277, #64, #424, #745, #72, #146, #896, #904, #901, #900, #62, #267, #406, #486, #502, #604, #708, #771, #821, #871 |
||
(10 ** ERC20(address(tokenIn)).decimals()); | ||
|
@@ -151,28 +219,32 @@ contract AutomationMaster is IAutomationMaster, Ownable { | |
|
||
///@notice check upkeep on all order types | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to gfx-labs/oku-custom-order-types#1. Fixes issues: #796, #763, #115, #589, #731, #700, #161, #789, #726, #109, #449, #761, #542, #24, #810, #202, #421, #429, #331, #357, #277, #64, #424, #745, #72, #146, #896, #904, #901, #900, #62, #267, #406, #486, #502, #604, #708, #771, #821, #871 |
||
function checkUpkeep( | ||
bytes calldata | ||
bytes calldata checkData | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to gfx-labs/oku-custom-order-types#1. Fixes issues: #796, #763, #115, #589, #731, #700, #161, #789, #726, #109, #449, #761, #542, #24, #810, #202, #421, #429, #331, #357, #277, #64, #424, #745, #72, #146, #896, #904, #901, #900, #62, #267, #406, #486, #502, #604, #708, #771, #821, #871 |
||
) | ||
external | ||
view | ||
override | ||
returns (bool upkeepNeeded, bytes memory performData) | ||
{ | ||
//check stop limit order | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to gfx-labs/oku-custom-order-types#1. Fixes issues: #796, #763, #115, #589, #731, #700, #161, #789, #726, #109, #449, #761, #542, #24, #810, #202, #421, #429, #331, #357, #277, #64, #424, #745, #72, #146, #896, #904, #901, #900, #62, #267, #406, #486, #502, #604, #708, #771, #821, #871 |
||
(upkeepNeeded, performData) = STOP_LIMIT_CONTRACT.checkUpkeep("0x"); | ||
(upkeepNeeded, performData) = STOP_LIMIT_CONTRACT.checkUpkeep( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to gfx-labs/oku-custom-order-types#1. Fixes issues: #796, #763, #115, #589, #731, #700, #161, #789, #726, #109, #449, #761, #542, #24, #810, #202, #421, #429, #331, #357, #277, #64, #424, #745, #72, #146, #896, #904, #901, #900, #62, #267, #406, #486, #502, #604, #708, #771, #821, #871 |
||
checkData | ||
); | ||
Comment on lines
+230
to
+232
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to gfx-labs/oku-custom-order-types#1. Fixes issues: #796, #763, #115, #589, #731, #700, #161, #789, #726, #109, #449, #761, #542, #24, #810, #202, #421, #429, #331, #357, #277, #64, #424, #745, #72, #146, #896, #904, #901, #900, #62, #267, #406, #486, #502, #604, #708, #771, #821, #871 |
||
if (upkeepNeeded) { | ||
return (true, performData); | ||
Comment on lines
+231
to
234
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to gfx-labs/oku-custom-order-types#1. Fixes issues: #796, #763, #115, #589, #731, #700, #161, #789, #726, #109, #449, #761, #542, #24, #810, #202, #421, #429, #331, #357, #277, #64, #424, #745, #72, #146, #896, #904, #901, #900, #62, #267, #406, #486, #502, #604, #708, #771, #821, #871 |
||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to gfx-labs/oku-custom-order-types#1. Fixes issues: #796, #763, #115, #589, #731, #700, #161, #789, #726, #109, #449, #761, #542, #24, #810, #202, #421, #429, #331, #357, #277, #64, #424, #745, #72, #146, #896, #904, #901, #900, #62, #267, #406, #486, #502, #604, #708, #771, #821, #871 |
||
|
||
//check bracket order | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to gfx-labs/oku-custom-order-types#1. Fixes issues: #796, #763, #115, #589, #731, #700, #161, #789, #726, #109, #449, #761, #542, #24, #810, #202, #421, #429, #331, #357, #277, #64, #424, #745, #72, #146, #896, #904, #901, #900, #62, #267, #406, #486, #502, #604, #708, #771, #821, #871 |
||
(upkeepNeeded, performData) = BRACKET_CONTRACT.checkUpkeep("0x"); | ||
(upkeepNeeded, performData) = BRACKET_CONTRACT.checkUpkeep(checkData); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to gfx-labs/oku-custom-order-types#1. Fixes issues: #796, #763, #115, #589, #731, #700, #161, #789, #726, #109, #449, #761, #542, #24, #810, #202, #421, #429, #331, #357, #277, #64, #424, #745, #72, #146, #896, #904, #901, #900, #62, #267, #406, #486, #502, #604, #708, #771, #821, #871
Comment on lines
236
to
+238
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to gfx-labs/oku-custom-order-types#1. Fixes issues: #796, #763, #115, #589, #731, #700, #161, #789, #726, #109, #449, #761, #542, #24, #810, #202, #421, #429, #331, #357, #277, #64, #424, #745, #72, #146, #896, #904, #901, #900, #62, #267, #406, #486, #502, #604, #708, #771, #821, #871 |
||
if (upkeepNeeded) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to gfx-labs/oku-custom-order-types#1. Fixes issues: #796, #763, #115, #589, #731, #700, #161, #789, #726, #109, #449, #761, #542, #24, #810, #202, #421, #429, #331, #357, #277, #64, #424, #745, #72, #146, #896, #904, #901, #900, #62, #267, #406, #486, #502, #604, #708, #771, #821, #871 |
||
return (true, performData); | ||
} | ||
} | ||
|
||
///@notice perform upkeep on any order type | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to gfx-labs/oku-custom-order-types#1. Fixes issues: #796, #763, #115, #589, #731, #700, #161, #789, #726, #109, #449, #761, #542, #24, #810, #202, #421, #429, #331, #357, #277, #64, #424, #745, #72, #146, #896, #904, #901, #900, #62, #267, #406, #486, #502, #604, #708, #771, #821, #871 |
||
function performUpkeep(bytes calldata performData) external override { | ||
function performUpkeep( | ||
Comment on lines
243
to
+245
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to gfx-labs/oku-custom-order-types#1. Fixes issues: #796, #763, #115, #589, #731, #700, #161, #789, #726, #109, #449, #761, #542, #24, #810, #202, #421, #429, #331, #357, #277, #64, #424, #745, #72, #146, #896, #904, #901, #900, #62, #267, #406, #486, #502, #604, #708, #771, #821, #871 |
||
bytes calldata performData | ||
) external override whenNotPaused { | ||
Comment on lines
+245
to
+247
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Change related to gfx-labs/oku-custom-order-types#1. Fixes issues: #796, #763, #115, #589, #731, #700, #161, #789, #726, #109, #449, #761, #542, #24, #810, #202, #421, #429, #331, #357, #277, #64, #424, #745, #72, #146, #896, #904, #901, #900, #62, #267, #406, #486, #502, #604, #708, #771, #821, #871 |
||
//decode into masterUpkeepData | ||
MasterUpkeepData memory data = abi.decode( | ||
performData, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
diff a/oku-custom-order-types/contracts/automatedTrigger/AutomationMaster.sol b/oku-custom-order-types/contracts/automatedTrigger/AutomationMaster.sol (rejected hunks) | ||
@@ -2,17 +2,20 @@ | ||
pragma solidity ^0.8.19; | ||
|
||
import "./IAutomation.sol"; | ||
+import "../oracle/IPythRelay.sol"; | ||
import "../libraries/ArrayMutation.sol"; | ||
import "../interfaces/openzeppelin/Ownable.sol"; | ||
import "../interfaces/openzeppelin/ERC20.sol"; | ||
import "../interfaces/openzeppelin/IERC20.sol"; | ||
import "../interfaces/openzeppelin/SafeERC20.sol"; | ||
-import "../oracle/IPythRelay.sol"; | ||
+import "../interfaces/openzeppelin/Pausable.sol"; | ||
+import "../interfaces/openzeppelin/EnumerableSet.sol"; | ||
|
||
///@notice This contract owns and handles all of the settings and accounting logic for automated swaps | ||
///@notice This contract should not hold any user funds, only collected fees | ||
-contract AutomationMaster is IAutomationMaster, Ownable { | ||
+contract AutomationMaster is IAutomationMaster, Ownable, Pausable { | ||
using SafeERC20 for IERC20; | ||
+ using EnumerableSet for EnumerableSet.AddressSet; | ||
|
||
///@notice maximum pending orders that may exist at a time, limiting the compute requriement for checkUpkeep | ||
uint16 public maxPendingOrders; | ||
@@ -20,13 +23,71 @@ contract AutomationMaster is IAutomationMaster, Ownable { | ||
///@notice minumum USD value required to create a new order, in 1e8 terms | ||
uint256 public minOrderSize; | ||
|
||
+ ///@notice fee to create an order, in order to deter spam | ||
+ uint256 public orderFee; | ||
+ | ||
///sub keeper contracts | ||
IStopLimit public STOP_LIMIT_CONTRACT; | ||
IBracket public BRACKET_CONTRACT; | ||
|
||
+ //whitelist of possible target contracts to execute swaps | ||
+ mapping(address => bool) public safeTargets; | ||
+ | ||
+ //whitelist of wallets allowed to set targets | ||
+ mapping(address => bool) public targetSetters; | ||
+ | ||
///each token must have a registered oracle in order to be tradable | ||
mapping(IERC20 => IPythRelay) public oracles; | ||
mapping(IERC20 => bytes32) public pythIds; | ||
+ mapping(address => uint96) private nonces; | ||
+ | ||
+ EnumerableSet.AddressSet private uniqueTokens; | ||
+ | ||
+ constructor(address owner) { | ||
+ _transferOwnership(owner); | ||
+ } | ||
+ | ||
+ receive() external payable {} | ||
+ | ||
+ function pauseAll( | ||
+ bool pause, | ||
+ IOracleLess oracleLessContract | ||
+ ) external override onlyOwner { | ||
+ if (pause) { | ||
+ _pause(); | ||
+ } else { | ||
+ _unpause(); | ||
+ } | ||
+ STOP_LIMIT_CONTRACT.pause(pause); | ||
+ BRACKET_CONTRACT.pause(pause); | ||
+ oracleLessContract.pause(pause); | ||
+ } | ||
+ | ||
+ ///@notice set the fee to create / modify orders | ||
+ ///@notice fee is taken from msg.value in the native gas token | ||
+ ///@param _orderFee is in wei | ||
+ function setOrderFee(uint256 _orderFee) external override onlyOwner { | ||
+ orderFee = _orderFee; | ||
+ } | ||
+ | ||
+ function whitelistTargetSetter( | ||
+ address wallet, | ||
+ bool canSet | ||
+ ) external onlyOwner { | ||
+ targetSetters[wallet] = canSet; | ||
+ } | ||
+ | ||
+ ///@notice toggle each idx in @param targets to be true/false as a valid target | ||
+ function whitelistTargets(address[] calldata targets) external { | ||
+ require(targetSetters[msg.sender], "!Allowed to set targets"); | ||
+ for (uint i = 0; i < targets.length; i++) { | ||
+ safeTargets[targets[i]] = !safeTargets[targets[i]]; | ||
+ } | ||
+ } | ||
+ | ||
+ function validateTarget(address target) external view override { | ||
+ require(safeTargets[target], "Target !Valid"); | ||
+ } | ||
|
||
///@notice register Stop Limit and Bracket order contracts | ||
function registerSubKeepers( | ||
@@ -87,9 +188,14 @@ contract AutomationMaster is IAutomationMaster, Ownable { | ||
} | ||
|
||
///@notice generate a random and unique order id | ||
- function generateOrderId(address sender) external view override returns (uint96) { | ||
+ function generateOrderId( | ||
+ address sender | ||
+ ) external override returns (uint96) { | ||
+ uint96 nonce = nonces[sender]++; | ||
uint256 hashedValue = uint256( | ||
- keccak256(abi.encodePacked(sender, block.timestamp)) | ||
+ keccak256( | ||
+ abi.encodePacked(sender, nonce, blockhash(block.number - 1)) | ||
+ ) | ||
); | ||
return uint96(hashedValue); | ||
} | ||
@@ -141,7 +247,10 @@ contract AutomationMaster is IAutomationMaster, Ownable { | ||
|
||
///@notice determine if a new order meets the minimum order size requirement | ||
///Value of @param amountIn of @param tokenIn must meed the minimum USD value | ||
- function checkMinOrderSize(IERC20 tokenIn, uint256 amountIn) external view override { | ||
+ function checkMinOrderSize( | ||
+ IERC20 tokenIn, | ||
+ uint256 amountIn | ||
+ ) external view override { | ||
uint256 currentPrice = oracles[tokenIn].currentValue(); | ||
uint256 usdValue = (currentPrice * amountIn) / | ||
(10 ** ERC20(address(tokenIn)).decimals()); | ||
@@ -151,7 +260,7 @@ contract AutomationMaster is IAutomationMaster, Ownable { | ||
|
||
///@notice check upkeep on all order types | ||
function checkUpkeep( | ||
- bytes calldata | ||
+ bytes calldata checkData | ||
) | ||
external | ||
view | ||
@@ -159,20 +268,24 @@ contract AutomationMaster is IAutomationMaster, Ownable { | ||
returns (bool upkeepNeeded, bytes memory performData) | ||
{ | ||
//check stop limit order | ||
- (upkeepNeeded, performData) = STOP_LIMIT_CONTRACT.checkUpkeep("0x"); | ||
+ (upkeepNeeded, performData) = STOP_LIMIT_CONTRACT.checkUpkeep( | ||
+ checkData | ||
+ ); | ||
if (upkeepNeeded) { | ||
return (true, performData); | ||
} | ||
|
||
//check bracket order | ||
- (upkeepNeeded, performData) = BRACKET_CONTRACT.checkUpkeep("0x"); | ||
+ (upkeepNeeded, performData) = BRACKET_CONTRACT.checkUpkeep(checkData); | ||
if (upkeepNeeded) { | ||
return (true, performData); | ||
} | ||
} | ||
|
||
///@notice perform upkeep on any order type | ||
- function performUpkeep(bytes calldata performData) external override { | ||
+ function performUpkeep( | ||
+ bytes calldata performData | ||
+ ) external override whenNotPaused { | ||
//decode into masterUpkeepData | ||
MasterUpkeepData memory data = abi.decode( | ||
performData, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change related to gfx-labs/oku-custom-order-types#1.
Fixes issues: #796, #763, #115, #589, #731, #700, #161, #789, #726, #109, #449, #761, #542, #24, #810, #202, #421, #429, #331, #357, #277, #64, #424, #745, #72, #146, #896, #904, #901, #900, #62, #267, #406, #486, #502, #604, #708, #771, #821, #871