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

Fix Review #1

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@
pragma solidity ^0.8.19;

import "./IAutomation.sol";
import "../oracle/IPythRelay.sol";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import "../libraries/ArrayMutation.sol";
import "../interfaces/openzeppelin/Ownable.sol";
import "../interfaces/openzeppelin/ERC20.sol";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

import "../interfaces/openzeppelin/IERC20.sol";
import "../interfaces/openzeppelin/SafeERC20.sol";
import "../oracle/IPythRelay.sol";
import "../interfaces/openzeppelin/Pausable.sol";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


Comment on lines +11 to 12
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

///@notice This contract owns and handles all of the settings and accounting logic for automated swaps
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

///@notice This contract should not hold any user funds, only collected fees
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

contract AutomationMaster is IAutomationMaster, Ownable {
contract AutomationMaster is IAutomationMaster, Ownable, Pausable {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using SafeERC20 for IERC20;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


///@notice maximum pending orders that may exist at a time, limiting the compute requriement for checkUpkeep
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expand All @@ -27,6 +28,25 @@ contract AutomationMaster is IAutomationMaster, Ownable {
///each token must have a registered oracle in order to be tradable
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mapping(IERC20 => IPythRelay) public oracles;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mapping(IERC20 => bytes32) public pythIds;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mapping(address => uint96) private nonces;

Comment on lines +31 to +32
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

constructor(address owner){
_transferOwnership(owner);
}

Comment on lines +33 to +36
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

function pauseAll(
bool pause,
IOracleLess oracleLessContract
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

) external override onlyOwner {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (pause) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_pause();
} else {
Comment on lines +42 to +43
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_unpause();
}
STOP_LIMIT_CONTRACT.pause(pause);
BRACKET_CONTRACT.pause(pause);
oracleLessContract.pause(pause);
}
Comment on lines +37 to +49
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +47 to +49
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


///@notice register Stop Limit and Bracket order contracts
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

function registerSubKeepers(
Expand Down Expand Up @@ -87,9 +107,14 @@ contract AutomationMaster is IAutomationMaster, Ownable {
}

///@notice generate a random and unique order id
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uint256 hashedValue = uint256(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

keccak256(abi.encodePacked(sender, block.timestamp))
keccak256(
abi.encodePacked(sender, nonce, blockhash(block.number - 1))
)
Comment on lines +155 to +157
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return uint96(hashedValue);
}
Expand Down Expand Up @@ -141,7 +166,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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

function checkMinOrderSize(IERC20 tokenIn, uint256 amountIn) external view override {
function checkMinOrderSize(
IERC20 tokenIn,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uint256 amountIn
) external view override {
Comment on lines +209 to +212
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uint256 currentPrice = oracles[tokenIn].currentValue();
uint256 usdValue = (currentPrice * amountIn) /
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(10 ** ERC20(address(tokenIn)).decimals());
Expand All @@ -151,28 +179,32 @@ contract AutomationMaster is IAutomationMaster, Ownable {

///@notice check upkeep on all order types
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

function checkUpkeep(
bytes calldata
bytes calldata checkData
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

)
external
view
override
returns (bool upkeepNeeded, bytes memory performData)
{
//check stop limit order
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(upkeepNeeded, performData) = STOP_LIMIT_CONTRACT.checkUpkeep("0x");
(upkeepNeeded, performData) = STOP_LIMIT_CONTRACT.checkUpkeep(
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

checkData
);
Comment on lines +230 to +232
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (upkeepNeeded) {
return (true, performData);
Comment on lines +231 to 234
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


//check bracket order
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(upkeepNeeded, performData) = BRACKET_CONTRACT.checkUpkeep("0x");
(upkeepNeeded, performData) = BRACKET_CONTRACT.checkUpkeep(checkData);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 236 to +238
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if (upkeepNeeded) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return (true, performData);
}
}

///@notice perform upkeep on any order type
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

function performUpkeep(bytes calldata performData) external override {
function performUpkeep(
Comment on lines 243 to +245
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

bytes calldata performData
) external override whenNotPaused {
Comment on lines +245 to +247
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

//decode into masterUpkeepData
MasterUpkeepData memory data = abi.decode(
performData,
Expand Down
Loading