pragma solidity 0.4.25;
// File: openzeppelin-solidity-v1.12.0/contracts/ownership/Ownable.sol
/**
* @title Ownable
* @dev The Ownable contract has an owner address, and provides basic authorization control
* functions, this simplifies the implementation of "user permissions".
*/
contract Ownable {
address public owner;
event OwnershipRenounced(address indexed previousOwner);
event OwnershipTransferred(
address indexed previousOwner,
address indexed newOwner
);
/**
* @dev The Ownable constructor sets the original `owner` of the contract to the sender
* account.
*/
constructor() public {
owner = msg.sender;
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
require(msg.sender == owner);
_;
}
/**
* @dev Allows the current owner to relinquish control of the contract.
* @notice Renouncing to ownership will leave the contract without an owner.
* It will not be possible to call the functions with the `onlyOwner`
* modifier anymore.
*/
function renounceOwnership() public onlyOwner {
emit OwnershipRenounced(owner);
owner = address(0);
}
/**
* @dev Allows the current owner to transfer control of the contract to a newOwner.
* @param _newOwner The address to transfer ownership to.
*/
function transferOwnership(address _newOwner) public onlyOwner {
_transferOwnership(_newOwner);
}
/**
* @dev Transfers control of the contract to a newOwner.
* @param _newOwner The address to transfer ownership to.
*/
function _transferOwnership(address _newOwner) internal {
require(_newOwner != address(0));
emit OwnershipTransferred(owner, _newOwner);
owner = _newOwner;
}
}
// File: openzeppelin-solidity-v1.12.0/contracts/ownership/Claimable.sol
/**
* @title Claimable
* @dev Extension for the Ownable contract, where the ownership needs to be claimed.
* This allows the new owner to accept the transfer.
*/
contract Claimable is Ownable {
address public pendingOwner;
/**
* @dev Modifier throws if called by any account other than the pendingOwner.
*/
modifier onlyPendingOwner() {
require(msg.sender == pendingOwner);
_;
}
/**
* @dev Allows the current owner to set the pendingOwner address.
* @param newOwner The address to transfer ownership to.
*/
function transferOwnership(address newOwner) public onlyOwner {
pendingOwner = newOwner;
}
/**
* @dev Allows the pendingOwner address to finalize the transfer.
*/
function claimOwnership() public onlyPendingOwner {
emit OwnershipTransferred(owner, pendingOwner);
owner = pendingOwner;
pendingOwner = address(0);
}
}
// File: contracts/utils/Adminable.sol
/**
* @title Adminable.
*/
contract Adminable is Claimable {
address[] public adminArray;
struct AdminInfo {
bool valid;
uint256 index;
}
mapping(address => AdminInfo) public adminTable;
event AdminAccepted(address indexed _admin);
event AdminRejected(address indexed _admin);
/**
* @dev Reverts if called by any account other than one of the administrators.
*/
modifier onlyAdmin() {
require(adminTable[msg.sender].valid, "caller is illegal");
_;
}
/**
* @dev Accept a new administrator.
* @param _admin The administrator's address.
*/
function accept(address _admin) external onlyOwner {
require(_admin != address(0), "administrator is illegal");
AdminInfo storage adminInfo = adminTable[_admin];
require(!adminInfo.valid, "administrator is already accepted");
adminInfo.valid = true;
adminInfo.index = adminArray.length;
adminArray.push(_admin);
emit AdminAccepted(_admin);
}
/**
* @dev Reject an existing administrator.
* @param _admin The administrator's address.
*/
function reject(address _admin) external onlyOwner {
AdminInfo storage adminInfo = adminTable[_admin];
require(adminArray.length > adminInfo.index, "administrator is already rejected");
require(_admin == adminArray[adminInfo.index], "administrator is already rejected");
// at this point we know that adminArray.length > adminInfo.index >= 0
address lastAdmin = adminArray[adminArray.length - 1]; // will never underflow
adminTable[lastAdmin].index = adminInfo.index;
adminArray[adminInfo.index] = lastAdmin;
adminArray.length -= 1; // will never underflow
delete adminTable[_admin];
emit AdminRejected(_admin);
}
/**
* @dev Get an array of all the administrators.
* @return An array of all the administrators.
*/
function getAdminArray() external view returns (address[] memory) {
return adminArray;
}
/**
* @dev Get the total number of administrators.
* @return The total number of administrators.
*/
function getAdminCount() external view returns (uint256) {
return adminArray.length;
}
}
// File: contracts/wallet_trading_limiter/interfaces/IWalletsTradingLimiterValueConverter.sol
/**
* @title Wallets Trading Limiter Value Converter Interface.
*/
interface IWalletsTradingLimiterValueConverter {
/**
* @dev Get the current limiter currency worth of a given SGR amount.
* @param _sgrAmount The amount of SGR to convert.
* @return The equivalent amount of the limiter currency.
*/
function toLimiterValue(uint256 _sgrAmount) external view returns (uint256);
}
// File: openzeppelin-solidity/contracts/math/SafeMath.sol
/**
* @title SafeMath
* @dev Math operations with safety checks that revert on error
*/
library SafeMath {
/**
* @dev Multiplies two numbers, reverts on overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
// Gas optimization: this is cheaper than requiring 'a' not being zero, but the
// benefit is lost if 'b' is also tested.
// See: https://github.com/OpenZeppelin/openzeppelin-solidity/pull/522
if (a == 0) {
return 0;
}
uint256 c = a * b;
require(c / a == b);
return c;
}
/**
* @dev Integer division of two numbers truncating the quotient, reverts on division by zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
require(b > 0); // Solidity only automatically asserts when dividing by 0
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
return c;
}
/**
* @dev Subtracts two numbers, reverts on overflow (i.e. if subtrahend is greater than minuend).
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
require(b <= a);
uint256 c = a - b;
return c;
}
/**
* @dev Adds two numbers, reverts on overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
uint256 c = a + b;
require(c >= a);
return c;
}
/**
* @dev Divides two numbers and returns the remainder (unsigned integer modulo),
* reverts when dividing by zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
require(b != 0);
return a % b;
}
}
// File: contracts/wallet_trading_limiter/WalletsTradingLimiterValueConverter.sol
/**
* Details of usage of licenced software see here: https://www.sogur.com/software/readme_v1
*/
/**
* @title Wallets Trading Limiter Value Converter.
*/
contract WalletsTradingLimiterValueConverter is IWalletsTradingLimiterValueConverter, Adminable {
string public constant VERSION = "1.0.1";
using SafeMath for uint256;
/**
* @dev price maximum resolution.
* @notice Allow for sufficiently-high resolution.
* @notice Prevents multiplication-overflow.
*/
uint256 public constant MAX_RESOLUTION = 0x10000000000000000;
uint256 public sequenceNum = 0;
uint256 public priceN = 0;
uint256 public priceD = 0;
event PriceSaved(uint256 _priceN, uint256 _priceD);
event PriceNotSaved(uint256 _priceN, uint256 _priceD);
/**
* @dev Set the price.
* @param _sequenceNum The sequence-number of the operation.
* @param _priceN The numerator of the price.
* @param _priceD The denominator of the price.
*/
function setPrice(uint256 _sequenceNum, uint256 _priceN, uint256 _priceD) external onlyAdmin {
require(1 <= _priceN && _priceN <= MAX_RESOLUTION, "price numerator is out of range");
require(1 <= _priceD && _priceD <= MAX_RESOLUTION, "price denominator is out of range");
if (sequenceNum < _sequenceNum) {
sequenceNum = _sequenceNum;
priceN = _priceN;
priceD = _priceD;
emit PriceSaved(_priceN, _priceD);
}
else {
emit PriceNotSaved(_priceN, _priceD);
}
}
/**
* @dev Get the current limiter worth of a given SGR amount.
* @param _sgrAmount The amount of SGR to convert.
* @return The equivalent limiter amount.
*/
function toLimiterValue(uint256 _sgrAmount) external view returns (uint256) {
assert(priceN > 0 && priceD > 0);
return _sgrAmount.mul(priceN) / priceD;
}
}
{
"compilationTarget": {
"WalletsTradingLimiterValueConverter.sol": "WalletsTradingLimiterValueConverter"
},
"evmVersion": "byzantium",
"libraries": {},
"optimizer": {
"enabled": true,
"runs": 6000
},
"remappings": []
}
[{"constant":true,"inputs":[{"name":"","type":"address"}],"name":"adminTable","outputs":[{"name":"valid","type":"bool"},{"name":"index","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"sequenceNum","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"claimOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[],"name":"renounceOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"name":"_sgrAmount","type":"uint256"}],"name":"toLimiterValue","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getAdminArray","outputs":[{"name":"","type":"address[]"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"getAdminCount","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"name":"","type":"uint256"}],"name":"adminArray","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"_admin","type":"address"}],"name":"accept","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_sequenceNum","type":"uint256"},{"name":"_priceN","type":"uint256"},{"name":"_priceD","type":"uint256"}],"name":"setPrice","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"name":"_admin","type":"address"}],"name":"reject","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"priceD","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"priceN","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"pendingOwner","outputs":[{"name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"MAX_RESOLUTION","outputs":[{"name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"name":"newOwner","type":"address"}],"name":"transferOwnership","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[],"name":"VERSION","outputs":[{"name":"","type":"string"}],"payable":false,"stateMutability":"view","type":"function"},{"anonymous":false,"inputs":[{"indexed":false,"name":"_priceN","type":"uint256"},{"indexed":false,"name":"_priceD","type":"uint256"}],"name":"PriceSaved","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"name":"_priceN","type":"uint256"},{"indexed":false,"name":"_priceD","type":"uint256"}],"name":"PriceNotSaved","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_admin","type":"address"}],"name":"AdminAccepted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"_admin","type":"address"}],"name":"AdminRejected","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"previousOwner","type":"address"}],"name":"OwnershipRenounced","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"name":"previousOwner","type":"address"},{"indexed":true,"name":"newOwner","type":"address"}],"name":"OwnershipTransferred","type":"event"}]