Source Code
Overview
ETH Balance
0 ETH
ETH Value
$0.00
Cross-Chain Transactions
Loading...
Loading
Contract Name:
RewardStore
Compiler Version
v0.8.17+commit.8df45f5f
Optimization Enabled:
Yes with 100 runs
Other Settings:
default evmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.17;
import '../utils/Roles.sol';
/// @title RewardStore
/// @notice Storage of reward data per user and token
contract RewardStore is Roles {
// user => token => amount
mapping(address => mapping(address => uint256)) private rewards;
constructor(RoleStore rs) Roles(rs) {}
function incrementReward(address user, address token, uint256 amount) external onlyContract {
rewards[user][token] += amount;
}
function decrementReward(address user, address token, uint256 amount) external onlyContract {
rewards[user][token] = rewards[user][token] <= amount ? 0 : rewards[user][token] - amount;
}
function getReward(address user, address token) external view returns (uint256) {
return rewards[user][token];
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (utils/structs/EnumerableSet.sol)
pragma solidity ^0.8.0;
/**
* @dev Library for managing
* https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive
* types.
*
* Sets have the following properties:
*
* - Elements are added, removed, and checked for existence in constant time
* (O(1)).
* - Elements are enumerated in O(n). No guarantees are made on the ordering.
*
* ```
* contract Example {
* // Add the library methods
* using EnumerableSet for EnumerableSet.AddressSet;
*
* // Declare a set state variable
* EnumerableSet.AddressSet private mySet;
* }
* ```
*
* As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`)
* and `uint256` (`UintSet`) are supported.
*
* [WARNING]
* ====
* Trying to delete such a structure from storage will likely result in data corruption, rendering the structure unusable.
* See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info.
*
* In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an array of EnumerableSet.
* ====
*/
library EnumerableSet {
// To implement this library for multiple types with as little code
// repetition as possible, we write it in terms of a generic Set type with
// bytes32 values.
// The Set implementation uses private functions, and user-facing
// implementations (such as AddressSet) are just wrappers around the
// underlying Set.
// This means that we can only create new EnumerableSets for types that fit
// in bytes32.
struct Set {
// Storage of set values
bytes32[] _values;
// Position of the value in the `values` array, plus 1 because index 0
// means a value is not in the set.
mapping(bytes32 => uint256) _indexes;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function _add(Set storage set, bytes32 value) private returns (bool) {
if (!_contains(set, value)) {
set._values.push(value);
// The value is stored at length-1, but we add 1 to all indexes
// and use 0 as a sentinel value
set._indexes[value] = set._values.length;
return true;
} else {
return false;
}
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function _remove(Set storage set, bytes32 value) private returns (bool) {
// We read and store the value's index to prevent multiple reads from the same storage slot
uint256 valueIndex = set._indexes[value];
if (valueIndex != 0) {
// Equivalent to contains(set, value)
// To delete an element from the _values array in O(1), we swap the element to delete with the last one in
// the array, and then remove the last element (sometimes called as 'swap and pop').
// This modifies the order of the array, as noted in {at}.
uint256 toDeleteIndex = valueIndex - 1;
uint256 lastIndex = set._values.length - 1;
if (lastIndex != toDeleteIndex) {
bytes32 lastValue = set._values[lastIndex];
// Move the last value to the index where the value to delete is
set._values[toDeleteIndex] = lastValue;
// Update the index for the moved value
set._indexes[lastValue] = valueIndex; // Replace lastValue's index to valueIndex
}
// Delete the slot where the moved value was stored
set._values.pop();
// Delete the index for the deleted slot
delete set._indexes[value];
return true;
} else {
return false;
}
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function _contains(Set storage set, bytes32 value) private view returns (bool) {
return set._indexes[value] != 0;
}
/**
* @dev Returns the number of values on the set. O(1).
*/
function _length(Set storage set) private view returns (uint256) {
return set._values.length;
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function _at(Set storage set, uint256 index) private view returns (bytes32) {
return set._values[index];
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function _values(Set storage set) private view returns (bytes32[] memory) {
return set._values;
}
// Bytes32Set
struct Bytes32Set {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _add(set._inner, value);
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) {
return _remove(set._inner, value);
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) {
return _contains(set._inner, value);
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(Bytes32Set storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) {
return _at(set._inner, index);
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(Bytes32Set storage set) internal view returns (bytes32[] memory) {
return _values(set._inner);
}
// AddressSet
struct AddressSet {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(AddressSet storage set, address value) internal returns (bool) {
return _add(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(AddressSet storage set, address value) internal returns (bool) {
return _remove(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(AddressSet storage set, address value) internal view returns (bool) {
return _contains(set._inner, bytes32(uint256(uint160(value))));
}
/**
* @dev Returns the number of values in the set. O(1).
*/
function length(AddressSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(AddressSet storage set, uint256 index) internal view returns (address) {
return address(uint160(uint256(_at(set._inner, index))));
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(AddressSet storage set) internal view returns (address[] memory) {
bytes32[] memory store = _values(set._inner);
address[] memory result;
/// @solidity memory-safe-assembly
assembly {
result := store
}
return result;
}
// UintSet
struct UintSet {
Set _inner;
}
/**
* @dev Add a value to a set. O(1).
*
* Returns true if the value was added to the set, that is if it was not
* already present.
*/
function add(UintSet storage set, uint256 value) internal returns (bool) {
return _add(set._inner, bytes32(value));
}
/**
* @dev Removes a value from a set. O(1).
*
* Returns true if the value was removed from the set, that is if it was
* present.
*/
function remove(UintSet storage set, uint256 value) internal returns (bool) {
return _remove(set._inner, bytes32(value));
}
/**
* @dev Returns true if the value is in the set. O(1).
*/
function contains(UintSet storage set, uint256 value) internal view returns (bool) {
return _contains(set._inner, bytes32(value));
}
/**
* @dev Returns the number of values on the set. O(1).
*/
function length(UintSet storage set) internal view returns (uint256) {
return _length(set._inner);
}
/**
* @dev Returns the value stored at position `index` in the set. O(1).
*
* Note that there are no guarantees on the ordering of values inside the
* array, and it may change when more values are added or removed.
*
* Requirements:
*
* - `index` must be strictly less than {length}.
*/
function at(UintSet storage set, uint256 index) internal view returns (uint256) {
return uint256(_at(set._inner, index));
}
/**
* @dev Return the entire set in an array
*
* WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed
* to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that
* this function has an unbounded cost, and using it as part of a state-changing function may render the function
* uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block.
*/
function values(UintSet storage set) internal view returns (uint256[] memory) {
bytes32[] memory store = _values(set._inner);
uint256[] memory result;
/// @solidity memory-safe-assembly
assembly {
result := store
}
return result;
}
}// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.17;
import '@openzeppelin/contracts/utils/structs/EnumerableSet.sol';
import '../utils/Governable.sol';
/**
* @title RoleStore
* @notice Role-based access control mechanism. Governance can grant and
* revoke roles dynamically via {grantRole} and {revokeRole}
*/
contract RoleStore is Governable {
// Libraries
using EnumerableSet for EnumerableSet.AddressSet;
using EnumerableSet for EnumerableSet.Bytes32Set;
// Set of roles
EnumerableSet.Bytes32Set internal roles;
// Role -> address
mapping(bytes32 => EnumerableSet.AddressSet) internal roleMembers;
constructor() Governable() {}
/// @notice Grants `role` to `account`
/// @dev Only callable by governance
function grantRole(address account, bytes32 role) external onlyGov {
// add role if not already present
if (!roles.contains(role)) roles.add(role);
require(roleMembers[role].add(account));
}
/// @notice Revokes `role` from `account`
/// @dev Only callable by governance
function revokeRole(address account, bytes32 role) external onlyGov {
require(roleMembers[role].remove(account));
// Remove role if it has no longer any members
if (roleMembers[role].length() == 0) {
roles.remove(role);
}
}
/// @notice Returns `true` if `account` has been granted `role`
function hasRole(address account, bytes32 role) external view returns (bool) {
return roleMembers[role].contains(account);
}
/// @notice Returns number of roles
function getRoleCount() external view returns (uint256) {
return roles.length();
}
}// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.17;
/// @title Governable
/// @notice Basic access control mechanism, gov has access to certain functions
contract Governable {
address public gov;
event SetGov(address prevGov, address nextGov);
/// @dev Initializes the contract setting the deployer address as governance
constructor() {
_setGov(msg.sender);
}
/// @dev Reverts if called by any account other than gov
modifier onlyGov() {
require(msg.sender == gov, '!gov');
_;
}
/// @notice Sets a new governance address
/// @dev Only callable by governance
function setGov(address _gov) external onlyGov {
_setGov(_gov);
}
/// @notice Sets a new governance address
/// @dev Internal function without access restriction
function _setGov(address _gov) internal {
address prevGov = gov;
gov = _gov;
emit SetGov(prevGov, _gov);
}
}// SPDX-License-Identifier: BUSL-1.1
pragma solidity 0.8.17;
import './Governable.sol';
import '../stores/RoleStore.sol';
/// @title Roles
/// @notice Role-based access control mechanism via onlyContract modifier
contract Roles is Governable {
bytes32 public constant CONTRACT = keccak256('CONTRACT');
RoleStore public roleStore;
/// @dev Initializes roleStore address
constructor(RoleStore rs) Governable() {
roleStore = rs;
}
/// @dev Reverts if caller address has not the contract role
modifier onlyContract() {
require(roleStore.hasRole(msg.sender, CONTRACT), '!contract-role');
_;
}
}{
"viaIR": true,
"optimizer": {
"enabled": true,
"runs": 100
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"devdoc",
"userdoc",
"metadata",
"abi"
]
}
},
"libraries": {}
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[{"internalType":"contract RoleStore","name":"rs","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"prevGov","type":"address"},{"indexed":false,"internalType":"address","name":"nextGov","type":"address"}],"name":"SetGov","type":"event"},{"inputs":[],"name":"CONTRACT","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"decrementReward","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"address","name":"token","type":"address"}],"name":"getReward","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"gov","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"user","type":"address"},{"internalType":"address","name":"token","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"incrementReward","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"roleStore","outputs":[{"internalType":"contract RoleStore","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_gov","type":"address"}],"name":"setGov","outputs":[],"stateMutability":"nonpayable","type":"function"}]Contract Creation Code
6080346100ad57601f6105bd38819003918201601f19168301916001600160401b038311848410176100b2578084926020946040528339810103126100ad57516001600160a01b03808216918290036100ad577f53351836099c03ffc3b1727d8abd4b0222afa87d4ed76ae3102d51369ef7f785604060005460018060a01b0319933385831617600055825191168152336020820152a160015416176001556040516104f490816100c98239f35b600080fd5b634e487b7160e01b600052604160045260246000fdfe608060408181526004918236101561001657600080fd5b600092833560e01c91826312d43a511461039d5750816342806a301461029c5781634a4a7b04146102735781636b0916951461021f578163b599a48f1461013b578163cfad57a21461009d575063fc833ac61461007257600080fd5b346100995781600319360112610099576020905160008051602061049f8339815191528152f35b5080fd5b838334610099576020366003190112610099576100b86103c1565b825490936001600160a01b0380831692913384900361011257507f53351836099c03ffc3b1727d8abd4b0222afa87d4ed76ae3102d51369ef7f785949516809160018060a01b03191617855582519182526020820152a180f35b60649085519062461bcd60e51b825260208183015260248201526310b3b7bb60e11b6044820152fd5b90503461021b5761014b366103dc565b600154855163ac4ab3fb60e01b8152338682015260008051602061049f83398151915260248201529195936001600160a01b039290916020908290604490829087165afa908115610211578392916101aa918a916101e3575b50610461565b16865260026020528286209116855260205283209081549283018093116101d057505580f35b634e487b7160e01b845260119052602483fd5b610204915060203d811161020a575b6101fc8183610411565b810190610449565b386101a4565b503d6101f2565b85513d8a823e3d90fd5b8280fd5b5050346100995780600319360112610099576102396103c1565b6001600160a01b03602435818116929083900361026f579160209491849316825260028552828220908252845220549051908152f35b8480fd5b50503461009957816003193601126100995760015490516001600160a01b039091168152602090f35b9190503461021b576102ad366103dc565b600154845163ac4ab3fb60e01b8152338188015260008051602061049f83398151915260248201526001600160a01b03969394602094929091908590829060449082908c165afa9081156103935788929161030e918b9161037c5750610461565b16808852600284528588209490961680885293835284872054821061034557505084935b8552600281528285209185525282205580f35b85875260028352848720848852835284872054918203918211610369575093610332565b634e487b7160e01b875260119052602486fd5b6102049150873d891161020a576101fc8183610411565b87513d8b823e3d90fd5b84903461009957816003193601126100995790546001600160a01b03168152602090f35b600435906001600160a01b03821682036103d757565b600080fd5b60609060031901126103d7576001600160a01b039060043582811681036103d7579160243590811681036103d7579060443590565b90601f8019910116810190811067ffffffffffffffff82111761043357604052565b634e487b7160e01b600052604160045260246000fd5b908160209103126103d7575180151581036103d75790565b1561046857565b60405162461bcd60e51b815260206004820152600e60248201526d21636f6e74726163742d726f6c6560901b6044820152606490fdfea66b7a3e6b19d24ccb6f717fc232a1bb0278a7f83f8e2211835fc4ed0fe69f19a264697066735822122081189b9ac1f7b23c90bc8168b791afb88552bdf52398abb87792f06405cc219764736f6c63430008110033000000000000000000000000e5da4704a582fe799dcd1dff31dc2ed2e0bdc961
Deployed Bytecode
0x608060408181526004918236101561001657600080fd5b600092833560e01c91826312d43a511461039d5750816342806a301461029c5781634a4a7b04146102735781636b0916951461021f578163b599a48f1461013b578163cfad57a21461009d575063fc833ac61461007257600080fd5b346100995781600319360112610099576020905160008051602061049f8339815191528152f35b5080fd5b838334610099576020366003190112610099576100b86103c1565b825490936001600160a01b0380831692913384900361011257507f53351836099c03ffc3b1727d8abd4b0222afa87d4ed76ae3102d51369ef7f785949516809160018060a01b03191617855582519182526020820152a180f35b60649085519062461bcd60e51b825260208183015260248201526310b3b7bb60e11b6044820152fd5b90503461021b5761014b366103dc565b600154855163ac4ab3fb60e01b8152338682015260008051602061049f83398151915260248201529195936001600160a01b039290916020908290604490829087165afa908115610211578392916101aa918a916101e3575b50610461565b16865260026020528286209116855260205283209081549283018093116101d057505580f35b634e487b7160e01b845260119052602483fd5b610204915060203d811161020a575b6101fc8183610411565b810190610449565b386101a4565b503d6101f2565b85513d8a823e3d90fd5b8280fd5b5050346100995780600319360112610099576102396103c1565b6001600160a01b03602435818116929083900361026f579160209491849316825260028552828220908252845220549051908152f35b8480fd5b50503461009957816003193601126100995760015490516001600160a01b039091168152602090f35b9190503461021b576102ad366103dc565b600154845163ac4ab3fb60e01b8152338188015260008051602061049f83398151915260248201526001600160a01b03969394602094929091908590829060449082908c165afa9081156103935788929161030e918b9161037c5750610461565b16808852600284528588209490961680885293835284872054821061034557505084935b8552600281528285209185525282205580f35b85875260028352848720848852835284872054918203918211610369575093610332565b634e487b7160e01b875260119052602486fd5b6102049150873d891161020a576101fc8183610411565b87513d8b823e3d90fd5b84903461009957816003193601126100995790546001600160a01b03168152602090f35b600435906001600160a01b03821682036103d757565b600080fd5b60609060031901126103d7576001600160a01b039060043582811681036103d7579160243590811681036103d7579060443590565b90601f8019910116810190811067ffffffffffffffff82111761043357604052565b634e487b7160e01b600052604160045260246000fd5b908160209103126103d7575180151581036103d75790565b1561046857565b60405162461bcd60e51b815260206004820152600e60248201526d21636f6e74726163742d726f6c6560901b6044820152606490fdfea66b7a3e6b19d24ccb6f717fc232a1bb0278a7f83f8e2211835fc4ed0fe69f19a264697066735822122081189b9ac1f7b23c90bc8168b791afb88552bdf52398abb87792f06405cc219764736f6c63430008110033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
000000000000000000000000e5da4704a582fe799dcd1dff31dc2ed2e0bdc961
-----Decoded View---------------
Arg [0] : rs (address): 0xe5DA4704a582Fe799dcd1dFF31dc2eD2e0BdC961
-----Encoded View---------------
1 Constructor Arguments found :
Arg [0] : 000000000000000000000000e5da4704a582fe799dcd1dff31dc2ed2e0bdc961
Loading...
Loading
Loading...
Loading
Loading...
Loading
Net Worth in USD
$0.00
Net Worth in ETH
0
Multichain Portfolio | 35 Chains
| Chain | Token | Portfolio % | Price | Amount | Value |
|---|
Loading...
Loading
Loading...
Loading
Loading...
Loading
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.