// SPDX-License-Identifier: AGPL-3.0-or-laterpragmasolidity 0.7.5;libraryEnumerableSet{
// 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.structSet {
// Storage of set valuesbytes32[] _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) privatereturns (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;
returntrue;
} else {
returnfalse;
}
}
/**
* @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) privatereturns (bool) {
// We read and store the value's index to prevent multiple reads from the same storage slotuint256 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;
// When the value to delete is the last one, the swap operation is unnecessary. However, since this occurs// so rarely, we still do the swap anyway to avoid the gas cost of adding an 'if' statement.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] = toDeleteIndex +1; // All indexes are 1-based// Delete the slot where the moved value was stored
set._values.pop();
// Delete the index for the deleted slotdelete set._indexes[value];
returntrue;
} else {
returnfalse;
}
}
/**
* @dev Returns true if the value is in the set. O(1).
*/function_contains(
Set storage set,
bytes32 value
) privateviewreturns (bool) {
return set._indexes[value] !=0;
}
/**
* @dev Returns the number of values on the set. O(1).
*/function_length(Set storage set) privateviewreturns (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
) privateviewreturns (bytes32) {
require(
set._values.length> index,
"EnumerableSet: index out of bounds"
);
return set._values[index];
}
function_getValues(
Set storage set_
) privateviewreturns (bytes32[] storage) {
return set_._values;
}
// TODO needs insert function that maintains order.// TODO needs NatSpec documentation comment./**
* Inserts new value by moving existing value at provided index to end
* of array and setting provided value at provided index
*/function_insert(
Set storage set_,
uint256 index_,
bytes32 valueToInsert_
) privatereturns (bool) {
require(set_._values.length> index_);
require(
!_contains(set_, valueToInsert_),
"Remove value you wish to insert if you wish to reorder array."
);
bytes32 existingValue_ = _at(set_, index_);
set_._values[index_] = valueToInsert_;
return _add(set_, existingValue_);
}
structBytes4Set {
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.
*/functionadd(Bytes4Set storage set, bytes4 value) internalreturns (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.
*/functionremove(
Bytes4Set storage set,
bytes4 value
) internalreturns (bool) {
return _remove(set._inner, value);
}
/**
* @dev Returns true if the value is in the set. O(1).
*/functioncontains(
Bytes4Set storage set,
bytes4 value
) internalviewreturns (bool) {
return _contains(set._inner, value);
}
/**
* @dev Returns the number of values on the set. O(1).
*/functionlength(Bytes4Set storage set) internalviewreturns (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}.
*/functionat(
Bytes4Set storage set,
uint256 index
) internalviewreturns (bytes4) {
returnbytes4(_at(set._inner, index));
}
functiongetValues(
Bytes4Set storage set_
) internalviewreturns (bytes4[] memory) {
bytes4[] memory bytes4Array_;
for (
uint256 iteration_ =0;
_length(set_._inner) > iteration_;
iteration_++
) {
bytes4Array_[iteration_] =bytes4(_at(set_._inner, iteration_));
}
return bytes4Array_;
}
functioninsert(
Bytes4Set storage set_,
uint256 index_,
bytes4 valueToInsert_
) internalreturns (bool) {
return _insert(set_._inner, index_, valueToInsert_);
}
structBytes32Set {
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.
*/functionadd(
Bytes32Set storage set,
bytes32 value
) internalreturns (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.
*/functionremove(
Bytes32Set storage set,
bytes32 value
) internalreturns (bool) {
return _remove(set._inner, value);
}
/**
* @dev Returns true if the value is in the set. O(1).
*/functioncontains(
Bytes32Set storage set,
bytes32 value
) internalviewreturns (bool) {
return _contains(set._inner, value);
}
/**
* @dev Returns the number of values on the set. O(1).
*/functionlength(Bytes32Set storage set) internalviewreturns (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}.
*/functionat(
Bytes32Set storage set,
uint256 index
) internalviewreturns (bytes32) {
return _at(set._inner, index);
}
functiongetValues(
Bytes32Set storage set_
) internalviewreturns (bytes4[] memory) {
bytes4[] memory bytes4Array_;
for (
uint256 iteration_ =0;
_length(set_._inner) >= iteration_;
iteration_++
) {
bytes4Array_[iteration_] =bytes4(at(set_, iteration_));
}
return bytes4Array_;
}
functioninsert(
Bytes32Set storage set_,
uint256 index_,
bytes32 valueToInsert_
) internalreturns (bool) {
return _insert(set_._inner, index_, valueToInsert_);
}
// AddressSetstructAddressSet {
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.
*/functionadd(
AddressSet storage set,
address value
) internalreturns (bool) {
return _add(set._inner, bytes32(uint256(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.
*/functionremove(
AddressSet storage set,
address value
) internalreturns (bool) {
return _remove(set._inner, bytes32(uint256(value)));
}
/**
* @dev Returns true if the value is in the set. O(1).
*/functioncontains(
AddressSet storage set,
address value
) internalviewreturns (bool) {
return _contains(set._inner, bytes32(uint256(value)));
}
/**
* @dev Returns the number of values in the set. O(1).
*/functionlength(AddressSet storage set) internalviewreturns (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}.
*/functionat(
AddressSet storage set,
uint256 index
) internalviewreturns (address) {
returnaddress(uint256(_at(set._inner, index)));
}
/**
* TODO Might require explicit conversion of bytes32[] to address[].
* Might require iteration.
*/functiongetValues(
AddressSet storage set_
) internalviewreturns (address[] memory) {
address[] memory addressArray;
for (
uint256 iteration_ =0;
_length(set_._inner) >= iteration_;
iteration_++
) {
addressArray[iteration_] = at(set_, iteration_);
}
return addressArray;
}
functioninsert(
AddressSet storage set_,
uint256 index_,
address valueToInsert_
) internalreturns (bool) {
return _insert(set_._inner, index_, bytes32(uint256(valueToInsert_)));
}
// UintSetstructUintSet {
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.
*/functionadd(UintSet storage set, uint256 value) internalreturns (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.
*/functionremove(
UintSet storage set,
uint256 value
) internalreturns (bool) {
return _remove(set._inner, bytes32(value));
}
/**
* @dev Returns true if the value is in the set. O(1).
*/functioncontains(
UintSet storage set,
uint256 value
) internalviewreturns (bool) {
return _contains(set._inner, bytes32(value));
}
/**
* @dev Returns the number of values on the set. O(1).
*/functionlength(UintSet storage set) internalviewreturns (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}.
*/functionat(
UintSet storage set,
uint256 index
) internalviewreturns (uint256) {
returnuint256(_at(set._inner, index));
}
structUInt256Set {
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.
*/functionadd(
UInt256Set storage set,
uint256 value
) internalreturns (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.
*/functionremove(
UInt256Set storage set,
uint256 value
) internalreturns (bool) {
return _remove(set._inner, bytes32(value));
}
/**
* @dev Returns true if the value is in the set. O(1).
*/functioncontains(
UInt256Set storage set,
uint256 value
) internalviewreturns (bool) {
return _contains(set._inner, bytes32(value));
}
/**
* @dev Returns the number of values on the set. O(1).
*/functionlength(UInt256Set storage set) internalviewreturns (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}.
*/functionat(
UInt256Set storage set,
uint256 index
) internalviewreturns (uint256) {
returnuint256(_at(set._inner, index));
}
}
Contract Source Code
File 5 of 14: IERC20.sol
// SPDX-License-Identifier: AGPL-3.0-or-laterpragmasolidity 0.7.5;interfaceIERC20{
functiondecimals() externalviewreturns (uint8);
/**
* @dev Returns the amount of tokens in existence.
*/functiontotalSupply() externalviewreturns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/functionbalanceOf(address account) externalviewreturns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `recipient`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/functiontransfer(address recipient,
uint256 amount
) externalreturns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/functionallowance(address owner,
address spender
) externalviewreturns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/functionapprove(address spender, uint256 amount) externalreturns (bool);
/**
* @dev Moves `amount` tokens from `sender` to `recipient` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/functiontransferFrom(address sender,
address recipient,
uint256 amount
) externalreturns (bool);
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/eventTransfer(addressindexedfrom, addressindexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/eventApproval(addressindexed owner,
addressindexed spender,
uint256 value
);
}
// SPDX-License-Identifier: AGPL-3.0-or-laterpragmasolidity 0.7.5;interfaceIWETH{
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/eventTransfer(addressindexedfrom, addressindexed to, uint256 value);
/**
* @dev Emitted when the allowance of a `spender` for an `owner` is set by
* a call to {approve}. `value` is the new allowance.
*/eventApproval(addressindexed owner,
addressindexed spender,
uint256 value
);
/**
* @dev Returns the amount of tokens in existence.
*/functiontotalSupply() externalviewreturns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/functionbalanceOf(address account) externalviewreturns (uint256);
/**
* @dev Moves `amount` tokens from the caller's account to `to`.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/functiontransfer(address to, uint256 amount) externalreturns (bool);
/**
* @dev Returns the remaining number of tokens that `spender` will be
* allowed to spend on behalf of `owner` through {transferFrom}. This is
* zero by default.
*
* This value changes when {approve} or {transferFrom} are called.
*/functionallowance(address owner,
address spender
) externalviewreturns (uint256);
/**
* @dev Sets `amount` as the allowance of `spender` over the caller's tokens.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* IMPORTANT: Beware that changing an allowance with this method brings the risk
* that someone may use both the old and the new allowance by unfortunate
* transaction ordering. One possible solution to mitigate this race
* condition is to first reduce the spender's allowance to 0 and set the
* desired value afterwards:
* https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729
*
* Emits an {Approval} event.
*/functionapprove(address spender, uint256 amount) externalreturns (bool);
/**
* @dev Moves `amount` tokens from `from` to `to` using the
* allowance mechanism. `amount` is then deducted from the caller's
* allowance.
*
* Returns a boolean value indicating whether the operation succeeded.
*
* Emits a {Transfer} event.
*/functiontransferFrom(addressfrom,
address to,
uint256 amount
) externalreturns (bool);
/// @notice Deposit ether to get wrapped etherfunctiondeposit() externalpayable;
/// @notice Withdraw wrapped ether to get etherfunctionwithdraw(uint256) external;
}
Contract Source Code
File 11 of 14: Ownable.sol
// SPDX-License-Identifier: AGPL-3.0-or-laterpragmasolidity 0.7.5;import"./lib/IOwnable.sol";
contractOwnableisIOwnable{
addressinternal _owner;
eventOwnershipTransferred(addressindexed previousOwner,
addressindexed newOwner
);
constructor() {
_owner =msg.sender;
emit OwnershipTransferred(address(0), _owner);
}
functionowner() publicviewoverridereturns (address) {
return _owner;
}
modifieronlyOwner() {
require(_owner ==msg.sender, "Ownable: caller is not the owner");
_;
}
functionrenounceOwnership() publicvirtualoverrideonlyOwner{
emit OwnershipTransferred(_owner, address(0));
_owner =address(0);
}
functiontransferOwnership(address newOwner_
) publicvirtualoverrideonlyOwner{
require(
newOwner_ !=address(0),
"Ownable: new owner is the zero address"
);
emit OwnershipTransferred(_owner, newOwner_);
_owner = newOwner_;
}
}
Contract Source Code
File 12 of 14: SafeMath.sol
// SPDX-License-Identifier: AGPL-3.0-or-laterpragmasolidity 0.7.5;librarySafeMath{
functionadd(uint256 a, uint256 b) internalpurereturns (uint256) {
uint256 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
functionadd32(uint32 a, uint32 b) internalpurereturns (uint32) {
uint32 c = a + b;
require(c >= a, "SafeMath: addition overflow");
return c;
}
functionsub(uint256 a, uint256 b) internalpurereturns (uint256) {
return sub(a, b, "SafeMath: subtraction overflow");
}
functionsub(uint256 a,
uint256 b,
stringmemory errorMessage
) internalpurereturns (uint256) {
require(b <= a, errorMessage);
uint256 c = a - b;
return c;
}
functionsub32(uint32 a, uint32 b) internalpurereturns (uint32) {
return sub32(a, b, "SafeMath: subtraction overflow");
}
functionsub32(uint32 a,
uint32 b,
stringmemory errorMessage
) internalpurereturns (uint32) {
require(b <= a, errorMessage);
uint32 c = a - b;
return c;
}
functionmul(uint256 a, uint256 b) internalpurereturns (uint256) {
if (a ==0) {
return0;
}
uint256 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
functionmul32(uint32 a, uint32 b) internalpurereturns (uint32) {
if (a ==0) {
return0;
}
uint32 c = a * b;
require(c / a == b, "SafeMath: multiplication overflow");
return c;
}
functiondiv(uint256 a, uint256 b) internalpurereturns (uint256) {
return div(a, b, "SafeMath: division by zero");
}
functiondiv(uint256 a,
uint256 b,
stringmemory errorMessage
) internalpurereturns (uint256) {
require(b >0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't holdreturn c;
}
functionmod(uint256 a, uint256 b) internalpurereturns (uint256) {
return mod(a, b, "SafeMath: modulo by zero");
}
functionmod(uint256 a,
uint256 b,
stringmemory errorMessage
) internalpurereturns (uint256) {
require(b !=0, errorMessage);
return a % b;
}
functionsqrrt(uint256 a) internalpurereturns (uint c) {
if (a >3) {
c = a;
uint b = add(div(a, 2), 1);
while (b < c) {
c = b;
b = div(add(div(a, b), b), 2);
}
} elseif (a !=0) {
c =1;
}
}
functionpercentageAmount(uint256 total_,
uint8 percentage_
) internalpurereturns (uint256 percentAmount_) {
return div(mul(total_, percentage_), 1000);
}
functionsubstractPercentage(uint256 total_,
uint8 percentageToSub_
) internalpurereturns (uint256 result_) {
return sub(total_, div(mul(total_, percentageToSub_), 1000));
}
functionpercentageOfTotal(uint256 part_,
uint256 total_
) internalpurereturns (uint256 percent_) {
return div(mul(part_, 100), total_);
}
functionaverage(uint256 a, uint256 b) internalpurereturns (uint256) {
// (a + b) / 2 can overflow, so we distributereturn (a /2) + (b /2) + (((a %2) + (b %2)) /2);
}
functionquadraticPricing(uint256 payment_,
uint256 multiplier_
) internalpurereturns (uint256) {
return sqrrt(mul(multiplier_, payment_));
}
functionbondingCurve(uint256 supply_,
uint256 multiplier_
) internalpurereturns (uint256) {
return mul(multiplier_, supply_);
}
}