-
Notifications
You must be signed in to change notification settings - Fork 1
/
CurrencyManager.sol
83 lines (67 loc) · 2.67 KB
/
CurrencyManager.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 {ICurrencyManager} from "./interfaces/ICurrencyManager.sol";
/**
* @title CurrencyManager
* @notice It allows adding/removing currencies for trading on the LooksRare exchange.
*/
contract CurrencyManager is ICurrencyManager, Ownable {
using EnumerableSet for EnumerableSet.AddressSet;
EnumerableSet.AddressSet private _whitelistedCurrencies;
event CurrencyRemoved(address indexed currency);
event CurrencyWhitelisted(address indexed currency);
/**
* @notice Add a currency in the system
* @param currency address of the currency to add
*/
function addCurrency(address currency) external override onlyOwner {
require(!_whitelistedCurrencies.contains(currency), "Currency: Already whitelisted");
_whitelistedCurrencies.add(currency);
emit CurrencyWhitelisted(currency);
}
/**
* @notice Remove a currency from the system
* @param currency address of the currency to remove
*/
function removeCurrency(address currency) external override onlyOwner {
require(_whitelistedCurrencies.contains(currency), "Currency: Not whitelisted");
_whitelistedCurrencies.remove(currency);
emit CurrencyRemoved(currency);
}
/**
* @notice Returns if a currency is in the system
* @param currency address of the currency
*/
function isCurrencyWhitelisted(address currency) external view override returns (bool) {
return _whitelistedCurrencies.contains(currency);
}
/**
* @notice View number of whitelisted currencies
*/
function viewCountWhitelistedCurrencies() external view override returns (uint256) {
return _whitelistedCurrencies.length();
}
/**
* @notice See whitelisted currencies in the system
* @param cursor cursor (should start at 0 for first request)
* @param size size of the response (e.g., 50)
*/
function viewWhitelistedCurrencies(uint256 cursor, uint256 size)
external
view
override
returns (address[] memory, uint256)
{
uint256 length = size;
if (length > _whitelistedCurrencies.length() - cursor) {
length = _whitelistedCurrencies.length() - cursor;
}
address[] memory whitelistedCurrencies = new address[](length);
for (uint256 i = 0; i < length; i++) {
whitelistedCurrencies[i] = _whitelistedCurrencies.at(cursor + i);
}
return (whitelistedCurrencies, cursor + length);
}
}