-
Notifications
You must be signed in to change notification settings - Fork 1
/
ExecutionManager.sol
83 lines (67 loc) · 2.72 KB
/
ExecutionManager.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {EnumerableSet} from "@openzeppelin/contracts/utils/structs/EnumerableSet.sol";
import {IExecutionManager} from "./interfaces/IExecutionManager.sol";
/**
* @title ExecutionManager
* @notice It allows adding/removing execution strategies for trading on the LooksRare exchange.
*/
contract ExecutionManager is IExecutionManager, Ownable {
using EnumerableSet for EnumerableSet.AddressSet;
EnumerableSet.AddressSet private _whitelistedStrategies;
event StrategyRemoved(address indexed strategy);
event StrategyWhitelisted(address indexed strategy);
/**
* @notice Add an execution strategy in the system
* @param strategy address of the strategy to add
*/
function addStrategy(address strategy) external override onlyOwner {
require(!_whitelistedStrategies.contains(strategy), "Strategy: Already whitelisted");
_whitelistedStrategies.add(strategy);
emit StrategyWhitelisted(strategy);
}
/**
* @notice Remove an execution strategy from the system
* @param strategy address of the strategy to remove
*/
function removeStrategy(address strategy) external override onlyOwner {
require(_whitelistedStrategies.contains(strategy), "Strategy: Not whitelisted");
_whitelistedStrategies.remove(strategy);
emit StrategyRemoved(strategy);
}
/**
* @notice Returns if an execution strategy is in the system
* @param strategy address of the strategy
*/
function isStrategyWhitelisted(address strategy) external view override returns (bool) {
return _whitelistedStrategies.contains(strategy);
}
/**
* @notice View number of whitelisted strategies
*/
function viewCountWhitelistedStrategies() external view override returns (uint256) {
return _whitelistedStrategies.length();
}
/**
* @notice See whitelisted strategies in the system
* @param cursor cursor (should start at 0 for first request)
* @param size size of the response (e.g., 50)
*/
function viewWhitelistedStrategies(uint256 cursor, uint256 size)
external
view
override
returns (address[] memory, uint256)
{
uint256 length = size;
if (length > _whitelistedStrategies.length() - cursor) {
length = _whitelistedStrategies.length() - cursor;
}
address[] memory whitelistedStrategies = new address[](length);
for (uint256 i = 0; i < length; i++) {
whitelistedStrategies[i] = _whitelistedStrategies.at(cursor + i);
}
return (whitelistedStrategies, cursor + length);
}
}