Source Code
More Info
Private Name Tags
ContractCreator
TokenTracker
Latest 25 from a total of 10,335 transactions
| Transaction Hash |
Method
|
Block
|
From
|
To
|
|||||
|---|---|---|---|---|---|---|---|---|---|
| Mint | 7337278 | 611 days ago | IN | 0 ETH | 0.00007947 | ||||
| Mint | 5631147 | 670 days ago | IN | 0 ETH | 0.00004066 | ||||
| Mint | 5454202 | 676 days ago | IN | 0 ETH | 0.00008853 | ||||
| Mint | 4909549 | 695 days ago | IN | 0 ETH | 0.00015412 | ||||
| Mint | 4281873 | 724 days ago | IN | 0 ETH | 0.00025149 | ||||
| Mint | 4280291 | 724 days ago | IN | 0 ETH | 0.00031806 | ||||
| Mint | 4234431 | 726 days ago | IN | 0 ETH | 0.00044151 | ||||
| Mint | 4234431 | 726 days ago | IN | 0 ETH | 0.00044151 | ||||
| Mint | 4234430 | 726 days ago | IN | 0 ETH | 0.00053141 | ||||
| Mint | 3472015 | 754 days ago | IN | 0 ETH | 0.00051974 | ||||
| Mint | 3331254 | 759 days ago | IN | 0 ETH | 0.00029661 | ||||
| Mint | 3063970 | 768 days ago | IN | 0 ETH | 0.00017157 | ||||
| Mint | 2961264 | 772 days ago | IN | 0 ETH | 0.00023518 | ||||
| Mint | 2919481 | 773 days ago | IN | 0 ETH | 0.00025494 | ||||
| Mint | 2917875 | 774 days ago | IN | 0 ETH | 0.0002642 | ||||
| Mint | 2917252 | 774 days ago | IN | 0 ETH | 0.00026201 | ||||
| Mint | 2916874 | 774 days ago | IN | 0 ETH | 0.00027017 | ||||
| Mint | 2916425 | 774 days ago | IN | 0 ETH | 0.00027688 | ||||
| Mint | 2916223 | 774 days ago | IN | 0 ETH | 0.00039071 | ||||
| Mint | 2916091 | 774 days ago | IN | 0 ETH | 0.00029458 | ||||
| Mint | 2915957 | 774 days ago | IN | 0 ETH | 0.00027302 | ||||
| Mint | 2915132 | 774 days ago | IN | 0 ETH | 0.00027914 | ||||
| Mint | 2914980 | 774 days ago | IN | 0 ETH | 0.00028238 | ||||
| Mint | 2914647 | 774 days ago | IN | 0 ETH | 0.00031428 | ||||
| Mint | 2914228 | 774 days ago | IN | 0 ETH | 0.0003111 |
View more zero value Internal Transactions in Advanced View mode
Advanced mode:
Cross-Chain Transactions
Loading...
Loading
Contract Name:
ReferenceSBTSelfSovereign
Compiler Version
v0.8.8+commit.dddeac2f
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.8;
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "../tokens/MasaSBTSelfSovereign.sol";
/// @title Soulbound reference Self-Sovereign SBT
/// @author Masa Finance
/// @notice Soulbound token that represents a Self-Sovereign SBT
/// @dev Inherits from the SBT contract.
contract ReferenceSBTSelfSovereign is MasaSBTSelfSovereign, ReentrancyGuard {
error MaxSBTMinted(address to, uint256 maximum);
uint256 public maxSBTToMint = 1;
/* ========== STATE VARIABLES =========================================== */
/* ========== INITIALIZE ================================================ */
/// @notice Creates a new Self-Sovereign SBT
/// @dev Creates a new Self-Sovereign SBT, inheriting from the SBT contract.
/// @param admin Administrator of the smart contract
/// @param name Name of the token
/// @param symbol Symbol of the token
/// @param baseTokenURI Base URI of the token
/// @param soulboundIdentity Address of the SoulboundIdentity contract
/// @param paymentParams Payment gateway params
/// @param _maxSBTToMint Maximum number of SBT that can be minted
constructor(
address admin,
string memory name,
string memory symbol,
string memory baseTokenURI,
address soulboundIdentity,
PaymentParams memory paymentParams,
uint256 _maxSBTToMint
)
MasaSBTSelfSovereign(
admin,
name,
symbol,
baseTokenURI,
soulboundIdentity,
paymentParams
)
EIP712("ReferenceSBTSelfSovereign", "1.0.0")
{
maxSBTToMint = _maxSBTToMint;
}
/* ========== RESTRICTED FUNCTIONS ====================================== */
/* ========== MUTATIVE FUNCTIONS ======================================== */
/// @notice Mints a new SBT
/// @dev The caller must have the MINTER role
/// @param paymentMethod Address of token that user want to pay
/// @param identityId TokenId of the identity to mint the NFT to
/// @param authorityAddress Address of the authority that signed the message
/// @param signatureDate Date of the signature
/// @param signature Signature of the message
/// @return The SBT ID of the newly minted SBT
function mint(
address paymentMethod,
uint256 identityId,
address authorityAddress,
uint256 signatureDate,
bytes calldata signature
) external payable virtual nonReentrant returns (uint256) {
address to = soulboundIdentity.ownerOf(identityId);
if (maxSBTToMint > 0 && balanceOf(to) >= maxSBTToMint)
revert MaxSBTMinted(to, maxSBTToMint);
if (to != _msgSender()) revert CallerNotOwner(_msgSender());
uint256 tokenId = _mintWithCounter(
paymentMethod,
to,
_hash(identityId, authorityAddress, signatureDate),
authorityAddress,
signature
);
emit MintedToIdentity(
tokenId,
identityId,
authorityAddress,
signatureDate,
paymentMethod,
mintPrice
);
return tokenId;
}
/// @notice Mints a new SBT
/// @dev The caller must have the MINTER role
/// @param paymentMethod Address of token that user want to pay
/// @param to The address to mint the SBT to
/// @param authorityAddress Address of the authority that signed the message
/// @param signatureDate Date of the signature
/// @param signature Signature of the message
/// @return The SBT ID of the newly minted SBT
function mint(
address paymentMethod,
address to,
address authorityAddress,
uint256 signatureDate,
bytes calldata signature
) external payable virtual returns (uint256) {
if (maxSBTToMint > 0 && balanceOf(to) >= maxSBTToMint)
revert MaxSBTMinted(to, maxSBTToMint);
if (to != _msgSender()) revert CallerNotOwner(_msgSender());
uint256 tokenId = _mintWithCounter(
paymentMethod,
to,
_hash(to, authorityAddress, signatureDate),
authorityAddress,
signature
);
emit MintedToAddress(
tokenId,
to,
authorityAddress,
signatureDate,
paymentMethod,
mintPrice
);
return tokenId;
}
/* ========== VIEWS ===================================================== */
function tokenURI(
uint256 tokenId
) public view virtual override returns (string memory) {
_requireMinted(tokenId);
return _baseURI();
}
/* ========== PRIVATE FUNCTIONS ========================================= */
function _hash(
uint256 identityId,
address authorityAddress,
uint256 signatureDate
) internal view returns (bytes32) {
return
_hashTypedDataV4(
keccak256(
abi.encode(
keccak256(
"Mint(uint256 identityId,address authorityAddress,uint256 signatureDate)"
),
identityId,
authorityAddress,
signatureDate
)
)
);
}
function _hash(
address to,
address authorityAddress,
uint256 signatureDate
) internal view returns (bytes32) {
return
_hashTypedDataV4(
keccak256(
abi.encode(
keccak256(
"Mint(address to,address authorityAddress,uint256 signatureDate)"
),
to,
authorityAddress,
signatureDate
)
)
);
}
/* ========== MODIFIERS ================================================= */
/* ========== EVENTS ==================================================== */
event MintedToIdentity(
uint256 tokenId,
uint256 identityId,
address authorityAddress,
uint256 signatureDate,
address paymentMethod,
uint256 mintPrice
);
event MintedToAddress(
uint256 tokenId,
address to,
address authorityAddress,
uint256 signatureDate,
address paymentMethod,
uint256 mintPrice
);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (access/AccessControl.sol)
pragma solidity ^0.8.0;
import "./IAccessControl.sol";
import "../utils/Context.sol";
import "../utils/Strings.sol";
import "../utils/introspection/ERC165.sol";
/**
* @dev Contract module that allows children to implement role-based access
* control mechanisms. This is a lightweight version that doesn't allow enumerating role
* members except through off-chain means by accessing the contract event logs. Some
* applications may benefit from on-chain enumerability, for those cases see
* {AccessControlEnumerable}.
*
* Roles are referred to by their `bytes32` identifier. These should be exposed
* in the external API and be unique. The best way to achieve this is by
* using `public constant` hash digests:
*
* ```solidity
* bytes32 public constant MY_ROLE = keccak256("MY_ROLE");
* ```
*
* Roles can be used to represent a set of permissions. To restrict access to a
* function call, use {hasRole}:
*
* ```solidity
* function foo() public {
* require(hasRole(MY_ROLE, msg.sender));
* ...
* }
* ```
*
* Roles can be granted and revoked dynamically via the {grantRole} and
* {revokeRole} functions. Each role has an associated admin role, and only
* accounts that have a role's admin role can call {grantRole} and {revokeRole}.
*
* By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means
* that only accounts with this role will be able to grant or revoke other
* roles. More complex role relationships can be created by using
* {_setRoleAdmin}.
*
* WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to
* grant and revoke this role. Extra precautions should be taken to secure
* accounts that have been granted it. We recommend using {AccessControlDefaultAdminRules}
* to enforce additional security measures for this role.
*/
abstract contract AccessControl is Context, IAccessControl, ERC165 {
struct RoleData {
mapping(address => bool) members;
bytes32 adminRole;
}
mapping(bytes32 => RoleData) private _roles;
bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00;
/**
* @dev Modifier that checks that an account has a specific role. Reverts
* with a standardized message including the required role.
*
* The format of the revert reason is given by the following regular expression:
*
* /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
*
* _Available since v4.1._
*/
modifier onlyRole(bytes32 role) {
_checkRole(role);
_;
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId);
}
/**
* @dev Returns `true` if `account` has been granted `role`.
*/
function hasRole(bytes32 role, address account) public view virtual override returns (bool) {
return _roles[role].members[account];
}
/**
* @dev Revert with a standard message if `_msgSender()` is missing `role`.
* Overriding this function changes the behavior of the {onlyRole} modifier.
*
* Format of the revert message is described in {_checkRole}.
*
* _Available since v4.6._
*/
function _checkRole(bytes32 role) internal view virtual {
_checkRole(role, _msgSender());
}
/**
* @dev Revert with a standard message if `account` is missing `role`.
*
* The format of the revert reason is given by the following regular expression:
*
* /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/
*/
function _checkRole(bytes32 role, address account) internal view virtual {
if (!hasRole(role, account)) {
revert(
string(
abi.encodePacked(
"AccessControl: account ",
Strings.toHexString(account),
" is missing role ",
Strings.toHexString(uint256(role), 32)
)
)
);
}
}
/**
* @dev Returns the admin role that controls `role`. See {grantRole} and
* {revokeRole}.
*
* To change a role's admin, use {_setRoleAdmin}.
*/
function getRoleAdmin(bytes32 role) public view virtual override returns (bytes32) {
return _roles[role].adminRole;
}
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*
* May emit a {RoleGranted} event.
*/
function grantRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
_grantRole(role, account);
}
/**
* @dev Revokes `role` from `account`.
*
* If `account` had been granted `role`, emits a {RoleRevoked} event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*
* May emit a {RoleRevoked} event.
*/
function revokeRole(bytes32 role, address account) public virtual override onlyRole(getRoleAdmin(role)) {
_revokeRole(role, account);
}
/**
* @dev Revokes `role` from the calling account.
*
* Roles are often managed via {grantRole} and {revokeRole}: this function's
* purpose is to provide a mechanism for accounts to lose their privileges
* if they are compromised (such as when a trusted device is misplaced).
*
* If the calling account had been revoked `role`, emits a {RoleRevoked}
* event.
*
* Requirements:
*
* - the caller must be `account`.
*
* May emit a {RoleRevoked} event.
*/
function renounceRole(bytes32 role, address account) public virtual override {
require(account == _msgSender(), "AccessControl: can only renounce roles for self");
_revokeRole(role, account);
}
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event. Note that unlike {grantRole}, this function doesn't perform any
* checks on the calling account.
*
* May emit a {RoleGranted} event.
*
* [WARNING]
* ====
* This function should only be called from the constructor when setting
* up the initial roles for the system.
*
* Using this function in any other way is effectively circumventing the admin
* system imposed by {AccessControl}.
* ====
*
* NOTE: This function is deprecated in favor of {_grantRole}.
*/
function _setupRole(bytes32 role, address account) internal virtual {
_grantRole(role, account);
}
/**
* @dev Sets `adminRole` as ``role``'s admin role.
*
* Emits a {RoleAdminChanged} event.
*/
function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual {
bytes32 previousAdminRole = getRoleAdmin(role);
_roles[role].adminRole = adminRole;
emit RoleAdminChanged(role, previousAdminRole, adminRole);
}
/**
* @dev Grants `role` to `account`.
*
* Internal function without access restriction.
*
* May emit a {RoleGranted} event.
*/
function _grantRole(bytes32 role, address account) internal virtual {
if (!hasRole(role, account)) {
_roles[role].members[account] = true;
emit RoleGranted(role, account, _msgSender());
}
}
/**
* @dev Revokes `role` from `account`.
*
* Internal function without access restriction.
*
* May emit a {RoleRevoked} event.
*/
function _revokeRole(bytes32 role, address account) internal virtual {
if (hasRole(role, account)) {
_roles[role].members[account] = false;
emit RoleRevoked(role, account, _msgSender());
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol)
pragma solidity ^0.8.0;
/**
* @dev External interface of AccessControl declared to support ERC165 detection.
*/
interface IAccessControl {
/**
* @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole`
*
* `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite
* {RoleAdminChanged} not being emitted signaling this.
*
* _Available since v3.1._
*/
event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole);
/**
* @dev Emitted when `account` is granted `role`.
*
* `sender` is the account that originated the contract call, an admin role
* bearer except when using {AccessControl-_setupRole}.
*/
event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender);
/**
* @dev Emitted when `account` is revoked `role`.
*
* `sender` is the account that originated the contract call:
* - if using `revokeRole`, it is the admin role bearer
* - if using `renounceRole`, it is the role bearer (i.e. `account`)
*/
event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender);
/**
* @dev Returns `true` if `account` has been granted `role`.
*/
function hasRole(bytes32 role, address account) external view returns (bool);
/**
* @dev Returns the admin role that controls `role`. See {grantRole} and
* {revokeRole}.
*
* To change a role's admin, use {AccessControl-_setRoleAdmin}.
*/
function getRoleAdmin(bytes32 role) external view returns (bytes32);
/**
* @dev Grants `role` to `account`.
*
* If `account` had not been already granted `role`, emits a {RoleGranted}
* event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function grantRole(bytes32 role, address account) external;
/**
* @dev Revokes `role` from `account`.
*
* If `account` had been granted `role`, emits a {RoleRevoked} event.
*
* Requirements:
*
* - the caller must have ``role``'s admin role.
*/
function revokeRole(bytes32 role, address account) external;
/**
* @dev Revokes `role` from the calling account.
*
* Roles are often managed via {grantRole} and {revokeRole}: this function's
* purpose is to provide a mechanism for accounts to lose their privileges
* if they are compromised (such as when a trusted device is misplaced).
*
* If the calling account had been granted `role`, emits a {RoleRevoked}
* event.
*
* Requirements:
*
* - the caller must be `account`.
*/
function renounceRole(bytes32 role, address account) external;
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)
pragma solidity ^0.8.0;
import "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor() {
_transferOwnership(_msgSender());
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (interfaces/IERC5267.sol)
pragma solidity ^0.8.0;
interface IERC5267 {
/**
* @dev MAY be emitted to signal that the domain could have changed.
*/
event EIP712DomainChanged();
/**
* @dev returns the fields and values that describe the domain separator used by this contract for EIP-712
* signature.
*/
function eip712Domain()
external
view
returns (
bytes1 fields,
string memory name,
string memory version,
uint256 chainId,
address verifyingContract,
bytes32 salt,
uint256[] memory extensions
);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.7.0) (security/Pausable.sol)
pragma solidity ^0.8.0;
import "../utils/Context.sol";
/**
* @dev Contract module which allows children to implement an emergency stop
* mechanism that can be triggered by an authorized account.
*
* This module is used through inheritance. It will make available the
* modifiers `whenNotPaused` and `whenPaused`, which can be applied to
* the functions of your contract. Note that they will not be pausable by
* simply including this module, only once the modifiers are put in place.
*/
abstract contract Pausable is Context {
/**
* @dev Emitted when the pause is triggered by `account`.
*/
event Paused(address account);
/**
* @dev Emitted when the pause is lifted by `account`.
*/
event Unpaused(address account);
bool private _paused;
/**
* @dev Initializes the contract in unpaused state.
*/
constructor() {
_paused = false;
}
/**
* @dev Modifier to make a function callable only when the contract is not paused.
*
* Requirements:
*
* - The contract must not be paused.
*/
modifier whenNotPaused() {
_requireNotPaused();
_;
}
/**
* @dev Modifier to make a function callable only when the contract is paused.
*
* Requirements:
*
* - The contract must be paused.
*/
modifier whenPaused() {
_requirePaused();
_;
}
/**
* @dev Returns true if the contract is paused, and false otherwise.
*/
function paused() public view virtual returns (bool) {
return _paused;
}
/**
* @dev Throws if the contract is paused.
*/
function _requireNotPaused() internal view virtual {
require(!paused(), "Pausable: paused");
}
/**
* @dev Throws if the contract is not paused.
*/
function _requirePaused() internal view virtual {
require(paused(), "Pausable: not paused");
}
/**
* @dev Triggers stopped state.
*
* Requirements:
*
* - The contract must not be paused.
*/
function _pause() internal virtual whenNotPaused {
_paused = true;
emit Paused(_msgSender());
}
/**
* @dev Returns to normal state.
*
* Requirements:
*
* - The contract must be paused.
*/
function _unpause() internal virtual whenPaused {
_paused = false;
emit Unpaused(_msgSender());
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (security/ReentrancyGuard.sol)
pragma solidity ^0.8.0;
/**
* @dev Contract module that helps prevent reentrant calls to a function.
*
* Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier
* available, which can be applied to functions to make sure there are no nested
* (reentrant) calls to them.
*
* Note that because there is a single `nonReentrant` guard, functions marked as
* `nonReentrant` may not call one another. This can be worked around by making
* those functions `private`, and then adding `external` `nonReentrant` entry
* points to them.
*
* TIP: If you would like to learn more about reentrancy and alternative ways
* to protect against it, check out our blog post
* https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul].
*/
abstract contract ReentrancyGuard {
// Booleans are more expensive than uint256 or any type that takes up a full
// word because each write operation emits an extra SLOAD to first read the
// slot's contents, replace the bits taken up by the boolean, and then write
// back. This is the compiler's defense against contract upgrades and
// pointer aliasing, and it cannot be disabled.
// The values being non-zero value makes deployment a bit more expensive,
// but in exchange the refund on every call to nonReentrant will be lower in
// amount. Since refunds are capped to a percentage of the total
// transaction's gas, it is best to keep them low in cases like this one, to
// increase the likelihood of the full refund coming into effect.
uint256 private constant _NOT_ENTERED = 1;
uint256 private constant _ENTERED = 2;
uint256 private _status;
constructor() {
_status = _NOT_ENTERED;
}
/**
* @dev Prevents a contract from calling itself, directly or indirectly.
* Calling a `nonReentrant` function from another `nonReentrant`
* function is not supported. It is possible to prevent this from happening
* by making the `nonReentrant` function external, and making it call a
* `private` function that does the actual work.
*/
modifier nonReentrant() {
_nonReentrantBefore();
_;
_nonReentrantAfter();
}
function _nonReentrantBefore() private {
// On the first call to nonReentrant, _status will be _NOT_ENTERED
require(_status != _ENTERED, "ReentrancyGuard: reentrant call");
// Any calls to nonReentrant after this point will fail
_status = _ENTERED;
}
function _nonReentrantAfter() private {
// By storing the original value once again, a refund is triggered (see
// https://eips.ethereum.org/EIPS/eip-2200)
_status = _NOT_ENTERED;
}
/**
* @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a
* `nonReentrant` function in the call stack.
*/
function _reentrancyGuardEntered() internal view returns (bool) {
return _status == _ENTERED;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/extensions/IERC20Permit.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in
* https://eips.ethereum.org/EIPS/eip-2612[EIP-2612].
*
* Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by
* presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't
* need to send a transaction, and thus is not required to hold Ether at all.
*/
interface IERC20Permit {
/**
* @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens,
* given ``owner``'s signed approval.
*
* IMPORTANT: The same issues {IERC20-approve} has related to transaction
* ordering also apply here.
*
* Emits an {Approval} event.
*
* Requirements:
*
* - `spender` cannot be the zero address.
* - `deadline` must be a timestamp in the future.
* - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner`
* over the EIP712-formatted function arguments.
* - the signature must use ``owner``'s current nonce (see {nonces}).
*
* For more information on the signature format, see the
* https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP
* section].
*/
function permit(
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) external;
/**
* @dev Returns the current nonce for `owner`. This value must be
* included whenever a signature is generated for {permit}.
*
* Every successful call to {permit} increases ``owner``'s nonce by one. This
* prevents a signature from being used multiple times.
*/
function nonces(address owner) external view returns (uint256);
/**
* @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}.
*/
// solhint-disable-next-line func-name-mixedcase
function DOMAIN_SEPARATOR() external view returns (bytes32);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC20 standard as defined in the EIP.
*/
interface IERC20 {
/**
* @dev Emitted when `value` tokens are moved from one account (`from`) to
* another (`to`).
*
* Note that `value` may be zero.
*/
event Transfer(address indexed from, address indexed 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.
*/
event Approval(address indexed owner, address indexed spender, uint256 value);
/**
* @dev Returns the amount of tokens in existence.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns the amount of tokens owned by `account`.
*/
function balanceOf(address account) external view returns (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.
*/
function transfer(address to, uint256 amount) external returns (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.
*/
function allowance(address owner, address spender) external view returns (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.
*/
function approve(address spender, uint256 amount) external returns (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.
*/
function transferFrom(address from, address to, uint256 amount) external returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.3) (token/ERC20/utils/SafeERC20.sol)
pragma solidity ^0.8.0;
import "../IERC20.sol";
import "../extensions/IERC20Permit.sol";
import "../../../utils/Address.sol";
/**
* @title SafeERC20
* @dev Wrappers around ERC20 operations that throw on failure (when the token
* contract returns false). Tokens that return no value (and instead revert or
* throw on failure) are also supported, non-reverting calls are assumed to be
* successful.
* To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract,
* which allows you to call the safe operations as `token.safeTransfer(...)`, etc.
*/
library SafeERC20 {
using Address for address;
/**
* @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeTransfer(IERC20 token, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transfer.selector, to, value));
}
/**
* @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the
* calling contract. If `token` returns no value, non-reverting calls are assumed to be successful.
*/
function safeTransferFrom(IERC20 token, address from, address to, uint256 value) internal {
_callOptionalReturn(token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value));
}
/**
* @dev Deprecated. This function has issues similar to the ones found in
* {IERC20-approve}, and its usage is discouraged.
*
* Whenever possible, use {safeIncreaseAllowance} and
* {safeDecreaseAllowance} instead.
*/
function safeApprove(IERC20 token, address spender, uint256 value) internal {
// safeApprove should only be called when setting an initial allowance,
// or when resetting it to zero. To increase and decrease it, use
// 'safeIncreaseAllowance' and 'safeDecreaseAllowance'
require(
(value == 0) || (token.allowance(address(this), spender) == 0),
"SafeERC20: approve from non-zero to non-zero allowance"
);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, value));
}
/**
* @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeIncreaseAllowance(IERC20 token, address spender, uint256 value) internal {
uint256 oldAllowance = token.allowance(address(this), spender);
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance + value));
}
/**
* @dev Decrease the calling contract's allowance toward `spender` by `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful.
*/
function safeDecreaseAllowance(IERC20 token, address spender, uint256 value) internal {
unchecked {
uint256 oldAllowance = token.allowance(address(this), spender);
require(oldAllowance >= value, "SafeERC20: decreased allowance below zero");
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, oldAllowance - value));
}
}
/**
* @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value,
* non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval
* to be set to zero before setting it to a non-zero value, such as USDT.
*/
function forceApprove(IERC20 token, address spender, uint256 value) internal {
bytes memory approvalCall = abi.encodeWithSelector(token.approve.selector, spender, value);
if (!_callOptionalReturnBool(token, approvalCall)) {
_callOptionalReturn(token, abi.encodeWithSelector(token.approve.selector, spender, 0));
_callOptionalReturn(token, approvalCall);
}
}
/**
* @dev Use a ERC-2612 signature to set the `owner` approval toward `spender` on `token`.
* Revert on invalid signature.
*/
function safePermit(
IERC20Permit token,
address owner,
address spender,
uint256 value,
uint256 deadline,
uint8 v,
bytes32 r,
bytes32 s
) internal {
uint256 nonceBefore = token.nonces(owner);
token.permit(owner, spender, value, deadline, v, r, s);
uint256 nonceAfter = token.nonces(owner);
require(nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed");
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*/
function _callOptionalReturn(IERC20 token, bytes memory data) private {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that
// the target address contains contract code and also asserts for success in the low-level call.
bytes memory returndata = address(token).functionCall(data, "SafeERC20: low-level call failed");
require(returndata.length == 0 || abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed");
}
/**
* @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement
* on the return value: the return value is optional (but if data is returned, it must not be false).
* @param token The token targeted by the call.
* @param data The call data (encoded using abi.encode or one of its variants).
*
* This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead.
*/
function _callOptionalReturnBool(IERC20 token, bytes memory data) private returns (bool) {
// We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since
// we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false
// and not revert is the subcall reverts.
(bool success, bytes memory returndata) = address(token).call(data);
return
success && (returndata.length == 0 || abi.decode(returndata, (bool))) && Address.isContract(address(token));
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC721/ERC721.sol)
pragma solidity ^0.8.0;
import "./IERC721.sol";
import "./IERC721Receiver.sol";
import "./extensions/IERC721Metadata.sol";
import "../../utils/Address.sol";
import "../../utils/Context.sol";
import "../../utils/Strings.sol";
import "../../utils/introspection/ERC165.sol";
/**
* @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC721] Non-Fungible Token Standard, including
* the Metadata extension, but not including the Enumerable extension, which is available separately as
* {ERC721Enumerable}.
*/
contract ERC721 is Context, ERC165, IERC721, IERC721Metadata {
using Address for address;
using Strings for uint256;
// Token name
string private _name;
// Token symbol
string private _symbol;
// Mapping from token ID to owner address
mapping(uint256 => address) private _owners;
// Mapping owner address to token count
mapping(address => uint256) private _balances;
// Mapping from token ID to approved address
mapping(uint256 => address) private _tokenApprovals;
// Mapping from owner to operator approvals
mapping(address => mapping(address => bool)) private _operatorApprovals;
/**
* @dev Initializes the contract by setting a `name` and a `symbol` to the token collection.
*/
constructor(string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165, IERC165) returns (bool) {
return
interfaceId == type(IERC721).interfaceId ||
interfaceId == type(IERC721Metadata).interfaceId ||
super.supportsInterface(interfaceId);
}
/**
* @dev See {IERC721-balanceOf}.
*/
function balanceOf(address owner) public view virtual override returns (uint256) {
require(owner != address(0), "ERC721: address zero is not a valid owner");
return _balances[owner];
}
/**
* @dev See {IERC721-ownerOf}.
*/
function ownerOf(uint256 tokenId) public view virtual override returns (address) {
address owner = _ownerOf(tokenId);
require(owner != address(0), "ERC721: invalid token ID");
return owner;
}
/**
* @dev See {IERC721Metadata-name}.
*/
function name() public view virtual override returns (string memory) {
return _name;
}
/**
* @dev See {IERC721Metadata-symbol}.
*/
function symbol() public view virtual override returns (string memory) {
return _symbol;
}
/**
* @dev See {IERC721Metadata-tokenURI}.
*/
function tokenURI(uint256 tokenId) public view virtual override returns (string memory) {
_requireMinted(tokenId);
string memory baseURI = _baseURI();
return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : "";
}
/**
* @dev Base URI for computing {tokenURI}. If set, the resulting URI for each
* token will be the concatenation of the `baseURI` and the `tokenId`. Empty
* by default, can be overridden in child contracts.
*/
function _baseURI() internal view virtual returns (string memory) {
return "";
}
/**
* @dev See {IERC721-approve}.
*/
function approve(address to, uint256 tokenId) public virtual override {
address owner = ERC721.ownerOf(tokenId);
require(to != owner, "ERC721: approval to current owner");
require(
_msgSender() == owner || isApprovedForAll(owner, _msgSender()),
"ERC721: approve caller is not token owner or approved for all"
);
_approve(to, tokenId);
}
/**
* @dev See {IERC721-getApproved}.
*/
function getApproved(uint256 tokenId) public view virtual override returns (address) {
_requireMinted(tokenId);
return _tokenApprovals[tokenId];
}
/**
* @dev See {IERC721-setApprovalForAll}.
*/
function setApprovalForAll(address operator, bool approved) public virtual override {
_setApprovalForAll(_msgSender(), operator, approved);
}
/**
* @dev See {IERC721-isApprovedForAll}.
*/
function isApprovedForAll(address owner, address operator) public view virtual override returns (bool) {
return _operatorApprovals[owner][operator];
}
/**
* @dev See {IERC721-transferFrom}.
*/
function transferFrom(address from, address to, uint256 tokenId) public virtual override {
//solhint-disable-next-line max-line-length
require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: caller is not token owner or approved");
_transfer(from, to, tokenId);
}
/**
* @dev See {IERC721-safeTransferFrom}.
*/
function safeTransferFrom(address from, address to, uint256 tokenId) public virtual override {
safeTransferFrom(from, to, tokenId, "");
}
/**
* @dev See {IERC721-safeTransferFrom}.
*/
function safeTransferFrom(address from, address to, uint256 tokenId, bytes memory data) public virtual override {
require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: caller is not token owner or approved");
_safeTransfer(from, to, tokenId, data);
}
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC721 protocol to prevent tokens from being forever locked.
*
* `data` is additional data, it has no specified format and it is sent in call to `to`.
*
* This internal function is equivalent to {safeTransferFrom}, and can be used to e.g.
* implement alternative mechanisms to perform token transfer, such as signature-based.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function _safeTransfer(address from, address to, uint256 tokenId, bytes memory data) internal virtual {
_transfer(from, to, tokenId);
require(_checkOnERC721Received(from, to, tokenId, data), "ERC721: transfer to non ERC721Receiver implementer");
}
/**
* @dev Returns the owner of the `tokenId`. Does NOT revert if token doesn't exist
*/
function _ownerOf(uint256 tokenId) internal view virtual returns (address) {
return _owners[tokenId];
}
/**
* @dev Returns whether `tokenId` exists.
*
* Tokens can be managed by their owner or approved accounts via {approve} or {setApprovalForAll}.
*
* Tokens start existing when they are minted (`_mint`),
* and stop existing when they are burned (`_burn`).
*/
function _exists(uint256 tokenId) internal view virtual returns (bool) {
return _ownerOf(tokenId) != address(0);
}
/**
* @dev Returns whether `spender` is allowed to manage `tokenId`.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function _isApprovedOrOwner(address spender, uint256 tokenId) internal view virtual returns (bool) {
address owner = ERC721.ownerOf(tokenId);
return (spender == owner || isApprovedForAll(owner, spender) || getApproved(tokenId) == spender);
}
/**
* @dev Safely mints `tokenId` and transfers it to `to`.
*
* Requirements:
*
* - `tokenId` must not exist.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function _safeMint(address to, uint256 tokenId) internal virtual {
_safeMint(to, tokenId, "");
}
/**
* @dev Same as {xref-ERC721-_safeMint-address-uint256-}[`_safeMint`], with an additional `data` parameter which is
* forwarded in {IERC721Receiver-onERC721Received} to contract recipients.
*/
function _safeMint(address to, uint256 tokenId, bytes memory data) internal virtual {
_mint(to, tokenId);
require(
_checkOnERC721Received(address(0), to, tokenId, data),
"ERC721: transfer to non ERC721Receiver implementer"
);
}
/**
* @dev Mints `tokenId` and transfers it to `to`.
*
* WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible
*
* Requirements:
*
* - `tokenId` must not exist.
* - `to` cannot be the zero address.
*
* Emits a {Transfer} event.
*/
function _mint(address to, uint256 tokenId) internal virtual {
require(to != address(0), "ERC721: mint to the zero address");
require(!_exists(tokenId), "ERC721: token already minted");
_beforeTokenTransfer(address(0), to, tokenId, 1);
// Check that tokenId was not minted by `_beforeTokenTransfer` hook
require(!_exists(tokenId), "ERC721: token already minted");
unchecked {
// Will not overflow unless all 2**256 token ids are minted to the same owner.
// Given that tokens are minted one by one, it is impossible in practice that
// this ever happens. Might change if we allow batch minting.
// The ERC fails to describe this case.
_balances[to] += 1;
}
_owners[tokenId] = to;
emit Transfer(address(0), to, tokenId);
_afterTokenTransfer(address(0), to, tokenId, 1);
}
/**
* @dev Destroys `tokenId`.
* The approval is cleared when the token is burned.
* This is an internal function that does not check if the sender is authorized to operate on the token.
*
* Requirements:
*
* - `tokenId` must exist.
*
* Emits a {Transfer} event.
*/
function _burn(uint256 tokenId) internal virtual {
address owner = ERC721.ownerOf(tokenId);
_beforeTokenTransfer(owner, address(0), tokenId, 1);
// Update ownership in case tokenId was transferred by `_beforeTokenTransfer` hook
owner = ERC721.ownerOf(tokenId);
// Clear approvals
delete _tokenApprovals[tokenId];
unchecked {
// Cannot overflow, as that would require more tokens to be burned/transferred
// out than the owner initially received through minting and transferring in.
_balances[owner] -= 1;
}
delete _owners[tokenId];
emit Transfer(owner, address(0), tokenId);
_afterTokenTransfer(owner, address(0), tokenId, 1);
}
/**
* @dev Transfers `tokenId` from `from` to `to`.
* As opposed to {transferFrom}, this imposes no restrictions on msg.sender.
*
* Requirements:
*
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
*
* Emits a {Transfer} event.
*/
function _transfer(address from, address to, uint256 tokenId) internal virtual {
require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer from incorrect owner");
require(to != address(0), "ERC721: transfer to the zero address");
_beforeTokenTransfer(from, to, tokenId, 1);
// Check that tokenId was not transferred by `_beforeTokenTransfer` hook
require(ERC721.ownerOf(tokenId) == from, "ERC721: transfer from incorrect owner");
// Clear approvals from the previous owner
delete _tokenApprovals[tokenId];
unchecked {
// `_balances[from]` cannot overflow for the same reason as described in `_burn`:
// `from`'s balance is the number of token held, which is at least one before the current
// transfer.
// `_balances[to]` could overflow in the conditions described in `_mint`. That would require
// all 2**256 token ids to be minted, which in practice is impossible.
_balances[from] -= 1;
_balances[to] += 1;
}
_owners[tokenId] = to;
emit Transfer(from, to, tokenId);
_afterTokenTransfer(from, to, tokenId, 1);
}
/**
* @dev Approve `to` to operate on `tokenId`
*
* Emits an {Approval} event.
*/
function _approve(address to, uint256 tokenId) internal virtual {
_tokenApprovals[tokenId] = to;
emit Approval(ERC721.ownerOf(tokenId), to, tokenId);
}
/**
* @dev Approve `operator` to operate on all of `owner` tokens
*
* Emits an {ApprovalForAll} event.
*/
function _setApprovalForAll(address owner, address operator, bool approved) internal virtual {
require(owner != operator, "ERC721: approve to caller");
_operatorApprovals[owner][operator] = approved;
emit ApprovalForAll(owner, operator, approved);
}
/**
* @dev Reverts if the `tokenId` has not been minted yet.
*/
function _requireMinted(uint256 tokenId) internal view virtual {
require(_exists(tokenId), "ERC721: invalid token ID");
}
/**
* @dev Internal function to invoke {IERC721Receiver-onERC721Received} on a target address.
* The call is not executed if the target address is not a contract.
*
* @param from address representing the previous owner of the given token ID
* @param to target address that will receive the tokens
* @param tokenId uint256 ID of the token to be transferred
* @param data bytes optional data to send along with the call
* @return bool whether the call correctly returned the expected magic value
*/
function _checkOnERC721Received(
address from,
address to,
uint256 tokenId,
bytes memory data
) private returns (bool) {
if (to.isContract()) {
try IERC721Receiver(to).onERC721Received(_msgSender(), from, tokenId, data) returns (bytes4 retval) {
return retval == IERC721Receiver.onERC721Received.selector;
} catch (bytes memory reason) {
if (reason.length == 0) {
revert("ERC721: transfer to non ERC721Receiver implementer");
} else {
/// @solidity memory-safe-assembly
assembly {
revert(add(32, reason), mload(reason))
}
}
}
} else {
return true;
}
}
/**
* @dev Hook that is called before any token transfer. This includes minting and burning. If {ERC721Consecutive} is
* used, the hook may be called as part of a consecutive (batch) mint, as indicated by `batchSize` greater than 1.
*
* Calling conditions:
*
* - When `from` and `to` are both non-zero, ``from``'s tokens will be transferred to `to`.
* - When `from` is zero, the tokens will be minted for `to`.
* - When `to` is zero, ``from``'s tokens will be burned.
* - `from` and `to` are never both zero.
* - `batchSize` is non-zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(address from, address to, uint256 firstTokenId, uint256 batchSize) internal virtual {}
/**
* @dev Hook that is called after any token transfer. This includes minting and burning. If {ERC721Consecutive} is
* used, the hook may be called as part of a consecutive (batch) mint, as indicated by `batchSize` greater than 1.
*
* Calling conditions:
*
* - When `from` and `to` are both non-zero, ``from``'s tokens were transferred to `to`.
* - When `from` is zero, the tokens were minted for `to`.
* - When `to` is zero, ``from``'s tokens were burned.
* - `from` and `to` are never both zero.
* - `batchSize` is non-zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _afterTokenTransfer(address from, address to, uint256 firstTokenId, uint256 batchSize) internal virtual {}
/**
* @dev Unsafe write access to the balances, used by extensions that "mint" tokens using an {ownerOf} override.
*
* WARNING: Anyone calling this MUST ensure that the balances remain consistent with the ownership. The invariant
* being that for any address `a` the value returned by `balanceOf(a)` must be equal to the number of tokens such
* that `ownerOf(tokenId)` is `a`.
*/
// solhint-disable-next-line func-name-mixedcase
function __unsafe_increaseBalance(address account, uint256 amount) internal {
_balances[account] += amount;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC721/extensions/ERC721Burnable.sol)
pragma solidity ^0.8.0;
import "../ERC721.sol";
import "../../../utils/Context.sol";
/**
* @title ERC721 Burnable Token
* @dev ERC721 Token that can be burned (destroyed).
*/
abstract contract ERC721Burnable is Context, ERC721 {
/**
* @dev Burns `tokenId`. See {ERC721-_burn}.
*
* Requirements:
*
* - The caller must own `tokenId` or be an approved operator.
*/
function burn(uint256 tokenId) public virtual {
//solhint-disable-next-line max-line-length
require(_isApprovedOrOwner(_msgSender(), tokenId), "ERC721: caller is not token owner or approved");
_burn(tokenId);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (token/ERC721/extensions/ERC721Enumerable.sol)
pragma solidity ^0.8.0;
import "../ERC721.sol";
import "./IERC721Enumerable.sol";
/**
* @dev This implements an optional extension of {ERC721} defined in the EIP that adds
* enumerability of all the token ids in the contract as well as all token ids owned by each
* account.
*/
abstract contract ERC721Enumerable is ERC721, IERC721Enumerable {
// Mapping from owner to list of owned token IDs
mapping(address => mapping(uint256 => uint256)) private _ownedTokens;
// Mapping from token ID to index of the owner tokens list
mapping(uint256 => uint256) private _ownedTokensIndex;
// Array with all token ids, used for enumeration
uint256[] private _allTokens;
// Mapping from token id to position in the allTokens array
mapping(uint256 => uint256) private _allTokensIndex;
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override(IERC165, ERC721) returns (bool) {
return interfaceId == type(IERC721Enumerable).interfaceId || super.supportsInterface(interfaceId);
}
/**
* @dev See {IERC721Enumerable-tokenOfOwnerByIndex}.
*/
function tokenOfOwnerByIndex(address owner, uint256 index) public view virtual override returns (uint256) {
require(index < ERC721.balanceOf(owner), "ERC721Enumerable: owner index out of bounds");
return _ownedTokens[owner][index];
}
/**
* @dev See {IERC721Enumerable-totalSupply}.
*/
function totalSupply() public view virtual override returns (uint256) {
return _allTokens.length;
}
/**
* @dev See {IERC721Enumerable-tokenByIndex}.
*/
function tokenByIndex(uint256 index) public view virtual override returns (uint256) {
require(index < ERC721Enumerable.totalSupply(), "ERC721Enumerable: global index out of bounds");
return _allTokens[index];
}
/**
* @dev See {ERC721-_beforeTokenTransfer}.
*/
function _beforeTokenTransfer(
address from,
address to,
uint256 firstTokenId,
uint256 batchSize
) internal virtual override {
super._beforeTokenTransfer(from, to, firstTokenId, batchSize);
if (batchSize > 1) {
// Will only trigger during construction. Batch transferring (minting) is not available afterwards.
revert("ERC721Enumerable: consecutive transfers not supported");
}
uint256 tokenId = firstTokenId;
if (from == address(0)) {
_addTokenToAllTokensEnumeration(tokenId);
} else if (from != to) {
_removeTokenFromOwnerEnumeration(from, tokenId);
}
if (to == address(0)) {
_removeTokenFromAllTokensEnumeration(tokenId);
} else if (to != from) {
_addTokenToOwnerEnumeration(to, tokenId);
}
}
/**
* @dev Private function to add a token to this extension's ownership-tracking data structures.
* @param to address representing the new owner of the given token ID
* @param tokenId uint256 ID of the token to be added to the tokens list of the given address
*/
function _addTokenToOwnerEnumeration(address to, uint256 tokenId) private {
uint256 length = ERC721.balanceOf(to);
_ownedTokens[to][length] = tokenId;
_ownedTokensIndex[tokenId] = length;
}
/**
* @dev Private function to add a token to this extension's token tracking data structures.
* @param tokenId uint256 ID of the token to be added to the tokens list
*/
function _addTokenToAllTokensEnumeration(uint256 tokenId) private {
_allTokensIndex[tokenId] = _allTokens.length;
_allTokens.push(tokenId);
}
/**
* @dev Private function to remove a token from this extension's ownership-tracking data structures. Note that
* while the token is not assigned a new owner, the `_ownedTokensIndex` mapping is _not_ updated: this allows for
* gas optimizations e.g. when performing a transfer operation (avoiding double writes).
* This has O(1) time complexity, but alters the order of the _ownedTokens array.
* @param from address representing the previous owner of the given token ID
* @param tokenId uint256 ID of the token to be removed from the tokens list of the given address
*/
function _removeTokenFromOwnerEnumeration(address from, uint256 tokenId) private {
// To prevent a gap in from's tokens array, we store the last token in the index of the token to delete, and
// then delete the last slot (swap and pop).
uint256 lastTokenIndex = ERC721.balanceOf(from) - 1;
uint256 tokenIndex = _ownedTokensIndex[tokenId];
// When the token to delete is the last token, the swap operation is unnecessary
if (tokenIndex != lastTokenIndex) {
uint256 lastTokenId = _ownedTokens[from][lastTokenIndex];
_ownedTokens[from][tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token
_ownedTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index
}
// This also deletes the contents at the last position of the array
delete _ownedTokensIndex[tokenId];
delete _ownedTokens[from][lastTokenIndex];
}
/**
* @dev Private function to remove a token from this extension's token tracking data structures.
* This has O(1) time complexity, but alters the order of the _allTokens array.
* @param tokenId uint256 ID of the token to be removed from the tokens list
*/
function _removeTokenFromAllTokensEnumeration(uint256 tokenId) private {
// To prevent a gap in the tokens array, we store the last token in the index of the token to delete, and
// then delete the last slot (swap and pop).
uint256 lastTokenIndex = _allTokens.length - 1;
uint256 tokenIndex = _allTokensIndex[tokenId];
// When the token to delete is the last token, the swap operation is unnecessary. However, since this occurs so
// rarely (when the last minted token is burnt) that we still do the swap here to avoid the gas cost of adding
// an 'if' statement (like in _removeTokenFromOwnerEnumeration)
uint256 lastTokenId = _allTokens[lastTokenIndex];
_allTokens[tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token
_allTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index
// This also deletes the contents at the last position of the array
delete _allTokensIndex[tokenId];
_allTokens.pop();
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.5.0) (token/ERC721/extensions/IERC721Enumerable.sol)
pragma solidity ^0.8.0;
import "../IERC721.sol";
/**
* @title ERC-721 Non-Fungible Token Standard, optional enumeration extension
* @dev See https://eips.ethereum.org/EIPS/eip-721
*/
interface IERC721Enumerable is IERC721 {
/**
* @dev Returns the total amount of tokens stored by the contract.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns a token ID owned by `owner` at a given `index` of its token list.
* Use along with {balanceOf} to enumerate all of ``owner``'s tokens.
*/
function tokenOfOwnerByIndex(address owner, uint256 index) external view returns (uint256);
/**
* @dev Returns a token ID at a given `index` of all the tokens stored by the contract.
* Use along with {totalSupply} to enumerate all tokens.
*/
function tokenByIndex(uint256 index) external view returns (uint256);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (token/ERC721/extensions/IERC721Metadata.sol)
pragma solidity ^0.8.0;
import "../IERC721.sol";
/**
* @title ERC-721 Non-Fungible Token Standard, optional metadata extension
* @dev See https://eips.ethereum.org/EIPS/eip-721
*/
interface IERC721Metadata is IERC721 {
/**
* @dev Returns the token collection name.
*/
function name() external view returns (string memory);
/**
* @dev Returns the token collection symbol.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.
*/
function tokenURI(uint256 tokenId) external view returns (string memory);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (token/ERC721/IERC721.sol)
pragma solidity ^0.8.0;
import "../../utils/introspection/IERC165.sol";
/**
* @dev Required interface of an ERC721 compliant contract.
*/
interface IERC721 is IERC165 {
/**
* @dev Emitted when `tokenId` token is transferred from `from` to `to`.
*/
event Transfer(address indexed from, address indexed to, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables `approved` to manage the `tokenId` token.
*/
event Approval(address indexed owner, address indexed approved, uint256 indexed tokenId);
/**
* @dev Emitted when `owner` enables or disables (`approved`) `operator` to manage all of its assets.
*/
event ApprovalForAll(address indexed owner, address indexed operator, bool approved);
/**
* @dev Returns the number of tokens in ``owner``'s account.
*/
function balanceOf(address owner) external view returns (uint256 balance);
/**
* @dev Returns the owner of the `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function ownerOf(uint256 tokenId) external view returns (address owner);
/**
* @dev Safely transfers `tokenId` token from `from` to `to`.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(address from, address to, uint256 tokenId, bytes calldata data) external;
/**
* @dev Safely transfers `tokenId` token from `from` to `to`, checking first that contract recipients
* are aware of the ERC721 protocol to prevent tokens from being forever locked.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must exist and be owned by `from`.
* - If the caller is not `from`, it must have been allowed to move this token by either {approve} or {setApprovalForAll}.
* - If `to` refers to a smart contract, it must implement {IERC721Receiver-onERC721Received}, which is called upon a safe transfer.
*
* Emits a {Transfer} event.
*/
function safeTransferFrom(address from, address to, uint256 tokenId) external;
/**
* @dev Transfers `tokenId` token from `from` to `to`.
*
* WARNING: Note that the caller is responsible to confirm that the recipient is capable of receiving ERC721
* or else they may be permanently lost. Usage of {safeTransferFrom} prevents loss, though the caller must
* understand this adds an external call which potentially creates a reentrancy vulnerability.
*
* Requirements:
*
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
* - `tokenId` token must be owned by `from`.
* - If the caller is not `from`, it must be approved to move this token by either {approve} or {setApprovalForAll}.
*
* Emits a {Transfer} event.
*/
function transferFrom(address from, address to, uint256 tokenId) external;
/**
* @dev Gives permission to `to` to transfer `tokenId` token to another account.
* The approval is cleared when the token is transferred.
*
* Only a single account can be approved at a time, so approving the zero address clears previous approvals.
*
* Requirements:
*
* - The caller must own the token or be an approved operator.
* - `tokenId` must exist.
*
* Emits an {Approval} event.
*/
function approve(address to, uint256 tokenId) external;
/**
* @dev Approve or remove `operator` as an operator for the caller.
* Operators can call {transferFrom} or {safeTransferFrom} for any token owned by the caller.
*
* Requirements:
*
* - The `operator` cannot be the caller.
*
* Emits an {ApprovalForAll} event.
*/
function setApprovalForAll(address operator, bool approved) external;
/**
* @dev Returns the account approved for `tokenId` token.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function getApproved(uint256 tokenId) external view returns (address operator);
/**
* @dev Returns if the `operator` is allowed to manage all of the assets of `owner`.
*
* See {setApprovalForAll}
*/
function isApprovedForAll(address owner, address operator) external view returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.6.0) (token/ERC721/IERC721Receiver.sol)
pragma solidity ^0.8.0;
/**
* @title ERC721 token receiver interface
* @dev Interface for any contract that wants to support safeTransfers
* from ERC721 asset contracts.
*/
interface IERC721Receiver {
/**
* @dev Whenever an {IERC721} `tokenId` token is transferred to this contract via {IERC721-safeTransferFrom}
* by `operator` from `from`, this function is called.
*
* It must return its Solidity selector to confirm the token transfer.
* If any other value is returned or the interface is not implemented by the recipient, the transfer will be reverted.
*
* The selector can be obtained in Solidity with `IERC721Receiver.onERC721Received.selector`.
*/
function onERC721Received(
address operator,
address from,
uint256 tokenId,
bytes calldata data
) external returns (bytes4);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol)
pragma solidity ^0.8.1;
/**
* @dev Collection of functions related to the address type
*/
library Address {
/**
* @dev Returns true if `account` is a contract.
*
* [IMPORTANT]
* ====
* It is unsafe to assume that an address for which this function returns
* false is an externally-owned account (EOA) and not a contract.
*
* Among others, `isContract` will return false for the following
* types of addresses:
*
* - an externally-owned account
* - a contract in construction
* - an address where a contract will be created
* - an address where a contract lived, but was destroyed
*
* Furthermore, `isContract` will also return true if the target contract within
* the same transaction is already scheduled for destruction by `SELFDESTRUCT`,
* which only has an effect at the end of a transaction.
* ====
*
* [IMPORTANT]
* ====
* You shouldn't rely on `isContract` to protect against flash loan attacks!
*
* Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets
* like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract
* constructor.
* ====
*/
function isContract(address account) internal view returns (bool) {
// This method relies on extcodesize/address.code.length, which returns 0
// for contracts in construction, since the code is only stored at the end
// of the constructor execution.
return account.code.length > 0;
}
/**
* @dev Replacement for Solidity's `transfer`: sends `amount` wei to
* `recipient`, forwarding all available gas and reverting on errors.
*
* https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost
* of certain opcodes, possibly making contracts go over the 2300 gas limit
* imposed by `transfer`, making them unable to receive funds via
* `transfer`. {sendValue} removes this limitation.
*
* https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more].
*
* IMPORTANT: because control is transferred to `recipient`, care must be
* taken to not create reentrancy vulnerabilities. Consider using
* {ReentrancyGuard} or the
* https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern].
*/
function sendValue(address payable recipient, uint256 amount) internal {
require(address(this).balance >= amount, "Address: insufficient balance");
(bool success, ) = recipient.call{value: amount}("");
require(success, "Address: unable to send value, recipient may have reverted");
}
/**
* @dev Performs a Solidity function call using a low level `call`. A
* plain `call` is an unsafe replacement for a function call: use this
* function instead.
*
* If `target` reverts with a revert reason, it is bubbled up by this
* function (like regular Solidity function calls).
*
* Returns the raw returned data. To convert to the expected return value,
* use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`].
*
* Requirements:
*
* - `target` must be a contract.
* - calling `target` with `data` must not revert.
*
* _Available since v3.1._
*/
function functionCall(address target, bytes memory data) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, "Address: low-level call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with
* `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
return functionCallWithValue(target, data, 0, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but also transferring `value` wei to `target`.
*
* Requirements:
*
* - the calling contract must have an ETH balance of at least `value`.
* - the called Solidity function must be `payable`.
*
* _Available since v3.1._
*/
function functionCallWithValue(address target, bytes memory data, uint256 value) internal returns (bytes memory) {
return functionCallWithValue(target, data, value, "Address: low-level call with value failed");
}
/**
* @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but
* with `errorMessage` as a fallback revert reason when `target` reverts.
*
* _Available since v3.1._
*/
function functionCallWithValue(
address target,
bytes memory data,
uint256 value,
string memory errorMessage
) internal returns (bytes memory) {
require(address(this).balance >= value, "Address: insufficient balance for call");
(bool success, bytes memory returndata) = target.call{value: value}(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) {
return functionStaticCall(target, data, "Address: low-level static call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a static call.
*
* _Available since v3.3._
*/
function functionStaticCall(
address target,
bytes memory data,
string memory errorMessage
) internal view returns (bytes memory) {
(bool success, bytes memory returndata) = target.staticcall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(address target, bytes memory data) internal returns (bytes memory) {
return functionDelegateCall(target, data, "Address: low-level delegate call failed");
}
/**
* @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`],
* but performing a delegate call.
*
* _Available since v3.4._
*/
function functionDelegateCall(
address target,
bytes memory data,
string memory errorMessage
) internal returns (bytes memory) {
(bool success, bytes memory returndata) = target.delegatecall(data);
return verifyCallResultFromTarget(target, success, returndata, errorMessage);
}
/**
* @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling
* the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract.
*
* _Available since v4.8._
*/
function verifyCallResultFromTarget(
address target,
bool success,
bytes memory returndata,
string memory errorMessage
) internal view returns (bytes memory) {
if (success) {
if (returndata.length == 0) {
// only check isContract if the call was successful and the return data is empty
// otherwise we already know that it was a contract
require(isContract(target), "Address: call to non-contract");
}
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
/**
* @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the
* revert reason or using the provided one.
*
* _Available since v4.3._
*/
function verifyCallResult(
bool success,
bytes memory returndata,
string memory errorMessage
) internal pure returns (bytes memory) {
if (success) {
return returndata;
} else {
_revert(returndata, errorMessage);
}
}
function _revert(bytes memory returndata, string memory errorMessage) private pure {
// Look for revert reason and bubble it up if present
if (returndata.length > 0) {
// The easiest way to bubble the revert reason is using memory via assembly
/// @solidity memory-safe-assembly
assembly {
let returndata_size := mload(returndata)
revert(add(32, returndata), returndata_size)
}
} else {
revert(errorMessage);
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Context.sol)
pragma solidity ^0.8.0;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/Counters.sol)
pragma solidity ^0.8.0;
/**
* @title Counters
* @author Matt Condon (@shrugs)
* @dev Provides counters that can only be incremented, decremented or reset. This can be used e.g. to track the number
* of elements in a mapping, issuing ERC721 ids, or counting request ids.
*
* Include with `using Counters for Counters.Counter;`
*/
library Counters {
struct Counter {
// This variable should never be directly accessed by users of the library: interactions must be restricted to
// the library's function. As of Solidity v0.5.2, this cannot be enforced, though there is a proposal to add
// this feature: see https://github.com/ethereum/solidity/issues/4637
uint256 _value; // default: 0
}
function current(Counter storage counter) internal view returns (uint256) {
return counter._value;
}
function increment(Counter storage counter) internal {
unchecked {
counter._value += 1;
}
}
function decrement(Counter storage counter) internal {
uint256 value = counter._value;
require(value > 0, "Counter: decrement overflow");
unchecked {
counter._value = value - 1;
}
}
function reset(Counter storage counter) internal {
counter._value = 0;
}
}// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (utils/cryptography/draft-EIP712.sol) pragma solidity ^0.8.0; // EIP-712 is Final as of 2022-08-11. This file is deprecated. import "./EIP712.sol";
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/cryptography/ECDSA.sol)
pragma solidity ^0.8.0;
import "../Strings.sol";
/**
* @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations.
*
* These functions can be used to verify that a message was signed by the holder
* of the private keys of a given address.
*/
library ECDSA {
enum RecoverError {
NoError,
InvalidSignature,
InvalidSignatureLength,
InvalidSignatureS,
InvalidSignatureV // Deprecated in v4.8
}
function _throwError(RecoverError error) private pure {
if (error == RecoverError.NoError) {
return; // no error: do nothing
} else if (error == RecoverError.InvalidSignature) {
revert("ECDSA: invalid signature");
} else if (error == RecoverError.InvalidSignatureLength) {
revert("ECDSA: invalid signature length");
} else if (error == RecoverError.InvalidSignatureS) {
revert("ECDSA: invalid signature 's' value");
}
}
/**
* @dev Returns the address that signed a hashed message (`hash`) with
* `signature` or error string. This address can then be used for verification purposes.
*
* The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
* this function rejects them by requiring the `s` value to be in the lower
* half order, and the `v` value to be either 27 or 28.
*
* IMPORTANT: `hash` _must_ be the result of a hash operation for the
* verification to be secure: it is possible to craft signatures that
* recover to arbitrary addresses for non-hashed data. A safe way to ensure
* this is by receiving a hash of the original message (which may otherwise
* be too long), and then calling {toEthSignedMessageHash} on it.
*
* Documentation for signature generation:
* - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js]
* - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers]
*
* _Available since v4.3._
*/
function tryRecover(bytes32 hash, bytes memory signature) internal pure returns (address, RecoverError) {
if (signature.length == 65) {
bytes32 r;
bytes32 s;
uint8 v;
// ecrecover takes the signature parameters, and the only way to get them
// currently is to use assembly.
/// @solidity memory-safe-assembly
assembly {
r := mload(add(signature, 0x20))
s := mload(add(signature, 0x40))
v := byte(0, mload(add(signature, 0x60)))
}
return tryRecover(hash, v, r, s);
} else {
return (address(0), RecoverError.InvalidSignatureLength);
}
}
/**
* @dev Returns the address that signed a hashed message (`hash`) with
* `signature`. This address can then be used for verification purposes.
*
* The `ecrecover` EVM opcode allows for malleable (non-unique) signatures:
* this function rejects them by requiring the `s` value to be in the lower
* half order, and the `v` value to be either 27 or 28.
*
* IMPORTANT: `hash` _must_ be the result of a hash operation for the
* verification to be secure: it is possible to craft signatures that
* recover to arbitrary addresses for non-hashed data. A safe way to ensure
* this is by receiving a hash of the original message (which may otherwise
* be too long), and then calling {toEthSignedMessageHash} on it.
*/
function recover(bytes32 hash, bytes memory signature) internal pure returns (address) {
(address recovered, RecoverError error) = tryRecover(hash, signature);
_throwError(error);
return recovered;
}
/**
* @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately.
*
* See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures]
*
* _Available since v4.3._
*/
function tryRecover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address, RecoverError) {
bytes32 s = vs & bytes32(0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff);
uint8 v = uint8((uint256(vs) >> 255) + 27);
return tryRecover(hash, v, r, s);
}
/**
* @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately.
*
* _Available since v4.2._
*/
function recover(bytes32 hash, bytes32 r, bytes32 vs) internal pure returns (address) {
(address recovered, RecoverError error) = tryRecover(hash, r, vs);
_throwError(error);
return recovered;
}
/**
* @dev Overload of {ECDSA-tryRecover} that receives the `v`,
* `r` and `s` signature fields separately.
*
* _Available since v4.3._
*/
function tryRecover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address, RecoverError) {
// EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature
// unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines
// the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most
// signatures from current libraries generate a unique signature with an s-value in the lower half order.
//
// If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value
// with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or
// vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept
// these malleable signatures as well.
if (uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0) {
return (address(0), RecoverError.InvalidSignatureS);
}
// If the signature is valid (and not malleable), return the signer address
address signer = ecrecover(hash, v, r, s);
if (signer == address(0)) {
return (address(0), RecoverError.InvalidSignature);
}
return (signer, RecoverError.NoError);
}
/**
* @dev Overload of {ECDSA-recover} that receives the `v`,
* `r` and `s` signature fields separately.
*/
function recover(bytes32 hash, uint8 v, bytes32 r, bytes32 s) internal pure returns (address) {
(address recovered, RecoverError error) = tryRecover(hash, v, r, s);
_throwError(error);
return recovered;
}
/**
* @dev Returns an Ethereum Signed Message, created from a `hash`. This
* produces hash corresponding to the one signed with the
* https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]
* JSON-RPC method as part of EIP-191.
*
* See {recover}.
*/
function toEthSignedMessageHash(bytes32 hash) internal pure returns (bytes32 message) {
// 32 is the length in bytes of hash,
// enforced by the type signature above
/// @solidity memory-safe-assembly
assembly {
mstore(0x00, "\x19Ethereum Signed Message:\n32")
mstore(0x1c, hash)
message := keccak256(0x00, 0x3c)
}
}
/**
* @dev Returns an Ethereum Signed Message, created from `s`. This
* produces hash corresponding to the one signed with the
* https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`]
* JSON-RPC method as part of EIP-191.
*
* See {recover}.
*/
function toEthSignedMessageHash(bytes memory s) internal pure returns (bytes32) {
return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n", Strings.toString(s.length), s));
}
/**
* @dev Returns an Ethereum Signed Typed Data, created from a
* `domainSeparator` and a `structHash`. This produces hash corresponding
* to the one signed with the
* https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`]
* JSON-RPC method as part of EIP-712.
*
* See {recover}.
*/
function toTypedDataHash(bytes32 domainSeparator, bytes32 structHash) internal pure returns (bytes32 data) {
/// @solidity memory-safe-assembly
assembly {
let ptr := mload(0x40)
mstore(ptr, "\x19\x01")
mstore(add(ptr, 0x02), domainSeparator)
mstore(add(ptr, 0x22), structHash)
data := keccak256(ptr, 0x42)
}
}
/**
* @dev Returns an Ethereum Signed Data with intended validator, created from a
* `validator` and `data` according to the version 0 of EIP-191.
*
* See {recover}.
*/
function toDataWithIntendedValidatorHash(address validator, bytes memory data) internal pure returns (bytes32) {
return keccak256(abi.encodePacked("\x19\x00", validator, data));
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/cryptography/EIP712.sol)
pragma solidity ^0.8.8;
import "./ECDSA.sol";
import "../ShortStrings.sol";
import "../../interfaces/IERC5267.sol";
/**
* @dev https://eips.ethereum.org/EIPS/eip-712[EIP 712] is a standard for hashing and signing of typed structured data.
*
* The encoding specified in the EIP is very generic, and such a generic implementation in Solidity is not feasible,
* thus this contract does not implement the encoding itself. Protocols need to implement the type-specific encoding
* they need in their contracts using a combination of `abi.encode` and `keccak256`.
*
* This contract implements the EIP 712 domain separator ({_domainSeparatorV4}) that is used as part of the encoding
* scheme, and the final step of the encoding to obtain the message digest that is then signed via ECDSA
* ({_hashTypedDataV4}).
*
* The implementation of the domain separator was designed to be as efficient as possible while still properly updating
* the chain id to protect against replay attacks on an eventual fork of the chain.
*
* NOTE: This contract implements the version of the encoding known as "v4", as implemented by the JSON RPC method
* https://docs.metamask.io/guide/signing-data.html[`eth_signTypedDataV4` in MetaMask].
*
* NOTE: In the upgradeable version of this contract, the cached values will correspond to the address, and the domain
* separator of the implementation contract. This will cause the `_domainSeparatorV4` function to always rebuild the
* separator from the immutable values, which is cheaper than accessing a cached version in cold storage.
*
* _Available since v3.4._
*
* @custom:oz-upgrades-unsafe-allow state-variable-immutable state-variable-assignment
*/
abstract contract EIP712 is IERC5267 {
using ShortStrings for *;
bytes32 private constant _TYPE_HASH =
keccak256("EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)");
// Cache the domain separator as an immutable value, but also store the chain id that it corresponds to, in order to
// invalidate the cached domain separator if the chain id changes.
bytes32 private immutable _cachedDomainSeparator;
uint256 private immutable _cachedChainId;
address private immutable _cachedThis;
bytes32 private immutable _hashedName;
bytes32 private immutable _hashedVersion;
ShortString private immutable _name;
ShortString private immutable _version;
string private _nameFallback;
string private _versionFallback;
/**
* @dev Initializes the domain separator and parameter caches.
*
* The meaning of `name` and `version` is specified in
* https://eips.ethereum.org/EIPS/eip-712#definition-of-domainseparator[EIP 712]:
*
* - `name`: the user readable name of the signing domain, i.e. the name of the DApp or the protocol.
* - `version`: the current major version of the signing domain.
*
* NOTE: These parameters cannot be changed except through a xref:learn::upgrading-smart-contracts.adoc[smart
* contract upgrade].
*/
constructor(string memory name, string memory version) {
_name = name.toShortStringWithFallback(_nameFallback);
_version = version.toShortStringWithFallback(_versionFallback);
_hashedName = keccak256(bytes(name));
_hashedVersion = keccak256(bytes(version));
_cachedChainId = block.chainid;
_cachedDomainSeparator = _buildDomainSeparator();
_cachedThis = address(this);
}
/**
* @dev Returns the domain separator for the current chain.
*/
function _domainSeparatorV4() internal view returns (bytes32) {
if (address(this) == _cachedThis && block.chainid == _cachedChainId) {
return _cachedDomainSeparator;
} else {
return _buildDomainSeparator();
}
}
function _buildDomainSeparator() private view returns (bytes32) {
return keccak256(abi.encode(_TYPE_HASH, _hashedName, _hashedVersion, block.chainid, address(this)));
}
/**
* @dev Given an already https://eips.ethereum.org/EIPS/eip-712#definition-of-hashstruct[hashed struct], this
* function returns the hash of the fully encoded EIP712 message for this domain.
*
* This hash can be used together with {ECDSA-recover} to obtain the signer of a message. For example:
*
* ```solidity
* bytes32 digest = _hashTypedDataV4(keccak256(abi.encode(
* keccak256("Mail(address to,string contents)"),
* mailTo,
* keccak256(bytes(mailContents))
* )));
* address signer = ECDSA.recover(digest, signature);
* ```
*/
function _hashTypedDataV4(bytes32 structHash) internal view virtual returns (bytes32) {
return ECDSA.toTypedDataHash(_domainSeparatorV4(), structHash);
}
/**
* @dev See {EIP-5267}.
*
* _Available since v4.9._
*/
function eip712Domain()
public
view
virtual
override
returns (
bytes1 fields,
string memory name,
string memory version,
uint256 chainId,
address verifyingContract,
bytes32 salt,
uint256[] memory extensions
)
{
return (
hex"0f", // 01111
_name.toStringWithFallback(_nameFallback),
_version.toStringWithFallback(_versionFallback),
block.chainid,
address(this),
bytes32(0),
new uint256[](0)
);
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol)
pragma solidity ^0.8.0;
import "./IERC165.sol";
/**
* @dev Implementation of the {IERC165} interface.
*
* Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check
* for the additional interface id that will be supported. For example:
*
* ```solidity
* function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
* return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId);
* }
* ```
*
* Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation.
*/
abstract contract ERC165 is IERC165 {
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
return interfaceId == type(IERC165).interfaceId;
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol)
pragma solidity ^0.8.0;
/**
* @dev Interface of the ERC165 standard, as defined in the
* https://eips.ethereum.org/EIPS/eip-165[EIP].
*
* Implementers can declare support of contract interfaces, which can then be
* queried by others ({ERC165Checker}).
*
* For an implementation, see {ERC165}.
*/
interface IERC165 {
/**
* @dev Returns true if this contract implements the interface defined by
* `interfaceId`. See the corresponding
* https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section]
* to learn more about how these ids are created.
*
* This function call must use less than 30 000 gas.
*/
function supportsInterface(bytes4 interfaceId) external view returns (bool);
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/math/Math.sol)
pragma solidity ^0.8.0;
/**
* @dev Standard math utilities missing in the Solidity language.
*/
library Math {
enum Rounding {
Down, // Toward negative infinity
Up, // Toward infinity
Zero // Toward zero
}
/**
* @dev Returns the largest of two numbers.
*/
function max(uint256 a, uint256 b) internal pure returns (uint256) {
return a > b ? a : b;
}
/**
* @dev Returns the smallest of two numbers.
*/
function min(uint256 a, uint256 b) internal pure returns (uint256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two numbers. The result is rounded towards
* zero.
*/
function average(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b) / 2 can overflow.
return (a & b) + (a ^ b) / 2;
}
/**
* @dev Returns the ceiling of the division of two numbers.
*
* This differs from standard division with `/` in that it rounds up instead
* of rounding down.
*/
function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) {
// (a + b - 1) / b can overflow on addition, so we distribute.
return a == 0 ? 0 : (a - 1) / b + 1;
}
/**
* @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0
* @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv)
* with further edits by Uniswap Labs also under MIT license.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator) internal pure returns (uint256 result) {
unchecked {
// 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use
// use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256
// variables such that product = prod1 * 2^256 + prod0.
uint256 prod0; // Least significant 256 bits of the product
uint256 prod1; // Most significant 256 bits of the product
assembly {
let mm := mulmod(x, y, not(0))
prod0 := mul(x, y)
prod1 := sub(sub(mm, prod0), lt(mm, prod0))
}
// Handle non-overflow cases, 256 by 256 division.
if (prod1 == 0) {
// Solidity will revert if denominator == 0, unlike the div opcode on its own.
// The surrounding unchecked block does not change this fact.
// See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic.
return prod0 / denominator;
}
// Make sure the result is less than 2^256. Also prevents denominator == 0.
require(denominator > prod1, "Math: mulDiv overflow");
///////////////////////////////////////////////
// 512 by 256 division.
///////////////////////////////////////////////
// Make division exact by subtracting the remainder from [prod1 prod0].
uint256 remainder;
assembly {
// Compute remainder using mulmod.
remainder := mulmod(x, y, denominator)
// Subtract 256 bit number from 512 bit number.
prod1 := sub(prod1, gt(remainder, prod0))
prod0 := sub(prod0, remainder)
}
// Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1.
// See https://cs.stackexchange.com/q/138556/92363.
// Does not overflow because the denominator cannot be zero at this stage in the function.
uint256 twos = denominator & (~denominator + 1);
assembly {
// Divide denominator by twos.
denominator := div(denominator, twos)
// Divide [prod1 prod0] by twos.
prod0 := div(prod0, twos)
// Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one.
twos := add(div(sub(0, twos), twos), 1)
}
// Shift in bits from prod1 into prod0.
prod0 |= prod1 * twos;
// Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such
// that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for
// four bits. That is, denominator * inv = 1 mod 2^4.
uint256 inverse = (3 * denominator) ^ 2;
// Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works
// in modular arithmetic, doubling the correct bits in each step.
inverse *= 2 - denominator * inverse; // inverse mod 2^8
inverse *= 2 - denominator * inverse; // inverse mod 2^16
inverse *= 2 - denominator * inverse; // inverse mod 2^32
inverse *= 2 - denominator * inverse; // inverse mod 2^64
inverse *= 2 - denominator * inverse; // inverse mod 2^128
inverse *= 2 - denominator * inverse; // inverse mod 2^256
// Because the division is now exact we can divide by multiplying with the modular inverse of denominator.
// This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is
// less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1
// is no longer required.
result = prod0 * inverse;
return result;
}
}
/**
* @notice Calculates x * y / denominator with full precision, following the selected rounding direction.
*/
function mulDiv(uint256 x, uint256 y, uint256 denominator, Rounding rounding) internal pure returns (uint256) {
uint256 result = mulDiv(x, y, denominator);
if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) {
result += 1;
}
return result;
}
/**
* @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down.
*
* Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11).
*/
function sqrt(uint256 a) internal pure returns (uint256) {
if (a == 0) {
return 0;
}
// For our first guess, we get the biggest power of 2 which is smaller than the square root of the target.
//
// We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have
// `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`.
//
// This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)`
// → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))`
// → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)`
//
// Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit.
uint256 result = 1 << (log2(a) >> 1);
// At this point `result` is an estimation with one bit of precision. We know the true value is a uint128,
// since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at
// every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision
// into the expected uint128 result.
unchecked {
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
result = (result + a / result) >> 1;
return min(result, a / result);
}
}
/**
* @notice Calculates sqrt(a), following the selected rounding direction.
*/
function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = sqrt(a);
return result + (rounding == Rounding.Up && result * result < a ? 1 : 0);
}
}
/**
* @dev Return the log in base 2, rounded down, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 128;
}
if (value >> 64 > 0) {
value >>= 64;
result += 64;
}
if (value >> 32 > 0) {
value >>= 32;
result += 32;
}
if (value >> 16 > 0) {
value >>= 16;
result += 16;
}
if (value >> 8 > 0) {
value >>= 8;
result += 8;
}
if (value >> 4 > 0) {
value >>= 4;
result += 4;
}
if (value >> 2 > 0) {
value >>= 2;
result += 2;
}
if (value >> 1 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 2, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log2(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log2(value);
return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 10, rounded down, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >= 10 ** 64) {
value /= 10 ** 64;
result += 64;
}
if (value >= 10 ** 32) {
value /= 10 ** 32;
result += 32;
}
if (value >= 10 ** 16) {
value /= 10 ** 16;
result += 16;
}
if (value >= 10 ** 8) {
value /= 10 ** 8;
result += 8;
}
if (value >= 10 ** 4) {
value /= 10 ** 4;
result += 4;
}
if (value >= 10 ** 2) {
value /= 10 ** 2;
result += 2;
}
if (value >= 10 ** 1) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 10, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log10(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log10(value);
return result + (rounding == Rounding.Up && 10 ** result < value ? 1 : 0);
}
}
/**
* @dev Return the log in base 256, rounded down, of a positive value.
* Returns 0 if given 0.
*
* Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string.
*/
function log256(uint256 value) internal pure returns (uint256) {
uint256 result = 0;
unchecked {
if (value >> 128 > 0) {
value >>= 128;
result += 16;
}
if (value >> 64 > 0) {
value >>= 64;
result += 8;
}
if (value >> 32 > 0) {
value >>= 32;
result += 4;
}
if (value >> 16 > 0) {
value >>= 16;
result += 2;
}
if (value >> 8 > 0) {
result += 1;
}
}
return result;
}
/**
* @dev Return the log in base 256, following the selected rounding direction, of a positive value.
* Returns 0 if given 0.
*/
function log256(uint256 value, Rounding rounding) internal pure returns (uint256) {
unchecked {
uint256 result = log256(value);
return result + (rounding == Rounding.Up && 1 << (result << 3) < value ? 1 : 0);
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/math/SafeMath.sol)
pragma solidity ^0.8.0;
// CAUTION
// This version of SafeMath should only be used with Solidity 0.8 or later,
// because it relies on the compiler's built in overflow checks.
/**
* @dev Wrappers over Solidity's arithmetic operations.
*
* NOTE: `SafeMath` is generally not needed starting with Solidity 0.8, since the compiler
* now has built in overflow checking.
*/
library SafeMath {
/**
* @dev Returns the addition of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryAdd(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
uint256 c = a + b;
if (c < a) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the subtraction of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function trySub(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b > a) return (false, 0);
return (true, a - b);
}
}
/**
* @dev Returns the multiplication of two unsigned integers, with an overflow flag.
*
* _Available since v3.4._
*/
function tryMul(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
// 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-contracts/pull/522
if (a == 0) return (true, 0);
uint256 c = a * b;
if (c / a != b) return (false, 0);
return (true, c);
}
}
/**
* @dev Returns the division of two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryDiv(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a / b);
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag.
*
* _Available since v3.4._
*/
function tryMod(uint256 a, uint256 b) internal pure returns (bool, uint256) {
unchecked {
if (b == 0) return (false, 0);
return (true, a % b);
}
}
/**
* @dev Returns the addition of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
return a + b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting on
* overflow (when the result is negative).
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
return a - b;
}
/**
* @dev Returns the multiplication of two unsigned integers, reverting on
* overflow.
*
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
return a * b;
}
/**
* @dev Returns the integer division of two unsigned integers, reverting on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator.
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
return a / b;
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting when dividing by zero.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
return a % b;
}
/**
* @dev Returns the subtraction of two unsigned integers, reverting with custom message on
* overflow (when the result is negative).
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {trySub}.
*
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
unchecked {
require(b <= a, errorMessage);
return a - b;
}
}
/**
* @dev Returns the integer division of two unsigned integers, reverting with custom message on
* division by zero. The result is rounded towards zero.
*
* Counterpart to Solidity's `/` operator. Note: this function uses a
* `revert` opcode (which leaves remaining gas untouched) while Solidity
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a / b;
}
}
/**
* @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo),
* reverting with custom message when dividing by zero.
*
* CAUTION: This function is deprecated because it requires allocating memory for the error
* message unnecessarily. For custom revert reasons use {tryMod}.
*
* Counterpart to Solidity's `%` operator. This function uses a `revert`
* opcode (which leaves remaining gas untouched) while Solidity uses an
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
unchecked {
require(b > 0, errorMessage);
return a % b;
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SignedMath.sol)
pragma solidity ^0.8.0;
/**
* @dev Standard signed math utilities missing in the Solidity language.
*/
library SignedMath {
/**
* @dev Returns the largest of two signed numbers.
*/
function max(int256 a, int256 b) internal pure returns (int256) {
return a > b ? a : b;
}
/**
* @dev Returns the smallest of two signed numbers.
*/
function min(int256 a, int256 b) internal pure returns (int256) {
return a < b ? a : b;
}
/**
* @dev Returns the average of two signed numbers without overflow.
* The result is rounded towards zero.
*/
function average(int256 a, int256 b) internal pure returns (int256) {
// Formula from the book "Hacker's Delight"
int256 x = (a & b) + ((a ^ b) >> 1);
return x + (int256(uint256(x) >> 255) & (a ^ b));
}
/**
* @dev Returns the absolute unsigned value of a signed value.
*/
function abs(int256 n) internal pure returns (uint256) {
unchecked {
// must be unchecked in order to support `n = type(int256).min`
return uint256(n >= 0 ? n : -n);
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/ShortStrings.sol)
pragma solidity ^0.8.8;
import "./StorageSlot.sol";
// | string | 0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA |
// | length | 0x BB |
type ShortString is bytes32;
/**
* @dev This library provides functions to convert short memory strings
* into a `ShortString` type that can be used as an immutable variable.
*
* Strings of arbitrary length can be optimized using this library if
* they are short enough (up to 31 bytes) by packing them with their
* length (1 byte) in a single EVM word (32 bytes). Additionally, a
* fallback mechanism can be used for every other case.
*
* Usage example:
*
* ```solidity
* contract Named {
* using ShortStrings for *;
*
* ShortString private immutable _name;
* string private _nameFallback;
*
* constructor(string memory contractName) {
* _name = contractName.toShortStringWithFallback(_nameFallback);
* }
*
* function name() external view returns (string memory) {
* return _name.toStringWithFallback(_nameFallback);
* }
* }
* ```
*/
library ShortStrings {
// Used as an identifier for strings longer than 31 bytes.
bytes32 private constant _FALLBACK_SENTINEL = 0x00000000000000000000000000000000000000000000000000000000000000FF;
error StringTooLong(string str);
error InvalidShortString();
/**
* @dev Encode a string of at most 31 chars into a `ShortString`.
*
* This will trigger a `StringTooLong` error is the input string is too long.
*/
function toShortString(string memory str) internal pure returns (ShortString) {
bytes memory bstr = bytes(str);
if (bstr.length > 31) {
revert StringTooLong(str);
}
return ShortString.wrap(bytes32(uint256(bytes32(bstr)) | bstr.length));
}
/**
* @dev Decode a `ShortString` back to a "normal" string.
*/
function toString(ShortString sstr) internal pure returns (string memory) {
uint256 len = byteLength(sstr);
// using `new string(len)` would work locally but is not memory safe.
string memory str = new string(32);
/// @solidity memory-safe-assembly
assembly {
mstore(str, len)
mstore(add(str, 0x20), sstr)
}
return str;
}
/**
* @dev Return the length of a `ShortString`.
*/
function byteLength(ShortString sstr) internal pure returns (uint256) {
uint256 result = uint256(ShortString.unwrap(sstr)) & 0xFF;
if (result > 31) {
revert InvalidShortString();
}
return result;
}
/**
* @dev Encode a string into a `ShortString`, or write it to storage if it is too long.
*/
function toShortStringWithFallback(string memory value, string storage store) internal returns (ShortString) {
if (bytes(value).length < 32) {
return toShortString(value);
} else {
StorageSlot.getStringSlot(store).value = value;
return ShortString.wrap(_FALLBACK_SENTINEL);
}
}
/**
* @dev Decode a string that was encoded to `ShortString` or written to storage using {setWithFallback}.
*/
function toStringWithFallback(ShortString value, string storage store) internal pure returns (string memory) {
if (ShortString.unwrap(value) != _FALLBACK_SENTINEL) {
return toString(value);
} else {
return store;
}
}
/**
* @dev Return the length of a string that was encoded to `ShortString` or written to storage using {setWithFallback}.
*
* WARNING: This will return the "byte length" of the string. This may not reflect the actual length in terms of
* actual characters as the UTF-8 encoding of a single character can span over multiple bytes.
*/
function byteLengthWithFallback(ShortString value, string storage store) internal view returns (uint256) {
if (ShortString.unwrap(value) != _FALLBACK_SENTINEL) {
return byteLength(value);
} else {
return bytes(store).length;
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/StorageSlot.sol)
// This file was procedurally generated from scripts/generate/templates/StorageSlot.js.
pragma solidity ^0.8.0;
/**
* @dev Library for reading and writing primitive types to specific storage slots.
*
* Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts.
* This library helps with reading and writing to such slots without the need for inline assembly.
*
* The functions in this library return Slot structs that contain a `value` member that can be used to read or write.
*
* Example usage to set ERC1967 implementation slot:
* ```solidity
* contract ERC1967 {
* bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc;
*
* function _getImplementation() internal view returns (address) {
* return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value;
* }
*
* function _setImplementation(address newImplementation) internal {
* require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract");
* StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation;
* }
* }
* ```
*
* _Available since v4.1 for `address`, `bool`, `bytes32`, `uint256`._
* _Available since v4.9 for `string`, `bytes`._
*/
library StorageSlot {
struct AddressSlot {
address value;
}
struct BooleanSlot {
bool value;
}
struct Bytes32Slot {
bytes32 value;
}
struct Uint256Slot {
uint256 value;
}
struct StringSlot {
string value;
}
struct BytesSlot {
bytes value;
}
/**
* @dev Returns an `AddressSlot` with member `value` located at `slot`.
*/
function getAddressSlot(bytes32 slot) internal pure returns (AddressSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `BooleanSlot` with member `value` located at `slot`.
*/
function getBooleanSlot(bytes32 slot) internal pure returns (BooleanSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `Bytes32Slot` with member `value` located at `slot`.
*/
function getBytes32Slot(bytes32 slot) internal pure returns (Bytes32Slot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `Uint256Slot` with member `value` located at `slot`.
*/
function getUint256Slot(bytes32 slot) internal pure returns (Uint256Slot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `StringSlot` with member `value` located at `slot`.
*/
function getStringSlot(bytes32 slot) internal pure returns (StringSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `StringSlot` representation of the string storage pointer `store`.
*/
function getStringSlot(string storage store) internal pure returns (StringSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := store.slot
}
}
/**
* @dev Returns an `BytesSlot` with member `value` located at `slot`.
*/
function getBytesSlot(bytes32 slot) internal pure returns (BytesSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := slot
}
}
/**
* @dev Returns an `BytesSlot` representation of the bytes storage pointer `store`.
*/
function getBytesSlot(bytes storage store) internal pure returns (BytesSlot storage r) {
/// @solidity memory-safe-assembly
assembly {
r.slot := store.slot
}
}
}// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (utils/Strings.sol)
pragma solidity ^0.8.0;
import "./math/Math.sol";
import "./math/SignedMath.sol";
/**
* @dev String operations.
*/
library Strings {
bytes16 private constant _SYMBOLS = "0123456789abcdef";
uint8 private constant _ADDRESS_LENGTH = 20;
/**
* @dev Converts a `uint256` to its ASCII `string` decimal representation.
*/
function toString(uint256 value) internal pure returns (string memory) {
unchecked {
uint256 length = Math.log10(value) + 1;
string memory buffer = new string(length);
uint256 ptr;
/// @solidity memory-safe-assembly
assembly {
ptr := add(buffer, add(32, length))
}
while (true) {
ptr--;
/// @solidity memory-safe-assembly
assembly {
mstore8(ptr, byte(mod(value, 10), _SYMBOLS))
}
value /= 10;
if (value == 0) break;
}
return buffer;
}
}
/**
* @dev Converts a `int256` to its ASCII `string` decimal representation.
*/
function toString(int256 value) internal pure returns (string memory) {
return string(abi.encodePacked(value < 0 ? "-" : "", toString(SignedMath.abs(value))));
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation.
*/
function toHexString(uint256 value) internal pure returns (string memory) {
unchecked {
return toHexString(value, Math.log256(value) + 1);
}
}
/**
* @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length.
*/
function toHexString(uint256 value, uint256 length) internal pure returns (string memory) {
bytes memory buffer = new bytes(2 * length + 2);
buffer[0] = "0";
buffer[1] = "x";
for (uint256 i = 2 * length + 1; i > 1; --i) {
buffer[i] = _SYMBOLS[value & 0xf];
value >>= 4;
}
require(value == 0, "Strings: hex length insufficient");
return string(buffer);
}
/**
* @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation.
*/
function toHexString(address addr) internal pure returns (string memory) {
return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH);
}
/**
* @dev Returns true if the two strings are equal.
*/
function equal(string memory a, string memory b) internal pure returns (bool) {
return keccak256(bytes(a)) == keccak256(bytes(b));
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.8;
import "@openzeppelin/contracts/access/AccessControl.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
import "../libraries/Errors.sol";
import "../interfaces/dex/IUniswapRouter.sol";
/// @title Pay using a Decentralized automated market maker (AMM) when needed
/// @author Masa Finance
/// @notice Smart contract to call a Dex AMM smart contract to pay to a project fee receiver
/// wallet recipient
/// @dev This smart contract will call the Uniswap Router interface, based on
/// https://github.com/Uniswap/v2-periphery/blob/master/contracts/interfaces/IUniswapV2Router01.sol
abstract contract PaymentGateway is AccessControl {
using SafeERC20 for IERC20;
using SafeMath for uint256;
bytes32 public constant PROJECT_ADMIN_ROLE =
keccak256("PROJECT_ADMIN_ROLE");
struct PaymentParams {
address swapRouter; // Swap router address
address wrappedNativeToken; // Wrapped native token address
address stableCoin; // Stable coin to pay the fee in (USDC)
address masaToken; // Utility token to pay the fee in (MASA)
address projectFeeReceiver; // Wallet that will receive the project fee
address protocolFeeReceiver; // Wallet that will receive the protocol fee
uint256 protocolFeeAmount; // Protocol fee amount in USD
uint256 protocolFeePercent; // Protocol fee amount added to the project fee
uint256 protocolFeePercentSub; // Protocol fee amount substracted from the project fee
}
/* ========== STATE VARIABLES =========================================== */
address public swapRouter;
address public wrappedNativeToken;
address public stableCoin; // USDC. It also needs to be enabled as payment method, if we want to pay in USDC
address public masaToken; // MASA. It also needs to be enabled as payment method, if we want to pay in MASA
// enabled payment methods: ETH and ERC20 tokens
mapping(address => bool) public enabledPaymentMethod;
address[] public enabledPaymentMethods;
address public projectFeeReceiver;
address public protocolFeeReceiver;
uint256 public protocolFeeAmount;
uint256 public protocolFeePercent; // Protocol fee amount added to the project fee
uint256 public protocolFeePercentSub; // Protocol fee amount substracted from the project fee
/* ========== INITIALIZE ================================================ */
/// @notice Creates a new Dex AMM
/// @dev Creates a new Decentralized automated market maker (AMM) smart contract,
// that will call the Uniswap Router interface
/// @param admin Administrator of the smart contract
/// @param paymentParams Payment params
constructor(address admin, PaymentParams memory paymentParams) {
_grantRole(DEFAULT_ADMIN_ROLE, admin);
swapRouter = paymentParams.swapRouter;
wrappedNativeToken = paymentParams.wrappedNativeToken;
stableCoin = paymentParams.stableCoin;
masaToken = paymentParams.masaToken;
projectFeeReceiver = paymentParams.projectFeeReceiver;
protocolFeeReceiver = paymentParams.protocolFeeReceiver;
protocolFeeAmount = paymentParams.protocolFeeAmount;
protocolFeePercent = paymentParams.protocolFeePercent;
protocolFeePercentSub = paymentParams.protocolFeePercentSub;
}
/* ========== RESTRICTED FUNCTIONS ====================================== */
/// @notice Sets the swap router address
/// @dev The caller must have the admin role to call this function
/// @param _swapRouter New swap router address
function setSwapRouter(
address _swapRouter
) external onlyRole(DEFAULT_ADMIN_ROLE) {
if (swapRouter == _swapRouter) revert SameValue();
swapRouter = _swapRouter;
}
/// @notice Sets the wrapped native token address
/// @dev The caller must have the admin role to call this function
/// @param _wrappedNativeToken New wrapped native token address
function setWrappedNativeToken(
address _wrappedNativeToken
) external onlyRole(DEFAULT_ADMIN_ROLE) {
if (wrappedNativeToken == _wrappedNativeToken) revert SameValue();
wrappedNativeToken = _wrappedNativeToken;
}
/// @notice Sets the stable coin to pay the fee in (USDC)
/// @dev The caller must have the admin role to call this function
/// @param _stableCoin New stable coin to pay the fee in
function setStableCoin(
address _stableCoin
) external onlyRole(DEFAULT_ADMIN_ROLE) {
if (stableCoin == _stableCoin) revert SameValue();
stableCoin = _stableCoin;
}
/// @notice Sets the utility token to pay the fee in (MASA)
/// @dev The caller must have the admin role to call this function
/// It can be set to address(0) to disable paying in MASA
/// @param _masaToken New utility token to pay the fee in
function setMasaToken(
address _masaToken
) external onlyRole(DEFAULT_ADMIN_ROLE) {
if (masaToken == _masaToken) revert SameValue();
masaToken = _masaToken;
}
/// @notice Adds a new token as a valid payment method
/// @dev The caller must have the admin role to call this function
/// @param _paymentMethod New token to add
function enablePaymentMethod(
address _paymentMethod
) external onlyRole(DEFAULT_ADMIN_ROLE) {
if (enabledPaymentMethod[_paymentMethod]) revert AlreadyAdded();
enabledPaymentMethod[_paymentMethod] = true;
enabledPaymentMethods.push(_paymentMethod);
}
/// @notice Removes a token as a valid payment method
/// @dev The caller must have the admin role to call this function
/// @param _paymentMethod Token to remove
function disablePaymentMethod(
address _paymentMethod
) external onlyRole(DEFAULT_ADMIN_ROLE) {
if (!enabledPaymentMethod[_paymentMethod])
revert NonExistingErc20Token(_paymentMethod);
enabledPaymentMethod[_paymentMethod] = false;
for (uint256 i = 0; i < enabledPaymentMethods.length; i++) {
if (enabledPaymentMethods[i] == _paymentMethod) {
enabledPaymentMethods[i] = enabledPaymentMethods[
enabledPaymentMethods.length - 1
];
enabledPaymentMethods.pop();
break;
}
}
}
/// @notice Set the project fee receiver wallet
/// @dev The caller must have the admin or project admin role to call this function
/// @param _projectFeeReceiver New project fee receiver wallet
function setProjectFeeReceiver(address _projectFeeReceiver) external {
if (
!hasRole(DEFAULT_ADMIN_ROLE, _msgSender()) &&
!hasRole(PROJECT_ADMIN_ROLE, _msgSender())
) revert UserMustHaveProtocolOrProjectAdminRole();
if (_projectFeeReceiver == projectFeeReceiver) revert SameValue();
projectFeeReceiver = _projectFeeReceiver;
}
/// @notice Set the protocol fee wallet
/// @dev The caller must have the admin role to call this function
/// @param _protocolFeeReceiver New protocol fee wallet
function setProtocolFeeReceiver(
address _protocolFeeReceiver
) external onlyRole(DEFAULT_ADMIN_ROLE) {
if (_protocolFeeReceiver == protocolFeeReceiver) revert SameValue();
protocolFeeReceiver = _protocolFeeReceiver;
}
/// @notice Set the protocol fee amount
/// @dev The caller must have the admin role to call this function
/// @param _protocolFeeAmount New protocol fee amount
function setProtocolFeeAmount(
uint256 _protocolFeeAmount
) external onlyRole(DEFAULT_ADMIN_ROLE) {
if (_protocolFeeAmount == protocolFeeAmount) revert SameValue();
protocolFeeAmount = _protocolFeeAmount;
}
/// @notice Set the protocol fee percent added to the project fee
/// @dev The caller must have the admin role to call this function
/// @param _protocolFeePercent New protocol fee percent added to the project fee
function setProtocolFeePercent(
uint256 _protocolFeePercent
) external onlyRole(DEFAULT_ADMIN_ROLE) {
if (_protocolFeePercent == protocolFeePercent) revert SameValue();
protocolFeePercent = _protocolFeePercent;
}
/// @notice Set the protocol fee percent substracted from the amount
/// @dev The caller must have the admin role to call this function
/// @param _protocolFeePercentSub New protocol fee percent substracted from the amount
function setProtocolFeePercentSub(
uint256 _protocolFeePercentSub
) external onlyRole(DEFAULT_ADMIN_ROLE) {
if (_protocolFeePercentSub == protocolFeePercentSub) revert SameValue();
protocolFeePercentSub = _protocolFeePercentSub;
}
/* ========== MUTATIVE FUNCTIONS ======================================== */
/* ========== VIEWS ===================================================== */
/// @notice Returns all available payment methods
/// @dev Returns the address of all available payment methods
/// @return Array of all enabled payment methods
function getEnabledPaymentMethods()
external
view
returns (address[] memory)
{
return enabledPaymentMethods;
}
/// @notice Calculates the protocol fee added to the project fee
/// @dev This method will calculate the protocol fee based on the payment method
/// @param paymentMethod Address of token that user want to pay
/// @param amount Price to be paid in the specified payment method
function getProtocolFee(
address paymentMethod,
uint256 amount
) external view returns (uint256) {
return _getProtocolFee(paymentMethod, amount);
}
/// @notice Calculates the protocol fee substracted from the amount
/// @dev This method will calculate the protocol fee based on the payment method
/// @param amount Price to be paid in the specified payment method
function getProtocolFeeSub(uint256 amount) external view returns (uint256) {
return _getProtocolFeeSub(amount);
}
/* ========== PRIVATE FUNCTIONS ========================================= */
/// @notice Converts an amount from a stable coin to a payment method amount
/// @dev This method will perform the swap between the stable coin and the
/// payment method, and return the amount of the payment method,
/// performing the swap if necessary
/// @param paymentMethod Address of token that user want to pay
/// @param amount Price to be converted in the specified payment method
function _convertFromStableCoin(
address paymentMethod,
uint256 amount
) internal view paymentParamsAlreadySet(amount) returns (uint256) {
if (!enabledPaymentMethod[paymentMethod] || paymentMethod == stableCoin)
revert InvalidToken(paymentMethod);
if (amount == 0) return 0;
if (paymentMethod == address(0)) {
return _estimateSwapAmount(wrappedNativeToken, stableCoin, amount);
} else {
return _estimateSwapAmount(paymentMethod, stableCoin, amount);
}
}
/// @notice Calculates the protocol fee added to the project fee
/// @dev This method will calculate the protocol fee based on the payment method
/// @param paymentMethod Address of token that user want to pay
/// @param amount Price to be paid in the specified payment method
function _getProtocolFee(
address paymentMethod,
uint256 amount
) internal view returns (uint256) {
uint256 protocolFee = 0;
if (protocolFeeAmount > 0) {
if (paymentMethod == stableCoin) {
protocolFee = protocolFeeAmount;
} else {
protocolFee = _convertFromStableCoin(
paymentMethod,
protocolFeeAmount
);
}
}
if (protocolFeePercent > 0) {
protocolFee = protocolFee.add(
amount.mul(protocolFeePercent).div(100)
);
}
return protocolFee;
}
/// @notice Calculates the protocol fee substracted from the amount
/// @dev This method will calculate the protocol fee based on the payment method
/// @param amount Price to be paid in the specified payment method
function _getProtocolFeeSub(
uint256 amount
) internal view returns (uint256) {
if (protocolFeePercentSub > 0) {
return amount.mul(protocolFeePercentSub).div(100);
} else {
return 0;
}
}
/// @notice Performs the payment in any payment method
/// @dev This method will transfer the funds to the project fee receiver wallet, performing
/// the swap if necessary, and transfer the protocol fee to the protocol fee wallet
/// @param paymentMethod Address of token that user want to pay
/// @param amount Price to be paid in the specified payment method
/// @param protocolFee Protocol fee to be paid in the specified payment method
function _pay(
address paymentMethod,
uint256 amount,
uint256 protocolFee
) internal paymentParamsAlreadySet(amount.add(protocolFee)) {
if (amount == 0 && protocolFee == 0) return;
uint256 protocolFeeSub = _getProtocolFeeSub(amount);
if (
(protocolFee > 0 || protocolFeeSub > 0) &&
protocolFeeReceiver == address(0)
) revert ProtocolFeeReceiverNotSet();
if (!enabledPaymentMethod[paymentMethod])
revert InvalidPaymentMethod(paymentMethod);
if (paymentMethod == address(0)) {
// ETH
if (msg.value < amount.add(protocolFee))
revert InsufficientEthAmount(amount.add(protocolFee));
if (amount.sub(protocolFeeSub) > 0) {
(bool success, ) = payable(projectFeeReceiver).call{
value: amount.sub(protocolFeeSub)
}("");
if (!success) revert TransferFailed();
}
if (protocolFee > 0) {
(bool success, ) = payable(protocolFeeReceiver).call{
value: protocolFee
}("");
if (!success) revert TransferFailed();
}
if (protocolFeeSub > 0) {
(bool success, ) = payable(protocolFeeReceiver).call{
value: protocolFeeSub
}("");
if (!success) revert TransferFailed();
}
if (msg.value > amount.add(protocolFee)) {
// return diff
uint256 refund = msg.value.sub(amount.add(protocolFee));
(bool success, ) = payable(msg.sender).call{value: refund}("");
if (!success) revert RefundFailed();
}
} else {
// ERC20 token, including MASA and USDC
if (amount.sub(protocolFeeSub) > 0) {
IERC20(paymentMethod).safeTransferFrom(
msg.sender,
projectFeeReceiver,
amount.sub(protocolFeeSub)
);
}
if (protocolFee > 0) {
IERC20(paymentMethod).safeTransferFrom(
msg.sender,
protocolFeeReceiver,
protocolFee
);
}
if (protocolFeeSub > 0) {
IERC20(paymentMethod).safeTransferFrom(
msg.sender,
protocolFeeReceiver,
protocolFeeSub
);
}
}
}
function _estimateSwapAmount(
address _fromToken,
address _toToken,
uint256 _amountOut
) private view returns (uint256) {
uint256[] memory amounts;
address[] memory path;
path = _getPathFromTokenToToken(_fromToken, _toToken);
amounts = IUniswapRouter(swapRouter).getAmountsIn(_amountOut, path);
return amounts[0];
}
function _getPathFromTokenToToken(
address fromToken,
address toToken
) private view returns (address[] memory) {
if (fromToken == wrappedNativeToken || toToken == wrappedNativeToken) {
address[] memory path = new address[](2);
path[0] = fromToken == wrappedNativeToken
? wrappedNativeToken
: fromToken;
path[1] = toToken == wrappedNativeToken
? wrappedNativeToken
: toToken;
return path;
} else {
address[] memory path = new address[](3);
path[0] = fromToken;
path[1] = wrappedNativeToken;
path[2] = toToken;
return path;
}
}
/* ========== MODIFIERS ================================================= */
modifier paymentParamsAlreadySet(uint256 amount) {
if (amount > 0 && swapRouter == address(0))
revert PaymentParamsNotSet();
if (amount > 0 && wrappedNativeToken == address(0))
revert PaymentParamsNotSet();
if (amount > 0 && stableCoin == address(0))
revert PaymentParamsNotSet();
if (amount > 0 && projectFeeReceiver == address(0))
revert PaymentParamsNotSet();
_;
}
/* ========== EVENTS ==================================================== */
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.8;
/// @title Uniswap Router interface
/// @author Masa Finance
/// @notice Interface of the Uniswap Router contract
/// @dev This interface is used to interact with the Uniswap Router contract,
/// and gets the most important functions of the contract. It's based on
/// https://github.com/Uniswap/v2-periphery/blob/master/contracts/interfaces/IUniswapV2Router01.sol
interface IUniswapRouter {
function swapExactTokensForTokens(
uint256 amountIn,
uint256 amountOutMin,
address[] calldata path,
address to,
uint256 deadline
) external returns (uint256[] memory amounts);
function swapExactETHForTokens(
uint256 amountOutMin,
address[] calldata path,
address to,
uint256 deadline
) external payable returns (uint256[] memory amounts);
function swapExactTokensForETH(
uint256 amountIn,
uint256 amountOutMin,
address[] calldata path,
address to,
uint256 deadline
) external returns (uint256[] memory amounts);
function getAmountsOut(
uint256 amountIn,
address[] calldata path
) external view returns (uint256[] memory amounts);
function getAmountsIn(
uint256 amountOut,
address[] calldata path
) external view returns (uint256[] memory amounts);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.8;
import "../tokens/SBT/ISBT.sol";
interface ILinkableSBT is ISBT {
function addLinkPrice() external view returns (uint256);
function addLinkPriceMASA() external view returns (uint256);
function queryLinkPrice() external view returns (uint256);
function queryLinkPriceMASA() external view returns (uint256);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.8;
import "../tokens/SBT/ISBT.sol";
import "./ISoulName.sol";
interface ISoulboundIdentity is ISBT {
function mint(address to) external payable returns (uint256);
function mint(
address paymentMethod,
address to
) external payable returns (uint256);
function mintIdentityWithName(
address to,
string memory name,
uint256 yearsPeriod,
string memory _tokenURI
) external payable returns (uint256);
function mintIdentityWithName(
address paymentMethod,
address to,
string memory name,
uint256 yearsPeriod,
string memory _tokenURI
) external payable returns (uint256);
function getSoulName() external view returns (ISoulName);
function tokenOfOwner(address owner) external view returns (uint256);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.8;
interface ISoulName {
function mint(
address to,
string memory name,
uint256 yearsPeriod,
string memory _tokenURI
) external returns (uint256);
function getExtension() external view returns (string memory);
function isAvailable(
string memory name
) external view returns (bool available);
function tokenData(
uint256 tokenId
) external view returns (string memory name, uint256 expirationDate);
function getTokenData(
string memory name
)
external
view
returns (
string memory sbtName,
bool linked,
uint256 identityId,
uint256 tokenId,
uint256 expirationDate,
bool active
);
function getTokenId(string memory name) external view returns (uint256);
function getSoulNames(
address owner
) external view returns (string[] memory sbtNames);
function getSoulNames(
uint256 identityId
) external view returns (string[] memory sbtNames);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.8;
error AddressDoesNotHaveIdentity(address to);
error AlreadyAdded();
error AuthorityNotExists(address authority);
error CallerNotOwner(address caller);
error CallerNotReader(address caller);
error CreditScoreAlreadyCreated(address to);
error IdentityAlreadyCreated(address to);
error IdentityOwnerIsReader(uint256 readerIdentityId);
error InsufficientEthAmount(uint256 amount);
error IdentityOwnerNotTokenOwner(uint256 tokenId, uint256 ownerIdentityId);
error InvalidPaymentMethod(address paymentMethod);
error InvalidSignature();
error InvalidSignatureDate(uint256 signatureDate);
error InvalidToken(address token);
error InvalidTokenURI(string tokenURI);
error LinkAlreadyExists(
address token,
uint256 tokenId,
uint256 readerIdentityId,
uint256 signatureDate
);
error LinkAlreadyRevoked();
error LinkDoesNotExist();
error NameAlreadyExists(string name);
error NameNotFound(string name);
error NameRegisteredByOtherAccount(string name, uint256 tokenId);
error NotAuthorized(address signer);
error NonExistingErc20Token(address erc20token);
error NotLinkedToAnIdentitySBT();
error PaymentParamsNotSet();
error ProtocolFeeReceiverNotSet();
error RefundFailed();
error SameValue();
error SBTAlreadyLinked(address token);
error SoulNameContractNotSet();
error SoulNameNotExist();
error SoulNameNotRegistered(address token);
error TokenNotFound(uint256 tokenId);
error TransferFailed();
error URIAlreadyExists(string tokenURI);
error UserMustHaveProtocolOrProjectAdminRole();
error ValidPeriodExpired(uint256 expirationDate);
error ZeroAddress();
error ZeroLengthName(string name);
error ZeroYearsPeriod(uint256 yearsPeriod);// SPDX-License-Identifier: MIT
pragma solidity ^0.8.8;
/// @title Utilities library for Masa Contracts Identity repository
/// @author Masa Finance
/// @notice Library of utilities for Masa Contracts Identity repository
library Utils {
struct slice {
uint256 _len;
uint256 _ptr;
}
function toLowerCase(
string memory _str
) internal pure returns (string memory) {
bytes memory bStr = bytes(_str);
bytes memory bLower = new bytes(bStr.length);
for (uint256 i = 0; i < bStr.length; i++) {
// Uppercase character...
if ((bStr[i] >= 0x41) && (bStr[i] <= 0x5A)) {
// So we add 0x20 to make it lowercase
bLower[i] = bytes1(uint8(bStr[i]) + 0x20);
} else {
bLower[i] = bStr[i];
}
}
return string(bLower);
}
function toSlice(string memory self) private pure returns (slice memory) {
uint256 ptr;
assembly {
ptr := add(self, 0x20)
}
return slice(bytes(self).length, ptr);
}
function startsWith(
string memory str,
string memory needle
) internal pure returns (bool) {
slice memory s_str = toSlice(str);
slice memory s_needle = toSlice(needle);
if (s_str._len < s_needle._len) {
return false;
}
if (s_str._ptr == s_needle._ptr) {
return true;
}
bool equal;
assembly {
let length := mload(s_needle)
let selfptr := mload(add(s_str, 0x20))
let needleptr := mload(add(s_needle, 0x20))
equal := eq(
keccak256(selfptr, length),
keccak256(needleptr, length)
)
}
return equal;
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.8;
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "../tokens/MasaSBTAuthority.sol";
/// @title Soulbound reference Authority SBT
/// @author Masa Finance
/// @notice Soulbound token that represents a Authority SBT
/// @dev Inherits from the SBT contract.
contract ReferenceSBTAuthority is MasaSBTAuthority, ReentrancyGuard {
error MaxSBTMinted(address to, uint256 maximum);
uint256 public maxSBTToMint = 1;
/* ========== STATE VARIABLES =========================================== */
/* ========== INITIALIZE ================================================ */
/// @notice Creates a new Authority SBT
/// @dev Creates a new Authority SBT, inheriting from the SBT contract.
/// @param admin Administrator of the smart contract
/// @param name Name of the token
/// @param symbol Symbol of the token
/// @param baseTokenURI Base URI of the token
/// @param soulboundIdentity Address of the SoulboundIdentity contract
/// @param paymentParams Payment gateway params
/// @param _maxSBTToMint Maximum number of SBT that can be minted
constructor(
address admin,
string memory name,
string memory symbol,
string memory baseTokenURI,
address soulboundIdentity,
PaymentParams memory paymentParams,
uint256 _maxSBTToMint
)
MasaSBTAuthority(
admin,
name,
symbol,
baseTokenURI,
soulboundIdentity,
paymentParams
)
{
maxSBTToMint = _maxSBTToMint;
}
/* ========== RESTRICTED FUNCTIONS ====================================== */
/* ========== MUTATIVE FUNCTIONS ======================================== */
/// @notice Mints a new SBT
/// @dev The caller must have the MINTER role
/// @param paymentMethod Address of token that user want to pay
/// @param identityId TokenId of the identity to mint the NFT to
/// @return The SBT ID of the newly minted SBT
function mint(
address paymentMethod,
uint256 identityId
) external payable nonReentrant returns (uint256) {
address to = soulboundIdentity.ownerOf(identityId);
if (maxSBTToMint > 0 && balanceOf(to) >= maxSBTToMint)
revert MaxSBTMinted(to, maxSBTToMint);
uint256 tokenId = _mintWithCounter(paymentMethod, to);
emit MintedToIdentity(tokenId, identityId);
return tokenId;
}
/// @notice Mints a new SBT
/// @dev The caller must have the MINTER role
/// @param paymentMethod Address of token that user want to pay
/// @param to The address to mint the SBT to
/// @return The SBT ID of the newly minted SBT
function mint(
address paymentMethod,
address to
) external payable nonReentrant returns (uint256) {
if (maxSBTToMint > 0 && balanceOf(to) >= maxSBTToMint)
revert MaxSBTMinted(to, maxSBTToMint);
uint256 tokenId = _mintWithCounter(paymentMethod, to);
emit MintedToAddress(tokenId, to);
return tokenId;
}
/// @notice Bulk mint of new SBTs
/// @dev The caller must have the MINTER role
/// @param paymentMethod Address of token that user want to pay
/// @param identityId TokenIds array of the identity to mint the NFT to
/// @return tokenIds The SBT IDs of the newly minted SBTs
function mint(
address paymentMethod,
uint256[] memory identityId
) external payable nonReentrant returns (uint256[] memory tokenIds) {
tokenIds = new uint256[](identityId.length);
uint256 t = 0;
for (uint256 i = 0; i < identityId.length; i++) {
address to = soulboundIdentity.ownerOf(identityId[i]);
if (maxSBTToMint > 0 && balanceOf(to) >= maxSBTToMint)
revert MaxSBTMinted(to, maxSBTToMint);
uint256 tokenId = _mintWithCounter(paymentMethod, to);
emit MintedToIdentity(tokenId, identityId[i]);
tokenIds[t] = tokenId;
t++;
}
return tokenIds;
}
/// @notice Bulk mint of new SBTs
/// @dev The caller must have the MINTER role
/// @param paymentMethod Address of token that user want to pay
/// @param to Addresses array to mint the SBT to
/// @return tokenIds The SBT IDs of the newly minted SBTs
function mint(
address paymentMethod,
address[] memory to
) external payable nonReentrant returns (uint256[] memory tokenIds) {
tokenIds = new uint256[](to.length);
uint256 t = 0;
for (uint256 i = 0; i < to.length; i++) {
if (maxSBTToMint > 0 && balanceOf(to[i]) >= maxSBTToMint)
revert MaxSBTMinted(to[i], maxSBTToMint);
uint256 tokenId = _mintWithCounter(paymentMethod, to[i]);
emit MintedToAddress(tokenId, to[i]);
tokenIds[t] = tokenId;
t++;
}
return tokenIds;
}
/* ========== VIEWS ===================================================== */
function tokenURI(
uint256 tokenId
) public view virtual override returns (string memory) {
_requireMinted(tokenId);
return _baseURI();
}
/* ========== PRIVATE FUNCTIONS ========================================= */
/* ========== MODIFIERS ================================================= */
/* ========== EVENTS ==================================================== */
event MintedToIdentity(uint256 tokenId, uint256 identityId);
event MintedToAddress(uint256 tokenId, address to);
}// Sources flattened with hardhat v2.17.1 https://hardhat.org // SPDX-License-Identifier: MIT // File @openzeppelin/contracts/access/[email protected] // Original license: SPDX_License_Identifier: MIT // OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol) pragma solidity ^0.8.0; /** * @dev External interface of AccessControl declared to support ERC165 detection. */ interface IAccessControl { /** * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole` * * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite * {RoleAdminChanged} not being emitted signaling this. * * _Available since v3.1._ */ event RoleAdminChanged( bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole ); /** * @dev Emitted when `account` is granted `role`. * * `sender` is the account that originated the contract call, an admin role * bearer except when using {AccessControl-_setupRole}. */ event RoleGranted( bytes32 indexed role, address indexed account, address indexed sender ); /** * @dev Emitted when `account` is revoked `role`. * * `sender` is the account that originated the contract call: * - if using `revokeRole`, it is the admin role bearer * - if using `renounceRole`, it is the role bearer (i.e. `account`) */ event RoleRevoked( bytes32 indexed role, address indexed account, address indexed sender ); /** * @dev Returns `true` if `account` has been granted `role`. */ function hasRole( bytes32 role, address account ) external view returns (bool); /** * @dev Returns the admin role that controls `role`. See {grantRole} and * {revokeRole}. * * To change a role's admin, use {AccessControl-_setRoleAdmin}. */ function getRoleAdmin(bytes32 role) external view returns (bytes32); /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. * * Requirements: * * - the caller must have ``role``'s admin role. */ function grantRole(bytes32 role, address account) external; /** * @dev Revokes `role` from `account`. * * If `account` had been granted `role`, emits a {RoleRevoked} event. * * Requirements: * * - the caller must have ``role``'s admin role. */ function revokeRole(bytes32 role, address account) external; /** * @dev Revokes `role` from the calling account. * * Roles are often managed via {grantRole} and {revokeRole}: this function's * purpose is to provide a mechanism for accounts to lose their privileges * if they are compromised (such as when a trusted device is misplaced). * * If the calling account had been granted `role`, emits a {RoleRevoked} * event. * * Requirements: * * - the caller must be `account`. */ function renounceRole(bytes32 role, address account) external; } // File @openzeppelin/contracts/utils/[email protected] // Original license: SPDX_License_Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Context.sol) pragma solidity ^0.8.0; /** * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } } // File @openzeppelin/contracts/utils/introspection/[email protected] // Original license: SPDX_License_Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC165 standard, as defined in the * https://eips.ethereum.org/EIPS/eip-165[EIP]. * * Implementers can declare support of contract interfaces, which can then be * queried by others ({ERC165Checker}). * * For an implementation, see {ERC165}. */ interface IERC165 { /** * @dev Returns true if this contract implements the interface defined by * `interfaceId`. See the corresponding * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] * to learn more about how these ids are created. * * This function call must use less than 30 000 gas. */ function supportsInterface(bytes4 interfaceId) external view returns (bool); } // File @openzeppelin/contracts/utils/introspection/[email protected] // Original license: SPDX_License_Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol) pragma solidity ^0.8.0; /** * @dev Implementation of the {IERC165} interface. * * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check * for the additional interface id that will be supported. For example: * * ```solidity * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId); * } * ``` * * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation. */ abstract contract ERC165 is IERC165 { /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface( bytes4 interfaceId ) public view virtual override returns (bool) { return interfaceId == type(IERC165).interfaceId; } } // File @openzeppelin/contracts/utils/math/[email protected] // Original license: SPDX_License_Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (utils/math/Math.sol) pragma solidity ^0.8.0; /** * @dev Standard math utilities missing in the Solidity language. */ library Math { enum Rounding { Down, // Toward negative infinity Up, // Toward infinity Zero // Toward zero } /** * @dev Returns the largest of two numbers. */ function max(uint256 a, uint256 b) internal pure returns (uint256) { return a > b ? a : b; } /** * @dev Returns the smallest of two numbers. */ function min(uint256 a, uint256 b) internal pure returns (uint256) { return a < b ? a : b; } /** * @dev Returns the average of two numbers. The result is rounded towards * zero. */ function average(uint256 a, uint256 b) internal pure returns (uint256) { // (a + b) / 2 can overflow. return (a & b) + (a ^ b) / 2; } /** * @dev Returns the ceiling of the division of two numbers. * * This differs from standard division with `/` in that it rounds up instead * of rounding down. */ function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) { // (a + b - 1) / b can overflow on addition, so we distribute. return a == 0 ? 0 : (a - 1) / b + 1; } /** * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0 * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) * with further edits by Uniswap Labs also under MIT license. */ function mulDiv( uint256 x, uint256 y, uint256 denominator ) internal pure returns (uint256 result) { unchecked { // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256 // variables such that product = prod1 * 2^256 + prod0. uint256 prod0; // Least significant 256 bits of the product uint256 prod1; // Most significant 256 bits of the product assembly { let mm := mulmod(x, y, not(0)) prod0 := mul(x, y) prod1 := sub(sub(mm, prod0), lt(mm, prod0)) } // Handle non-overflow cases, 256 by 256 division. if (prod1 == 0) { // Solidity will revert if denominator == 0, unlike the div opcode on its own. // The surrounding unchecked block does not change this fact. // See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic. return prod0 / denominator; } // Make sure the result is less than 2^256. Also prevents denominator == 0. require(denominator > prod1, "Math: mulDiv overflow"); /////////////////////////////////////////////// // 512 by 256 division. /////////////////////////////////////////////// // Make division exact by subtracting the remainder from [prod1 prod0]. uint256 remainder; assembly { // Compute remainder using mulmod. remainder := mulmod(x, y, denominator) // Subtract 256 bit number from 512 bit number. prod1 := sub(prod1, gt(remainder, prod0)) prod0 := sub(prod0, remainder) } // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1. // See https://cs.stackexchange.com/q/138556/92363. // Does not overflow because the denominator cannot be zero at this stage in the function. uint256 twos = denominator & (~denominator + 1); assembly { // Divide denominator by twos. denominator := div(denominator, twos) // Divide [prod1 prod0] by twos. prod0 := div(prod0, twos) // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one. twos := add(div(sub(0, twos), twos), 1) } // Shift in bits from prod1 into prod0. prod0 |= prod1 * twos; // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for // four bits. That is, denominator * inv = 1 mod 2^4. uint256 inverse = (3 * denominator) ^ 2; // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works // in modular arithmetic, doubling the correct bits in each step. inverse *= 2 - denominator * inverse; // inverse mod 2^8 inverse *= 2 - denominator * inverse; // inverse mod 2^16 inverse *= 2 - denominator * inverse; // inverse mod 2^32 inverse *= 2 - denominator * inverse; // inverse mod 2^64 inverse *= 2 - denominator * inverse; // inverse mod 2^128 inverse *= 2 - denominator * inverse; // inverse mod 2^256 // Because the division is now exact we can divide by multiplying with the modular inverse of denominator. // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1 // is no longer required. result = prod0 * inverse; return result; } } /** * @notice Calculates x * y / denominator with full precision, following the selected rounding direction. */ function mulDiv( uint256 x, uint256 y, uint256 denominator, Rounding rounding ) internal pure returns (uint256) { uint256 result = mulDiv(x, y, denominator); if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) { result += 1; } return result; } /** * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down. * * Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11). */ function sqrt(uint256 a) internal pure returns (uint256) { if (a == 0) { return 0; } // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target. // // We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`. // // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)` // → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))` // → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)` // // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit. uint256 result = 1 << (log2(a) >> 1); // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128, // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision // into the expected uint128 result. unchecked { result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; return min(result, a / result); } } /** * @notice Calculates sqrt(a), following the selected rounding direction. */ function sqrt( uint256 a, Rounding rounding ) internal pure returns (uint256) { unchecked { uint256 result = sqrt(a); return result + (rounding == Rounding.Up && result * result < a ? 1 : 0); } } /** * @dev Return the log in base 2, rounded down, of a positive value. * Returns 0 if given 0. */ function log2(uint256 value) internal pure returns (uint256) { uint256 result = 0; unchecked { if (value >> 128 > 0) { value >>= 128; result += 128; } if (value >> 64 > 0) { value >>= 64; result += 64; } if (value >> 32 > 0) { value >>= 32; result += 32; } if (value >> 16 > 0) { value >>= 16; result += 16; } if (value >> 8 > 0) { value >>= 8; result += 8; } if (value >> 4 > 0) { value >>= 4; result += 4; } if (value >> 2 > 0) { value >>= 2; result += 2; } if (value >> 1 > 0) { result += 1; } } return result; } /** * @dev Return the log in base 2, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log2( uint256 value, Rounding rounding ) internal pure returns (uint256) { unchecked { uint256 result = log2(value); return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0); } } /** * @dev Return the log in base 10, rounded down, of a positive value. * Returns 0 if given 0. */ function log10(uint256 value) internal pure returns (uint256) { uint256 result = 0; unchecked { if (value >= 10 ** 64) { value /= 10 ** 64; result += 64; } if (value >= 10 ** 32) { value /= 10 ** 32; result += 32; } if (value >= 10 ** 16) { value /= 10 ** 16; result += 16; } if (value >= 10 ** 8) { value /= 10 ** 8; result += 8; } if (value >= 10 ** 4) { value /= 10 ** 4; result += 4; } if (value >= 10 ** 2) { value /= 10 ** 2; result += 2; } if (value >= 10 ** 1) { result += 1; } } return result; } /** * @dev Return the log in base 10, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log10( uint256 value, Rounding rounding ) internal pure returns (uint256) { unchecked { uint256 result = log10(value); return result + (rounding == Rounding.Up && 10 ** result < value ? 1 : 0); } } /** * @dev Return the log in base 256, rounded down, of a positive value. * Returns 0 if given 0. * * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string. */ function log256(uint256 value) internal pure returns (uint256) { uint256 result = 0; unchecked { if (value >> 128 > 0) { value >>= 128; result += 16; } if (value >> 64 > 0) { value >>= 64; result += 8; } if (value >> 32 > 0) { value >>= 32; result += 4; } if (value >> 16 > 0) { value >>= 16; result += 2; } if (value >> 8 > 0) { result += 1; } } return result; } /** * @dev Return the log in base 256, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log256( uint256 value, Rounding rounding ) internal pure returns (uint256) { unchecked { uint256 result = log256(value); return result + (rounding == Rounding.Up && 1 << (result << 3) < value ? 1 : 0); } } } // File @openzeppelin/contracts/utils/math/[email protected] // Original license: SPDX_License_Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SignedMath.sol) pragma solidity ^0.8.0; /** * @dev Standard signed math utilities missing in the Solidity language. */ library SignedMath { /** * @dev Returns the largest of two signed numbers. */ function max(int256 a, int256 b) internal pure returns (int256) { return a > b ? a : b; } /** * @dev Returns the smallest of two signed numbers. */ function min(int256 a, int256 b) internal pure returns (int256) { return a < b ? a : b; } /** * @dev Returns the average of two signed numbers without overflow. * The result is rounded towards zero. */ function average(int256 a, int256 b) internal pure returns (int256) { // Formula from the book "Hacker's Delight" int256 x = (a & b) + ((a ^ b) >> 1); return x + (int256(uint256(x) >> 255) & (a ^ b)); } /** * @dev Returns the absolute unsigned value of a signed value. */ function abs(int256 n) internal pure returns (uint256) { unchecked { // must be unchecked in order to support `n = type(int256).min` return uint256(n >= 0 ? n : -n); } } } // File @openzeppelin/contracts/utils/[email protected] // Original license: SPDX_License_Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (utils/Strings.sol) pragma solidity ^0.8.0; /** * @dev String operations. */ library Strings { bytes16 private constant _SYMBOLS = "0123456789abcdef"; uint8 private constant _ADDRESS_LENGTH = 20; /** * @dev Converts a `uint256` to its ASCII `string` decimal representation. */ function toString(uint256 value) internal pure returns (string memory) { unchecked { uint256 length = Math.log10(value) + 1; string memory buffer = new string(length); uint256 ptr; /// @solidity memory-safe-assembly assembly { ptr := add(buffer, add(32, length)) } while (true) { ptr--; /// @solidity memory-safe-assembly assembly { mstore8(ptr, byte(mod(value, 10), _SYMBOLS)) } value /= 10; if (value == 0) break; } return buffer; } } /** * @dev Converts a `int256` to its ASCII `string` decimal representation. */ function toString(int256 value) internal pure returns (string memory) { return string( abi.encodePacked( value < 0 ? "-" : "", toString(SignedMath.abs(value)) ) ); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. */ function toHexString(uint256 value) internal pure returns (string memory) { unchecked { return toHexString(value, Math.log256(value) + 1); } } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. */ function toHexString( uint256 value, uint256 length ) internal pure returns (string memory) { bytes memory buffer = new bytes(2 * length + 2); buffer[0] = "0"; buffer[1] = "x"; for (uint256 i = 2 * length + 1; i > 1; --i) { buffer[i] = _SYMBOLS[value & 0xf]; value >>= 4; } require(value == 0, "Strings: hex length insufficient"); return string(buffer); } /** * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation. */ function toHexString(address addr) internal pure returns (string memory) { return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH); } /** * @dev Returns true if the two strings are equal. */ function equal( string memory a, string memory b ) internal pure returns (bool) { return keccak256(bytes(a)) == keccak256(bytes(b)); } } // File @openzeppelin/contracts/access/[email protected] // Original license: SPDX_License_Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (access/AccessControl.sol) pragma solidity ^0.8.0; /** * @dev Contract module that allows children to implement role-based access * control mechanisms. This is a lightweight version that doesn't allow enumerating role * members except through off-chain means by accessing the contract event logs. Some * applications may benefit from on-chain enumerability, for those cases see * {AccessControlEnumerable}. * * Roles are referred to by their `bytes32` identifier. These should be exposed * in the external API and be unique. The best way to achieve this is by * using `public constant` hash digests: * * ```solidity * bytes32 public constant MY_ROLE = keccak256("MY_ROLE"); * ``` * * Roles can be used to represent a set of permissions. To restrict access to a * function call, use {hasRole}: * * ```solidity * function foo() public { * require(hasRole(MY_ROLE, msg.sender)); * ... * } * ``` * * Roles can be granted and revoked dynamically via the {grantRole} and * {revokeRole} functions. Each role has an associated admin role, and only * accounts that have a role's admin role can call {grantRole} and {revokeRole}. * * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means * that only accounts with this role will be able to grant or revoke other * roles. More complex role relationships can be created by using * {_setRoleAdmin}. * * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to * grant and revoke this role. Extra precautions should be taken to secure * accounts that have been granted it. We recommend using {AccessControlDefaultAdminRules} * to enforce additional security measures for this role. */ abstract contract AccessControl is Context, IAccessControl, ERC165 { struct RoleData { mapping(address => bool) members; bytes32 adminRole; } mapping(bytes32 => RoleData) private _roles; bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00; /** * @dev Modifier that checks that an account has a specific role. Reverts * with a standardized message including the required role. * * The format of the revert reason is given by the following regular expression: * * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/ * * _Available since v4.1._ */ modifier onlyRole(bytes32 role) { _checkRole(role); _; } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface( bytes4 interfaceId ) public view virtual override returns (bool) { return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId); } /** * @dev Returns `true` if `account` has been granted `role`. */ function hasRole( bytes32 role, address account ) public view virtual override returns (bool) { return _roles[role].members[account]; } /** * @dev Revert with a standard message if `_msgSender()` is missing `role`. * Overriding this function changes the behavior of the {onlyRole} modifier. * * Format of the revert message is described in {_checkRole}. * * _Available since v4.6._ */ function _checkRole(bytes32 role) internal view virtual { _checkRole(role, _msgSender()); } /** * @dev Revert with a standard message if `account` is missing `role`. * * The format of the revert reason is given by the following regular expression: * * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/ */ function _checkRole(bytes32 role, address account) internal view virtual { if (!hasRole(role, account)) { revert( string( abi.encodePacked( "AccessControl: account ", Strings.toHexString(account), " is missing role ", Strings.toHexString(uint256(role), 32) ) ) ); } } /** * @dev Returns the admin role that controls `role`. See {grantRole} and * {revokeRole}. * * To change a role's admin, use {_setRoleAdmin}. */ function getRoleAdmin( bytes32 role ) public view virtual override returns (bytes32) { return _roles[role].adminRole; } /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. * * Requirements: * * - the caller must have ``role``'s admin role. * * May emit a {RoleGranted} event. */ function grantRole( bytes32 role, address account ) public virtual override onlyRole(getRoleAdmin(role)) { _grantRole(role, account); } /** * @dev Revokes `role` from `account`. * * If `account` had been granted `role`, emits a {RoleRevoked} event. * * Requirements: * * - the caller must have ``role``'s admin role. * * May emit a {RoleRevoked} event. */ function revokeRole( bytes32 role, address account ) public virtual override onlyRole(getRoleAdmin(role)) { _revokeRole(role, account); } /** * @dev Revokes `role` from the calling account. * * Roles are often managed via {grantRole} and {revokeRole}: this function's * purpose is to provide a mechanism for accounts to lose their privileges * if they are compromised (such as when a trusted device is misplaced). * * If the calling account had been revoked `role`, emits a {RoleRevoked} * event. * * Requirements: * * - the caller must be `account`. * * May emit a {RoleRevoked} event. */ function renounceRole( bytes32 role, address account ) public virtual override { require( account == _msgSender(), "AccessControl: can only renounce roles for self" ); _revokeRole(role, account); } /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. Note that unlike {grantRole}, this function doesn't perform any * checks on the calling account. * * May emit a {RoleGranted} event. * * [WARNING] * ==== * This function should only be called from the constructor when setting * up the initial roles for the system. * * Using this function in any other way is effectively circumventing the admin * system imposed by {AccessControl}. * ==== * * NOTE: This function is deprecated in favor of {_grantRole}. */ function _setupRole(bytes32 role, address account) internal virtual { _grantRole(role, account); } /** * @dev Sets `adminRole` as ``role``'s admin role. * * Emits a {RoleAdminChanged} event. */ function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual { bytes32 previousAdminRole = getRoleAdmin(role); _roles[role].adminRole = adminRole; emit RoleAdminChanged(role, previousAdminRole, adminRole); } /** * @dev Grants `role` to `account`. * * Internal function without access restriction. * * May emit a {RoleGranted} event. */ function _grantRole(bytes32 role, address account) internal virtual { if (!hasRole(role, account)) { _roles[role].members[account] = true; emit RoleGranted(role, account, _msgSender()); } } /** * @dev Revokes `role` from `account`. * * Internal function without access restriction. * * May emit a {RoleRevoked} event. */ function _revokeRole(bytes32 role, address account) internal virtual { if (hasRole(role, account)) { _roles[role].members[account] = false; emit RoleRevoked(role, account, _msgSender()); } } } // File @openzeppelin/contracts/token/ERC20/extensions/[email protected] // Original license: SPDX_License_Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/extensions/IERC20Permit.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612]. * * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't * need to send a transaction, and thus is not required to hold Ether at all. */ interface IERC20Permit { /** * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens, * given ``owner``'s signed approval. * * IMPORTANT: The same issues {IERC20-approve} has related to transaction * ordering also apply here. * * Emits an {Approval} event. * * Requirements: * * - `spender` cannot be the zero address. * - `deadline` must be a timestamp in the future. * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner` * over the EIP712-formatted function arguments. * - the signature must use ``owner``'s current nonce (see {nonces}). * * For more information on the signature format, see the * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP * section]. */ function permit( address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) external; /** * @dev Returns the current nonce for `owner`. This value must be * included whenever a signature is generated for {permit}. * * Every successful call to {permit} increases ``owner``'s nonce by one. This * prevents a signature from being used multiple times. */ function nonces(address owner) external view returns (uint256); /** * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}. */ // solhint-disable-next-line func-name-mixedcase function DOMAIN_SEPARATOR() external view returns (bytes32); } // File @openzeppelin/contracts/token/ERC20/[email protected] // Original license: SPDX_License_Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed 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. */ event Approval( address indexed owner, address indexed spender, uint256 value ); /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (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. */ function transfer(address to, uint256 amount) external returns (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. */ function allowance( address owner, address spender ) external view returns (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. */ function approve(address spender, uint256 amount) external returns (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. */ function transferFrom( address from, address to, uint256 amount ) external returns (bool); } // File @openzeppelin/contracts/utils/[email protected] // Original license: SPDX_License_Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol) pragma solidity ^0.8.1; /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * * Furthermore, `isContract` will also return true if the target contract within * the same transaction is already scheduled for destruction by `SELFDESTRUCT`, * which only has an effect at the end of a transaction. * ==== * * [IMPORTANT] * ==== * You shouldn't rely on `isContract` to protect against flash loan attacks! * * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract * constructor. * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize/address.code.length, which returns 0 // for contracts in construction, since the code is only stored at the end // of the constructor execution. return account.code.length > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require( address(this).balance >= amount, "Address: insufficient balance" ); (bool success, ) = recipient.call{value: amount}(""); require( success, "Address: unable to send value, recipient may have reverted" ); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data ) internal returns (bytes memory) { return functionCallWithValue( target, data, 0, "Address: low-level call failed" ); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value ) internal returns (bytes memory) { return functionCallWithValue( target, data, value, "Address: low-level call with value failed" ); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require( address(this).balance >= value, "Address: insufficient balance for call" ); (bool success, bytes memory returndata) = target.call{value: value}( data ); return verifyCallResultFromTarget( target, success, returndata, errorMessage ); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data ) internal view returns (bytes memory) { return functionStaticCall( target, data, "Address: low-level static call failed" ); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResultFromTarget( target, success, returndata, errorMessage ); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall( address target, bytes memory data ) internal returns (bytes memory) { return functionDelegateCall( target, data, "Address: low-level delegate call failed" ); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResultFromTarget( target, success, returndata, errorMessage ); } /** * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract. * * _Available since v4.8._ */ function verifyCallResultFromTarget( address target, bool success, bytes memory returndata, string memory errorMessage ) internal view returns (bytes memory) { if (success) { if (returndata.length == 0) { // only check isContract if the call was successful and the return data is empty // otherwise we already know that it was a contract require(isContract(target), "Address: call to non-contract"); } return returndata; } else { _revert(returndata, errorMessage); } } /** * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason or using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { _revert(returndata, errorMessage); } } function _revert( bytes memory returndata, string memory errorMessage ) private pure { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly /// @solidity memory-safe-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } // File @openzeppelin/contracts/token/ERC20/utils/[email protected] // Original license: SPDX_License_Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.3) (token/ERC20/utils/SafeERC20.sol) pragma solidity ^0.8.0; /** * @title SafeERC20 * @dev Wrappers around ERC20 operations that throw on failure (when the token * contract returns false). Tokens that return no value (and instead revert or * throw on failure) are also supported, non-reverting calls are assumed to be * successful. * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract, * which allows you to call the safe operations as `token.safeTransfer(...)`, etc. */ library SafeERC20 { using Address for address; /** * @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value, * non-reverting calls are assumed to be successful. */ function safeTransfer(IERC20 token, address to, uint256 value) internal { _callOptionalReturn( token, abi.encodeWithSelector(token.transfer.selector, to, value) ); } /** * @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the * calling contract. If `token` returns no value, non-reverting calls are assumed to be successful. */ function safeTransferFrom( IERC20 token, address from, address to, uint256 value ) internal { _callOptionalReturn( token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value) ); } /** * @dev Deprecated. This function has issues similar to the ones found in * {IERC20-approve}, and its usage is discouraged. * * Whenever possible, use {safeIncreaseAllowance} and * {safeDecreaseAllowance} instead. */ function safeApprove( IERC20 token, address spender, uint256 value ) internal { // safeApprove should only be called when setting an initial allowance, // or when resetting it to zero. To increase and decrease it, use // 'safeIncreaseAllowance' and 'safeDecreaseAllowance' require( (value == 0) || (token.allowance(address(this), spender) == 0), "SafeERC20: approve from non-zero to non-zero allowance" ); _callOptionalReturn( token, abi.encodeWithSelector(token.approve.selector, spender, value) ); } /** * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value, * non-reverting calls are assumed to be successful. */ function safeIncreaseAllowance( IERC20 token, address spender, uint256 value ) internal { uint256 oldAllowance = token.allowance(address(this), spender); _callOptionalReturn( token, abi.encodeWithSelector( token.approve.selector, spender, oldAllowance + value ) ); } /** * @dev Decrease the calling contract's allowance toward `spender` by `value`. If `token` returns no value, * non-reverting calls are assumed to be successful. */ function safeDecreaseAllowance( IERC20 token, address spender, uint256 value ) internal { unchecked { uint256 oldAllowance = token.allowance(address(this), spender); require( oldAllowance >= value, "SafeERC20: decreased allowance below zero" ); _callOptionalReturn( token, abi.encodeWithSelector( token.approve.selector, spender, oldAllowance - value ) ); } } /** * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value, * non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval * to be set to zero before setting it to a non-zero value, such as USDT. */ function forceApprove( IERC20 token, address spender, uint256 value ) internal { bytes memory approvalCall = abi.encodeWithSelector( token.approve.selector, spender, value ); if (!_callOptionalReturnBool(token, approvalCall)) { _callOptionalReturn( token, abi.encodeWithSelector(token.approve.selector, spender, 0) ); _callOptionalReturn(token, approvalCall); } } /** * @dev Use a ERC-2612 signature to set the `owner` approval toward `spender` on `token`. * Revert on invalid signature. */ function safePermit( IERC20Permit token, address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) internal { uint256 nonceBefore = token.nonces(owner); token.permit(owner, spender, value, deadline, v, r, s); uint256 nonceAfter = token.nonces(owner); require( nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed" ); } /** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). */ function _callOptionalReturn(IERC20 token, bytes memory data) private { // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since // we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that // the target address contains contract code and also asserts for success in the low-level call. bytes memory returndata = address(token).functionCall( data, "SafeERC20: low-level call failed" ); require( returndata.length == 0 || abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed" ); } /** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). * * This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead. */ function _callOptionalReturnBool( IERC20 token, bytes memory data ) private returns (bool) { // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since // we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false // and not revert is the subcall reverts. (bool success, bytes memory returndata) = address(token).call(data); return success && (returndata.length == 0 || abi.decode(returndata, (bool))) && Address.isContract(address(token)); } } // File @openzeppelin/contracts/utils/math/[email protected] // Original license: SPDX_License_Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (utils/math/SafeMath.sol) pragma solidity ^0.8.0; // CAUTION // This version of SafeMath should only be used with Solidity 0.8 or later, // because it relies on the compiler's built in overflow checks. /** * @dev Wrappers over Solidity's arithmetic operations. * * NOTE: `SafeMath` is generally not needed starting with Solidity 0.8, since the compiler * now has built in overflow checking. */ library SafeMath { /** * @dev Returns the addition of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryAdd( uint256 a, uint256 b ) internal pure returns (bool, uint256) { unchecked { uint256 c = a + b; if (c < a) return (false, 0); return (true, c); } } /** * @dev Returns the subtraction of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function trySub( uint256 a, uint256 b ) internal pure returns (bool, uint256) { unchecked { if (b > a) return (false, 0); return (true, a - b); } } /** * @dev Returns the multiplication of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryMul( uint256 a, uint256 b ) internal pure returns (bool, uint256) { unchecked { // 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-contracts/pull/522 if (a == 0) return (true, 0); uint256 c = a * b; if (c / a != b) return (false, 0); return (true, c); } } /** * @dev Returns the division of two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryDiv( uint256 a, uint256 b ) internal pure returns (bool, uint256) { unchecked { if (b == 0) return (false, 0); return (true, a / b); } } /** * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryMod( uint256 a, uint256 b ) internal pure returns (bool, uint256) { unchecked { if (b == 0) return (false, 0); return (true, a % b); } } /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { return a + b; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return a - b; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { return a * b; } /** * @dev Returns the integer division of two unsigned integers, reverting on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return a / b; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return a % b; } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {trySub}. * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { unchecked { require(b <= a, errorMessage); return a - b; } } /** * @dev Returns the integer division of two unsigned integers, reverting with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { unchecked { require(b > 0, errorMessage); return a / b; } } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting with custom message when dividing by zero. * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {tryMod}. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { unchecked { require(b > 0, errorMessage); return a % b; } } } // File contracts/interfaces/dex/IUniswapRouter.sol // Original license: SPDX_License_Identifier: MIT pragma solidity ^0.8.8; /// @title Uniswap Router interface /// @author Masa Finance /// @notice Interface of the Uniswap Router contract /// @dev This interface is used to interact with the Uniswap Router contract, /// and gets the most important functions of the contract. It's based on /// https://github.com/Uniswap/v2-periphery/blob/master/contracts/interfaces/IUniswapV2Router01.sol interface IUniswapRouter { function swapExactTokensForTokens( uint256 amountIn, uint256 amountOutMin, address[] calldata path, address to, uint256 deadline ) external returns (uint256[] memory amounts); function swapExactETHForTokens( uint256 amountOutMin, address[] calldata path, address to, uint256 deadline ) external payable returns (uint256[] memory amounts); function swapExactTokensForETH( uint256 amountIn, uint256 amountOutMin, address[] calldata path, address to, uint256 deadline ) external returns (uint256[] memory amounts); function getAmountsOut( uint256 amountIn, address[] calldata path ) external view returns (uint256[] memory amounts); function getAmountsIn( uint256 amountOut, address[] calldata path ) external view returns (uint256[] memory amounts); } // File contracts/libraries/Errors.sol // Original license: SPDX_License_Identifier: MIT pragma solidity ^0.8.8; error AddressDoesNotHaveIdentity(address to); error AlreadyAdded(); error AuthorityNotExists(address authority); error CallerNotOwner(address caller); error CallerNotReader(address caller); error CreditScoreAlreadyCreated(address to); error IdentityAlreadyCreated(address to); error IdentityOwnerIsReader(uint256 readerIdentityId); error InsufficientEthAmount(uint256 amount); error IdentityOwnerNotTokenOwner(uint256 tokenId, uint256 ownerIdentityId); error InvalidPaymentMethod(address paymentMethod); error InvalidSignature(); error InvalidSignatureDate(uint256 signatureDate); error InvalidToken(address token); error InvalidTokenURI(string tokenURI); error LinkAlreadyExists( address token, uint256 tokenId, uint256 readerIdentityId, uint256 signatureDate ); error LinkAlreadyRevoked(); error LinkDoesNotExist(); error NameAlreadyExists(string name); error NameNotFound(string name); error NameRegisteredByOtherAccount(string name, uint256 tokenId); error NotAuthorized(address signer); error NonExistingErc20Token(address erc20token); error NotLinkedToAnIdentitySBT(); error PaymentParamsNotSet(); error ProtocolFeeReceiverNotSet(); error RefundFailed(); error SameValue(); error SBTAlreadyLinked(address token); error SoulNameContractNotSet(); error SoulNameNotExist(); error SoulNameNotRegistered(address token); error TokenNotFound(uint256 tokenId); error TransferFailed(); error URIAlreadyExists(string tokenURI); error UserMustHaveProtocolOrProjectAdminRole(); error ValidPeriodExpired(uint256 expirationDate); error ZeroAddress(); error ZeroLengthName(string name); error ZeroYearsPeriod(uint256 yearsPeriod); // File contracts/dex/PaymentGateway.sol // Original license: SPDX_License_Identifier: MIT pragma solidity ^0.8.8; /// @title Pay using a Decentralized automated market maker (AMM) when needed /// @author Masa Finance /// @notice Smart contract to call a Dex AMM smart contract to pay to a project fee receiver /// wallet recipient /// @dev This smart contract will call the Uniswap Router interface, based on /// https://github.com/Uniswap/v2-periphery/blob/master/contracts/interfaces/IUniswapV2Router01.sol abstract contract PaymentGateway is AccessControl { using SafeERC20 for IERC20; using SafeMath for uint256; bytes32 public constant PROJECT_ADMIN_ROLE = keccak256("PROJECT_ADMIN_ROLE"); struct PaymentParams { address swapRouter; // Swap router address address wrappedNativeToken; // Wrapped native token address address stableCoin; // Stable coin to pay the fee in (USDC) address masaToken; // Utility token to pay the fee in (MASA) address projectFeeReceiver; // Wallet that will receive the project fee address protocolFeeReceiver; // Wallet that will receive the protocol fee uint256 protocolFeeAmount; // Protocol fee amount in USD uint256 protocolFeePercent; // Protocol fee amount added to the project fee uint256 protocolFeePercentSub; // Protocol fee amount substracted from the project fee } /* ========== STATE VARIABLES =========================================== */ address public swapRouter; address public wrappedNativeToken; address public stableCoin; // USDC. It also needs to be enabled as payment method, if we want to pay in USDC address public masaToken; // MASA. It also needs to be enabled as payment method, if we want to pay in MASA // enabled payment methods: ETH and ERC20 tokens mapping(address => bool) public enabledPaymentMethod; address[] public enabledPaymentMethods; address public projectFeeReceiver; address public protocolFeeReceiver; uint256 public protocolFeeAmount; uint256 public protocolFeePercent; // Protocol fee amount added to the project fee uint256 public protocolFeePercentSub; // Protocol fee amount substracted from the project fee /* ========== INITIALIZE ================================================ */ /// @notice Creates a new Dex AMM /// @dev Creates a new Decentralized automated market maker (AMM) smart contract, // that will call the Uniswap Router interface /// @param admin Administrator of the smart contract /// @param paymentParams Payment params constructor(address admin, PaymentParams memory paymentParams) { _grantRole(DEFAULT_ADMIN_ROLE, admin); swapRouter = paymentParams.swapRouter; wrappedNativeToken = paymentParams.wrappedNativeToken; stableCoin = paymentParams.stableCoin; masaToken = paymentParams.masaToken; projectFeeReceiver = paymentParams.projectFeeReceiver; protocolFeeReceiver = paymentParams.protocolFeeReceiver; protocolFeeAmount = paymentParams.protocolFeeAmount; protocolFeePercent = paymentParams.protocolFeePercent; protocolFeePercentSub = paymentParams.protocolFeePercentSub; } /* ========== RESTRICTED FUNCTIONS ====================================== */ /// @notice Sets the swap router address /// @dev The caller must have the admin role to call this function /// @param _swapRouter New swap router address function setSwapRouter( address _swapRouter ) external onlyRole(DEFAULT_ADMIN_ROLE) { if (swapRouter == _swapRouter) revert SameValue(); swapRouter = _swapRouter; } /// @notice Sets the wrapped native token address /// @dev The caller must have the admin role to call this function /// @param _wrappedNativeToken New wrapped native token address function setWrappedNativeToken( address _wrappedNativeToken ) external onlyRole(DEFAULT_ADMIN_ROLE) { if (wrappedNativeToken == _wrappedNativeToken) revert SameValue(); wrappedNativeToken = _wrappedNativeToken; } /// @notice Sets the stable coin to pay the fee in (USDC) /// @dev The caller must have the admin role to call this function /// @param _stableCoin New stable coin to pay the fee in function setStableCoin( address _stableCoin ) external onlyRole(DEFAULT_ADMIN_ROLE) { if (stableCoin == _stableCoin) revert SameValue(); stableCoin = _stableCoin; } /// @notice Sets the utility token to pay the fee in (MASA) /// @dev The caller must have the admin role to call this function /// It can be set to address(0) to disable paying in MASA /// @param _masaToken New utility token to pay the fee in function setMasaToken( address _masaToken ) external onlyRole(DEFAULT_ADMIN_ROLE) { if (masaToken == _masaToken) revert SameValue(); masaToken = _masaToken; } /// @notice Adds a new token as a valid payment method /// @dev The caller must have the admin role to call this function /// @param _paymentMethod New token to add function enablePaymentMethod( address _paymentMethod ) external onlyRole(DEFAULT_ADMIN_ROLE) { if (enabledPaymentMethod[_paymentMethod]) revert AlreadyAdded(); enabledPaymentMethod[_paymentMethod] = true; enabledPaymentMethods.push(_paymentMethod); } /// @notice Removes a token as a valid payment method /// @dev The caller must have the admin role to call this function /// @param _paymentMethod Token to remove function disablePaymentMethod( address _paymentMethod ) external onlyRole(DEFAULT_ADMIN_ROLE) { if (!enabledPaymentMethod[_paymentMethod]) revert NonExistingErc20Token(_paymentMethod); enabledPaymentMethod[_paymentMethod] = false; for (uint256 i = 0; i < enabledPaymentMethods.length; i++) { if (enabledPaymentMethods[i] == _paymentMethod) { enabledPaymentMethods[i] = enabledPaymentMethods[ enabledPaymentMethods.length - 1 ]; enabledPaymentMethods.pop(); break; } } } /// @notice Set the project fee receiver wallet /// @dev The caller must have the admin or project admin role to call this function /// @param _projectFeeReceiver New project fee receiver wallet function setProjectFeeReceiver(address _projectFeeReceiver) external { if ( !hasRole(DEFAULT_ADMIN_ROLE, _msgSender()) && !hasRole(PROJECT_ADMIN_ROLE, _msgSender()) ) revert UserMustHaveProtocolOrProjectAdminRole(); if (_projectFeeReceiver == projectFeeReceiver) revert SameValue(); projectFeeReceiver = _projectFeeReceiver; } /// @notice Set the protocol fee wallet /// @dev The caller must have the admin role to call this function /// @param _protocolFeeReceiver New protocol fee wallet function setProtocolFeeReceiver( address _protocolFeeReceiver ) external onlyRole(DEFAULT_ADMIN_ROLE) { if (_protocolFeeReceiver == protocolFeeReceiver) revert SameValue(); protocolFeeReceiver = _protocolFeeReceiver; } /// @notice Set the protocol fee amount /// @dev The caller must have the admin role to call this function /// @param _protocolFeeAmount New protocol fee amount function setProtocolFeeAmount( uint256 _protocolFeeAmount ) external onlyRole(DEFAULT_ADMIN_ROLE) { if (_protocolFeeAmount == protocolFeeAmount) revert SameValue(); protocolFeeAmount = _protocolFeeAmount; } /// @notice Set the protocol fee percent added to the project fee /// @dev The caller must have the admin role to call this function /// @param _protocolFeePercent New protocol fee percent added to the project fee function setProtocolFeePercent( uint256 _protocolFeePercent ) external onlyRole(DEFAULT_ADMIN_ROLE) { if (_protocolFeePercent == protocolFeePercent) revert SameValue(); protocolFeePercent = _protocolFeePercent; } /// @notice Set the protocol fee percent substracted from the amount /// @dev The caller must have the admin role to call this function /// @param _protocolFeePercentSub New protocol fee percent substracted from the amount function setProtocolFeePercentSub( uint256 _protocolFeePercentSub ) external onlyRole(DEFAULT_ADMIN_ROLE) { if (_protocolFeePercentSub == protocolFeePercentSub) revert SameValue(); protocolFeePercentSub = _protocolFeePercentSub; } /* ========== MUTATIVE FUNCTIONS ======================================== */ /* ========== VIEWS ===================================================== */ /// @notice Returns all available payment methods /// @dev Returns the address of all available payment methods /// @return Array of all enabled payment methods function getEnabledPaymentMethods() external view returns (address[] memory) { return enabledPaymentMethods; } /// @notice Calculates the protocol fee added to the project fee /// @dev This method will calculate the protocol fee based on the payment method /// @param paymentMethod Address of token that user want to pay /// @param amount Price to be paid in the specified payment method function getProtocolFee( address paymentMethod, uint256 amount ) external view returns (uint256) { return _getProtocolFee(paymentMethod, amount); } /// @notice Calculates the protocol fee substracted from the amount /// @dev This method will calculate the protocol fee based on the payment method /// @param amount Price to be paid in the specified payment method function getProtocolFeeSub(uint256 amount) external view returns (uint256) { return _getProtocolFeeSub(amount); } /* ========== PRIVATE FUNCTIONS ========================================= */ /// @notice Converts an amount from a stable coin to a payment method amount /// @dev This method will perform the swap between the stable coin and the /// payment method, and return the amount of the payment method, /// performing the swap if necessary /// @param paymentMethod Address of token that user want to pay /// @param amount Price to be converted in the specified payment method function _convertFromStableCoin( address paymentMethod, uint256 amount ) internal view paymentParamsAlreadySet(amount) returns (uint256) { if (!enabledPaymentMethod[paymentMethod] || paymentMethod == stableCoin) revert InvalidToken(paymentMethod); if (amount == 0) return 0; if (paymentMethod == address(0)) { return _estimateSwapAmount(wrappedNativeToken, stableCoin, amount); } else { return _estimateSwapAmount(paymentMethod, stableCoin, amount); } } /// @notice Calculates the protocol fee added to the project fee /// @dev This method will calculate the protocol fee based on the payment method /// @param paymentMethod Address of token that user want to pay /// @param amount Price to be paid in the specified payment method function _getProtocolFee( address paymentMethod, uint256 amount ) internal view returns (uint256) { uint256 protocolFee = 0; if (protocolFeeAmount > 0) { if (paymentMethod == stableCoin) { protocolFee = protocolFeeAmount; } else { protocolFee = _convertFromStableCoin( paymentMethod, protocolFeeAmount ); } } if (protocolFeePercent > 0) { protocolFee = protocolFee.add( amount.mul(protocolFeePercent).div(100) ); } return protocolFee; } /// @notice Calculates the protocol fee substracted from the amount /// @dev This method will calculate the protocol fee based on the payment method /// @param amount Price to be paid in the specified payment method function _getProtocolFeeSub( uint256 amount ) internal view returns (uint256) { if (protocolFeePercentSub > 0) { return amount.mul(protocolFeePercentSub).div(100); } else { return 0; } } /// @notice Performs the payment in any payment method /// @dev This method will transfer the funds to the project fee receiver wallet, performing /// the swap if necessary, and transfer the protocol fee to the protocol fee wallet /// @param paymentMethod Address of token that user want to pay /// @param amount Price to be paid in the specified payment method /// @param protocolFee Protocol fee to be paid in the specified payment method function _pay( address paymentMethod, uint256 amount, uint256 protocolFee ) internal paymentParamsAlreadySet(amount.add(protocolFee)) { if (amount == 0 && protocolFee == 0) return; uint256 protocolFeeSub = _getProtocolFeeSub(amount); if ( (protocolFee > 0 || protocolFeeSub > 0) && protocolFeeReceiver == address(0) ) revert ProtocolFeeReceiverNotSet(); if (!enabledPaymentMethod[paymentMethod]) revert InvalidPaymentMethod(paymentMethod); if (paymentMethod == address(0)) { // ETH if (msg.value < amount.add(protocolFee)) revert InsufficientEthAmount(amount.add(protocolFee)); if (amount.sub(protocolFeeSub) > 0) { (bool success, ) = payable(projectFeeReceiver).call{ value: amount.sub(protocolFeeSub) }(""); if (!success) revert TransferFailed(); } if (protocolFee > 0) { (bool success, ) = payable(protocolFeeReceiver).call{ value: protocolFee }(""); if (!success) revert TransferFailed(); } if (protocolFeeSub > 0) { (bool success, ) = payable(protocolFeeReceiver).call{ value: protocolFeeSub }(""); if (!success) revert TransferFailed(); } if (msg.value > amount.add(protocolFee)) { // return diff uint256 refund = msg.value.sub(amount.add(protocolFee)); (bool success, ) = payable(msg.sender).call{value: refund}(""); if (!success) revert RefundFailed(); } } else { // ERC20 token, including MASA and USDC if (amount.sub(protocolFeeSub) > 0) { IERC20(paymentMethod).safeTransferFrom( msg.sender, projectFeeReceiver, amount.sub(protocolFeeSub) ); } if (protocolFee > 0) { IERC20(paymentMethod).safeTransferFrom( msg.sender, protocolFeeReceiver, protocolFee ); } if (protocolFeeSub > 0) { IERC20(paymentMethod).safeTransferFrom( msg.sender, protocolFeeReceiver, protocolFeeSub ); } } } function _estimateSwapAmount( address _fromToken, address _toToken, uint256 _amountOut ) private view returns (uint256) { uint256[] memory amounts; address[] memory path; path = _getPathFromTokenToToken(_fromToken, _toToken); amounts = IUniswapRouter(swapRouter).getAmountsIn(_amountOut, path); return amounts[0]; } function _getPathFromTokenToToken( address fromToken, address toToken ) private view returns (address[] memory) { if (fromToken == wrappedNativeToken || toToken == wrappedNativeToken) { address[] memory path = new address[](2); path[0] = fromToken == wrappedNativeToken ? wrappedNativeToken : fromToken; path[1] = toToken == wrappedNativeToken ? wrappedNativeToken : toToken; return path; } else { address[] memory path = new address[](3); path[0] = fromToken; path[1] = wrappedNativeToken; path[2] = toToken; return path; } } /* ========== MODIFIERS ================================================= */ modifier paymentParamsAlreadySet(uint256 amount) { if (amount > 0 && swapRouter == address(0)) revert PaymentParamsNotSet(); if (amount > 0 && wrappedNativeToken == address(0)) revert PaymentParamsNotSet(); if (amount > 0 && stableCoin == address(0)) revert PaymentParamsNotSet(); if (amount > 0 && projectFeeReceiver == address(0)) revert PaymentParamsNotSet(); _; } /* ========== EVENTS ==================================================== */ } // File contracts/tokens/SBT/ISBT.sol // Original license: SPDX_License_Identifier: MIT pragma solidity ^0.8.8; interface ISBT is IERC165 { /// @dev This emits when an SBT is newly minted. /// This event emits when SBTs are created event Mint(address indexed _owner, uint256 indexed _tokenId); /// @dev This emits when an SBT is burned /// This event emits when SBTs are destroyed event Burn(address indexed _owner, uint256 indexed _tokenId); /// @notice Count all SBTs assigned to an owner /// @dev SBTs assigned to the zero address are considered invalid, and this /// function throws for queries about the zero address. /// @param _owner An address for whom to query the balance /// @return The number of SBTs owned by `_owner`, possibly zero function balanceOf(address _owner) external view returns (uint256); /// @notice Find the owner of an SBT /// @dev SBTs assigned to zero address are considered invalid, and queries /// about them do throw. /// @param _tokenId The identifier for an SBT /// @return The address of the owner of the SBT function ownerOf(uint256 _tokenId) external view returns (address); } // File contracts/interfaces/ILinkableSBT.sol // Original license: SPDX_License_Identifier: MIT pragma solidity ^0.8.8; interface ILinkableSBT is ISBT { function addLinkPrice() external view returns (uint256); function addLinkPriceMASA() external view returns (uint256); function queryLinkPrice() external view returns (uint256); function queryLinkPriceMASA() external view returns (uint256); } // File contracts/interfaces/ISoulName.sol // Original license: SPDX_License_Identifier: MIT pragma solidity ^0.8.8; interface ISoulName { function mint( address to, string memory name, uint256 yearsPeriod, string memory _tokenURI ) external returns (uint256); function getExtension() external view returns (string memory); function isAvailable( string memory name ) external view returns (bool available); function tokenData( uint256 tokenId ) external view returns (string memory name, uint256 expirationDate); function getTokenData( string memory name ) external view returns ( string memory sbtName, bool linked, uint256 identityId, uint256 tokenId, uint256 expirationDate, bool active ); function getTokenId(string memory name) external view returns (uint256); function getSoulNames( address owner ) external view returns (string[] memory sbtNames); function getSoulNames( uint256 identityId ) external view returns (string[] memory sbtNames); } // File contracts/interfaces/ISoulboundIdentity.sol // Original license: SPDX_License_Identifier: MIT pragma solidity ^0.8.8; interface ISoulboundIdentity is ISBT { function mint(address to) external payable returns (uint256); function mint( address paymentMethod, address to ) external payable returns (uint256); function mintIdentityWithName( address to, string memory name, uint256 yearsPeriod, string memory _tokenURI ) external payable returns (uint256); function mintIdentityWithName( address paymentMethod, address to, string memory name, uint256 yearsPeriod, string memory _tokenURI ) external payable returns (uint256); function getSoulName() external view returns (ISoulName); function tokenOfOwner(address owner) external view returns (uint256); } // File @openzeppelin/contracts/security/[email protected] // Original license: SPDX_License_Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (security/ReentrancyGuard.sol) pragma solidity ^0.8.0; /** * @dev Contract module that helps prevent reentrant calls to a function. * * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier * available, which can be applied to functions to make sure there are no nested * (reentrant) calls to them. * * Note that because there is a single `nonReentrant` guard, functions marked as * `nonReentrant` may not call one another. This can be worked around by making * those functions `private`, and then adding `external` `nonReentrant` entry * points to them. * * TIP: If you would like to learn more about reentrancy and alternative ways * to protect against it, check out our blog post * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul]. */ abstract contract ReentrancyGuard { // Booleans are more expensive than uint256 or any type that takes up a full // word because each write operation emits an extra SLOAD to first read the // slot's contents, replace the bits taken up by the boolean, and then write // back. This is the compiler's defense against contract upgrades and // pointer aliasing, and it cannot be disabled. // The values being non-zero value makes deployment a bit more expensive, // but in exchange the refund on every call to nonReentrant will be lower in // amount. Since refunds are capped to a percentage of the total // transaction's gas, it is best to keep them low in cases like this one, to // increase the likelihood of the full refund coming into effect. uint256 private constant _NOT_ENTERED = 1; uint256 private constant _ENTERED = 2; uint256 private _status; constructor() { _status = _NOT_ENTERED; } /** * @dev Prevents a contract from calling itself, directly or indirectly. * Calling a `nonReentrant` function from another `nonReentrant` * function is not supported. It is possible to prevent this from happening * by making the `nonReentrant` function external, and making it call a * `private` function that does the actual work. */ modifier nonReentrant() { _nonReentrantBefore(); _; _nonReentrantAfter(); } function _nonReentrantBefore() private { // On the first call to nonReentrant, _status will be _NOT_ENTERED require(_status != _ENTERED, "ReentrancyGuard: reentrant call"); // Any calls to nonReentrant after this point will fail _status = _ENTERED; } function _nonReentrantAfter() private { // By storing the original value once again, a refund is triggered (see // https://eips.ethereum.org/EIPS/eip-2200) _status = _NOT_ENTERED; } /** * @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a * `nonReentrant` function in the call stack. */ function _reentrancyGuardEntered() internal view returns (bool) { return _status == _ENTERED; } } // File @openzeppelin/contracts/utils/[email protected] // Original license: SPDX_License_Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Counters.sol) pragma solidity ^0.8.0; /** * @title Counters * @author Matt Condon (@shrugs) * @dev Provides counters that can only be incremented, decremented or reset. This can be used e.g. to track the number * of elements in a mapping, issuing ERC721 ids, or counting request ids. * * Include with `using Counters for Counters.Counter;` */ library Counters { struct Counter { // This variable should never be directly accessed by users of the library: interactions must be restricted to // the library's function. As of Solidity v0.5.2, this cannot be enforced, though there is a proposal to add // this feature: see https://github.com/ethereum/solidity/issues/4637 uint256 _value; // default: 0 } function current(Counter storage counter) internal view returns (uint256) { return counter._value; } function increment(Counter storage counter) internal { unchecked { counter._value += 1; } } function decrement(Counter storage counter) internal { uint256 value = counter._value; require(value > 0, "Counter: decrement overflow"); unchecked { counter._value = value - 1; } } function reset(Counter storage counter) internal { counter._value = 0; } } // File contracts/tokens/SBT/extensions/ISBTMetadata.sol // Original license: SPDX_License_Identifier: MIT pragma solidity ^0.8.8; /** * @title SBT Soulbound Token Standard, optional metadata extension */ interface ISBTMetadata is ISBT { /** * @dev Returns the token collection name. */ function name() external view returns (string memory); /** * @dev Returns the token collection symbol. */ function symbol() external view returns (string memory); /** * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token. */ function tokenURI(uint256 tokenId) external view returns (string memory); } // File contracts/tokens/SBT/SBT.sol // Original license: SPDX_License_Identifier: MIT pragma solidity ^0.8.8; /// @title SBT /// @author Masa Finance /// @notice Soulbound token is an NFT token that is not transferable. contract SBT is Context, ERC165, ISBT, ISBTMetadata { using Strings for uint256; // Token name string private _name; // Token symbol string private _symbol; // Mapping from token ID to owner address mapping(uint256 => address) private _owners; // Mapping owner address to token count mapping(address => uint256) private _balances; /** * @dev Initializes the contract by setting a `name` and a `symbol` to the token collection. */ constructor(string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface( bytes4 interfaceId ) public view virtual override(ERC165, IERC165) returns (bool) { return interfaceId == type(ISBT).interfaceId || interfaceId == type(ISBTMetadata).interfaceId || super.supportsInterface(interfaceId); } /** * @dev See {ISBT-balanceOf}. */ function balanceOf( address owner ) public view virtual override returns (uint256) { require(owner != address(0), "SBT: address zero is not a valid owner"); return _balances[owner]; } /** * @dev See {ISBT-ownerOf}. */ function ownerOf( uint256 tokenId ) public view virtual override returns (address) { address owner = _owners[tokenId]; require(owner != address(0), "SBT: invalid token ID"); return owner; } /** * @dev See {ISBTMetadata-name}. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev See {ISBTMetadata-symbol}. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev See {ISBTMetadata-tokenURI}. */ function tokenURI( uint256 tokenId ) public view virtual override returns (string memory) { _requireMinted(tokenId); string memory baseURI = _baseURI(); return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : ""; } /** * @dev Base URI for computing {tokenURI}. If set, the resulting URI for each * token will be the concatenation of the `baseURI` and the `tokenId`. Empty * by default, can be overridden in child contracts. */ function _baseURI() internal view virtual returns (string memory) { return ""; } /** * @dev Returns whether `spender` is allowed to manage `tokenId`. * * Requirements: * * - `tokenId` must exist. */ function _isOwner( address spender, uint256 tokenId ) internal view virtual returns (bool) { address owner = SBT.ownerOf(tokenId); return (spender == owner); } /** * @dev Returns whether `tokenId` exists. * * Tokens can be managed by their owner. * * Tokens start existing when they are minted (`_mint`), * and stop existing when they are burned (`_burn`). */ function _exists(uint256 tokenId) internal view virtual returns (bool) { return _owners[tokenId] != address(0); } /** * @dev Mints `tokenId` and transfers it to `to`. * * WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible * * Requirements: * * - `tokenId` must not exist. * - `to` cannot be the zero address. * * Emits a {Mint} event. */ function _mint(address to, uint256 tokenId) internal virtual { require(to != address(0), "SBT: mint to the zero address"); require(!_exists(tokenId), "SBT: token already minted"); _beforeTokenTransfer(address(0), to, tokenId); _balances[to] += 1; _owners[tokenId] = to; emit Mint(to, tokenId); _afterTokenTransfer(address(0), to, tokenId); } /** * @dev Destroys `tokenId`. * * Requirements: * - `tokenId` must exist. * * Emits a {Burn} event. */ function _burn(uint256 tokenId) internal virtual { address owner = SBT.ownerOf(tokenId); _beforeTokenTransfer(owner, address(0), tokenId); _balances[owner] -= 1; delete _owners[tokenId]; emit Burn(owner, tokenId); _afterTokenTransfer(owner, address(0), tokenId); } /** * @dev Reverts if the `tokenId` has not been minted yet. */ function _requireMinted(uint256 tokenId) internal view virtual { require(_exists(tokenId), "SBT: invalid token ID"); } /** * @dev Hook that is called before any token minting/burning * * Calling conditions: * * - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be * transferred to `to`. * - When `from` is zero, `tokenId` will be minted for `to`. * - When `to` is zero, ``from``'s `tokenId` will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer(address, address, uint256) internal virtual {} /** * @dev Hook that is called after any minting/burning of tokens * * Calling conditions: * - when `from` and `to` are both non-zero. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _afterTokenTransfer(address, address, uint256) internal virtual {} } // File contracts/tokens/SBT/extensions/SBTBurnable.sol // Original license: SPDX_License_Identifier: MIT pragma solidity ^0.8.8; /** * @title SBT Burnable Token * @dev SBT Token that can be burned (destroyed). */ abstract contract SBTBurnable is Context, SBT { /** * @dev Burns `tokenId`. See {SBT-_burn}. * * Requirements: * * - The caller must own `tokenId` or be an approved operator. */ function burn(uint256 tokenId) public virtual { //solhint-disable-next-line max-line-length require( _isOwner(_msgSender(), tokenId), "SBT: caller is not token owner" ); _burn(tokenId); } } // File contracts/tokens/SBT/extensions/ISBTEnumerable.sol // Original license: SPDX_License_Identifier: MIT pragma solidity ^0.8.8; /** * @title SBT Soulbound Token Standard, optional enumeration extension */ interface ISBTEnumerable is ISBT { /** * @dev Returns the total amount of tokens stored by the contract. */ function totalSupply() external view returns (uint256); /** * @dev Returns a token ID owned by `owner` at a given `index` of its token list. * Use along with {balanceOf} to enumerate all of ``owner``'s tokens. */ function tokenOfOwnerByIndex( address owner, uint256 index ) external view returns (uint256); /** * @dev Returns a token ID at a given `index` of all the tokens stored by the contract. * Use along with {totalSupply} to enumerate all tokens. */ function tokenByIndex(uint256 index) external view returns (uint256); } // File contracts/tokens/SBT/extensions/SBTEnumerable.sol // Original license: SPDX_License_Identifier: MIT pragma solidity ^0.8.8; /** * @dev This implements an optional extension of {SBT} defined in the EIP that adds * enumerability of all the token ids in the contract as well as all token ids owned by each * account. */ abstract contract SBTEnumerable is SBT, ISBTEnumerable { // Mapping from owner to list of owned token IDs mapping(address => mapping(uint256 => uint256)) private _ownedTokens; // Mapping from token ID to index of the owner tokens list mapping(uint256 => uint256) private _ownedTokensIndex; // Array with all token ids, used for enumeration uint256[] private _allTokens; // Mapping from token id to position in the allTokens array mapping(uint256 => uint256) private _allTokensIndex; /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface( bytes4 interfaceId ) public view virtual override(IERC165, SBT) returns (bool) { return interfaceId == type(ISBTEnumerable).interfaceId || super.supportsInterface(interfaceId); } /** * @dev See {ISBTEnumerable-tokenOfOwnerByIndex}. */ function tokenOfOwnerByIndex( address owner, uint256 index ) public view virtual override returns (uint256) { require( index < SBT.balanceOf(owner), "SBTEnumerable: owner index out of bounds" ); return _ownedTokens[owner][index]; } /** * @dev See {ISBTEnumerable-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _allTokens.length; } /** * @dev See {ISBTEnumerable-tokenByIndex}. */ function tokenByIndex( uint256 index ) public view virtual override returns (uint256) { require( index < SBTEnumerable.totalSupply(), "SBTEnumerable: global index out of bounds" ); return _allTokens[index]; } /** * @dev Hook that is called before any token transfer. This includes minting * and burning. * * Calling conditions: * * - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be * transferred to `to`. * - When `from` is zero, `tokenId` will be minted for `to`. * - When `to` is zero, ``from``'s `tokenId` will be burned. * - `from` cannot be the zero address. * - `to` cannot be the zero address. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer( address from, address to, uint256 tokenId ) internal virtual override { super._beforeTokenTransfer(from, to, tokenId); if (from == address(0)) { _addTokenToAllTokensEnumeration(tokenId); } else if (from != to) { _removeTokenFromOwnerEnumeration(from, tokenId); } if (to == address(0)) { _removeTokenFromAllTokensEnumeration(tokenId); } else if (to != from) { _addTokenToOwnerEnumeration(to, tokenId); } } /** * @dev Private function to add a token to this extension's ownership-tracking data structures. * @param to address representing the new owner of the given token ID * @param tokenId uint256 ID of the token to be added to the tokens list of the given address */ function _addTokenToOwnerEnumeration(address to, uint256 tokenId) private { uint256 length = SBT.balanceOf(to); _ownedTokens[to][length] = tokenId; _ownedTokensIndex[tokenId] = length; } /** * @dev Private function to add a token to this extension's token tracking data structures. * @param tokenId uint256 ID of the token to be added to the tokens list */ function _addTokenToAllTokensEnumeration(uint256 tokenId) private { _allTokensIndex[tokenId] = _allTokens.length; _allTokens.push(tokenId); } /** * @dev Private function to remove a token from this extension's ownership-tracking data structures. Note that * while the token is not assigned a new owner, the `_ownedTokensIndex` mapping is _not_ updated: this allows for * gas optimizations e.g. when performing a transfer operation (avoiding double writes). * This has O(1) time complexity, but alters the order of the _ownedTokens array. * @param from address representing the previous owner of the given token ID * @param tokenId uint256 ID of the token to be removed from the tokens list of the given address */ function _removeTokenFromOwnerEnumeration( address from, uint256 tokenId ) private { // To prevent a gap in from's tokens array, we store the last token in the index of the token to delete, and // then delete the last slot (swap and pop). uint256 lastTokenIndex = SBT.balanceOf(from) - 1; uint256 tokenIndex = _ownedTokensIndex[tokenId]; // When the token to delete is the last token, the swap operation is unnecessary if (tokenIndex != lastTokenIndex) { uint256 lastTokenId = _ownedTokens[from][lastTokenIndex]; _ownedTokens[from][tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token _ownedTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index } // This also deletes the contents at the last position of the array delete _ownedTokensIndex[tokenId]; delete _ownedTokens[from][lastTokenIndex]; } /** * @dev Private function to remove a token from this extension's token tracking data structures. * This has O(1) time complexity, but alters the order of the _allTokens array. * @param tokenId uint256 ID of the token to be removed from the tokens list */ function _removeTokenFromAllTokensEnumeration(uint256 tokenId) private { // To prevent a gap in the tokens array, we store the last token in the index of the token to delete, and // then delete the last slot (swap and pop). uint256 lastTokenIndex = _allTokens.length - 1; uint256 tokenIndex = _allTokensIndex[tokenId]; // When the token to delete is the last token, the swap operation is unnecessary. However, since this occurs so // rarely (when the last minted token is burnt) that we still do the swap here to avoid the gas cost of adding // an 'if' statement (like in _removeTokenFromOwnerEnumeration) uint256 lastTokenId = _allTokens[lastTokenIndex]; _allTokens[tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token _allTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index // This also deletes the contents at the last position of the array delete _allTokensIndex[tokenId]; _allTokens.pop(); } } // File contracts/tokens/MasaSBT.sol // Original license: SPDX_License_Identifier: MIT pragma solidity ^0.8.8; /// @title MasaSBT /// @author Masa Finance /// @notice Soulbound token. Non-fungible token that is not transferable. /// @dev Implementation of https://papers.ssrn.com/sol3/papers.cfm?abstract_id=4105763 Soulbound token. /// Adds a link to a SoulboundIdentity SC to let minting using the identityId /// Adds a payment gateway to let minting paying a fee abstract contract MasaSBT is PaymentGateway, SBT, SBTEnumerable, SBTBurnable, ILinkableSBT { /* ========== STATE VARIABLES =========================================== */ using Strings for uint256; string private _baseTokenURI; ISoulboundIdentity public soulboundIdentity; uint256 public mintPrice; // price in stable coin uint256 public mintPriceMASA; // price in MASA uint256 public override addLinkPrice; // price in stable coin uint256 public override addLinkPriceMASA; // price in MASA uint256 public override queryLinkPrice; // price in stable coin uint256 public override queryLinkPriceMASA; // price in MASA /* ========== INITIALIZE ================================================ */ /// @notice Creates a new soulbound token /// @dev Creates a new soulbound token /// @param admin Administrator of the smart contract /// @param name Name of the token /// @param symbol Symbol of the token /// @param baseTokenURI Base URI of the token /// @param _soulboundIdentity Address of the SoulboundIdentity contract /// @param paymentParams Payment gateway params constructor( address admin, string memory name, string memory symbol, string memory baseTokenURI, address _soulboundIdentity, PaymentParams memory paymentParams ) SBT(name, symbol) PaymentGateway(admin, paymentParams) { _grantRole(DEFAULT_ADMIN_ROLE, admin); _baseTokenURI = baseTokenURI; soulboundIdentity = ISoulboundIdentity(_soulboundIdentity); } /* ========== RESTRICTED FUNCTIONS ====================================== */ /// @notice Sets the price of minting in stable coin /// @dev The caller must have the admin or project admin role to call this function /// @param _mintPrice New price of minting in stable coin function setMintPrice(uint256 _mintPrice) external { if ( !hasRole(DEFAULT_ADMIN_ROLE, _msgSender()) && !hasRole(PROJECT_ADMIN_ROLE, _msgSender()) ) revert UserMustHaveProtocolOrProjectAdminRole(); if (mintPrice == _mintPrice) revert SameValue(); mintPrice = _mintPrice; } /// @notice Sets the price of minting in MASA /// @dev The caller must have the admin or project admin role to call this function /// @param _mintPriceMASA New price of minting in MASA function setMintPriceMASA(uint256 _mintPriceMASA) external { if ( !hasRole(DEFAULT_ADMIN_ROLE, _msgSender()) && !hasRole(PROJECT_ADMIN_ROLE, _msgSender()) ) revert UserMustHaveProtocolOrProjectAdminRole(); if (mintPriceMASA == _mintPriceMASA) revert SameValue(); mintPriceMASA = _mintPriceMASA; } /// @notice Sets the SoulboundIdentity contract address linked to this SBT /// @dev The caller must be the admin to call this function /// @param _soulboundIdentity Address of the SoulboundIdentity contract function setSoulboundIdentity( address _soulboundIdentity ) external onlyRole(DEFAULT_ADMIN_ROLE) { if (address(soulboundIdentity) == _soulboundIdentity) revert SameValue(); soulboundIdentity = ISoulboundIdentity(_soulboundIdentity); } /// @notice Sets the price for adding the link in SoulLinker in stable coin /// @dev The caller must have the admin or project admin role to call this function /// @param _addLinkPrice New price for adding the link in SoulLinker in stable coin function setAddLinkPrice(uint256 _addLinkPrice) external { if ( !hasRole(DEFAULT_ADMIN_ROLE, _msgSender()) && !hasRole(PROJECT_ADMIN_ROLE, _msgSender()) ) revert UserMustHaveProtocolOrProjectAdminRole(); if (addLinkPrice == _addLinkPrice) revert SameValue(); addLinkPrice = _addLinkPrice; } /// @notice Sets the price for adding the link in SoulLinker in MASA /// @dev The caller must have the admin or project admin role to call this function /// @param _addLinkPriceMASA New price for adding the link in SoulLinker in MASA function setAddLinkPriceMASA(uint256 _addLinkPriceMASA) external { if ( !hasRole(DEFAULT_ADMIN_ROLE, _msgSender()) && !hasRole(PROJECT_ADMIN_ROLE, _msgSender()) ) revert UserMustHaveProtocolOrProjectAdminRole(); if (addLinkPriceMASA == _addLinkPriceMASA) revert SameValue(); addLinkPriceMASA = _addLinkPriceMASA; } /// @notice Sets the price for reading data in SoulLinker in stable coin /// @dev The caller must have the admin or project admin role to call this function /// @param _queryLinkPrice New price for reading data in SoulLinker in stable coin function setQueryLinkPrice(uint256 _queryLinkPrice) external { if ( !hasRole(DEFAULT_ADMIN_ROLE, _msgSender()) && !hasRole(PROJECT_ADMIN_ROLE, _msgSender()) ) revert UserMustHaveProtocolOrProjectAdminRole(); if (queryLinkPrice == _queryLinkPrice) revert SameValue(); queryLinkPrice = _queryLinkPrice; } /// @notice Sets the price for reading data in SoulLinker in MASA /// @dev The caller must have the admin or project admin role to call this function /// @param _queryLinkPriceMASA New price for reading data in SoulLinker in MASA function setQueryLinkPriceMASA(uint256 _queryLinkPriceMASA) external { if ( !hasRole(DEFAULT_ADMIN_ROLE, _msgSender()) && !hasRole(PROJECT_ADMIN_ROLE, _msgSender()) ) revert UserMustHaveProtocolOrProjectAdminRole(); if (queryLinkPriceMASA == _queryLinkPriceMASA) revert SameValue(); queryLinkPriceMASA = _queryLinkPriceMASA; } /* ========== MUTATIVE FUNCTIONS ======================================== */ /* ========== VIEWS ===================================================== */ /// @notice Returns the identityId owned by the given token /// @param tokenId Id of the token /// @return Id of the identity function getIdentityId(uint256 tokenId) external view returns (uint256) { if (soulboundIdentity == ISoulboundIdentity(address(0))) revert NotLinkedToAnIdentitySBT(); address owner = super.ownerOf(tokenId); return soulboundIdentity.tokenOfOwner(owner); } /// @notice Returns true if the token exists /// @dev Returns true if the token has been minted /// @param tokenId Token to check /// @return True if the token exists function exists(uint256 tokenId) external view returns (bool) { return _exists(tokenId); } /// @notice A distinct Uniform Resource Identifier (URI) for a given asset. /// @dev Throws if `_tokenId` is not a valid SBT. URIs are defined in RFC /// 3986. The URI may point to a JSON file that conforms to the "ERC721 /// Metadata JSON Schema". /// @param tokenId SBT to get the URI of /// @return URI of the SBT function tokenURI( uint256 tokenId ) public view virtual override returns (string memory) { _requireMinted(tokenId); string memory baseURI = _baseURI(); return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, tokenId.toString(), ".json")) : ""; } /// @notice Query if a contract implements an interface /// @dev Interface identification is specified in ERC-165. /// @param interfaceId The interface identifier, as specified in ERC-165 /// @return `true` if the contract implements `interfaceId` and /// `interfaceId` is not 0xffffffff, `false` otherwise function supportsInterface( bytes4 interfaceId ) public view virtual override(SBT, SBTEnumerable, AccessControl, IERC165) returns (bool) { return super.supportsInterface(interfaceId); } /// @notice Returns the price for minting /// @dev Returns current pricing for minting /// @param paymentMethod Address of token that user want to pay /// @return price Current price for minting in the given payment method function getMintPrice( address paymentMethod ) public view returns (uint256 price) { if (mintPrice == 0 && mintPriceMASA == 0) { price = 0; } else if ( paymentMethod == masaToken && enabledPaymentMethod[paymentMethod] && mintPriceMASA > 0 ) { // price in MASA without conversion rate price = mintPriceMASA; } else if ( paymentMethod == stableCoin && enabledPaymentMethod[paymentMethod] ) { // stable coin price = mintPrice; } else if (enabledPaymentMethod[paymentMethod]) { // ETH and ERC 20 token price = _convertFromStableCoin(paymentMethod, mintPrice); } else { revert InvalidPaymentMethod(paymentMethod); } return price; } /// @notice Returns the price for minting with protocol fee /// @dev Returns current pricing for minting with protocol fee /// @param paymentMethod Address of token that user want to pay /// @return price Current price for minting in the given payment method /// @return protocolFee Current protocol fee for minting in the given payment method function getMintPriceWithProtocolFee( address paymentMethod ) public view returns (uint256 price, uint256 protocolFee) { price = getMintPrice(paymentMethod); return (price, _getProtocolFee(paymentMethod, price)); } /* ========== PRIVATE FUNCTIONS ========================================= */ function _baseURI() internal view virtual override returns (string memory) { return _baseTokenURI; } function _beforeTokenTransfer( address from, address to, uint256 tokenId ) internal virtual override(SBT, SBTEnumerable) { super._beforeTokenTransfer(from, to, tokenId); } /* ========== MODIFIERS ================================================= */ /* ========== EVENTS ==================================================== */ } // File contracts/tokens/MasaSBTAuthority.sol // Original license: SPDX_License_Identifier: MIT pragma solidity ^0.8.8; /// @title MasaSBT /// @author Masa Finance /// @notice Soulbound token. Non-fungible token that is not transferable. /// @dev Implementation of https://papers.ssrn.com/sol3/papers.cfm?abstract_id=4105763 Soulbound token. abstract contract MasaSBTAuthority is MasaSBT { /* ========== STATE VARIABLES =========================================== */ using Counters for Counters.Counter; bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE"); Counters.Counter private _tokenIdCounter; /* ========== INITIALIZE ================================================ */ /// @notice Creates a new soulbound token /// @dev Creates a new soulbound token /// @param admin Administrator of the smart contract /// @param name Name of the token /// @param symbol Symbol of the token /// @param baseTokenURI Base URI of the token /// @param soulboundIdentity Address of the SoulboundIdentity contract /// @param paymentParams Payment gateway params constructor( address admin, string memory name, string memory symbol, string memory baseTokenURI, address soulboundIdentity, PaymentParams memory paymentParams ) MasaSBT( admin, name, symbol, baseTokenURI, soulboundIdentity, paymentParams ) { _grantRole(MINTER_ROLE, admin); } /* ========== RESTRICTED FUNCTIONS ====================================== */ function _mintWithCounter( address paymentMethod, address to ) internal virtual onlyRole(MINTER_ROLE) returns (uint256) { (uint256 price, uint256 protocolFee) = getMintPriceWithProtocolFee( paymentMethod ); _pay(paymentMethod, price, protocolFee); uint256 tokenId = _tokenIdCounter.current(); _tokenIdCounter.increment(); _mint(to, tokenId); return tokenId; } /* ========== MUTATIVE FUNCTIONS ======================================== */ /* ========== VIEWS ===================================================== */ /* ========== PRIVATE FUNCTIONS ========================================= */ /* ========== MODIFIERS ================================================= */ /* ========== EVENTS ==================================================== */ } // File contracts/reference/ReferenceSBTAuthority.sol // Original license: SPDX_License_Identifier: MIT pragma solidity ^0.8.8; /// @title Soulbound reference Authority SBT /// @author Masa Finance /// @notice Soulbound token that represents a Authority SBT /// @dev Inherits from the SBT contract. contract ReferenceSBTAuthority is MasaSBTAuthority, ReentrancyGuard { error MaxSBTMinted(address to, uint256 maximum); uint256 public maxSBTToMint = 1; /* ========== STATE VARIABLES =========================================== */ /* ========== INITIALIZE ================================================ */ /// @notice Creates a new Authority SBT /// @dev Creates a new Authority SBT, inheriting from the SBT contract. /// @param admin Administrator of the smart contract /// @param name Name of the token /// @param symbol Symbol of the token /// @param baseTokenURI Base URI of the token /// @param soulboundIdentity Address of the SoulboundIdentity contract /// @param paymentParams Payment gateway params /// @param _maxSBTToMint Maximum number of SBT that can be minted constructor( address admin, string memory name, string memory symbol, string memory baseTokenURI, address soulboundIdentity, PaymentParams memory paymentParams, uint256 _maxSBTToMint ) MasaSBTAuthority( admin, name, symbol, baseTokenURI, soulboundIdentity, paymentParams ) { maxSBTToMint = _maxSBTToMint; } /* ========== RESTRICTED FUNCTIONS ====================================== */ /* ========== MUTATIVE FUNCTIONS ======================================== */ /// @notice Mints a new SBT /// @dev The caller must have the MINTER role /// @param paymentMethod Address of token that user want to pay /// @param identityId TokenId of the identity to mint the NFT to /// @return The SBT ID of the newly minted SBT function mint( address paymentMethod, uint256 identityId ) external payable nonReentrant returns (uint256) { address to = soulboundIdentity.ownerOf(identityId); if (maxSBTToMint > 0 && balanceOf(to) >= maxSBTToMint) revert MaxSBTMinted(to, maxSBTToMint); uint256 tokenId = _mintWithCounter(paymentMethod, to); emit MintedToIdentity(tokenId, identityId); return tokenId; } /// @notice Mints a new SBT /// @dev The caller must have the MINTER role /// @param paymentMethod Address of token that user want to pay /// @param to The address to mint the SBT to /// @return The SBT ID of the newly minted SBT function mint( address paymentMethod, address to ) external payable nonReentrant returns (uint256) { if (maxSBTToMint > 0 && balanceOf(to) >= maxSBTToMint) revert MaxSBTMinted(to, maxSBTToMint); uint256 tokenId = _mintWithCounter(paymentMethod, to); emit MintedToAddress(tokenId, to); return tokenId; } /// @notice Bulk mint of new SBTs /// @dev The caller must have the MINTER role /// @param paymentMethod Address of token that user want to pay /// @param identityId TokenIds array of the identity to mint the NFT to /// @return tokenIds The SBT IDs of the newly minted SBTs function mint( address paymentMethod, uint256[] memory identityId ) external payable nonReentrant returns (uint256[] memory tokenIds) { tokenIds = new uint256[](identityId.length); uint256 t = 0; for (uint256 i = 0; i < identityId.length; i++) { address to = soulboundIdentity.ownerOf(identityId[i]); if (maxSBTToMint > 0 && balanceOf(to) >= maxSBTToMint) revert MaxSBTMinted(to, maxSBTToMint); uint256 tokenId = _mintWithCounter(paymentMethod, to); emit MintedToIdentity(tokenId, identityId[i]); tokenIds[t] = tokenId; t++; } return tokenIds; } /// @notice Bulk mint of new SBTs /// @dev The caller must have the MINTER role /// @param paymentMethod Address of token that user want to pay /// @param to Addresses array to mint the SBT to /// @return tokenIds The SBT IDs of the newly minted SBTs function mint( address paymentMethod, address[] memory to ) external payable nonReentrant returns (uint256[] memory tokenIds) { tokenIds = new uint256[](to.length); uint256 t = 0; for (uint256 i = 0; i < to.length; i++) { if (maxSBTToMint > 0 && balanceOf(to[i]) >= maxSBTToMint) revert MaxSBTMinted(to[i], maxSBTToMint); uint256 tokenId = _mintWithCounter(paymentMethod, to[i]); emit MintedToAddress(tokenId, to[i]); tokenIds[t] = tokenId; t++; } return tokenIds; } /* ========== VIEWS ===================================================== */ function tokenURI( uint256 tokenId ) public view virtual override returns (string memory) { _requireMinted(tokenId); return _baseURI(); } /* ========== PRIVATE FUNCTIONS ========================================= */ /* ========== MODIFIERS ================================================= */ /* ========== EVENTS ==================================================== */ event MintedToIdentity(uint256 tokenId, uint256 identityId); event MintedToAddress(uint256 tokenId, address to); }
// Sources flattened with hardhat v2.17.1 https://hardhat.org // SPDX-License-Identifier: MIT // File @openzeppelin/contracts/access/[email protected] // Original license: SPDX_License_Identifier: MIT // OpenZeppelin Contracts v4.4.1 (access/IAccessControl.sol) pragma solidity ^0.8.0; /** * @dev External interface of AccessControl declared to support ERC165 detection. */ interface IAccessControl { /** * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole` * * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite * {RoleAdminChanged} not being emitted signaling this. * * _Available since v3.1._ */ event RoleAdminChanged( bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole ); /** * @dev Emitted when `account` is granted `role`. * * `sender` is the account that originated the contract call, an admin role * bearer except when using {AccessControl-_setupRole}. */ event RoleGranted( bytes32 indexed role, address indexed account, address indexed sender ); /** * @dev Emitted when `account` is revoked `role`. * * `sender` is the account that originated the contract call: * - if using `revokeRole`, it is the admin role bearer * - if using `renounceRole`, it is the role bearer (i.e. `account`) */ event RoleRevoked( bytes32 indexed role, address indexed account, address indexed sender ); /** * @dev Returns `true` if `account` has been granted `role`. */ function hasRole( bytes32 role, address account ) external view returns (bool); /** * @dev Returns the admin role that controls `role`. See {grantRole} and * {revokeRole}. * * To change a role's admin, use {AccessControl-_setRoleAdmin}. */ function getRoleAdmin(bytes32 role) external view returns (bytes32); /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. * * Requirements: * * - the caller must have ``role``'s admin role. */ function grantRole(bytes32 role, address account) external; /** * @dev Revokes `role` from `account`. * * If `account` had been granted `role`, emits a {RoleRevoked} event. * * Requirements: * * - the caller must have ``role``'s admin role. */ function revokeRole(bytes32 role, address account) external; /** * @dev Revokes `role` from the calling account. * * Roles are often managed via {grantRole} and {revokeRole}: this function's * purpose is to provide a mechanism for accounts to lose their privileges * if they are compromised (such as when a trusted device is misplaced). * * If the calling account had been granted `role`, emits a {RoleRevoked} * event. * * Requirements: * * - the caller must be `account`. */ function renounceRole(bytes32 role, address account) external; } // File @openzeppelin/contracts/utils/[email protected] // Original license: SPDX_License_Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Context.sol) pragma solidity ^0.8.0; /** * @dev Provides information about the current execution context, including the * sender of the transaction and its data. While these are generally available * via msg.sender and msg.data, they should not be accessed in such a direct * manner, since when dealing with meta-transactions the account sending and * paying for execution may not be the actual sender (as far as an application * is concerned). * * This contract is only required for intermediate, library-like contracts. */ abstract contract Context { function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } } // File @openzeppelin/contracts/utils/introspection/[email protected] // Original license: SPDX_License_Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/IERC165.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC165 standard, as defined in the * https://eips.ethereum.org/EIPS/eip-165[EIP]. * * Implementers can declare support of contract interfaces, which can then be * queried by others ({ERC165Checker}). * * For an implementation, see {ERC165}. */ interface IERC165 { /** * @dev Returns true if this contract implements the interface defined by * `interfaceId`. See the corresponding * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] * to learn more about how these ids are created. * * This function call must use less than 30 000 gas. */ function supportsInterface(bytes4 interfaceId) external view returns (bool); } // File @openzeppelin/contracts/utils/introspection/[email protected] // Original license: SPDX_License_Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol) pragma solidity ^0.8.0; /** * @dev Implementation of the {IERC165} interface. * * Contracts that want to implement ERC165 should inherit from this contract and override {supportsInterface} to check * for the additional interface id that will be supported. For example: * * ```solidity * function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { * return interfaceId == type(MyInterface).interfaceId || super.supportsInterface(interfaceId); * } * ``` * * Alternatively, {ERC165Storage} provides an easier to use but more expensive implementation. */ abstract contract ERC165 is IERC165 { /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface( bytes4 interfaceId ) public view virtual override returns (bool) { return interfaceId == type(IERC165).interfaceId; } } // File @openzeppelin/contracts/utils/math/[email protected] // Original license: SPDX_License_Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (utils/math/Math.sol) pragma solidity ^0.8.0; /** * @dev Standard math utilities missing in the Solidity language. */ library Math { enum Rounding { Down, // Toward negative infinity Up, // Toward infinity Zero // Toward zero } /** * @dev Returns the largest of two numbers. */ function max(uint256 a, uint256 b) internal pure returns (uint256) { return a > b ? a : b; } /** * @dev Returns the smallest of two numbers. */ function min(uint256 a, uint256 b) internal pure returns (uint256) { return a < b ? a : b; } /** * @dev Returns the average of two numbers. The result is rounded towards * zero. */ function average(uint256 a, uint256 b) internal pure returns (uint256) { // (a + b) / 2 can overflow. return (a & b) + (a ^ b) / 2; } /** * @dev Returns the ceiling of the division of two numbers. * * This differs from standard division with `/` in that it rounds up instead * of rounding down. */ function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) { // (a + b - 1) / b can overflow on addition, so we distribute. return a == 0 ? 0 : (a - 1) / b + 1; } /** * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0 * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) * with further edits by Uniswap Labs also under MIT license. */ function mulDiv( uint256 x, uint256 y, uint256 denominator ) internal pure returns (uint256 result) { unchecked { // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256 // variables such that product = prod1 * 2^256 + prod0. uint256 prod0; // Least significant 256 bits of the product uint256 prod1; // Most significant 256 bits of the product assembly { let mm := mulmod(x, y, not(0)) prod0 := mul(x, y) prod1 := sub(sub(mm, prod0), lt(mm, prod0)) } // Handle non-overflow cases, 256 by 256 division. if (prod1 == 0) { // Solidity will revert if denominator == 0, unlike the div opcode on its own. // The surrounding unchecked block does not change this fact. // See https://docs.soliditylang.org/en/latest/control-structures.html#checked-or-unchecked-arithmetic. return prod0 / denominator; } // Make sure the result is less than 2^256. Also prevents denominator == 0. require(denominator > prod1, "Math: mulDiv overflow"); /////////////////////////////////////////////// // 512 by 256 division. /////////////////////////////////////////////// // Make division exact by subtracting the remainder from [prod1 prod0]. uint256 remainder; assembly { // Compute remainder using mulmod. remainder := mulmod(x, y, denominator) // Subtract 256 bit number from 512 bit number. prod1 := sub(prod1, gt(remainder, prod0)) prod0 := sub(prod0, remainder) } // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1. // See https://cs.stackexchange.com/q/138556/92363. // Does not overflow because the denominator cannot be zero at this stage in the function. uint256 twos = denominator & (~denominator + 1); assembly { // Divide denominator by twos. denominator := div(denominator, twos) // Divide [prod1 prod0] by twos. prod0 := div(prod0, twos) // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one. twos := add(div(sub(0, twos), twos), 1) } // Shift in bits from prod1 into prod0. prod0 |= prod1 * twos; // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for // four bits. That is, denominator * inv = 1 mod 2^4. uint256 inverse = (3 * denominator) ^ 2; // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works // in modular arithmetic, doubling the correct bits in each step. inverse *= 2 - denominator * inverse; // inverse mod 2^8 inverse *= 2 - denominator * inverse; // inverse mod 2^16 inverse *= 2 - denominator * inverse; // inverse mod 2^32 inverse *= 2 - denominator * inverse; // inverse mod 2^64 inverse *= 2 - denominator * inverse; // inverse mod 2^128 inverse *= 2 - denominator * inverse; // inverse mod 2^256 // Because the division is now exact we can divide by multiplying with the modular inverse of denominator. // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1 // is no longer required. result = prod0 * inverse; return result; } } /** * @notice Calculates x * y / denominator with full precision, following the selected rounding direction. */ function mulDiv( uint256 x, uint256 y, uint256 denominator, Rounding rounding ) internal pure returns (uint256) { uint256 result = mulDiv(x, y, denominator); if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) { result += 1; } return result; } /** * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down. * * Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11). */ function sqrt(uint256 a) internal pure returns (uint256) { if (a == 0) { return 0; } // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target. // // We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`. // // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)` // → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))` // → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)` // // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit. uint256 result = 1 << (log2(a) >> 1); // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128, // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision // into the expected uint128 result. unchecked { result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; return min(result, a / result); } } /** * @notice Calculates sqrt(a), following the selected rounding direction. */ function sqrt( uint256 a, Rounding rounding ) internal pure returns (uint256) { unchecked { uint256 result = sqrt(a); return result + (rounding == Rounding.Up && result * result < a ? 1 : 0); } } /** * @dev Return the log in base 2, rounded down, of a positive value. * Returns 0 if given 0. */ function log2(uint256 value) internal pure returns (uint256) { uint256 result = 0; unchecked { if (value >> 128 > 0) { value >>= 128; result += 128; } if (value >> 64 > 0) { value >>= 64; result += 64; } if (value >> 32 > 0) { value >>= 32; result += 32; } if (value >> 16 > 0) { value >>= 16; result += 16; } if (value >> 8 > 0) { value >>= 8; result += 8; } if (value >> 4 > 0) { value >>= 4; result += 4; } if (value >> 2 > 0) { value >>= 2; result += 2; } if (value >> 1 > 0) { result += 1; } } return result; } /** * @dev Return the log in base 2, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log2( uint256 value, Rounding rounding ) internal pure returns (uint256) { unchecked { uint256 result = log2(value); return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0); } } /** * @dev Return the log in base 10, rounded down, of a positive value. * Returns 0 if given 0. */ function log10(uint256 value) internal pure returns (uint256) { uint256 result = 0; unchecked { if (value >= 10 ** 64) { value /= 10 ** 64; result += 64; } if (value >= 10 ** 32) { value /= 10 ** 32; result += 32; } if (value >= 10 ** 16) { value /= 10 ** 16; result += 16; } if (value >= 10 ** 8) { value /= 10 ** 8; result += 8; } if (value >= 10 ** 4) { value /= 10 ** 4; result += 4; } if (value >= 10 ** 2) { value /= 10 ** 2; result += 2; } if (value >= 10 ** 1) { result += 1; } } return result; } /** * @dev Return the log in base 10, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log10( uint256 value, Rounding rounding ) internal pure returns (uint256) { unchecked { uint256 result = log10(value); return result + (rounding == Rounding.Up && 10 ** result < value ? 1 : 0); } } /** * @dev Return the log in base 256, rounded down, of a positive value. * Returns 0 if given 0. * * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string. */ function log256(uint256 value) internal pure returns (uint256) { uint256 result = 0; unchecked { if (value >> 128 > 0) { value >>= 128; result += 16; } if (value >> 64 > 0) { value >>= 64; result += 8; } if (value >> 32 > 0) { value >>= 32; result += 4; } if (value >> 16 > 0) { value >>= 16; result += 2; } if (value >> 8 > 0) { result += 1; } } return result; } /** * @dev Return the log in base 256, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log256( uint256 value, Rounding rounding ) internal pure returns (uint256) { unchecked { uint256 result = log256(value); return result + (rounding == Rounding.Up && 1 << (result << 3) < value ? 1 : 0); } } } // File @openzeppelin/contracts/utils/math/[email protected] // Original license: SPDX_License_Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (utils/math/SignedMath.sol) pragma solidity ^0.8.0; /** * @dev Standard signed math utilities missing in the Solidity language. */ library SignedMath { /** * @dev Returns the largest of two signed numbers. */ function max(int256 a, int256 b) internal pure returns (int256) { return a > b ? a : b; } /** * @dev Returns the smallest of two signed numbers. */ function min(int256 a, int256 b) internal pure returns (int256) { return a < b ? a : b; } /** * @dev Returns the average of two signed numbers without overflow. * The result is rounded towards zero. */ function average(int256 a, int256 b) internal pure returns (int256) { // Formula from the book "Hacker's Delight" int256 x = (a & b) + ((a ^ b) >> 1); return x + (int256(uint256(x) >> 255) & (a ^ b)); } /** * @dev Returns the absolute unsigned value of a signed value. */ function abs(int256 n) internal pure returns (uint256) { unchecked { // must be unchecked in order to support `n = type(int256).min` return uint256(n >= 0 ? n : -n); } } } // File @openzeppelin/contracts/utils/[email protected] // Original license: SPDX_License_Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (utils/Strings.sol) pragma solidity ^0.8.0; /** * @dev String operations. */ library Strings { bytes16 private constant _SYMBOLS = "0123456789abcdef"; uint8 private constant _ADDRESS_LENGTH = 20; /** * @dev Converts a `uint256` to its ASCII `string` decimal representation. */ function toString(uint256 value) internal pure returns (string memory) { unchecked { uint256 length = Math.log10(value) + 1; string memory buffer = new string(length); uint256 ptr; /// @solidity memory-safe-assembly assembly { ptr := add(buffer, add(32, length)) } while (true) { ptr--; /// @solidity memory-safe-assembly assembly { mstore8(ptr, byte(mod(value, 10), _SYMBOLS)) } value /= 10; if (value == 0) break; } return buffer; } } /** * @dev Converts a `int256` to its ASCII `string` decimal representation. */ function toString(int256 value) internal pure returns (string memory) { return string( abi.encodePacked( value < 0 ? "-" : "", toString(SignedMath.abs(value)) ) ); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. */ function toHexString(uint256 value) internal pure returns (string memory) { unchecked { return toHexString(value, Math.log256(value) + 1); } } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. */ function toHexString( uint256 value, uint256 length ) internal pure returns (string memory) { bytes memory buffer = new bytes(2 * length + 2); buffer[0] = "0"; buffer[1] = "x"; for (uint256 i = 2 * length + 1; i > 1; --i) { buffer[i] = _SYMBOLS[value & 0xf]; value >>= 4; } require(value == 0, "Strings: hex length insufficient"); return string(buffer); } /** * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation. */ function toHexString(address addr) internal pure returns (string memory) { return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH); } /** * @dev Returns true if the two strings are equal. */ function equal( string memory a, string memory b ) internal pure returns (bool) { return keccak256(bytes(a)) == keccak256(bytes(b)); } } // File @openzeppelin/contracts/access/[email protected] // Original license: SPDX_License_Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (access/AccessControl.sol) pragma solidity ^0.8.0; /** * @dev Contract module that allows children to implement role-based access * control mechanisms. This is a lightweight version that doesn't allow enumerating role * members except through off-chain means by accessing the contract event logs. Some * applications may benefit from on-chain enumerability, for those cases see * {AccessControlEnumerable}. * * Roles are referred to by their `bytes32` identifier. These should be exposed * in the external API and be unique. The best way to achieve this is by * using `public constant` hash digests: * * ```solidity * bytes32 public constant MY_ROLE = keccak256("MY_ROLE"); * ``` * * Roles can be used to represent a set of permissions. To restrict access to a * function call, use {hasRole}: * * ```solidity * function foo() public { * require(hasRole(MY_ROLE, msg.sender)); * ... * } * ``` * * Roles can be granted and revoked dynamically via the {grantRole} and * {revokeRole} functions. Each role has an associated admin role, and only * accounts that have a role's admin role can call {grantRole} and {revokeRole}. * * By default, the admin role for all roles is `DEFAULT_ADMIN_ROLE`, which means * that only accounts with this role will be able to grant or revoke other * roles. More complex role relationships can be created by using * {_setRoleAdmin}. * * WARNING: The `DEFAULT_ADMIN_ROLE` is also its own admin: it has permission to * grant and revoke this role. Extra precautions should be taken to secure * accounts that have been granted it. We recommend using {AccessControlDefaultAdminRules} * to enforce additional security measures for this role. */ abstract contract AccessControl is Context, IAccessControl, ERC165 { struct RoleData { mapping(address => bool) members; bytes32 adminRole; } mapping(bytes32 => RoleData) private _roles; bytes32 public constant DEFAULT_ADMIN_ROLE = 0x00; /** * @dev Modifier that checks that an account has a specific role. Reverts * with a standardized message including the required role. * * The format of the revert reason is given by the following regular expression: * * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/ * * _Available since v4.1._ */ modifier onlyRole(bytes32 role) { _checkRole(role); _; } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface( bytes4 interfaceId ) public view virtual override returns (bool) { return interfaceId == type(IAccessControl).interfaceId || super.supportsInterface(interfaceId); } /** * @dev Returns `true` if `account` has been granted `role`. */ function hasRole( bytes32 role, address account ) public view virtual override returns (bool) { return _roles[role].members[account]; } /** * @dev Revert with a standard message if `_msgSender()` is missing `role`. * Overriding this function changes the behavior of the {onlyRole} modifier. * * Format of the revert message is described in {_checkRole}. * * _Available since v4.6._ */ function _checkRole(bytes32 role) internal view virtual { _checkRole(role, _msgSender()); } /** * @dev Revert with a standard message if `account` is missing `role`. * * The format of the revert reason is given by the following regular expression: * * /^AccessControl: account (0x[0-9a-f]{40}) is missing role (0x[0-9a-f]{64})$/ */ function _checkRole(bytes32 role, address account) internal view virtual { if (!hasRole(role, account)) { revert( string( abi.encodePacked( "AccessControl: account ", Strings.toHexString(account), " is missing role ", Strings.toHexString(uint256(role), 32) ) ) ); } } /** * @dev Returns the admin role that controls `role`. See {grantRole} and * {revokeRole}. * * To change a role's admin, use {_setRoleAdmin}. */ function getRoleAdmin( bytes32 role ) public view virtual override returns (bytes32) { return _roles[role].adminRole; } /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. * * Requirements: * * - the caller must have ``role``'s admin role. * * May emit a {RoleGranted} event. */ function grantRole( bytes32 role, address account ) public virtual override onlyRole(getRoleAdmin(role)) { _grantRole(role, account); } /** * @dev Revokes `role` from `account`. * * If `account` had been granted `role`, emits a {RoleRevoked} event. * * Requirements: * * - the caller must have ``role``'s admin role. * * May emit a {RoleRevoked} event. */ function revokeRole( bytes32 role, address account ) public virtual override onlyRole(getRoleAdmin(role)) { _revokeRole(role, account); } /** * @dev Revokes `role` from the calling account. * * Roles are often managed via {grantRole} and {revokeRole}: this function's * purpose is to provide a mechanism for accounts to lose their privileges * if they are compromised (such as when a trusted device is misplaced). * * If the calling account had been revoked `role`, emits a {RoleRevoked} * event. * * Requirements: * * - the caller must be `account`. * * May emit a {RoleRevoked} event. */ function renounceRole( bytes32 role, address account ) public virtual override { require( account == _msgSender(), "AccessControl: can only renounce roles for self" ); _revokeRole(role, account); } /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. Note that unlike {grantRole}, this function doesn't perform any * checks on the calling account. * * May emit a {RoleGranted} event. * * [WARNING] * ==== * This function should only be called from the constructor when setting * up the initial roles for the system. * * Using this function in any other way is effectively circumventing the admin * system imposed by {AccessControl}. * ==== * * NOTE: This function is deprecated in favor of {_grantRole}. */ function _setupRole(bytes32 role, address account) internal virtual { _grantRole(role, account); } /** * @dev Sets `adminRole` as ``role``'s admin role. * * Emits a {RoleAdminChanged} event. */ function _setRoleAdmin(bytes32 role, bytes32 adminRole) internal virtual { bytes32 previousAdminRole = getRoleAdmin(role); _roles[role].adminRole = adminRole; emit RoleAdminChanged(role, previousAdminRole, adminRole); } /** * @dev Grants `role` to `account`. * * Internal function without access restriction. * * May emit a {RoleGranted} event. */ function _grantRole(bytes32 role, address account) internal virtual { if (!hasRole(role, account)) { _roles[role].members[account] = true; emit RoleGranted(role, account, _msgSender()); } } /** * @dev Revokes `role` from `account`. * * Internal function without access restriction. * * May emit a {RoleRevoked} event. */ function _revokeRole(bytes32 role, address account) internal virtual { if (hasRole(role, account)) { _roles[role].members[account] = false; emit RoleRevoked(role, account, _msgSender()); } } } // File @openzeppelin/contracts/token/ERC20/extensions/[email protected] // Original license: SPDX_License_Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/extensions/IERC20Permit.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 Permit extension allowing approvals to be made via signatures, as defined in * https://eips.ethereum.org/EIPS/eip-2612[EIP-2612]. * * Adds the {permit} method, which can be used to change an account's ERC20 allowance (see {IERC20-allowance}) by * presenting a message signed by the account. By not relying on {IERC20-approve}, the token holder account doesn't * need to send a transaction, and thus is not required to hold Ether at all. */ interface IERC20Permit { /** * @dev Sets `value` as the allowance of `spender` over ``owner``'s tokens, * given ``owner``'s signed approval. * * IMPORTANT: The same issues {IERC20-approve} has related to transaction * ordering also apply here. * * Emits an {Approval} event. * * Requirements: * * - `spender` cannot be the zero address. * - `deadline` must be a timestamp in the future. * - `v`, `r` and `s` must be a valid `secp256k1` signature from `owner` * over the EIP712-formatted function arguments. * - the signature must use ``owner``'s current nonce (see {nonces}). * * For more information on the signature format, see the * https://eips.ethereum.org/EIPS/eip-2612#specification[relevant EIP * section]. */ function permit( address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) external; /** * @dev Returns the current nonce for `owner`. This value must be * included whenever a signature is generated for {permit}. * * Every successful call to {permit} increases ``owner``'s nonce by one. This * prevents a signature from being used multiple times. */ function nonces(address owner) external view returns (uint256); /** * @dev Returns the domain separator used in the encoding of the signature for {permit}, as defined by {EIP712}. */ // solhint-disable-next-line func-name-mixedcase function DOMAIN_SEPARATOR() external view returns (bytes32); } // File @openzeppelin/contracts/token/ERC20/[email protected] // Original license: SPDX_License_Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (token/ERC20/IERC20.sol) pragma solidity ^0.8.0; /** * @dev Interface of the ERC20 standard as defined in the EIP. */ interface IERC20 { /** * @dev Emitted when `value` tokens are moved from one account (`from`) to * another (`to`). * * Note that `value` may be zero. */ event Transfer(address indexed from, address indexed 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. */ event Approval( address indexed owner, address indexed spender, uint256 value ); /** * @dev Returns the amount of tokens in existence. */ function totalSupply() external view returns (uint256); /** * @dev Returns the amount of tokens owned by `account`. */ function balanceOf(address account) external view returns (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. */ function transfer(address to, uint256 amount) external returns (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. */ function allowance( address owner, address spender ) external view returns (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. */ function approve(address spender, uint256 amount) external returns (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. */ function transferFrom( address from, address to, uint256 amount ) external returns (bool); } // File @openzeppelin/contracts/utils/[email protected] // Original license: SPDX_License_Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (utils/Address.sol) pragma solidity ^0.8.1; /** * @dev Collection of functions related to the address type */ library Address { /** * @dev Returns true if `account` is a contract. * * [IMPORTANT] * ==== * It is unsafe to assume that an address for which this function returns * false is an externally-owned account (EOA) and not a contract. * * Among others, `isContract` will return false for the following * types of addresses: * * - an externally-owned account * - a contract in construction * - an address where a contract will be created * - an address where a contract lived, but was destroyed * * Furthermore, `isContract` will also return true if the target contract within * the same transaction is already scheduled for destruction by `SELFDESTRUCT`, * which only has an effect at the end of a transaction. * ==== * * [IMPORTANT] * ==== * You shouldn't rely on `isContract` to protect against flash loan attacks! * * Preventing calls from contracts is highly discouraged. It breaks composability, breaks support for smart wallets * like Gnosis Safe, and does not provide security since it can be circumvented by calling from a contract * constructor. * ==== */ function isContract(address account) internal view returns (bool) { // This method relies on extcodesize/address.code.length, which returns 0 // for contracts in construction, since the code is only stored at the end // of the constructor execution. return account.code.length > 0; } /** * @dev Replacement for Solidity's `transfer`: sends `amount` wei to * `recipient`, forwarding all available gas and reverting on errors. * * https://eips.ethereum.org/EIPS/eip-1884[EIP1884] increases the gas cost * of certain opcodes, possibly making contracts go over the 2300 gas limit * imposed by `transfer`, making them unable to receive funds via * `transfer`. {sendValue} removes this limitation. * * https://consensys.net/diligence/blog/2019/09/stop-using-soliditys-transfer-now/[Learn more]. * * IMPORTANT: because control is transferred to `recipient`, care must be * taken to not create reentrancy vulnerabilities. Consider using * {ReentrancyGuard} or the * https://solidity.readthedocs.io/en/v0.8.0/security-considerations.html#use-the-checks-effects-interactions-pattern[checks-effects-interactions pattern]. */ function sendValue(address payable recipient, uint256 amount) internal { require( address(this).balance >= amount, "Address: insufficient balance" ); (bool success, ) = recipient.call{value: amount}(""); require( success, "Address: unable to send value, recipient may have reverted" ); } /** * @dev Performs a Solidity function call using a low level `call`. A * plain `call` is an unsafe replacement for a function call: use this * function instead. * * If `target` reverts with a revert reason, it is bubbled up by this * function (like regular Solidity function calls). * * Returns the raw returned data. To convert to the expected return value, * use https://solidity.readthedocs.io/en/latest/units-and-global-variables.html?highlight=abi.decode#abi-encoding-and-decoding-functions[`abi.decode`]. * * Requirements: * * - `target` must be a contract. * - calling `target` with `data` must not revert. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data ) internal returns (bytes memory) { return functionCallWithValue( target, data, 0, "Address: low-level call failed" ); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value ) internal returns (bytes memory) { return functionCallWithValue( target, data, value, "Address: low-level call with value failed" ); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require( address(this).balance >= value, "Address: insufficient balance for call" ); (bool success, bytes memory returndata) = target.call{value: value}( data ); return verifyCallResultFromTarget( target, success, returndata, errorMessage ); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data ) internal view returns (bytes memory) { return functionStaticCall( target, data, "Address: low-level static call failed" ); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResultFromTarget( target, success, returndata, errorMessage ); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall( address target, bytes memory data ) internal returns (bytes memory) { return functionDelegateCall( target, data, "Address: low-level delegate call failed" ); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a delegate call. * * _Available since v3.4._ */ function functionDelegateCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResultFromTarget( target, success, returndata, errorMessage ); } /** * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract. * * _Available since v4.8._ */ function verifyCallResultFromTarget( address target, bool success, bytes memory returndata, string memory errorMessage ) internal view returns (bytes memory) { if (success) { if (returndata.length == 0) { // only check isContract if the call was successful and the return data is empty // otherwise we already know that it was a contract require(isContract(target), "Address: call to non-contract"); } return returndata; } else { _revert(returndata, errorMessage); } } /** * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason or using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { _revert(returndata, errorMessage); } } function _revert( bytes memory returndata, string memory errorMessage ) private pure { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly /// @solidity memory-safe-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } } // File @openzeppelin/contracts/token/ERC20/utils/[email protected] // Original license: SPDX_License_Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.3) (token/ERC20/utils/SafeERC20.sol) pragma solidity ^0.8.0; /** * @title SafeERC20 * @dev Wrappers around ERC20 operations that throw on failure (when the token * contract returns false). Tokens that return no value (and instead revert or * throw on failure) are also supported, non-reverting calls are assumed to be * successful. * To use this library you can add a `using SafeERC20 for IERC20;` statement to your contract, * which allows you to call the safe operations as `token.safeTransfer(...)`, etc. */ library SafeERC20 { using Address for address; /** * @dev Transfer `value` amount of `token` from the calling contract to `to`. If `token` returns no value, * non-reverting calls are assumed to be successful. */ function safeTransfer(IERC20 token, address to, uint256 value) internal { _callOptionalReturn( token, abi.encodeWithSelector(token.transfer.selector, to, value) ); } /** * @dev Transfer `value` amount of `token` from `from` to `to`, spending the approval given by `from` to the * calling contract. If `token` returns no value, non-reverting calls are assumed to be successful. */ function safeTransferFrom( IERC20 token, address from, address to, uint256 value ) internal { _callOptionalReturn( token, abi.encodeWithSelector(token.transferFrom.selector, from, to, value) ); } /** * @dev Deprecated. This function has issues similar to the ones found in * {IERC20-approve}, and its usage is discouraged. * * Whenever possible, use {safeIncreaseAllowance} and * {safeDecreaseAllowance} instead. */ function safeApprove( IERC20 token, address spender, uint256 value ) internal { // safeApprove should only be called when setting an initial allowance, // or when resetting it to zero. To increase and decrease it, use // 'safeIncreaseAllowance' and 'safeDecreaseAllowance' require( (value == 0) || (token.allowance(address(this), spender) == 0), "SafeERC20: approve from non-zero to non-zero allowance" ); _callOptionalReturn( token, abi.encodeWithSelector(token.approve.selector, spender, value) ); } /** * @dev Increase the calling contract's allowance toward `spender` by `value`. If `token` returns no value, * non-reverting calls are assumed to be successful. */ function safeIncreaseAllowance( IERC20 token, address spender, uint256 value ) internal { uint256 oldAllowance = token.allowance(address(this), spender); _callOptionalReturn( token, abi.encodeWithSelector( token.approve.selector, spender, oldAllowance + value ) ); } /** * @dev Decrease the calling contract's allowance toward `spender` by `value`. If `token` returns no value, * non-reverting calls are assumed to be successful. */ function safeDecreaseAllowance( IERC20 token, address spender, uint256 value ) internal { unchecked { uint256 oldAllowance = token.allowance(address(this), spender); require( oldAllowance >= value, "SafeERC20: decreased allowance below zero" ); _callOptionalReturn( token, abi.encodeWithSelector( token.approve.selector, spender, oldAllowance - value ) ); } } /** * @dev Set the calling contract's allowance toward `spender` to `value`. If `token` returns no value, * non-reverting calls are assumed to be successful. Meant to be used with tokens that require the approval * to be set to zero before setting it to a non-zero value, such as USDT. */ function forceApprove( IERC20 token, address spender, uint256 value ) internal { bytes memory approvalCall = abi.encodeWithSelector( token.approve.selector, spender, value ); if (!_callOptionalReturnBool(token, approvalCall)) { _callOptionalReturn( token, abi.encodeWithSelector(token.approve.selector, spender, 0) ); _callOptionalReturn(token, approvalCall); } } /** * @dev Use a ERC-2612 signature to set the `owner` approval toward `spender` on `token`. * Revert on invalid signature. */ function safePermit( IERC20Permit token, address owner, address spender, uint256 value, uint256 deadline, uint8 v, bytes32 r, bytes32 s ) internal { uint256 nonceBefore = token.nonces(owner); token.permit(owner, spender, value, deadline, v, r, s); uint256 nonceAfter = token.nonces(owner); require( nonceAfter == nonceBefore + 1, "SafeERC20: permit did not succeed" ); } /** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). */ function _callOptionalReturn(IERC20 token, bytes memory data) private { // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since // we're implementing it ourselves. We use {Address-functionCall} to perform this call, which verifies that // the target address contains contract code and also asserts for success in the low-level call. bytes memory returndata = address(token).functionCall( data, "SafeERC20: low-level call failed" ); require( returndata.length == 0 || abi.decode(returndata, (bool)), "SafeERC20: ERC20 operation did not succeed" ); } /** * @dev Imitates a Solidity high-level call (i.e. a regular function call to a contract), relaxing the requirement * on the return value: the return value is optional (but if data is returned, it must not be false). * @param token The token targeted by the call. * @param data The call data (encoded using abi.encode or one of its variants). * * This is a variant of {_callOptionalReturn} that silents catches all reverts and returns a bool instead. */ function _callOptionalReturnBool( IERC20 token, bytes memory data ) private returns (bool) { // We need to perform a low level call here, to bypass Solidity's return data size checking mechanism, since // we're implementing it ourselves. We cannot use {Address-functionCall} here since this should return false // and not revert is the subcall reverts. (bool success, bytes memory returndata) = address(token).call(data); return success && (returndata.length == 0 || abi.decode(returndata, (bool))) && Address.isContract(address(token)); } } // File @openzeppelin/contracts/interfaces/[email protected] // Original license: SPDX_License_Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (interfaces/IERC5267.sol) pragma solidity ^0.8.0; interface IERC5267 { /** * @dev MAY be emitted to signal that the domain could have changed. */ event EIP712DomainChanged(); /** * @dev returns the fields and values that describe the domain separator used by this contract for EIP-712 * signature. */ function eip712Domain() external view returns ( bytes1 fields, string memory name, string memory version, uint256 chainId, address verifyingContract, bytes32 salt, uint256[] memory extensions ); } // File @openzeppelin/contracts/utils/cryptography/[email protected] // Original license: SPDX_License_Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (utils/cryptography/ECDSA.sol) pragma solidity ^0.8.0; /** * @dev Elliptic Curve Digital Signature Algorithm (ECDSA) operations. * * These functions can be used to verify that a message was signed by the holder * of the private keys of a given address. */ library ECDSA { enum RecoverError { NoError, InvalidSignature, InvalidSignatureLength, InvalidSignatureS, InvalidSignatureV // Deprecated in v4.8 } function _throwError(RecoverError error) private pure { if (error == RecoverError.NoError) { return; // no error: do nothing } else if (error == RecoverError.InvalidSignature) { revert("ECDSA: invalid signature"); } else if (error == RecoverError.InvalidSignatureLength) { revert("ECDSA: invalid signature length"); } else if (error == RecoverError.InvalidSignatureS) { revert("ECDSA: invalid signature 's' value"); } } /** * @dev Returns the address that signed a hashed message (`hash`) with * `signature` or error string. This address can then be used for verification purposes. * * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures: * this function rejects them by requiring the `s` value to be in the lower * half order, and the `v` value to be either 27 or 28. * * IMPORTANT: `hash` _must_ be the result of a hash operation for the * verification to be secure: it is possible to craft signatures that * recover to arbitrary addresses for non-hashed data. A safe way to ensure * this is by receiving a hash of the original message (which may otherwise * be too long), and then calling {toEthSignedMessageHash} on it. * * Documentation for signature generation: * - with https://web3js.readthedocs.io/en/v1.3.4/web3-eth-accounts.html#sign[Web3.js] * - with https://docs.ethers.io/v5/api/signer/#Signer-signMessage[ethers] * * _Available since v4.3._ */ function tryRecover( bytes32 hash, bytes memory signature ) internal pure returns (address, RecoverError) { if (signature.length == 65) { bytes32 r; bytes32 s; uint8 v; // ecrecover takes the signature parameters, and the only way to get them // currently is to use assembly. /// @solidity memory-safe-assembly assembly { r := mload(add(signature, 0x20)) s := mload(add(signature, 0x40)) v := byte(0, mload(add(signature, 0x60))) } return tryRecover(hash, v, r, s); } else { return (address(0), RecoverError.InvalidSignatureLength); } } /** * @dev Returns the address that signed a hashed message (`hash`) with * `signature`. This address can then be used for verification purposes. * * The `ecrecover` EVM opcode allows for malleable (non-unique) signatures: * this function rejects them by requiring the `s` value to be in the lower * half order, and the `v` value to be either 27 or 28. * * IMPORTANT: `hash` _must_ be the result of a hash operation for the * verification to be secure: it is possible to craft signatures that * recover to arbitrary addresses for non-hashed data. A safe way to ensure * this is by receiving a hash of the original message (which may otherwise * be too long), and then calling {toEthSignedMessageHash} on it. */ function recover( bytes32 hash, bytes memory signature ) internal pure returns (address) { (address recovered, RecoverError error) = tryRecover(hash, signature); _throwError(error); return recovered; } /** * @dev Overload of {ECDSA-tryRecover} that receives the `r` and `vs` short-signature fields separately. * * See https://eips.ethereum.org/EIPS/eip-2098[EIP-2098 short signatures] * * _Available since v4.3._ */ function tryRecover( bytes32 hash, bytes32 r, bytes32 vs ) internal pure returns (address, RecoverError) { bytes32 s = vs & bytes32( 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff ); uint8 v = uint8((uint256(vs) >> 255) + 27); return tryRecover(hash, v, r, s); } /** * @dev Overload of {ECDSA-recover} that receives the `r and `vs` short-signature fields separately. * * _Available since v4.2._ */ function recover( bytes32 hash, bytes32 r, bytes32 vs ) internal pure returns (address) { (address recovered, RecoverError error) = tryRecover(hash, r, vs); _throwError(error); return recovered; } /** * @dev Overload of {ECDSA-tryRecover} that receives the `v`, * `r` and `s` signature fields separately. * * _Available since v4.3._ */ function tryRecover( bytes32 hash, uint8 v, bytes32 r, bytes32 s ) internal pure returns (address, RecoverError) { // EIP-2 still allows signature malleability for ecrecover(). Remove this possibility and make the signature // unique. Appendix F in the Ethereum Yellow paper (https://ethereum.github.io/yellowpaper/paper.pdf), defines // the valid range for s in (301): 0 < s < secp256k1n ÷ 2 + 1, and for v in (302): v ∈ {27, 28}. Most // signatures from current libraries generate a unique signature with an s-value in the lower half order. // // If your library generates malleable signatures, such as s-values in the upper range, calculate a new s-value // with 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141 - s1 and flip v from 27 to 28 or // vice versa. If your library also generates signatures with 0/1 for v instead 27/28, add 27 to v to accept // these malleable signatures as well. if ( uint256(s) > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0 ) { return (address(0), RecoverError.InvalidSignatureS); } // If the signature is valid (and not malleable), return the signer address address signer = ecrecover(hash, v, r, s); if (signer == address(0)) { return (address(0), RecoverError.InvalidSignature); } return (signer, RecoverError.NoError); } /** * @dev Overload of {ECDSA-recover} that receives the `v`, * `r` and `s` signature fields separately. */ function recover( bytes32 hash, uint8 v, bytes32 r, bytes32 s ) internal pure returns (address) { (address recovered, RecoverError error) = tryRecover(hash, v, r, s); _throwError(error); return recovered; } /** * @dev Returns an Ethereum Signed Message, created from a `hash`. This * produces hash corresponding to the one signed with the * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`] * JSON-RPC method as part of EIP-191. * * See {recover}. */ function toEthSignedMessageHash( bytes32 hash ) internal pure returns (bytes32 message) { // 32 is the length in bytes of hash, // enforced by the type signature above /// @solidity memory-safe-assembly assembly { mstore(0x00, "\x19Ethereum Signed Message:\n32") mstore(0x1c, hash) message := keccak256(0x00, 0x3c) } } /** * @dev Returns an Ethereum Signed Message, created from `s`. This * produces hash corresponding to the one signed with the * https://eth.wiki/json-rpc/API#eth_sign[`eth_sign`] * JSON-RPC method as part of EIP-191. * * See {recover}. */ function toEthSignedMessageHash( bytes memory s ) internal pure returns (bytes32) { return keccak256( abi.encodePacked( "\x19Ethereum Signed Message:\n", Strings.toString(s.length), s ) ); } /** * @dev Returns an Ethereum Signed Typed Data, created from a * `domainSeparator` and a `structHash`. This produces hash corresponding * to the one signed with the * https://eips.ethereum.org/EIPS/eip-712[`eth_signTypedData`] * JSON-RPC method as part of EIP-712. * * See {recover}. */ function toTypedDataHash( bytes32 domainSeparator, bytes32 structHash ) internal pure returns (bytes32 data) { /// @solidity memory-safe-assembly assembly { let ptr := mload(0x40) mstore(ptr, "\x19\x01") mstore(add(ptr, 0x02), domainSeparator) mstore(add(ptr, 0x22), structHash) data := keccak256(ptr, 0x42) } } /** * @dev Returns an Ethereum Signed Data with intended validator, created from a * `validator` and `data` according to the version 0 of EIP-191. * * See {recover}. */ function toDataWithIntendedValidatorHash( address validator, bytes memory data ) internal pure returns (bytes32) { return keccak256(abi.encodePacked("\x19\x00", validator, data)); } } // File @openzeppelin/contracts/utils/[email protected] // Original license: SPDX_License_Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (utils/StorageSlot.sol) // This file was procedurally generated from scripts/generate/templates/StorageSlot.js. pragma solidity ^0.8.0; /** * @dev Library for reading and writing primitive types to specific storage slots. * * Storage slots are often used to avoid storage conflict when dealing with upgradeable contracts. * This library helps with reading and writing to such slots without the need for inline assembly. * * The functions in this library return Slot structs that contain a `value` member that can be used to read or write. * * Example usage to set ERC1967 implementation slot: * ```solidity * contract ERC1967 { * bytes32 internal constant _IMPLEMENTATION_SLOT = 0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc; * * function _getImplementation() internal view returns (address) { * return StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value; * } * * function _setImplementation(address newImplementation) internal { * require(Address.isContract(newImplementation), "ERC1967: new implementation is not a contract"); * StorageSlot.getAddressSlot(_IMPLEMENTATION_SLOT).value = newImplementation; * } * } * ``` * * _Available since v4.1 for `address`, `bool`, `bytes32`, `uint256`._ * _Available since v4.9 for `string`, `bytes`._ */ library StorageSlot { struct AddressSlot { address value; } struct BooleanSlot { bool value; } struct Bytes32Slot { bytes32 value; } struct Uint256Slot { uint256 value; } struct StringSlot { string value; } struct BytesSlot { bytes value; } /** * @dev Returns an `AddressSlot` with member `value` located at `slot`. */ function getAddressSlot( bytes32 slot ) internal pure returns (AddressSlot storage r) { /// @solidity memory-safe-assembly assembly { r.slot := slot } } /** * @dev Returns an `BooleanSlot` with member `value` located at `slot`. */ function getBooleanSlot( bytes32 slot ) internal pure returns (BooleanSlot storage r) { /// @solidity memory-safe-assembly assembly { r.slot := slot } } /** * @dev Returns an `Bytes32Slot` with member `value` located at `slot`. */ function getBytes32Slot( bytes32 slot ) internal pure returns (Bytes32Slot storage r) { /// @solidity memory-safe-assembly assembly { r.slot := slot } } /** * @dev Returns an `Uint256Slot` with member `value` located at `slot`. */ function getUint256Slot( bytes32 slot ) internal pure returns (Uint256Slot storage r) { /// @solidity memory-safe-assembly assembly { r.slot := slot } } /** * @dev Returns an `StringSlot` with member `value` located at `slot`. */ function getStringSlot( bytes32 slot ) internal pure returns (StringSlot storage r) { /// @solidity memory-safe-assembly assembly { r.slot := slot } } /** * @dev Returns an `StringSlot` representation of the string storage pointer `store`. */ function getStringSlot( string storage store ) internal pure returns (StringSlot storage r) { /// @solidity memory-safe-assembly assembly { r.slot := store.slot } } /** * @dev Returns an `BytesSlot` with member `value` located at `slot`. */ function getBytesSlot( bytes32 slot ) internal pure returns (BytesSlot storage r) { /// @solidity memory-safe-assembly assembly { r.slot := slot } } /** * @dev Returns an `BytesSlot` representation of the bytes storage pointer `store`. */ function getBytesSlot( bytes storage store ) internal pure returns (BytesSlot storage r) { /// @solidity memory-safe-assembly assembly { r.slot := store.slot } } } // File @openzeppelin/contracts/utils/[email protected] // Original license: SPDX_License_Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (utils/ShortStrings.sol) pragma solidity ^0.8.8; // | string | 0xAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA | // | length | 0x BB | type ShortString is bytes32; /** * @dev This library provides functions to convert short memory strings * into a `ShortString` type that can be used as an immutable variable. * * Strings of arbitrary length can be optimized using this library if * they are short enough (up to 31 bytes) by packing them with their * length (1 byte) in a single EVM word (32 bytes). Additionally, a * fallback mechanism can be used for every other case. * * Usage example: * * ```solidity * contract Named { * using ShortStrings for *; * * ShortString private immutable _name; * string private _nameFallback; * * constructor(string memory contractName) { * _name = contractName.toShortStringWithFallback(_nameFallback); * } * * function name() external view returns (string memory) { * return _name.toStringWithFallback(_nameFallback); * } * } * ``` */ library ShortStrings { // Used as an identifier for strings longer than 31 bytes. bytes32 private constant _FALLBACK_SENTINEL = 0x00000000000000000000000000000000000000000000000000000000000000FF; error StringTooLong(string str); error InvalidShortString(); /** * @dev Encode a string of at most 31 chars into a `ShortString`. * * This will trigger a `StringTooLong` error is the input string is too long. */ function toShortString( string memory str ) internal pure returns (ShortString) { bytes memory bstr = bytes(str); if (bstr.length > 31) { revert StringTooLong(str); } return ShortString.wrap(bytes32(uint256(bytes32(bstr)) | bstr.length)); } /** * @dev Decode a `ShortString` back to a "normal" string. */ function toString(ShortString sstr) internal pure returns (string memory) { uint256 len = byteLength(sstr); // using `new string(len)` would work locally but is not memory safe. string memory str = new string(32); /// @solidity memory-safe-assembly assembly { mstore(str, len) mstore(add(str, 0x20), sstr) } return str; } /** * @dev Return the length of a `ShortString`. */ function byteLength(ShortString sstr) internal pure returns (uint256) { uint256 result = uint256(ShortString.unwrap(sstr)) & 0xFF; if (result > 31) { revert InvalidShortString(); } return result; } /** * @dev Encode a string into a `ShortString`, or write it to storage if it is too long. */ function toShortStringWithFallback( string memory value, string storage store ) internal returns (ShortString) { if (bytes(value).length < 32) { return toShortString(value); } else { StorageSlot.getStringSlot(store).value = value; return ShortString.wrap(_FALLBACK_SENTINEL); } } /** * @dev Decode a string that was encoded to `ShortString` or written to storage using {setWithFallback}. */ function toStringWithFallback( ShortString value, string storage store ) internal pure returns (string memory) { if (ShortString.unwrap(value) != _FALLBACK_SENTINEL) { return toString(value); } else { return store; } } /** * @dev Return the length of a string that was encoded to `ShortString` or written to storage using {setWithFallback}. * * WARNING: This will return the "byte length" of the string. This may not reflect the actual length in terms of * actual characters as the UTF-8 encoding of a single character can span over multiple bytes. */ function byteLengthWithFallback( ShortString value, string storage store ) internal view returns (uint256) { if (ShortString.unwrap(value) != _FALLBACK_SENTINEL) { return byteLength(value); } else { return bytes(store).length; } } } // File @openzeppelin/contracts/utils/cryptography/[email protected] // Original license: SPDX_License_Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (utils/cryptography/EIP712.sol) pragma solidity ^0.8.8; /** * @dev https://eips.ethereum.org/EIPS/eip-712[EIP 712] is a standard for hashing and signing of typed structured data. * * The encoding specified in the EIP is very generic, and such a generic implementation in Solidity is not feasible, * thus this contract does not implement the encoding itself. Protocols need to implement the type-specific encoding * they need in their contracts using a combination of `abi.encode` and `keccak256`. * * This contract implements the EIP 712 domain separator ({_domainSeparatorV4}) that is used as part of the encoding * scheme, and the final step of the encoding to obtain the message digest that is then signed via ECDSA * ({_hashTypedDataV4}). * * The implementation of the domain separator was designed to be as efficient as possible while still properly updating * the chain id to protect against replay attacks on an eventual fork of the chain. * * NOTE: This contract implements the version of the encoding known as "v4", as implemented by the JSON RPC method * https://docs.metamask.io/guide/signing-data.html[`eth_signTypedDataV4` in MetaMask]. * * NOTE: In the upgradeable version of this contract, the cached values will correspond to the address, and the domain * separator of the implementation contract. This will cause the `_domainSeparatorV4` function to always rebuild the * separator from the immutable values, which is cheaper than accessing a cached version in cold storage. * * _Available since v3.4._ * * @custom:oz-upgrades-unsafe-allow state-variable-immutable state-variable-assignment */ abstract contract EIP712 is IERC5267 { using ShortStrings for *; bytes32 private constant _TYPE_HASH = keccak256( "EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)" ); // Cache the domain separator as an immutable value, but also store the chain id that it corresponds to, in order to // invalidate the cached domain separator if the chain id changes. bytes32 private immutable _cachedDomainSeparator; uint256 private immutable _cachedChainId; address private immutable _cachedThis; bytes32 private immutable _hashedName; bytes32 private immutable _hashedVersion; ShortString private immutable _name; ShortString private immutable _version; string private _nameFallback; string private _versionFallback; /** * @dev Initializes the domain separator and parameter caches. * * The meaning of `name` and `version` is specified in * https://eips.ethereum.org/EIPS/eip-712#definition-of-domainseparator[EIP 712]: * * - `name`: the user readable name of the signing domain, i.e. the name of the DApp or the protocol. * - `version`: the current major version of the signing domain. * * NOTE: These parameters cannot be changed except through a xref:learn::upgrading-smart-contracts.adoc[smart * contract upgrade]. */ constructor(string memory name, string memory version) { _name = name.toShortStringWithFallback(_nameFallback); _version = version.toShortStringWithFallback(_versionFallback); _hashedName = keccak256(bytes(name)); _hashedVersion = keccak256(bytes(version)); _cachedChainId = block.chainid; _cachedDomainSeparator = _buildDomainSeparator(); _cachedThis = address(this); } /** * @dev Returns the domain separator for the current chain. */ function _domainSeparatorV4() internal view returns (bytes32) { if (address(this) == _cachedThis && block.chainid == _cachedChainId) { return _cachedDomainSeparator; } else { return _buildDomainSeparator(); } } function _buildDomainSeparator() private view returns (bytes32) { return keccak256( abi.encode( _TYPE_HASH, _hashedName, _hashedVersion, block.chainid, address(this) ) ); } /** * @dev Given an already https://eips.ethereum.org/EIPS/eip-712#definition-of-hashstruct[hashed struct], this * function returns the hash of the fully encoded EIP712 message for this domain. * * This hash can be used together with {ECDSA-recover} to obtain the signer of a message. For example: * * ```solidity * bytes32 digest = _hashTypedDataV4(keccak256(abi.encode( * keccak256("Mail(address to,string contents)"), * mailTo, * keccak256(bytes(mailContents)) * ))); * address signer = ECDSA.recover(digest, signature); * ``` */ function _hashTypedDataV4( bytes32 structHash ) internal view virtual returns (bytes32) { return ECDSA.toTypedDataHash(_domainSeparatorV4(), structHash); } /** * @dev See {EIP-5267}. * * _Available since v4.9._ */ function eip712Domain() public view virtual override returns ( bytes1 fields, string memory name, string memory version, uint256 chainId, address verifyingContract, bytes32 salt, uint256[] memory extensions ) { return ( hex"0f", // 01111 _name.toStringWithFallback(_nameFallback), _version.toStringWithFallback(_versionFallback), block.chainid, address(this), bytes32(0), new uint256[](0) ); } } // File @openzeppelin/contracts/utils/cryptography/[email protected] // Original license: SPDX_License_Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (utils/cryptography/draft-EIP712.sol) pragma solidity ^0.8.0; // EIP-712 is Final as of 2022-08-11. This file is deprecated. // File @openzeppelin/contracts/utils/math/[email protected] // Original license: SPDX_License_Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (utils/math/SafeMath.sol) pragma solidity ^0.8.0; // CAUTION // This version of SafeMath should only be used with Solidity 0.8 or later, // because it relies on the compiler's built in overflow checks. /** * @dev Wrappers over Solidity's arithmetic operations. * * NOTE: `SafeMath` is generally not needed starting with Solidity 0.8, since the compiler * now has built in overflow checking. */ library SafeMath { /** * @dev Returns the addition of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryAdd( uint256 a, uint256 b ) internal pure returns (bool, uint256) { unchecked { uint256 c = a + b; if (c < a) return (false, 0); return (true, c); } } /** * @dev Returns the subtraction of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function trySub( uint256 a, uint256 b ) internal pure returns (bool, uint256) { unchecked { if (b > a) return (false, 0); return (true, a - b); } } /** * @dev Returns the multiplication of two unsigned integers, with an overflow flag. * * _Available since v3.4._ */ function tryMul( uint256 a, uint256 b ) internal pure returns (bool, uint256) { unchecked { // 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-contracts/pull/522 if (a == 0) return (true, 0); uint256 c = a * b; if (c / a != b) return (false, 0); return (true, c); } } /** * @dev Returns the division of two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryDiv( uint256 a, uint256 b ) internal pure returns (bool, uint256) { unchecked { if (b == 0) return (false, 0); return (true, a / b); } } /** * @dev Returns the remainder of dividing two unsigned integers, with a division by zero flag. * * _Available since v3.4._ */ function tryMod( uint256 a, uint256 b ) internal pure returns (bool, uint256) { unchecked { if (b == 0) return (false, 0); return (true, a % b); } } /** * @dev Returns the addition of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `+` operator. * * Requirements: * * - Addition cannot overflow. */ function add(uint256 a, uint256 b) internal pure returns (uint256) { return a + b; } /** * @dev Returns the subtraction of two unsigned integers, reverting on * overflow (when the result is negative). * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub(uint256 a, uint256 b) internal pure returns (uint256) { return a - b; } /** * @dev Returns the multiplication of two unsigned integers, reverting on * overflow. * * Counterpart to Solidity's `*` operator. * * Requirements: * * - Multiplication cannot overflow. */ function mul(uint256 a, uint256 b) internal pure returns (uint256) { return a * b; } /** * @dev Returns the integer division of two unsigned integers, reverting on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. * * Requirements: * * - The divisor cannot be zero. */ function div(uint256 a, uint256 b) internal pure returns (uint256) { return a / b; } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting when dividing by zero. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod(uint256 a, uint256 b) internal pure returns (uint256) { return a % b; } /** * @dev Returns the subtraction of two unsigned integers, reverting with custom message on * overflow (when the result is negative). * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {trySub}. * * Counterpart to Solidity's `-` operator. * * Requirements: * * - Subtraction cannot overflow. */ function sub( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { unchecked { require(b <= a, errorMessage); return a - b; } } /** * @dev Returns the integer division of two unsigned integers, reverting with custom message on * division by zero. The result is rounded towards zero. * * Counterpart to Solidity's `/` operator. Note: this function uses a * `revert` opcode (which leaves remaining gas untouched) while Solidity * uses an invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function div( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { unchecked { require(b > 0, errorMessage); return a / b; } } /** * @dev Returns the remainder of dividing two unsigned integers. (unsigned integer modulo), * reverting with custom message when dividing by zero. * * CAUTION: This function is deprecated because it requires allocating memory for the error * message unnecessarily. For custom revert reasons use {tryMod}. * * Counterpart to Solidity's `%` operator. This function uses a `revert` * opcode (which leaves remaining gas untouched) while Solidity uses an * invalid opcode to revert (consuming all remaining gas). * * Requirements: * * - The divisor cannot be zero. */ function mod( uint256 a, uint256 b, string memory errorMessage ) internal pure returns (uint256) { unchecked { require(b > 0, errorMessage); return a % b; } } } // File contracts/interfaces/dex/IUniswapRouter.sol // Original license: SPDX_License_Identifier: MIT pragma solidity ^0.8.8; /// @title Uniswap Router interface /// @author Masa Finance /// @notice Interface of the Uniswap Router contract /// @dev This interface is used to interact with the Uniswap Router contract, /// and gets the most important functions of the contract. It's based on /// https://github.com/Uniswap/v2-periphery/blob/master/contracts/interfaces/IUniswapV2Router01.sol interface IUniswapRouter { function swapExactTokensForTokens( uint256 amountIn, uint256 amountOutMin, address[] calldata path, address to, uint256 deadline ) external returns (uint256[] memory amounts); function swapExactETHForTokens( uint256 amountOutMin, address[] calldata path, address to, uint256 deadline ) external payable returns (uint256[] memory amounts); function swapExactTokensForETH( uint256 amountIn, uint256 amountOutMin, address[] calldata path, address to, uint256 deadline ) external returns (uint256[] memory amounts); function getAmountsOut( uint256 amountIn, address[] calldata path ) external view returns (uint256[] memory amounts); function getAmountsIn( uint256 amountOut, address[] calldata path ) external view returns (uint256[] memory amounts); } // File contracts/libraries/Errors.sol // Original license: SPDX_License_Identifier: MIT pragma solidity ^0.8.8; error AddressDoesNotHaveIdentity(address to); error AlreadyAdded(); error AuthorityNotExists(address authority); error CallerNotOwner(address caller); error CallerNotReader(address caller); error CreditScoreAlreadyCreated(address to); error IdentityAlreadyCreated(address to); error IdentityOwnerIsReader(uint256 readerIdentityId); error InsufficientEthAmount(uint256 amount); error IdentityOwnerNotTokenOwner(uint256 tokenId, uint256 ownerIdentityId); error InvalidPaymentMethod(address paymentMethod); error InvalidSignature(); error InvalidSignatureDate(uint256 signatureDate); error InvalidToken(address token); error InvalidTokenURI(string tokenURI); error LinkAlreadyExists( address token, uint256 tokenId, uint256 readerIdentityId, uint256 signatureDate ); error LinkAlreadyRevoked(); error LinkDoesNotExist(); error NameAlreadyExists(string name); error NameNotFound(string name); error NameRegisteredByOtherAccount(string name, uint256 tokenId); error NotAuthorized(address signer); error NonExistingErc20Token(address erc20token); error NotLinkedToAnIdentitySBT(); error PaymentParamsNotSet(); error ProtocolFeeReceiverNotSet(); error RefundFailed(); error SameValue(); error SBTAlreadyLinked(address token); error SoulNameContractNotSet(); error SoulNameNotExist(); error SoulNameNotRegistered(address token); error TokenNotFound(uint256 tokenId); error TransferFailed(); error URIAlreadyExists(string tokenURI); error UserMustHaveProtocolOrProjectAdminRole(); error ValidPeriodExpired(uint256 expirationDate); error ZeroAddress(); error ZeroLengthName(string name); error ZeroYearsPeriod(uint256 yearsPeriod); // File contracts/dex/PaymentGateway.sol // Original license: SPDX_License_Identifier: MIT pragma solidity ^0.8.8; /// @title Pay using a Decentralized automated market maker (AMM) when needed /// @author Masa Finance /// @notice Smart contract to call a Dex AMM smart contract to pay to a project fee receiver /// wallet recipient /// @dev This smart contract will call the Uniswap Router interface, based on /// https://github.com/Uniswap/v2-periphery/blob/master/contracts/interfaces/IUniswapV2Router01.sol abstract contract PaymentGateway is AccessControl { using SafeERC20 for IERC20; using SafeMath for uint256; bytes32 public constant PROJECT_ADMIN_ROLE = keccak256("PROJECT_ADMIN_ROLE"); struct PaymentParams { address swapRouter; // Swap router address address wrappedNativeToken; // Wrapped native token address address stableCoin; // Stable coin to pay the fee in (USDC) address masaToken; // Utility token to pay the fee in (MASA) address projectFeeReceiver; // Wallet that will receive the project fee address protocolFeeReceiver; // Wallet that will receive the protocol fee uint256 protocolFeeAmount; // Protocol fee amount in USD uint256 protocolFeePercent; // Protocol fee amount added to the project fee uint256 protocolFeePercentSub; // Protocol fee amount substracted from the project fee } /* ========== STATE VARIABLES =========================================== */ address public swapRouter; address public wrappedNativeToken; address public stableCoin; // USDC. It also needs to be enabled as payment method, if we want to pay in USDC address public masaToken; // MASA. It also needs to be enabled as payment method, if we want to pay in MASA // enabled payment methods: ETH and ERC20 tokens mapping(address => bool) public enabledPaymentMethod; address[] public enabledPaymentMethods; address public projectFeeReceiver; address public protocolFeeReceiver; uint256 public protocolFeeAmount; uint256 public protocolFeePercent; // Protocol fee amount added to the project fee uint256 public protocolFeePercentSub; // Protocol fee amount substracted from the project fee /* ========== INITIALIZE ================================================ */ /// @notice Creates a new Dex AMM /// @dev Creates a new Decentralized automated market maker (AMM) smart contract, // that will call the Uniswap Router interface /// @param admin Administrator of the smart contract /// @param paymentParams Payment params constructor(address admin, PaymentParams memory paymentParams) { _grantRole(DEFAULT_ADMIN_ROLE, admin); swapRouter = paymentParams.swapRouter; wrappedNativeToken = paymentParams.wrappedNativeToken; stableCoin = paymentParams.stableCoin; masaToken = paymentParams.masaToken; projectFeeReceiver = paymentParams.projectFeeReceiver; protocolFeeReceiver = paymentParams.protocolFeeReceiver; protocolFeeAmount = paymentParams.protocolFeeAmount; protocolFeePercent = paymentParams.protocolFeePercent; protocolFeePercentSub = paymentParams.protocolFeePercentSub; } /* ========== RESTRICTED FUNCTIONS ====================================== */ /// @notice Sets the swap router address /// @dev The caller must have the admin role to call this function /// @param _swapRouter New swap router address function setSwapRouter( address _swapRouter ) external onlyRole(DEFAULT_ADMIN_ROLE) { if (swapRouter == _swapRouter) revert SameValue(); swapRouter = _swapRouter; } /// @notice Sets the wrapped native token address /// @dev The caller must have the admin role to call this function /// @param _wrappedNativeToken New wrapped native token address function setWrappedNativeToken( address _wrappedNativeToken ) external onlyRole(DEFAULT_ADMIN_ROLE) { if (wrappedNativeToken == _wrappedNativeToken) revert SameValue(); wrappedNativeToken = _wrappedNativeToken; } /// @notice Sets the stable coin to pay the fee in (USDC) /// @dev The caller must have the admin role to call this function /// @param _stableCoin New stable coin to pay the fee in function setStableCoin( address _stableCoin ) external onlyRole(DEFAULT_ADMIN_ROLE) { if (stableCoin == _stableCoin) revert SameValue(); stableCoin = _stableCoin; } /// @notice Sets the utility token to pay the fee in (MASA) /// @dev The caller must have the admin role to call this function /// It can be set to address(0) to disable paying in MASA /// @param _masaToken New utility token to pay the fee in function setMasaToken( address _masaToken ) external onlyRole(DEFAULT_ADMIN_ROLE) { if (masaToken == _masaToken) revert SameValue(); masaToken = _masaToken; } /// @notice Adds a new token as a valid payment method /// @dev The caller must have the admin role to call this function /// @param _paymentMethod New token to add function enablePaymentMethod( address _paymentMethod ) external onlyRole(DEFAULT_ADMIN_ROLE) { if (enabledPaymentMethod[_paymentMethod]) revert AlreadyAdded(); enabledPaymentMethod[_paymentMethod] = true; enabledPaymentMethods.push(_paymentMethod); } /// @notice Removes a token as a valid payment method /// @dev The caller must have the admin role to call this function /// @param _paymentMethod Token to remove function disablePaymentMethod( address _paymentMethod ) external onlyRole(DEFAULT_ADMIN_ROLE) { if (!enabledPaymentMethod[_paymentMethod]) revert NonExistingErc20Token(_paymentMethod); enabledPaymentMethod[_paymentMethod] = false; for (uint256 i = 0; i < enabledPaymentMethods.length; i++) { if (enabledPaymentMethods[i] == _paymentMethod) { enabledPaymentMethods[i] = enabledPaymentMethods[ enabledPaymentMethods.length - 1 ]; enabledPaymentMethods.pop(); break; } } } /// @notice Set the project fee receiver wallet /// @dev The caller must have the admin or project admin role to call this function /// @param _projectFeeReceiver New project fee receiver wallet function setProjectFeeReceiver(address _projectFeeReceiver) external { if ( !hasRole(DEFAULT_ADMIN_ROLE, _msgSender()) && !hasRole(PROJECT_ADMIN_ROLE, _msgSender()) ) revert UserMustHaveProtocolOrProjectAdminRole(); if (_projectFeeReceiver == projectFeeReceiver) revert SameValue(); projectFeeReceiver = _projectFeeReceiver; } /// @notice Set the protocol fee wallet /// @dev The caller must have the admin role to call this function /// @param _protocolFeeReceiver New protocol fee wallet function setProtocolFeeReceiver( address _protocolFeeReceiver ) external onlyRole(DEFAULT_ADMIN_ROLE) { if (_protocolFeeReceiver == protocolFeeReceiver) revert SameValue(); protocolFeeReceiver = _protocolFeeReceiver; } /// @notice Set the protocol fee amount /// @dev The caller must have the admin role to call this function /// @param _protocolFeeAmount New protocol fee amount function setProtocolFeeAmount( uint256 _protocolFeeAmount ) external onlyRole(DEFAULT_ADMIN_ROLE) { if (_protocolFeeAmount == protocolFeeAmount) revert SameValue(); protocolFeeAmount = _protocolFeeAmount; } /// @notice Set the protocol fee percent added to the project fee /// @dev The caller must have the admin role to call this function /// @param _protocolFeePercent New protocol fee percent added to the project fee function setProtocolFeePercent( uint256 _protocolFeePercent ) external onlyRole(DEFAULT_ADMIN_ROLE) { if (_protocolFeePercent == protocolFeePercent) revert SameValue(); protocolFeePercent = _protocolFeePercent; } /// @notice Set the protocol fee percent substracted from the amount /// @dev The caller must have the admin role to call this function /// @param _protocolFeePercentSub New protocol fee percent substracted from the amount function setProtocolFeePercentSub( uint256 _protocolFeePercentSub ) external onlyRole(DEFAULT_ADMIN_ROLE) { if (_protocolFeePercentSub == protocolFeePercentSub) revert SameValue(); protocolFeePercentSub = _protocolFeePercentSub; } /* ========== MUTATIVE FUNCTIONS ======================================== */ /* ========== VIEWS ===================================================== */ /// @notice Returns all available payment methods /// @dev Returns the address of all available payment methods /// @return Array of all enabled payment methods function getEnabledPaymentMethods() external view returns (address[] memory) { return enabledPaymentMethods; } /// @notice Calculates the protocol fee added to the project fee /// @dev This method will calculate the protocol fee based on the payment method /// @param paymentMethod Address of token that user want to pay /// @param amount Price to be paid in the specified payment method function getProtocolFee( address paymentMethod, uint256 amount ) external view returns (uint256) { return _getProtocolFee(paymentMethod, amount); } /// @notice Calculates the protocol fee substracted from the amount /// @dev This method will calculate the protocol fee based on the payment method /// @param amount Price to be paid in the specified payment method function getProtocolFeeSub(uint256 amount) external view returns (uint256) { return _getProtocolFeeSub(amount); } /* ========== PRIVATE FUNCTIONS ========================================= */ /// @notice Converts an amount from a stable coin to a payment method amount /// @dev This method will perform the swap between the stable coin and the /// payment method, and return the amount of the payment method, /// performing the swap if necessary /// @param paymentMethod Address of token that user want to pay /// @param amount Price to be converted in the specified payment method function _convertFromStableCoin( address paymentMethod, uint256 amount ) internal view paymentParamsAlreadySet(amount) returns (uint256) { if (!enabledPaymentMethod[paymentMethod] || paymentMethod == stableCoin) revert InvalidToken(paymentMethod); if (amount == 0) return 0; if (paymentMethod == address(0)) { return _estimateSwapAmount(wrappedNativeToken, stableCoin, amount); } else { return _estimateSwapAmount(paymentMethod, stableCoin, amount); } } /// @notice Calculates the protocol fee added to the project fee /// @dev This method will calculate the protocol fee based on the payment method /// @param paymentMethod Address of token that user want to pay /// @param amount Price to be paid in the specified payment method function _getProtocolFee( address paymentMethod, uint256 amount ) internal view returns (uint256) { uint256 protocolFee = 0; if (protocolFeeAmount > 0) { if (paymentMethod == stableCoin) { protocolFee = protocolFeeAmount; } else { protocolFee = _convertFromStableCoin( paymentMethod, protocolFeeAmount ); } } if (protocolFeePercent > 0) { protocolFee = protocolFee.add( amount.mul(protocolFeePercent).div(100) ); } return protocolFee; } /// @notice Calculates the protocol fee substracted from the amount /// @dev This method will calculate the protocol fee based on the payment method /// @param amount Price to be paid in the specified payment method function _getProtocolFeeSub( uint256 amount ) internal view returns (uint256) { if (protocolFeePercentSub > 0) { return amount.mul(protocolFeePercentSub).div(100); } else { return 0; } } /// @notice Performs the payment in any payment method /// @dev This method will transfer the funds to the project fee receiver wallet, performing /// the swap if necessary, and transfer the protocol fee to the protocol fee wallet /// @param paymentMethod Address of token that user want to pay /// @param amount Price to be paid in the specified payment method /// @param protocolFee Protocol fee to be paid in the specified payment method function _pay( address paymentMethod, uint256 amount, uint256 protocolFee ) internal paymentParamsAlreadySet(amount.add(protocolFee)) { if (amount == 0 && protocolFee == 0) return; uint256 protocolFeeSub = _getProtocolFeeSub(amount); if ( (protocolFee > 0 || protocolFeeSub > 0) && protocolFeeReceiver == address(0) ) revert ProtocolFeeReceiverNotSet(); if (!enabledPaymentMethod[paymentMethod]) revert InvalidPaymentMethod(paymentMethod); if (paymentMethod == address(0)) { // ETH if (msg.value < amount.add(protocolFee)) revert InsufficientEthAmount(amount.add(protocolFee)); if (amount.sub(protocolFeeSub) > 0) { (bool success, ) = payable(projectFeeReceiver).call{ value: amount.sub(protocolFeeSub) }(""); if (!success) revert TransferFailed(); } if (protocolFee > 0) { (bool success, ) = payable(protocolFeeReceiver).call{ value: protocolFee }(""); if (!success) revert TransferFailed(); } if (protocolFeeSub > 0) { (bool success, ) = payable(protocolFeeReceiver).call{ value: protocolFeeSub }(""); if (!success) revert TransferFailed(); } if (msg.value > amount.add(protocolFee)) { // return diff uint256 refund = msg.value.sub(amount.add(protocolFee)); (bool success, ) = payable(msg.sender).call{value: refund}(""); if (!success) revert RefundFailed(); } } else { // ERC20 token, including MASA and USDC if (amount.sub(protocolFeeSub) > 0) { IERC20(paymentMethod).safeTransferFrom( msg.sender, projectFeeReceiver, amount.sub(protocolFeeSub) ); } if (protocolFee > 0) { IERC20(paymentMethod).safeTransferFrom( msg.sender, protocolFeeReceiver, protocolFee ); } if (protocolFeeSub > 0) { IERC20(paymentMethod).safeTransferFrom( msg.sender, protocolFeeReceiver, protocolFeeSub ); } } } function _estimateSwapAmount( address _fromToken, address _toToken, uint256 _amountOut ) private view returns (uint256) { uint256[] memory amounts; address[] memory path; path = _getPathFromTokenToToken(_fromToken, _toToken); amounts = IUniswapRouter(swapRouter).getAmountsIn(_amountOut, path); return amounts[0]; } function _getPathFromTokenToToken( address fromToken, address toToken ) private view returns (address[] memory) { if (fromToken == wrappedNativeToken || toToken == wrappedNativeToken) { address[] memory path = new address[](2); path[0] = fromToken == wrappedNativeToken ? wrappedNativeToken : fromToken; path[1] = toToken == wrappedNativeToken ? wrappedNativeToken : toToken; return path; } else { address[] memory path = new address[](3); path[0] = fromToken; path[1] = wrappedNativeToken; path[2] = toToken; return path; } } /* ========== MODIFIERS ================================================= */ modifier paymentParamsAlreadySet(uint256 amount) { if (amount > 0 && swapRouter == address(0)) revert PaymentParamsNotSet(); if (amount > 0 && wrappedNativeToken == address(0)) revert PaymentParamsNotSet(); if (amount > 0 && stableCoin == address(0)) revert PaymentParamsNotSet(); if (amount > 0 && projectFeeReceiver == address(0)) revert PaymentParamsNotSet(); _; } /* ========== EVENTS ==================================================== */ } // File contracts/tokens/SBT/ISBT.sol // Original license: SPDX_License_Identifier: MIT pragma solidity ^0.8.8; interface ISBT is IERC165 { /// @dev This emits when an SBT is newly minted. /// This event emits when SBTs are created event Mint(address indexed _owner, uint256 indexed _tokenId); /// @dev This emits when an SBT is burned /// This event emits when SBTs are destroyed event Burn(address indexed _owner, uint256 indexed _tokenId); /// @notice Count all SBTs assigned to an owner /// @dev SBTs assigned to the zero address are considered invalid, and this /// function throws for queries about the zero address. /// @param _owner An address for whom to query the balance /// @return The number of SBTs owned by `_owner`, possibly zero function balanceOf(address _owner) external view returns (uint256); /// @notice Find the owner of an SBT /// @dev SBTs assigned to zero address are considered invalid, and queries /// about them do throw. /// @param _tokenId The identifier for an SBT /// @return The address of the owner of the SBT function ownerOf(uint256 _tokenId) external view returns (address); } // File contracts/interfaces/ILinkableSBT.sol // Original license: SPDX_License_Identifier: MIT pragma solidity ^0.8.8; interface ILinkableSBT is ISBT { function addLinkPrice() external view returns (uint256); function addLinkPriceMASA() external view returns (uint256); function queryLinkPrice() external view returns (uint256); function queryLinkPriceMASA() external view returns (uint256); } // File contracts/interfaces/ISoulName.sol // Original license: SPDX_License_Identifier: MIT pragma solidity ^0.8.8; interface ISoulName { function mint( address to, string memory name, uint256 yearsPeriod, string memory _tokenURI ) external returns (uint256); function getExtension() external view returns (string memory); function isAvailable( string memory name ) external view returns (bool available); function tokenData( uint256 tokenId ) external view returns (string memory name, uint256 expirationDate); function getTokenData( string memory name ) external view returns ( string memory sbtName, bool linked, uint256 identityId, uint256 tokenId, uint256 expirationDate, bool active ); function getTokenId(string memory name) external view returns (uint256); function getSoulNames( address owner ) external view returns (string[] memory sbtNames); function getSoulNames( uint256 identityId ) external view returns (string[] memory sbtNames); } // File contracts/interfaces/ISoulboundIdentity.sol // Original license: SPDX_License_Identifier: MIT pragma solidity ^0.8.8; interface ISoulboundIdentity is ISBT { function mint(address to) external payable returns (uint256); function mint( address paymentMethod, address to ) external payable returns (uint256); function mintIdentityWithName( address to, string memory name, uint256 yearsPeriod, string memory _tokenURI ) external payable returns (uint256); function mintIdentityWithName( address paymentMethod, address to, string memory name, uint256 yearsPeriod, string memory _tokenURI ) external payable returns (uint256); function getSoulName() external view returns (ISoulName); function tokenOfOwner(address owner) external view returns (uint256); } // File @openzeppelin/contracts/security/[email protected] // Original license: SPDX_License_Identifier: MIT // OpenZeppelin Contracts (last updated v4.9.0) (security/ReentrancyGuard.sol) pragma solidity ^0.8.0; /** * @dev Contract module that helps prevent reentrant calls to a function. * * Inheriting from `ReentrancyGuard` will make the {nonReentrant} modifier * available, which can be applied to functions to make sure there are no nested * (reentrant) calls to them. * * Note that because there is a single `nonReentrant` guard, functions marked as * `nonReentrant` may not call one another. This can be worked around by making * those functions `private`, and then adding `external` `nonReentrant` entry * points to them. * * TIP: If you would like to learn more about reentrancy and alternative ways * to protect against it, check out our blog post * https://blog.openzeppelin.com/reentrancy-after-istanbul/[Reentrancy After Istanbul]. */ abstract contract ReentrancyGuard { // Booleans are more expensive than uint256 or any type that takes up a full // word because each write operation emits an extra SLOAD to first read the // slot's contents, replace the bits taken up by the boolean, and then write // back. This is the compiler's defense against contract upgrades and // pointer aliasing, and it cannot be disabled. // The values being non-zero value makes deployment a bit more expensive, // but in exchange the refund on every call to nonReentrant will be lower in // amount. Since refunds are capped to a percentage of the total // transaction's gas, it is best to keep them low in cases like this one, to // increase the likelihood of the full refund coming into effect. uint256 private constant _NOT_ENTERED = 1; uint256 private constant _ENTERED = 2; uint256 private _status; constructor() { _status = _NOT_ENTERED; } /** * @dev Prevents a contract from calling itself, directly or indirectly. * Calling a `nonReentrant` function from another `nonReentrant` * function is not supported. It is possible to prevent this from happening * by making the `nonReentrant` function external, and making it call a * `private` function that does the actual work. */ modifier nonReentrant() { _nonReentrantBefore(); _; _nonReentrantAfter(); } function _nonReentrantBefore() private { // On the first call to nonReentrant, _status will be _NOT_ENTERED require(_status != _ENTERED, "ReentrancyGuard: reentrant call"); // Any calls to nonReentrant after this point will fail _status = _ENTERED; } function _nonReentrantAfter() private { // By storing the original value once again, a refund is triggered (see // https://eips.ethereum.org/EIPS/eip-2200) _status = _NOT_ENTERED; } /** * @dev Returns true if the reentrancy guard is currently set to "entered", which indicates there is a * `nonReentrant` function in the call stack. */ function _reentrancyGuardEntered() internal view returns (bool) { return _status == _ENTERED; } } // File @openzeppelin/contracts/utils/[email protected] // Original license: SPDX_License_Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Counters.sol) pragma solidity ^0.8.0; /** * @title Counters * @author Matt Condon (@shrugs) * @dev Provides counters that can only be incremented, decremented or reset. This can be used e.g. to track the number * of elements in a mapping, issuing ERC721 ids, or counting request ids. * * Include with `using Counters for Counters.Counter;` */ library Counters { struct Counter { // This variable should never be directly accessed by users of the library: interactions must be restricted to // the library's function. As of Solidity v0.5.2, this cannot be enforced, though there is a proposal to add // this feature: see https://github.com/ethereum/solidity/issues/4637 uint256 _value; // default: 0 } function current(Counter storage counter) internal view returns (uint256) { return counter._value; } function increment(Counter storage counter) internal { unchecked { counter._value += 1; } } function decrement(Counter storage counter) internal { uint256 value = counter._value; require(value > 0, "Counter: decrement overflow"); unchecked { counter._value = value - 1; } } function reset(Counter storage counter) internal { counter._value = 0; } } // File contracts/tokens/SBT/extensions/ISBTMetadata.sol // Original license: SPDX_License_Identifier: MIT pragma solidity ^0.8.8; /** * @title SBT Soulbound Token Standard, optional metadata extension */ interface ISBTMetadata is ISBT { /** * @dev Returns the token collection name. */ function name() external view returns (string memory); /** * @dev Returns the token collection symbol. */ function symbol() external view returns (string memory); /** * @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token. */ function tokenURI(uint256 tokenId) external view returns (string memory); } // File contracts/tokens/SBT/SBT.sol // Original license: SPDX_License_Identifier: MIT pragma solidity ^0.8.8; /// @title SBT /// @author Masa Finance /// @notice Soulbound token is an NFT token that is not transferable. contract SBT is Context, ERC165, ISBT, ISBTMetadata { using Strings for uint256; // Token name string private _name; // Token symbol string private _symbol; // Mapping from token ID to owner address mapping(uint256 => address) private _owners; // Mapping owner address to token count mapping(address => uint256) private _balances; /** * @dev Initializes the contract by setting a `name` and a `symbol` to the token collection. */ constructor(string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface( bytes4 interfaceId ) public view virtual override(ERC165, IERC165) returns (bool) { return interfaceId == type(ISBT).interfaceId || interfaceId == type(ISBTMetadata).interfaceId || super.supportsInterface(interfaceId); } /** * @dev See {ISBT-balanceOf}. */ function balanceOf( address owner ) public view virtual override returns (uint256) { require(owner != address(0), "SBT: address zero is not a valid owner"); return _balances[owner]; } /** * @dev See {ISBT-ownerOf}. */ function ownerOf( uint256 tokenId ) public view virtual override returns (address) { address owner = _owners[tokenId]; require(owner != address(0), "SBT: invalid token ID"); return owner; } /** * @dev See {ISBTMetadata-name}. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev See {ISBTMetadata-symbol}. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev See {ISBTMetadata-tokenURI}. */ function tokenURI( uint256 tokenId ) public view virtual override returns (string memory) { _requireMinted(tokenId); string memory baseURI = _baseURI(); return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, tokenId.toString())) : ""; } /** * @dev Base URI for computing {tokenURI}. If set, the resulting URI for each * token will be the concatenation of the `baseURI` and the `tokenId`. Empty * by default, can be overridden in child contracts. */ function _baseURI() internal view virtual returns (string memory) { return ""; } /** * @dev Returns whether `spender` is allowed to manage `tokenId`. * * Requirements: * * - `tokenId` must exist. */ function _isOwner( address spender, uint256 tokenId ) internal view virtual returns (bool) { address owner = SBT.ownerOf(tokenId); return (spender == owner); } /** * @dev Returns whether `tokenId` exists. * * Tokens can be managed by their owner. * * Tokens start existing when they are minted (`_mint`), * and stop existing when they are burned (`_burn`). */ function _exists(uint256 tokenId) internal view virtual returns (bool) { return _owners[tokenId] != address(0); } /** * @dev Mints `tokenId` and transfers it to `to`. * * WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible * * Requirements: * * - `tokenId` must not exist. * - `to` cannot be the zero address. * * Emits a {Mint} event. */ function _mint(address to, uint256 tokenId) internal virtual { require(to != address(0), "SBT: mint to the zero address"); require(!_exists(tokenId), "SBT: token already minted"); _beforeTokenTransfer(address(0), to, tokenId); _balances[to] += 1; _owners[tokenId] = to; emit Mint(to, tokenId); _afterTokenTransfer(address(0), to, tokenId); } /** * @dev Destroys `tokenId`. * * Requirements: * - `tokenId` must exist. * * Emits a {Burn} event. */ function _burn(uint256 tokenId) internal virtual { address owner = SBT.ownerOf(tokenId); _beforeTokenTransfer(owner, address(0), tokenId); _balances[owner] -= 1; delete _owners[tokenId]; emit Burn(owner, tokenId); _afterTokenTransfer(owner, address(0), tokenId); } /** * @dev Reverts if the `tokenId` has not been minted yet. */ function _requireMinted(uint256 tokenId) internal view virtual { require(_exists(tokenId), "SBT: invalid token ID"); } /** * @dev Hook that is called before any token minting/burning * * Calling conditions: * * - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be * transferred to `to`. * - When `from` is zero, `tokenId` will be minted for `to`. * - When `to` is zero, ``from``'s `tokenId` will be burned. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer(address, address, uint256) internal virtual {} /** * @dev Hook that is called after any minting/burning of tokens * * Calling conditions: * - when `from` and `to` are both non-zero. * - `from` and `to` are never both zero. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _afterTokenTransfer(address, address, uint256) internal virtual {} } // File contracts/tokens/SBT/extensions/SBTBurnable.sol // Original license: SPDX_License_Identifier: MIT pragma solidity ^0.8.8; /** * @title SBT Burnable Token * @dev SBT Token that can be burned (destroyed). */ abstract contract SBTBurnable is Context, SBT { /** * @dev Burns `tokenId`. See {SBT-_burn}. * * Requirements: * * - The caller must own `tokenId` or be an approved operator. */ function burn(uint256 tokenId) public virtual { //solhint-disable-next-line max-line-length require( _isOwner(_msgSender(), tokenId), "SBT: caller is not token owner" ); _burn(tokenId); } } // File contracts/tokens/SBT/extensions/ISBTEnumerable.sol // Original license: SPDX_License_Identifier: MIT pragma solidity ^0.8.8; /** * @title SBT Soulbound Token Standard, optional enumeration extension */ interface ISBTEnumerable is ISBT { /** * @dev Returns the total amount of tokens stored by the contract. */ function totalSupply() external view returns (uint256); /** * @dev Returns a token ID owned by `owner` at a given `index` of its token list. * Use along with {balanceOf} to enumerate all of ``owner``'s tokens. */ function tokenOfOwnerByIndex( address owner, uint256 index ) external view returns (uint256); /** * @dev Returns a token ID at a given `index` of all the tokens stored by the contract. * Use along with {totalSupply} to enumerate all tokens. */ function tokenByIndex(uint256 index) external view returns (uint256); } // File contracts/tokens/SBT/extensions/SBTEnumerable.sol // Original license: SPDX_License_Identifier: MIT pragma solidity ^0.8.8; /** * @dev This implements an optional extension of {SBT} defined in the EIP that adds * enumerability of all the token ids in the contract as well as all token ids owned by each * account. */ abstract contract SBTEnumerable is SBT, ISBTEnumerable { // Mapping from owner to list of owned token IDs mapping(address => mapping(uint256 => uint256)) private _ownedTokens; // Mapping from token ID to index of the owner tokens list mapping(uint256 => uint256) private _ownedTokensIndex; // Array with all token ids, used for enumeration uint256[] private _allTokens; // Mapping from token id to position in the allTokens array mapping(uint256 => uint256) private _allTokensIndex; /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface( bytes4 interfaceId ) public view virtual override(IERC165, SBT) returns (bool) { return interfaceId == type(ISBTEnumerable).interfaceId || super.supportsInterface(interfaceId); } /** * @dev See {ISBTEnumerable-tokenOfOwnerByIndex}. */ function tokenOfOwnerByIndex( address owner, uint256 index ) public view virtual override returns (uint256) { require( index < SBT.balanceOf(owner), "SBTEnumerable: owner index out of bounds" ); return _ownedTokens[owner][index]; } /** * @dev See {ISBTEnumerable-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _allTokens.length; } /** * @dev See {ISBTEnumerable-tokenByIndex}. */ function tokenByIndex( uint256 index ) public view virtual override returns (uint256) { require( index < SBTEnumerable.totalSupply(), "SBTEnumerable: global index out of bounds" ); return _allTokens[index]; } /** * @dev Hook that is called before any token transfer. This includes minting * and burning. * * Calling conditions: * * - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be * transferred to `to`. * - When `from` is zero, `tokenId` will be minted for `to`. * - When `to` is zero, ``from``'s `tokenId` will be burned. * - `from` cannot be the zero address. * - `to` cannot be the zero address. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer( address from, address to, uint256 tokenId ) internal virtual override { super._beforeTokenTransfer(from, to, tokenId); if (from == address(0)) { _addTokenToAllTokensEnumeration(tokenId); } else if (from != to) { _removeTokenFromOwnerEnumeration(from, tokenId); } if (to == address(0)) { _removeTokenFromAllTokensEnumeration(tokenId); } else if (to != from) { _addTokenToOwnerEnumeration(to, tokenId); } } /** * @dev Private function to add a token to this extension's ownership-tracking data structures. * @param to address representing the new owner of the given token ID * @param tokenId uint256 ID of the token to be added to the tokens list of the given address */ function _addTokenToOwnerEnumeration(address to, uint256 tokenId) private { uint256 length = SBT.balanceOf(to); _ownedTokens[to][length] = tokenId; _ownedTokensIndex[tokenId] = length; } /** * @dev Private function to add a token to this extension's token tracking data structures. * @param tokenId uint256 ID of the token to be added to the tokens list */ function _addTokenToAllTokensEnumeration(uint256 tokenId) private { _allTokensIndex[tokenId] = _allTokens.length; _allTokens.push(tokenId); } /** * @dev Private function to remove a token from this extension's ownership-tracking data structures. Note that * while the token is not assigned a new owner, the `_ownedTokensIndex` mapping is _not_ updated: this allows for * gas optimizations e.g. when performing a transfer operation (avoiding double writes). * This has O(1) time complexity, but alters the order of the _ownedTokens array. * @param from address representing the previous owner of the given token ID * @param tokenId uint256 ID of the token to be removed from the tokens list of the given address */ function _removeTokenFromOwnerEnumeration( address from, uint256 tokenId ) private { // To prevent a gap in from's tokens array, we store the last token in the index of the token to delete, and // then delete the last slot (swap and pop). uint256 lastTokenIndex = SBT.balanceOf(from) - 1; uint256 tokenIndex = _ownedTokensIndex[tokenId]; // When the token to delete is the last token, the swap operation is unnecessary if (tokenIndex != lastTokenIndex) { uint256 lastTokenId = _ownedTokens[from][lastTokenIndex]; _ownedTokens[from][tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token _ownedTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index } // This also deletes the contents at the last position of the array delete _ownedTokensIndex[tokenId]; delete _ownedTokens[from][lastTokenIndex]; } /** * @dev Private function to remove a token from this extension's token tracking data structures. * This has O(1) time complexity, but alters the order of the _allTokens array. * @param tokenId uint256 ID of the token to be removed from the tokens list */ function _removeTokenFromAllTokensEnumeration(uint256 tokenId) private { // To prevent a gap in the tokens array, we store the last token in the index of the token to delete, and // then delete the last slot (swap and pop). uint256 lastTokenIndex = _allTokens.length - 1; uint256 tokenIndex = _allTokensIndex[tokenId]; // When the token to delete is the last token, the swap operation is unnecessary. However, since this occurs so // rarely (when the last minted token is burnt) that we still do the swap here to avoid the gas cost of adding // an 'if' statement (like in _removeTokenFromOwnerEnumeration) uint256 lastTokenId = _allTokens[lastTokenIndex]; _allTokens[tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token _allTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index // This also deletes the contents at the last position of the array delete _allTokensIndex[tokenId]; _allTokens.pop(); } } // File contracts/tokens/MasaSBT.sol // Original license: SPDX_License_Identifier: MIT pragma solidity ^0.8.8; /// @title MasaSBT /// @author Masa Finance /// @notice Soulbound token. Non-fungible token that is not transferable. /// @dev Implementation of https://papers.ssrn.com/sol3/papers.cfm?abstract_id=4105763 Soulbound token. /// Adds a link to a SoulboundIdentity SC to let minting using the identityId /// Adds a payment gateway to let minting paying a fee abstract contract MasaSBT is PaymentGateway, SBT, SBTEnumerable, SBTBurnable, ILinkableSBT { /* ========== STATE VARIABLES =========================================== */ using Strings for uint256; string private _baseTokenURI; ISoulboundIdentity public soulboundIdentity; uint256 public mintPrice; // price in stable coin uint256 public mintPriceMASA; // price in MASA uint256 public override addLinkPrice; // price in stable coin uint256 public override addLinkPriceMASA; // price in MASA uint256 public override queryLinkPrice; // price in stable coin uint256 public override queryLinkPriceMASA; // price in MASA /* ========== INITIALIZE ================================================ */ /// @notice Creates a new soulbound token /// @dev Creates a new soulbound token /// @param admin Administrator of the smart contract /// @param name Name of the token /// @param symbol Symbol of the token /// @param baseTokenURI Base URI of the token /// @param _soulboundIdentity Address of the SoulboundIdentity contract /// @param paymentParams Payment gateway params constructor( address admin, string memory name, string memory symbol, string memory baseTokenURI, address _soulboundIdentity, PaymentParams memory paymentParams ) SBT(name, symbol) PaymentGateway(admin, paymentParams) { _grantRole(DEFAULT_ADMIN_ROLE, admin); _baseTokenURI = baseTokenURI; soulboundIdentity = ISoulboundIdentity(_soulboundIdentity); } /* ========== RESTRICTED FUNCTIONS ====================================== */ /// @notice Sets the price of minting in stable coin /// @dev The caller must have the admin or project admin role to call this function /// @param _mintPrice New price of minting in stable coin function setMintPrice(uint256 _mintPrice) external { if ( !hasRole(DEFAULT_ADMIN_ROLE, _msgSender()) && !hasRole(PROJECT_ADMIN_ROLE, _msgSender()) ) revert UserMustHaveProtocolOrProjectAdminRole(); if (mintPrice == _mintPrice) revert SameValue(); mintPrice = _mintPrice; } /// @notice Sets the price of minting in MASA /// @dev The caller must have the admin or project admin role to call this function /// @param _mintPriceMASA New price of minting in MASA function setMintPriceMASA(uint256 _mintPriceMASA) external { if ( !hasRole(DEFAULT_ADMIN_ROLE, _msgSender()) && !hasRole(PROJECT_ADMIN_ROLE, _msgSender()) ) revert UserMustHaveProtocolOrProjectAdminRole(); if (mintPriceMASA == _mintPriceMASA) revert SameValue(); mintPriceMASA = _mintPriceMASA; } /// @notice Sets the SoulboundIdentity contract address linked to this SBT /// @dev The caller must be the admin to call this function /// @param _soulboundIdentity Address of the SoulboundIdentity contract function setSoulboundIdentity( address _soulboundIdentity ) external onlyRole(DEFAULT_ADMIN_ROLE) { if (address(soulboundIdentity) == _soulboundIdentity) revert SameValue(); soulboundIdentity = ISoulboundIdentity(_soulboundIdentity); } /// @notice Sets the price for adding the link in SoulLinker in stable coin /// @dev The caller must have the admin or project admin role to call this function /// @param _addLinkPrice New price for adding the link in SoulLinker in stable coin function setAddLinkPrice(uint256 _addLinkPrice) external { if ( !hasRole(DEFAULT_ADMIN_ROLE, _msgSender()) && !hasRole(PROJECT_ADMIN_ROLE, _msgSender()) ) revert UserMustHaveProtocolOrProjectAdminRole(); if (addLinkPrice == _addLinkPrice) revert SameValue(); addLinkPrice = _addLinkPrice; } /// @notice Sets the price for adding the link in SoulLinker in MASA /// @dev The caller must have the admin or project admin role to call this function /// @param _addLinkPriceMASA New price for adding the link in SoulLinker in MASA function setAddLinkPriceMASA(uint256 _addLinkPriceMASA) external { if ( !hasRole(DEFAULT_ADMIN_ROLE, _msgSender()) && !hasRole(PROJECT_ADMIN_ROLE, _msgSender()) ) revert UserMustHaveProtocolOrProjectAdminRole(); if (addLinkPriceMASA == _addLinkPriceMASA) revert SameValue(); addLinkPriceMASA = _addLinkPriceMASA; } /// @notice Sets the price for reading data in SoulLinker in stable coin /// @dev The caller must have the admin or project admin role to call this function /// @param _queryLinkPrice New price for reading data in SoulLinker in stable coin function setQueryLinkPrice(uint256 _queryLinkPrice) external { if ( !hasRole(DEFAULT_ADMIN_ROLE, _msgSender()) && !hasRole(PROJECT_ADMIN_ROLE, _msgSender()) ) revert UserMustHaveProtocolOrProjectAdminRole(); if (queryLinkPrice == _queryLinkPrice) revert SameValue(); queryLinkPrice = _queryLinkPrice; } /// @notice Sets the price for reading data in SoulLinker in MASA /// @dev The caller must have the admin or project admin role to call this function /// @param _queryLinkPriceMASA New price for reading data in SoulLinker in MASA function setQueryLinkPriceMASA(uint256 _queryLinkPriceMASA) external { if ( !hasRole(DEFAULT_ADMIN_ROLE, _msgSender()) && !hasRole(PROJECT_ADMIN_ROLE, _msgSender()) ) revert UserMustHaveProtocolOrProjectAdminRole(); if (queryLinkPriceMASA == _queryLinkPriceMASA) revert SameValue(); queryLinkPriceMASA = _queryLinkPriceMASA; } /* ========== MUTATIVE FUNCTIONS ======================================== */ /* ========== VIEWS ===================================================== */ /// @notice Returns the identityId owned by the given token /// @param tokenId Id of the token /// @return Id of the identity function getIdentityId(uint256 tokenId) external view returns (uint256) { if (soulboundIdentity == ISoulboundIdentity(address(0))) revert NotLinkedToAnIdentitySBT(); address owner = super.ownerOf(tokenId); return soulboundIdentity.tokenOfOwner(owner); } /// @notice Returns true if the token exists /// @dev Returns true if the token has been minted /// @param tokenId Token to check /// @return True if the token exists function exists(uint256 tokenId) external view returns (bool) { return _exists(tokenId); } /// @notice A distinct Uniform Resource Identifier (URI) for a given asset. /// @dev Throws if `_tokenId` is not a valid SBT. URIs are defined in RFC /// 3986. The URI may point to a JSON file that conforms to the "ERC721 /// Metadata JSON Schema". /// @param tokenId SBT to get the URI of /// @return URI of the SBT function tokenURI( uint256 tokenId ) public view virtual override returns (string memory) { _requireMinted(tokenId); string memory baseURI = _baseURI(); return bytes(baseURI).length > 0 ? string(abi.encodePacked(baseURI, tokenId.toString(), ".json")) : ""; } /// @notice Query if a contract implements an interface /// @dev Interface identification is specified in ERC-165. /// @param interfaceId The interface identifier, as specified in ERC-165 /// @return `true` if the contract implements `interfaceId` and /// `interfaceId` is not 0xffffffff, `false` otherwise function supportsInterface( bytes4 interfaceId ) public view virtual override(SBT, SBTEnumerable, AccessControl, IERC165) returns (bool) { return super.supportsInterface(interfaceId); } /// @notice Returns the price for minting /// @dev Returns current pricing for minting /// @param paymentMethod Address of token that user want to pay /// @return price Current price for minting in the given payment method function getMintPrice( address paymentMethod ) public view returns (uint256 price) { if (mintPrice == 0 && mintPriceMASA == 0) { price = 0; } else if ( paymentMethod == masaToken && enabledPaymentMethod[paymentMethod] && mintPriceMASA > 0 ) { // price in MASA without conversion rate price = mintPriceMASA; } else if ( paymentMethod == stableCoin && enabledPaymentMethod[paymentMethod] ) { // stable coin price = mintPrice; } else if (enabledPaymentMethod[paymentMethod]) { // ETH and ERC 20 token price = _convertFromStableCoin(paymentMethod, mintPrice); } else { revert InvalidPaymentMethod(paymentMethod); } return price; } /// @notice Returns the price for minting with protocol fee /// @dev Returns current pricing for minting with protocol fee /// @param paymentMethod Address of token that user want to pay /// @return price Current price for minting in the given payment method /// @return protocolFee Current protocol fee for minting in the given payment method function getMintPriceWithProtocolFee( address paymentMethod ) public view returns (uint256 price, uint256 protocolFee) { price = getMintPrice(paymentMethod); return (price, _getProtocolFee(paymentMethod, price)); } /* ========== PRIVATE FUNCTIONS ========================================= */ function _baseURI() internal view virtual override returns (string memory) { return _baseTokenURI; } function _beforeTokenTransfer( address from, address to, uint256 tokenId ) internal virtual override(SBT, SBTEnumerable) { super._beforeTokenTransfer(from, to, tokenId); } /* ========== MODIFIERS ================================================= */ /* ========== EVENTS ==================================================== */ } // File contracts/tokens/MasaSBTSelfSovereign.sol // Original license: SPDX_License_Identifier: MIT pragma solidity ^0.8.8; /// @title MasaSBTSelfSovereign /// @author Masa Finance /// @notice Soulbound token. Non-fungible token that is not transferable. /// Adds a self-sovereign protocol to let minting using an authority signature /// @dev Implementation of https://papers.ssrn.com/sol3/papers.cfm?abstract_id=4105763 Soulbound token. abstract contract MasaSBTSelfSovereign is MasaSBT, EIP712 { /* ========== STATE VARIABLES =========================================== */ using Counters for Counters.Counter; Counters.Counter private _tokenIdCounter; mapping(address => bool) public authorities; /* ========== INITIALIZE ================================================ */ /// @notice Creates a new soulbound token /// @dev Creates a new soulbound token /// @param admin Administrator of the smart contract /// @param name Name of the token /// @param symbol Symbol of the token /// @param baseTokenURI Base URI of the token /// @param soulboundIdentity Address of the SoulboundIdentity contract /// @param paymentParams Payment gateway params constructor( address admin, string memory name, string memory symbol, string memory baseTokenURI, address soulboundIdentity, PaymentParams memory paymentParams ) MasaSBT( admin, name, symbol, baseTokenURI, soulboundIdentity, paymentParams ) {} /* ========== RESTRICTED FUNCTIONS ====================================== */ /// @notice Adds a new authority to the list of authorities /// @dev The caller must have the admin or project admin role to call this function /// @param _authority New authority to add function addAuthority(address _authority) external { if ( !hasRole(DEFAULT_ADMIN_ROLE, _msgSender()) && !hasRole(PROJECT_ADMIN_ROLE, _msgSender()) ) revert UserMustHaveProtocolOrProjectAdminRole(); if (_authority == address(0)) revert ZeroAddress(); if (authorities[_authority]) revert AlreadyAdded(); authorities[_authority] = true; } /// @notice Removes an authority from the list of authorities /// @dev The caller must have the admin or project admin role to call this function /// @param _authority Authority to remove function removeAuthority(address _authority) external { if ( !hasRole(DEFAULT_ADMIN_ROLE, _msgSender()) && !hasRole(PROJECT_ADMIN_ROLE, _msgSender()) ) revert UserMustHaveProtocolOrProjectAdminRole(); if (_authority == address(0)) revert ZeroAddress(); if (!authorities[_authority]) revert AuthorityNotExists(_authority); authorities[_authority] = false; } /* ========== MUTATIVE FUNCTIONS ======================================== */ /* ========== VIEWS ===================================================== */ /* ========== PRIVATE FUNCTIONS ========================================= */ function _verify( bytes32 digest, bytes memory signature, address signer ) private view { address _signer = ECDSA.recover(digest, signature); if (_signer != signer) revert InvalidSignature(); if (!authorities[_signer]) revert NotAuthorized(_signer); } function _mintWithCounter( address paymentMethod, address to, bytes32 digest, address authorityAddress, bytes calldata signature ) internal virtual returns (uint256) { _verify(digest, signature, authorityAddress); (uint256 price, uint256 protocolFee) = getMintPriceWithProtocolFee( paymentMethod ); _pay(paymentMethod, price, protocolFee); uint256 tokenId = _tokenIdCounter.current(); _tokenIdCounter.increment(); _mint(to, tokenId); return tokenId; } /* ========== MODIFIERS ================================================= */ /* ========== EVENTS ==================================================== */ } // File contracts/reference/ReferenceSBTSelfSovereign.sol // Original license: SPDX_License_Identifier: MIT pragma solidity ^0.8.8; /// @title Soulbound reference Self-Sovereign SBT /// @author Masa Finance /// @notice Soulbound token that represents a Self-Sovereign SBT /// @dev Inherits from the SBT contract. contract ReferenceSBTSelfSovereign is MasaSBTSelfSovereign, ReentrancyGuard { error MaxSBTMinted(address to, uint256 maximum); uint256 public maxSBTToMint = 1; /* ========== STATE VARIABLES =========================================== */ /* ========== INITIALIZE ================================================ */ /// @notice Creates a new Self-Sovereign SBT /// @dev Creates a new Self-Sovereign SBT, inheriting from the SBT contract. /// @param admin Administrator of the smart contract /// @param name Name of the token /// @param symbol Symbol of the token /// @param baseTokenURI Base URI of the token /// @param soulboundIdentity Address of the SoulboundIdentity contract /// @param paymentParams Payment gateway params /// @param _maxSBTToMint Maximum number of SBT that can be minted constructor( address admin, string memory name, string memory symbol, string memory baseTokenURI, address soulboundIdentity, PaymentParams memory paymentParams, uint256 _maxSBTToMint ) MasaSBTSelfSovereign( admin, name, symbol, baseTokenURI, soulboundIdentity, paymentParams ) EIP712("ReferenceSBTSelfSovereign", "1.0.0") { maxSBTToMint = _maxSBTToMint; } /* ========== RESTRICTED FUNCTIONS ====================================== */ /* ========== MUTATIVE FUNCTIONS ======================================== */ /// @notice Mints a new SBT /// @dev The caller must have the MINTER role /// @param paymentMethod Address of token that user want to pay /// @param identityId TokenId of the identity to mint the NFT to /// @param authorityAddress Address of the authority that signed the message /// @param signatureDate Date of the signature /// @param signature Signature of the message /// @return The SBT ID of the newly minted SBT function mint( address paymentMethod, uint256 identityId, address authorityAddress, uint256 signatureDate, bytes calldata signature ) external payable virtual nonReentrant returns (uint256) { address to = soulboundIdentity.ownerOf(identityId); if (maxSBTToMint > 0 && balanceOf(to) >= maxSBTToMint) revert MaxSBTMinted(to, maxSBTToMint); if (to != _msgSender()) revert CallerNotOwner(_msgSender()); uint256 tokenId = _mintWithCounter( paymentMethod, to, _hash(identityId, authorityAddress, signatureDate), authorityAddress, signature ); emit MintedToIdentity( tokenId, identityId, authorityAddress, signatureDate, paymentMethod, mintPrice ); return tokenId; } /// @notice Mints a new SBT /// @dev The caller must have the MINTER role /// @param paymentMethod Address of token that user want to pay /// @param to The address to mint the SBT to /// @param authorityAddress Address of the authority that signed the message /// @param signatureDate Date of the signature /// @param signature Signature of the message /// @return The SBT ID of the newly minted SBT function mint( address paymentMethod, address to, address authorityAddress, uint256 signatureDate, bytes calldata signature ) external payable virtual returns (uint256) { if (maxSBTToMint > 0 && balanceOf(to) >= maxSBTToMint) revert MaxSBTMinted(to, maxSBTToMint); if (to != _msgSender()) revert CallerNotOwner(_msgSender()); uint256 tokenId = _mintWithCounter( paymentMethod, to, _hash(to, authorityAddress, signatureDate), authorityAddress, signature ); emit MintedToAddress( tokenId, to, authorityAddress, signatureDate, paymentMethod, mintPrice ); return tokenId; } /* ========== VIEWS ===================================================== */ function tokenURI( uint256 tokenId ) public view virtual override returns (string memory) { _requireMinted(tokenId); return _baseURI(); } /* ========== PRIVATE FUNCTIONS ========================================= */ function _hash( uint256 identityId, address authorityAddress, uint256 signatureDate ) internal view returns (bytes32) { return _hashTypedDataV4( keccak256( abi.encode( keccak256( "Mint(uint256 identityId,address authorityAddress,uint256 signatureDate)" ), identityId, authorityAddress, signatureDate ) ) ); } function _hash( address to, address authorityAddress, uint256 signatureDate ) internal view returns (bytes32) { return _hashTypedDataV4( keccak256( abi.encode( keccak256( "Mint(address to,address authorityAddress,uint256 signatureDate)" ), to, authorityAddress, signatureDate ) ) ); } /* ========== MODIFIERS ================================================= */ /* ========== EVENTS ==================================================== */ event MintedToIdentity( uint256 tokenId, uint256 identityId, address authorityAddress, uint256 signatureDate, address paymentMethod, uint256 mintPrice ); event MintedToAddress( uint256 tokenId, address to, address authorityAddress, uint256 signatureDate, address paymentMethod, uint256 mintPrice ); }
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.8;
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "./libraries/Errors.sol";
import "./tokens/MasaSBTSelfSovereign.sol";
/// @title Soulbound Credit Score
/// @author Masa Finance
/// @notice Soulbound token that represents a credit score.
/// @dev Soulbound credit score, that inherits from the SBT contract.
contract SoulboundCreditScore is MasaSBTSelfSovereign, ReentrancyGuard {
/* ========== STATE VARIABLES =========================================== */
/* ========== INITIALIZE ================================================ */
/// @notice Creates a new soulbound credit score
/// @dev Creates a new soulbound credit score, inheriting from the SBT contract.
/// @param admin Administrator of the smart contract
/// @param name Name of the token
/// @param symbol Symbol of the token
/// @param baseTokenURI Base URI of the token
/// @param soulboundIdentity Address of the SoulboundIdentity contract
/// @param paymentParams Payment gateway params
constructor(
address admin,
string memory name,
string memory symbol,
string memory baseTokenURI,
address soulboundIdentity,
PaymentParams memory paymentParams
)
MasaSBTSelfSovereign(
admin,
name,
symbol,
baseTokenURI,
soulboundIdentity,
paymentParams
)
EIP712("SoulboundCreditScore", "1.0.0")
{}
/* ========== RESTRICTED FUNCTIONS ====================================== */
/* ========== MUTATIVE FUNCTIONS ======================================== */
/// @notice Mints a new SBT
/// @dev The caller must have the MINTER role
/// @param paymentMethod Address of token that user want to pay
/// @param identityId TokenId of the identity to mint the NFT to
/// @param authorityAddress Address of the authority that signed the message
/// @param signatureDate Date of the signature
/// @param signature Signature of the message
/// @return The NFT ID of the newly minted SBT
function mint(
address paymentMethod,
uint256 identityId,
address authorityAddress,
uint256 signatureDate,
bytes calldata signature
) external payable nonReentrant returns (uint256) {
address to = soulboundIdentity.ownerOf(identityId);
if (to != _msgSender()) revert CallerNotOwner(_msgSender());
if (balanceOf(to) > 0) revert CreditScoreAlreadyCreated(to);
uint256 tokenId = _mintWithCounter(
paymentMethod,
to,
_hash(identityId, authorityAddress, signatureDate),
authorityAddress,
signature
);
emit SoulboundCreditScoreMintedToIdentity(
tokenId,
identityId,
authorityAddress,
signatureDate,
paymentMethod,
mintPrice
);
return tokenId;
}
/// @notice Mints a new SBT
/// @dev The caller must have the MINTER role
/// @param paymentMethod Address of token that user want to pay
/// @param to The address to mint the SBT to
/// @param authorityAddress Address of the authority that signed the message
/// @param signatureDate Date of the signature
/// @param signature Signature of the message
/// @return The SBT ID of the newly minted SBT
function mint(
address paymentMethod,
address to,
address authorityAddress,
uint256 signatureDate,
bytes calldata signature
) external payable nonReentrant returns (uint256) {
if (to != _msgSender()) revert CallerNotOwner(_msgSender());
if (balanceOf(to) > 0) revert CreditScoreAlreadyCreated(to);
uint256 tokenId = _mintWithCounter(
paymentMethod,
to,
_hash(to, authorityAddress, signatureDate),
authorityAddress,
signature
);
emit SoulboundCreditScoreMintedToAddress(
tokenId,
to,
authorityAddress,
signatureDate,
paymentMethod,
mintPrice
);
return tokenId;
}
/* ========== VIEWS ===================================================== */
/* ========== PRIVATE FUNCTIONS ========================================= */
function _hash(
uint256 identityId,
address authorityAddress,
uint256 signatureDate
) internal view returns (bytes32) {
return
_hashTypedDataV4(
keccak256(
abi.encode(
keccak256(
"MintCreditScore(uint256 identityId,address authorityAddress,uint256 signatureDate)"
),
identityId,
authorityAddress,
signatureDate
)
)
);
}
function _hash(
address to,
address authorityAddress,
uint256 signatureDate
) internal view returns (bytes32) {
return
_hashTypedDataV4(
keccak256(
abi.encode(
keccak256(
"MintCreditScore(address to,address authorityAddress,uint256 signatureDate)"
),
to,
authorityAddress,
signatureDate
)
)
);
}
/* ========== MODIFIERS ================================================= */
/* ========== EVENTS ==================================================== */
event SoulboundCreditScoreMintedToIdentity(
uint256 tokenId,
uint256 identityId,
address authorityAddress,
uint256 signatureDate,
address paymentMethod,
uint256 mintPrice
);
event SoulboundCreditScoreMintedToAddress(
uint256 tokenId,
address to,
address authorityAddress,
uint256 signatureDate,
address paymentMethod,
uint256 mintPrice
);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.8;
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "./libraries/Errors.sol";
import "./tokens/MasaSBTSelfSovereign.sol";
/// @title Soulbound Two-factor authentication (Green - 2FA)
/// @author Masa Finance
/// @notice Soulbound token that represents a Two-factor authentication (2FA)
/// @dev Soulbound Green, that inherits from the SBT contract.
contract SoulboundGreen is MasaSBTSelfSovereign, ReentrancyGuard {
/* ========== STATE VARIABLES =========================================== */
/* ========== INITIALIZE ================================================ */
/// @notice Creates a new soulbound Two-factor authentication (Green - 2FA)
/// @dev Creates a new soulbound Green, inheriting from the SBT contract.
/// @param admin Administrator of the smart contract
/// @param name Name of the token
/// @param symbol Symbol of the token
/// @param baseTokenURI Base URI of the token
/// @param soulboundIdentity Address of the SoulboundIdentity contract
/// @param paymentParams Payment gateway params
constructor(
address admin,
string memory name,
string memory symbol,
string memory baseTokenURI,
address soulboundIdentity,
PaymentParams memory paymentParams
)
MasaSBTSelfSovereign(
admin,
name,
symbol,
baseTokenURI,
soulboundIdentity,
paymentParams
)
EIP712("SoulboundGreen", "1.0.0")
{}
/* ========== RESTRICTED FUNCTIONS ====================================== */
/* ========== MUTATIVE FUNCTIONS ======================================== */
/// @notice Mints a new SBT
/// @dev The caller must have the MINTER role
/// @param paymentMethod Address of token that user want to pay
/// @param identityId TokenId of the identity to mint the NFT to
/// @param authorityAddress Address of the authority that signed the message
/// @param signatureDate Date of the signature
/// @param signature Signature of the message
/// @return The NFT ID of the newly minted SBT
function mint(
address paymentMethod,
uint256 identityId,
address authorityAddress,
uint256 signatureDate,
bytes calldata signature
) external payable nonReentrant returns (uint256) {
address to = soulboundIdentity.ownerOf(identityId);
if (to != _msgSender()) revert CallerNotOwner(_msgSender());
uint256 tokenId = _mintWithCounter(
paymentMethod,
to,
_hash(identityId, authorityAddress, signatureDate),
authorityAddress,
signature
);
emit SoulboundGreenMintedToIdentity(
tokenId,
identityId,
authorityAddress,
signatureDate,
paymentMethod,
mintPrice
);
return tokenId;
}
/// @notice Mints a new SBT
/// @dev The caller must have the MINTER role
/// @param paymentMethod Address of token that user want to pay
/// @param to The address to mint the SBT to
/// @param authorityAddress Address of the authority that signed the message
/// @param signatureDate Date of the signature
/// @param signature Signature of the message
/// @return The SBT ID of the newly minted SBT
function mint(
address paymentMethod,
address to,
address authorityAddress,
uint256 signatureDate,
bytes calldata signature
) external payable nonReentrant returns (uint256) {
if (to != _msgSender()) revert CallerNotOwner(_msgSender());
uint256 tokenId = _mintWithCounter(
paymentMethod,
to,
_hash(to, authorityAddress, signatureDate),
authorityAddress,
signature
);
emit SoulboundGreenMintedToAddress(
tokenId,
to,
authorityAddress,
signatureDate,
paymentMethod,
mintPrice
);
return tokenId;
}
/* ========== VIEWS ===================================================== */
/* ========== PRIVATE FUNCTIONS ========================================= */
function _hash(
uint256 identityId,
address authorityAddress,
uint256 signatureDate
) internal view returns (bytes32) {
return
_hashTypedDataV4(
keccak256(
abi.encode(
keccak256(
"MintGreen(uint256 identityId,address authorityAddress,uint256 signatureDate)"
),
identityId,
authorityAddress,
signatureDate
)
)
);
}
function _hash(
address to,
address authorityAddress,
uint256 signatureDate
) internal view returns (bytes32) {
return
_hashTypedDataV4(
keccak256(
abi.encode(
keccak256(
"MintGreen(address to,address authorityAddress,uint256 signatureDate)"
),
to,
authorityAddress,
signatureDate
)
)
);
}
/* ========== MODIFIERS ================================================= */
/* ========== EVENTS ==================================================== */
event SoulboundGreenMintedToIdentity(
uint256 tokenId,
uint256 identityId,
address authorityAddress,
uint256 signatureDate,
address paymentMethod,
uint256 mintPrice
);
event SoulboundGreenMintedToAddress(
uint256 tokenId,
address to,
address authorityAddress,
uint256 signatureDate,
address paymentMethod,
uint256 mintPrice
);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.8;
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "./libraries/Errors.sol";
import "./interfaces/ISoulboundIdentity.sol";
import "./interfaces/ISoulName.sol";
import "./tokens/MasaSBTAuthority.sol";
/// @title Soulbound Identity
/// @author Masa Finance
/// @notice Soulbound token that represents an identity.
/// @dev Soulbound identity, that inherits from the SBT contract.
contract SoulboundIdentity is
MasaSBTAuthority,
ISoulboundIdentity,
ReentrancyGuard
{
/* ========== STATE VARIABLES =========================================== */
ISoulName public soulName;
/* ========== INITIALIZE ================================================ */
/// @notice Creates a new soulbound identity
/// @dev Creates a new soulbound identity, inheriting from the SBT contract.
/// @param admin Administrator of the smart contract
/// @param name Name of the token
/// @param symbol Symbol of the token
/// @param baseTokenURI Base URI of the token
/// @param paymentParams Payment gateway params
constructor(
address admin,
string memory name,
string memory symbol,
string memory baseTokenURI,
PaymentParams memory paymentParams
)
MasaSBTAuthority(
admin,
name,
symbol,
baseTokenURI,
address(0),
paymentParams
)
{}
/* ========== RESTRICTED FUNCTIONS ====================================== */
/// @notice Sets the SoulName contract address linked to this identity
/// @dev The caller must have the admin role to call this function
/// @param _soulName Address of the SoulName contract
function setSoulName(
ISoulName _soulName
) external onlyRole(DEFAULT_ADMIN_ROLE) {
if (address(_soulName) == address(0)) revert ZeroAddress();
if (soulName == _soulName) revert SameValue();
soulName = _soulName;
}
/* ========== MUTATIVE FUNCTIONS ======================================== */
/// @notice Mints a new soulbound identity
/// @dev The caller can only mint one identity per address
/// @param to Address of the owner of the new identity
/// @return The identity ID of the newly minted identity
function mint(address to) external payable override returns (uint256) {
return mint(address(0), to);
}
/// @notice Mints a new soulbound identity
/// @dev The caller can only mint one identity per address
/// @param paymentMethod Address of the payment method to use
/// @param to Address of the owner of the new identity
/// @return The identity ID of the newly minted identity
function mint(
address paymentMethod,
address to
) public payable override returns (uint256) {
// Soulbound identity already created!
if (balanceOf(to) > 0) revert IdentityAlreadyCreated(to);
return _mintWithCounter(paymentMethod, to);
}
/// @notice Mints a new soulbound identity with a SoulName associated to it
/// @dev The caller can only mint one identity per address, and the name must be unique
/// @param to Address of the owner of the new identity
/// @param name Name of the new identity
/// @param yearsPeriod Years of validity of the name
/// @param _tokenURI URI of the NFT
function mintIdentityWithName(
address to,
string memory name,
uint256 yearsPeriod,
string memory _tokenURI
) external payable override soulNameAlreadySet returns (uint256) {
return
mintIdentityWithName(address(0), to, name, yearsPeriod, _tokenURI);
}
/// @notice Mints a new soulbound identity with a SoulName associated to it
/// @dev The caller can only mint one identity per address, and the name must be unique
/// @param paymentMethod Address of the payment method to use
/// @param to Address of the owner of the new identity
/// @param name Name of the new identity
/// @param yearsPeriod Years of validity of the name
/// @param _tokenURI URI of the NFT
function mintIdentityWithName(
address paymentMethod,
address to,
string memory name,
uint256 yearsPeriod,
string memory _tokenURI
)
public
payable
override
soulNameAlreadySet
nonReentrant
returns (uint256)
{
uint256 identityId = mint(paymentMethod, to);
soulName.mint(to, name, yearsPeriod, _tokenURI);
return identityId;
}
/* ========== VIEWS ===================================================== */
/// @notice Returns the address of the SoulName contract linked to this identity
/// @dev This function returns the address of the SoulName contract linked to this identity
/// @return Address of the SoulName contract
function getSoulName() external view override returns (ISoulName) {
return soulName;
}
/// @notice Returns the extension of the soul name
/// @dev This function returns the extension of the soul name
/// @return Extension of the soul name
function getExtension() external view returns (string memory) {
return soulName.getExtension();
}
/// @notice Returns the owner address of an identity
/// @dev This function returns the owner address of the identity specified by the tokenId
/// @param tokenId TokenId of the identity
/// @return Address of the owner of the identity
function ownerOf(
uint256 tokenId
) public view override(SBT, ISBT) returns (address) {
return super.ownerOf(tokenId);
}
/// @notice Returns the owner address of a soul name
/// @dev This function returns the owner address of the soul name identity specified by the name
/// @param name Name of the soul name
/// @return Address of the owner of the identity
function ownerOf(
string memory name
) external view soulNameAlreadySet returns (address) {
(, , uint256 identityId, , , ) = soulName.getTokenData(name);
return super.ownerOf(identityId);
}
/// @notice Returns the URI of a soul name
/// @dev This function returns the token URI of the soul name identity specified by the name
/// @param name Name of the soul name
/// @return URI of the identity associated to a soul name
function tokenURI(
string memory name
) external view soulNameAlreadySet returns (string memory) {
(, , uint256 identityId, , , ) = soulName.getTokenData(name);
return super.tokenURI(identityId);
}
/// @notice Returns the URI of the owner of an identity
/// @dev This function returns the token URI of the identity owned by an account
/// @param owner Address of the owner of the identity
/// @return URI of the identity owned by the account
function tokenURI(address owner) external view returns (string memory) {
uint256 tokenId = tokenOfOwner(owner);
return super.tokenURI(tokenId);
}
/// @notice Returns the identity id of an account
/// @dev This function returns the tokenId of the identity owned by an account
/// @param owner Address of the owner of the identity
/// @return TokenId of the identity owned by the account
function tokenOfOwner(
address owner
) public view override returns (uint256) {
return super.tokenOfOwnerByIndex(owner, 0);
}
/// @notice Checks if a soul name is available
/// @dev This function queries if a soul name already exists and is in the available state
/// @param name Name of the soul name
/// @return available `true` if the soul name is available, `false` otherwise
function isAvailable(
string memory name
) external view soulNameAlreadySet returns (bool available) {
return soulName.isAvailable(name);
}
/// @notice Returns the information of a soul name
/// @dev This function queries the information of a soul name
/// @param name Name of the soul name
/// @return sbtName Soul name, in upper/lower case and extension
/// @return linked `true` if the soul name is linked, `false` otherwise
/// @return identityId Identity id of the soul name
/// @return tokenId SoulName id of the soul name
/// @return expirationDate Expiration date of the soul name
/// @return active `true` if the soul name is active, `false` otherwise
function getTokenData(
string memory name
)
external
view
soulNameAlreadySet
returns (
string memory sbtName,
bool linked,
uint256 identityId,
uint256 tokenId,
uint256 expirationDate,
bool active
)
{
return soulName.getTokenData(name);
}
/// @notice Returns all the active soul names of an account
/// @dev This function queries all the identity names of the specified account
/// @param owner Address of the owner of the identities
/// @return sbtNames Array of soul names associated to the account
function getSoulNames(
address owner
) external view soulNameAlreadySet returns (string[] memory sbtNames) {
return soulName.getSoulNames(owner);
}
// SoulName -> SoulboundIdentity.tokenId
// SoulName -> account -> SoulboundIdentity.tokenId
/// @notice Returns all the active soul names of an account
/// @dev This function queries all the identity names of the specified identity Id
/// @param tokenId TokenId of the identity
/// @return sbtNames Array of soul names associated to the identity Id
function getSoulNames(
uint256 tokenId
) external view soulNameAlreadySet returns (string[] memory sbtNames) {
return soulName.getSoulNames(tokenId);
}
/* ========== PRIVATE FUNCTIONS ========================================= */
/* ========== MODIFIERS ================================================= */
modifier soulNameAlreadySet() {
if (address(soulName) == address(0)) revert SoulNameContractNotSet();
_;
}
/* ========== EVENTS ==================================================== */
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.8;
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "@openzeppelin/contracts/utils/cryptography/draft-EIP712.sol";
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import "@openzeppelin/contracts/security/Pausable.sol";
import "./libraries/Errors.sol";
import "./dex/PaymentGateway.sol";
import "./interfaces/ILinkableSBT.sol";
import "./interfaces/ISoulboundIdentity.sol";
import "./interfaces/ISoulName.sol";
import "./tokens/SBT/extensions/ISBTEnumerable.sol";
/// @title Soul linker
/// @author Masa Finance
/// @notice Soul linker smart contract that let add links to a Soulbound token.
contract SoulLinker is PaymentGateway, EIP712, Pausable, ReentrancyGuard {
/* ========== STATE VARIABLES =========================================== */
ISoulboundIdentity public soulboundIdentity;
ISoulName[] public soulNames;
mapping(address => bool) public isSoulName;
// token => tokenId => readerIdentityId => signatureDate => LinkData
mapping(address => mapping(uint256 => mapping(uint256 => mapping(uint256 => LinkData))))
private _links;
// token => tokenId => readerIdentityId
mapping(address => mapping(uint256 => uint256[]))
private _linkReaderIdentityIds;
// token => tokenId => readerIdentityId => signatureDate
mapping(address => mapping(uint256 => mapping(uint256 => uint256[])))
private _linkSignatureDates;
// readerIdentityId => ReaderLink
mapping(uint256 => ReaderLink[]) private _readerLinks;
struct LinkData {
bool exists;
uint256 ownerIdentityId;
uint256 expirationDate;
bool isRevoked;
}
struct ReaderLink {
address token;
uint256 tokenId;
uint256 signatureDate;
}
struct LinkKey {
uint256 readerIdentityId;
uint256 signatureDate;
}
struct DefaultSoulName {
bool exists;
address token;
uint256 tokenId;
}
mapping(address => DefaultSoulName) public defaultSoulName; // stores the token id of the default soul name
/* ========== INITIALIZE ================================================ */
/// @notice Creates a new soul linker
/// @param admin Administrator of the smart contract
/// @param _soulboundIdentity Soulbound identity smart contract
/// @param _soulNames Soul name smart contracts
/// @param paymentParams Payment gateway params
constructor(
address admin,
ISoulboundIdentity _soulboundIdentity,
ISoulName[] memory _soulNames,
PaymentParams memory paymentParams
) EIP712("SoulLinker", "1.0.0") PaymentGateway(admin, paymentParams) {
if (address(_soulboundIdentity) == address(0)) revert ZeroAddress();
soulboundIdentity = _soulboundIdentity;
soulNames = _soulNames;
for (uint256 i = 0; i < _soulNames.length; i++) {
isSoulName[address(_soulNames[i])] = true;
}
}
/* ========== RESTRICTED FUNCTIONS ====================================== */
/// @notice Sets the SoulboundIdentity contract address linked to this soul store
/// @dev The caller must have the admin role to call this function
/// @param _soulboundIdentity Address of the SoulboundIdentity contract
function setSoulboundIdentity(
ISoulboundIdentity _soulboundIdentity
) external onlyRole(DEFAULT_ADMIN_ROLE) {
if (address(_soulboundIdentity) == address(0)) revert ZeroAddress();
if (soulboundIdentity == _soulboundIdentity) revert SameValue();
soulboundIdentity = _soulboundIdentity;
}
/// @notice Add a SoulName contract address linked to this soul store
/// @dev The caller must have the admin role to call this function
/// @param soulName Address of the SoulName contract
function addSoulName(
ISoulName soulName
) external onlyRole(DEFAULT_ADMIN_ROLE) {
if (address(soulName) == address(0)) revert ZeroAddress();
for (uint256 i = 0; i < soulNames.length; i++) {
if (soulNames[i] == soulName) revert SameValue();
}
soulNames.push(soulName);
isSoulName[address(soulName)] = true;
}
/// @notice Remove a SoulName contract address linked to this soul store
/// @dev The caller must have the admin role to call this function
/// @param soulName Address of the SoulName contract
function removeSoulName(
ISoulName soulName
) external onlyRole(DEFAULT_ADMIN_ROLE) {
if (address(soulName) == address(0)) revert ZeroAddress();
for (uint256 i = 0; i < soulNames.length; i++) {
if (soulNames[i] == soulName) {
soulNames[i] = soulNames[soulNames.length - 1];
soulNames.pop();
isSoulName[address(soulName)] = false;
return;
}
}
revert SoulNameNotExist();
}
/// @notice Pauses the smart contract
/// @dev The caller must have the admin role to call this function
function pause() external onlyRole(DEFAULT_ADMIN_ROLE) {
_pause();
}
/// @notice Unpauses the smart contract
/// @dev The caller must have the admin role to call this function
function unpause() external onlyRole(DEFAULT_ADMIN_ROLE) {
_unpause();
}
/* ========== MUTATIVE FUNCTIONS ======================================== */
/// @notice Stores the link, validating the signature of the given read link request
/// @dev The token must be linked to this soul linker
/// @param readerIdentityId Id of the identity of the reader
/// @param ownerIdentityId Id of the identity of the owner of the SBT
/// @param token Address of the SBT contract
/// @param tokenId Id of the token
/// @param signatureDate Signature date of the signature
/// @param expirationDate Expiration date of the signature
/// @param signature Signature of the read link request made by the owner
function addLink(
address paymentMethod,
uint256 readerIdentityId,
uint256 ownerIdentityId,
address token,
uint256 tokenId,
uint256 signatureDate,
uint256 expirationDate,
bytes calldata signature
) external payable whenNotPaused nonReentrant {
address ownerAddress = soulboundIdentity.ownerOf(ownerIdentityId);
address readerAddress = soulboundIdentity.ownerOf(readerIdentityId);
address tokenOwner = ISBTEnumerable(token).ownerOf(tokenId);
if (ownerAddress != tokenOwner)
revert IdentityOwnerNotTokenOwner(tokenId, ownerIdentityId);
if (readerAddress != _msgSender()) revert CallerNotReader(_msgSender());
if (ownerIdentityId == readerIdentityId)
revert IdentityOwnerIsReader(readerIdentityId);
if (signatureDate == 0) revert InvalidSignatureDate(signatureDate);
if (expirationDate < block.timestamp)
revert ValidPeriodExpired(expirationDate);
if (_links[token][tokenId][readerIdentityId][signatureDate].exists)
revert LinkAlreadyExists(
token,
tokenId,
readerIdentityId,
signatureDate
);
if (
!_verify(
_hash(
readerIdentityId,
ownerIdentityId,
token,
tokenId,
signatureDate,
expirationDate
),
signature,
ownerAddress
)
) revert InvalidSignature();
(
uint256 price,
uint256 protocolFee
) = getPriceForAddLinkWithProtocolFee(paymentMethod, token);
_pay(paymentMethod, price, protocolFee);
// token => tokenId => readerIdentityId => signatureDate => LinkData
_links[token][tokenId][readerIdentityId][signatureDate] = LinkData(
true,
ownerIdentityId,
expirationDate,
false
);
if (_linkSignatureDates[token][tokenId][readerIdentityId].length == 0) {
_linkReaderIdentityIds[token][tokenId].push(readerIdentityId);
}
_linkSignatureDates[token][tokenId][readerIdentityId].push(
signatureDate
);
_readerLinks[readerIdentityId].push(
ReaderLink(token, tokenId, signatureDate)
);
emit LinkAdded(
readerIdentityId,
ownerIdentityId,
token,
tokenId,
signatureDate,
expirationDate
);
}
/// @notice Revokes the link
/// @dev The links can be revoked, wether the token is linked or not.
/// The caller must be the owner of the token.
/// The owner of the token can revoke a link even if the reader has not added it yet.
/// @param readerIdentityId Id of the identity of the reader
/// @param ownerIdentityId Id of the identity of the owner of the SBT
/// @param token Address of the SBT contract
/// @param tokenId Id of the token
/// @param signatureDate Signature date of the signature
function revokeLink(
uint256 readerIdentityId,
uint256 ownerIdentityId,
address token,
uint256 tokenId,
uint256 signatureDate
) external whenNotPaused {
address ownerAddress = soulboundIdentity.ownerOf(ownerIdentityId);
address tokenOwner = ISBTEnumerable(token).ownerOf(tokenId);
if (ownerAddress != tokenOwner)
revert IdentityOwnerNotTokenOwner(tokenId, ownerIdentityId);
if (ownerAddress != _msgSender()) revert CallerNotOwner(_msgSender());
if (ownerIdentityId == readerIdentityId)
revert IdentityOwnerIsReader(readerIdentityId);
if (_links[token][tokenId][readerIdentityId][signatureDate].isRevoked)
revert LinkAlreadyRevoked();
if (_links[token][tokenId][readerIdentityId][signatureDate].exists) {
// token => tokenId => readerIdentityId => signatureDate => LinkData
_links[token][tokenId][readerIdentityId][signatureDate]
.isRevoked = true;
} else {
// if the link doesn't exist, store it
// token => tokenId => readerIdentityId => signatureDate => LinkData
_links[token][tokenId][readerIdentityId][signatureDate] = LinkData(
true,
ownerIdentityId,
0,
true
);
if (
_linkSignatureDates[token][tokenId][readerIdentityId].length ==
0
) {
_linkReaderIdentityIds[token][tokenId].push(readerIdentityId);
}
_linkSignatureDates[token][tokenId][readerIdentityId].push(
signatureDate
);
_readerLinks[readerIdentityId].push(
ReaderLink(token, tokenId, signatureDate)
);
}
emit LinkRevoked(
readerIdentityId,
ownerIdentityId,
token,
tokenId,
signatureDate
);
}
/// @notice Sets the default soul name for the owner
/// @dev The caller must be the owner of the soul name.
/// @param token Address of the SoulName contract
/// @param tokenId TokenId of the soul name
function setDefaultSoulName(address token, uint256 tokenId) external {
if (isSoulName[token] == false) revert SoulNameNotRegistered(token);
address soulNameOwner = ISBTEnumerable(token).ownerOf(tokenId);
if (_msgSender() != soulNameOwner) revert CallerNotOwner(_msgSender());
defaultSoulName[_msgSender()].token = token;
defaultSoulName[_msgSender()].tokenId = tokenId;
defaultSoulName[_msgSender()].exists = true;
}
/* ========== VIEWS ===================================================== */
/// @notice Returns the identityId owned by the given token
/// @dev The token must be linked to this soul linker
/// @param token Address of the SBT contract
/// @param tokenId Id of the token
/// @return Id of the identity
function getIdentityId(
address token,
uint256 tokenId
) external view returns (uint256) {
address owner = ISBTEnumerable(token).ownerOf(tokenId);
return soulboundIdentity.tokenOfOwner(owner);
}
/// @notice Returns the list of connected SBTs by a given SBT token
/// @param identityId Id of the identity
/// @param token Address of the SBT contract
/// @return List of connected SBTs
function getSBTConnections(
uint256 identityId,
address token
) external view returns (uint256[] memory) {
address owner = soulboundIdentity.ownerOf(identityId);
return getSBTConnections(owner, token);
}
/// @notice Returns the list of connected SBTs by a given SBT token
/// @param owner Address of the owner of the identity
/// @param token Address of the SBT contract
/// @return List of connectec SBTs
function getSBTConnections(
address owner,
address token
) public view returns (uint256[] memory) {
uint256 connections = ISBTEnumerable(token).balanceOf(owner);
uint256[] memory sbtConnections = new uint256[](connections);
for (uint256 i = 0; i < connections; i++) {
sbtConnections[i] = ISBTEnumerable(token).tokenOfOwnerByIndex(
owner,
i
);
}
return sbtConnections;
}
/// @notice Returns the list of link signature dates for a given SBT token and reader
/// @param token Address of the SBT contract
/// @param tokenId Id of the token
/// @return List of linked SBTs
function getLinks(
address token,
uint256 tokenId
) external view returns (LinkKey[] memory) {
uint256 nLinkKeys = 0;
for (
uint256 i = 0;
i < _linkReaderIdentityIds[token][tokenId].length;
i++
) {
uint256 readerIdentityId = _linkReaderIdentityIds[token][tokenId][
i
];
for (
uint256 j = 0;
j <
_linkSignatureDates[token][tokenId][readerIdentityId].length;
j++
) {
nLinkKeys++;
}
}
LinkKey[] memory linkKeys = new LinkKey[](nLinkKeys);
uint256 n = 0;
for (
uint256 i = 0;
i < _linkReaderIdentityIds[token][tokenId].length;
i++
) {
uint256 readerIdentityId = _linkReaderIdentityIds[token][tokenId][
i
];
for (
uint256 j = 0;
j <
_linkSignatureDates[token][tokenId][readerIdentityId].length;
j++
) {
uint256 signatureDate = _linkSignatureDates[token][tokenId][
readerIdentityId
][j];
linkKeys[n].readerIdentityId = readerIdentityId;
linkKeys[n].signatureDate = signatureDate;
n++;
}
}
return linkKeys;
}
/// @notice Returns the list of link signature dates for a given SBT token and reader
/// @param token Address of the SBT contract
/// @param tokenId Id of the token
/// @param readerIdentityId Id of the identity of the reader of the SBT
/// @return List of linked SBTs
function getLinkSignatureDates(
address token,
uint256 tokenId,
uint256 readerIdentityId
) external view returns (uint256[] memory) {
return _linkSignatureDates[token][tokenId][readerIdentityId];
}
/// @notice Returns the information of link dates for a given SBT token and reader
/// @param token Address of the SBT contract
/// @param tokenId Id of the token
/// @param readerIdentityId Id of the identity of the reader of the SBT
/// @param signatureDate Signature date of the signature
/// @return linkData List of linked SBTs
function getLinkInfo(
address token,
uint256 tokenId,
uint256 readerIdentityId,
uint256 signatureDate
) external view returns (LinkData memory) {
return _links[token][tokenId][readerIdentityId][signatureDate];
}
/// @notice Returns the list of links for a given reader identity id
/// @param readerIdentityId Id of the identity of the reader of the SBT
/// @return List of links for the reader
function getReaderLinks(
uint256 readerIdentityId
) external view returns (ReaderLink[] memory) {
return _readerLinks[readerIdentityId];
}
/// @notice Validates the link of the given read link request and returns the
/// data that reader can read if the link is valid
/// @dev The token must be linked to this soul linker
/// @param readerIdentityId Id of the identity of the reader
/// @param ownerIdentityId Id of the identity of the owner of the SBT
/// @param token Address of the SBT contract
/// @param tokenId Id of the token
/// @param signatureDate Signature date of the signature
/// @return True if the link is valid
function validateLink(
uint256 readerIdentityId,
uint256 ownerIdentityId,
address token,
uint256 tokenId,
uint256 signatureDate
) external view returns (bool) {
address ownerAddress = soulboundIdentity.ownerOf(ownerIdentityId);
address tokenOwner = ISBTEnumerable(token).ownerOf(tokenId);
LinkData memory link = _links[token][tokenId][readerIdentityId][
signatureDate
];
if (ownerAddress != tokenOwner)
revert IdentityOwnerNotTokenOwner(tokenId, ownerIdentityId);
if (!link.exists) revert LinkDoesNotExist();
if (link.expirationDate < block.timestamp)
revert ValidPeriodExpired(link.expirationDate);
if (link.isRevoked) revert LinkAlreadyRevoked();
return true;
}
/// @notice Returns the price for storing a link
/// @dev Returns the current pricing for storing a link
/// @param paymentMethod Address of token that user want to pay
/// @param token Token that user want to store link
/// @return price Current price for storing a link
function getPriceForAddLink(
address paymentMethod,
address token
) public view returns (uint256 price) {
uint256 addLinkPrice = ILinkableSBT(token).addLinkPrice();
uint256 addLinkPriceMASA = ILinkableSBT(token).addLinkPriceMASA();
if (addLinkPrice == 0 && addLinkPriceMASA == 0) {
price = 0;
} else if (
paymentMethod == masaToken &&
enabledPaymentMethod[paymentMethod] &&
addLinkPriceMASA > 0
) {
// price in MASA without conversion rate
price = addLinkPriceMASA;
} else if (
paymentMethod == stableCoin && enabledPaymentMethod[paymentMethod]
) {
// stable coin
price = addLinkPrice;
} else if (enabledPaymentMethod[paymentMethod]) {
// ETH and ERC 20 token
price = _convertFromStableCoin(paymentMethod, addLinkPrice);
} else {
revert InvalidPaymentMethod(paymentMethod);
}
return price;
}
/// @notice Returns the price for storing a link with protocol fee
/// @dev Returns the current pricing for storing a link with protocol fee
/// @param paymentMethod Address of token that user want to pay
/// @param token Token that user want to store link
/// @return price Current price for storing a link
/// @return protocolFee Current protocol fee for storing a link
function getPriceForAddLinkWithProtocolFee(
address paymentMethod,
address token
) public view returns (uint256 price, uint256 protocolFee) {
price = getPriceForAddLink(paymentMethod, token);
return (price, _getProtocolFee(paymentMethod, price));
}
/// @notice Returns all the active soul names of an account
/// @dev This function queries all the identity names of the specified account
/// @param owner Address of the owner of the identities
/// @return defaultName Default soul name of the account
/// @return names Array of soul names associated to the account
function getSoulNames(
address owner
) public view returns (string memory defaultName, string[] memory names) {
uint256 nameCount = 0;
for (uint256 i = 0; i < soulNames.length; i++) {
string[] memory _soulNamesFromIdentity = soulNames[i].getSoulNames(
owner
);
for (uint256 j = 0; j < _soulNamesFromIdentity.length; j++) {
nameCount++;
}
}
string[] memory _soulNames = new string[](nameCount);
uint256 n = 0;
for (uint256 i = 0; i < soulNames.length; i++) {
string[] memory _soulNamesFromIdentity = soulNames[i].getSoulNames(
owner
);
for (uint256 j = 0; j < _soulNamesFromIdentity.length; j++) {
_soulNames[n] = _soulNamesFromIdentity[j];
n++;
}
}
return (getDefaultSoulName(owner), _soulNames);
}
/// @notice Returns all the active soul names of an account
/// @dev This function queries all the identity names of the specified identity Id
/// @param tokenId TokenId of the identity
/// @return defaultName Default soul name of the account
/// @return names Array of soul names associated to the account
function getSoulNames(
uint256 tokenId
) external view returns (string memory defaultName, string[] memory names) {
address owner = soulboundIdentity.ownerOf(tokenId);
return getSoulNames(owner);
}
/// @notice Returns the default soul name of an account
/// @dev This function queries the default soul name of the specified account
/// @param owner Address of the owner of the identities
/// @return Default soul name associated to the account
function getDefaultSoulName(
address owner
) public view returns (string memory) {
// we have set a default soul name
if (defaultSoulName[owner].exists) {
address token = defaultSoulName[owner].token;
uint256 tokenId = defaultSoulName[owner].tokenId;
address soulNameOwner = ISBTEnumerable(token).ownerOf(tokenId);
// the soul name has not changed owner
if (soulNameOwner == owner) {
// the soul name is not expired
(string memory name, uint256 expirationDate) = ISoulName(token)
.tokenData(tokenId);
if (expirationDate >= block.timestamp) {
return name;
}
}
}
return "";
}
/* ========== PRIVATE FUNCTIONS ========================================= */
function _hash(
uint256 readerIdentityId,
uint256 ownerIdentityId,
address token,
uint256 tokenId,
uint256 signatureDate,
uint256 expirationDate
) internal view returns (bytes32) {
return
_hashTypedDataV4(
keccak256(
abi.encode(
keccak256(
"Link(uint256 readerIdentityId,uint256 ownerIdentityId,address token,uint256 tokenId,uint256 signatureDate,uint256 expirationDate)"
),
readerIdentityId,
ownerIdentityId,
token,
tokenId,
signatureDate,
expirationDate
)
)
);
}
function _verify(
bytes32 digest,
bytes memory signature,
address owner
) internal pure returns (bool) {
return ECDSA.recover(digest, signature) == owner;
}
/* ========== MODIFIERS ================================================= */
/* ========== EVENTS ==================================================== */
event LinkAdded(
uint256 readerIdentityId,
uint256 ownerIdentityId,
address token,
uint256 tokenId,
uint256 signatureDate,
uint256 expirationDate
);
event LinkRevoked(
uint256 readerIdentityId,
uint256 ownerIdentityId,
address token,
uint256 tokenId,
uint256 signatureDate
);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.8;
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
import "./libraries/Errors.sol";
import "./libraries/Utils.sol";
import "./interfaces/ISoulboundIdentity.sol";
import "./interfaces/ISoulName.sol";
import "./tokens/MasaNFT.sol";
/// @title SoulName NFT
/// @author Masa Finance
/// @notice SoulName NFT that points to a Soulbound identity token
/// @dev SoulName NFT, that inherits from the NFT contract, and points to a Soulbound identity token.
/// It has an extension, and stores all the information about the identity names.
contract SoulName is MasaNFT, ISoulName, ReentrancyGuard {
/* ========== STATE VARIABLES ========== */
using SafeMath for uint256;
uint256 constant YEAR = 31536000; // 60 seconds * 60 minutes * 24 hours * 365 days
ISoulboundIdentity public soulboundIdentity;
string public extension; // suffix of the names (.soul?)
// contractURI() points to the smart contract metadata
// see https://docs.opensea.io/docs/contract-level-metadata
string public contractURI;
// Optional mapping for token URIs
mapping(uint256 => string) private _tokenURIs;
mapping(string => bool) private _URIs; // used to check if a uri is already used
mapping(uint256 => TokenData) public override tokenData; // used to store the data of the token id
mapping(string => NameData) public nameData; // stores the token id of the current active soul name
struct TokenData {
string name; // Name with lowercase and uppercase
uint256 expirationDate;
}
struct NameData {
bool exists;
uint256 tokenId;
}
/* ========== INITIALIZE ========== */
/// @notice Creates a new SoulName NFT
/// @dev Creates a new SoulName NFT, that points to a Soulbound identity, inheriting from the NFT contract.
/// @param admin Administrator of the smart contract
/// @param name Name of the token
/// @param symbol Symbol of the token
/// @param _soulboundIdentity Address of the Soulbound identity contract
/// @param _extension Extension of the soul name
/// @param _contractURI URI of the smart contract metadata
constructor(
address admin,
string memory name,
string memory symbol,
ISoulboundIdentity _soulboundIdentity,
string memory _extension,
string memory _contractURI
) MasaNFT(admin, name, symbol, "") {
if (address(_soulboundIdentity) == address(0)) revert ZeroAddress();
soulboundIdentity = _soulboundIdentity;
extension = _extension;
contractURI = _contractURI;
}
/* ========== RESTRICTED FUNCTIONS ====================================== */
/// @notice Sets the SoulboundIdentity contract address linked to this soul name
/// @dev The caller must have the admin role to call this function
/// @param _soulboundIdentity Address of the SoulboundIdentity contract
function setSoulboundIdentity(
ISoulboundIdentity _soulboundIdentity
) external onlyRole(DEFAULT_ADMIN_ROLE) {
if (address(_soulboundIdentity) == address(0)) revert ZeroAddress();
if (soulboundIdentity == _soulboundIdentity) revert SameValue();
soulboundIdentity = _soulboundIdentity;
}
/// @notice Sets the extension of the soul name
/// @dev The caller must have the admin role to call this function
/// @param _extension Extension of the soul name
function setExtension(
string memory _extension
) external onlyRole(DEFAULT_ADMIN_ROLE) {
if (
keccak256(abi.encodePacked((extension))) ==
keccak256(abi.encodePacked((_extension)))
) revert SameValue();
extension = _extension;
}
/// @notice Sets the URI of the smart contract metadata
/// @dev The caller must have the admin role to call this function
/// @param _contractURI URI of the smart contract metadata
function setContractURI(
string memory _contractURI
) external onlyRole(DEFAULT_ADMIN_ROLE) {
if (
keccak256(abi.encodePacked((contractURI))) ==
keccak256(abi.encodePacked((_contractURI)))
) revert SameValue();
contractURI = _contractURI;
}
/* ========== MUTATIVE FUNCTIONS ========== */
/// @notice Mints a new soul name
/// @dev The caller can mint more than one name. The soul name must be unique.
/// @param to Address of the owner of the new soul name
/// @param name Name of the new soul name
/// @param yearsPeriod Years of validity of the name
/// @param _tokenURI URI of the NFT
function mint(
address to,
string memory name,
uint256 yearsPeriod,
string memory _tokenURI
) external override nonReentrant returns (uint256) {
if (!isAvailable(name)) revert NameAlreadyExists(name);
if (bytes(name).length == 0) revert ZeroLengthName(name);
if (yearsPeriod == 0) revert ZeroYearsPeriod(yearsPeriod);
if (soulboundIdentity.balanceOf(to) == 0)
revert AddressDoesNotHaveIdentity(to);
if (
!Utils.startsWith(_tokenURI, "ar://") &&
!Utils.startsWith(_tokenURI, "https://arweave.net/") &&
!Utils.startsWith(_tokenURI, "ipfs://")
) revert InvalidTokenURI(_tokenURI);
uint256 tokenId = _mintWithCounter(to);
_setTokenURI(tokenId, _tokenURI);
tokenData[tokenId].name = name;
tokenData[tokenId].expirationDate = block.timestamp.add(
YEAR.mul(yearsPeriod)
);
string memory lowercaseName = Utils.toLowerCase(name);
nameData[lowercaseName].tokenId = tokenId;
nameData[lowercaseName].exists = true;
return tokenId;
}
/// @notice Update the expiration date of a soul name
/// @dev The caller must be the owner or an approved address of the soul name.
/// @param tokenId TokenId of the soul name
/// @param yearsPeriod Years of validity of the name
function renewYearsPeriod(uint256 tokenId, uint256 yearsPeriod) external {
// ERC721: caller is not token owner nor approved
if (!_isApprovedOrOwner(_msgSender(), tokenId))
revert CallerNotOwner(_msgSender());
if (yearsPeriod == 0) revert ZeroYearsPeriod(yearsPeriod);
// check that the last registered tokenId for that name is the current token
string memory lowercaseName = Utils.toLowerCase(
tokenData[tokenId].name
);
if (nameData[lowercaseName].tokenId != tokenId)
revert NameRegisteredByOtherAccount(lowercaseName, tokenId);
// check if the name is expired
if (tokenData[tokenId].expirationDate < block.timestamp) {
tokenData[tokenId].expirationDate = block.timestamp.add(
YEAR.mul(yearsPeriod)
);
} else {
tokenData[tokenId].expirationDate = tokenData[tokenId]
.expirationDate
.add(YEAR.mul(yearsPeriod));
}
emit YearsPeriodRenewed(
tokenId,
yearsPeriod,
tokenData[tokenId].expirationDate
);
}
/// @notice Burn a soul name
/// @dev The caller must be the owner or an approved address of the soul name.
/// @param tokenId TokenId of the soul name to burn
function burn(uint256 tokenId) public override {
if (!_exists(tokenId)) revert TokenNotFound(tokenId);
string memory lowercaseName = Utils.toLowerCase(
tokenData[tokenId].name
);
// remove info from tokenIdName and tokenData
delete tokenData[tokenId];
// if the last owner of the name is burning it, remove the name from nameData
if (nameData[lowercaseName].tokenId == tokenId) {
delete nameData[lowercaseName];
}
if (bytes(_tokenURIs[tokenId]).length != 0) {
_URIs[_tokenURIs[tokenId]] = false;
delete _tokenURIs[tokenId];
}
super.burn(tokenId);
}
/* ========== VIEWS ========== */
/// @notice Returns the extension of the soul name
/// @dev This function is used to get the extension of the soul name
/// @return Extension of the soul name
function getExtension() external view override returns (string memory) {
return extension;
}
/// @notice Checks if a soul name is available
/// @dev This function queries if a soul name already exists and is in the available state
/// @param name Name of the soul name
/// @return available `true` if the soul name is available, `false` otherwise
function isAvailable(
string memory name
) public view override returns (bool available) {
string memory lowercaseName = Utils.toLowerCase(name);
if (nameData[lowercaseName].exists) {
uint256 tokenId = nameData[lowercaseName].tokenId;
return tokenData[tokenId].expirationDate < block.timestamp;
} else {
return true;
}
}
/// @notice Returns the information of a soul name
/// @dev This function queries the information of a soul name
/// @param name Name of the soul name
/// @return sbtName Soul name, in upper/lower case and extension
/// @return linked `true` if the soul name is linked, `false` otherwise
/// @return identityId Identity id of the soul name
/// @return tokenId SoulName id of the soul name
/// @return expirationDate Expiration date of the soul name
/// @return active `true` if the soul name is active, `false` otherwise
function getTokenData(
string memory name
)
external
view
override
returns (
string memory sbtName,
bool linked,
uint256 identityId,
uint256 tokenId,
uint256 expirationDate,
bool active
)
{
tokenId = _getTokenId(name);
address _owner = ownerOf(tokenId);
bool _linked = soulboundIdentity.balanceOf(_owner) > 0;
uint256 _identityId = 0;
if (_linked) {
_identityId = soulboundIdentity.tokenOfOwner(_owner);
}
TokenData memory _tokenData = tokenData[tokenId];
return (
_getName(_tokenData.name),
_linked,
_identityId,
tokenId,
_tokenData.expirationDate,
_tokenData.expirationDate >= block.timestamp
);
}
/// @notice Returns the token id of a soul name
/// @dev This function queries the token id of a soul name
/// @param name Name of the soul name
/// @return SoulName id of the soul name
function getTokenId(
string memory name
) external view override returns (uint256) {
return _getTokenId(name);
}
/// @notice Returns all the active soul names of an account
/// @dev This function queries all the identity names of the specified identity Id
/// @param identityId TokenId of the identity
/// @return sbtNames Array of soul names associated to the identity Id
function getSoulNames(
uint256 identityId
) external view override returns (string[] memory sbtNames) {
// return owner if exists
address _owner = soulboundIdentity.ownerOf(identityId);
return getSoulNames(_owner);
}
/// @notice Returns all the active soul names of an account
/// @dev This function queries all the identity names of the specified account
/// @param owner Address of the owner of the identities
/// @return sbtNames Array of soul names associated to the account
function getSoulNames(
address owner
) public view override returns (string[] memory sbtNames) {
uint256 results = 0;
uint256 balance = balanceOf(owner);
for (uint256 i = 0; i < balance; i++) {
uint256 tokenId = tokenOfOwnerByIndex(owner, i);
if (tokenData[tokenId].expirationDate >= block.timestamp) {
results = results.add(1);
}
}
string[] memory _sbtNames = new string[](results);
uint256 index = 0;
for (uint256 i = 0; i < balance; i++) {
uint256 tokenId = tokenOfOwnerByIndex(owner, i);
if (tokenData[tokenId].expirationDate >= block.timestamp) {
_sbtNames[index] = Utils.toLowerCase(tokenData[tokenId].name);
index = index.add(1);
}
}
// return identity names if exists and are active
return _sbtNames;
}
/// @notice A distinct Uniform Resource Identifier (URI) for a given asset.
/// @dev This function returns the token URI of the soul name specified by the name
/// @param name Name of the soul name
/// @return URI of the soulname associated to a name
function tokenURI(
string memory name
) external view virtual returns (string memory) {
uint256 tokenId = _getTokenId(name);
return tokenURI(tokenId);
}
/// @notice A distinct Uniform Resource Identifier (URI) for a given asset.
/// @dev Throws if `_tokenId` is not a valid NFT. URIs are defined in RFC
/// 3986. The URI may point to a JSON file that conforms to the "ERC721
/// Metadata JSON Schema".
/// @param tokenId NFT to get the URI of
/// @return URI of the NFT
function tokenURI(
uint256 tokenId
) public view virtual override returns (string memory) {
_requireMinted(tokenId);
string memory _tokenURI = _tokenURIs[tokenId];
string memory base = _baseURI();
// If there is no base URI, return the token URI.
if (bytes(base).length == 0) {
return _tokenURI;
}
// If both are set, concatenate the baseURI and tokenURI (via abi.encodePacked).
if (bytes(_tokenURI).length > 0) {
return string(abi.encodePacked(base, _tokenURI));
}
return super.tokenURI(tokenId);
}
/* ========== PRIVATE FUNCTIONS ========== */
function _getName(string memory name) private view returns (string memory) {
return string(bytes.concat(bytes(name), bytes(extension)));
}
function _getTokenId(string memory name) private view returns (uint256) {
string memory lowercaseName = Utils.toLowerCase(name);
if (!nameData[lowercaseName].exists) revert NameNotFound(name);
return nameData[lowercaseName].tokenId;
}
function _setTokenURI(
uint256 tokenId,
string memory _tokenURI
) internal virtual {
if (!_exists(tokenId)) revert TokenNotFound(tokenId);
if (_URIs[_tokenURI]) revert URIAlreadyExists(_tokenURI);
_tokenURIs[tokenId] = _tokenURI;
_URIs[_tokenURI] = true;
}
/* ========== MODIFIERS ========== */
/* ========== EVENTS ========== */
event YearsPeriodRenewed(
uint256 tokenId,
uint256 yearsPeriod,
uint256 newExpirationDate
);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.8;
import "@openzeppelin/contracts/utils/cryptography/draft-EIP712.sol";
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
import "@openzeppelin/contracts/security/Pausable.sol";
import "./libraries/Errors.sol";
import "./dex/PaymentGateway.sol";
import "./interfaces/ISoulboundIdentity.sol";
import "./interfaces/ISoulName.sol";
/// @title Soul Store
/// @author Masa Finance
/// @notice Soul Store, that can mint new Soulbound Identities and Soul Name NFTs, paying a fee
/// @dev From this smart contract we can mint new Soulbound Identities and Soul Name NFTs.
/// This minting can be done paying a fee in ETH, USDC or MASA
contract SoulStore is PaymentGateway, Pausable, ReentrancyGuard, EIP712 {
using SafeMath for uint256;
/* ========== STATE VARIABLES ========== */
ISoulboundIdentity public soulboundIdentity;
ISoulName public soulName;
mapping(uint256 => uint256) public nameRegistrationPricePerYear; // (length --> price in stable coin per year)
mapping(address => bool) public authorities;
/* ========== INITIALIZE ========== */
/// @notice Creates a new Soul Store
/// @dev Creates a new Soul Store, that has the role to minting new Soulbound Identities
/// and Soul Name NFTs, paying a fee
/// @param admin Administrator of the smart contract
/// @param _soulBoundIdentity Address of the Soulbound identity contract
/// @param _soulName Address of the SoulName contract
/// @param _nameRegistrationPricePerYear Price of the default name registering in stable coin per year
/// @param paymentParams Payment gateway params
constructor(
address admin,
ISoulboundIdentity _soulBoundIdentity,
ISoulName _soulName,
uint256 _nameRegistrationPricePerYear,
PaymentParams memory paymentParams
) PaymentGateway(admin, paymentParams) EIP712("SoulStore", "1.0.0") {
if (address(_soulBoundIdentity) == address(0)) revert ZeroAddress();
if (address(_soulName) == address(0)) revert ZeroAddress();
soulboundIdentity = _soulBoundIdentity;
soulName = _soulName;
nameRegistrationPricePerYear[0] = _nameRegistrationPricePerYear; // name price for default length per year
}
/* ========== RESTRICTED FUNCTIONS ========== */
/// @notice Sets the SoulboundIdentity contract address linked to this store
/// @dev The caller must have the admin role to call this function
/// @param _soulboundIdentity New SoulboundIdentity contract address
function setSoulboundIdentity(
ISoulboundIdentity _soulboundIdentity
) external onlyRole(DEFAULT_ADMIN_ROLE) {
if (address(_soulboundIdentity) == address(0)) revert ZeroAddress();
if (soulboundIdentity == _soulboundIdentity) revert SameValue();
soulboundIdentity = _soulboundIdentity;
}
/// @notice Sets the SoulName contract address linked to this store
/// @dev The caller must have the admin role to call this function
/// @param _soulName New SoulName contract address
function setSoulName(
ISoulName _soulName
) external onlyRole(DEFAULT_ADMIN_ROLE) {
if (address(_soulName) == address(0)) revert ZeroAddress();
if (soulName == _soulName) revert SameValue();
soulName = _soulName;
}
/// @notice Sets the price of the name registering per one year in stable coin
/// @dev The caller must have the admin or project admin role to call this function
/// @param _nameLength Length of the name
/// @param _nameRegistrationPricePerYear New price of the name registering per one
/// year in stable coin for that name length per year
function setNameRegistrationPricePerYear(
uint256 _nameLength,
uint256 _nameRegistrationPricePerYear
) external {
if (
!hasRole(DEFAULT_ADMIN_ROLE, _msgSender()) &&
!hasRole(PROJECT_ADMIN_ROLE, _msgSender())
) revert UserMustHaveProtocolOrProjectAdminRole();
if (
nameRegistrationPricePerYear[_nameLength] ==
_nameRegistrationPricePerYear
) revert SameValue();
nameRegistrationPricePerYear[
_nameLength
] = _nameRegistrationPricePerYear;
}
/// @notice Adds a new authority to the list of authorities
/// @dev The caller must have the admin or project admin role to call this function
/// @param _authority New authority to add
function addAuthority(address _authority) external {
if (
!hasRole(DEFAULT_ADMIN_ROLE, _msgSender()) &&
!hasRole(PROJECT_ADMIN_ROLE, _msgSender())
) revert UserMustHaveProtocolOrProjectAdminRole();
if (_authority == address(0)) revert ZeroAddress();
if (authorities[_authority]) revert AlreadyAdded();
authorities[_authority] = true;
}
/// @notice Removes an authority from the list of authorities
/// @dev The caller must have the admin or project admin role to call this function
/// @param _authority Authority to remove
function removeAuthority(address _authority) external {
if (
!hasRole(DEFAULT_ADMIN_ROLE, _msgSender()) &&
!hasRole(PROJECT_ADMIN_ROLE, _msgSender())
) revert UserMustHaveProtocolOrProjectAdminRole();
if (_authority == address(0)) revert ZeroAddress();
if (!authorities[_authority]) revert AuthorityNotExists(_authority);
authorities[_authority] = false;
}
/// @notice Pauses the smart contract
/// @dev The caller must have the admin role to call this function
function pause() external onlyRole(DEFAULT_ADMIN_ROLE) {
_pause();
}
/// @notice Unpauses the smart contract
/// @dev The caller must have the admin role to call this function
function unpause() external onlyRole(DEFAULT_ADMIN_ROLE) {
_unpause();
}
/* ========== MUTATIVE FUNCTIONS ========== */
/// @notice Mints a new Soulbound Identity and Name purchasing it
/// @dev This function allows the purchase of a soulbound identity and name using
/// stable coin (USDC), native token (ETH) or utility token (MASA)
/// @param paymentMethod Address of token that user want to pay
/// @param name Name of the new soul name
/// @param nameLength Length of the name
/// @param yearsPeriod Years of validity of the name
/// @param tokenURI URI of the NFT
/// @param authorityAddress Address of the authority
/// @param signature Signature of the authority
/// @return TokenId of the new soulbound identity
function purchaseIdentityAndName(
address paymentMethod,
string memory name,
uint256 nameLength,
uint256 yearsPeriod,
string memory tokenURI,
address authorityAddress,
bytes calldata signature
) external payable virtual whenNotPaused nonReentrant returns (uint256) {
(
uint256 price,
uint256 protocolFee
) = getPriceForMintingNameWithProtocolFee(
paymentMethod,
nameLength,
yearsPeriod
);
_pay(paymentMethod, price, protocolFee);
// finalize purchase
uint256 tokenId = _mintSoulboundIdentityAndName(
_msgSender(),
name,
nameLength,
yearsPeriod,
tokenURI,
authorityAddress,
signature
);
emit SoulboundIdentityAndNamePurchased(
_msgSender(),
tokenId,
name,
yearsPeriod,
paymentMethod,
price,
protocolFee
);
return tokenId;
}
/// @notice Mints a new Soulbound Identity purchasing it
/// @dev This function allows the purchase of a soulbound identity for free
/// @return TokenId of the new soulbound identity
function purchaseIdentity() external virtual returns (uint256) {
uint256 tokenId = _mintSoulboundIdentity(_msgSender());
emit SoulboundIdentityPurchased(_msgSender(), tokenId);
return tokenId;
}
/// @notice Mints a new Soul Name purchasing it
/// @dev This function allows the purchase of a soul name using
/// stable coin (USDC), native token (ETH) or utility token (MASA)
/// @param paymentMethod Address of token that user want to pay
/// @param to Address of the owner of the new soul name
/// @param name Name of the new soul name
/// @param nameLength Length of the name
/// @param yearsPeriod Years of validity of the name
/// @param tokenURI URI of the NFT
/// @param authorityAddress Address of the authority
/// @param signature Signature of the authority
/// @return TokenId of the new sou name
function purchaseName(
address paymentMethod,
address to,
string memory name,
uint256 nameLength,
uint256 yearsPeriod,
string memory tokenURI,
address authorityAddress,
bytes calldata signature
) external payable virtual whenNotPaused nonReentrant returns (uint256) {
(
uint256 price,
uint256 protocolFee
) = getPriceForMintingNameWithProtocolFee(
paymentMethod,
nameLength,
yearsPeriod
);
_pay(paymentMethod, price, protocolFee);
// finalize purchase
uint256 tokenId = _mintSoulName(
to,
name,
nameLength,
yearsPeriod,
tokenURI,
authorityAddress,
signature
);
emit SoulNamePurchased(
to,
tokenId,
name,
yearsPeriod,
paymentMethod,
price,
protocolFee
);
return tokenId;
}
/* ========== VIEWS ========== */
/// @notice Returns the price of register a name per year in stable coin for an specific length
/// @dev Returns the price for registering per year in USD for an specific name length
/// @param nameLength Length of the name
/// @return Price in stable coin for that name length
function getNameRegistrationPricePerYear(
uint256 nameLength
) public view returns (uint256) {
uint256 price = nameRegistrationPricePerYear[nameLength];
if (price == 0) {
// if not found, return the default price
price = nameRegistrationPricePerYear[0];
}
return price;
}
/// @notice Returns the price of the name minting
/// @dev Returns current pricing for name minting for a given name length and years period
/// @param paymentMethod Address of token that user want to pay
/// @param nameLength Length of the name
/// @param yearsPeriod Years of validity of the name
/// @return price Current price of the name minting in the given payment method
function getPriceForMintingName(
address paymentMethod,
uint256 nameLength,
uint256 yearsPeriod
) public view virtual returns (uint256 price) {
uint256 mintPrice = getNameRegistrationPricePerYear(nameLength).mul(
yearsPeriod
);
if (mintPrice == 0) {
price = 0;
} else if (
paymentMethod == stableCoin && enabledPaymentMethod[paymentMethod]
) {
// stable coin
price = mintPrice;
} else if (enabledPaymentMethod[paymentMethod]) {
// ETH and ERC 20 token
price = _convertFromStableCoin(paymentMethod, mintPrice);
} else {
revert InvalidPaymentMethod(paymentMethod);
}
return price;
}
/// @notice Returns the price of the name minting with protocol fee
/// @dev Returns current pricing for name minting for a given name length and years period with protocol fee
/// @param paymentMethod Address of token that user want to pay
/// @param nameLength Length of the name
/// @param yearsPeriod Years of validity of the name
/// @return price Current price of the name minting in the given payment method
/// @return protocolFee Current protocol fee of the name minting in the given payment method
function getPriceForMintingNameWithProtocolFee(
address paymentMethod,
uint256 nameLength,
uint256 yearsPeriod
) public view virtual returns (uint256 price, uint256 protocolFee) {
price = getPriceForMintingName(paymentMethod, nameLength, yearsPeriod);
return (price, _getProtocolFee(paymentMethod, price));
}
/* ========== PRIVATE FUNCTIONS ========== */
/// @notice Mints a new Soulbound Identity and Name
/// @dev The final step of all purchase options. Will mint a
/// new Soulbound Identity and a Soul Name NFT
/// @param to Address of the owner of the new soul name
/// @param name Name of the new soul name
/// @param nameLength Length of the name
/// @param yearsPeriod Years of validity of the name
/// @param tokenURI URI of the NFT
/// @param authorityAddress Address of the authority
/// @param signature Signature of the authority
/// @return TokenId of the new soulbound identity
function _mintSoulboundIdentityAndName(
address to,
string memory name,
uint256 nameLength,
uint256 yearsPeriod,
string memory tokenURI,
address authorityAddress,
bytes calldata signature
) internal virtual returns (uint256) {
_verify(
_hash(to, name, nameLength, yearsPeriod, tokenURI),
signature,
authorityAddress
);
// mint Soulbound identity token
uint256 tokenId = soulboundIdentity.mint(to);
// mint Soul Name token
soulName.mint(to, name, yearsPeriod, tokenURI);
return tokenId;
}
/// @notice Mints a new Soulbound Identity
/// @dev The final step of all purchase options. Will mint a
/// new Soulbound Identity
/// @param to Address of the owner of the new identity
/// @return TokenId of the new soulbound identity
function _mintSoulboundIdentity(
address to
) internal virtual returns (uint256) {
// mint Soulbound identity token
uint256 tokenId = soulboundIdentity.mint(to);
return tokenId;
}
/// @notice Mints a new Soul Name
/// @dev The final step of all purchase options. Will mint a
/// new Soul Name NFT
/// @param to Address of the owner of the new soul name
/// @param name Name of the new soul name
/// @param nameLength Length of the name
/// @param yearsPeriod Years of validity of the name
/// @param tokenURI URI of the NFT
/// @param authorityAddress Address of the authority
/// @param signature Signature of the authority
/// @return TokenId of the new soul name
function _mintSoulName(
address to,
string memory name,
uint256 nameLength,
uint256 yearsPeriod,
string memory tokenURI,
address authorityAddress,
bytes calldata signature
) internal virtual returns (uint256) {
_verify(
_hash(to, name, nameLength, yearsPeriod, tokenURI),
signature,
authorityAddress
);
// mint Soul Name token
uint256 tokenId = soulName.mint(to, name, yearsPeriod, tokenURI);
return tokenId;
}
function _verify(
bytes32 digest,
bytes memory signature,
address signer
) internal view {
address _signer = ECDSA.recover(digest, signature);
if (_signer != signer) revert InvalidSignature();
if (!authorities[_signer]) revert NotAuthorized(_signer);
}
function _hash(
address to,
string memory name,
uint256 nameLength,
uint256 yearsPeriod,
string memory tokenURI
) internal view returns (bytes32) {
return
_hashTypedDataV4(
keccak256(
abi.encode(
keccak256(
"MintSoulName(address to,string name,uint256 nameLength,uint256 yearsPeriod,string tokenURI)"
),
to,
keccak256(bytes(name)),
nameLength,
yearsPeriod,
keccak256(bytes(tokenURI))
)
)
);
}
/* ========== MODIFIERS ========== */
/* ========== EVENTS ========== */
event SoulboundIdentityAndNamePurchased(
address indexed account,
uint256 tokenId,
string indexed name,
uint256 yearsPeriod,
address indexed paymentMethod,
uint256 price,
uint256 protocolFee
);
event SoulboundIdentityPurchased(address indexed account, uint256 tokenId);
event SoulNamePurchased(
address indexed account,
uint256 tokenId,
string indexed name,
uint256 yearsPeriod,
address indexed paymentMethod,
uint256 price,
uint256 protocolFee
);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.8;
import "@openzeppelin/contracts/token/ERC721/ERC721.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol";
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Burnable.sol";
import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts/access/AccessControl.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
import "@openzeppelin/contracts/utils/Strings.sol";
/// @title MasaNFT
/// @author Masa Finance
/// @notice Non-fungible token is a token that is not fungible.
/// @dev Implementation of https://eips.ethereum.org/EIPS/eip-721[ERC721] Non-Fungible Token Standard,
/// that inherits from {ERC721Enumerable}, {Ownable}, {AccessControl} and {ERC721Burnable}.
abstract contract MasaNFT is
ERC721,
ERC721Enumerable,
Ownable,
AccessControl,
ERC721Burnable
{
/* ========== STATE VARIABLES =========================================== */
using Strings for uint256;
using Counters for Counters.Counter;
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
Counters.Counter private _tokenIdCounter;
string private _baseTokenURI;
/* ========== INITIALIZE ================================================ */
/// @notice Creates a new NFT
/// @dev Creates a new Non-fungible token
/// @param admin Administrator of the smart contract
/// @param name Name of the token
/// @param symbol Symbol of the token
/// @param baseTokenURI Base URI of the token
constructor(
address admin,
string memory name,
string memory symbol,
string memory baseTokenURI
) ERC721(name, symbol) {
Ownable.transferOwnership(admin);
_grantRole(DEFAULT_ADMIN_ROLE, admin);
_grantRole(MINTER_ROLE, admin);
_baseTokenURI = baseTokenURI;
}
/* ========== RESTRICTED FUNCTIONS ====================================== */
function _mintWithCounter(
address to
) internal onlyRole(MINTER_ROLE) returns (uint256) {
uint256 tokenId = _tokenIdCounter.current();
_tokenIdCounter.increment();
_safeMint(to, tokenId);
return tokenId;
}
/* ========== MUTATIVE FUNCTIONS ======================================== */
/* ========== VIEWS ===================================================== */
/// @notice Returns true if the token exists
/// @dev Returns true if the token has been minted
/// @param tokenId Token to check
/// @return True if the token exists
function exists(uint256 tokenId) external view returns (bool) {
return _exists(tokenId);
}
/// @notice A distinct Uniform Resource Identifier (URI) for a given asset.
/// @dev Throws if `_tokenId` is not a valid NFT. URIs are defined in RFC
/// 3986. The URI may point to a JSON file that conforms to the "ERC721
/// Metadata JSON Schema".
/// @param tokenId NFT to get the URI of
/// @return URI of the NFT
function tokenURI(
uint256 tokenId
) public view virtual override returns (string memory) {
_requireMinted(tokenId);
string memory baseURI = _baseURI();
return
bytes(baseURI).length > 0
? string(abi.encodePacked(baseURI, tokenId.toString(), ".json"))
: "";
}
/// @notice Query if a contract implements an interface
/// @dev Interface identification is specified in ERC-165.
/// @param interfaceId The interface identifier, as specified in ERC-165
/// @return `true` if the contract implements `interfaceId` and
/// `interfaceId` is not 0xffffffff, `false` otherwise
function supportsInterface(
bytes4 interfaceId
)
public
view
virtual
override(ERC721, ERC721Enumerable, AccessControl)
returns (bool)
{
return super.supportsInterface(interfaceId);
}
/* ========== PRIVATE FUNCTIONS ========================================= */
function _baseURI() internal view virtual override returns (string memory) {
return _baseTokenURI;
}
function _beforeTokenTransfer(
address from,
address to,
uint256 firstTokenId,
uint256 batchSize
) internal virtual override(ERC721, ERC721Enumerable) {
super._beforeTokenTransfer(from, to, firstTokenId, batchSize);
}
/* ========== MODIFIERS ================================================= */
/* ========== EVENTS ==================================================== */
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.8;
import "@openzeppelin/contracts/utils/Strings.sol";
import "../dex/PaymentGateway.sol";
import "../libraries/Errors.sol";
import "../interfaces/ISoulboundIdentity.sol";
import "../interfaces/ILinkableSBT.sol";
import "./SBT/SBT.sol";
import "./SBT/extensions/SBTEnumerable.sol";
import "./SBT/extensions/SBTBurnable.sol";
/// @title MasaSBT
/// @author Masa Finance
/// @notice Soulbound token. Non-fungible token that is not transferable.
/// @dev Implementation of https://papers.ssrn.com/sol3/papers.cfm?abstract_id=4105763 Soulbound token.
/// Adds a link to a SoulboundIdentity SC to let minting using the identityId
/// Adds a payment gateway to let minting paying a fee
abstract contract MasaSBT is
PaymentGateway,
SBT,
SBTEnumerable,
SBTBurnable,
ILinkableSBT
{
/* ========== STATE VARIABLES =========================================== */
using Strings for uint256;
string private _baseTokenURI;
ISoulboundIdentity public soulboundIdentity;
uint256 public mintPrice; // price in stable coin
uint256 public mintPriceMASA; // price in MASA
uint256 public override addLinkPrice; // price in stable coin
uint256 public override addLinkPriceMASA; // price in MASA
uint256 public override queryLinkPrice; // price in stable coin
uint256 public override queryLinkPriceMASA; // price in MASA
/* ========== INITIALIZE ================================================ */
/// @notice Creates a new soulbound token
/// @dev Creates a new soulbound token
/// @param admin Administrator of the smart contract
/// @param name Name of the token
/// @param symbol Symbol of the token
/// @param baseTokenURI Base URI of the token
/// @param _soulboundIdentity Address of the SoulboundIdentity contract
/// @param paymentParams Payment gateway params
constructor(
address admin,
string memory name,
string memory symbol,
string memory baseTokenURI,
address _soulboundIdentity,
PaymentParams memory paymentParams
) SBT(name, symbol) PaymentGateway(admin, paymentParams) {
_grantRole(DEFAULT_ADMIN_ROLE, admin);
_baseTokenURI = baseTokenURI;
soulboundIdentity = ISoulboundIdentity(_soulboundIdentity);
}
/* ========== RESTRICTED FUNCTIONS ====================================== */
/// @notice Sets the price of minting in stable coin
/// @dev The caller must have the admin or project admin role to call this function
/// @param _mintPrice New price of minting in stable coin
function setMintPrice(uint256 _mintPrice) external {
if (
!hasRole(DEFAULT_ADMIN_ROLE, _msgSender()) &&
!hasRole(PROJECT_ADMIN_ROLE, _msgSender())
) revert UserMustHaveProtocolOrProjectAdminRole();
if (mintPrice == _mintPrice) revert SameValue();
mintPrice = _mintPrice;
}
/// @notice Sets the price of minting in MASA
/// @dev The caller must have the admin or project admin role to call this function
/// @param _mintPriceMASA New price of minting in MASA
function setMintPriceMASA(uint256 _mintPriceMASA) external {
if (
!hasRole(DEFAULT_ADMIN_ROLE, _msgSender()) &&
!hasRole(PROJECT_ADMIN_ROLE, _msgSender())
) revert UserMustHaveProtocolOrProjectAdminRole();
if (mintPriceMASA == _mintPriceMASA) revert SameValue();
mintPriceMASA = _mintPriceMASA;
}
/// @notice Sets the SoulboundIdentity contract address linked to this SBT
/// @dev The caller must be the admin to call this function
/// @param _soulboundIdentity Address of the SoulboundIdentity contract
function setSoulboundIdentity(
address _soulboundIdentity
) external onlyRole(DEFAULT_ADMIN_ROLE) {
if (address(soulboundIdentity) == _soulboundIdentity)
revert SameValue();
soulboundIdentity = ISoulboundIdentity(_soulboundIdentity);
}
/// @notice Sets the price for adding the link in SoulLinker in stable coin
/// @dev The caller must have the admin or project admin role to call this function
/// @param _addLinkPrice New price for adding the link in SoulLinker in stable coin
function setAddLinkPrice(uint256 _addLinkPrice) external {
if (
!hasRole(DEFAULT_ADMIN_ROLE, _msgSender()) &&
!hasRole(PROJECT_ADMIN_ROLE, _msgSender())
) revert UserMustHaveProtocolOrProjectAdminRole();
if (addLinkPrice == _addLinkPrice) revert SameValue();
addLinkPrice = _addLinkPrice;
}
/// @notice Sets the price for adding the link in SoulLinker in MASA
/// @dev The caller must have the admin or project admin role to call this function
/// @param _addLinkPriceMASA New price for adding the link in SoulLinker in MASA
function setAddLinkPriceMASA(uint256 _addLinkPriceMASA) external {
if (
!hasRole(DEFAULT_ADMIN_ROLE, _msgSender()) &&
!hasRole(PROJECT_ADMIN_ROLE, _msgSender())
) revert UserMustHaveProtocolOrProjectAdminRole();
if (addLinkPriceMASA == _addLinkPriceMASA) revert SameValue();
addLinkPriceMASA = _addLinkPriceMASA;
}
/// @notice Sets the price for reading data in SoulLinker in stable coin
/// @dev The caller must have the admin or project admin role to call this function
/// @param _queryLinkPrice New price for reading data in SoulLinker in stable coin
function setQueryLinkPrice(uint256 _queryLinkPrice) external {
if (
!hasRole(DEFAULT_ADMIN_ROLE, _msgSender()) &&
!hasRole(PROJECT_ADMIN_ROLE, _msgSender())
) revert UserMustHaveProtocolOrProjectAdminRole();
if (queryLinkPrice == _queryLinkPrice) revert SameValue();
queryLinkPrice = _queryLinkPrice;
}
/// @notice Sets the price for reading data in SoulLinker in MASA
/// @dev The caller must have the admin or project admin role to call this function
/// @param _queryLinkPriceMASA New price for reading data in SoulLinker in MASA
function setQueryLinkPriceMASA(uint256 _queryLinkPriceMASA) external {
if (
!hasRole(DEFAULT_ADMIN_ROLE, _msgSender()) &&
!hasRole(PROJECT_ADMIN_ROLE, _msgSender())
) revert UserMustHaveProtocolOrProjectAdminRole();
if (queryLinkPriceMASA == _queryLinkPriceMASA) revert SameValue();
queryLinkPriceMASA = _queryLinkPriceMASA;
}
/* ========== MUTATIVE FUNCTIONS ======================================== */
/* ========== VIEWS ===================================================== */
/// @notice Returns the identityId owned by the given token
/// @param tokenId Id of the token
/// @return Id of the identity
function getIdentityId(uint256 tokenId) external view returns (uint256) {
if (soulboundIdentity == ISoulboundIdentity(address(0)))
revert NotLinkedToAnIdentitySBT();
address owner = super.ownerOf(tokenId);
return soulboundIdentity.tokenOfOwner(owner);
}
/// @notice Returns true if the token exists
/// @dev Returns true if the token has been minted
/// @param tokenId Token to check
/// @return True if the token exists
function exists(uint256 tokenId) external view returns (bool) {
return _exists(tokenId);
}
/// @notice A distinct Uniform Resource Identifier (URI) for a given asset.
/// @dev Throws if `_tokenId` is not a valid SBT. URIs are defined in RFC
/// 3986. The URI may point to a JSON file that conforms to the "ERC721
/// Metadata JSON Schema".
/// @param tokenId SBT to get the URI of
/// @return URI of the SBT
function tokenURI(
uint256 tokenId
) public view virtual override returns (string memory) {
_requireMinted(tokenId);
string memory baseURI = _baseURI();
return
bytes(baseURI).length > 0
? string(abi.encodePacked(baseURI, tokenId.toString(), ".json"))
: "";
}
/// @notice Query if a contract implements an interface
/// @dev Interface identification is specified in ERC-165.
/// @param interfaceId The interface identifier, as specified in ERC-165
/// @return `true` if the contract implements `interfaceId` and
/// `interfaceId` is not 0xffffffff, `false` otherwise
function supportsInterface(
bytes4 interfaceId
)
public
view
virtual
override(SBT, SBTEnumerable, AccessControl, IERC165)
returns (bool)
{
return super.supportsInterface(interfaceId);
}
/// @notice Returns the price for minting
/// @dev Returns current pricing for minting
/// @param paymentMethod Address of token that user want to pay
/// @return price Current price for minting in the given payment method
function getMintPrice(
address paymentMethod
) public view returns (uint256 price) {
if (mintPrice == 0 && mintPriceMASA == 0) {
price = 0;
} else if (
paymentMethod == masaToken &&
enabledPaymentMethod[paymentMethod] &&
mintPriceMASA > 0
) {
// price in MASA without conversion rate
price = mintPriceMASA;
} else if (
paymentMethod == stableCoin && enabledPaymentMethod[paymentMethod]
) {
// stable coin
price = mintPrice;
} else if (enabledPaymentMethod[paymentMethod]) {
// ETH and ERC 20 token
price = _convertFromStableCoin(paymentMethod, mintPrice);
} else {
revert InvalidPaymentMethod(paymentMethod);
}
return price;
}
/// @notice Returns the price for minting with protocol fee
/// @dev Returns current pricing for minting with protocol fee
/// @param paymentMethod Address of token that user want to pay
/// @return price Current price for minting in the given payment method
/// @return protocolFee Current protocol fee for minting in the given payment method
function getMintPriceWithProtocolFee(
address paymentMethod
) public view returns (uint256 price, uint256 protocolFee) {
price = getMintPrice(paymentMethod);
return (price, _getProtocolFee(paymentMethod, price));
}
/* ========== PRIVATE FUNCTIONS ========================================= */
function _baseURI() internal view virtual override returns (string memory) {
return _baseTokenURI;
}
function _beforeTokenTransfer(
address from,
address to,
uint256 tokenId
) internal virtual override(SBT, SBTEnumerable) {
super._beforeTokenTransfer(from, to, tokenId);
}
/* ========== MODIFIERS ================================================= */
/* ========== EVENTS ==================================================== */
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.8;
import "@openzeppelin/contracts/utils/Counters.sol";
import "./MasaSBT.sol";
/// @title MasaSBT
/// @author Masa Finance
/// @notice Soulbound token. Non-fungible token that is not transferable.
/// @dev Implementation of https://papers.ssrn.com/sol3/papers.cfm?abstract_id=4105763 Soulbound token.
abstract contract MasaSBTAuthority is MasaSBT {
/* ========== STATE VARIABLES =========================================== */
using Counters for Counters.Counter;
bytes32 public constant MINTER_ROLE = keccak256("MINTER_ROLE");
Counters.Counter private _tokenIdCounter;
/* ========== INITIALIZE ================================================ */
/// @notice Creates a new soulbound token
/// @dev Creates a new soulbound token
/// @param admin Administrator of the smart contract
/// @param name Name of the token
/// @param symbol Symbol of the token
/// @param baseTokenURI Base URI of the token
/// @param soulboundIdentity Address of the SoulboundIdentity contract
/// @param paymentParams Payment gateway params
constructor(
address admin,
string memory name,
string memory symbol,
string memory baseTokenURI,
address soulboundIdentity,
PaymentParams memory paymentParams
)
MasaSBT(
admin,
name,
symbol,
baseTokenURI,
soulboundIdentity,
paymentParams
)
{
_grantRole(MINTER_ROLE, admin);
}
/* ========== RESTRICTED FUNCTIONS ====================================== */
function _mintWithCounter(
address paymentMethod,
address to
) internal virtual onlyRole(MINTER_ROLE) returns (uint256) {
(uint256 price, uint256 protocolFee) = getMintPriceWithProtocolFee(
paymentMethod
);
_pay(paymentMethod, price, protocolFee);
uint256 tokenId = _tokenIdCounter.current();
_tokenIdCounter.increment();
_mint(to, tokenId);
return tokenId;
}
/* ========== MUTATIVE FUNCTIONS ======================================== */
/* ========== VIEWS ===================================================== */
/* ========== PRIVATE FUNCTIONS ========================================= */
/* ========== MODIFIERS ================================================= */
/* ========== EVENTS ==================================================== */
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.8;
import "@openzeppelin/contracts/utils/cryptography/draft-EIP712.sol";
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import "@openzeppelin/contracts/utils/Counters.sol";
import "../libraries/Errors.sol";
import "./MasaSBT.sol";
/// @title MasaSBTSelfSovereign
/// @author Masa Finance
/// @notice Soulbound token. Non-fungible token that is not transferable.
/// Adds a self-sovereign protocol to let minting using an authority signature
/// @dev Implementation of https://papers.ssrn.com/sol3/papers.cfm?abstract_id=4105763 Soulbound token.
abstract contract MasaSBTSelfSovereign is MasaSBT, EIP712 {
/* ========== STATE VARIABLES =========================================== */
using Counters for Counters.Counter;
Counters.Counter private _tokenIdCounter;
mapping(address => bool) public authorities;
/* ========== INITIALIZE ================================================ */
/// @notice Creates a new soulbound token
/// @dev Creates a new soulbound token
/// @param admin Administrator of the smart contract
/// @param name Name of the token
/// @param symbol Symbol of the token
/// @param baseTokenURI Base URI of the token
/// @param soulboundIdentity Address of the SoulboundIdentity contract
/// @param paymentParams Payment gateway params
constructor(
address admin,
string memory name,
string memory symbol,
string memory baseTokenURI,
address soulboundIdentity,
PaymentParams memory paymentParams
)
MasaSBT(
admin,
name,
symbol,
baseTokenURI,
soulboundIdentity,
paymentParams
)
{}
/* ========== RESTRICTED FUNCTIONS ====================================== */
/// @notice Adds a new authority to the list of authorities
/// @dev The caller must have the admin or project admin role to call this function
/// @param _authority New authority to add
function addAuthority(address _authority) external {
if (
!hasRole(DEFAULT_ADMIN_ROLE, _msgSender()) &&
!hasRole(PROJECT_ADMIN_ROLE, _msgSender())
) revert UserMustHaveProtocolOrProjectAdminRole();
if (_authority == address(0)) revert ZeroAddress();
if (authorities[_authority]) revert AlreadyAdded();
authorities[_authority] = true;
}
/// @notice Removes an authority from the list of authorities
/// @dev The caller must have the admin or project admin role to call this function
/// @param _authority Authority to remove
function removeAuthority(address _authority) external {
if (
!hasRole(DEFAULT_ADMIN_ROLE, _msgSender()) &&
!hasRole(PROJECT_ADMIN_ROLE, _msgSender())
) revert UserMustHaveProtocolOrProjectAdminRole();
if (_authority == address(0)) revert ZeroAddress();
if (!authorities[_authority]) revert AuthorityNotExists(_authority);
authorities[_authority] = false;
}
/* ========== MUTATIVE FUNCTIONS ======================================== */
/* ========== VIEWS ===================================================== */
/* ========== PRIVATE FUNCTIONS ========================================= */
function _verify(
bytes32 digest,
bytes memory signature,
address signer
) private view {
address _signer = ECDSA.recover(digest, signature);
if (_signer != signer) revert InvalidSignature();
if (!authorities[_signer]) revert NotAuthorized(_signer);
}
function _mintWithCounter(
address paymentMethod,
address to,
bytes32 digest,
address authorityAddress,
bytes calldata signature
) internal virtual returns (uint256) {
_verify(digest, signature, authorityAddress);
(uint256 price, uint256 protocolFee) = getMintPriceWithProtocolFee(
paymentMethod
);
_pay(paymentMethod, price, protocolFee);
uint256 tokenId = _tokenIdCounter.current();
_tokenIdCounter.increment();
_mint(to, tokenId);
return tokenId;
}
/* ========== MODIFIERS ================================================= */
/* ========== EVENTS ==================================================== */
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.8;
import "../ISBT.sol";
/**
* @title SBT Soulbound Token Standard, optional enumeration extension
*/
interface ISBTEnumerable is ISBT {
/**
* @dev Returns the total amount of tokens stored by the contract.
*/
function totalSupply() external view returns (uint256);
/**
* @dev Returns a token ID owned by `owner` at a given `index` of its token list.
* Use along with {balanceOf} to enumerate all of ``owner``'s tokens.
*/
function tokenOfOwnerByIndex(
address owner,
uint256 index
) external view returns (uint256);
/**
* @dev Returns a token ID at a given `index` of all the tokens stored by the contract.
* Use along with {totalSupply} to enumerate all tokens.
*/
function tokenByIndex(uint256 index) external view returns (uint256);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.8;
import "../ISBT.sol";
/**
* @title SBT Soulbound Token Standard, optional metadata extension
*/
interface ISBTMetadata is ISBT {
/**
* @dev Returns the token collection name.
*/
function name() external view returns (string memory);
/**
* @dev Returns the token collection symbol.
*/
function symbol() external view returns (string memory);
/**
* @dev Returns the Uniform Resource Identifier (URI) for `tokenId` token.
*/
function tokenURI(uint256 tokenId) external view returns (string memory);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.8;
import "@openzeppelin/contracts/utils/Context.sol";
import "../SBT.sol";
/**
* @title SBT Burnable Token
* @dev SBT Token that can be burned (destroyed).
*/
abstract contract SBTBurnable is Context, SBT {
/**
* @dev Burns `tokenId`. See {SBT-_burn}.
*
* Requirements:
*
* - The caller must own `tokenId` or be an approved operator.
*/
function burn(uint256 tokenId) public virtual {
//solhint-disable-next-line max-line-length
require(
_isOwner(_msgSender(), tokenId),
"SBT: caller is not token owner"
);
_burn(tokenId);
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.8;
import "../SBT.sol";
import "./ISBTEnumerable.sol";
/**
* @dev This implements an optional extension of {SBT} defined in the EIP that adds
* enumerability of all the token ids in the contract as well as all token ids owned by each
* account.
*/
abstract contract SBTEnumerable is SBT, ISBTEnumerable {
// Mapping from owner to list of owned token IDs
mapping(address => mapping(uint256 => uint256)) private _ownedTokens;
// Mapping from token ID to index of the owner tokens list
mapping(uint256 => uint256) private _ownedTokensIndex;
// Array with all token ids, used for enumeration
uint256[] private _allTokens;
// Mapping from token id to position in the allTokens array
mapping(uint256 => uint256) private _allTokensIndex;
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(
bytes4 interfaceId
) public view virtual override(IERC165, SBT) returns (bool) {
return
interfaceId == type(ISBTEnumerable).interfaceId ||
super.supportsInterface(interfaceId);
}
/**
* @dev See {ISBTEnumerable-tokenOfOwnerByIndex}.
*/
function tokenOfOwnerByIndex(
address owner,
uint256 index
) public view virtual override returns (uint256) {
require(
index < SBT.balanceOf(owner),
"SBTEnumerable: owner index out of bounds"
);
return _ownedTokens[owner][index];
}
/**
* @dev See {ISBTEnumerable-totalSupply}.
*/
function totalSupply() public view virtual override returns (uint256) {
return _allTokens.length;
}
/**
* @dev See {ISBTEnumerable-tokenByIndex}.
*/
function tokenByIndex(
uint256 index
) public view virtual override returns (uint256) {
require(
index < SBTEnumerable.totalSupply(),
"SBTEnumerable: global index out of bounds"
);
return _allTokens[index];
}
/**
* @dev Hook that is called before any token transfer. This includes minting
* and burning.
*
* Calling conditions:
*
* - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be
* transferred to `to`.
* - When `from` is zero, `tokenId` will be minted for `to`.
* - When `to` is zero, ``from``'s `tokenId` will be burned.
* - `from` cannot be the zero address.
* - `to` cannot be the zero address.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(
address from,
address to,
uint256 tokenId
) internal virtual override {
super._beforeTokenTransfer(from, to, tokenId);
if (from == address(0)) {
_addTokenToAllTokensEnumeration(tokenId);
} else if (from != to) {
_removeTokenFromOwnerEnumeration(from, tokenId);
}
if (to == address(0)) {
_removeTokenFromAllTokensEnumeration(tokenId);
} else if (to != from) {
_addTokenToOwnerEnumeration(to, tokenId);
}
}
/**
* @dev Private function to add a token to this extension's ownership-tracking data structures.
* @param to address representing the new owner of the given token ID
* @param tokenId uint256 ID of the token to be added to the tokens list of the given address
*/
function _addTokenToOwnerEnumeration(address to, uint256 tokenId) private {
uint256 length = SBT.balanceOf(to);
_ownedTokens[to][length] = tokenId;
_ownedTokensIndex[tokenId] = length;
}
/**
* @dev Private function to add a token to this extension's token tracking data structures.
* @param tokenId uint256 ID of the token to be added to the tokens list
*/
function _addTokenToAllTokensEnumeration(uint256 tokenId) private {
_allTokensIndex[tokenId] = _allTokens.length;
_allTokens.push(tokenId);
}
/**
* @dev Private function to remove a token from this extension's ownership-tracking data structures. Note that
* while the token is not assigned a new owner, the `_ownedTokensIndex` mapping is _not_ updated: this allows for
* gas optimizations e.g. when performing a transfer operation (avoiding double writes).
* This has O(1) time complexity, but alters the order of the _ownedTokens array.
* @param from address representing the previous owner of the given token ID
* @param tokenId uint256 ID of the token to be removed from the tokens list of the given address
*/
function _removeTokenFromOwnerEnumeration(
address from,
uint256 tokenId
) private {
// To prevent a gap in from's tokens array, we store the last token in the index of the token to delete, and
// then delete the last slot (swap and pop).
uint256 lastTokenIndex = SBT.balanceOf(from) - 1;
uint256 tokenIndex = _ownedTokensIndex[tokenId];
// When the token to delete is the last token, the swap operation is unnecessary
if (tokenIndex != lastTokenIndex) {
uint256 lastTokenId = _ownedTokens[from][lastTokenIndex];
_ownedTokens[from][tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token
_ownedTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index
}
// This also deletes the contents at the last position of the array
delete _ownedTokensIndex[tokenId];
delete _ownedTokens[from][lastTokenIndex];
}
/**
* @dev Private function to remove a token from this extension's token tracking data structures.
* This has O(1) time complexity, but alters the order of the _allTokens array.
* @param tokenId uint256 ID of the token to be removed from the tokens list
*/
function _removeTokenFromAllTokensEnumeration(uint256 tokenId) private {
// To prevent a gap in the tokens array, we store the last token in the index of the token to delete, and
// then delete the last slot (swap and pop).
uint256 lastTokenIndex = _allTokens.length - 1;
uint256 tokenIndex = _allTokensIndex[tokenId];
// When the token to delete is the last token, the swap operation is unnecessary. However, since this occurs so
// rarely (when the last minted token is burnt) that we still do the swap here to avoid the gas cost of adding
// an 'if' statement (like in _removeTokenFromOwnerEnumeration)
uint256 lastTokenId = _allTokens[lastTokenIndex];
_allTokens[tokenIndex] = lastTokenId; // Move the last token to the slot of the to-delete token
_allTokensIndex[lastTokenId] = tokenIndex; // Update the moved token's index
// This also deletes the contents at the last position of the array
delete _allTokensIndex[tokenId];
_allTokens.pop();
}
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.8;
import "@openzeppelin/contracts/utils/introspection/IERC165.sol";
interface ISBT is IERC165 {
/// @dev This emits when an SBT is newly minted.
/// This event emits when SBTs are created
event Mint(address indexed _owner, uint256 indexed _tokenId);
/// @dev This emits when an SBT is burned
/// This event emits when SBTs are destroyed
event Burn(address indexed _owner, uint256 indexed _tokenId);
/// @notice Count all SBTs assigned to an owner
/// @dev SBTs assigned to the zero address are considered invalid, and this
/// function throws for queries about the zero address.
/// @param _owner An address for whom to query the balance
/// @return The number of SBTs owned by `_owner`, possibly zero
function balanceOf(address _owner) external view returns (uint256);
/// @notice Find the owner of an SBT
/// @dev SBTs assigned to zero address are considered invalid, and queries
/// about them do throw.
/// @param _tokenId The identifier for an SBT
/// @return The address of the owner of the SBT
function ownerOf(uint256 _tokenId) external view returns (address);
}// SPDX-License-Identifier: MIT
pragma solidity ^0.8.8;
import "@openzeppelin/contracts/utils/introspection/ERC165.sol";
import "@openzeppelin/contracts/utils/Context.sol";
import "@openzeppelin/contracts/utils/Strings.sol";
import "./ISBT.sol";
import "./extensions/ISBTMetadata.sol";
/// @title SBT
/// @author Masa Finance
/// @notice Soulbound token is an NFT token that is not transferable.
contract SBT is Context, ERC165, ISBT, ISBTMetadata {
using Strings for uint256;
// Token name
string private _name;
// Token symbol
string private _symbol;
// Mapping from token ID to owner address
mapping(uint256 => address) private _owners;
// Mapping owner address to token count
mapping(address => uint256) private _balances;
/**
* @dev Initializes the contract by setting a `name` and a `symbol` to the token collection.
*/
constructor(string memory name_, string memory symbol_) {
_name = name_;
_symbol = symbol_;
}
/**
* @dev See {IERC165-supportsInterface}.
*/
function supportsInterface(
bytes4 interfaceId
) public view virtual override(ERC165, IERC165) returns (bool) {
return
interfaceId == type(ISBT).interfaceId ||
interfaceId == type(ISBTMetadata).interfaceId ||
super.supportsInterface(interfaceId);
}
/**
* @dev See {ISBT-balanceOf}.
*/
function balanceOf(
address owner
) public view virtual override returns (uint256) {
require(owner != address(0), "SBT: address zero is not a valid owner");
return _balances[owner];
}
/**
* @dev See {ISBT-ownerOf}.
*/
function ownerOf(
uint256 tokenId
) public view virtual override returns (address) {
address owner = _owners[tokenId];
require(owner != address(0), "SBT: invalid token ID");
return owner;
}
/**
* @dev See {ISBTMetadata-name}.
*/
function name() public view virtual override returns (string memory) {
return _name;
}
/**
* @dev See {ISBTMetadata-symbol}.
*/
function symbol() public view virtual override returns (string memory) {
return _symbol;
}
/**
* @dev See {ISBTMetadata-tokenURI}.
*/
function tokenURI(
uint256 tokenId
) public view virtual override returns (string memory) {
_requireMinted(tokenId);
string memory baseURI = _baseURI();
return
bytes(baseURI).length > 0
? string(abi.encodePacked(baseURI, tokenId.toString()))
: "";
}
/**
* @dev Base URI for computing {tokenURI}. If set, the resulting URI for each
* token will be the concatenation of the `baseURI` and the `tokenId`. Empty
* by default, can be overridden in child contracts.
*/
function _baseURI() internal view virtual returns (string memory) {
return "";
}
/**
* @dev Returns whether `spender` is allowed to manage `tokenId`.
*
* Requirements:
*
* - `tokenId` must exist.
*/
function _isOwner(
address spender,
uint256 tokenId
) internal view virtual returns (bool) {
address owner = SBT.ownerOf(tokenId);
return (spender == owner);
}
/**
* @dev Returns whether `tokenId` exists.
*
* Tokens can be managed by their owner.
*
* Tokens start existing when they are minted (`_mint`),
* and stop existing when they are burned (`_burn`).
*/
function _exists(uint256 tokenId) internal view virtual returns (bool) {
return _owners[tokenId] != address(0);
}
/**
* @dev Mints `tokenId` and transfers it to `to`.
*
* WARNING: Usage of this method is discouraged, use {_safeMint} whenever possible
*
* Requirements:
*
* - `tokenId` must not exist.
* - `to` cannot be the zero address.
*
* Emits a {Mint} event.
*/
function _mint(address to, uint256 tokenId) internal virtual {
require(to != address(0), "SBT: mint to the zero address");
require(!_exists(tokenId), "SBT: token already minted");
_beforeTokenTransfer(address(0), to, tokenId);
_balances[to] += 1;
_owners[tokenId] = to;
emit Mint(to, tokenId);
_afterTokenTransfer(address(0), to, tokenId);
}
/**
* @dev Destroys `tokenId`.
*
* Requirements:
* - `tokenId` must exist.
*
* Emits a {Burn} event.
*/
function _burn(uint256 tokenId) internal virtual {
address owner = SBT.ownerOf(tokenId);
_beforeTokenTransfer(owner, address(0), tokenId);
_balances[owner] -= 1;
delete _owners[tokenId];
emit Burn(owner, tokenId);
_afterTokenTransfer(owner, address(0), tokenId);
}
/**
* @dev Reverts if the `tokenId` has not been minted yet.
*/
function _requireMinted(uint256 tokenId) internal view virtual {
require(_exists(tokenId), "SBT: invalid token ID");
}
/**
* @dev Hook that is called before any token minting/burning
*
* Calling conditions:
*
* - When `from` and `to` are both non-zero, ``from``'s `tokenId` will be
* transferred to `to`.
* - When `from` is zero, `tokenId` will be minted for `to`.
* - When `to` is zero, ``from``'s `tokenId` will be burned.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _beforeTokenTransfer(address, address, uint256) internal virtual {}
/**
* @dev Hook that is called after any minting/burning of tokens
*
* Calling conditions:
* - when `from` and `to` are both non-zero.
* - `from` and `to` are never both zero.
*
* To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks].
*/
function _afterTokenTransfer(address, address, uint256) internal virtual {}
}{
"optimizer": {
"enabled": true,
"runs": 1,
"details": {
"yul": false
}
},
"outputSelection": {
"*": {
"*": [
"evm.bytecode",
"evm.deployedBytecode",
"abi"
]
}
},
"metadata": {
"useLiteralContent": true
}
}Contract Security Audit
- No Contract Security Audit Submitted- Submit Audit Here
Contract ABI
API[{"inputs":[{"internalType":"address","name":"admin","type":"address"},{"internalType":"string","name":"name","type":"string"},{"internalType":"string","name":"symbol","type":"string"},{"internalType":"string","name":"baseTokenURI","type":"string"},{"internalType":"address","name":"soulboundIdentity","type":"address"},{"components":[{"internalType":"address","name":"swapRouter","type":"address"},{"internalType":"address","name":"wrappedNativeToken","type":"address"},{"internalType":"address","name":"stableCoin","type":"address"},{"internalType":"address","name":"masaToken","type":"address"},{"internalType":"address","name":"projectFeeReceiver","type":"address"},{"internalType":"address","name":"protocolFeeReceiver","type":"address"},{"internalType":"uint256","name":"protocolFeeAmount","type":"uint256"},{"internalType":"uint256","name":"protocolFeePercent","type":"uint256"},{"internalType":"uint256","name":"protocolFeePercentSub","type":"uint256"}],"internalType":"struct PaymentGateway.PaymentParams","name":"paymentParams","type":"tuple"},{"internalType":"uint256","name":"_maxSBTToMint","type":"uint256"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"AlreadyAdded","type":"error"},{"inputs":[{"internalType":"address","name":"authority","type":"address"}],"name":"AuthorityNotExists","type":"error"},{"inputs":[{"internalType":"address","name":"caller","type":"address"}],"name":"CallerNotOwner","type":"error"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"InsufficientEthAmount","type":"error"},{"inputs":[{"internalType":"address","name":"paymentMethod","type":"address"}],"name":"InvalidPaymentMethod","type":"error"},{"inputs":[],"name":"InvalidShortString","type":"error"},{"inputs":[],"name":"InvalidSignature","type":"error"},{"inputs":[{"internalType":"address","name":"token","type":"address"}],"name":"InvalidToken","type":"error"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"maximum","type":"uint256"}],"name":"MaxSBTMinted","type":"error"},{"inputs":[{"internalType":"address","name":"erc20token","type":"address"}],"name":"NonExistingErc20Token","type":"error"},{"inputs":[{"internalType":"address","name":"signer","type":"address"}],"name":"NotAuthorized","type":"error"},{"inputs":[],"name":"NotLinkedToAnIdentitySBT","type":"error"},{"inputs":[],"name":"PaymentParamsNotSet","type":"error"},{"inputs":[],"name":"ProtocolFeeReceiverNotSet","type":"error"},{"inputs":[],"name":"RefundFailed","type":"error"},{"inputs":[],"name":"SameValue","type":"error"},{"inputs":[{"internalType":"string","name":"str","type":"string"}],"name":"StringTooLong","type":"error"},{"inputs":[],"name":"TransferFailed","type":"error"},{"inputs":[],"name":"UserMustHaveProtocolOrProjectAdminRole","type":"error"},{"inputs":[],"name":"ZeroAddress","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_owner","type":"address"},{"indexed":true,"internalType":"uint256","name":"_tokenId","type":"uint256"}],"name":"Burn","type":"event"},{"anonymous":false,"inputs":[],"name":"EIP712DomainChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"_owner","type":"address"},{"indexed":true,"internalType":"uint256","name":"_tokenId","type":"uint256"}],"name":"Mint","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"address","name":"authorityAddress","type":"address"},{"indexed":false,"internalType":"uint256","name":"signatureDate","type":"uint256"},{"indexed":false,"internalType":"address","name":"paymentMethod","type":"address"},{"indexed":false,"internalType":"uint256","name":"mintPrice","type":"uint256"}],"name":"MintedToAddress","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"identityId","type":"uint256"},{"indexed":false,"internalType":"address","name":"authorityAddress","type":"address"},{"indexed":false,"internalType":"uint256","name":"signatureDate","type":"uint256"},{"indexed":false,"internalType":"address","name":"paymentMethod","type":"address"},{"indexed":false,"internalType":"uint256","name":"mintPrice","type":"uint256"}],"name":"MintedToIdentity","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"previousAdminRole","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"newAdminRole","type":"bytes32"}],"name":"RoleAdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleGranted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleRevoked","type":"event"},{"inputs":[],"name":"DEFAULT_ADMIN_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PROJECT_ADMIN_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_authority","type":"address"}],"name":"addAuthority","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"addLinkPrice","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"addLinkPriceMASA","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"authorities","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"burn","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_paymentMethod","type":"address"}],"name":"disablePaymentMethod","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"eip712Domain","outputs":[{"internalType":"bytes1","name":"fields","type":"bytes1"},{"internalType":"string","name":"name","type":"string"},{"internalType":"string","name":"version","type":"string"},{"internalType":"uint256","name":"chainId","type":"uint256"},{"internalType":"address","name":"verifyingContract","type":"address"},{"internalType":"bytes32","name":"salt","type":"bytes32"},{"internalType":"uint256[]","name":"extensions","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_paymentMethod","type":"address"}],"name":"enablePaymentMethod","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"","type":"address"}],"name":"enabledPaymentMethod","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"enabledPaymentMethods","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"exists","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getEnabledPaymentMethods","outputs":[{"internalType":"address[]","name":"","type":"address[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"getIdentityId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"paymentMethod","type":"address"}],"name":"getMintPrice","outputs":[{"internalType":"uint256","name":"price","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"paymentMethod","type":"address"}],"name":"getMintPriceWithProtocolFee","outputs":[{"internalType":"uint256","name":"price","type":"uint256"},{"internalType":"uint256","name":"protocolFee","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"paymentMethod","type":"address"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"getProtocolFee","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"getProtocolFeeSub","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"getRoleAdmin","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"grantRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"hasRole","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"masaToken","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"maxSBTToMint","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"paymentMethod","type":"address"},{"internalType":"uint256","name":"identityId","type":"uint256"},{"internalType":"address","name":"authorityAddress","type":"address"},{"internalType":"uint256","name":"signatureDate","type":"uint256"},{"internalType":"bytes","name":"signature","type":"bytes"}],"name":"mint","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"address","name":"paymentMethod","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"address","name":"authorityAddress","type":"address"},{"internalType":"uint256","name":"signatureDate","type":"uint256"},{"internalType":"bytes","name":"signature","type":"bytes"}],"name":"mint","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"payable","type":"function"},{"inputs":[],"name":"mintPrice","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"mintPriceMASA","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"name","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"ownerOf","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"projectFeeReceiver","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"protocolFeeAmount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"protocolFeePercent","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"protocolFeePercentSub","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"protocolFeeReceiver","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"queryLinkPrice","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"queryLinkPriceMASA","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"_authority","type":"address"}],"name":"removeAuthority","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"renounceRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"revokeRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_addLinkPrice","type":"uint256"}],"name":"setAddLinkPrice","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_addLinkPriceMASA","type":"uint256"}],"name":"setAddLinkPriceMASA","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_masaToken","type":"address"}],"name":"setMasaToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_mintPrice","type":"uint256"}],"name":"setMintPrice","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_mintPriceMASA","type":"uint256"}],"name":"setMintPriceMASA","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_projectFeeReceiver","type":"address"}],"name":"setProjectFeeReceiver","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_protocolFeeAmount","type":"uint256"}],"name":"setProtocolFeeAmount","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_protocolFeePercent","type":"uint256"}],"name":"setProtocolFeePercent","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_protocolFeePercentSub","type":"uint256"}],"name":"setProtocolFeePercentSub","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_protocolFeeReceiver","type":"address"}],"name":"setProtocolFeeReceiver","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_queryLinkPrice","type":"uint256"}],"name":"setQueryLinkPrice","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_queryLinkPriceMASA","type":"uint256"}],"name":"setQueryLinkPriceMASA","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_soulboundIdentity","type":"address"}],"name":"setSoulboundIdentity","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_stableCoin","type":"address"}],"name":"setStableCoin","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_swapRouter","type":"address"}],"name":"setSwapRouter","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"_wrappedNativeToken","type":"address"}],"name":"setWrappedNativeToken","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"soulboundIdentity","outputs":[{"internalType":"contract ISoulboundIdentity","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"stableCoin","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"swapRouter","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"symbol","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"index","type":"uint256"}],"name":"tokenByIndex","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"},{"internalType":"uint256","name":"index","type":"uint256"}],"name":"tokenOfOwnerByIndex","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"tokenURI","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"wrappedNativeToken","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"}]Contract Creation Code
61016060405260016021553480156200001757600080fd5b5060405162004f8e38038062004f8e8339810160408190526200003a916200072b565b8686868686866040518060400160405280601981526020017f5265666572656e636553425453656c66536f7665726569676e00000000000000815250604051806040016040528060058152602001640312e302e360dc1b81525087878787878784848783620000b36000801b836200025b60201b60201c565b8051600180546001600160a01b03199081166001600160a01b039384161790915560208084015160028054841691851691909117905560408401516003805484169185169190911790556060840151600480548416918516919091179055608084015160078054841691851691909117905560a084015160088054909316931692909217905560c082015160095560e0820151600a5561010090910151600b558351620001679250600c91850190620003fb565b5080516200017d90600d906020840190620003fb565b506200018f915060009050876200025b565b8251620001a4906014906020860190620003fb565b5081601560006101000a8154816001600160a01b0302191690836001600160a01b03160217905550505050505050620001ed601c83620002fc60201b62001d121790919060201c565b610120526200020a81601d620002fc602090811b62001d1217901c565b61014052815160208084019190912060e052815190820120610100524660a0526200023462000350565b6080525050503060601b60c052505060016020555050506021555062000982945050505050565b6000828152602081815260408083206001600160a01b038516845290915290205460ff16620002f8576000828152602081815260408083206001600160a01b03851684529091529020805460ff19166001179055620002b73390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45b5050565b60006020835110156200031c576200031483620003ac565b90506200034a565b826200033383620003f860201b62001d491760201c565b8151620003449260200190620003fb565b5060ff90505b92915050565b60e0516101005160405160009262000391927f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f924690309060200162000843565b60405160208183030381529060405280519060200120905090565b600080829050601f81511115620003e3578260405163305a27a960e01b8152600401620003da9190620008d2565b60405180910390fd5b8051620003f082620008f7565b179392505050565b90565b828054620004099062000951565b90600052602060002090601f0160209004810192826200042d576000855562000478565b82601f106200044857805160ff191683800117855562000478565b8280016001018555821562000478579182015b82811115620004785782518255916020019190600101906200045b565b50620004869291506200048a565b5090565b5b808211156200048657600081556001016200048b565b60006001600160a01b0382166200034a565b620004be81620004a1565b8114620004ca57600080fd5b50565b80516200034a81620004b3565b601f01601f191690565b634e487b7160e01b600052604160045260246000fd5b6200050582620004da565b81018181106001600160401b0382111715620005255762000525620004e4565b6040525050565b60006200053860405190565b9050620005468282620004fa565b919050565b60006001600160401b03821115620005675762000567620004e4565b6200057282620004da565b60200192915050565b60005b83811015620005985781810151838201526020016200057e565b83811115620005a8576000848401525b50505050565b6000620005c5620005bf846200054b565b6200052c565b905082815260208101848484011115620005e257620005e2600080fd5b620005ef8482856200057b565b509392505050565b600082601f8301126200060d576200060d600080fd5b81516200061f848260208601620005ae565b949350505050565b80620004be565b80516200034a8162000627565b60006101208284031215620006535762000653600080fd5b620006606101206200052c565b90506000620006708484620004cd565b82525060206200068384848301620004cd565b60208301525060406200069984828501620004cd565b6040830152506060620006af84828501620004cd565b6060830152506080620006c584828501620004cd565b60808301525060a0620006db84828501620004cd565b60a08301525060c0620006f1848285016200062e565b60c08301525060e062000707848285016200062e565b60e0830152506101006200071e848285016200062e565b6101008301525092915050565b60008060008060008060006101e0888a0312156200074c576200074c600080fd5b60006200075a8a8a620004cd565b97505060208801516001600160401b038111156200077b576200077b600080fd5b620007898a828b01620005f7565b96505060408801516001600160401b03811115620007aa57620007aa600080fd5b620007b88a828b01620005f7565b95505060608801516001600160401b03811115620007d957620007d9600080fd5b620007e78a828b01620005f7565b9450506080620007fa8a828b01620004cd565b93505060a06200080d8a828b016200063b565b9250506101c0620008218a828b016200062e565b91505092959891949750929550565b805b82525050565b6200083281620004a1565b60a0810162000853828862000830565b62000862602083018762000830565b62000871604083018662000830565b62000880606083018562000830565b6200088f608083018462000838565b9695505050505050565b6000620008a4825190565b808452602084019350620008bd8185602086016200057b565b620008c881620004da565b9093019392505050565b60208082528101620008e5818462000899565b9392505050565b60006200034a825190565b600062000902825190565b602083016200091181620008ec565b9250602082101562000934576200092f600019836020036008021b90565b831692505b5050919050565b634e487b7160e01b600052602260045260246000fd5b6002810460018216806200096657607f821691505b602082108114156200097c576200097c6200093b565b50919050565b60805160a05160c05160601c60e0516101005161012051610140516145ae620009e060003960006116870152600061165c0152600061315b0152600061313a01526000612d9801526000612dc201526000612dec01526145ae6000f3fe6080604052600436106102f35760003560e01c8062bdfde5146102f857806301ffc9a71461031a5780630513c3e91461035057806306fdde031461037d578063102005191461039f578063126ed01c146103c157806313150b48146103ee578063135f470c1461040457806317fcb39b1461041a57806318160ddd1461043a5780631830e8811461044f5780631f37c1241461046557806320d558aa1461047b578063217a2c7b1461048e57806323af4e17146104ae578063248a9ca3146104ce57806326defa73146104ee578063289c686b1461050e5780632f2ff15d1461052e5780632f745c591461054e57806336568abe1461056e57806339a51be51461058e5780633ad3033e146105ae5780633c72ae70146105ce57806341273657146105ee57806341c04d5e1461060e57806342966c681461063057806346877b1a146106505780634962a158146106705780634f558e79146106905780634f6ccce7146106b05780636352211e146106d05780636817c76c146106f05780636bfd499f1461070657806370a0823114610726578063719d0f2b1461074657806376ad199714610766578063776d1a541461078657806377bed5ed1461079c5780637a0d1646146107c95780637ad09dff146107f95780637db8cb681461080c57806381e392ad1461082c57806384b0196e146108425780638d0184611461086a5780638ec9c93b1461088a57806391223d69146108a057806391d14854146108d057806394a665e9146108f057806395d89b4114610910578063992642e51461092557806399b589cb14610945578063a217fddf14610965578063a49834211461097a578063b97d6b231461099a578063c1177d19146109b0578063c31c9c07146109d0578063c86aadb6146109f0578063c87b56dd14610a10578063d544e01014610a30578063d547741f14610a50578063d6e6eb9f14610a70578063da058ae314610a86578063eb93e85514610aa6578063ebda439614610ad4578063f4a0a52814610af4578063fd48ac8314610b14575b600080fd5b34801561030457600080fd5b50610318610313366004613714565b610b34565b005b34801561032657600080fd5b5061033a610335366004613750565b610b68565b604051610347919061377b565b60405180910390f35b34801561035c57600080fd5b5061037061036b366004613714565b610b79565b60405161034791906137a9565b34801561038957600080fd5b50610392610ba3565b6040516103479190613821565b3480156103ab57600080fd5b506103b4610c35565b604051610347919061388f565b3480156103cd57600080fd5b506103e16103dc366004613714565b610c96565b60405161034791906138a6565b3480156103fa57600080fd5b506103e1601b5481565b34801561041057600080fd5b506103e1600b5481565b34801561042657600080fd5b50600254610370906001600160a01b031681565b34801561044657600080fd5b506012546103e1565b34801561045b57600080fd5b506103e160175481565b34801561047157600080fd5b506103e160185481565b6103e1610489366004613912565b610ca1565b34801561049a57600080fd5b506103e16104a93660046139a7565b610e18565b3480156104ba57600080fd5b506103186104c93660046139e4565b610e2b565b3480156104da57600080fd5b506103e16104e9366004613714565b610e88565b3480156104fa57600080fd5b506103186105093660046139e4565b610e9d565b34801561051a57600080fd5b50610318610529366004613714565b610f6d565b34801561053a57600080fd5b50610318610549366004613a05565b610fe0565b34801561055a57600080fd5b506103e16105693660046139a7565b611001565b34801561057a57600080fd5b50610318610589366004613a05565b611053565b34801561059a57600080fd5b50600854610370906001600160a01b031681565b3480156105ba57600080fd5b506103186105c93660046139e4565b611089565b3480156105da57600080fd5b506103186105e9366004613714565b6110e6565b3480156105fa57600080fd5b506103186106093660046139e4565b611159565b34801561061a57600080fd5b506103e160008051602061455983398151915281565b34801561063c57600080fd5b5061031861064b366004613714565b6111b6565b34801561065c57600080fd5b5061031861066b3660046139e4565b6111e8565b34801561067c57600080fd5b5061031861068b366004613714565b611245565b34801561069c57600080fd5b5061033a6106ab366004613714565b6112b8565b3480156106bc57600080fd5b506103e16106cb366004613714565b6112c3565b3480156106dc57600080fd5b506103706106eb366004613714565b611311565b3480156106fc57600080fd5b506103e160165481565b34801561071257600080fd5b50610318610721366004613714565b611346565b34801561073257600080fd5b506103e16107413660046139e4565b61137a565b34801561075257600080fd5b506103e16107613660046139e4565b6113be565b34801561077257600080fd5b506103186107813660046139e4565b6114be565b34801561079257600080fd5b506103e160195481565b3480156107a857600080fd5b506015546107bc906001600160a01b031681565b6040516103479190613a6d565b3480156107d557600080fd5b5061033a6107e43660046139e4565b60056020526000908152604090205460ff1681565b6103e1610807366004613a7b565b61151b565b34801561081857600080fd5b50610318610827366004613714565b6115db565b34801561083857600080fd5b506103e160215481565b34801561084e57600080fd5b5061085761164e565b6040516103479796959493929190613b0e565b34801561087657600080fd5b506103186108853660046139e4565b6116d7565b34801561089657600080fd5b506103e160095481565b3480156108ac57600080fd5b5061033a6108bb3660046139e4565b601f6020526000908152604090205460ff1681565b3480156108dc57600080fd5b5061033a6108eb366004613a05565b611773565b3480156108fc57600080fd5b5061031861090b3660046139e4565b61179c565b34801561091c57600080fd5b50610392611909565b34801561093157600080fd5b50600354610370906001600160a01b031681565b34801561095157600080fd5b50600754610370906001600160a01b031681565b34801561097157600080fd5b506103e1600081565b34801561098657600080fd5b50610318610995366004613714565b611918565b3480156109a657600080fd5b506103e1601a5481565b3480156109bc57600080fd5b506103e16109cb366004613714565b61194c565b3480156109dc57600080fd5b50600154610370906001600160a01b031681565b3480156109fc57600080fd5b50610318610a0b3660046139e4565b611a04565b348015610a1c57600080fd5b50610392610a2b366004613714565b611ab0565b348015610a3c57600080fd5b50610318610a4b3660046139e4565b611ac3565b348015610a5c57600080fd5b50610318610a6b366004613a05565b611b91565b348015610a7c57600080fd5b506103e1600a5481565b348015610a9257600080fd5b50610318610aa13660046139e4565b611bad565b348015610ab257600080fd5b50610ac6610ac13660046139e4565b611c0a565b604051610347929190613b7d565b348015610ae057600080fd5b50600454610370906001600160a01b031681565b348015610b0057600080fd5b50610318610b0f366004613714565b611c2c565b348015610b2057600080fd5b50610318610b2f366004613714565b611c9f565b6000610b3f81611d4c565b600954821415610b625760405163c23f6ccb60e01b815260040160405180910390fd5b50600955565b6000610b7382611d56565b92915050565b60068181548110610b8957600080fd5b6000918252602090912001546001600160a01b0316905081565b6060600c8054610bb290613bae565b80601f0160208091040260200160405190810160405280929190818152602001828054610bde90613bae565b8015610c2b5780601f10610c0057610100808354040283529160200191610c2b565b820191906000526020600020905b815481529060010190602001808311610c0e57829003601f168201915b5050505050905090565b60606006805480602002602001604051908101604052809291908181526020018280548015610c2b57602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311610c6f575050505050905090565b6000610b7382611d7b565b6000610cab611dae565b6015546040516331a9108f60e11b81526000916001600160a01b031690636352211e90610cdc908a906004016138a6565b60206040518083038186803b158015610cf457600080fd5b505afa158015610d08573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d2c9190613be6565b90506000602154118015610d4a5750602154610d478261137a565b10155b15610d76576021546040516305dfb04760e01b8152610d6d918391600401613c07565b60405180910390fd5b6001600160a01b0381163314610da257335b60405163060296c760e31b8152600401610d6d91906137a9565b6000610dbc8983610db48b8b8b611dd8565b8a8989611e37565b90507fde721cf9ad79824593dc755ba31a6b43dd42c6e2bf7edb2a6762206ec35cc437818989898d601654604051610df996959493929190613c15565b60405180910390a1915050610e0e6001602055565b9695505050505050565b6000610e248383611ec8565b9392505050565b6000610e3681611d4c565b6003546001600160a01b0383811691161415610e655760405163c23f6ccb60e01b815260040160405180910390fd5b50600380546001600160a01b0319166001600160a01b0392909216919091179055565b60009081526020819052604090206001015490565b610ea8600033611773565b158015610eca5750610ec860008051602061455983398151915233611773565b155b15610ee8576040516326f0f48160e01b815260040160405180910390fd5b6001600160a01b038116610f0f5760405163d92e233d60e01b815260040160405180910390fd5b6001600160a01b0381166000908152601f602052604090205460ff1615610f495760405163f411c32760e01b815260040160405180910390fd5b6001600160a01b03166000908152601f60205260409020805460ff19166001179055565b610f78600033611773565b158015610f9a5750610f9860008051602061455983398151915233611773565b155b15610fb8576040516326f0f48160e01b815260040160405180910390fd5b806018541415610fdb5760405163c23f6ccb60e01b815260040160405180910390fd5b601855565b610fe982610e88565b610ff281611d4c565b610ffc8383611f2f565b505050565b600061100c8361137a565b821061102a5760405162461bcd60e51b8152600401610d6d90613cac565b506001600160a01b03919091166000908152601060209081526040808320938352929052205490565b6001600160a01b038116331461107b5760405162461bcd60e51b8152600401610d6d90613d08565b6110858282611fb3565b5050565b600061109481611d4c565b6015546001600160a01b03838116911614156110c35760405163c23f6ccb60e01b815260040160405180910390fd5b50601580546001600160a01b0319166001600160a01b0392909216919091179055565b6110f1600033611773565b158015611113575061111160008051602061455983398151915233611773565b155b15611131576040516326f0f48160e01b815260040160405180910390fd5b8060195414156111545760405163c23f6ccb60e01b815260040160405180910390fd5b601955565b600061116481611d4c565b6001546001600160a01b03838116911614156111935760405163c23f6ccb60e01b815260040160405180910390fd5b50600180546001600160a01b0319166001600160a01b0392909216919091179055565b6111c03382612018565b6111dc5760405162461bcd60e51b8152600401610d6d90613d4f565b6111e58161203b565b50565b60006111f381611d4c565b6008546001600160a01b03838116911614156112225760405163c23f6ccb60e01b815260040160405180910390fd5b50600880546001600160a01b0319166001600160a01b0392909216919091179055565b611250600033611773565b158015611272575061127060008051602061455983398151915233611773565b155b15611290576040516326f0f48160e01b815260040160405180910390fd5b8060175414156112b35760405163c23f6ccb60e01b815260040160405180910390fd5b601755565b6000610b73826120d5565b60006112ce60125490565b82106112ec5760405162461bcd60e51b8152600401610d6d90613da5565b601282815481106112ff576112ff613db5565b90600052602060002001549050919050565b6000818152600e60205260408120546001600160a01b031680610b735760405162461bcd60e51b8152600401610d6d90613df7565b600061135181611d4c565b600b548214156113745760405163c23f6ccb60e01b815260040160405180910390fd5b50600b55565b60006001600160a01b0382166113a25760405162461bcd60e51b8152600401610d6d90613e4a565b506001600160a01b03166000908152600f602052604090205490565b600060165460001480156113d25750601754155b156113df57506000919050565b6004546001600160a01b03838116911614801561141457506001600160a01b03821660009081526005602052604090205460ff165b801561142257506000601754115b1561142f57505060175490565b6003546001600160a01b03838116911614801561146457506001600160a01b03821660009081526005602052604090205460ff165b1561147157505060165490565b6001600160a01b03821660009081526005602052604090205460ff161561149e57610b73826016546120f2565b81604051630ac29ab760e31b8152600401610d6d91906137a9565b919050565b60006114c981611d4c565b6004546001600160a01b03838116911614156114f85760405163c23f6ccb60e01b815260040160405180910390fd5b50600480546001600160a01b0319166001600160a01b0392909216919091179055565b60008060215411801561153857506021546115358761137a565b10155b1561155b576021546040516305dfb04760e01b8152610d6d918891600401613c07565b6001600160a01b03861633146115715733610d88565b600061158b88886115838a8a8a612285565b898888611e37565b90507fc90403d5f004ffdbf65d5821160d02ec2aca1434bf532f015ae34177b0b36f37818888888c6016546040516115c896959493929190613e5a565b60405180910390a1979650505050505050565b6115e6600033611773565b158015611608575061160660008051602061455983398151915233611773565b155b15611626576040516326f0f48160e01b815260040160405180910390fd5b80601b5414156116495760405163c23f6ccb60e01b815260040160405180910390fd5b601b55565b6000606080828080836116827f0000000000000000000000000000000000000000000000000000000000000000601c6122c1565b6116ad7f0000000000000000000000000000000000000000000000000000000000000000601d6122c1565b60408051600080825260208201909252600f60f81b9b939a50919850469750309650945092509050565b6116e2600033611773565b158015611704575061170260008051602061455983398151915233611773565b155b15611722576040516326f0f48160e01b815260040160405180910390fd5b6007546001600160a01b03828116911614156117515760405163c23f6ccb60e01b815260040160405180910390fd5b600780546001600160a01b0319166001600160a01b0392909216919091179055565b6000918252602082815260408084206001600160a01b0393909316845291905290205460ff1690565b60006117a781611d4c565b6001600160a01b03821660009081526005602052604090205460ff166117e257816040516318317bd560e01b8152600401610d6d91906137a9565b6001600160a01b0382166000908152600560205260408120805460ff191690555b600654811015610ffc57826001600160a01b03166006828154811061182a5761182a613db5565b6000918252602090912001546001600160a01b031614156118f7576006805461185590600190613ea1565b8154811061186557611865613db5565b600091825260209091200154600680546001600160a01b03909216918390811061189157611891613db5565b9060005260206000200160006101000a8154816001600160a01b0302191690836001600160a01b0316021790555060068054806118d0576118d0613eb8565b600082815260209020810160001990810180546001600160a01b0319169055019055505050565b8061190181613ece565b915050611803565b6060600d8054610bb290613bae565b600061192381611d4c565b600a548214156119465760405163c23f6ccb60e01b815260040160405180910390fd5b50600a55565b6015546000906001600160a01b031661197857604051630d7fe67b60e41b815260040160405180910390fd5b600061198383611311565b60155460405163294cdf0d60e01b81529192506001600160a01b03169063294cdf0d906119b49084906004016137a9565b60206040518083038186803b1580156119cc57600080fd5b505afa1580156119e0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e249190613ef4565b6000611a0f81611d4c565b6001600160a01b03821660009081526005602052604090205460ff1615611a495760405163f411c32760e01b815260040160405180910390fd5b506001600160a01b03166000818152600560205260408120805460ff191660019081179091556006805491820181559091527ff652222313e28459528d920b65115c16c04f3efc82aaedc97be59f3f377c0d3f0180546001600160a01b0319169091179055565b6060611abb82612365565b610b7361238a565b611ace600033611773565b158015611af05750611aee60008051602061455983398151915233611773565b155b15611b0e576040516326f0f48160e01b815260040160405180910390fd5b6001600160a01b038116611b355760405163d92e233d60e01b815260040160405180910390fd5b6001600160a01b0381166000908152601f602052604090205460ff16611b7057806040516324b1f80560e21b8152600401610d6d91906137a9565b6001600160a01b03166000908152601f60205260409020805460ff19169055565b611b9a82610e88565b611ba381611d4c565b610ffc8383611fb3565b6000611bb881611d4c565b6002546001600160a01b0383811691161415611be75760405163c23f6ccb60e01b815260040160405180910390fd5b50600280546001600160a01b0319166001600160a01b0392909216919091179055565b600080611c16836113be565b915081611c238484611ec8565b91509150915091565b611c37600033611773565b158015611c595750611c5760008051602061455983398151915233611773565b155b15611c77576040516326f0f48160e01b815260040160405180910390fd5b806016541415611c9a5760405163c23f6ccb60e01b815260040160405180910390fd5b601655565b611caa600033611773565b158015611ccc5750611cca60008051602061455983398151915233611773565b155b15611cea576040516326f0f48160e01b815260040160405180910390fd5b80601a541415611d0d5760405163c23f6ccb60e01b815260040160405180910390fd5b601a55565b6000602083511015611d2e57611d2783612399565b9050610b73565b82828151611d3f9260200190613663565b5060ff9050610b73565b90565b6111e581336123d7565b60006001600160e01b0319821663780e9d6360e01b1480610b735750610b7382612430565b600b5460009015611da657610b736064611da0600b548561247090919063ffffffff16565b9061247c565b506000919050565b60026020541415611dd15760405162461bcd60e51b8152600401610d6d90613f49565b6002602055565b6000611e2f7fd3080a573ad5ada7eacc784494b0c203508360ba3533e33b0ce5bedd3d287fe5858585604051602001611e149493929190613f59565b60405160208183030381529060405280519060200120612488565b949350505050565b6000611e7b8584848080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152508992506124b5915050565b600080611e8789611c0a565b91509150611e96898383612536565b6000611ea1601e5490565b9050611eb1601e80546001019055565b611ebb89826129e9565b9998505050505050505050565b600954600090819015611f03576003546001600160a01b0385811691161415611ef45750600954611f03565b611f00846009546120f2565b90505b600a5415610e2457611e2f611f286064611da0600a548761247090919063ffffffff16565b8290612ac5565b611f398282611773565b611085576000828152602081815260408083206001600160a01b03851684529091529020805460ff19166001179055611f6f3390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b611fbd8282611773565b15611085576000828152602081815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b60008061202483611311565b6001600160a01b0385811691161491505092915050565b600061204682611311565b905061205481600084612ad1565b6001600160a01b0381166000908152600f6020526040812080546001929061207d908490613ea1565b90915550506000828152600e602052604080822080546001600160a01b03191690555183916001600160a01b038416917fcc16f5dbb4873280815c1ee09dbd06736cffcc184412cf7a71a0fdb75d397ca59190a35050565b6000908152600e60205260409020546001600160a01b0316151590565b60008160008111801561210e57506001546001600160a01b0316155b1561212c5760405163fca2174f60e01b815260040160405180910390fd5b60008111801561214557506002546001600160a01b0316155b156121635760405163fca2174f60e01b815260040160405180910390fd5b60008111801561217c57506003546001600160a01b0316155b1561219a5760405163fca2174f60e01b815260040160405180910390fd5b6000811180156121b357506007546001600160a01b0316155b156121d15760405163fca2174f60e01b815260040160405180910390fd5b6001600160a01b03841660009081526005602052604090205460ff16158061220657506003546001600160a01b038581169116145b15612226578360405163961c9a4f60e01b8152600401610d6d91906137a9565b82612234576000915061227e565b6001600160a01b0384166122665760025460035461225f916001600160a01b03908116911685612adc565b915061227e565b60035461225f9085906001600160a01b031685612adc565b5092915050565b6000611e2f7fd6ae75dd53278a61126ba2841ea1297d05c2fc42e0b02b88e8bbf74f4d1e3e3c858585604051602001611e149493929190613f97565b606060ff83146122d457611d2783612b9a565b8180546122e090613bae565b80601f016020809104026020016040519081016040528092919081815260200182805461230c90613bae565b80156123595780601f1061232e57610100808354040283529160200191612359565b820191906000526020600020905b81548152906001019060200180831161233c57829003601f168201915b50505050509050610b73565b61236e816120d5565b6111e55760405162461bcd60e51b8152600401610d6d90613df7565b606060148054610bb290613bae565b600080829050601f815111156123c4578260405163305a27a960e01b8152600401610d6d9190613821565b80516123cf82613fbc565b179392505050565b6123e18282611773565b611085576123ee81612bd9565b6123f9836020612beb565b60405160200161240a92919061401d565b60408051601f198184030181529082905262461bcd60e51b8252610d6d91600401613821565b60006001600160e01b031982166313f2a32f60e01b148061246157506001600160e01b03198216635b5e139f60e01b145b80610b735750610b7382612d56565b6000610e24828461406f565b6000610e2482846140a4565b6000610b73612495612d8b565b8360405161190160f01b8152600281019290925260228201526042902090565b60006124c18484612e1b565b9050816001600160a01b0316816001600160a01b0316146124f557604051638baa579f60e01b815260040160405180910390fd5b6001600160a01b0381166000908152601f602052604090205460ff166125305780604051634a0bfec160e01b8152600401610d6d91906137a9565b50505050565b6125408282612ac5565b60008111801561255957506001546001600160a01b0316155b156125775760405163fca2174f60e01b815260040160405180910390fd5b60008111801561259057506002546001600160a01b0316155b156125ae5760405163fca2174f60e01b815260040160405180910390fd5b6000811180156125c757506003546001600160a01b0316155b156125e55760405163fca2174f60e01b815260040160405180910390fd5b6000811180156125fe57506007546001600160a01b0316155b1561261c5760405163fca2174f60e01b815260040160405180910390fd5b82158015612628575081155b1561263257612530565b600061263d84611d7b565b9050600083118061264e5750600081115b801561266357506008546001600160a01b0316155b156126815760405163910af6f560e01b815260040160405180910390fd5b6001600160a01b03851660009081526005602052604090205460ff166126bc5784604051630ac29ab760e31b8152600401610d6d91906137a9565b6001600160a01b03851661295e576126d48484612ac5565b3410156126ff576126e58484612ac5565b60405163091a6d0f60e01b8152600401610d6d91906138a6565b600061270b8583612e3f565b111561279c576007546000906001600160a01b031661272a8684612e3f565b604051612736906140b8565b60006040518083038185875af1925050503d8060008114612773576040519150601f19603f3d011682016040523d82523d6000602084013e612778565b606091505b505090508061279a576040516312171d8360e31b815260040160405180910390fd5b505b8215612826576008546040516000916001600160a01b03169085906127c0906140b8565b60006040518083038185875af1925050503d80600081146127fd576040519150601f19603f3d011682016040523d82523d6000602084013e612802565b606091505b5050905080612824576040516312171d8360e31b815260040160405180910390fd5b505b80156128b0576008546040516000916001600160a01b031690839061284a906140b8565b60006040518083038185875af1925050503d8060008114612887576040519150601f19603f3d011682016040523d82523d6000602084013e61288c565b606091505b50509050806128ae576040516312171d8360e31b815260040160405180910390fd5b505b6128ba8484612ac5565b3411156129595760006128d76128d08686612ac5565b3490612e3f565b90506000336001600160a01b0316826040516128f2906140b8565b60006040518083038185875af1925050503d806000811461292f576040519150601f19603f3d011682016040523d82523d6000602084013e612934565b606091505b505090508061295657604051633c31275160e21b815260040160405180910390fd5b50505b6129e2565b600061296a8583612e3f565b111561299e5760075461299e9033906001600160a01b031661298c8785612e3f565b6001600160a01b038916929190612e4b565b82156129c0576008546129c0906001600160a01b038781169133911686612e4b565b80156129e2576008546129e2906001600160a01b038781169133911684612e4b565b5050505050565b6001600160a01b038216612a0f5760405162461bcd60e51b8152600401610d6d906140f4565b612a18816120d5565b15612a355760405162461bcd60e51b8152600401610d6d90614134565b612a4160008383612ad1565b6001600160a01b0382166000908152600f60205260408120805460019290612a6a908490614144565b90915550506000818152600e602052604080822080546001600160a01b0319166001600160a01b038616908117909155905183927f0f6798a560793a54c3bcfe86a93cde1e73087d944c0ea20544137d412139688591a35050565b6000610e248284614144565b610ffc838383612ea3565b6000606080612aeb8686612f5b565b6001546040516307c0329d60e21b81529192506001600160a01b031690631f00ca7490612b1e908790859060040161415c565b60006040518083038186803b158015612b3657600080fd5b505afa158015612b4a573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052612b729190810190614267565b915081600081518110612b8757612b87613db5565b6020026020010151925050509392505050565b60606000612ba7836130ed565b604080516020808252818301909252919250600091906020820181803683375050509182525060208101929092525090565b6060610b736001600160a01b03831660145b60606000612bfa83600261406f565b612c05906002614144565b6001600160401b03811115612c1c57612c1c613e75565b6040519080825280601f01601f191660200182016040528015612c46576020820181803683370190505b509050600360fc1b81600081518110612c6157612c61613db5565b60200101906001600160f81b031916908160001a905350600f60fb1b81600181518110612c9057612c90613db5565b60200101906001600160f81b031916908160001a9053506000612cb484600261406f565b612cbf906001614144565b90505b6001811115612d37576f181899199a1a9b1b9c1cb0b131b232b360811b85600f1660108110612cf357612cf3613db5565b1a60f81b828281518110612d0957612d09613db5565b60200101906001600160f81b031916908160001a90535060049490941c93612d30816142a1565b9050612cc2565b508315610e245760405162461bcd60e51b8152600401610d6d906142ea565b60006001600160e01b03198216637965db0b60e01b1480610b7357506301ffc9a760e01b6001600160e01b0319831614610b73565b6000306001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016148015612de457507f000000000000000000000000000000000000000000000000000000000000000046145b15612e0e57507f000000000000000000000000000000000000000000000000000000000000000090565b612e16613115565b905090565b6000806000612e2a85856131ab565b91509150612e37816131f1565b509392505050565b6000610e248284613ea1565b612530846323b872dd60e01b858585604051602401612e6c939291906142fa565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b0319909316929092179091526132a4565b6001600160a01b038316612efe57612ef981601280546000838152601360205260408120829055600182018355919091527fbb8a6a4669ba250d26cd7a459eca9d215f8307e33aebe50379bc5a3617ec34440155565b612f21565b816001600160a01b0316836001600160a01b031614612f2157612f218382613336565b6001600160a01b038216612f3857610ffc816133d3565b826001600160a01b0316826001600160a01b031614610ffc57610ffc8282613482565b6002546060906001600160a01b0384811691161480612f8757506002546001600160a01b038381169116145b1561305157604080516002808252606082018352600092602083019080368337019050506002549091506001600160a01b03858116911614612fc95783612fd6565b6002546001600160a01b03165b81600081518110612fe957612fe9613db5565b6001600160a01b039283166020918202929092010152600254848216911614613012578261301f565b6002546001600160a01b03165b8160018151811061303257613032613db5565b6001600160a01b03909216602092830291909101909101529050610b73565b6040805160038082526080820190925260009160208201606080368337019050509050838160008151811061308857613088613db5565b6001600160a01b0392831660209182029290920101526002548251911690829060019081106130b9576130b9613db5565b60200260200101906001600160a01b031690816001600160a01b031681525050828160028151811061303257613032613db5565b600060ff8216601f811115610b7357604051632cd44ac360e21b815260040160405180910390fd5b60007f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f7f00000000000000000000000000000000000000000000000000000000000000007f00000000000000000000000000000000000000000000000000000000000000004630604051602001613190959493929190614322565b60405160208183030381529060405280519060200120905090565b6000808251604114156131e25760208301516040840151606085015160001a6131d6878285856134c6565b945094505050506131ea565b506000905060025b9250929050565b600081600481111561320557613205614364565b141561320e5750565b600181600481111561322257613222614364565b14156132405760405162461bcd60e51b8152600401610d6d906143a9565b600281600481111561325457613254614364565b14156132725760405162461bcd60e51b8152600401610d6d906143ed565b600381600481111561328657613286614364565b14156111e55760405162461bcd60e51b8152600401610d6d9061443c565b60006132f9826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166135739092919063ffffffff16565b905080516000148061331a57508080602001905181019061331a919061445f565b610ffc5760405162461bcd60e51b8152600401610d6d906144c7565b600060016133438461137a565b61334d9190613ea1565b6000838152601160205260409020549091508082146133a0576001600160a01b03841660009081526010602090815260408083208584528252808320548484528184208190558352601190915290208190555b5060009182526011602090815260408084208490556001600160a01b039094168352601081528383209183525290812055565b6012546000906133e590600190613ea1565b6000838152601360205260408120546012805493945090928490811061340d5761340d613db5565b90600052602060002001549050806012838154811061342e5761342e613db5565b600091825260208083209091019290925582815260139091526040808220849055858252812055601280548061346657613466613eb8565b6001900381819060005260206000200160009055905550505050565b600061348d8361137a565b6001600160a01b039093166000908152601060209081526040808320868452825280832085905593825260119052919091209190915550565b6000806fa2a8918ca85bafe22016d0b997e4df60600160ff1b038311156134f3575060009050600361356a565b60006001878787876040516000815260200160405260405161351894939291906144e0565b6020604051602081039080840390855afa15801561353a573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b0381166135635760006001925092505061356a565b9150600090505b94509492505050565b6060611e2f848460008585600080866001600160a01b0316858760405161359a9190614508565b60006040518083038185875af1925050503d80600081146135d7576040519150601f19603f3d011682016040523d82523d6000602084013e6135dc565b606091505b50915091506135ed878383876135f8565b979650505050505050565b6060831561363457825161362d576001600160a01b0385163b61362d5760405162461bcd60e51b8152600401610d6d90614548565b5081611e2f565b611e2f83838151156136495781518083602001fd5b8060405162461bcd60e51b8152600401610d6d9190613821565b82805461366f90613bae565b90600052602060002090601f01602090048101928261369157600085556136d7565b82601f106136aa57805160ff19168380011785556136d7565b828001600101855582156136d7579182015b828111156136d75782518255916020019190600101906136bc565b506136e39291506136e7565b5090565b5b808211156136e357600081556001016136e8565b805b81146111e557600080fd5b8035610b73816136fc565b60006020828403121561372957613729600080fd5b6000611e2f8484613709565b6001600160e01b031981166136fe565b8035610b7381613735565b60006020828403121561376557613765600080fd5b6000611e2f8484613745565b8015155b82525050565b60208101610b738284613771565b6001600160a01b031690565b6000610b7382613789565b61377581613795565b60208101610b7382846137a0565b60005b838110156137d25781810151838201526020016137ba565b838111156125305750506000910152565b601f01601f191690565b60006137f7825190565b80845260208401935061380e8185602086016137b7565b613817816137e3565b9093019392505050565b60208082528101610e2481846137ed565b600061383e83836137a0565b505060200190565b6000613850825190565b80845260209384019383018060005b838110156138845781516138738882613832565b97506020830192505060010161385f565b509495945050505050565b60208082528101610e248184613846565b80613775565b60208101610b7382846138a0565b6136fe81613795565b8035610b73816138b4565b60008083601f8401126138dd576138dd600080fd5b5081356001600160401b038111156138f7576138f7600080fd5b6020830191508360018202830111156131ea576131ea600080fd5b60008060008060008060a0878903121561392e5761392e600080fd5b600061393a89896138bd565b965050602061394b89828a01613709565b955050604061395c89828a016138bd565b945050606061396d89828a01613709565b93505060808701356001600160401b0381111561398c5761398c600080fd5b61399889828a016138c8565b92509250509295509295509295565b600080604083850312156139bd576139bd600080fd5b60006139c985856138bd565b92505060206139da85828601613709565b9150509250929050565b6000602082840312156139f9576139f9600080fd5b6000611e2f84846138bd565b60008060408385031215613a1b57613a1b600080fd5b6000613a278585613709565b92505060206139da858286016138bd565b6000610b73613a49611d4984613789565b613789565b6000610b7382613a38565b6000610b7382613a4e565b61377581613a59565b60208101610b738284613a64565b60008060008060008060a08789031215613a9757613a97600080fd5b6000613aa389896138bd565b965050602061394b89828a016138bd565b6001600160f81b03198116613775565b600061383e83836138a0565b6000613ada825190565b80845260209384019383018060005b83811015613884578151613afd8882613ac4565b975060208301925050600101613ae9565b60e08101613b1c828a613ab4565b8181036020830152613b2e81896137ed565b90508181036040830152613b4281886137ed565b9050613b5160608301876138a0565b613b5e60808301866137a0565b613b6b60a08301856138a0565b81810360c0830152611ebb8184613ad0565b60408101613b8b82856138a0565b610e2460208301846138a0565b634e487b7160e01b600052602260045260246000fd5b600281046001821680613bc257607f821691505b60208210811415613bd557613bd5613b98565b50919050565b8051610b73816138b4565b600060208284031215613bfb57613bfb600080fd5b6000611e2f8484613bdb565b60408101613b8b82856137a0565b60c08101613c2382896138a0565b613c3060208301886138a0565b613c3d60408301876137a0565b613c4a60608301866138a0565b613c5760808301856137a0565b6135ed60a08301846138a0565b602881526000602082017f534254456e756d657261626c653a206f776e657220696e646578206f7574206f8152676620626f756e647360c01b602082015291505b5060400190565b60208082528101610b7381613c64565b602f81526000602082017f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636581526e103937b632b9903337b91039b2b63360891b60208201529150613ca5565b60208082528101610b7381613cbc565b601e81526000602082017f5342543a2063616c6c6572206973206e6f7420746f6b656e206f776e65720000815291505b5060200190565b60208082528101610b7381613d18565b602981526000602082017f534254456e756d657261626c653a20676c6f62616c20696e646578206f7574208152686f6620626f756e647360b81b60208201529150613ca5565b60208082528101610b7381613d5f565b634e487b7160e01b600052603260045260246000fd5b601581526000602082017414d0950e881a5b9d985b1a59081d1bdad95b881251605a1b81529150613d48565b60208082528101610b7381613dcb565b602681526000602082017f5342543a2061646472657373207a65726f206973206e6f7420612076616c69648152651037bbb732b960d11b60208201529150613ca5565b60208082528101610b7381613e07565b60c08101613e6882896138a0565b613c3060208301886137a0565b634e487b7160e01b600052604160045260246000fd5b634e487b7160e01b600052601160045260246000fd5b600082821015613eb357613eb3613e8b565b500390565b634e487b7160e01b600052603160045260246000fd5b6000600019821415613ee257613ee2613e8b565b5060010190565b8051610b73816136fc565b600060208284031215613f0957613f09600080fd5b6000611e2f8484613ee9565b601f81526000602082017f5265656e7472616e637947756172643a207265656e7472616e742063616c6c0081529150613d48565b60208082528101610b7381613f15565b60808101613f6782876138a0565b613f7460208301866138a0565b613f8160408301856137a0565b613f8e60608301846138a0565b95945050505050565b60808101613fa582876138a0565b613f7460208301866137a0565b6000610b73825190565b6000613fc6825190565b60208301613fd381613fb2565b92506020821015613ff457613fef600019836020036008021b90565b831692505b5050919050565b6000614005825190565b6140138185602086016137b7565b9290920192915050565b76020b1b1b2b9b9a1b7b73a3937b61d1030b1b1b7bab73a1604d1b815260170160006140498285613ffb565b7001034b99036b4b9b9b4b733903937b6329607d1b81526011019150611e2f8284613ffb565b600081600019048311821515161561408957614089613e8b565b500290565b634e487b7160e01b600052601260045260246000fd5b6000826140b3576140b361408e565b500490565b600081610b73565b601d81526000602082017f5342543a206d696e7420746f20746865207a65726f206164647265737300000081529150613d48565b60208082528101610b73816140c0565b601981526000602082017814d0950e881d1bdad95b88185b1c9958591e481b5a5b9d1959603a1b81529150613d48565b60208082528101610b7381614104565b6000821982111561415757614157613e8b565b500190565b6040810161416a82856138a0565b8181036020830152611e2f8184613846565b614185826137e3565b81018181106001600160401b03821117156141a2576141a2613e75565b6040525050565b60006141b460405190565b90506114b9828261417c565b60006001600160401b038211156141d9576141d9613e75565b5060209081020190565b60006141f66141f1846141c0565b6141a9565b8381529050602080820190840283018581111561421557614215600080fd5b835b81811015614239578061422a8882613ee9565b84525060209283019201614217565b5050509392505050565b600082601f83011261425757614257600080fd5b8151611e2f8482602086016141e3565b60006020828403121561427c5761427c600080fd5b81516001600160401b0381111561429557614295600080fd5b611e2f84828501614243565b6000816142b0576142b0613e8b565b506000190190565b60208082527f537472696e67733a20686578206c656e67746820696e73756666696369656e7491019081526000613d48565b60208082528101610b73816142b8565b6060810161430882866137a0565b61431560208301856137a0565b611e2f60408301846138a0565b60a0810161433082886138a0565b61433d60208301876138a0565b61434a60408301866138a0565b61435760608301856138a0565b610e0e60808301846137a0565b634e487b7160e01b600052602160045260246000fd5b601881526000602082017745434453413a20696e76616c6964207369676e617475726560401b81529150613d48565b60208082528101610b738161437a565b601f81526000602082017f45434453413a20696e76616c6964207369676e6174757265206c656e6774680081529150613d48565b60208082528101610b73816143b9565b602281526000602082017f45434453413a20696e76616c6964207369676e6174757265202773272076616c815261756560f01b60208201529150613ca5565b60208082528101610b73816143fd565b8015156136fe565b8051610b738161444c565b60006020828403121561447457614474600080fd5b6000611e2f8484614454565b602a81526000602082017f5361666545524332303a204552433230206f7065726174696f6e20646964206e8152691bdd081cdd58d8d9595960b21b60208201529150613ca5565b60208082528101610b7381614480565b60ff8116613775565b608081016144ee82876138a0565b6144fb60208301866144d7565b613f8160408301856138a0565b6000610e248284613ffb565b601d81526000602082017f416464726573733a2063616c6c20746f206e6f6e2d636f6e747261637400000081529150613d48565b60208082528101610b738161451456fe52eafc11f6f81f86878bffd31109a0d92f37506527754f00788853ff9f63b130a2646970667358221220bedfa5e1580b54e54fffd7068983e6a127913ae2e09ea63caa03ef60e5b9d86b64736f6c6343000808003300000000000000000000000084a74cc52048dd8421df4a9eb139d91bb7744b4e00000000000000000000000000000000000000000000000000000000000001e0000000000000000000000000000000000000000000000000000000000000022000000000000000000000000000000000000000000000000000000000000002600000000000000000000000008903d8d4f4c06814d7ecb42b1258e2209d53a7d40000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d000000000000000000000000b4fbf271143f4fbf7b91a5ded31805e42b2208d6000000000000000000000000d87ba7a50b2e7e660f678a895e4b72e7cb4ccd9c0000000000000000000000001f9840a85d5af5bf1d1762f925bdaddc4201f98400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e56328c0ab5cb79af9df2f76c0479ba461550750000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000001b5363726f6c6c20494420536f756c6420426f756e6420546f6b656e000000000000000000000000000000000000000000000000000000000000000000000000034944530000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003f68747470733a2f2f617277656176652e6e65742f466b6751464d64517343347055664d6170476a37727976486f46314e724536315274644e7267326777594500
Deployed Bytecode
0x6080604052600436106102f35760003560e01c8062bdfde5146102f857806301ffc9a71461031a5780630513c3e91461035057806306fdde031461037d578063102005191461039f578063126ed01c146103c157806313150b48146103ee578063135f470c1461040457806317fcb39b1461041a57806318160ddd1461043a5780631830e8811461044f5780631f37c1241461046557806320d558aa1461047b578063217a2c7b1461048e57806323af4e17146104ae578063248a9ca3146104ce57806326defa73146104ee578063289c686b1461050e5780632f2ff15d1461052e5780632f745c591461054e57806336568abe1461056e57806339a51be51461058e5780633ad3033e146105ae5780633c72ae70146105ce57806341273657146105ee57806341c04d5e1461060e57806342966c681461063057806346877b1a146106505780634962a158146106705780634f558e79146106905780634f6ccce7146106b05780636352211e146106d05780636817c76c146106f05780636bfd499f1461070657806370a0823114610726578063719d0f2b1461074657806376ad199714610766578063776d1a541461078657806377bed5ed1461079c5780637a0d1646146107c95780637ad09dff146107f95780637db8cb681461080c57806381e392ad1461082c57806384b0196e146108425780638d0184611461086a5780638ec9c93b1461088a57806391223d69146108a057806391d14854146108d057806394a665e9146108f057806395d89b4114610910578063992642e51461092557806399b589cb14610945578063a217fddf14610965578063a49834211461097a578063b97d6b231461099a578063c1177d19146109b0578063c31c9c07146109d0578063c86aadb6146109f0578063c87b56dd14610a10578063d544e01014610a30578063d547741f14610a50578063d6e6eb9f14610a70578063da058ae314610a86578063eb93e85514610aa6578063ebda439614610ad4578063f4a0a52814610af4578063fd48ac8314610b14575b600080fd5b34801561030457600080fd5b50610318610313366004613714565b610b34565b005b34801561032657600080fd5b5061033a610335366004613750565b610b68565b604051610347919061377b565b60405180910390f35b34801561035c57600080fd5b5061037061036b366004613714565b610b79565b60405161034791906137a9565b34801561038957600080fd5b50610392610ba3565b6040516103479190613821565b3480156103ab57600080fd5b506103b4610c35565b604051610347919061388f565b3480156103cd57600080fd5b506103e16103dc366004613714565b610c96565b60405161034791906138a6565b3480156103fa57600080fd5b506103e1601b5481565b34801561041057600080fd5b506103e1600b5481565b34801561042657600080fd5b50600254610370906001600160a01b031681565b34801561044657600080fd5b506012546103e1565b34801561045b57600080fd5b506103e160175481565b34801561047157600080fd5b506103e160185481565b6103e1610489366004613912565b610ca1565b34801561049a57600080fd5b506103e16104a93660046139a7565b610e18565b3480156104ba57600080fd5b506103186104c93660046139e4565b610e2b565b3480156104da57600080fd5b506103e16104e9366004613714565b610e88565b3480156104fa57600080fd5b506103186105093660046139e4565b610e9d565b34801561051a57600080fd5b50610318610529366004613714565b610f6d565b34801561053a57600080fd5b50610318610549366004613a05565b610fe0565b34801561055a57600080fd5b506103e16105693660046139a7565b611001565b34801561057a57600080fd5b50610318610589366004613a05565b611053565b34801561059a57600080fd5b50600854610370906001600160a01b031681565b3480156105ba57600080fd5b506103186105c93660046139e4565b611089565b3480156105da57600080fd5b506103186105e9366004613714565b6110e6565b3480156105fa57600080fd5b506103186106093660046139e4565b611159565b34801561061a57600080fd5b506103e160008051602061455983398151915281565b34801561063c57600080fd5b5061031861064b366004613714565b6111b6565b34801561065c57600080fd5b5061031861066b3660046139e4565b6111e8565b34801561067c57600080fd5b5061031861068b366004613714565b611245565b34801561069c57600080fd5b5061033a6106ab366004613714565b6112b8565b3480156106bc57600080fd5b506103e16106cb366004613714565b6112c3565b3480156106dc57600080fd5b506103706106eb366004613714565b611311565b3480156106fc57600080fd5b506103e160165481565b34801561071257600080fd5b50610318610721366004613714565b611346565b34801561073257600080fd5b506103e16107413660046139e4565b61137a565b34801561075257600080fd5b506103e16107613660046139e4565b6113be565b34801561077257600080fd5b506103186107813660046139e4565b6114be565b34801561079257600080fd5b506103e160195481565b3480156107a857600080fd5b506015546107bc906001600160a01b031681565b6040516103479190613a6d565b3480156107d557600080fd5b5061033a6107e43660046139e4565b60056020526000908152604090205460ff1681565b6103e1610807366004613a7b565b61151b565b34801561081857600080fd5b50610318610827366004613714565b6115db565b34801561083857600080fd5b506103e160215481565b34801561084e57600080fd5b5061085761164e565b6040516103479796959493929190613b0e565b34801561087657600080fd5b506103186108853660046139e4565b6116d7565b34801561089657600080fd5b506103e160095481565b3480156108ac57600080fd5b5061033a6108bb3660046139e4565b601f6020526000908152604090205460ff1681565b3480156108dc57600080fd5b5061033a6108eb366004613a05565b611773565b3480156108fc57600080fd5b5061031861090b3660046139e4565b61179c565b34801561091c57600080fd5b50610392611909565b34801561093157600080fd5b50600354610370906001600160a01b031681565b34801561095157600080fd5b50600754610370906001600160a01b031681565b34801561097157600080fd5b506103e1600081565b34801561098657600080fd5b50610318610995366004613714565b611918565b3480156109a657600080fd5b506103e1601a5481565b3480156109bc57600080fd5b506103e16109cb366004613714565b61194c565b3480156109dc57600080fd5b50600154610370906001600160a01b031681565b3480156109fc57600080fd5b50610318610a0b3660046139e4565b611a04565b348015610a1c57600080fd5b50610392610a2b366004613714565b611ab0565b348015610a3c57600080fd5b50610318610a4b3660046139e4565b611ac3565b348015610a5c57600080fd5b50610318610a6b366004613a05565b611b91565b348015610a7c57600080fd5b506103e1600a5481565b348015610a9257600080fd5b50610318610aa13660046139e4565b611bad565b348015610ab257600080fd5b50610ac6610ac13660046139e4565b611c0a565b604051610347929190613b7d565b348015610ae057600080fd5b50600454610370906001600160a01b031681565b348015610b0057600080fd5b50610318610b0f366004613714565b611c2c565b348015610b2057600080fd5b50610318610b2f366004613714565b611c9f565b6000610b3f81611d4c565b600954821415610b625760405163c23f6ccb60e01b815260040160405180910390fd5b50600955565b6000610b7382611d56565b92915050565b60068181548110610b8957600080fd5b6000918252602090912001546001600160a01b0316905081565b6060600c8054610bb290613bae565b80601f0160208091040260200160405190810160405280929190818152602001828054610bde90613bae565b8015610c2b5780601f10610c0057610100808354040283529160200191610c2b565b820191906000526020600020905b815481529060010190602001808311610c0e57829003601f168201915b5050505050905090565b60606006805480602002602001604051908101604052809291908181526020018280548015610c2b57602002820191906000526020600020905b81546001600160a01b03168152600190910190602001808311610c6f575050505050905090565b6000610b7382611d7b565b6000610cab611dae565b6015546040516331a9108f60e11b81526000916001600160a01b031690636352211e90610cdc908a906004016138a6565b60206040518083038186803b158015610cf457600080fd5b505afa158015610d08573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610d2c9190613be6565b90506000602154118015610d4a5750602154610d478261137a565b10155b15610d76576021546040516305dfb04760e01b8152610d6d918391600401613c07565b60405180910390fd5b6001600160a01b0381163314610da257335b60405163060296c760e31b8152600401610d6d91906137a9565b6000610dbc8983610db48b8b8b611dd8565b8a8989611e37565b90507fde721cf9ad79824593dc755ba31a6b43dd42c6e2bf7edb2a6762206ec35cc437818989898d601654604051610df996959493929190613c15565b60405180910390a1915050610e0e6001602055565b9695505050505050565b6000610e248383611ec8565b9392505050565b6000610e3681611d4c565b6003546001600160a01b0383811691161415610e655760405163c23f6ccb60e01b815260040160405180910390fd5b50600380546001600160a01b0319166001600160a01b0392909216919091179055565b60009081526020819052604090206001015490565b610ea8600033611773565b158015610eca5750610ec860008051602061455983398151915233611773565b155b15610ee8576040516326f0f48160e01b815260040160405180910390fd5b6001600160a01b038116610f0f5760405163d92e233d60e01b815260040160405180910390fd5b6001600160a01b0381166000908152601f602052604090205460ff1615610f495760405163f411c32760e01b815260040160405180910390fd5b6001600160a01b03166000908152601f60205260409020805460ff19166001179055565b610f78600033611773565b158015610f9a5750610f9860008051602061455983398151915233611773565b155b15610fb8576040516326f0f48160e01b815260040160405180910390fd5b806018541415610fdb5760405163c23f6ccb60e01b815260040160405180910390fd5b601855565b610fe982610e88565b610ff281611d4c565b610ffc8383611f2f565b505050565b600061100c8361137a565b821061102a5760405162461bcd60e51b8152600401610d6d90613cac565b506001600160a01b03919091166000908152601060209081526040808320938352929052205490565b6001600160a01b038116331461107b5760405162461bcd60e51b8152600401610d6d90613d08565b6110858282611fb3565b5050565b600061109481611d4c565b6015546001600160a01b03838116911614156110c35760405163c23f6ccb60e01b815260040160405180910390fd5b50601580546001600160a01b0319166001600160a01b0392909216919091179055565b6110f1600033611773565b158015611113575061111160008051602061455983398151915233611773565b155b15611131576040516326f0f48160e01b815260040160405180910390fd5b8060195414156111545760405163c23f6ccb60e01b815260040160405180910390fd5b601955565b600061116481611d4c565b6001546001600160a01b03838116911614156111935760405163c23f6ccb60e01b815260040160405180910390fd5b50600180546001600160a01b0319166001600160a01b0392909216919091179055565b6111c03382612018565b6111dc5760405162461bcd60e51b8152600401610d6d90613d4f565b6111e58161203b565b50565b60006111f381611d4c565b6008546001600160a01b03838116911614156112225760405163c23f6ccb60e01b815260040160405180910390fd5b50600880546001600160a01b0319166001600160a01b0392909216919091179055565b611250600033611773565b158015611272575061127060008051602061455983398151915233611773565b155b15611290576040516326f0f48160e01b815260040160405180910390fd5b8060175414156112b35760405163c23f6ccb60e01b815260040160405180910390fd5b601755565b6000610b73826120d5565b60006112ce60125490565b82106112ec5760405162461bcd60e51b8152600401610d6d90613da5565b601282815481106112ff576112ff613db5565b90600052602060002001549050919050565b6000818152600e60205260408120546001600160a01b031680610b735760405162461bcd60e51b8152600401610d6d90613df7565b600061135181611d4c565b600b548214156113745760405163c23f6ccb60e01b815260040160405180910390fd5b50600b55565b60006001600160a01b0382166113a25760405162461bcd60e51b8152600401610d6d90613e4a565b506001600160a01b03166000908152600f602052604090205490565b600060165460001480156113d25750601754155b156113df57506000919050565b6004546001600160a01b03838116911614801561141457506001600160a01b03821660009081526005602052604090205460ff165b801561142257506000601754115b1561142f57505060175490565b6003546001600160a01b03838116911614801561146457506001600160a01b03821660009081526005602052604090205460ff165b1561147157505060165490565b6001600160a01b03821660009081526005602052604090205460ff161561149e57610b73826016546120f2565b81604051630ac29ab760e31b8152600401610d6d91906137a9565b919050565b60006114c981611d4c565b6004546001600160a01b03838116911614156114f85760405163c23f6ccb60e01b815260040160405180910390fd5b50600480546001600160a01b0319166001600160a01b0392909216919091179055565b60008060215411801561153857506021546115358761137a565b10155b1561155b576021546040516305dfb04760e01b8152610d6d918891600401613c07565b6001600160a01b03861633146115715733610d88565b600061158b88886115838a8a8a612285565b898888611e37565b90507fc90403d5f004ffdbf65d5821160d02ec2aca1434bf532f015ae34177b0b36f37818888888c6016546040516115c896959493929190613e5a565b60405180910390a1979650505050505050565b6115e6600033611773565b158015611608575061160660008051602061455983398151915233611773565b155b15611626576040516326f0f48160e01b815260040160405180910390fd5b80601b5414156116495760405163c23f6ccb60e01b815260040160405180910390fd5b601b55565b6000606080828080836116827f5265666572656e636553425453656c66536f7665726569676e00000000000019601c6122c1565b6116ad7f312e302e30000000000000000000000000000000000000000000000000000005601d6122c1565b60408051600080825260208201909252600f60f81b9b939a50919850469750309650945092509050565b6116e2600033611773565b158015611704575061170260008051602061455983398151915233611773565b155b15611722576040516326f0f48160e01b815260040160405180910390fd5b6007546001600160a01b03828116911614156117515760405163c23f6ccb60e01b815260040160405180910390fd5b600780546001600160a01b0319166001600160a01b0392909216919091179055565b6000918252602082815260408084206001600160a01b0393909316845291905290205460ff1690565b60006117a781611d4c565b6001600160a01b03821660009081526005602052604090205460ff166117e257816040516318317bd560e01b8152600401610d6d91906137a9565b6001600160a01b0382166000908152600560205260408120805460ff191690555b600654811015610ffc57826001600160a01b03166006828154811061182a5761182a613db5565b6000918252602090912001546001600160a01b031614156118f7576006805461185590600190613ea1565b8154811061186557611865613db5565b600091825260209091200154600680546001600160a01b03909216918390811061189157611891613db5565b9060005260206000200160006101000a8154816001600160a01b0302191690836001600160a01b0316021790555060068054806118d0576118d0613eb8565b600082815260209020810160001990810180546001600160a01b0319169055019055505050565b8061190181613ece565b915050611803565b6060600d8054610bb290613bae565b600061192381611d4c565b600a548214156119465760405163c23f6ccb60e01b815260040160405180910390fd5b50600a55565b6015546000906001600160a01b031661197857604051630d7fe67b60e41b815260040160405180910390fd5b600061198383611311565b60155460405163294cdf0d60e01b81529192506001600160a01b03169063294cdf0d906119b49084906004016137a9565b60206040518083038186803b1580156119cc57600080fd5b505afa1580156119e0573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610e249190613ef4565b6000611a0f81611d4c565b6001600160a01b03821660009081526005602052604090205460ff1615611a495760405163f411c32760e01b815260040160405180910390fd5b506001600160a01b03166000818152600560205260408120805460ff191660019081179091556006805491820181559091527ff652222313e28459528d920b65115c16c04f3efc82aaedc97be59f3f377c0d3f0180546001600160a01b0319169091179055565b6060611abb82612365565b610b7361238a565b611ace600033611773565b158015611af05750611aee60008051602061455983398151915233611773565b155b15611b0e576040516326f0f48160e01b815260040160405180910390fd5b6001600160a01b038116611b355760405163d92e233d60e01b815260040160405180910390fd5b6001600160a01b0381166000908152601f602052604090205460ff16611b7057806040516324b1f80560e21b8152600401610d6d91906137a9565b6001600160a01b03166000908152601f60205260409020805460ff19169055565b611b9a82610e88565b611ba381611d4c565b610ffc8383611fb3565b6000611bb881611d4c565b6002546001600160a01b0383811691161415611be75760405163c23f6ccb60e01b815260040160405180910390fd5b50600280546001600160a01b0319166001600160a01b0392909216919091179055565b600080611c16836113be565b915081611c238484611ec8565b91509150915091565b611c37600033611773565b158015611c595750611c5760008051602061455983398151915233611773565b155b15611c77576040516326f0f48160e01b815260040160405180910390fd5b806016541415611c9a5760405163c23f6ccb60e01b815260040160405180910390fd5b601655565b611caa600033611773565b158015611ccc5750611cca60008051602061455983398151915233611773565b155b15611cea576040516326f0f48160e01b815260040160405180910390fd5b80601a541415611d0d5760405163c23f6ccb60e01b815260040160405180910390fd5b601a55565b6000602083511015611d2e57611d2783612399565b9050610b73565b82828151611d3f9260200190613663565b5060ff9050610b73565b90565b6111e581336123d7565b60006001600160e01b0319821663780e9d6360e01b1480610b735750610b7382612430565b600b5460009015611da657610b736064611da0600b548561247090919063ffffffff16565b9061247c565b506000919050565b60026020541415611dd15760405162461bcd60e51b8152600401610d6d90613f49565b6002602055565b6000611e2f7fd3080a573ad5ada7eacc784494b0c203508360ba3533e33b0ce5bedd3d287fe5858585604051602001611e149493929190613f59565b60405160208183030381529060405280519060200120612488565b949350505050565b6000611e7b8584848080601f0160208091040260200160405190810160405280939291908181526020018383808284376000920191909152508992506124b5915050565b600080611e8789611c0a565b91509150611e96898383612536565b6000611ea1601e5490565b9050611eb1601e80546001019055565b611ebb89826129e9565b9998505050505050505050565b600954600090819015611f03576003546001600160a01b0385811691161415611ef45750600954611f03565b611f00846009546120f2565b90505b600a5415610e2457611e2f611f286064611da0600a548761247090919063ffffffff16565b8290612ac5565b611f398282611773565b611085576000828152602081815260408083206001600160a01b03851684529091529020805460ff19166001179055611f6f3390565b6001600160a01b0316816001600160a01b0316837f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d60405160405180910390a45050565b611fbd8282611773565b15611085576000828152602081815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b60008061202483611311565b6001600160a01b0385811691161491505092915050565b600061204682611311565b905061205481600084612ad1565b6001600160a01b0381166000908152600f6020526040812080546001929061207d908490613ea1565b90915550506000828152600e602052604080822080546001600160a01b03191690555183916001600160a01b038416917fcc16f5dbb4873280815c1ee09dbd06736cffcc184412cf7a71a0fdb75d397ca59190a35050565b6000908152600e60205260409020546001600160a01b0316151590565b60008160008111801561210e57506001546001600160a01b0316155b1561212c5760405163fca2174f60e01b815260040160405180910390fd5b60008111801561214557506002546001600160a01b0316155b156121635760405163fca2174f60e01b815260040160405180910390fd5b60008111801561217c57506003546001600160a01b0316155b1561219a5760405163fca2174f60e01b815260040160405180910390fd5b6000811180156121b357506007546001600160a01b0316155b156121d15760405163fca2174f60e01b815260040160405180910390fd5b6001600160a01b03841660009081526005602052604090205460ff16158061220657506003546001600160a01b038581169116145b15612226578360405163961c9a4f60e01b8152600401610d6d91906137a9565b82612234576000915061227e565b6001600160a01b0384166122665760025460035461225f916001600160a01b03908116911685612adc565b915061227e565b60035461225f9085906001600160a01b031685612adc565b5092915050565b6000611e2f7fd6ae75dd53278a61126ba2841ea1297d05c2fc42e0b02b88e8bbf74f4d1e3e3c858585604051602001611e149493929190613f97565b606060ff83146122d457611d2783612b9a565b8180546122e090613bae565b80601f016020809104026020016040519081016040528092919081815260200182805461230c90613bae565b80156123595780601f1061232e57610100808354040283529160200191612359565b820191906000526020600020905b81548152906001019060200180831161233c57829003601f168201915b50505050509050610b73565b61236e816120d5565b6111e55760405162461bcd60e51b8152600401610d6d90613df7565b606060148054610bb290613bae565b600080829050601f815111156123c4578260405163305a27a960e01b8152600401610d6d9190613821565b80516123cf82613fbc565b179392505050565b6123e18282611773565b611085576123ee81612bd9565b6123f9836020612beb565b60405160200161240a92919061401d565b60408051601f198184030181529082905262461bcd60e51b8252610d6d91600401613821565b60006001600160e01b031982166313f2a32f60e01b148061246157506001600160e01b03198216635b5e139f60e01b145b80610b735750610b7382612d56565b6000610e24828461406f565b6000610e2482846140a4565b6000610b73612495612d8b565b8360405161190160f01b8152600281019290925260228201526042902090565b60006124c18484612e1b565b9050816001600160a01b0316816001600160a01b0316146124f557604051638baa579f60e01b815260040160405180910390fd5b6001600160a01b0381166000908152601f602052604090205460ff166125305780604051634a0bfec160e01b8152600401610d6d91906137a9565b50505050565b6125408282612ac5565b60008111801561255957506001546001600160a01b0316155b156125775760405163fca2174f60e01b815260040160405180910390fd5b60008111801561259057506002546001600160a01b0316155b156125ae5760405163fca2174f60e01b815260040160405180910390fd5b6000811180156125c757506003546001600160a01b0316155b156125e55760405163fca2174f60e01b815260040160405180910390fd5b6000811180156125fe57506007546001600160a01b0316155b1561261c5760405163fca2174f60e01b815260040160405180910390fd5b82158015612628575081155b1561263257612530565b600061263d84611d7b565b9050600083118061264e5750600081115b801561266357506008546001600160a01b0316155b156126815760405163910af6f560e01b815260040160405180910390fd5b6001600160a01b03851660009081526005602052604090205460ff166126bc5784604051630ac29ab760e31b8152600401610d6d91906137a9565b6001600160a01b03851661295e576126d48484612ac5565b3410156126ff576126e58484612ac5565b60405163091a6d0f60e01b8152600401610d6d91906138a6565b600061270b8583612e3f565b111561279c576007546000906001600160a01b031661272a8684612e3f565b604051612736906140b8565b60006040518083038185875af1925050503d8060008114612773576040519150601f19603f3d011682016040523d82523d6000602084013e612778565b606091505b505090508061279a576040516312171d8360e31b815260040160405180910390fd5b505b8215612826576008546040516000916001600160a01b03169085906127c0906140b8565b60006040518083038185875af1925050503d80600081146127fd576040519150601f19603f3d011682016040523d82523d6000602084013e612802565b606091505b5050905080612824576040516312171d8360e31b815260040160405180910390fd5b505b80156128b0576008546040516000916001600160a01b031690839061284a906140b8565b60006040518083038185875af1925050503d8060008114612887576040519150601f19603f3d011682016040523d82523d6000602084013e61288c565b606091505b50509050806128ae576040516312171d8360e31b815260040160405180910390fd5b505b6128ba8484612ac5565b3411156129595760006128d76128d08686612ac5565b3490612e3f565b90506000336001600160a01b0316826040516128f2906140b8565b60006040518083038185875af1925050503d806000811461292f576040519150601f19603f3d011682016040523d82523d6000602084013e612934565b606091505b505090508061295657604051633c31275160e21b815260040160405180910390fd5b50505b6129e2565b600061296a8583612e3f565b111561299e5760075461299e9033906001600160a01b031661298c8785612e3f565b6001600160a01b038916929190612e4b565b82156129c0576008546129c0906001600160a01b038781169133911686612e4b565b80156129e2576008546129e2906001600160a01b038781169133911684612e4b565b5050505050565b6001600160a01b038216612a0f5760405162461bcd60e51b8152600401610d6d906140f4565b612a18816120d5565b15612a355760405162461bcd60e51b8152600401610d6d90614134565b612a4160008383612ad1565b6001600160a01b0382166000908152600f60205260408120805460019290612a6a908490614144565b90915550506000818152600e602052604080822080546001600160a01b0319166001600160a01b038616908117909155905183927f0f6798a560793a54c3bcfe86a93cde1e73087d944c0ea20544137d412139688591a35050565b6000610e248284614144565b610ffc838383612ea3565b6000606080612aeb8686612f5b565b6001546040516307c0329d60e21b81529192506001600160a01b031690631f00ca7490612b1e908790859060040161415c565b60006040518083038186803b158015612b3657600080fd5b505afa158015612b4a573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f19168201604052612b729190810190614267565b915081600081518110612b8757612b87613db5565b6020026020010151925050509392505050565b60606000612ba7836130ed565b604080516020808252818301909252919250600091906020820181803683375050509182525060208101929092525090565b6060610b736001600160a01b03831660145b60606000612bfa83600261406f565b612c05906002614144565b6001600160401b03811115612c1c57612c1c613e75565b6040519080825280601f01601f191660200182016040528015612c46576020820181803683370190505b509050600360fc1b81600081518110612c6157612c61613db5565b60200101906001600160f81b031916908160001a905350600f60fb1b81600181518110612c9057612c90613db5565b60200101906001600160f81b031916908160001a9053506000612cb484600261406f565b612cbf906001614144565b90505b6001811115612d37576f181899199a1a9b1b9c1cb0b131b232b360811b85600f1660108110612cf357612cf3613db5565b1a60f81b828281518110612d0957612d09613db5565b60200101906001600160f81b031916908160001a90535060049490941c93612d30816142a1565b9050612cc2565b508315610e245760405162461bcd60e51b8152600401610d6d906142ea565b60006001600160e01b03198216637965db0b60e01b1480610b7357506301ffc9a760e01b6001600160e01b0319831614610b73565b6000306001600160a01b037f0000000000000000000000004d236e55e54ed960887659d046c60f377cca58f816148015612de457507f000000000000000000000000000000000000000000000000000000000008275046145b15612e0e57507f4b99b88955297ea3e0edbd5c3b44b326394d0530b4f5b6631f2dcc69bfae16b890565b612e16613115565b905090565b6000806000612e2a85856131ab565b91509150612e37816131f1565b509392505050565b6000610e248284613ea1565b612530846323b872dd60e01b858585604051602401612e6c939291906142fa565b60408051601f198184030181529190526020810180516001600160e01b03166001600160e01b0319909316929092179091526132a4565b6001600160a01b038316612efe57612ef981601280546000838152601360205260408120829055600182018355919091527fbb8a6a4669ba250d26cd7a459eca9d215f8307e33aebe50379bc5a3617ec34440155565b612f21565b816001600160a01b0316836001600160a01b031614612f2157612f218382613336565b6001600160a01b038216612f3857610ffc816133d3565b826001600160a01b0316826001600160a01b031614610ffc57610ffc8282613482565b6002546060906001600160a01b0384811691161480612f8757506002546001600160a01b038381169116145b1561305157604080516002808252606082018352600092602083019080368337019050506002549091506001600160a01b03858116911614612fc95783612fd6565b6002546001600160a01b03165b81600081518110612fe957612fe9613db5565b6001600160a01b039283166020918202929092010152600254848216911614613012578261301f565b6002546001600160a01b03165b8160018151811061303257613032613db5565b6001600160a01b03909216602092830291909101909101529050610b73565b6040805160038082526080820190925260009160208201606080368337019050509050838160008151811061308857613088613db5565b6001600160a01b0392831660209182029290920101526002548251911690829060019081106130b9576130b9613db5565b60200260200101906001600160a01b031690816001600160a01b031681525050828160028151811061303257613032613db5565b600060ff8216601f811115610b7357604051632cd44ac360e21b815260040160405180910390fd5b60007f8b73c3c69bb8fe3d512ecc4cf759cc79239f7b179b0ffacaa9a75d522b39400f7faaa10bc35c59f668b88e42fbdc82766d1a28d6923c0c351a95c9cc5ad3a978557f06c015bd22b4c69690933c1058878ebdfef31f9aaae40bbe86d8a09fe1b2972c4630604051602001613190959493929190614322565b60405160208183030381529060405280519060200120905090565b6000808251604114156131e25760208301516040840151606085015160001a6131d6878285856134c6565b945094505050506131ea565b506000905060025b9250929050565b600081600481111561320557613205614364565b141561320e5750565b600181600481111561322257613222614364565b14156132405760405162461bcd60e51b8152600401610d6d906143a9565b600281600481111561325457613254614364565b14156132725760405162461bcd60e51b8152600401610d6d906143ed565b600381600481111561328657613286614364565b14156111e55760405162461bcd60e51b8152600401610d6d9061443c565b60006132f9826040518060400160405280602081526020017f5361666545524332303a206c6f772d6c6576656c2063616c6c206661696c6564815250856001600160a01b03166135739092919063ffffffff16565b905080516000148061331a57508080602001905181019061331a919061445f565b610ffc5760405162461bcd60e51b8152600401610d6d906144c7565b600060016133438461137a565b61334d9190613ea1565b6000838152601160205260409020549091508082146133a0576001600160a01b03841660009081526010602090815260408083208584528252808320548484528184208190558352601190915290208190555b5060009182526011602090815260408084208490556001600160a01b039094168352601081528383209183525290812055565b6012546000906133e590600190613ea1565b6000838152601360205260408120546012805493945090928490811061340d5761340d613db5565b90600052602060002001549050806012838154811061342e5761342e613db5565b600091825260208083209091019290925582815260139091526040808220849055858252812055601280548061346657613466613eb8565b6001900381819060005260206000200160009055905550505050565b600061348d8361137a565b6001600160a01b039093166000908152601060209081526040808320868452825280832085905593825260119052919091209190915550565b6000806fa2a8918ca85bafe22016d0b997e4df60600160ff1b038311156134f3575060009050600361356a565b60006001878787876040516000815260200160405260405161351894939291906144e0565b6020604051602081039080840390855afa15801561353a573d6000803e3d6000fd5b5050604051601f1901519150506001600160a01b0381166135635760006001925092505061356a565b9150600090505b94509492505050565b6060611e2f848460008585600080866001600160a01b0316858760405161359a9190614508565b60006040518083038185875af1925050503d80600081146135d7576040519150601f19603f3d011682016040523d82523d6000602084013e6135dc565b606091505b50915091506135ed878383876135f8565b979650505050505050565b6060831561363457825161362d576001600160a01b0385163b61362d5760405162461bcd60e51b8152600401610d6d90614548565b5081611e2f565b611e2f83838151156136495781518083602001fd5b8060405162461bcd60e51b8152600401610d6d9190613821565b82805461366f90613bae565b90600052602060002090601f01602090048101928261369157600085556136d7565b82601f106136aa57805160ff19168380011785556136d7565b828001600101855582156136d7579182015b828111156136d75782518255916020019190600101906136bc565b506136e39291506136e7565b5090565b5b808211156136e357600081556001016136e8565b805b81146111e557600080fd5b8035610b73816136fc565b60006020828403121561372957613729600080fd5b6000611e2f8484613709565b6001600160e01b031981166136fe565b8035610b7381613735565b60006020828403121561376557613765600080fd5b6000611e2f8484613745565b8015155b82525050565b60208101610b738284613771565b6001600160a01b031690565b6000610b7382613789565b61377581613795565b60208101610b7382846137a0565b60005b838110156137d25781810151838201526020016137ba565b838111156125305750506000910152565b601f01601f191690565b60006137f7825190565b80845260208401935061380e8185602086016137b7565b613817816137e3565b9093019392505050565b60208082528101610e2481846137ed565b600061383e83836137a0565b505060200190565b6000613850825190565b80845260209384019383018060005b838110156138845781516138738882613832565b97506020830192505060010161385f565b509495945050505050565b60208082528101610e248184613846565b80613775565b60208101610b7382846138a0565b6136fe81613795565b8035610b73816138b4565b60008083601f8401126138dd576138dd600080fd5b5081356001600160401b038111156138f7576138f7600080fd5b6020830191508360018202830111156131ea576131ea600080fd5b60008060008060008060a0878903121561392e5761392e600080fd5b600061393a89896138bd565b965050602061394b89828a01613709565b955050604061395c89828a016138bd565b945050606061396d89828a01613709565b93505060808701356001600160401b0381111561398c5761398c600080fd5b61399889828a016138c8565b92509250509295509295509295565b600080604083850312156139bd576139bd600080fd5b60006139c985856138bd565b92505060206139da85828601613709565b9150509250929050565b6000602082840312156139f9576139f9600080fd5b6000611e2f84846138bd565b60008060408385031215613a1b57613a1b600080fd5b6000613a278585613709565b92505060206139da858286016138bd565b6000610b73613a49611d4984613789565b613789565b6000610b7382613a38565b6000610b7382613a4e565b61377581613a59565b60208101610b738284613a64565b60008060008060008060a08789031215613a9757613a97600080fd5b6000613aa389896138bd565b965050602061394b89828a016138bd565b6001600160f81b03198116613775565b600061383e83836138a0565b6000613ada825190565b80845260209384019383018060005b83811015613884578151613afd8882613ac4565b975060208301925050600101613ae9565b60e08101613b1c828a613ab4565b8181036020830152613b2e81896137ed565b90508181036040830152613b4281886137ed565b9050613b5160608301876138a0565b613b5e60808301866137a0565b613b6b60a08301856138a0565b81810360c0830152611ebb8184613ad0565b60408101613b8b82856138a0565b610e2460208301846138a0565b634e487b7160e01b600052602260045260246000fd5b600281046001821680613bc257607f821691505b60208210811415613bd557613bd5613b98565b50919050565b8051610b73816138b4565b600060208284031215613bfb57613bfb600080fd5b6000611e2f8484613bdb565b60408101613b8b82856137a0565b60c08101613c2382896138a0565b613c3060208301886138a0565b613c3d60408301876137a0565b613c4a60608301866138a0565b613c5760808301856137a0565b6135ed60a08301846138a0565b602881526000602082017f534254456e756d657261626c653a206f776e657220696e646578206f7574206f8152676620626f756e647360c01b602082015291505b5060400190565b60208082528101610b7381613c64565b602f81526000602082017f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636581526e103937b632b9903337b91039b2b63360891b60208201529150613ca5565b60208082528101610b7381613cbc565b601e81526000602082017f5342543a2063616c6c6572206973206e6f7420746f6b656e206f776e65720000815291505b5060200190565b60208082528101610b7381613d18565b602981526000602082017f534254456e756d657261626c653a20676c6f62616c20696e646578206f7574208152686f6620626f756e647360b81b60208201529150613ca5565b60208082528101610b7381613d5f565b634e487b7160e01b600052603260045260246000fd5b601581526000602082017414d0950e881a5b9d985b1a59081d1bdad95b881251605a1b81529150613d48565b60208082528101610b7381613dcb565b602681526000602082017f5342543a2061646472657373207a65726f206973206e6f7420612076616c69648152651037bbb732b960d11b60208201529150613ca5565b60208082528101610b7381613e07565b60c08101613e6882896138a0565b613c3060208301886137a0565b634e487b7160e01b600052604160045260246000fd5b634e487b7160e01b600052601160045260246000fd5b600082821015613eb357613eb3613e8b565b500390565b634e487b7160e01b600052603160045260246000fd5b6000600019821415613ee257613ee2613e8b565b5060010190565b8051610b73816136fc565b600060208284031215613f0957613f09600080fd5b6000611e2f8484613ee9565b601f81526000602082017f5265656e7472616e637947756172643a207265656e7472616e742063616c6c0081529150613d48565b60208082528101610b7381613f15565b60808101613f6782876138a0565b613f7460208301866138a0565b613f8160408301856137a0565b613f8e60608301846138a0565b95945050505050565b60808101613fa582876138a0565b613f7460208301866137a0565b6000610b73825190565b6000613fc6825190565b60208301613fd381613fb2565b92506020821015613ff457613fef600019836020036008021b90565b831692505b5050919050565b6000614005825190565b6140138185602086016137b7565b9290920192915050565b76020b1b1b2b9b9a1b7b73a3937b61d1030b1b1b7bab73a1604d1b815260170160006140498285613ffb565b7001034b99036b4b9b9b4b733903937b6329607d1b81526011019150611e2f8284613ffb565b600081600019048311821515161561408957614089613e8b565b500290565b634e487b7160e01b600052601260045260246000fd5b6000826140b3576140b361408e565b500490565b600081610b73565b601d81526000602082017f5342543a206d696e7420746f20746865207a65726f206164647265737300000081529150613d48565b60208082528101610b73816140c0565b601981526000602082017814d0950e881d1bdad95b88185b1c9958591e481b5a5b9d1959603a1b81529150613d48565b60208082528101610b7381614104565b6000821982111561415757614157613e8b565b500190565b6040810161416a82856138a0565b8181036020830152611e2f8184613846565b614185826137e3565b81018181106001600160401b03821117156141a2576141a2613e75565b6040525050565b60006141b460405190565b90506114b9828261417c565b60006001600160401b038211156141d9576141d9613e75565b5060209081020190565b60006141f66141f1846141c0565b6141a9565b8381529050602080820190840283018581111561421557614215600080fd5b835b81811015614239578061422a8882613ee9565b84525060209283019201614217565b5050509392505050565b600082601f83011261425757614257600080fd5b8151611e2f8482602086016141e3565b60006020828403121561427c5761427c600080fd5b81516001600160401b0381111561429557614295600080fd5b611e2f84828501614243565b6000816142b0576142b0613e8b565b506000190190565b60208082527f537472696e67733a20686578206c656e67746820696e73756666696369656e7491019081526000613d48565b60208082528101610b73816142b8565b6060810161430882866137a0565b61431560208301856137a0565b611e2f60408301846138a0565b60a0810161433082886138a0565b61433d60208301876138a0565b61434a60408301866138a0565b61435760608301856138a0565b610e0e60808301846137a0565b634e487b7160e01b600052602160045260246000fd5b601881526000602082017745434453413a20696e76616c6964207369676e617475726560401b81529150613d48565b60208082528101610b738161437a565b601f81526000602082017f45434453413a20696e76616c6964207369676e6174757265206c656e6774680081529150613d48565b60208082528101610b73816143b9565b602281526000602082017f45434453413a20696e76616c6964207369676e6174757265202773272076616c815261756560f01b60208201529150613ca5565b60208082528101610b73816143fd565b8015156136fe565b8051610b738161444c565b60006020828403121561447457614474600080fd5b6000611e2f8484614454565b602a81526000602082017f5361666545524332303a204552433230206f7065726174696f6e20646964206e8152691bdd081cdd58d8d9595960b21b60208201529150613ca5565b60208082528101610b7381614480565b60ff8116613775565b608081016144ee82876138a0565b6144fb60208301866144d7565b613f8160408301856138a0565b6000610e248284613ffb565b601d81526000602082017f416464726573733a2063616c6c20746f206e6f6e2d636f6e747261637400000081529150613d48565b60208082528101610b738161451456fe52eafc11f6f81f86878bffd31109a0d92f37506527754f00788853ff9f63b130a2646970667358221220bedfa5e1580b54e54fffd7068983e6a127913ae2e09ea63caa03ef60e5b9d86b64736f6c63430008080033
Constructor Arguments (ABI-Encoded and is the last bytes of the Contract Creation Code above)
00000000000000000000000084a74cc52048dd8421df4a9eb139d91bb7744b4e00000000000000000000000000000000000000000000000000000000000001e0000000000000000000000000000000000000000000000000000000000000022000000000000000000000000000000000000000000000000000000000000002600000000000000000000000008903d8d4f4c06814d7ecb42b1258e2209d53a7d40000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d000000000000000000000000b4fbf271143f4fbf7b91a5ded31805e42b2208d6000000000000000000000000d87ba7a50b2e7e660f678a895e4b72e7cb4ccd9c0000000000000000000000001f9840a85d5af5bf1d1762f925bdaddc4201f98400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000e56328c0ab5cb79af9df2f76c0479ba461550750000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000001b5363726f6c6c20494420536f756c6420426f756e6420546f6b656e000000000000000000000000000000000000000000000000000000000000000000000000034944530000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000003f68747470733a2f2f617277656176652e6e65742f466b6751464d64517343347055664d6170476a37727976486f46314e724536315274644e7267326777594500
-----Decoded View---------------
Arg [0] : admin (address): 0x84a74cC52048dd8421Df4a9EB139D91bb7744b4E
Arg [1] : name (string): Scroll ID Sould Bound Token
Arg [2] : symbol (string): IDS
Arg [3] : baseTokenURI (string): https://arweave.net/FkgQFMdQsC4pUfMapGj7ryvHoF1NrE61RtdNrg2gwYE
Arg [4] : soulboundIdentity (address): 0x8903D8D4F4c06814D7ecb42b1258E2209d53A7d4
Arg [5] : paymentParams (tuple):
Arg [1] : swapRouter (address): 0x7a250d5630B4cF539739dF2C5dAcb4c659F2488D
Arg [2] : wrappedNativeToken (address): 0xB4FBF271143F4FBf7B91A5ded31805e42b2208d6
Arg [3] : stableCoin (address): 0xD87Ba7A50B2E7E660f678A895E4B72E7CB4CCd9C
Arg [4] : masaToken (address): 0x1f9840a85d5aF5bf1D1762F925BDADdC4201F984
Arg [5] : projectFeeReceiver (address): 0x0000000000000000000000000000000000000000
Arg [6] : protocolFeeReceiver (address): 0x0E56328c0Ab5cb79aF9Df2F76C0479ba46155075
Arg [7] : protocolFeeAmount (uint256): 0
Arg [8] : protocolFeePercent (uint256): 0
Arg [9] : protocolFeePercentSub (uint256): 0
Arg [6] : _maxSBTToMint (uint256): 1
-----Encoded View---------------
22 Constructor Arguments found :
Arg [0] : 00000000000000000000000084a74cc52048dd8421df4a9eb139d91bb7744b4e
Arg [1] : 00000000000000000000000000000000000000000000000000000000000001e0
Arg [2] : 0000000000000000000000000000000000000000000000000000000000000220
Arg [3] : 0000000000000000000000000000000000000000000000000000000000000260
Arg [4] : 0000000000000000000000008903d8d4f4c06814d7ecb42b1258e2209d53a7d4
Arg [5] : 0000000000000000000000007a250d5630b4cf539739df2c5dacb4c659f2488d
Arg [6] : 000000000000000000000000b4fbf271143f4fbf7b91a5ded31805e42b2208d6
Arg [7] : 000000000000000000000000d87ba7a50b2e7e660f678a895e4b72e7cb4ccd9c
Arg [8] : 0000000000000000000000001f9840a85d5af5bf1d1762f925bdaddc4201f984
Arg [9] : 0000000000000000000000000000000000000000000000000000000000000000
Arg [10] : 0000000000000000000000000e56328c0ab5cb79af9df2f76c0479ba46155075
Arg [11] : 0000000000000000000000000000000000000000000000000000000000000000
Arg [12] : 0000000000000000000000000000000000000000000000000000000000000000
Arg [13] : 0000000000000000000000000000000000000000000000000000000000000000
Arg [14] : 0000000000000000000000000000000000000000000000000000000000000001
Arg [15] : 000000000000000000000000000000000000000000000000000000000000001b
Arg [16] : 5363726f6c6c20494420536f756c6420426f756e6420546f6b656e0000000000
Arg [17] : 0000000000000000000000000000000000000000000000000000000000000003
Arg [18] : 4944530000000000000000000000000000000000000000000000000000000000
Arg [19] : 000000000000000000000000000000000000000000000000000000000000003f
Arg [20] : 68747470733a2f2f617277656176652e6e65742f466b6751464d645173433470
Arg [21] : 55664d6170476a37727976486f46314e724536315274644e7267326777594500
Deployed Bytecode Sourcemap
348:6268:45:-:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;7767:238:36;;;;;;;;;;-1:-1:-1;7767:238:36;;;;;:::i;:::-;;:::i;:::-;;8439:253:48;;;;;;;;;;-1:-1:-1;8439:253:48;;;;;:::i;:::-;;:::i;:::-;;;;;;;:::i;:::-;;;;;;;;2173:38:36;;;;;;;;;;-1:-1:-1;2173:38:36;;;;;:::i;:::-;;:::i;:::-;;;;;;;:::i;1989:98:52:-;;;;;;;;;;;;;:::i;:::-;;;;;;;:::i;9327:150:36:-;;;;;;;;;;;;;:::i;:::-;;;;;;;:::i;10189:125::-;;;;;;;;;;-1:-1:-1;10189:125:36;;;;;:::i;:::-;;:::i;:::-;;;;;;;:::i;1355:42:48:-;;;;;;;;;;;;;;;;2422:36:36;;;;;;;;;;;;;;;;1796:33;;;;;;;;;;-1:-1:-1;1796:33:36;;;;-1:-1:-1;;;;;1796:33:36;;;1592:111:56;;;;;;;;;;-1:-1:-1;1679:10:56;:17;1592:111;;1106:28:48;;;;;;;;;;;;;;;;1158:36;;;;;;;;;;;;;;;;2349:918:45;;;;;;:::i;:::-;;:::i;9776:179:36:-;;;;;;;;;;-1:-1:-1;9776:179:36;;;;;:::i;:::-;;:::i;4614:196::-;;;;;;;;;;-1:-1:-1;4614:196:36;;;;;:::i;:::-;;:::i;4504:129:0:-;;;;;;;;;;-1:-1:-1;4504:129:0;;;;;:::i;:::-;;:::i;2061:404:50:-;;;;;;;;;;-1:-1:-1;2061:404:50;;;;;:::i;:::-;;:::i;4290:350:48:-;;;;;;;;;;-1:-1:-1;4290:350:48;;;;;:::i;:::-;;:::i;4929:145:0:-;;;;;;;;;;-1:-1:-1;4929:145:0;;;;;:::i;:::-;;:::i;1221:303:56:-;;;;;;;;;;-1:-1:-1;1221:303:56;;;;;:::i;:::-;;:::i;6038:214:0:-;;;;;;;;;;-1:-1:-1;6038:214:0;;;;;:::i;:::-;;:::i;2257:34:36:-;;;;;;;;;;-1:-1:-1;2257:34:36;;;;-1:-1:-1;;;;;2257:34:36;;;3749:279:48;;;;;;;;;;-1:-1:-1;3749:279:48;;;;;:::i;:::-;;:::i;4892:374::-;;;;;;;;;;-1:-1:-1;4892:374:48;;;;;:::i;:::-;;:::i;3775:196:36:-;;;;;;;;;;-1:-1:-1;3775:196:36;;;;;:::i;:::-;;:::i;896:84::-;;;;;;;;;;;;-1:-1:-1;;;;;;;;;;;896:84:36;;435:247:55;;;;;;;;;;-1:-1:-1;435:247:55;;;;;:::i;:::-;;:::i;7338:250:36:-;;;;;;;;;;-1:-1:-1;7338:250:36;;;;;:::i;:::-;;:::i;3168:356:48:-;;;;;;;;;;-1:-1:-1;3168:356:48;;;;;:::i;:::-;;:::i;7311:102::-;;;;;;;;;;-1:-1:-1;7311:102:48;;;;;:::i;:::-;;:::i;1772:272:56:-;;;;;;;;;;-1:-1:-1;1772:272:56;;;;;:::i;:::-;;:::i;1701:229:52:-;;;;;;;;;;-1:-1:-1;1701:229:52;;;;;:::i;:::-;;:::i;1052:24:48:-;;;;;;;;;;;;;;;;8722:262:36;;;;;;;;;;-1:-1:-1;8722:262:36;;;;;:::i;:::-;;:::i;1432:215:52:-;;;;;;;;;;-1:-1:-1;1432:215:52;;;;;:::i;:::-;;:::i;8937:858:48:-;;;;;;;;;;-1:-1:-1;8937:858:48;;;;;:::i;:::-;;:::i;5075:190:36:-;;;;;;;;;;-1:-1:-1;5075:190:36;;;;;:::i;:::-;;:::i;1224:40:48:-;;;;;;;;;;;;;;;;1002:43;;;;;;;;;;-1:-1:-1;1002:43:48;;;;-1:-1:-1;;;;;1002:43:48;;;;;;;;;;:::i;2115:52:36:-;;;;;;;;;;-1:-1:-1;2115:52:36;;;;;:::i;:::-;;;;;;;;;;;;;;;;3705:820:45;;;;;;:::i;:::-;;:::i;6134:386:48:-;;;;;;;;;;-1:-1:-1;6134:386:48;;;;;:::i;:::-;;:::i;484:31:45:-;;;;;;;;;;;;;;;;5021:633:23;;;;;;;;;;;;;:::i;:::-;;;;;;;;;;;;;:::i;6771:386:36:-;;;;;;;;;;-1:-1:-1;6771:386:36;;;;;:::i;:::-;;:::i;2297:32::-;;;;;;;;;;;;;;;;852:43:50;;;;;;;;;;-1:-1:-1;852:43:50;;;;;:::i;:::-;;;;;;;;;;;;;;;;3021:145:0;;;;;;;;;;-1:-1:-1;3021:145:0;;;;;:::i;:::-;;:::i;5920:638:36:-;;;;;;;;;;-1:-1:-1;5920:638:36;;;;;:::i;:::-;;:::i;2148:102:52:-;;;;;;;;;;;;;:::i;1836:25:36:-;;;;;;;;;;-1:-1:-1;1836:25:36;;;;-1:-1:-1;;;;;1836:25:36;;;2218:33;;;;;;;;;;-1:-1:-1;2218:33:36;;;;-1:-1:-1;;;;;2218:33:36;;;2153:49:0;;;;;;;;;;-1:-1:-1;2153:49:0;2198:4;2153:49;;8237:244:36;;;;;;;;;;-1:-1:-1;8237:244:36;;;;;:::i;:::-;;:::i;1287:38:48:-;;;;;;;;;;;;;;;;6828:294;;;;;;;;;;-1:-1:-1;6828:294:48;;;;;:::i;:::-;;:::i;1765:25:36:-;;;;;;;;;;-1:-1:-1;1765:25:36;;;;-1:-1:-1;;;;;1765:25:36;;;5448:291;;;;;;;;;;-1:-1:-1;5448:291:36;;;;;:::i;:::-;;:::i;4613:170:45:-;;;;;;;;;;-1:-1:-1;4613:170:45;;;;;:::i;:::-;;:::i;2671:425:50:-;;;;;;;;;;-1:-1:-1;2671:425:50;;;;;:::i;:::-;;:::i;5354:147:0:-;;;;;;;;;;-1:-1:-1;5354:147:0;;;;;:::i;:::-;;:::i;2335:33:36:-;;;;;;;;;;;;;;;;4170:244;;;;;;;;;;-1:-1:-1;4170:244:36;;;;;:::i;:::-;;:::i;10165:246:48:-;;;;;;;;;;-1:-1:-1;10165:246:48;;;;;:::i;:::-;;:::i;:::-;;;;;;;;:::i;1949:24:36:-;;;;;;;;;;-1:-1:-1;1949:24:36;;;;-1:-1:-1;;;;;1949:24:36;;;2633:332:48;;;;;;;;;;-1:-1:-1;2633:332:48;;;;;:::i;:::-;;:::i;5524:362::-;;;;;;;;;;-1:-1:-1;5524:362:48;;;;;:::i;:::-;;:::i;7767:238:36:-;2198:4:0;2631:16;2198:4;2631:10;:16::i;:::-;7913:17:36::1;;7891:18;:39;7887:63;;;7939:11;;-1:-1:-1::0;;;7939:11:36::1;;;;;;;;;;;7887:63;-1:-1:-1::0;7960:17:36::1;:38:::0;7767:238::o;8439:253:48:-;8622:4;8649:36;8673:11;8649:23;:36::i;:::-;8642:43;8439:253;-1:-1:-1;;8439:253:48:o;2173:38:36:-;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;;;;2173:38:36;;-1:-1:-1;2173:38:36;:::o;1989:98:52:-;2043:13;2075:5;2068:12;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;1989:98;:::o;9327:150:36:-;9410:16;9449:21;9442:28;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;;;;9442:28:36;;;;;;;;;;;;;;;;;;;;;;9327:150;:::o;10189:125::-;10255:7;10281:26;10300:6;10281:18;:26::i;2349:918:45:-;2574:7;2261:21:5;:19;:21::i;:::-;2606:17:45::1;::::0;:37:::1;::::0;-1:-1:-1;;;2606:37:45;;2593:10:::1;::::0;-1:-1:-1;;;;;2606:17:45::1;::::0;:25:::1;::::0;:37:::1;::::0;2632:10;;2606:37:::1;;;:::i;:::-;;;;;;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;::::0;::::1;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;2593:50;;2672:1;2657:12;;:16;:49;;;;;2694:12;;2677:13;2687:2;2677:9;:13::i;:::-;:29;;2657:49;2653:104;;;2744:12;::::0;2727:30:::1;::::0;-1:-1:-1;;;2727:30:45;;::::1;::::0;2740:2;;2727:30:::1;;;:::i;:::-;;;;;;;;2653:104;-1:-1:-1::0;;;;;2771:18:45;::::1;719:10:17::0;2771:18:45::1;2767:59;;719:10:17::0;2813:12:45::1;2798:28;;-1:-1:-1::0;;;2798:28:45::1;;;;;;;;:::i;2767:59::-;2837:15;2855:186;2885:13;2912:2;2928:50;2934:10;2946:16;2964:13;2928:5;:50::i;:::-;2992:16;3022:9;;2855:16;:186::i;:::-;2837:204;;3057:178;3087:7;3108:10;3132:16;3162:13;3189;3216:9;;3057:178;;;;;;;;;;;:::i;:::-;;;;;;;;3253:7:::0;-1:-1:-1;;2303:20:5;1716:1;2809:7;:22;2629:209;2303:20;2349:918:45;;;;;;;;:::o;9776:179:36:-;9884:7;9910:38;9926:13;9941:6;9910:15;:38::i;:::-;9903:45;9776:179;-1:-1:-1;;;9776:179:36:o;4614:196::-;2198:4:0;2631:16;2198:4;2631:10;:16::i;:::-;4724:10:36::1;::::0;-1:-1:-1;;;;;4724:25:36;;::::1;:10:::0;::::1;:25;4720:49;;;4758:11;;-1:-1:-1::0;;;4758:11:36::1;;;;;;;;;;;4720:49;-1:-1:-1::0;4779:10:36::1;:24:::0;;-1:-1:-1;;;;;;4779:24:36::1;-1:-1:-1::0;;;;;4779:24:36;;;::::1;::::0;;;::::1;::::0;;4614:196::o;4504:129:0:-;4578:7;4604:12;;;;;;;;;;:22;;;;4504:129::o;2061:404:50:-;2140:41;2198:4:0;719:10:17;3021:145:0;:::i;2140:41:50:-;2139:42;:100;;;;-1:-1:-1;2198:41:50;-1:-1:-1;;;;;;;;;;;719:10:17;3021:145:0;:::i;2198:41:50:-;2197:42;2139:100;2122:175;;;2257:40;;-1:-1:-1;;;2257:40:50;;;;;;;;;;;2122:175;-1:-1:-1;;;;;2311:24:50;;2307:50;;2344:13;;-1:-1:-1;;;2344:13:50;;;;;;;;;;;2307:50;-1:-1:-1;;;;;2371:23:50;;;;;;:11;:23;;;;;;;;2367:50;;;2403:14;;-1:-1:-1;;;2403:14:50;;;;;;;;;;;2367:50;-1:-1:-1;;;;;2428:23:50;;;;;:11;:23;;;;;:30;;-1:-1:-1;;2428:30:50;2454:4;2428:30;;;2061:404::o;4290:350:48:-;4375:41;2198:4:0;719:10:17;3021:145:0;:::i;4375:41:48:-;4374:42;:100;;;;-1:-1:-1;4433:41:48;-1:-1:-1;;;;;;;;;;;719:10:17;3021:145:0;:::i;4433:41:48:-;4432:42;4374:100;4357:175;;;4492:40;;-1:-1:-1;;;4492:40:48;;;;;;;;;;;4357:175;4562:13;4546:12;;:29;4542:53;;;4584:11;;-1:-1:-1;;;4584:11:48;;;;;;;;;;;4542:53;4605:12;:28;4290:350::o;4929:145:0:-;5012:18;5025:4;5012:12;:18::i;:::-;2631:16;2642:4;2631:10;:16::i;:::-;5042:25:::1;5053:4;5059:7;5042:10;:25::i;:::-;4929:145:::0;;;:::o;1221:303:56:-;1340:7;1388:20;1402:5;1388:13;:20::i;:::-;1380:5;:28;1359:115;;;;-1:-1:-1;;;1359:115:56;;;;;;;:::i;:::-;-1:-1:-1;;;;;;1491:19:56;;;;;;;;:12;:19;;;;;;;;:26;;;;;;;;;1221:303::o;6038:214:0:-;-1:-1:-1;;;;;6133:23:0;;719:10:17;6133:23:0;6125:83;;;;-1:-1:-1;;;6125:83:0;;;;;;;:::i;:::-;6219:26;6231:4;6237:7;6219:11;:26::i;:::-;6038:214;;:::o;3749:279:48:-;2198:4:0;2631:16;2198:4;2631:10;:16::i;:::-;3881:17:48::1;::::0;-1:-1:-1;;;;;3873:48:48;;::::1;3881:17:::0;::::1;3873:48;3869:84;;;3942:11;;-1:-1:-1::0;;;3942:11:48::1;;;;;;;;;;;3869:84;-1:-1:-1::0;3963:17:48::1;:58:::0;;-1:-1:-1;;;;;;3963:58:48::1;-1:-1:-1::0;;;;;3963:58:48;;;::::1;::::0;;;::::1;::::0;;3749:279::o;4892:374::-;4985:41;2198:4:0;719:10:17;3021:145:0;:::i;4985:41:48:-;4984:42;:100;;;;-1:-1:-1;5043:41:48;-1:-1:-1;;;;;;;;;;;719:10:17;3021:145:0;:::i;5043:41:48:-;5042:42;4984:100;4967:175;;;5102:40;;-1:-1:-1;;;5102:40:48;;;;;;;;;;;4967:175;5176:17;5156:16;;:37;5152:61;;;5202:11;;-1:-1:-1;;;5202:11:48;;;;;;;;;;;5152:61;5223:16;:36;4892:374::o;3775:196:36:-;2198:4:0;2631:16;2198:4;2631:10;:16::i;:::-;3885:10:36::1;::::0;-1:-1:-1;;;;;3885:25:36;;::::1;:10:::0;::::1;:25;3881:49;;;3919:11;;-1:-1:-1::0;;;3919:11:36::1;;;;;;;;;;;3881:49;-1:-1:-1::0;3940:10:36::1;:24:::0;;-1:-1:-1;;;;;;3940:24:36::1;-1:-1:-1::0;;;;;3940:24:36;;;::::1;::::0;;;::::1;::::0;;3775:196::o;435:247:55:-;564:31;719:10:17;587:7:55;564:8;:31::i;:::-;543:108;;;;-1:-1:-1;;;543:108:55;;;;;;;:::i;:::-;661:14;667:7;661:5;:14::i;:::-;435:247;:::o;7338:250:36:-;2198:4:0;2631:16;2198:4;2631:10;:16::i;:::-;7490:19:36::1;::::0;-1:-1:-1;;;;;7466:43:36;;::::1;7490:19:::0;::::1;7466:43;7462:67;;;7518:11;;-1:-1:-1::0;;;7518:11:36::1;;;;;;;;;;;7462:67;-1:-1:-1::0;7539:19:36::1;:42:::0;;-1:-1:-1;;;;;;7539:42:36::1;-1:-1:-1::0;;;;;7539:42:36;;;::::1;::::0;;;::::1;::::0;;7338:250::o;3168:356:48:-;3255:41;2198:4:0;719:10:17;3021:145:0;:::i;3255:41:48:-;3254:42;:100;;;;-1:-1:-1;3313:41:48;-1:-1:-1;;;;;;;;;;;719:10:17;3021:145:0;:::i;3313:41:48:-;3312:42;3254:100;3237:175;;;3372:40;;-1:-1:-1;;;3372:40:48;;;;;;;;;;;3237:175;3443:14;3426:13;;:31;3422:55;;;3466:11;;-1:-1:-1;;;3466:11:48;;;;;;;;;;;3422:55;3487:13;:30;3168:356::o;7311:102::-;7367:4;7390:16;7398:7;7390;:16::i;1772:272:56:-;1861:7;1909:27;1679:10;:17;;1592:111;1909:27;1901:5;:35;1880:123;;;;-1:-1:-1;;;1880:123:56;;;;;;;:::i;:::-;2020:10;2031:5;2020:17;;;;;;;;:::i;:::-;;;;;;;;;2013:24;;1772:272;;;:::o;1701:229:52:-;1787:7;1822:16;;;:7;:16;;;;;;-1:-1:-1;;;;;1822:16:52;1856:19;1848:53;;;;-1:-1:-1;;;1848:53:52;;;;;;;:::i;8722:262:36:-;2198:4:0;2631:16;2198:4;2631:10;:16::i;:::-;8880:21:36::1;;8854:22;:47;8850:71;;;8910:11;;-1:-1:-1::0;;;8910:11:36::1;;;;;;;;;;;8850:71;-1:-1:-1::0;8931:21:36::1;:46:::0;8722:262::o;1432:215:52:-;1518:7;-1:-1:-1;;;;;1545:19:52;;1537:70;;;;-1:-1:-1;;;1537:70:52;;;;;;;:::i;:::-;-1:-1:-1;;;;;;1624:16:52;;;;;:9;:16;;;;;;;1432:215::o;8937:858:48:-;9017:13;9046:9;;9059:1;9046:14;:36;;;;-1:-1:-1;9064:13:48;;:18;9046:36;9042:725;;;-1:-1:-1;9106:1:48;8937:858;;;:::o;9042:725::-;9158:9;;-1:-1:-1;;;;;9141:26:48;;;9158:9;;9141:26;:77;;;;-1:-1:-1;;;;;;9183:35:48;;;;;;:20;:35;;;;;;;;9141:77;:110;;;;;9250:1;9234:13;;:17;9141:110;9124:643;;;-1:-1:-1;;9337:13:48;;;8937:858::o;9124:643::-;9401:10;;-1:-1:-1;;;;;9384:27:48;;;9401:10;;9384:27;:66;;;;-1:-1:-1;;;;;;9415:35:48;;;;;;:20;:35;;;;;;;;9384:66;9367:400;;;-1:-1:-1;;9510:9:48;;;8937:858::o;9367:400::-;-1:-1:-1;;;;;9540:35:48;;;;;;:20;:35;;;;;;;;9536:231;;;9635:48;9658:13;9673:9;;9635:22;:48::i;9536:231::-;9742:13;9721:35;;-1:-1:-1;;;9721:35:48;;;;;;;;:::i;9536:231::-;8937:858;;;:::o;5075:190:36:-;2198:4:0;2631:16;2198:4;2631:10;:16::i;:::-;5183:9:36::1;::::0;-1:-1:-1;;;;;5183:23:36;;::::1;:9:::0;::::1;:23;5179:47;;;5215:11;;-1:-1:-1::0;;;5215:11:36::1;;;;;;;;;;;5179:47;-1:-1:-1::0;5236:9:36::1;:22:::0;;-1:-1:-1;;;;;;5236:22:36::1;-1:-1:-1::0;;;;;5236:22:36;;;::::1;::::0;;;::::1;::::0;;5075:190::o;3705:820:45:-;3909:7;3947:1;3932:12;;:16;:49;;;;;3969:12;;3952:13;3962:2;3952:9;:13::i;:::-;:29;;3932:49;3928:104;;;4019:12;;4002:30;;-1:-1:-1;;;4002:30:45;;;;4015:2;;4002:30;;;:::i;3928:104::-;-1:-1:-1;;;;;4046:18:45;;719:10:17;4046:18:45;4042:59;;719:10:17;4088:12:45;640:96:17;4042:59:45;4112:15;4130:178;4160:13;4187:2;4203:42;4209:2;4213:16;4231:13;4203:5;:42::i;:::-;4259:16;4289:9;;4130:16;:178::i;:::-;4112:196;;4324:169;4353:7;4374:2;4390:16;4420:13;4447;4474:9;;4324:169;;;;;;;;;;;:::i;:::-;;;;;;;;4511:7;3705:820;-1:-1:-1;;;;;;;3705:820:45:o;6134:386:48:-;6231:41;2198:4:0;719:10:17;3021:145:0;:::i;6231:41:48:-;6230:42;:100;;;;-1:-1:-1;6289:41:48;-1:-1:-1;;;;;;;;;;;719:10:17;3021:145:0;:::i;6289:41:48:-;6288:42;6230:100;6213:175;;;6348:40;;-1:-1:-1;;;6348:40:48;;;;;;;;;;;6213:175;6424:19;6402:18;;:41;6398:65;;;6452:11;;-1:-1:-1;;;6452:11:48;;;;;;;;;;;6398:65;6473:18;:40;6134:386::o;5021:633:23:-;5136:13;5163:18;;5136:13;;;5163:18;5427:41;:5;5454:13;5427:26;:41::i;:::-;5482:47;:8;5512:16;5482:29;:47::i;:::-;5621:16;;;5605:1;5621:16;;;;;;;;;-1:-1:-1;;;5376:271:23;;;-1:-1:-1;5376:271:23;;-1:-1:-1;5543:13:23;;-1:-1:-1;5578:4:23;;-1:-1:-1;5605:1:23;-1:-1:-1;5621:16:23;-1:-1:-1;5376:271:23;-1:-1:-1;5021:633:23:o;6771:386:36:-;6868:41;2198:4:0;719:10:17;3021:145:0;:::i;6868:41:36:-;6867:42;:100;;;;-1:-1:-1;6926:41:36;-1:-1:-1;;;;;;;;;;;719:10:17;3021:145:0;:::i;6926:41:36:-;6925:42;6867:100;6850:175;;;6985:40;;-1:-1:-1;;;6985:40:36;;;;;;;;;;;6850:175;7062:18;;-1:-1:-1;;;;;7039:41:36;;;7062:18;;7039:41;7035:65;;;7089:11;;-1:-1:-1;;;7089:11:36;;;;;;;;;;;7035:65;7110:18;:40;;-1:-1:-1;;;;;;7110:40:36;-1:-1:-1;;;;;7110:40:36;;;;;;;;;;6771:386::o;3021:145:0:-;3107:4;3130:12;;;;;;;;;;;-1:-1:-1;;;;;3130:29:0;;;;;;;;;;;;;;;3021:145::o;5920:638:36:-;2198:4:0;2631:16;2198:4;2631:10;:16::i;:::-;-1:-1:-1;;;;;6041:36:36;::::1;;::::0;;;:20:::1;:36;::::0;;;;;::::1;;6036:99;;6120:14;6098:37;;-1:-1:-1::0;;;6098:37:36::1;;;;;;;;:::i;6036:99::-;-1:-1:-1::0;;;;;6146:36:36;::::1;6185:5;6146:36:::0;;;:20:::1;:36;::::0;;;;:44;;-1:-1:-1;;6146:44:36::1;::::0;;6200:352:::1;6224:21;:28:::0;6220:32;::::1;6200:352;;;6305:14;-1:-1:-1::0;;;;;6277:42:36::1;:21;6299:1;6277:24;;;;;;;;:::i;:::-;;::::0;;;::::1;::::0;;;::::1;::::0;-1:-1:-1;;;;;6277:24:36::1;:42;6273:269;;;6366:21;6409:28:::0;;:32:::1;::::0;6440:1:::1;::::0;6409:32:::1;:::i;:::-;6366:93;;;;;;;;:::i;:::-;;::::0;;;::::1;::::0;;;::::1;::::0;6339:21:::1;:24:::0;;-1:-1:-1;;;;;6366:93:36;;::::1;::::0;6361:1;;6339:24;::::1;;;;;:::i;:::-;;;;;;;;;:120;;;;;-1:-1:-1::0;;;;;6339:120:36::1;;;;;-1:-1:-1::0;;;;;6339:120:36::1;;;;;;6477:21;:27;;;;;;;:::i;:::-;;::::0;;;::::1;::::0;;;;-1:-1:-1;;6477:27:36;;;;;-1:-1:-1;;;;;;6477:27:36::1;::::0;;;;;4929:145:0;;;:::o;6273:269:36:-:1;6254:3:::0;::::1;::::0;::::1;:::i;:::-;;;;6200:352;;2148:102:52::0;2204:13;2236:7;2229:14;;;;;:::i;8237:244:36:-;2198:4:0;2631:16;2198:4;2631:10;:16::i;:::-;8386:18:36::1;;8363:19;:41;8359:65;;;8413:11;;-1:-1:-1::0;;;8413:11:36::1;;;;;;;;;;;8359:65;-1:-1:-1::0;8434:18:36::1;:40:::0;8237:244::o;6828:294:48:-;6914:17;;6891:7;;-1:-1:-1;;;;;6914:17:48;6910:102;;6986:26;;-1:-1:-1;;;6986:26:48;;;;;;;;;;;6910:102;7023:13;7039:22;7053:7;7039:13;:22::i;:::-;7078:17;;:37;;-1:-1:-1;;;7078:37:48;;7023:38;;-1:-1:-1;;;;;;7078:17:48;;:30;;:37;;7023:38;;7078:37;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;5448:291:36:-;2198:4:0;2631:16;2198:4;2631:10;:16::i;:::-;-1:-1:-1;;;;;5567:36:36;::::1;;::::0;;;:20:::1;:36;::::0;;;;;::::1;;5563:63;;;5612:14;;-1:-1:-1::0;;;5612:14:36::1;;;;;;;;;;;5563:63;-1:-1:-1::0;;;;;;5637:36:36::1;;::::0;;;:20:::1;:36;::::0;;;;:43;;-1:-1:-1;;5637:43:36::1;5676:4;5637:43:::0;;::::1;::::0;;;5690:21:::1;:42:::0;;;;::::1;::::0;;;;;;::::1;::::0;;-1:-1:-1;;;;;;5690:42:36::1;::::0;;::::1;::::0;;5448:291::o;4613:170:45:-;4700:13;4725:23;4740:7;4725:14;:23::i;:::-;4766:10;:8;:10::i;2671:425:50:-;2753:41;2198:4:0;719:10:17;3021:145:0;:::i;2753:41:50:-;2752:42;:100;;;;-1:-1:-1;2811:41:50;-1:-1:-1;;;;;;;;;;;719:10:17;3021:145:0;:::i;2811:41:50:-;2810:42;2752:100;2735:175;;;2870:40;;-1:-1:-1;;;2870:40:50;;;;;;;;;;;2735:175;-1:-1:-1;;;;;2924:24:50;;2920:50;;2957:13;;-1:-1:-1;;;2957:13:50;;;;;;;;;;;2920:50;-1:-1:-1;;;;;2985:23:50;;;;;;:11;:23;;;;;;;;2980:67;;3036:10;3017:30;;-1:-1:-1;;;3017:30:50;;;;;;;;:::i;2980:67::-;-1:-1:-1;;;;;3058:23:50;3084:5;3058:23;;;:11;:23;;;;;:31;;-1:-1:-1;;3058:31:50;;;2671:425::o;5354:147:0:-;5438:18;5451:4;5438:12;:18::i;:::-;2631:16;2642:4;2631:10;:16::i;:::-;5468:26:::1;5480:4;5486:7;5468:11;:26::i;4170:244:36:-:0;2198:4:0;2631:16;2198:4;2631:10;:16::i;:::-;4296:18:36::1;::::0;-1:-1:-1;;;;;4296:41:36;;::::1;:18:::0;::::1;:41;4292:65;;;4346:11;;-1:-1:-1::0;;;4346:11:36::1;;;;;;;;;;;4292:65;-1:-1:-1::0;4367:18:36::1;:40:::0;;-1:-1:-1;;;;;;4367:40:36::1;-1:-1:-1::0;;;;;4367:40:36;;;::::1;::::0;;;::::1;::::0;;4170:244::o;10165:246:48:-;10260:13;10275:19;10314:27;10327:13;10314:12;:27::i;:::-;10306:35;;10359:5;10366:37;10382:13;10397:5;10366:15;:37::i;:::-;10351:53;;;;10165:246;;;:::o;2633:332::-;2712:41;2198:4:0;719:10:17;3021:145:0;:::i;2712:41:48:-;2711:42;:100;;;;-1:-1:-1;2770:41:48;-1:-1:-1;;;;;;;;;;;719:10:17;3021:145:0;:::i;2770:41:48:-;2769:42;2711:100;2694:175;;;2829:40;;-1:-1:-1;;;2829:40:48;;;;;;;;;;;2694:175;2896:10;2883:9;;:23;2879:47;;;2915:11;;-1:-1:-1;;;2915:11:48;;;;;;;;;;;2879:47;2936:9;:22;2633:332::o;5524:362::-;5613:41;2198:4:0;719:10:17;3021:145:0;:::i;5613:41:48:-;5612:42;:100;;;;-1:-1:-1;5671:41:48;-1:-1:-1;;;;;;;;;;;719:10:17;3021:145:0;:::i;5671:41:48:-;5670:42;5612:100;5595:175;;;5730:40;;-1:-1:-1;;;5730:40:48;;;;;;;;;;;5595:175;5802:15;5784:14;;:33;5780:57;;;5826:11;;-1:-1:-1;;;5826:11:48;;;;;;;;;;;5780:57;5847:14;:32;5524:362::o;2895:341:19:-;2991:11;3040:2;3024:5;3018:19;:24;3014:216;;;3065:20;3079:5;3065:13;:20::i;:::-;3058:27;;;;3014:216;3157:5;3142;3116:46;;;;;;;;:::i;:::-;-1:-1:-1;1371:66:19;;-1:-1:-1;3176:43:19;;3310:202:20;3486:10;3310:202::o;3460:103:0:-;3526:30;3537:4;719:10:17;3526::0;:30::i;891:254:56:-;1004:4;-1:-1:-1;;;;;;1039:47:56;;-1:-1:-1;;;1039:47:56;;:99;;;1102:36;1126:11;1102:23;:36::i;12576:250:36:-;12680:21;;12657:7;;12680:25;12676:144;;12728:42;12766:3;12728:33;12739:21;;12728:6;:10;;:33;;;;:::i;:::-;:37;;:42::i;12676:144::-;-1:-1:-1;12808:1:36;;12576:250;-1:-1:-1;12576:250:36:o;2336:287:5:-;1759:1;2468:7;;:19;;2460:63;;;;-1:-1:-1;;;2460:63:5;;;;;;;:::i;:::-;1759:1;2598:7;:18;2336:287::o;4871:592:45:-;5008:7;5046:410;5147:138;5311:10;5347:16;5389:13;5111:313;;;;;;;;;;;:::i;:::-;;;;;;;;;;;;;5080:362;;;;;;5046:16;:410::i;:::-;5027:429;4871:592;-1:-1:-1;;;;4871:592:45:o;3661:578:50:-;3862:7;3881:44;3889:6;3897:9;;3881:44;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;3908:16:50;;-1:-1:-1;3881:7:50;;-1:-1:-1;;3881:44:50:i;:::-;3937:13;3952:19;3975:64;4016:13;3975:27;:64::i;:::-;3936:103;;;;4049:39;4054:13;4069:5;4076:11;4049:4;:39::i;:::-;4099:15;4117:25;:15;918:14:18;;827:112;4117:25:50;4099:43;;4152:27;:15;1032:19:18;;1050:1;1032:19;;;945:123;4152:27:50;4189:18;4195:2;4199:7;4189:5;:18::i;:::-;4225:7;3661:578;-1:-1:-1;;;;;;;;;3661:578:50:o;11670:672:36:-;11835:17;;11779:7;;;;11835:21;11831:315;;11893:10;;-1:-1:-1;;;;;11876:27:36;;;11893:10;;11876:27;11872:264;;;-1:-1:-1;11937:17:36;;11872:264;;;12007:114;12051:13;12086:17;;12007:22;:114::i;:::-;11993:128;;11872:264;12159:18;;:22;12155:153;;12211:86;12244:39;12279:3;12244:30;12255:18;;12244:6;:10;;:30;;;;:::i;:39::-;12211:11;;:15;:86::i;7587:233:0:-;7670:22;7678:4;7684:7;7670;:22::i;:::-;7665:149;;7708:6;:12;;;;;;;;;;;-1:-1:-1;;;;;7708:29:0;;;;;;;;;:36;;-1:-1:-1;;7708:36:0;7740:4;7708:36;;;7790:12;719:10:17;;640:96;7790:12:0;-1:-1:-1;;;;;7763:40:0;7781:7;-1:-1:-1;;;;;7763:40:0;7775:4;7763:40;;;;;;;;;;7587:233;;:::o;7991:234::-;8074:22;8082:4;8088:7;8074;:22::i;:::-;8070:149;;;8144:5;8112:12;;;;;;;;;;;-1:-1:-1;;;;;8112:29:0;;;;;;;;;;:37;;-1:-1:-1;;8112:37:0;;;8168:40;719:10:17;;8112:12:0;;8168:40;;8144:5;8168:40;7991:234;;:::o;3139:199:52:-;3244:4;3260:13;3276:20;3288:7;3276:11;:20::i;:::-;-1:-1:-1;;;;;3314:16:52;;;;;;;-1:-1:-1;;3139:199:52;;;;:::o;4580:320::-;4639:13;4655:20;4667:7;4655:11;:20::i;:::-;4639:36;;4686:48;4707:5;4722:1;4726:7;4686:20;:48::i;:::-;-1:-1:-1;;;;;4745:16:52;;;;;;:9;:16;;;;;:21;;4765:1;;4745:16;:21;;4765:1;;4745:21;:::i;:::-;;;;-1:-1:-1;;4783:16:52;;;;:7;:16;;;;;;4776:23;;-1:-1:-1;;;;;;4776:23:52;;;4815:20;4791:7;;-1:-1:-1;;;;;4815:20:52;;;;;4783:16;4815:20;6038:214:0;;:::o;3583:125:52:-;3648:4;3671:16;;;:7;:16;;;;;;-1:-1:-1;;;;;3671:16:52;:30;;;3583:125::o;10816:555:36:-;10964:7;10947:6;17190:1;17181:6;:10;:38;;;;-1:-1:-1;17195:10:36;;-1:-1:-1;;;;;17195:10:36;:24;17181:38;17177:84;;;17240:21;;-1:-1:-1;;;17240:21:36;;;;;;;;;;;17177:84;17284:1;17275:6;:10;:46;;;;-1:-1:-1;17289:18:36;;-1:-1:-1;;;;;17289:18:36;:32;17275:46;17271:92;;;17342:21;;-1:-1:-1;;;17342:21:36;;;;;;;;;;;17271:92;17386:1;17377:6;:10;:38;;;;-1:-1:-1;17391:10:36;;-1:-1:-1;;;;;17391:10:36;:24;17377:38;17373:84;;;17436:21;;-1:-1:-1;;;17436:21:36;;;;;;;;;;;17373:84;17480:1;17471:6;:10;:46;;;;-1:-1:-1;17485:18:36;;-1:-1:-1;;;;;17485:18:36;:32;17471:46;17467:92;;;17538:21;;-1:-1:-1;;;17538:21:36;;;;;;;;;;;17467:92;-1:-1:-1;;;;;10988:35:36;::::1;;::::0;;;:20:::1;:35;::::0;;;;;::::1;;10987:36;::::0;:67:::1;;-1:-1:-1::0;11044:10:36::1;::::0;-1:-1:-1;;;;;11027:27:36;;::::1;11044:10:::0;::::1;11027:27;10987:67;10983:119;;;11088:13;11075:27;;-1:-1:-1::0;;;11075:27:36::1;;;;;;;;:::i;10983:119::-;11117:11:::0;11113:25:::1;;11137:1;11130:8;;;;11113:25;-1:-1:-1::0;;;;;11153:27:36;::::1;11149:216;;11223:18;::::0;11243:10:::1;::::0;11203:59:::1;::::0;-1:-1:-1;;;;;11223:18:36;;::::1;::::0;11243:10:::1;11255:6:::0;11203:19:::1;:59::i;:::-;11196:66;;;;11149:216;11335:10;::::0;11300:54:::1;::::0;11320:13;;-1:-1:-1;;;;;11335:10:36::1;11347:6:::0;11300:19:::1;:54::i;11149:216::-;10816:555:::0;;;;;:::o;5469:568:45:-;5598:7;5636:394;5737:130;5893:2;5921:16;5963:13;5701:297;;;;;;;;;;;:::i;3367:268:19:-;3461:13;1371:66;3490:47;;3486:143;;3560:15;3569:5;3560:8;:15::i;3486:143::-;3613:5;3606:12;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;4984:130:52;5065:16;5073:7;5065;:16::i;:::-;5057:50;;;;-1:-1:-1;;;5057:50:52;;;;;;;:::i;10499:112:48:-;10559:13;10591;10584:20;;;;;:::i;1689:286:19:-;1754:11;1777:17;1803:3;1777:30;;1835:2;1821:4;:11;:16;1817:72;;;1874:3;1860:18;;-1:-1:-1;;;1860:18:19;;;;;;;;:::i;1817:72::-;1955:11;;1938:13;1955:4;1938:13;:::i;:::-;1930:36;;1689:286;-1:-1:-1;;;1689:286:19:o;3844:479:0:-;3932:22;3940:4;3946:7;3932;:22::i;:::-;3927:390;;4115:28;4135:7;4115:19;:28::i;:::-;4214:38;4242:4;4249:2;4214:19;:38::i;:::-;4022:252;;;;;;;;;:::i;:::-;;;;-1:-1:-1;;4022:252:0;;;;;;;;;;-1:-1:-1;;;3970:336:0;;;;;;;:::i;1068:308:52:-;1184:4;-1:-1:-1;;;;;;1219:37:52;;-1:-1:-1;;;1219:37:52;;:98;;-1:-1:-1;;;;;;;1272:45:52;;-1:-1:-1;;;1272:45:52;1219:98;:150;;;;1333:36;1357:11;1333:23;:36::i;3465:96:28:-;3523:7;3549:5;3553:1;3549;:5;:::i;3850:96::-;3908:7;3934:5;3938:1;3934;:5;:::i;4768:165:23:-;4845:7;4871:55;4893:20;:18;:20::i;:::-;4915:10;8536:4:22;8530:11;-1:-1:-1;;;8554:23:22;;8606:4;8597:14;;8590:39;;;;8658:4;8649:14;;8642:34;8712:4;8697:20;;;8336:397;3348:307:50;3474:15;3492:32;3506:6;3514:9;3492:13;:32::i;:::-;3474:50;;3549:6;-1:-1:-1;;;;;3538:17:50;:7;-1:-1:-1;;;;;3538:17:50;;3534:48;;3564:18;;-1:-1:-1;;;3564:18:50;;;;;;;;;;;3534:48;-1:-1:-1;;;;;3597:20:50;;;;;;:11;:20;;;;;;;;3592:56;;3640:7;3626:22;;-1:-1:-1;;;3626:22:50;;;;;;;;:::i;3592:56::-;3464:191;3348:307;;;:::o;13297:2588:36:-;13434:23;:6;13445:11;13434:10;:23::i;:::-;17190:1;17181:6;:10;:38;;;;-1:-1:-1;17195:10:36;;-1:-1:-1;;;;;17195:10:36;:24;17181:38;17177:84;;;17240:21;;-1:-1:-1;;;17240:21:36;;;;;;;;;;;17177:84;17284:1;17275:6;:10;:46;;;;-1:-1:-1;17289:18:36;;-1:-1:-1;;;;;17289:18:36;:32;17275:46;17271:92;;;17342:21;;-1:-1:-1;;;17342:21:36;;;;;;;;;;;17271:92;17386:1;17377:6;:10;:38;;;;-1:-1:-1;17391:10:36;;-1:-1:-1;;;;;17391:10:36;:24;17377:38;17373:84;;;17436:21;;-1:-1:-1;;;17436:21:36;;;;;;;;;;;17373:84;17480:1;17471:6;:10;:46;;;;-1:-1:-1;17485:18:36;;-1:-1:-1;;;;;17485:18:36;:32;17471:46;17467:92;;;17538:21;;-1:-1:-1;;;17538:21:36;;;;;;;;;;;17467:92;13473:11;;:31;::::1;;;-1:-1:-1::0;13488:16:36;;13473:31:::1;13469:44;;;13506:7;;13469:44;13523:22;13548:26;13567:6;13548:18;:26::i;:::-;13523:51;;13617:1;13603:11;:15;:37;;;;13639:1;13622:14;:18;13603:37;13602:88;;;;-1:-1:-1::0;13657:19:36::1;::::0;-1:-1:-1;;;;;13657:19:36::1;:33:::0;13602:88:::1;13585:150;;;13708:27;;-1:-1:-1::0;;;13708:27:36::1;;;;;;;;;;;13585:150;-1:-1:-1::0;;;;;13751:35:36;::::1;;::::0;;;:20:::1;:35;::::0;;;;;::::1;;13746:96;;13828:13;13807:35;;-1:-1:-1::0;;;13807:35:36::1;;;;;;;;:::i;13746:96::-;-1:-1:-1::0;;;;;13856:27:36;::::1;13852:2027;;13934:23;:6:::0;13945:11;13934:10:::1;:23::i;:::-;13922:9;:35;13918:110;;;14004:23;:6:::0;14015:11;14004:10:::1;:23::i;:::-;13982:46;;-1:-1:-1::0;;;13982:46:36::1;;;;;;;;:::i;13918:110::-;14075:1;14046:26;:6:::0;14057:14;14046:10:::1;:26::i;:::-;:30;14042:252;;;14123:18;::::0;14097:12:::1;::::0;-1:-1:-1;;;;;14123:18:36::1;14176:26;:6:::0;14187:14;14176:10:::1;:26::i;:::-;14115:109;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;14096:128;;;14247:7;14242:37;;14263:16;;-1:-1:-1::0;;;14263:16:36::1;;;;;;;;;;;14242:37;14078:216;14042:252;14311:15:::0;;14307:223:::1;;14373:19;::::0;14365:95:::1;::::0;14347:12:::1;::::0;-1:-1:-1;;;;;14373:19:36::1;::::0;14427:11;;14365:95:::1;::::0;::::1;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;14346:114;;;14483:7;14478:37;;14499:16;;-1:-1:-1::0;;;14499:16:36::1;;;;;;;;;;;14478:37;14328:202;14307:223;14547:18:::0;;14543:229:::1;;14612:19;::::0;14604:98:::1;::::0;14586:12:::1;::::0;-1:-1:-1;;;;;14612:19:36::1;::::0;14666:14;;14604:98:::1;::::0;::::1;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;14585:117;;;14725:7;14720:37;;14741:16;;-1:-1:-1::0;;;14741:16:36::1;;;;;;;;;;;14720:37;14567:205;14543:229;14801:23;:6:::0;14812:11;14801:10:::1;:23::i;:::-;14789:9;:35;14785:293;;;14875:14;14892:38;14906:23;:6:::0;14917:11;14906:10:::1;:23::i;:::-;14892:9;::::0;:13:::1;:38::i;:::-;14875:55;;14949:12;14975:10;-1:-1:-1::0;;;;;14967:24:36::1;14999:6;14967:43;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;14948:62;;;15033:7;15028:35;;15049:14;;-1:-1:-1::0;;;15049:14:36::1;;;;;;;;;;;15028:35;14826:252;;14785:293;13852:2027;;;15193:1;15164:26;:6:::0;15175:14;15164:10:::1;:26::i;:::-;:30;15160:245;;;15306:18;::::0;15214:176:::1;::::0;15274:10:::1;::::0;-1:-1:-1;;;;;15306:18:36::1;15346:26;:6:::0;15357:14;15346:10:::1;:26::i;:::-;-1:-1:-1::0;;;;;15214:38:36;::::1;::::0;:176;;:38:::1;:176::i;:::-;15422:15:::0;;15418:216:::1;;15549:19;::::0;15457:162:::1;::::0;-1:-1:-1;;;;;15457:38:36;;::::1;::::0;15517:10:::1;::::0;15549:19:::1;15590:11:::0;15457:38:::1;:162::i;:::-;15651:18:::0;;15647:222:::1;;15781:19;::::0;15689:165:::1;::::0;-1:-1:-1;;;;;15689:38:36;;::::1;::::0;15749:10:::1;::::0;15781:19:::1;15822:14:::0;15689:38:::1;:165::i;:::-;13459:2426;13297:2588:::0;;;;:::o;4026:405:52:-;-1:-1:-1;;;;;4105:16:52;;4097:58;;;;-1:-1:-1;;;4097:58:52;;;;;;;:::i;:::-;4174:16;4182:7;4174;:16::i;:::-;4173:17;4165:55;;;;-1:-1:-1;;;4165:55:52;;;;;;;:::i;:::-;4231:45;4260:1;4264:2;4268:7;4231:20;:45::i;:::-;-1:-1:-1;;;;;4287:13:52;;;;;;:9;:13;;;;;:18;;4304:1;;4287:13;:18;;4304:1;;4287:18;:::i;:::-;;;;-1:-1:-1;;4315:16:52;;;;:7;:16;;;;;;:21;;-1:-1:-1;;;;;;4315:21:52;-1:-1:-1;;;;;4315:21:52;;;;;;;;4352:17;;4315:16;;4352:17;;;6038:214:0;;:::o;2755:96:28:-;2813:7;2839:5;2843:1;2839;:5;:::i;10617:211:48:-;10776:45;10803:4;10809:2;10813:7;10776:26;:45::i;15891:387:36:-;16030:7;16049:24;16083:21;16121:46;16146:10;16158:8;16121:24;:46::i;:::-;16202:10;;16187:57;;-1:-1:-1;;;16187:57:36;;16114:53;;-1:-1:-1;;;;;;16202:10:36;;16187:39;;:57;;16227:10;;16114:53;;16187:57;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;16187:57:36;;;;;;;;;;;;:::i;:::-;16177:67;;16261:7;16269:1;16261:10;;;;;;;;:::i;:::-;;;;;;;16254:17;;;;15891:387;;;;;:::o;2059:405:19:-;2118:13;2143:11;2157:16;2168:4;2157:10;:16::i;:::-;2281:14;;;2292:2;2281:14;;;;;;;;;2143:30;;-1:-1:-1;2261:17:19;;2281:14;;;;;;;;;-1:-1:-1;;;2371:16:19;;;-1:-1:-1;2416:4:19;2407:14;;2400:28;;;;-1:-1:-1;2371:16:19;2059:405::o;2407:149:21:-;2465:13;2497:52;-1:-1:-1;;;;;2509:22:21;;343:2;1818:437;1893:13;1918:19;1950:10;1954:6;1950:1;:10;:::i;:::-;:14;;1963:1;1950:14;:::i;:::-;-1:-1:-1;;;;;1940:25:21;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;1940:25:21;;1918:47;;-1:-1:-1;;;1975:6:21;1982:1;1975:9;;;;;;;;:::i;:::-;;;;:15;-1:-1:-1;;;;;1975:15:21;;;;;;;;;-1:-1:-1;;;2000:6:21;2007:1;2000:9;;;;;;;;:::i;:::-;;;;:15;-1:-1:-1;;;;;2000:15:21;;;;;;;;-1:-1:-1;2030:9:21;2042:10;2046:6;2042:1;:10;:::i;:::-;:14;;2055:1;2042:14;:::i;:::-;2030:26;;2025:128;2062:1;2058;:5;2025:128;;;-1:-1:-1;;;2105:5:21;2113:3;2105:11;2096:21;;;;;;;:::i;:::-;;;;2084:6;2091:1;2084:9;;;;;;;;:::i;:::-;;;;:33;-1:-1:-1;;;;;2084:33:21;;;;;;;;-1:-1:-1;2141:1:21;2131:11;;;;;2065:3;;;:::i;:::-;;;2025:128;;;-1:-1:-1;2170:10:21;;2162:55;;;;-1:-1:-1;;;2162:55:21;;;;;;;:::i;2732:202:0:-;2817:4;-1:-1:-1;;;;;;2840:47:0;;-1:-1:-1;;;2840:47:0;;:87;;-1:-1:-1;;;;;;;;;;937:40:25;;;2891:36:0;829:155:25;3695:262:23;3748:7;3779:4;-1:-1:-1;;;;;3788:11:23;3771:28;;:63;;;;;3820:14;3803:13;:31;3771:63;3767:184;;;-1:-1:-1;3857:22:23;;3695:262::o;3767:184::-;3917:23;:21;:23::i;:::-;3910:30;;3695:262;:::o;3661:227:22:-;3739:7;3759:17;3778:18;3800:27;3811:4;3817:9;3800:10;:27::i;:::-;3758:69;;;;3837:18;3849:5;3837:11;:18::i;:::-;-1:-1:-1;3872:9:22;3661:227;-1:-1:-1;;;3661:227:22:o;3122:96:28:-;3180:7;3206:5;3210:1;3206;:5;:::i;1355:203:8:-;1455:96;1475:5;1505:27;;;1534:4;1540:2;1544:5;1482:68;;;;;;;;;;:::i;:::-;;;;-1:-1:-1;;1482:68:8;;;;;;;;;;;;;;-1:-1:-1;;;;;1482:68:8;-1:-1:-1;;;;;;1482:68:8;;;;;;;;;;1455:19;:96::i;2640:572:56:-;-1:-1:-1;;;;;2839:18:56;;2835:183;;2873:40;2905:7;4018:10;:17;;3991:24;;;;:15;:24;;;;;:44;;;4045:24;;;;;;;;;;;;3915:161;2873:40;2835:183;;;2942:2;-1:-1:-1;;;;;2934:10:56;:4;-1:-1:-1;;;;;2934:10:56;;2930:88;;2960:47;2993:4;2999:7;2960:32;:47::i;:::-;-1:-1:-1;;;;;3031:16:56;;3027:179;;3063:45;3100:7;3063:36;:45::i;3027:179::-;3135:4;-1:-1:-1;;;;;3129:10:56;:2;-1:-1:-1;;;;;3129:10:56;;3125:81;;3155:40;3183:2;3187:7;3155:27;:40::i;16284:746:36:-;16443:18;;16398:16;;-1:-1:-1;;;;;16430:31:36;;;16443:18;;16430:31;;:64;;-1:-1:-1;16476:18:36;;-1:-1:-1;;;;;16465:29:36;;;16476:18;;16465:29;16430:64;16426:598;;;16534:16;;;16548:1;16534:16;;;;;;;;16510:21;;16534:16;;;;;;;;;;-1:-1:-1;;16587:18:36;;16510:40;;-1:-1:-1;;;;;;16574:31:36;;;16587:18;;16574:31;:96;;16661:9;16574:96;;;16624:18;;-1:-1:-1;;;;;16624:18:36;16574:96;16564:4;16569:1;16564:7;;;;;;;;:::i;:::-;-1:-1:-1;;;;;16564:106:36;;;:7;;;;;;;;;:106;16705:18;;16694:29;;;16705:18;;16694:29;:92;;16779:7;16694:92;;;16742:18;;-1:-1:-1;;;;;16742:18:36;16694:92;16684:4;16689:1;16684:7;;;;;;;;:::i;:::-;-1:-1:-1;;;;;16684:102:36;;;:7;;;;;;;;;;;:102;16807:4;-1:-1:-1;16800:11:36;;16426:598;16866:16;;;16880:1;16866:16;;;;;;;;;16842:21;;16866:16;;;;;;;;;;-1:-1:-1;16866:16:36;16842:40;;16906:9;16896:4;16901:1;16896:7;;;;;;;;:::i;:::-;-1:-1:-1;;;;;16896:19:36;;;:7;;;;;;;;;:19;16939:18;;16929:7;;16939:18;;;16929:4;;16939:18;;16929:7;;;;;;:::i;:::-;;;;;;:28;-1:-1:-1;;;;;16929:28:36;;;-1:-1:-1;;;;;16929:28:36;;;;;16981:7;16971:4;16976:1;16971:7;;;;;;;;:::i;2536:245:19:-;2597:7;2669:4;2633:40;;2696:2;2687:11;;2683:69;;;2721:20;;-1:-1:-1;;;2721:20:19;;;;;;;;;;;3963:180:23;4018:7;1929:95;4077:11;4090:14;4106:13;4129:4;4054:81;;;;;;;;;;;;:::i;:::-;;;;;;;;;;;;;4044:92;;;;;;4037:99;;3963:180;:::o;2145:730:22:-;2226:7;2235:12;2263:9;:16;2283:2;2263:22;2259:610;;;2599:4;2584:20;;2578:27;2648:4;2633:20;;2627:27;2705:4;2690:20;;2684:27;2301:9;2676:36;2746:25;2757:4;2676:36;2578:27;2627;2746:10;:25::i;:::-;2739:32;;;;;;;;;2259:610;-1:-1:-1;2818:1:22;;-1:-1:-1;2822:35:22;2259:610;2145:730;;;;;:::o;570:511::-;647:20;638:5;:29;;;;;;;;:::i;:::-;;634:441;;;570:511;:::o;634:441::-;743:29;734:5;:38;;;;;;;;:::i;:::-;;730:345;;;788:34;;-1:-1:-1;;;788:34:22;;;;;;;:::i;730:345::-;852:35;843:5;:44;;;;;;;;:::i;:::-;;839:236;;;903:41;;-1:-1:-1;;;903:41:22;;;;;;;:::i;839:236::-;974:30;965:5;:39;;;;;;;;:::i;:::-;;961:114;;;1020:44;;-1:-1:-1;;;1020:44:22;;;;;;;:::i;5196:642:8:-;5615:23;5641:69;5669:4;5641:69;;;;;;;;;;;;;;;;;5649:5;-1:-1:-1;;;;;5641:27:8;;;:69;;;;;:::i;:::-;5615:95;;5728:10;:17;5749:1;5728:22;:56;;;;5765:10;5754:30;;;;;;;;;;;;:::i;:::-;5720:111;;;;-1:-1:-1;;;5720:111:8;;;;;;;:::i;4693:989:56:-;4977:22;5024:1;5002:19;5016:4;5002:13;:19::i;:::-;:23;;;;:::i;:::-;5035:18;5056:26;;;:17;:26;;;;;;4977:48;;-1:-1:-1;5186:28:56;;;5182:323;;-1:-1:-1;;;;;5252:18:56;;5230:19;5252:18;;;:12;:18;;;;;;;;:34;;;;;;;;;5301:30;;;;;;:44;;;5417:30;;:17;:30;;;;;:43;;;5182:323;-1:-1:-1;5598:26:56;;;;:17;:26;;;;;;;;5591:33;;;-1:-1:-1;;;;;5641:18:56;;;;;:12;:18;;;;;:34;;;;;;;5634:41;4693:989::o;5970:1061::-;6244:10;:17;6219:22;;6244:21;;6264:1;;6244:21;:::i;:::-;6275:18;6296:24;;;:15;:24;;;;;;6664:10;:26;;6219:46;;-1:-1:-1;6296:24:56;;6219:46;;6664:26;;;;;;:::i;:::-;;;;;;;;;6642:48;;6726:11;6701:10;6712;6701:22;;;;;;;;:::i;:::-;;;;;;;;;;;;:36;;;;6805:28;;;:15;:28;;;;;;;:41;;;6974:24;;;;;6967:31;7008:10;:16;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;6041:990;;;5970:1061;:::o;3506:214::-;3590:14;3607:17;3621:2;3607:13;:17::i;:::-;-1:-1:-1;;;;;3634:16:56;;;;;;;:12;:16;;;;;;;;:24;;;;;;;;:34;;;3678:26;;;:17;:26;;;;;;:35;;;;-1:-1:-1;3506:214:56:o;5009:1456:22:-;5097:7;;-1:-1:-1;;;;;6008:79:22;;6004:161;;;-1:-1:-1;6119:1:22;;-1:-1:-1;6123:30:22;6103:51;;6004:161;6259:14;6276:24;6286:4;6292:1;6295;6298;6276:24;;;;;;;;;;;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;6276:24:22;;-1:-1:-1;;6276:24:22;;;-1:-1:-1;;;;;;;6314:20:22;;6310:101;;6366:1;6370:29;6350:50;;;;;;;6310:101;6429:6;-1:-1:-1;6437:20:22;;-1:-1:-1;5009:1456:22;;;;;;;;:::o;4108:223:16:-;4241:12;4272:52;4294:6;4302:4;4308:1;4311:12;4241;5446;5460:23;5487:6;-1:-1:-1;;;;;5487:11:16;5506:5;5513:4;5487:31;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;5445:73;;;;5535:69;5562:6;5570:7;5579:10;5591:12;5535:26;:69::i;:::-;5528:76;5165:446;-1:-1:-1;;;;;;;5165:446:16:o;7671:628::-;7851:12;7879:7;7875:418;;;7906:17;;7902:286;;-1:-1:-1;;;;;1702:19:16;;;8113:60;;;;-1:-1:-1;;;8113:60:16;;;;;;;:::i;:::-;-1:-1:-1;8208:10:16;8201:17;;7875:418;8249:33;8257:10;8269:12;8980:17;;:21;8976:379;;9208:10;9202:17;9264:15;9251:10;9247:2;9243:19;9236:44;8976:379;9331:12;9324:20;;-1:-1:-1;;;9324:20:16;;;;;;;;:::i;-1:-1:-1:-;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;;;:::o;:::-;;;;;;;;;;;;;;;417:122:57;508:5;490:24;483:5;480:35;470:63;;529:1;526;519:12;545:139;616:20;;645:33;616:20;645:33;:::i;690:329::-;749:6;798:2;786:9;777:7;773:23;769:32;766:119;;;804:79;348:6268:45;;;804:79:57;924:1;949:53;994:7;974:9;949:53;:::i;1180:120::-;-1:-1:-1;;;;;;1090:78:57;;1252:23;1025:149;1306:137;1376:20;;1405:32;1376:20;1405:32;:::i;1449:327::-;1507:6;1556:2;1544:9;1535:7;1531:23;1527:32;1524:119;;;1562:79;348:6268:45;;;1562:79:57;1682:1;1707:52;1751:7;1731:9;1707:52;:::i;1878:109::-;1852:13;;1845:21;1959;1954:3;1947:34;1878:109;;:::o;1993:210::-;2118:2;2103:18;;2131:65;2107:9;2169:6;2131:65;:::i;2209:126::-;-1:-1:-1;;;;;2275:54:57;;2209:126::o;2341:96::-;2378:7;2407:24;2425:5;2407:24;:::i;2443:118::-;2530:24;2548:5;2530:24;:::i;2567:222::-;2698:2;2683:18;;2711:71;2687:9;2755:6;2711:71;:::i;3075:307::-;3143:1;3153:113;3167:6;3164:1;3161:13;3153:113;;;3243:11;;;3237:18;3224:11;;;3217:39;3189:2;3182:10;3153:113;;;3284:6;3281:1;3278:13;3275:101;;;-1:-1:-1;;3364:1:57;3346:16;;3339:27;3075:307::o;3388:102::-;3480:2;3460:14;-1:-1:-1;;3456:28:57;;3388:102::o;3496:364::-;3584:3;3612:39;3645:5;2875:12;;2795:99;3612:39;3006:19;;;3058:4;3049:14;;3660:78;;3747:52;3792:6;3787:3;3780:4;3773:5;3769:16;3747:52;:::i;:::-;3824:29;3846:6;3824:29;:::i;:::-;3815:39;;;;3496:364;-1:-1:-1;;;3496:364:57:o;3866:313::-;4017:2;4030:47;;;4002:18;;4094:78;4002:18;4158:6;4094:78;:::i;4747:179::-;4816:10;4837:46;4879:3;4871:6;4837:46;:::i;:::-;-1:-1:-1;;4915:4:57;4906:14;;4747:179::o;5081:732::-;5200:3;5229:54;5277:5;2875:12;;2795:99;5229:54;3006:19;;;3058:4;3049:14;;;;4606;;;5519:1;5504:284;5529:6;5526:1;5523:13;5504:284;;;5605:6;5599:13;5632:63;5691:3;5676:13;5632:63;:::i;:::-;5625:70;-1:-1:-1;5034:4:57;5025:14;;5708:70;-1:-1:-1;;5551:1:57;5544:9;5504:284;;;-1:-1:-1;5804:3:57;;5081:732;-1:-1:-1;;;;;5081:732:57:o;5819:373::-;6000:2;6013:47;;;5985:18;;6077:108;5985:18;6171:6;6077:108;:::i;6198:118::-;6303:5;6285:24;3310:202:20;6322:222:57;6453:2;6438:18;;6466:71;6442:9;6510:6;6466:71;:::i;6550:122::-;6623:24;6641:5;6623:24;:::i;6678:139::-;6749:20;;6778:33;6749:20;6778:33;:::i;7205:552::-;7262:8;7272:6;7322:3;7315:4;7307:6;7303:17;7299:27;7289:122;;7330:79;348:6268:45;;;7330:79:57;-1:-1:-1;7430:20:57;;-1:-1:-1;;;;;7462:30:57;;7459:117;;;7495:79;348:6268:45;;;7495:79:57;7609:4;7601:6;7597:17;7585:29;;7663:3;7655:4;7647:6;7643:17;7633:8;7629:32;7626:41;7623:128;;;7670:79;348:6268:45;;;7763:1109:57;7869:6;7877;7885;7893;7901;7909;7958:3;7946:9;7937:7;7933:23;7929:33;7926:120;;;7965:79;348:6268:45;;;7965:79:57;8085:1;8110:53;8155:7;8135:9;8110:53;:::i;:::-;8100:63;;8056:117;8212:2;8238:53;8283:7;8274:6;8263:9;8259:22;8238:53;:::i;:::-;8228:63;;8183:118;8340:2;8366:53;8411:7;8402:6;8391:9;8387:22;8366:53;:::i;:::-;8356:63;;8311:118;8468:2;8494:53;8539:7;8530:6;8519:9;8515:22;8494:53;:::i;:::-;8484:63;;8439:118;8624:3;8613:9;8609:19;8596:33;-1:-1:-1;;;;;8648:6:57;8645:30;8642:117;;;8678:79;348:6268:45;;;8678:79:57;8791:64;8847:7;8838:6;8827:9;8823:22;8791:64;:::i;:::-;8773:82;;;;8567:298;7763:1109;;;;;;;;:::o;8878:474::-;8946:6;8954;9003:2;8991:9;8982:7;8978:23;8974:32;8971:119;;;9009:79;348:6268:45;;;9009:79:57;9129:1;9154:53;9199:7;9179:9;9154:53;:::i;:::-;9144:63;;9100:117;9256:2;9282:53;9327:7;9318:6;9307:9;9303:22;9282:53;:::i;:::-;9272:63;;9227:118;8878:474;;;;;:::o;9358:329::-;9417:6;9466:2;9454:9;9445:7;9441:23;9437:32;9434:119;;;9472:79;348:6268:45;;;9472:79:57;9592:1;9617:53;9662:7;9642:9;9617:53;:::i;10736:474::-;10804:6;10812;10861:2;10849:9;10840:7;10836:23;10832:32;10829:119;;;10867:79;348:6268:45;;;10867:79:57;10987:1;11012:53;11057:7;11037:9;11012:53;:::i;:::-;11002:63;;10958:117;11114:2;11140:53;11185:7;11176:6;11165:9;11161:22;11140:53;:::i;11282:142::-;11332:9;11365:53;11383:34;11392:24;11410:5;11392:24;:::i;11383:34::-;11365:53;:::i;11430:126::-;11480:9;11513:37;11544:5;11513:37;:::i;11562:154::-;11640:9;11673:37;11704:5;11673:37;:::i;11722:187::-;11837:65;11896:5;11837:65;:::i;11915:278::-;12074:2;12059:18;;12087:99;12063:9;12159:6;12087:99;:::i;12199:1109::-;12305:6;12313;12321;12329;12337;12345;12394:3;12382:9;12373:7;12369:23;12365:33;12362:120;;;12401:79;348:6268:45;;;12401:79:57;12521:1;12546:53;12591:7;12571:9;12546:53;:::i;:::-;12536:63;;12492:117;12648:2;12674:53;12719:7;12710:6;12699:9;12695:22;12674:53;:::i;13469:115::-;-1:-1:-1;;;;;;13379:78:57;;13554:23;13314:149;14152:179;14221:10;14242:46;14284:3;14276:6;14242:46;:::i;14486:732::-;14605:3;14634:54;14682:5;2875:12;;2795:99;14634:54;3006:19;;;3058:4;3049:14;;;;4606;;;14924:1;14909:284;14934:6;14931:1;14928:13;14909:284;;;15010:6;15004:13;15037:63;15096:3;15081:13;15037:63;:::i;:::-;15030:70;-1:-1:-1;5034:4:57;5025:14;;15113:70;-1:-1:-1;;14956:1:57;14949:9;14909:284;;15224:1215;15611:3;15596:19;;15625:69;15600:9;15667:6;15625:69;:::i;:::-;15741:9;15735:4;15731:20;15726:2;15715:9;15711:18;15704:48;15769:78;15842:4;15833:6;15769:78;:::i;:::-;15761:86;;15894:9;15888:4;15884:20;15879:2;15868:9;15864:18;15857:48;15922:78;15995:4;15986:6;15922:78;:::i;:::-;15914:86;;16010:72;16078:2;16067:9;16063:18;16054:6;16010:72;:::i;:::-;16092:73;16160:3;16149:9;16145:19;16136:6;16092:73;:::i;:::-;16175;16243:3;16232:9;16228:19;16219:6;16175:73;:::i;:::-;16296:9;16290:4;16286:20;16280:3;16269:9;16265:19;16258:49;16324:108;16427:4;16418:6;16324:108;:::i;16445:332::-;16604:2;16589:18;;16617:71;16593:9;16661:6;16617:71;:::i;:::-;16698:72;16766:2;16755:9;16751:18;16742:6;16698:72;:::i;16783:180::-;-1:-1:-1;;;16828:1:57;16821:88;16928:4;16925:1;16918:15;16952:4;16949:1;16942:15;16969:320;17050:1;17040:12;;17097:1;17087:12;;;17108:81;;17174:4;17166:6;17162:17;17152:27;;17108:81;17236:2;17228:6;17225:14;17205:18;17202:38;17199:84;;;17255:18;;:::i;:::-;17020:269;16969:320;;;:::o;17295:143::-;17377:13;;17399:33;17377:13;17399:33;:::i;17444:351::-;17514:6;17563:2;17551:9;17542:7;17538:23;17534:32;17531:119;;;17569:79;348:6268:45;;;17569:79:57;17689:1;17714:64;17770:7;17750:9;17714:64;:::i;17801:332::-;17960:2;17945:18;;17973:71;17949:9;18017:6;17973:71;:::i;18139:775::-;18410:3;18395:19;;18424:71;18399:9;18468:6;18424:71;:::i;:::-;18505:72;18573:2;18562:9;18558:18;18549:6;18505:72;:::i;:::-;18587;18655:2;18644:9;18640:18;18631:6;18587:72;:::i;:::-;18669;18737:2;18726:9;18722:18;18713:6;18669:72;:::i;:::-;18751:73;18819:3;18808:9;18804:19;18795:6;18751:73;:::i;:::-;18834;18902:3;18891:9;18887:19;18878:6;18834:73;:::i;19153:366::-;19380:2;3006:19;;19295:3;3058:4;3049:14;;19060:34;19037:58;;-1:-1:-1;;;19124:2:57;19112:15;;19105:35;19309:74;-1:-1:-1;19392:93:57;-1:-1:-1;19510:2:57;19501:12;;19153:366::o;19525:419::-;19729:2;19742:47;;;19714:18;;19806:131;19714:18;19806:131;:::i;20190:366::-;20417:2;3006:19;;20332:3;3058:4;3049:14;;20090:34;20067:58;;-1:-1:-1;;;20154:2:57;20142:15;;20135:42;20346:74;-1:-1:-1;20429:93:57;19950:234;20562:419;20766:2;20779:47;;;20751:18;;20843:131;20751:18;20843:131;:::i;21173:366::-;21400:2;3006:19;;21315:3;3058:4;3049:14;;21127:32;21104:56;;21329:74;-1:-1:-1;21412:93:57;-1:-1:-1;21530:2:57;21521:12;;21173:366::o;21545:419::-;21749:2;21762:47;;;21734:18;;21826:131;21734:18;21826:131;:::i;22204:366::-;22431:2;3006:19;;22346:3;3058:4;3049:14;;22110:34;22087:58;;-1:-1:-1;;;22174:2:57;22162:15;;22155:36;22360:74;-1:-1:-1;22443:93:57;21970:228;22576:419;22780:2;22793:47;;;22765:18;;22857:131;22765:18;22857:131;:::i;23001:180::-;-1:-1:-1;;;23046:1:57;23039:88;23146:4;23143:1;23136:15;23170:4;23167:1;23160:15;23364:366;23591:2;3006:19;;23506:3;3058:4;3049:14;;-1:-1:-1;;;23304:47:57;;23520:74;-1:-1:-1;23603:93:57;23187:171;23736:419;23940:2;23953:47;;;23925:18;;24017:131;23925:18;24017:131;:::i;24392:366::-;24619:2;3006:19;;24534:3;3058:4;3049:14;;24301:34;24278:58;;-1:-1:-1;;;24365:2:57;24353:15;;24346:33;24548:74;-1:-1:-1;24631:93:57;24161:225;24764:419;24968:2;24981:47;;;24953:18;;25045:131;24953:18;25045:131;:::i;25189:775::-;25460:3;25445:19;;25474:71;25449:9;25518:6;25474:71;:::i;:::-;25555:72;25623:2;25612:9;25608:18;25599:6;25555:72;:::i;25970:180::-;-1:-1:-1;;;26015:1:57;26008:88;26115:4;26112:1;26105:15;26139:4;26136:1;26129:15;26156:180;-1:-1:-1;;;26201:1:57;26194:88;26301:4;26298:1;26291:15;26325:4;26322:1;26315:15;26342:191;26382:4;26475:1;26472;26469:8;26466:34;;;26480:18;;:::i;:::-;-1:-1:-1;26518:9:57;;26342:191::o;26539:180::-;-1:-1:-1;;;26584:1:57;26577:88;26684:4;26681:1;26674:15;26708:4;26705:1;26698:15;26725:233;26764:3;-1:-1:-1;;26826:5:57;26823:77;26820:103;;;26903:18;;:::i;:::-;-1:-1:-1;26950:1:57;26939:13;;26725:233::o;26964:143::-;27046:13;;27068:33;27046:13;27068:33;:::i;27113:351::-;27183:6;27232:2;27220:9;27211:7;27207:23;27203:32;27200:119;;;27238:79;348:6268:45;;;27238:79:57;27358:1;27383:64;27439:7;27419:9;27383:64;:::i;27657:366::-;27884:2;3006:19;;27799:3;3058:4;3049:14;;27610:33;27587:57;;27813:74;-1:-1:-1;27896:93:57;27470:181;28029:419;28233:2;28246:47;;;28218:18;;28310:131;28218:18;28310:131;:::i;28454:553::-;28669:3;28654:19;;28683:71;28658:9;28727:6;28683:71;:::i;:::-;28764:72;28832:2;28821:9;28817:18;28808:6;28764:72;:::i;:::-;28846;28914:2;28903:9;28899:18;28890:6;28846:72;:::i;:::-;28928;28996:2;28985:9;28981:18;28972:6;28928:72;:::i;:::-;28454:553;;;;;;;:::o;29013:::-;29228:3;29213:19;;29242:71;29217:9;29286:6;29242:71;:::i;:::-;29323:72;29391:2;29380:9;29376:18;29367:6;29323:72;:::i;29798:154::-;29841:11;29877:29;29901:3;29895:10;3486::20;3310:202;30071:594:57;30155:5;30186:38;30218:5;2875:12;;2795:99;30186:38;4615:4;4606:14;;30335:35;4606:14;30335:35;:::i;:::-;30326:44;;30394:2;30386:6;30383:14;30380:278;;;30465:169;-1:-1:-1;;30520:6:57;30516:2;30512:15;30509:1;30505:23;30042:16;;29958:107;30465:169;30442:5;30421:227;30412:236;;30380:278;30161:504;;30071:594;;;:::o;31412:377::-;31518:3;31546:39;31579:5;2875:12;;2795:99;31546:39;31699:52;31744:6;31739:3;31732:4;31725:5;31721:16;31699:52;:::i;:::-;31767:16;;;;;31412:377;-1:-1:-1;;31412:377:57:o;32376:967::-;-1:-1:-1;;;30942:49:57;;31397:2;31388:12;32758:3;32945:95;31388:12;33027:6;32945:95;:::i;:::-;-1:-1:-1;;;31912:43:57;;32361:2;32352:12;;-1:-1:-1;33222:95:57;32352:12;33304:6;33222:95;:::i;33349:348::-;33389:7;33634:1;-1:-1:-1;;33562:74:57;33559:1;33556:81;33551:1;33544:9;33537:17;33533:105;33530:131;;;33641:18;;:::i;:::-;-1:-1:-1;33682:9:57;;33349:348::o;33703:180::-;-1:-1:-1;;;33748:1:57;33741:88;33848:4;33845:1;33838:15;33872:4;33869:1;33862:15;33889:185;33929:1;34019;34009:35;;34024:18;;:::i;:::-;-1:-1:-1;34059:9:57;;33889:185::o;34757:379::-;34941:3;35106;34963:147;3310:202:20;35327:366:57;35554:2;3006:19;;35469:3;3058:4;3049:14;;35282:31;35259:55;;35483:74;-1:-1:-1;35566:93:57;35142:179;35699:419;35903:2;35916:47;;;35888:18;;35980:131;35888:18;35980:131;:::i;36305:366::-;36532:2;3006:19;;36447:3;3058:4;3049:14;;-1:-1:-1;;;36241:51:57;;36461:74;-1:-1:-1;36544:93:57;36124:175;36677:419;36881:2;36894:47;;;36866:18;;36958:131;36866:18;36958:131;:::i;37102:305::-;37142:3;37277:74;;37271:81;;37268:107;;;37355:18;;:::i;:::-;-1:-1:-1;37392:9:57;;37102:305::o;37413:483::-;37622:2;37607:18;;37635:71;37611:9;37679:6;37635:71;:::i;:::-;37753:9;37747:4;37743:20;37738:2;37727:9;37723:18;37716:48;37781:108;37884:4;37875:6;37781:108;:::i;37902:281::-;37985:27;38007:4;37985:27;:::i;:::-;37977:6;37973:40;38115:6;38103:10;38100:22;-1:-1:-1;;;;;38067:10:57;38064:34;38061:62;38058:88;;;38126:18;;:::i;:::-;38162:2;38155:22;-1:-1:-1;;37902:281:57:o;38189:129::-;38223:6;38250:20;73:2;67:9;;7:75;38250:20;38240:30;;38279:33;38307:4;38299:6;38279:33;:::i;38324:311::-;38401:4;-1:-1:-1;;;;;38483:6:57;38480:30;38477:56;;;38513:18;;:::i;:::-;-1:-1:-1;38563:4:57;38551:17;;;38613:15;;38324:311::o;38658:732::-;38765:5;38790:81;38806:64;38863:6;38806:64;:::i;:::-;38790:81;:::i;:::-;38906:21;;;38781:90;-1:-1:-1;38954:4:57;38943:16;;;;38995:17;;38983:30;;39025:15;;;39022:122;;;39055:79;348:6268:45;;;39055:79:57;39170:6;39153:231;39187:6;39182:3;39179:15;39153:231;;;39262:3;39291:48;39335:3;39323:10;39291:48;:::i;:::-;39279:61;;-1:-1:-1;39369:4:57;39360:14;;;;39204;39153:231;;;39157:21;38771:619;;38658:732;;;;;:::o;39413:385::-;39495:5;39544:3;39537:4;39529:6;39525:17;39521:27;39511:122;;39552:79;348:6268:45;;;39552:79:57;39662:6;39656:13;39687:105;39788:3;39780:6;39773:4;39765:6;39761:17;39687:105;:::i;39804:554::-;39899:6;39948:2;39936:9;39927:7;39923:23;39919:32;39916:119;;;39954:79;348:6268:45;;;39954:79:57;40074:24;;-1:-1:-1;;;;;40114:30:57;;40111:117;;;40147:79;348:6268:45;;;40147:79:57;40252:89;40333:7;40324:6;40313:9;40309:22;40252:89;:::i;40364:171::-;40403:3;40462:15;40459:41;;40480:18;;:::i;:::-;-1:-1:-1;;;40516:13:57;;40364:171::o;40729:366::-;40956:2;3006:19;;;40681:34;3049:14;;40658:58;;;40871:3;40968:93;40541:182;41101:419;41305:2;41318:47;;;41290:18;;41382:131;41290:18;41382:131;:::i;41526:442::-;41713:2;41698:18;;41726:71;41702:9;41770:6;41726:71;:::i;:::-;41807:72;41875:2;41864:9;41860:18;41851:6;41807:72;:::i;:::-;41889;41957:2;41946:9;41942:18;41933:6;41889:72;:::i;41974:664::-;42217:3;42202:19;;42231:71;42206:9;42275:6;42231:71;:::i;:::-;42312:72;42380:2;42369:9;42365:18;42356:6;42312:72;:::i;:::-;42394;42462:2;42451:9;42447:18;42438:6;42394:72;:::i;:::-;42476;42544:2;42533:9;42529:18;42520:6;42476:72;:::i;:::-;42558:73;42626:3;42615:9;42611:19;42602:6;42558:73;:::i;42644:180::-;-1:-1:-1;;;42689:1:57;42682:88;42789:4;42786:1;42779:15;42813:4;42810:1;42803:15;43010:366;43237:2;3006:19;;43152:3;3058:4;3049:14;;-1:-1:-1;;;42947:50:57;;43166:74;-1:-1:-1;43249:93:57;42830:174;43382:419;43586:2;43599:47;;;43571:18;;43663:131;43571:18;43663:131;:::i;43994:366::-;44221:2;3006:19;;44136:3;3058:4;3049:14;;43947:33;43924:57;;44150:74;-1:-1:-1;44233:93:57;43807:181;44366:419;44570:2;44583:47;;;44555:18;;44647:131;44555:18;44647:131;:::i;45018:366::-;45245:2;3006:19;;45160:3;3058:4;3049:14;;44931:34;44908:58;;-1:-1:-1;;;44995:2:57;44983:15;;44976:29;45174:74;-1:-1:-1;45257:93:57;44791:221;45390:419;45594:2;45607:47;;;45579:18;;45671:131;45579:18;45671:131;:::i;45815:116::-;1852:13;;1845:21;45885;1782:90;45937:137;46016:13;;46038:30;46016:13;46038:30;:::i;46080:345::-;46147:6;46196:2;46184:9;46175:7;46171:23;46167:32;46164:119;;;46202:79;348:6268:45;;;46202:79:57;46322:1;46347:61;46400:7;46380:9;46347:61;:::i;46666:366::-;46893:2;3006:19;;46808:3;3058:4;3049:14;;46571:34;46548:58;;-1:-1:-1;;;46635:2:57;46623:15;;46616:37;46822:74;-1:-1:-1;46905:93:57;46431:229;47038:419;47242:2;47255:47;;;47227:18;;47319:131;47227:18;47319:131;:::i;47555:112::-;47538:4;47527:16;;47638:22;47463:86;47673:545;47884:3;47869:19;;47898:71;47873:9;47942:6;47898:71;:::i;:::-;47979:68;48043:2;48032:9;48028:18;48019:6;47979:68;:::i;:::-;48057:72;48125:2;48114:9;48110:18;48101:6;48057:72;:::i;49631:271::-;49761:3;49783:93;49872:3;49863:6;49783:93;:::i;50093:366::-;50320:2;3006:19;;50235:3;3058:4;3049:14;;50048:31;50025:55;;50249:74;-1:-1:-1;50332:93:57;49908:179;50465:419;50669:2;50682:47;;;50654:18;;50746:131;50654:18;50746:131;:::i
Swarm Source
ipfs://bedfa5e1580b54e54fffd7068983e6a127913ae2e09ea63caa03ef60e5b9d86b
Loading...
Loading
Loading...
Loading
Loading...
Loading
Net Worth in USD
$0.00
Net Worth in ETH
Multichain Portfolio | 33 Chains
| Chain | Token | Portfolio % | Price | Amount | Value |
|---|
Loading...
Loading
Loading...
Loading
Loading...
Loading
[ Download: CSV Export ]
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.