Address Details
contract
0xaf02af83c8a81f7851E9ef2C8298ADAA1D1D46e4
- Contract Name
- CarbonPathAdmin
- Creator
- 0xfcd838–35b66b at 0x7e312a–245b06
- Balance
- 0 CELO ( )
- Locked CELO Balance
- 0.00 CELO
- Voting CELO Balance
- 0.00 CELO
- Pending Unlocked Gold
- 0.00 CELO
- Tokens
-
Fetching tokens...
- Transactions
- 29 Transactions
- Transfers
- 63 Transfers
- Gas Used
- 3,513,871
- Last Balance Update
- 13587099
Transactions
Token Transfers
Internal Transactions
Coin Balance History
Logs
Code
Read Contract
Write Contract
This contract has been verified via Sourcify.
View contract in Sourcify repository
- Contract name:
- CarbonPathAdmin
- Optimization enabled
- true
- Compiler version
- v0.8.17+commit.8df45f5f
- Optimization runs
- 200
- EVM Version
- london
- Verified at
- 2022-09-30T12:04:52.993872Z
contracts/CarbonPathAdmin.sol
// contracts/CarbonpathAdmin.sol // SPDX-License-Identifier: Apache-2.0 pragma solidity 0.8.17; import '@openzeppelin/contracts/access/Ownable.sol'; import '@openzeppelin/contracts/access/AccessControl.sol'; import '@openzeppelin/contracts/utils/math/SafeMath.sol'; import '@openzeppelin/contracts/token/ERC20/IERC20.sol'; import '@openzeppelin/contracts/security/ReentrancyGuard.sol'; import './CarbonPathNFT.sol'; import './CarbonPathToken.sol'; /** * @title Carbon Path Admin */ contract CarbonPathAdmin is Ownable, AccessControl, ReentrancyGuard { using SafeMath for uint256; CarbonPathNFT public carbonPathNFT; CarbonPathToken public carbonPathToken; IERC20 public stableToken; address public cpFeeAddress; address public bufferPoolAddress; address public nonProfitAddress; address public sellerAddress; uint256 public constant BASE_PERCENTAGE = 1000; // 100%, to support 1 decimal place uint256 public constant NON_PROFIT_PERCENTAGE = 50; // 5% uint256 public constant EXCHANGE_RATE = 30; bytes32 private constant MINTER_ROLE = keccak256('MINTER_ROLE'); constructor( address _nftContractAddress, address _tokenContractAddress, address _stableTokenAddress ) { carbonPathNFT = CarbonPathNFT(_nftContractAddress); carbonPathToken = CarbonPathToken(_tokenContractAddress); stableToken = IERC20(_stableTokenAddress); _setupRole(DEFAULT_ADMIN_ROLE, _msgSender()); _setupRole(MINTER_ROLE, _msgSender()); } function _calculateCPFee(uint256 amount, uint256 cpFeePercentage) private pure returns (uint256) { return (amount * cpFeePercentage) / BASE_PERCENTAGE; } function _calculateNonProfitFee(uint256 amount) private pure returns (uint256) { return (amount * NON_PROFIT_PERCENTAGE) / BASE_PERCENTAGE; } function _calculateStableTokenAmount(uint256 cpAmount) private pure returns (uint256) { return cpAmount * EXCHANGE_RATE; } /** * @dev Require that the call came from the seller address. */ modifier onlySeller() { require(_msgSender() == sellerAddress, 'CarbonPathAdmin: caller is not the seller'); _; } /** * @dev Grant Minter Role to the address * * Requirements: * - the caller must have the `DEFAULT_ADMIN_ROLE`. */ function grantMinter(address account) public { require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()), 'CarbonPathAdmin: must be an admin'); _grantRole(MINTER_ROLE, account); } /** * @dev Revoke Minter Role to the address * * Requirements: * - the caller must have the `DEFAULT_ADMIN_ROLE`. */ function revokeMinter(address account) public { require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()), 'CarbonPathAdmin: must be an admin'); _revokeRole(MINTER_ROLE, account); } /** * @dev Sets the receiver of CP Fee * * Requirements: * - the caller must have the `DEFAULT_ADMIN_ROLE`. */ function setCpFeeAddress(address _address) public { require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()), 'CarbonPathAdmin: must have admin role'); cpFeeAddress = _address; } /** * @dev Sets the receiver of Non Profit Percentage * * Requirements: * - the caller must have the `DEFAULT_ADMIN_ROLE`. */ function setNonProfitAddress(address _address) public { require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()), 'CarbonPathAdmin: must have admin role'); nonProfitAddress = _address; } /** * @dev Sets the receiver of Buffer Pool Tokens * * Requirements: * - the caller must have the `DEFAULT_ADMIN_ROLE`. */ function setBufferPoolAddress(address _address) public { require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()), 'CarbonPathAdmin: must have admin role'); bufferPoolAddress = _address; } /** * @dev Sets the seller address * * Requirements: * - the caller must have the `DEFAULT_ADMIN_ROLE`. */ function setSellerAddress(address _address) public { require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()), 'CarbonPathAdmin: must have admin role'); sellerAddress = _address; } /** * @dev Creates a new token for `to`. * Additionally sets URI for the token. * * Requirements: * - the caller must have the `MINTER_ROLE`. */ function mint( address to, uint256 advanceAmount, uint256 cpFeePercentage, uint256 bufferAmount, address operatorAddress, string memory tokenUri, string memory metadata ) public virtual nonReentrant { require(hasRole(MINTER_ROLE, _msgSender()), 'CarbonPathAdmin: must have minter role to mint'); // TODO: Add a check where well polygon is checked first before minting the NFT carbonPathNFT.mint(to, advanceAmount, bufferAmount, tokenUri, metadata); uint256 cpFee = _calculateCPFee(advanceAmount, cpFeePercentage); uint256 nonProfitFee = _calculateNonProfitFee(bufferAmount); //Mint Carbon Path Tokens carbonPathToken.mint(address(this), advanceAmount + bufferAmount); // Transfer advance amount carbonPathToken.transfer(cpFeeAddress, cpFee); carbonPathToken.transfer(operatorAddress, advanceAmount - cpFee); // Tranfer buffer amount carbonPathToken.transfer(nonProfitAddress, nonProfitFee); carbonPathToken.transfer(bufferPoolAddress, bufferAmount - nonProfitFee); } /** * @dev Retire the carbon token for a well * */ function retire(uint256 tokenId, uint256 amount) public virtual nonReentrant { require(amount > 0, 'CarbonPathAdmin: retired amount must be at least 1'); require( carbonPathToken.balanceOf(_msgSender()) >= amount, 'CarbonPathAdmin: not enough balance' ); // Update number of retired EAVS carbonPathNFT.updateRetiredEAVs(tokenId, amount); //Burn the tokens carbonPathToken.burnFrom(_msgSender(), amount); } /** * @dev Transfer CarbonPathToken for Selling * * Requirements: * - the caller must have the `SELLER_ROLE`. */ function sell(uint256 amount) public virtual onlySeller nonReentrant { require(amount > 0, 'CarbonPathAdmin: sell amount must be at least 1'); require( carbonPathToken.balanceOf(_msgSender()) >= amount, 'CarbonPathAdmin: not enough balance' ); carbonPathToken.transferFrom(_msgSender(), address(this), amount); } /** * @dev Withdraw stored CarbonPathTokens * * Requirements: * - the caller must have the `SELLER_ROLE`. */ function withdraw(uint256 amount) public virtual onlySeller nonReentrant { require(amount > 0, 'CarbonPathAdmin: withdraw amount must be at least 1'); require( carbonPathToken.balanceOf(address(this)) >= amount, 'CarbonPathAdmin: not enough balance' ); carbonPathToken.transfer(_msgSender(), amount); } /** * @dev Buy coins for selling * */ function buy(uint256 cpAmount) public virtual nonReentrant { require(cpAmount > 0, 'CarbonPathAdmin: buy amount must be at least 1'); require( carbonPathToken.balanceOf(address(this)) >= cpAmount, 'CarbonPathAdmin: not enough balance' ); uint256 requiredAmount = _calculateStableTokenAmount(cpAmount); require( stableToken.balanceOf(_msgSender()) >= requiredAmount, 'CarbonPathAdmin: not enough stable token' ); stableToken.transferFrom(_msgSender(), sellerAddress, requiredAmount); carbonPathToken.transfer(_msgSender(), cpAmount); } }
/_openzeppelin/contracts/access/AccessControl.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.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: * * ``` * 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}: * * ``` * 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. */ 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(uint160(account), 20), " 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()); } } }
/_openzeppelin/contracts/access/IAccessControl.sol
// 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; }
/_openzeppelin/contracts/access/Ownable.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.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 anymore. Can only be called by the current owner. * * NOTE: Renouncing ownership will leave the contract without an owner, * thereby removing 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); } }
/_openzeppelin/contracts/security/Pausable.sol
// 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()); } }
/_openzeppelin/contracts/security/ReentrancyGuard.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (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() { // On the first call to nonReentrant, _notEntered will be true require(_status != _ENTERED, "ReentrancyGuard: reentrant call"); // Any calls to nonReentrant after this point will fail _status = _ENTERED; _; // By storing the original value once again, a refund is triggered (see // https://eips.ethereum.org/EIPS/eip-2200) _status = _NOT_ENTERED; } }
/_openzeppelin/contracts/token/ERC20/ERC20.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (token/ERC20/ERC20.sol) pragma solidity ^0.8.0; import "./IERC20.sol"; import "./extensions/IERC20Metadata.sol"; import "../../utils/Context.sol"; /** * @dev Implementation of the {IERC20} interface. * * This implementation is agnostic to the way tokens are created. This means * that a supply mechanism has to be added in a derived contract using {_mint}. * For a generic mechanism see {ERC20PresetMinterPauser}. * * TIP: For a detailed writeup see our guide * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How * to implement supply mechanisms]. * * We have followed general OpenZeppelin Contracts guidelines: functions revert * instead returning `false` on failure. This behavior is nonetheless * conventional and does not conflict with the expectations of ERC20 * applications. * * Additionally, an {Approval} event is emitted on calls to {transferFrom}. * This allows applications to reconstruct the allowance for all accounts just * by listening to said events. Other implementations of the EIP may not emit * these events, as it isn't required by the specification. * * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} * functions have been added to mitigate the well-known issues around setting * allowances. See {IERC20-approve}. */ contract ERC20 is Context, IERC20, IERC20Metadata { mapping(address => uint256) private _balances; mapping(address => mapping(address => uint256)) private _allowances; uint256 private _totalSupply; string private _name; string private _symbol; /** * @dev Sets the values for {name} and {symbol}. * * The default value of {decimals} is 18. To select a different value for * {decimals} you should overload it. * * All two of these values are immutable: they can only be set once during * construction. */ constructor(string memory name_, string memory symbol_) { _name = name_; _symbol = symbol_; } /** * @dev Returns the name of the token. */ function name() public view virtual override returns (string memory) { return _name; } /** * @dev Returns the symbol of the token, usually a shorter version of the * name. */ function symbol() public view virtual override returns (string memory) { return _symbol; } /** * @dev Returns the number of decimals used to get its user representation. * For example, if `decimals` equals `2`, a balance of `505` tokens should * be displayed to a user as `5.05` (`505 / 10 ** 2`). * * Tokens usually opt for a value of 18, imitating the relationship between * Ether and Wei. This is the value {ERC20} uses, unless this function is * overridden; * * NOTE: This information is only used for _display_ purposes: it in * no way affects any of the arithmetic of the contract, including * {IERC20-balanceOf} and {IERC20-transfer}. */ function decimals() public view virtual override returns (uint8) { return 18; } /** * @dev See {IERC20-totalSupply}. */ function totalSupply() public view virtual override returns (uint256) { return _totalSupply; } /** * @dev See {IERC20-balanceOf}. */ function balanceOf(address account) public view virtual override returns (uint256) { return _balances[account]; } /** * @dev See {IERC20-transfer}. * * Requirements: * * - `to` cannot be the zero address. * - the caller must have a balance of at least `amount`. */ function transfer(address to, uint256 amount) public virtual override returns (bool) { address owner = _msgSender(); _transfer(owner, to, amount); return true; } /** * @dev See {IERC20-allowance}. */ function allowance(address owner, address spender) public view virtual override returns (uint256) { return _allowances[owner][spender]; } /** * @dev See {IERC20-approve}. * * NOTE: If `amount` is the maximum `uint256`, the allowance is not updated on * `transferFrom`. This is semantically equivalent to an infinite approval. * * Requirements: * * - `spender` cannot be the zero address. */ function approve(address spender, uint256 amount) public virtual override returns (bool) { address owner = _msgSender(); _approve(owner, spender, amount); return true; } /** * @dev See {IERC20-transferFrom}. * * Emits an {Approval} event indicating the updated allowance. This is not * required by the EIP. See the note at the beginning of {ERC20}. * * NOTE: Does not update the allowance if the current allowance * is the maximum `uint256`. * * Requirements: * * - `from` and `to` cannot be the zero address. * - `from` must have a balance of at least `amount`. * - the caller must have allowance for ``from``'s tokens of at least * `amount`. */ function transferFrom( address from, address to, uint256 amount ) public virtual override returns (bool) { address spender = _msgSender(); _spendAllowance(from, spender, amount); _transfer(from, to, amount); return true; } /** * @dev Atomically increases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. */ function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { address owner = _msgSender(); _approve(owner, spender, allowance(owner, spender) + addedValue); return true; } /** * @dev Atomically decreases the allowance granted to `spender` by the caller. * * This is an alternative to {approve} that can be used as a mitigation for * problems described in {IERC20-approve}. * * Emits an {Approval} event indicating the updated allowance. * * Requirements: * * - `spender` cannot be the zero address. * - `spender` must have allowance for the caller of at least * `subtractedValue`. */ function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { address owner = _msgSender(); uint256 currentAllowance = allowance(owner, spender); require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); unchecked { _approve(owner, spender, currentAllowance - subtractedValue); } return true; } /** * @dev Moves `amount` of tokens from `from` to `to`. * * This internal function is equivalent to {transfer}, and can be used to * e.g. implement automatic token fees, slashing mechanisms, etc. * * Emits a {Transfer} event. * * Requirements: * * - `from` cannot be the zero address. * - `to` cannot be the zero address. * - `from` must have a balance of at least `amount`. */ function _transfer( address from, address to, uint256 amount ) internal virtual { require(from != address(0), "ERC20: transfer from the zero address"); require(to != address(0), "ERC20: transfer to the zero address"); _beforeTokenTransfer(from, to, amount); uint256 fromBalance = _balances[from]; require(fromBalance >= amount, "ERC20: transfer amount exceeds balance"); unchecked { _balances[from] = fromBalance - amount; } _balances[to] += amount; emit Transfer(from, to, amount); _afterTokenTransfer(from, to, amount); } /** @dev Creates `amount` tokens and assigns them to `account`, increasing * the total supply. * * Emits a {Transfer} event with `from` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. */ function _mint(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: mint to the zero address"); _beforeTokenTransfer(address(0), account, amount); _totalSupply += amount; _balances[account] += amount; emit Transfer(address(0), account, amount); _afterTokenTransfer(address(0), account, amount); } /** * @dev Destroys `amount` tokens from `account`, reducing the * total supply. * * Emits a {Transfer} event with `to` set to the zero address. * * Requirements: * * - `account` cannot be the zero address. * - `account` must have at least `amount` tokens. */ function _burn(address account, uint256 amount) internal virtual { require(account != address(0), "ERC20: burn from the zero address"); _beforeTokenTransfer(account, address(0), amount); uint256 accountBalance = _balances[account]; require(accountBalance >= amount, "ERC20: burn amount exceeds balance"); unchecked { _balances[account] = accountBalance - amount; } _totalSupply -= amount; emit Transfer(account, address(0), amount); _afterTokenTransfer(account, address(0), amount); } /** * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. * * This internal function is equivalent to `approve`, and can be used to * e.g. set automatic allowances for certain subsystems, etc. * * Emits an {Approval} event. * * Requirements: * * - `owner` cannot be the zero address. * - `spender` cannot be the zero address. */ function _approve( address owner, address spender, uint256 amount ) internal virtual { require(owner != address(0), "ERC20: approve from the zero address"); require(spender != address(0), "ERC20: approve to the zero address"); _allowances[owner][spender] = amount; emit Approval(owner, spender, amount); } /** * @dev Updates `owner` s allowance for `spender` based on spent `amount`. * * Does not update the allowance amount in case of infinite allowance. * Revert if not enough allowance is available. * * Might emit an {Approval} event. */ function _spendAllowance( address owner, address spender, uint256 amount ) internal virtual { uint256 currentAllowance = allowance(owner, spender); if (currentAllowance != type(uint256).max) { require(currentAllowance >= amount, "ERC20: insufficient allowance"); unchecked { _approve(owner, spender, currentAllowance - amount); } } } /** * @dev Hook that is called before any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * will be transferred to `to`. * - when `from` is zero, `amount` tokens will be minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens 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 from, address to, uint256 amount ) internal virtual {} /** * @dev Hook that is called after any transfer of tokens. This includes * minting and burning. * * Calling conditions: * * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens * has been transferred to `to`. * - when `from` is zero, `amount` tokens have been minted for `to`. * - when `to` is zero, `amount` of ``from``'s tokens have been 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 _afterTokenTransfer( address from, address to, uint256 amount ) internal virtual {} }
/_openzeppelin/contracts/token/ERC20/IERC20.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.6.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); }
/_openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC20/extensions/IERC20Metadata.sol) pragma solidity ^0.8.0; import "../IERC20.sol"; /** * @dev Interface for the optional metadata functions from the ERC20 standard. * * _Available since v4.1._ */ interface IERC20Metadata is IERC20 { /** * @dev Returns the name of the token. */ function name() external view returns (string memory); /** * @dev Returns the symbol of the token. */ function symbol() external view returns (string memory); /** * @dev Returns the decimals places of the token. */ function decimals() external view returns (uint8); }
/_openzeppelin/contracts/token/ERC721/ERC721.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.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 = _owners[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 nor 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 nor 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 nor 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 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 _owners[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); _balances[to] += 1; _owners[tokenId] = to; emit Transfer(address(0), to, tokenId); _afterTokenTransfer(address(0), to, tokenId); } /** * @dev Destroys `tokenId`. * The approval is cleared when the token is burned. * * Requirements: * * - `tokenId` must exist. * * Emits a {Transfer} event. */ function _burn(uint256 tokenId) internal virtual { address owner = ERC721.ownerOf(tokenId); _beforeTokenTransfer(owner, address(0), tokenId); // Clear approvals _approve(address(0), tokenId); _balances[owner] -= 1; delete _owners[tokenId]; emit Transfer(owner, address(0), tokenId); _afterTokenTransfer(owner, address(0), tokenId); } /** * @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); // Clear approvals from the previous owner _approve(address(0), tokenId); _balances[from] -= 1; _balances[to] += 1; _owners[tokenId] = to; emit Transfer(from, to, tokenId); _afterTokenTransfer(from, to, tokenId); } /** * @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. * * 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 from, address to, uint256 tokenId ) internal virtual {} /** * @dev Hook that is called after any transfer of tokens. This includes * minting and burning. * * 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 from, address to, uint256 tokenId ) internal virtual {} }
/_openzeppelin/contracts/token/ERC721/IERC721.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.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: Usage of this method is discouraged, use {safeTransferFrom} whenever possible. * * 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); }
/_openzeppelin/contracts/token/ERC721/IERC721Receiver.sol
// 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); }
/_openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (token/ERC721/extensions/ERC721URIStorage.sol) pragma solidity ^0.8.0; import "../ERC721.sol"; /** * @dev ERC721 token with storage based token URI management. */ abstract contract ERC721URIStorage is ERC721 { using Strings for uint256; // Optional mapping for token URIs mapping(uint256 => string) private _tokenURIs; /** * @dev See {IERC721Metadata-tokenURI}. */ 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); } /** * @dev Sets `_tokenURI` as the tokenURI of `tokenId`. * * Requirements: * * - `tokenId` must exist. */ function _setTokenURI(uint256 tokenId, string memory _tokenURI) internal virtual { require(_exists(tokenId), "ERC721URIStorage: URI set of nonexistent token"); _tokenURIs[tokenId] = _tokenURI; } /** * @dev See {ERC721-_burn}. This override additionally checks to see if a * token-specific URI was set for the token, and if so, it deletes the token URI from * the storage mapping. */ function _burn(uint256 tokenId) internal virtual override { super._burn(tokenId); if (bytes(_tokenURIs[tokenId]).length != 0) { delete _tokenURIs[tokenId]; } } }
/_openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol
// 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); }
/_openzeppelin/contracts/utils/Address.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.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 * ==== * * [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://diligence.consensys.net/posts/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.5.11/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 functionCall(target, data, "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"); require(isContract(target), "Address: call to non-contract"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResult(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) { require(isContract(target), "Address: static call to non-contract"); (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResult(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) { require(isContract(target), "Address: delegate call to non-contract"); (bool success, bytes memory returndata) = target.delegatecall(data); return verifyCallResult(success, returndata, errorMessage); } /** * @dev Tool to verifies that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason 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 { // 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); } } } }
/_openzeppelin/contracts/utils/Context.sol
// 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; } }
/_openzeppelin/contracts/utils/Counters.sol
// 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; } }
/_openzeppelin/contracts/utils/Strings.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (utils/Strings.sol) pragma solidity ^0.8.0; /** * @dev String operations. */ library Strings { bytes16 private constant _HEX_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) { // Inspired by OraclizeAPI's implementation - MIT licence // https://github.com/oraclize/ethereum-api/blob/b42146b063c7d6ee1358846c198246239e9360e8/oraclizeAPI_0.4.25.sol if (value == 0) { return "0"; } uint256 temp = value; uint256 digits; while (temp != 0) { digits++; temp /= 10; } bytes memory buffer = new bytes(digits); while (value != 0) { digits -= 1; buffer[digits] = bytes1(uint8(48 + uint256(value % 10))); value /= 10; } return string(buffer); } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. */ function toHexString(uint256 value) internal pure returns (string memory) { if (value == 0) { return "0x00"; } uint256 temp = value; uint256 length = 0; while (temp != 0) { length++; temp >>= 8; } return toHexString(value, length); } /** * @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] = _HEX_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); } }
/_openzeppelin/contracts/utils/introspection/ERC165.sol
// 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; } }
/_openzeppelin/contracts/utils/introspection/IERC165.sol
// 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); }
/_openzeppelin/contracts/utils/math/SafeMath.sol
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.6.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; } } }
/contracts/CarbonPathNFT.sol
// contracts/CarbonPathNFT.sol // SPDX-License-Identifier: Apache-2.0 pragma solidity 0.8.17; import '@openzeppelin/contracts/access/Ownable.sol'; import '@openzeppelin/contracts/utils/math/SafeMath.sol'; import '@openzeppelin/contracts/utils/Counters.sol'; import '@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol'; /** * @title Carbon Path NFT */ contract CarbonPathNFT is Ownable, ERC721URIStorage { using SafeMath for uint256; using Counters for Counters.Counter; Counters.Counter private _tokenIdTracker; // Contract address of the Admin contract that can access this token address private _adminAddress; struct EAVTokens { uint256 advanceEAVs; uint256 bufferPoolEAVs; uint256 retiredEAVs; } mapping(uint256 => string) private metadata; // mapping of tokenId to metadata mapping(uint256 => EAVTokens) private eavTokens; // mapping of tokenId to number of EAVTokens constructor(address adminAddress) ERC721('Carbon Path NFT', '$CPNFT') { require(adminAddress != address(0), 'CarbonPathNFT: zero address for admin'); _adminAddress = adminAddress; } /** * @dev Require that the call came from the admin address. */ modifier onlyAdmin() { require(_msgSender() == _adminAddress, 'CarbonPathNFT: caller is not the admin'); _; } /** * @dev Returns the market address set via {setAdminAddress}. * */ function getAdminAddress() public view returns (address adminAddress) { return _adminAddress; } /** * @dev Set a new admin address. * * Requirements: * - the caller must be the owner. */ function setAdminAddress(address adminAddress) public onlyOwner { require(adminAddress != address(0), 'CarbonPathNFT: zero address for admin'); _adminAddress = adminAddress; } /** * @dev Returns the number of advance EAVs in the tokenId * */ function getAdvancedEAVs(uint256 tokenId) public view returns (uint256) { return eavTokens[tokenId].advanceEAVs; } /** * @dev Returns the number of buffer pool EAVs in the tokenId * */ function getBufferPoolEAVs(uint256 tokenId) public view returns (uint256) { return eavTokens[tokenId].bufferPoolEAVs; } /** * @dev Returns the number of retired EAVs in the tokenId * */ function getRetiredEAVs(uint256 tokenId) public view returns (uint256) { return eavTokens[tokenId].retiredEAVs; } /** * @dev Returns the metadata stored in the tokenId * */ function getMetadata(uint256 tokenId) public view returns (string memory) { return metadata[tokenId]; } /** * @dev Set the metadata for an NFT. * * Requirements: * - the caller must be the owner. */ function setMetadata(uint256 tokenId, string memory _metadata) external onlyOwner { metadata[tokenId] = _metadata; } /** * @dev Returns whether `spender` is allowed to manage `tokenId`. * * Requirements: * - `tokenId` must exist. */ function _isApprovedOrOwnerOrAdmin(address spender, uint256 tokenId) internal view returns (bool) { return (_isApprovedOrOwner(spender, tokenId) || spender == _adminAddress); } /** * @dev Creates a new token for `to`. * Additionally sets URI and metadata for the token * * Requirements: * - Only the admin address can mint NFTs */ function mint( address to, uint256 advanceAmount, uint256 bufferAmount, string memory tokenUri, string memory _metadata ) public virtual onlyAdmin { require(bytes(tokenUri).length > 0, 'CarbonPathNFT: uri should be set'); uint256 tokenId = _tokenIdTracker.current(); //set metadata and number of EAVs metadata[tokenId] = _metadata; eavTokens[tokenId].advanceEAVs = advanceAmount; eavTokens[tokenId].bufferPoolEAVs = bufferAmount; eavTokens[tokenId].retiredEAVs = 0; super._safeMint(to, tokenId); super._setTokenURI(tokenId, tokenUri); _tokenIdTracker.increment(); } /** * @dev update the number of RetiredEAVs * * Requirements: * - Only the admin address can update */ function updateRetiredEAVs(uint256 tokenId, uint256 retiredAmount) public virtual onlyAdmin { require( eavTokens[tokenId].advanceEAVs + eavTokens[tokenId].bufferPoolEAVs >= eavTokens[tokenId].retiredEAVs + retiredAmount, 'CarbonPathNFT: retired amount will exceed minted amount' ); eavTokens[tokenId].retiredEAVs += retiredAmount; } }
/contracts/CarbonPathToken.sol
// contracts/CarbonPathToken.sol // SPDX-License-Identifier: Apache-2.0 pragma solidity 0.8.17; import '@openzeppelin/contracts/token/ERC20/ERC20.sol'; import '@openzeppelin/contracts/security/Pausable.sol'; import '@openzeppelin/contracts/access/AccessControl.sol'; /** * @title CarbonPath Token */ contract CarbonPathToken is AccessControl, Pausable, ERC20 { bytes32 private constant MINTER_ROLE = keccak256('MINTER_ROLE'); constructor(string memory _name, string memory _symbol) ERC20(_name, _symbol) { // Setup initial permission for contract deployer _grantRole(DEFAULT_ADMIN_ROLE, _msgSender()); _grantRole(MINTER_ROLE, _msgSender()); } // Overides function decimals() public view virtual override returns (uint8) { return 0; } /** * @dev Grant Minter Role to the address * * Requirements: * - the caller must have the `DEFAULT_ADMIN_ROLE`. */ function grantMinter(address account) public { require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()), 'CarbonPathToken: must be an admin'); _grantRole(MINTER_ROLE, account); } /** * @dev Revoke Minter Role to the address * * Requirements: * - the caller must have the `DEFAULT_ADMIN_ROLE`. */ function revokeMinter(address account) public { require(hasRole(DEFAULT_ADMIN_ROLE, _msgSender()), 'CarbonPathToken: must be an admin'); _revokeRole(MINTER_ROLE, account); } /** * @dev Mints Carbon Path Tokens. * * Requirements: * - the caller must have the `MINTER_ROLE`. */ function mint(address account, uint256 amount) public { require(hasRole(MINTER_ROLE, _msgSender()), 'CarbonPathToken: must have minter role to mint'); _mint(account, amount); } /** * @dev Destroys `amount` tokens from the caller. * * See {ERC20-_burn}. * * Requirements: * * - the caller must have `MINTER_ROLE` */ function burn(uint256 amount) public virtual { require(hasRole(MINTER_ROLE, _msgSender()), 'CarbonPathToken: must have minter role to burn'); _burn(_msgSender(), amount); } /** * @dev Destroys `amount` tokens from `account`, deducting from the caller's * allowance. * * See {ERC20-_burn} and {ERC20-allowance}. * * Requirements: * * - the caller must have allowance for ``accounts``'s tokens of at least * `amount`. * - the caller must have `MINTER_ROLE` */ function burnFrom(address account, uint256 amount) public virtual { require(hasRole(MINTER_ROLE, _msgSender()), 'CarbonPathToken: must have minter role to burn'); _spendAllowance(account, _msgSender(), amount); _burn(account, amount); } }
Contract ABI
[{"type":"constructor","stateMutability":"nonpayable","inputs":[{"type":"address","name":"_nftContractAddress","internalType":"address"},{"type":"address","name":"_tokenContractAddress","internalType":"address"},{"type":"address","name":"_stableTokenAddress","internalType":"address"}]},{"type":"event","name":"OwnershipTransferred","inputs":[{"type":"address","name":"previousOwner","internalType":"address","indexed":true},{"type":"address","name":"newOwner","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"RoleAdminChanged","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32","indexed":true},{"type":"bytes32","name":"previousAdminRole","internalType":"bytes32","indexed":true},{"type":"bytes32","name":"newAdminRole","internalType":"bytes32","indexed":true}],"anonymous":false},{"type":"event","name":"RoleGranted","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32","indexed":true},{"type":"address","name":"account","internalType":"address","indexed":true},{"type":"address","name":"sender","internalType":"address","indexed":true}],"anonymous":false},{"type":"event","name":"RoleRevoked","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32","indexed":true},{"type":"address","name":"account","internalType":"address","indexed":true},{"type":"address","name":"sender","internalType":"address","indexed":true}],"anonymous":false},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"BASE_PERCENTAGE","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32","name":"","internalType":"bytes32"}],"name":"DEFAULT_ADMIN_ROLE","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"EXCHANGE_RATE","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"uint256","name":"","internalType":"uint256"}],"name":"NON_PROFIT_PERCENTAGE","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"bufferPoolAddress","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"buy","inputs":[{"type":"uint256","name":"cpAmount","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"contract CarbonPathNFT"}],"name":"carbonPathNFT","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"contract CarbonPathToken"}],"name":"carbonPathToken","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"cpFeeAddress","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bytes32","name":"","internalType":"bytes32"}],"name":"getRoleAdmin","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"grantMinter","inputs":[{"type":"address","name":"account","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"grantRole","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32"},{"type":"address","name":"account","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"hasRole","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32"},{"type":"address","name":"account","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"mint","inputs":[{"type":"address","name":"to","internalType":"address"},{"type":"uint256","name":"advanceAmount","internalType":"uint256"},{"type":"uint256","name":"cpFeePercentage","internalType":"uint256"},{"type":"uint256","name":"bufferAmount","internalType":"uint256"},{"type":"address","name":"operatorAddress","internalType":"address"},{"type":"string","name":"tokenUri","internalType":"string"},{"type":"string","name":"metadata","internalType":"string"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"nonProfitAddress","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"owner","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"renounceOwnership","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"renounceRole","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32"},{"type":"address","name":"account","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"retire","inputs":[{"type":"uint256","name":"tokenId","internalType":"uint256"},{"type":"uint256","name":"amount","internalType":"uint256"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"revokeMinter","inputs":[{"type":"address","name":"account","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"revokeRole","inputs":[{"type":"bytes32","name":"role","internalType":"bytes32"},{"type":"address","name":"account","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"sell","inputs":[{"type":"uint256","name":"amount","internalType":"uint256"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"address"}],"name":"sellerAddress","inputs":[]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setBufferPoolAddress","inputs":[{"type":"address","name":"_address","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setCpFeeAddress","inputs":[{"type":"address","name":"_address","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setNonProfitAddress","inputs":[{"type":"address","name":"_address","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"setSellerAddress","inputs":[{"type":"address","name":"_address","internalType":"address"}]},{"type":"function","stateMutability":"view","outputs":[{"type":"address","name":"","internalType":"contract IERC20"}],"name":"stableToken","inputs":[]},{"type":"function","stateMutability":"view","outputs":[{"type":"bool","name":"","internalType":"bool"}],"name":"supportsInterface","inputs":[{"type":"bytes4","name":"interfaceId","internalType":"bytes4"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"transferOwnership","inputs":[{"type":"address","name":"newOwner","internalType":"address"}]},{"type":"function","stateMutability":"nonpayable","outputs":[],"name":"withdraw","inputs":[{"type":"uint256","name":"amount","internalType":"uint256"}]}]
Contract Creation Code
0x60806040523480156200001157600080fd5b5060405162001fbe38038062001fbe8339810160408190526200003491620001cf565b6200003f33620000ca565b6001600255600380546001600160a01b038086166001600160a01b0319928316179092556004805485841690831617905560058054928416929091169190911790556200009560006200008f3390565b6200011a565b620000c17f9f2df0fed2c77648de5860a4cc508cd0818c85b8b8a1ab4ceeef8d981c8956a6336200011a565b50505062000219565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b6200012682826200012a565b5050565b60008281526001602090815260408083206001600160a01b038516845290915290205460ff16620001265760008281526001602081815260408084206001600160a01b0386168086529252808420805460ff19169093179092559051339285917f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d9190a45050565b80516001600160a01b0381168114620001ca57600080fd5b919050565b600080600060608486031215620001e557600080fd5b620001f084620001b2565b92506200020060208501620001b2565b91506200021060408501620001b2565b90509250925092565b611d9580620002296000396000f3fe608060405234801561001057600080fd5b50600436106101e45760003560e01c80635380aea31161010f578063bbf8d3a5116100a2578063d96a094a11610071578063d96a094a14610400578063e4849b3214610413578063e4d589e814610426578063f2fde38b1461043957600080fd5b8063bbf8d3a5146103b4578063c57e5663146103c7578063cfbd4885146103da578063d547741f146103ed57600080fd5b806391d14854116100de57806391d1485414610373578063a12df12e14610386578063a217fddf14610399578063a9d75b2b146103a157600080fd5b80635380aea31461033f578063715018a6146103525780637e2e8d931461035a5780638da5cb5b1461036257600080fd5b8063261707fa116101875780632f2ff15d116101565780632f2ff15d146102f357806336568abe146103065780633d9b2ae614610319578063528ee6051461032c57600080fd5b8063261707fa146102b15780632643d627146102c4578063293a7f2e146102cd5780632e1a7d4d146102e057600080fd5b806312f2d071116101c357806312f2d0711461025157806314a8bd0d14610264578063159eea051461027a578063248a9ca31461028d57600080fd5b8062fee372146101e957806301ffc9a7146102195780630d374eca1461023c575b600080fd5b6007546101fc906001600160a01b031681565b6040516001600160a01b0390911681526020015b60405180910390f35b61022c610227366004611809565b61044c565b6040519015158152602001610210565b61024f61024a36600461184f565b610483565b005b61024f61025f36600461190d565b6104d5565b61026c601e81565b604051908152602001610210565b6004546101fc906001600160a01b031681565b61026c61029b3660046119af565b6000908152600160208190526040909120015490565b61024f6102bf36600461184f565b6108ae565b61026c6103e881565b61024f6102db3660046119c8565b610902565b61024f6102ee3660046119af565b610b0b565b61024f6103013660046119ea565b610cdb565b61024f6103143660046119ea565b610d06565b6009546101fc906001600160a01b031681565b61024f61033a36600461184f565b610d84565b6006546101fc906001600160a01b031681565b61024f610dcd565b61026c603281565b6000546001600160a01b03166101fc565b61022c6103813660046119ea565b610de1565b61024f61039436600461184f565b610e0c565b61026c600081565b6005546101fc906001600160a01b031681565b6003546101fc906001600160a01b031681565b61024f6103d536600461184f565b610e55565b61024f6103e836600461184f565b610e9e565b61024f6103fb3660046119ea565b610eef565b61024f61040e3660046119af565b610f15565b61024f6104213660046119af565b611231565b6008546101fc906001600160a01b031681565b61024f61044736600461184f565b6113c6565b60006001600160e01b03198216637965db0b60e01b148061047d57506301ffc9a760e01b6001600160e01b03198316145b92915050565b61048e600033610de1565b6104b35760405162461bcd60e51b81526004016104aa90611a16565b60405180910390fd5b600880546001600160a01b0319166001600160a01b0392909216919091179055565b60028054036104f65760405162461bcd60e51b81526004016104aa90611a5b565b600280556105247f9f2df0fed2c77648de5860a4cc508cd0818c85b8b8a1ab4ceeef8d981c8956a633610de1565b6105875760405162461bcd60e51b815260206004820152602e60248201527f436172626f6e5061746841646d696e3a206d7573742068617665206d696e746560448201526d1c881c9bdb19481d1bc81b5a5b9d60921b60648201526084016104aa565b600354604051630da026c360e31b81526001600160a01b0390911690636d013618906105bf908a908a90899088908890600401611ae2565b600060405180830381600087803b1580156105d957600080fd5b505af11580156105ed573d6000803e3d6000fd5b5050505060006105fd878761143c565b9050600061060a8661145c565b6004549091506001600160a01b03166340c10f1930610629898c611b43565b6040516001600160e01b031960e085901b1681526001600160a01b0390921660048301526024820152604401600060405180830381600087803b15801561066f57600080fd5b505af1158015610683573d6000803e3d6000fd5b50506004805460065460405163a9059cbb60e01b81526001600160a01b03918216938101939093526024830187905216925063a9059cbb91506044016020604051808303816000875af11580156106de573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107029190611b56565b506004546001600160a01b031663a9059cbb8661071f858c611b78565b6040516001600160e01b031960e085901b1681526001600160a01b03909216600483015260248201526044016020604051808303816000875af115801561076a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061078e9190611b56565b506004805460085460405163a9059cbb60e01b81526001600160a01b039182169381019390935260248301849052169063a9059cbb906044016020604051808303816000875af11580156107e6573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061080a9190611b56565b506004546007546001600160a01b039182169163a9059cbb911661082e848a611b78565b6040516001600160e01b031960e085901b1681526001600160a01b03909216600483015260248201526044016020604051808303816000875af1158015610879573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061089d9190611b56565b505060016002555050505050505050565b6108b9600033610de1565b6108d55760405162461bcd60e51b81526004016104aa90611b8b565b6108ff7f9f2df0fed2c77648de5860a4cc508cd0818c85b8b8a1ab4ceeef8d981c8956a682611476565b50565b60028054036109235760405162461bcd60e51b81526004016104aa90611a5b565b600280558061098f5760405162461bcd60e51b815260206004820152603260248201527f436172626f6e5061746841646d696e3a207265746972656420616d6f756e74206044820152716d757374206265206174206c65617374203160701b60648201526084016104aa565b60045481906001600160a01b03166370a08231336040516001600160e01b031960e084901b1681526001600160a01b039091166004820152602401602060405180830381865afa1580156109e7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a0b9190611bcc565b1015610a295760405162461bcd60e51b81526004016104aa90611be5565b6003546040516305806dc960e01b815260048101849052602481018390526001600160a01b03909116906305806dc990604401600060405180830381600087803b158015610a7657600080fd5b505af1158015610a8a573d6000803e3d6000fd5b50506004546001600160a01b031691506379cc67909050336040516001600160e01b031960e084901b1681526001600160a01b03909116600482015260248101849052604401600060405180830381600087803b158015610aea57600080fd5b505af1158015610afe573d6000803e3d6000fd5b5050600160025550505050565b6009546001600160a01b0316336001600160a01b031614610b3e5760405162461bcd60e51b81526004016104aa90611c28565b6002805403610b5f5760405162461bcd60e51b81526004016104aa90611a5b565b6002805580610bcc5760405162461bcd60e51b815260206004820152603360248201527f436172626f6e5061746841646d696e3a20776974686472617720616d6f756e74604482015272206d757374206265206174206c65617374203160681b60648201526084016104aa565b600480546040516370a0823160e01b8152309281019290925282916001600160a01b03909116906370a0823190602401602060405180830381865afa158015610c19573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c3d9190611bcc565b1015610c5b5760405162461bcd60e51b81526004016104aa90611be5565b6004805460405163a9059cbb60e01b81523392810192909252602482018390526001600160a01b03169063a9059cbb906044015b6020604051808303816000875af1158015610cae573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610cd29190611b56565b50506001600255565b60008281526001602081905260409091200154610cf7816114e1565b610d018383611476565b505050565b6001600160a01b0381163314610d765760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201526e103937b632b9903337b91039b2b63360891b60648201526084016104aa565b610d8082826114eb565b5050565b610d8f600033610de1565b610dab5760405162461bcd60e51b81526004016104aa90611a16565b600780546001600160a01b0319166001600160a01b0392909216919091179055565b610dd5611552565b610ddf60006115ac565b565b60009182526001602090815260408084206001600160a01b0393909316845291905290205460ff1690565b610e17600033610de1565b610e335760405162461bcd60e51b81526004016104aa90611a16565b600980546001600160a01b0319166001600160a01b0392909216919091179055565b610e60600033610de1565b610e7c5760405162461bcd60e51b81526004016104aa90611a16565b600680546001600160a01b0319166001600160a01b0392909216919091179055565b610ea9600033610de1565b610ec55760405162461bcd60e51b81526004016104aa90611b8b565b6108ff7f9f2df0fed2c77648de5860a4cc508cd0818c85b8b8a1ab4ceeef8d981c8956a6826114eb565b60008281526001602081905260409091200154610f0b816114e1565b610d0183836114eb565b6002805403610f365760405162461bcd60e51b81526004016104aa90611a5b565b6002805580610f9e5760405162461bcd60e51b815260206004820152602e60248201527f436172626f6e5061746841646d696e3a2062757920616d6f756e74206d75737460448201526d206265206174206c65617374203160901b60648201526084016104aa565b600480546040516370a0823160e01b8152309281019290925282916001600160a01b03909116906370a0823190602401602060405180830381865afa158015610feb573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061100f9190611bcc565b101561102d5760405162461bcd60e51b81526004016104aa90611be5565b6000611038826115fc565b60055490915081906001600160a01b03166370a08231336040516001600160e01b031960e084901b1681526001600160a01b039091166004820152602401602060405180830381865afa158015611093573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110b79190611bcc565b10156111165760405162461bcd60e51b815260206004820152602860248201527f436172626f6e5061746841646d696e3a206e6f7420656e6f75676820737461626044820152673632903a37b5b2b760c11b60648201526084016104aa565b6005546001600160a01b03166323b872dd3360095460405160e084901b6001600160e01b03191681526001600160a01b03928316600482015291166024820152604481018490526064016020604051808303816000875af115801561117f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111a39190611b56565b506004546001600160a01b031663a9059cbb336040516001600160e01b031960e084901b1681526001600160a01b039091166004820152602481018590526044016020604051808303816000875af1158015611203573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112279190611b56565b5050600160025550565b6009546001600160a01b0316336001600160a01b0316146112645760405162461bcd60e51b81526004016104aa90611c28565b60028054036112855760405162461bcd60e51b81526004016104aa90611a5b565b60028055806112ee5760405162461bcd60e51b815260206004820152602f60248201527f436172626f6e5061746841646d696e3a2073656c6c20616d6f756e74206d757360448201526e74206265206174206c65617374203160881b60648201526084016104aa565b60045481906001600160a01b03166370a08231336040516001600160e01b031960e084901b1681526001600160a01b039091166004820152602401602060405180830381865afa158015611346573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061136a9190611bcc565b10156113885760405162461bcd60e51b81526004016104aa90611be5565b600480546040516323b872dd60e01b81523392810192909252306024830152604482018390526001600160a01b0316906323b872dd90606401610c8f565b6113ce611552565b6001600160a01b0381166114335760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b60648201526084016104aa565b6108ff816115ac565b60006103e861144b8385611c71565b6114559190611c88565b9392505050565b60006103e861146c603284611c71565b61047d9190611c88565b6114808282610de1565b610d805760008281526001602081815260408084206001600160a01b0386168086529252808420805460ff19169093179092559051339285917f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d9190a45050565b6108ff8133611609565b6114f58282610de1565b15610d805760008281526001602090815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b6000546001600160a01b03163314610ddf5760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064016104aa565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b600061047d601e83611c71565b6116138282610de1565b610d805761162b816001600160a01b0316601461166d565b61163683602061166d565b604051602001611647929190611caa565b60408051601f198184030181529082905262461bcd60e51b82526104aa91600401611d1f565b6060600061167c836002611c71565b611687906002611b43565b67ffffffffffffffff81111561169f5761169f61186a565b6040519080825280601f01601f1916602001820160405280156116c9576020820181803683370190505b509050600360fc1b816000815181106116e4576116e4611d32565b60200101906001600160f81b031916908160001a905350600f60fb1b8160018151811061171357611713611d32565b60200101906001600160f81b031916908160001a9053506000611737846002611c71565b611742906001611b43565b90505b60018111156117ba576f181899199a1a9b1b9c1cb0b131b232b360811b85600f166010811061177657611776611d32565b1a60f81b82828151811061178c5761178c611d32565b60200101906001600160f81b031916908160001a90535060049490941c936117b381611d48565b9050611745565b5083156114555760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e7460448201526064016104aa565b60006020828403121561181b57600080fd5b81356001600160e01b03198116811461145557600080fd5b80356001600160a01b038116811461184a57600080fd5b919050565b60006020828403121561186157600080fd5b61145582611833565b634e487b7160e01b600052604160045260246000fd5b600082601f83011261189157600080fd5b813567ffffffffffffffff808211156118ac576118ac61186a565b604051601f8301601f19908116603f011681019082821181831017156118d4576118d461186a565b816040528381528660208588010111156118ed57600080fd5b836020870160208301376000602085830101528094505050505092915050565b600080600080600080600060e0888a03121561192857600080fd5b61193188611833565b965060208801359550604088013594506060880135935061195460808901611833565b925060a088013567ffffffffffffffff8082111561197157600080fd5b61197d8b838c01611880565b935060c08a013591508082111561199357600080fd5b506119a08a828b01611880565b91505092959891949750929550565b6000602082840312156119c157600080fd5b5035919050565b600080604083850312156119db57600080fd5b50508035926020909101359150565b600080604083850312156119fd57600080fd5b82359150611a0d60208401611833565b90509250929050565b60208082526025908201527f436172626f6e5061746841646d696e3a206d75737420686176652061646d696e60408201526420726f6c6560d81b606082015260800190565b6020808252601f908201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604082015260600190565b60005b83811015611aad578181015183820152602001611a95565b50506000910152565b60008151808452611ace816020860160208601611a92565b601f01601f19169290920160200192915050565b60018060a01b038616815284602082015283604082015260a060608201526000611b0f60a0830185611ab6565b8281036080840152611b218185611ab6565b98975050505050505050565b634e487b7160e01b600052601160045260246000fd5b8082018082111561047d5761047d611b2d565b600060208284031215611b6857600080fd5b8151801515811461145557600080fd5b8181038181111561047d5761047d611b2d565b60208082526021908201527f436172626f6e5061746841646d696e3a206d75737420626520616e2061646d696040820152603760f91b606082015260800190565b600060208284031215611bde57600080fd5b5051919050565b60208082526023908201527f436172626f6e5061746841646d696e3a206e6f7420656e6f7567682062616c616040820152626e636560e81b606082015260800190565b60208082526029908201527f436172626f6e5061746841646d696e3a2063616c6c6572206973206e6f74207460408201526834329039b2b63632b960b91b606082015260800190565b808202811582820484141761047d5761047d611b2d565b600082611ca557634e487b7160e01b600052601260045260246000fd5b500490565b7f416363657373436f6e74726f6c3a206163636f756e7420000000000000000000815260008351611ce2816017850160208801611a92565b7001034b99036b4b9b9b4b733903937b6329607d1b6017918401918201528351611d13816028840160208801611a92565b01602801949350505050565b6020815260006114556020830184611ab6565b634e487b7160e01b600052603260045260246000fd5b600081611d5757611d57611b2d565b50600019019056fea26469706673582212205ea3b6b452f7c2adef0a0a42e1263497d8e9aa2dc406123cb98cfa724c37bde564736f6c634300081100330000000000000000000000009a24c5553d17c2ed5942deea26a8a009439c6df200000000000000000000000088e953d6499abce5e75e7a07edf2e8abad99df50000000000000000000000000874069fa1eb16d44d622f2e0ca25eea172369bc1
Deployed ByteCode
0x608060405234801561001057600080fd5b50600436106101e45760003560e01c80635380aea31161010f578063bbf8d3a5116100a2578063d96a094a11610071578063d96a094a14610400578063e4849b3214610413578063e4d589e814610426578063f2fde38b1461043957600080fd5b8063bbf8d3a5146103b4578063c57e5663146103c7578063cfbd4885146103da578063d547741f146103ed57600080fd5b806391d14854116100de57806391d1485414610373578063a12df12e14610386578063a217fddf14610399578063a9d75b2b146103a157600080fd5b80635380aea31461033f578063715018a6146103525780637e2e8d931461035a5780638da5cb5b1461036257600080fd5b8063261707fa116101875780632f2ff15d116101565780632f2ff15d146102f357806336568abe146103065780633d9b2ae614610319578063528ee6051461032c57600080fd5b8063261707fa146102b15780632643d627146102c4578063293a7f2e146102cd5780632e1a7d4d146102e057600080fd5b806312f2d071116101c357806312f2d0711461025157806314a8bd0d14610264578063159eea051461027a578063248a9ca31461028d57600080fd5b8062fee372146101e957806301ffc9a7146102195780630d374eca1461023c575b600080fd5b6007546101fc906001600160a01b031681565b6040516001600160a01b0390911681526020015b60405180910390f35b61022c610227366004611809565b61044c565b6040519015158152602001610210565b61024f61024a36600461184f565b610483565b005b61024f61025f36600461190d565b6104d5565b61026c601e81565b604051908152602001610210565b6004546101fc906001600160a01b031681565b61026c61029b3660046119af565b6000908152600160208190526040909120015490565b61024f6102bf36600461184f565b6108ae565b61026c6103e881565b61024f6102db3660046119c8565b610902565b61024f6102ee3660046119af565b610b0b565b61024f6103013660046119ea565b610cdb565b61024f6103143660046119ea565b610d06565b6009546101fc906001600160a01b031681565b61024f61033a36600461184f565b610d84565b6006546101fc906001600160a01b031681565b61024f610dcd565b61026c603281565b6000546001600160a01b03166101fc565b61022c6103813660046119ea565b610de1565b61024f61039436600461184f565b610e0c565b61026c600081565b6005546101fc906001600160a01b031681565b6003546101fc906001600160a01b031681565b61024f6103d536600461184f565b610e55565b61024f6103e836600461184f565b610e9e565b61024f6103fb3660046119ea565b610eef565b61024f61040e3660046119af565b610f15565b61024f6104213660046119af565b611231565b6008546101fc906001600160a01b031681565b61024f61044736600461184f565b6113c6565b60006001600160e01b03198216637965db0b60e01b148061047d57506301ffc9a760e01b6001600160e01b03198316145b92915050565b61048e600033610de1565b6104b35760405162461bcd60e51b81526004016104aa90611a16565b60405180910390fd5b600880546001600160a01b0319166001600160a01b0392909216919091179055565b60028054036104f65760405162461bcd60e51b81526004016104aa90611a5b565b600280556105247f9f2df0fed2c77648de5860a4cc508cd0818c85b8b8a1ab4ceeef8d981c8956a633610de1565b6105875760405162461bcd60e51b815260206004820152602e60248201527f436172626f6e5061746841646d696e3a206d7573742068617665206d696e746560448201526d1c881c9bdb19481d1bc81b5a5b9d60921b60648201526084016104aa565b600354604051630da026c360e31b81526001600160a01b0390911690636d013618906105bf908a908a90899088908890600401611ae2565b600060405180830381600087803b1580156105d957600080fd5b505af11580156105ed573d6000803e3d6000fd5b5050505060006105fd878761143c565b9050600061060a8661145c565b6004549091506001600160a01b03166340c10f1930610629898c611b43565b6040516001600160e01b031960e085901b1681526001600160a01b0390921660048301526024820152604401600060405180830381600087803b15801561066f57600080fd5b505af1158015610683573d6000803e3d6000fd5b50506004805460065460405163a9059cbb60e01b81526001600160a01b03918216938101939093526024830187905216925063a9059cbb91506044016020604051808303816000875af11580156106de573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906107029190611b56565b506004546001600160a01b031663a9059cbb8661071f858c611b78565b6040516001600160e01b031960e085901b1681526001600160a01b03909216600483015260248201526044016020604051808303816000875af115801561076a573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061078e9190611b56565b506004805460085460405163a9059cbb60e01b81526001600160a01b039182169381019390935260248301849052169063a9059cbb906044016020604051808303816000875af11580156107e6573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061080a9190611b56565b506004546007546001600160a01b039182169163a9059cbb911661082e848a611b78565b6040516001600160e01b031960e085901b1681526001600160a01b03909216600483015260248201526044016020604051808303816000875af1158015610879573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061089d9190611b56565b505060016002555050505050505050565b6108b9600033610de1565b6108d55760405162461bcd60e51b81526004016104aa90611b8b565b6108ff7f9f2df0fed2c77648de5860a4cc508cd0818c85b8b8a1ab4ceeef8d981c8956a682611476565b50565b60028054036109235760405162461bcd60e51b81526004016104aa90611a5b565b600280558061098f5760405162461bcd60e51b815260206004820152603260248201527f436172626f6e5061746841646d696e3a207265746972656420616d6f756e74206044820152716d757374206265206174206c65617374203160701b60648201526084016104aa565b60045481906001600160a01b03166370a08231336040516001600160e01b031960e084901b1681526001600160a01b039091166004820152602401602060405180830381865afa1580156109e7573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610a0b9190611bcc565b1015610a295760405162461bcd60e51b81526004016104aa90611be5565b6003546040516305806dc960e01b815260048101849052602481018390526001600160a01b03909116906305806dc990604401600060405180830381600087803b158015610a7657600080fd5b505af1158015610a8a573d6000803e3d6000fd5b50506004546001600160a01b031691506379cc67909050336040516001600160e01b031960e084901b1681526001600160a01b03909116600482015260248101849052604401600060405180830381600087803b158015610aea57600080fd5b505af1158015610afe573d6000803e3d6000fd5b5050600160025550505050565b6009546001600160a01b0316336001600160a01b031614610b3e5760405162461bcd60e51b81526004016104aa90611c28565b6002805403610b5f5760405162461bcd60e51b81526004016104aa90611a5b565b6002805580610bcc5760405162461bcd60e51b815260206004820152603360248201527f436172626f6e5061746841646d696e3a20776974686472617720616d6f756e74604482015272206d757374206265206174206c65617374203160681b60648201526084016104aa565b600480546040516370a0823160e01b8152309281019290925282916001600160a01b03909116906370a0823190602401602060405180830381865afa158015610c19573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610c3d9190611bcc565b1015610c5b5760405162461bcd60e51b81526004016104aa90611be5565b6004805460405163a9059cbb60e01b81523392810192909252602482018390526001600160a01b03169063a9059cbb906044015b6020604051808303816000875af1158015610cae573d6000803e3d6000fd5b505050506040513d601f19601f82011682018060405250810190610cd29190611b56565b50506001600255565b60008281526001602081905260409091200154610cf7816114e1565b610d018383611476565b505050565b6001600160a01b0381163314610d765760405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201526e103937b632b9903337b91039b2b63360891b60648201526084016104aa565b610d8082826114eb565b5050565b610d8f600033610de1565b610dab5760405162461bcd60e51b81526004016104aa90611a16565b600780546001600160a01b0319166001600160a01b0392909216919091179055565b610dd5611552565b610ddf60006115ac565b565b60009182526001602090815260408084206001600160a01b0393909316845291905290205460ff1690565b610e17600033610de1565b610e335760405162461bcd60e51b81526004016104aa90611a16565b600980546001600160a01b0319166001600160a01b0392909216919091179055565b610e60600033610de1565b610e7c5760405162461bcd60e51b81526004016104aa90611a16565b600680546001600160a01b0319166001600160a01b0392909216919091179055565b610ea9600033610de1565b610ec55760405162461bcd60e51b81526004016104aa90611b8b565b6108ff7f9f2df0fed2c77648de5860a4cc508cd0818c85b8b8a1ab4ceeef8d981c8956a6826114eb565b60008281526001602081905260409091200154610f0b816114e1565b610d0183836114eb565b6002805403610f365760405162461bcd60e51b81526004016104aa90611a5b565b6002805580610f9e5760405162461bcd60e51b815260206004820152602e60248201527f436172626f6e5061746841646d696e3a2062757920616d6f756e74206d75737460448201526d206265206174206c65617374203160901b60648201526084016104aa565b600480546040516370a0823160e01b8152309281019290925282916001600160a01b03909116906370a0823190602401602060405180830381865afa158015610feb573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061100f9190611bcc565b101561102d5760405162461bcd60e51b81526004016104aa90611be5565b6000611038826115fc565b60055490915081906001600160a01b03166370a08231336040516001600160e01b031960e084901b1681526001600160a01b039091166004820152602401602060405180830381865afa158015611093573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906110b79190611bcc565b10156111165760405162461bcd60e51b815260206004820152602860248201527f436172626f6e5061746841646d696e3a206e6f7420656e6f75676820737461626044820152673632903a37b5b2b760c11b60648201526084016104aa565b6005546001600160a01b03166323b872dd3360095460405160e084901b6001600160e01b03191681526001600160a01b03928316600482015291166024820152604481018490526064016020604051808303816000875af115801561117f573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906111a39190611b56565b506004546001600160a01b031663a9059cbb336040516001600160e01b031960e084901b1681526001600160a01b039091166004820152602481018590526044016020604051808303816000875af1158015611203573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906112279190611b56565b5050600160025550565b6009546001600160a01b0316336001600160a01b0316146112645760405162461bcd60e51b81526004016104aa90611c28565b60028054036112855760405162461bcd60e51b81526004016104aa90611a5b565b60028055806112ee5760405162461bcd60e51b815260206004820152602f60248201527f436172626f6e5061746841646d696e3a2073656c6c20616d6f756e74206d757360448201526e74206265206174206c65617374203160881b60648201526084016104aa565b60045481906001600160a01b03166370a08231336040516001600160e01b031960e084901b1681526001600160a01b039091166004820152602401602060405180830381865afa158015611346573d6000803e3d6000fd5b505050506040513d601f19601f8201168201806040525081019061136a9190611bcc565b10156113885760405162461bcd60e51b81526004016104aa90611be5565b600480546040516323b872dd60e01b81523392810192909252306024830152604482018390526001600160a01b0316906323b872dd90606401610c8f565b6113ce611552565b6001600160a01b0381166114335760405162461bcd60e51b815260206004820152602660248201527f4f776e61626c653a206e6577206f776e657220697320746865207a65726f206160448201526564647265737360d01b60648201526084016104aa565b6108ff816115ac565b60006103e861144b8385611c71565b6114559190611c88565b9392505050565b60006103e861146c603284611c71565b61047d9190611c88565b6114808282610de1565b610d805760008281526001602081815260408084206001600160a01b0386168086529252808420805460ff19169093179092559051339285917f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d9190a45050565b6108ff8133611609565b6114f58282610de1565b15610d805760008281526001602090815260408083206001600160a01b0385168085529252808320805460ff1916905551339285917ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b9190a45050565b6000546001600160a01b03163314610ddf5760405162461bcd60e51b815260206004820181905260248201527f4f776e61626c653a2063616c6c6572206973206e6f7420746865206f776e657260448201526064016104aa565b600080546001600160a01b038381166001600160a01b0319831681178455604051919092169283917f8be0079c531659141344cd1fd0a4f28419497f9722a3daafe3b4186f6b6457e09190a35050565b600061047d601e83611c71565b6116138282610de1565b610d805761162b816001600160a01b0316601461166d565b61163683602061166d565b604051602001611647929190611caa565b60408051601f198184030181529082905262461bcd60e51b82526104aa91600401611d1f565b6060600061167c836002611c71565b611687906002611b43565b67ffffffffffffffff81111561169f5761169f61186a565b6040519080825280601f01601f1916602001820160405280156116c9576020820181803683370190505b509050600360fc1b816000815181106116e4576116e4611d32565b60200101906001600160f81b031916908160001a905350600f60fb1b8160018151811061171357611713611d32565b60200101906001600160f81b031916908160001a9053506000611737846002611c71565b611742906001611b43565b90505b60018111156117ba576f181899199a1a9b1b9c1cb0b131b232b360811b85600f166010811061177657611776611d32565b1a60f81b82828151811061178c5761178c611d32565b60200101906001600160f81b031916908160001a90535060049490941c936117b381611d48565b9050611745565b5083156114555760405162461bcd60e51b815260206004820181905260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e7460448201526064016104aa565b60006020828403121561181b57600080fd5b81356001600160e01b03198116811461145557600080fd5b80356001600160a01b038116811461184a57600080fd5b919050565b60006020828403121561186157600080fd5b61145582611833565b634e487b7160e01b600052604160045260246000fd5b600082601f83011261189157600080fd5b813567ffffffffffffffff808211156118ac576118ac61186a565b604051601f8301601f19908116603f011681019082821181831017156118d4576118d461186a565b816040528381528660208588010111156118ed57600080fd5b836020870160208301376000602085830101528094505050505092915050565b600080600080600080600060e0888a03121561192857600080fd5b61193188611833565b965060208801359550604088013594506060880135935061195460808901611833565b925060a088013567ffffffffffffffff8082111561197157600080fd5b61197d8b838c01611880565b935060c08a013591508082111561199357600080fd5b506119a08a828b01611880565b91505092959891949750929550565b6000602082840312156119c157600080fd5b5035919050565b600080604083850312156119db57600080fd5b50508035926020909101359150565b600080604083850312156119fd57600080fd5b82359150611a0d60208401611833565b90509250929050565b60208082526025908201527f436172626f6e5061746841646d696e3a206d75737420686176652061646d696e60408201526420726f6c6560d81b606082015260800190565b6020808252601f908201527f5265656e7472616e637947756172643a207265656e7472616e742063616c6c00604082015260600190565b60005b83811015611aad578181015183820152602001611a95565b50506000910152565b60008151808452611ace816020860160208601611a92565b601f01601f19169290920160200192915050565b60018060a01b038616815284602082015283604082015260a060608201526000611b0f60a0830185611ab6565b8281036080840152611b218185611ab6565b98975050505050505050565b634e487b7160e01b600052601160045260246000fd5b8082018082111561047d5761047d611b2d565b600060208284031215611b6857600080fd5b8151801515811461145557600080fd5b8181038181111561047d5761047d611b2d565b60208082526021908201527f436172626f6e5061746841646d696e3a206d75737420626520616e2061646d696040820152603760f91b606082015260800190565b600060208284031215611bde57600080fd5b5051919050565b60208082526023908201527f436172626f6e5061746841646d696e3a206e6f7420656e6f7567682062616c616040820152626e636560e81b606082015260800190565b60208082526029908201527f436172626f6e5061746841646d696e3a2063616c6c6572206973206e6f74207460408201526834329039b2b63632b960b91b606082015260800190565b808202811582820484141761047d5761047d611b2d565b600082611ca557634e487b7160e01b600052601260045260246000fd5b500490565b7f416363657373436f6e74726f6c3a206163636f756e7420000000000000000000815260008351611ce2816017850160208801611a92565b7001034b99036b4b9b9b4b733903937b6329607d1b6017918401918201528351611d13816028840160208801611a92565b01602801949350505050565b6020815260006114556020830184611ab6565b634e487b7160e01b600052603260045260246000fd5b600081611d5757611d57611b2d565b50600019019056fea26469706673582212205ea3b6b452f7c2adef0a0a42e1263497d8e9aa2dc406123cb98cfa724c37bde564736f6c63430008110033