Source Code
Overview
POL Balance
More Info
ContractCreator
Multichain Info
N/A
Loading...
Loading
This contract may be a proxy contract. Click on More Options and select Is this a proxy? to confirm and enable the "Read as Proxy" & "Write as Proxy" tabs.
Similar Match Source Code This contract matches the deployed Bytecode of the Source Code for Contract 0xc94e5401...960fd3Db1 The constructor portion of the code might be different and could alter the actual behaviour of the contract
Contract Name:
Removal
Compiler Version
v0.8.17+commit.8df45f5f
Optimization Enabled:
Yes with 800 runs
Other Settings:
default evmVersion
Contract Source Code (Solidity Standard Json-Input format)
// SPDX-License-Identifier: MIT pragma solidity =0.8.17; import { ERC1155SupplyUpgradeable, ERC1155Upgradeable } from "@openzeppelin/contracts-upgradeable/token/ERC1155/extensions/ERC1155SupplyUpgradeable.sol"; import { MathUpgradeable } from "@openzeppelin/contracts-upgradeable/utils/math/MathUpgradeable.sol"; import { MulticallUpgradeable } from "@openzeppelin/contracts-upgradeable/utils/MulticallUpgradeable.sol"; import { EnumerableSetUpgradeable } from "@openzeppelin/contracts-upgradeable/utils/structs/EnumerableSetUpgradeable.sol"; import { AccessPresetPausable, AccessControlEnumerableUpgradeable } from "./AccessPresetPausable.sol"; import { RemovalNotYetMinted, RemovalAlreadySoldOrConsigned, ForbiddenTransfer, ForbiddenTransfer, ForbiddenTransfer, InvalidData } from "./Errors.sol"; import {IMarket} from "./IMarket.sol"; import {ICertificate} from "./ICertificate.sol"; import {IRemoval} from "./IRemoval.sol"; import {RemovalIdLib, DecodedRemovalIdV0} from "./RemovalIdLib.sol"; /** * @title An extended ERC1155 token contract for carbon removal accounting. * @author Nori Inc. * @notice This contract uses ERC1155 tokens as an accounting system for keeping track of carbon that Nori has * verified to have been removed from the atmosphere. Each token ID encodes information about the source of the * removed carbon (see the [RemovalIdLib docs](../docs/RemovalIdLib.md) for encoding details), and each token represents * the smallest unit of carbon removal accounting. For example, in an agricultural methodology, a specific token ID * represents one parcel of land in a specific year. The total supply of that token ID is the number of tonnes of * carbon removed. * * ##### Additional behaviors and features: * * ###### Minting * - Only accounts with the CONSIGNOR_ROLE can mint removal tokens, which should only be account(s) controlled by Nori. * - When removal tokens are minted, additional data about those removals are stored in a mapping keyed by the token ID, * such as a project ID. * - Minting reverts when attempting to mint a token ID that already exists. * - The function `addBalance` can be used to mint additional balance to a token ID that already exists. * * * ###### Listing * - _Listing_ refers to the process of listing removal tokens for sale in Nori's marketplace (the Market contract). * - Removals are listed for sale by transferring ownership of the tokens to the Market contract via * `consign`. Alternatively, If the `to` argument to `mintBatch` is the address of the Market contract, * removal tokens will be listed in the same transaction that they are minted. * - Only accounts with the CONSIGNOR_ROLE can list removals for sale in the market. * * * ###### Releasing * - _Releasing_ refers to the process of accounting for carbon that has failed to meet its permanence guarantee * and has been released into the atmosphere prematurely. * - This accounting is performed by burning the affected balance of a removal that has been released. * - Only accounts with the RELEASER_ROLE can initiate a release. * - When a removal token is released, balances are burned in a specific order until the released amount * has been accounted for: Releasing burns first from unlisted balances, second from listed balances and third from the * certificate contract (see `Removal.release` for more). * - Affected certificates will have any released balances replaced by new removals purchased by Nori, though an * automated implementation of this process is beyond the scope of this version of the contracts. * * * ###### Token ID encoding and decoding * - This contract uses the inlined library RemovalIdLib for uint256. * - When minting tokens, an array of structs containing information about each removal is passed as an argument to * `mintBatch` and that data is used to generate the encoded token IDs for each removal. * - `decodeRemovalIdV0` is exposed externally for encoding and decoding Removal token IDs that contain uniquely * identifying information about the removal. See the [RemovalIdLib docs](../docs/RemovalIdLib.md) for encoding details. * * ###### Additional behaviors and features * * - [ERC-1155 functionality](https://eips.ethereum.org/EIPS/eip-1155) * - [Upgradeable](https://docs.openzeppelin.com/contracts/4.x/upgradeable) * - [Initializable](https://docs.openzeppelin.com/contracts/4.x/upgradeable#multiple-inheritance) * - [Pausable](https://docs.openzeppelin.com/contracts/4.x/api/security#Pausable): all functions that mutate state are * pausable * - [Role-based access control](https://docs.openzeppelin.com/contracts/4.x/access-control) * - `CONSIGNOR_ROLE`: Can mint removal tokens and list them for sale in the Market contract. * - `RELEASER_ROLE`: Can release partial or full removal balances. * - `PAUSER_ROLE`: Can pause and unpause the contract. * - `DEFAULT_ADMIN_ROLE`: This is the only role that can add/revoke other accounts to any of the roles. * * ##### Inherits: * * - [ERC1155Upgradeable](https://docs.openzeppelin.com/contracts/4.x/api/token/erc11555) * - [ERC1155Supply](https://docs.openzeppelin.com/contracts/4.x/api/token/erc1155#ERC1155Supply) * - [MulticallUpgradeable](https://docs.openzeppelin.com/contracts/4.x/api/utils#Multicall) * - [PausableUpgradeable](https://docs.openzeppelin.com/contracts/4.x/api/security#Pausable) * - [AccessControlEnumerableUpgradeable](https://docs.openzeppelin.com/contracts/4.x/api/access) * - [ContextUpgradeable](https://docs.openzeppelin.com/upgrades-plugins/1.x/writing-upgradeable) * - [Initializable](https://docs.openzeppelin.com/contracts/4.x/api/proxy#Initializable) * - [ERC165Upgradeable](https://docs.openzeppelin.com/contracts/4.x/api/utils#ERC165) * * ##### Implements: * * - [IERC1155Upgradeable](https://docs.openzeppelin.com/contracts/4.x/api/token/erc1155#IERC1155) * - [IERC1155MetadataURI](https://docs.openzeppelin.com/contracts/4.x/api/token/erc1155#IERC1155MetadataURI) * - [IAccessControlEnumerable](https://docs.openzeppelin.com/contracts/4.x/api/access#AccessControlEnumerable) * - [IERC165Upgradeable](https://docs.openzeppelin.com/contracts/4.x/api/utils#IERC165) * * ##### Uses: * * - [MathUpgradeable](https://docs.openzeppelin.com/contracts/4.x/api/utils#Math) * - [EnumerableSetUpgradeable](https://docs.openzeppelin.com/contracts/4.x/api/utils#EnumerableSet) for * `EnumerableSetUpgradeable.UintSet` */ contract Removal is IRemoval, ERC1155SupplyUpgradeable, AccessPresetPausable, MulticallUpgradeable { using EnumerableSetUpgradeable for EnumerableSetUpgradeable.UintSet; /** * @notice Role conferring the ability to mint removals as well as the ability to list minted removals that have yet * to be listed for sale. */ bytes32 public constant CONSIGNOR_ROLE = keccak256("CONSIGNOR_ROLE"); /** * @notice Role conferring the ability to mark a removal as released. */ bytes32 public constant RELEASER_ROLE = keccak256("RELEASER_ROLE"); /** * @notice The Market contract that removals can be bought and sold from. */ IMarket internal _market; /** * @notice The Certificate contract that removals are retired into. */ ICertificate private _certificate; /** * @dev Deprecated. This storage gap remains to maintain the storage layout of the contract. */ mapping(uint256 => uint8) private _projectIdToHoldbackPercentage; /** * @dev Maps from a removal ID to the project ID it belongs to. */ mapping(uint256 => uint256) private _removalIdToProjectId; /** * @notice Maps from an address to an EnumerableSet of the token IDs for which that address has a non-zero balance. */ mapping(address => EnumerableSetUpgradeable.UintSet) private _addressToOwnedTokenIds; /** * @notice The current balance of across all removals listed in the market contract. */ uint256 private _currentMarketBalance; /** * @notice Emitted on updating the addresses for contracts. * @param market The address of the new market contract. * @param certificate The address of the new certificate contract. */ event RegisterContractAddresses(IMarket market, ICertificate certificate); /** * @notice Emitted on releasing a removal from a supplier, the market, or a certificate. * @param id The id of the removal that was released. * @param fromAddress The address the removal was released from. * @param amount The amount that was released. */ event ReleaseRemoval( uint256 indexed id, address indexed fromAddress, uint256 amount ); /** * @notice Emitted when legacy removals are minted and then immediately used to migrate a legacy certificate. * @param certificateRecipient The recipient of the certificate to mint via migration. * @param certificateAmount The total amount of the certificate to mint via migration (denominated in NRTs). * @param certificateId The ID of the certificate to mint via migration. * @param removalIds The removal IDs to use to mint the certificate via migration. * @param removalAmounts The amounts for each corresponding removal ID to use to mint the certificate via migration. */ event Migrate( address indexed certificateRecipient, uint256 indexed certificateAmount, uint256 indexed certificateId, uint256[] removalIds, uint256[] removalAmounts ); /** * @notice Emitted when removals are directly retired into a certificate by Nori. * @param certificateRecipient The recipient of the certificate. * @param certificateAmount The total amount of the certificate to mint (denominated in RTs). * @param certificateId The ID of the certificate being minted. * @param removalIds The removal IDs to use to mint the certificate. * @param removalAmounts The amounts to retire from each corresponding removal ID. */ event Retire( address indexed certificateRecipient, uint256 indexed certificateAmount, uint256 indexed certificateId, uint256[] removalIds, uint256[] removalAmounts ); /** * @notice Locks the contract, preventing any future re-initialization. * @dev See more [here](https://docs.openzeppelin.com/contracts/4.x/api/proxy#Initializable-_disableInitializers--). * @custom:oz-upgrades-unsafe-allow constructor */ constructor() { _disableInitializers(); } /** * @notice Initializes the Removal contract. * @param baseURI The base URI for the removal NFTs. */ function initialize(string memory baseURI) external initializer { __Context_init_unchained(); __ERC165_init_unchained(); __ERC1155_init_unchained({uri_: string(abi.encodePacked(baseURI, "{id}"))}); __Pausable_init_unchained(); __ERC1155Supply_init_unchained(); __AccessControl_init_unchained(); __AccessControlEnumerable_init_unchained(); __Multicall_init_unchained(); _grantRole({role: DEFAULT_ADMIN_ROLE, account: _msgSender()}); _grantRole({role: PAUSER_ROLE, account: _msgSender()}); _grantRole({role: CONSIGNOR_ROLE, account: _msgSender()}); _grantRole({role: RELEASER_ROLE, account: _msgSender()}); } /** * @notice Registers the market and certificate contracts so that they can be referenced in this contract. * Called as part of the market contract system deployment process. * @dev Emits a `RegisterContractAddresses` event. * * ##### Requirements: * * - Can only be used when the caller has the `DEFAULT_ADMIN_ROLE` role. * - Can only be used when this contract is not paused. * @param market The address of the Market contract. * @param certificate The address of the Certificate contract. */ function registerContractAddresses( IMarket market, ICertificate certificate ) external whenNotPaused onlyRole(DEFAULT_ADMIN_ROLE) { _market = market; _certificate = certificate; emit RegisterContractAddresses({market: market, certificate: certificate}); } /** * @notice Mints multiple removals at once (for a single supplier). * @dev If `to` is the market address, the removals are listed for sale in the market. * * ##### Requirements: * - Can only be used when the caller has the `CONSIGNOR_ROLE` * - Enforces the rules of `Removal._beforeTokenTransfer` * - Can only be used when this contract is not paused * - Cannot mint to a removal ID that already exists (use `addBalance` instead). * @param to The recipient of this batch of removals. Should be the supplier's address or the market address. * @param amounts Each removal's tonnes of CO2 formatted. * @param removals The removals to mint (represented as an array of `DecodedRemovalIdV0`). These removals are used * to encode the removal IDs. * @param projectId The project ID for this batch of removals. */ function mintBatch( address to, uint256[] calldata amounts, DecodedRemovalIdV0[] calldata removals, uint256 projectId ) external onlyRole(CONSIGNOR_ROLE) { uint256[] memory ids = _createRemovals({ removals: removals, projectId: projectId }); _mintBatch({to: to, ids: ids, amounts: amounts, data: ""}); } /** * @notice Mints additional balance for multiple removals at once. * @dev If `to` is the market address, the removals are listed for sale in the market. * * ##### Requirements: * - Can only be used when the caller has the `CONSIGNOR_ROLE` role. * - Can only be used when this contract is not paused. * - IDs must already have been minted via `mintBatch`. * - Enforces the rules of `Removal._beforeTokenTransfer`. * @param to The supplier address or market address. * @param amounts Each removal's additional tonnes of CO2 formatted. * @param ids The removal IDs to add balance for. */ function addBalance( address to, uint256[] calldata amounts, uint256[] calldata ids ) external onlyRole(CONSIGNOR_ROLE) { for (uint256 i = 0; i < ids.length; ++i) { if (_removalIdToProjectId[ids[i]] == 0) { revert RemovalNotYetMinted({tokenId: ids[i]}); } } _mintBatch({to: to, ids: ids, amounts: amounts, data: ""}); } /** * @notice Lists the provided `amount` of the specified removal `id` for sale in Nori's marketplace. * @dev The Market contract implements `onERC1155Received`, which is invoked upon receipt of any tokens from * this contract, and handles the mechanics of listing this token for sale. * @param from The current owner of the specified token ID and amount * @param id The token ID of the removal token being listed for sale * @param amount The balance of this token ID to transfer to the Market contract */ function consign( address from, uint256 id, uint256 amount ) external onlyRole(CONSIGNOR_ROLE) { if (from == address(_certificate) || from == address(_market)) { revert RemovalAlreadySoldOrConsigned({tokenId: id}); } _safeTransferFrom({ from: from, to: address(_market), id: id, amount: amount, data: "" }); } /** * @notice Transfers the provided `amounts` (denominated in NRTs) of the specified removal `ids` directly to the * Certificate contract to mint a certificate. This function provides Nori the ability to retire removals directly * into the Certificate contract and to specify exactly which removals will be retired. * @dev The Certificate contract implements `onERC1155BatchReceived`, which is invoked upon receipt of a batch of * removals (triggered via `_safeBatchTransferFrom`). This function circumvents the market contract by * transferring the removals from an account with the `CONSIGNOR_ROLE` role. * Emits a `Retire` event. * * It is necessary that the consignor holds the removals because of the following: * - `ids` can be composed of a list of removal IDs that belong to one or more suppliers. * - `_safeBatchTransferFrom` only accepts one `from` address. * - `Certificate.onERC1155BatchReceived` will mint a *new* certificate every time an additional batch is received, so * we must ensure that all the removals comprising the certificate come from a single batch. * * ##### Requirements: * - The caller must have the `CONSIGNOR_ROLE` role. * - The contract must not be paused. * - The specified removal IDs must exist (e.g., via a prior call to the `mintBatch` function). * - The rules of `Removal._beforeTokenTransfer` are enforced. * @param ids An array of the removal IDs to add to transfer to the Certificate contract. This array can contain IDs * of removals that belong to one or more supplier address (designated in the encoding of the removal ID). * @param amounts An array of the removal amounts to add to transfer to the Certificate contract. Each amount in this * array corresponds to the removal ID with the same index in the `ids` parameter. * @param certificateRecipient The recipient of the certificate to be minted. * @param certificateAmount The total amount of the certificate. */ function retire( uint256[] calldata ids, uint256[] calldata amounts, address certificateRecipient, uint256 certificateAmount ) external onlyRole(CONSIGNOR_ROLE) { emit Retire({ certificateRecipient: certificateRecipient, certificateAmount: certificateAmount, certificateId: _certificate.totalMinted(), removalIds: ids, removalAmounts: amounts }); _safeBatchTransferFrom({ from: _msgSender(), to: address(_certificate), ids: ids, amounts: amounts, data: abi.encode( false, certificateRecipient, certificateAmount, address(0), 0, 0 ) }); } /** * @notice Accounts for carbon that has failed to meet its permanence guarantee and has been released into * the atmosphere prematurely. * @dev Releases `amount` of removal `id` by burning it. The replacement of released removals that had * already been included in certificates is beyond the scope of this version of the contracts. * * ##### Requirements: * * - Releasing burns first from unlisted balances, second from listed balances and third from certificates. * - If there is unlisted balance for this removal (e.g., owned by the supplier address encoded in the token ID), * that balance is burned up to `amount`. * - If the released amount has not yet been fully burned and the removal is listed, it is delisted from the market * and up to any remaining released amount is burned from the Market's balance. * - Finally, if the released amount is still not fully accounted for, the removal must be owned by one or more * certificates. The remaining released amount is burned from the Certificate contract's balance. * - The caller must have the `RELEASER_ROLE`. * - The rules of `_burn` are enforced. * - Can only be used when the contract is not paused. * @param id The ID of the removal to release some amount of. * @param amount The amount of the removal to release. */ function release( uint256 id, uint256 amount ) external onlyRole(RELEASER_ROLE) { uint256 amountReleased = 0; uint256 unlistedBalance = balanceOf({ account: RemovalIdLib.supplierAddress({removalId: id}), id: id }); if (unlistedBalance > 0) { uint256 amountToRelease = MathUpgradeable.min({ a: amount, b: unlistedBalance }); _releaseFromSupplier({id: id, amount: amountToRelease}); amountReleased += amountToRelease; } if (amountReleased < amount) { uint256 listedBalance = balanceOf({ account: this.getMarketAddress(), id: id }); if (listedBalance > 0) { uint256 amountToRelease = MathUpgradeable.min({ a: amount - amountReleased, b: listedBalance }); _releaseFromMarket({amount: amountToRelease, id: id}); amountReleased += amountToRelease; } if (amountReleased < amount) { if (balanceOf({account: this.getCertificateAddress(), id: id}) > 0) { uint256 amountToRelease = amount - amountReleased; _releaseFromCertificate({id: id, amount: amount - amountReleased}); amountReleased += amountToRelease; } } } } /** * @notice Get the address of the Market contract. * @return The address of the Market contract. */ function getMarketAddress() external view returns (address) { return address(_market); } /** * @notice Get the address of the Certificate contract. * @return The address of the Certificate contract. */ function getCertificateAddress() external view returns (address) { return address(_certificate); } /** * @notice Get the project ID for a given removal ID. * @param id The removal token ID for which to retrieve the project ID. * @return The project ID for the removal token ID. */ function getProjectId(uint256 id) external view override returns (uint256) { return _removalIdToProjectId[id]; } /** * @notice The current total balance of all removal tokens owned by the Market contract. * This sum is maintained as a running total for efficient lookup during purchases. * @return The total balance of all removal tokens owned by the Market contract. */ function getMarketBalance() external view returns (uint256) { return _currentMarketBalance; } /** * @notice Returns an array of all token IDs currently owned by `owner`. * @param owner The account for which to retrieve owned token IDs. * @return An array of all Removal token IDs currently owned by `owner`. */ function getOwnedTokenIds( address owner ) external view returns (uint256[] memory) { return _addressToOwnedTokenIds[owner].values(); } /** * @notice The number of unique token IDs owned by the given `account`. * Maintained for efficient lookup of the number of distinct removal tokens owned by the Market. * @param account The account for which to retrieve the unique number of token IDs owned. * @return The number of unique Removal token IDs owned by the given `account`. */ function numberOfTokensOwnedByAddress( address account ) external view returns (uint256) { return _addressToOwnedTokenIds[account].length(); } /** * @notice Decodes a V0 removal ID into its component data. * @param id The removal ID to decode. * @return The decoded removal ID data. */ function decodeRemovalIdV0( uint256 id ) external pure returns (DecodedRemovalIdV0 memory) { return RemovalIdLib.decodeRemovalIdV0({removalId: id}); } /** * @notice Transfers `amount` tokens of token type `id` from `from` to `to`. * @dev Calls `ERC1155Upgradeable.safeTransferFrom` * * Emits a `TransferSingle` event. * * ##### Requirements: * * - Can only be called by the Market contract. * - `to` cannot be the zero address. * - If the caller is not `from`, it must have been approved to spend ``from``'s tokens via `setApprovalForAll`. * - `from` must have a balance of tokens of type `id` of at least `amount`. * - If `to` refers to a smart contract, it must implement `IERC1155Receiver.onERC1155Received` and return the * acceptance magic value. * @param from The address to transfer from. * @param to The address to transfer to. * @param id The removal ID to transfer. * @param amount The amount of removals to transfer. * @param data The data to pass to the receiver contract. */ function safeTransferFrom( address from, address to, uint256 id, uint256 amount, bytes memory data ) public override { if (_msgSender() != address(_market)) { revert ForbiddenTransfer(); } super.safeTransferFrom({ from: from, to: to, id: id, amount: amount, data: data }); } /** * @notice Batched version of `safeTransferFrom`. * @dev Emits a `TransferBatch` event. * * ##### Requirements: * * - Can only be called by the Market contract. * - `ids` and `amounts` must have the same length. * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the * acceptance magic value. * @param from The address to transfer from. * @param to The address to transfer to. * @param ids The removal IDs to transfer. * @param amounts The amounts of removals to transfer. * @param data The data to pass to the receiver contract. */ function safeBatchTransferFrom( address from, address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data ) public override { if (_msgSender() != address(_market)) { revert ForbiddenTransfer(); } super.safeBatchTransferFrom({ from: from, to: to, ids: ids, amounts: amounts, data: data }); } /** * @notice Allows an address with the `CONSIGNOR_ROLE` to transfer tokens. * @dev Emits a `TransferBatch` event. * * ##### Requirements: * * - Can only be called by an address with the `CONSIGNOR_ROLE`. * - Respects the rules of `Removal._beforeTokenTransfer`. * - `ids` and `amounts` must have the same length. * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the * acceptance magic value. * @param from The address to transfer from. * @param to The address to transfer to. * @param ids The removal IDs to transfer. * @param amounts The amounts of removals to transfer. */ function consignorBatchTransfer( address from, address to, uint256[] memory ids, uint256[] memory amounts ) public onlyRole(CONSIGNOR_ROLE) { super._safeBatchTransferFrom({ from: from, to: to, ids: ids, amounts: amounts, data: "" }); } /** * @notice Grants or revokes permission to `operator` to transfer the caller's tokens, according to `approved`. * @dev Emits an `ApprovalForAll` event. * * ##### Requirements: * - Can only be used when the contract is not paused. * - `operator` cannot be the caller. * @param operator The address to grant or revoke approval from. * @param approved Whether or not the `operator` is approved to transfer the caller's tokens. */ function setApprovalForAll( address operator, bool approved ) public override whenNotPaused { _setApprovalForAll({ owner: _msgSender(), operator: operator, approved: approved }); } /** * @notice Returns true if this contract implements the interface defined by * `interfaceId`. * @dev See the corresponding [EIP section](https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified) to * learn more about how these ids are created. * See [IERC165.supportsInterface]( * https://docs.openzeppelin.com/contracts/4.x/api/utils#IERC165-supportsInterface-bytes4-) for more. * This function call must use less than 30,000 gas. * @param interfaceId A bytes4 value which represents an interface ID. * @return True if this contract implements the interface defined by `interfaceId`, otherwise false. */ function supportsInterface( bytes4 interfaceId ) public view override(ERC1155Upgradeable, AccessControlEnumerableUpgradeable) returns (bool) { return super.supportsInterface({interfaceId: interfaceId}); } /** * @notice Called during `mintBatch`, creates the removal IDs from the removal data, validates * the new IDs to prevent minting a pre-existing ID, stores the project ID in a mapping. * @param removals An array of `DecodedRemovalIdV0` structs containing data about each removal. * @param projectId The project IDentifier for this batch of removals. * @return An array of removal IDs that were created. */ function _createRemovals( DecodedRemovalIdV0[] calldata removals, uint256 projectId ) internal returns (uint256[] memory) { uint256[] memory ids = new uint256[](removals.length); // Skip overflow check as for loop is indexed starting at zero. unchecked { for (uint256 i = 0; i < removals.length; ++i) { uint256 id = RemovalIdLib.createRemovalId({removal: removals[i]}); _createRemoval({id: id, projectId: projectId}); ids[i] = id; } } return ids; } /** * @notice Called by `_createRemovals`, validates the new IDs to prevent minting a pre-existing ID, * stores the project ID in a mapping. * @param id The removal ID being minted. * @param projectId The project ID for this removal. */ function _createRemoval(uint256 id, uint256 projectId) internal { _validateRemoval({id: id}); _removalIdToProjectId[id] = projectId; } /** * @notice Burns `amount` of token ID `id` from the supplier address encoded in the ID. * @dev Emits a `ReleaseRemoval` event. * @param id The token ID to burn. * @param amount The amount to burn. */ function _releaseFromSupplier(uint256 id, uint256 amount) internal { address supplierAddress = RemovalIdLib.supplierAddress({removalId: id}); super._burn({from: supplierAddress, id: id, amount: amount}); emit ReleaseRemoval({id: id, fromAddress: supplierAddress, amount: amount}); } /** * @notice Burns `amount` of token ID `id` from the Market's balance. * @dev Emits a `ReleaseRemoval` event. * @param id The token ID to burn. * @param amount The amount to burn. */ function _releaseFromMarket(uint256 id, uint256 amount) internal { super._burn({from: this.getMarketAddress(), id: id, amount: amount}); _market.release({removalId: id}); emit ReleaseRemoval({ id: id, fromAddress: this.getMarketAddress(), amount: amount }); } /** * @notice Burns `amount` of token ID `id` from the Certificate's balance. * @dev Emits a `ReleaseRemoval` event. * @param id The removal ID to burn. * @param amount The amount to burn. */ function _releaseFromCertificate(uint256 id, uint256 amount) internal { address certificateAddress_ = this.getCertificateAddress(); super._burn({from: certificateAddress_, id: id, amount: amount}); _certificate.incrementNrtDeficit({amount: amount}); emit ReleaseRemoval({ id: id, fromAddress: certificateAddress_, amount: amount }); } /** * @notice Hook that is called before any token transfer. This includes minting and burning, as well as * batched variants. Disables transfers to any address that is not the Market or Certificate contracts, the zero * address (for burning), the supplier address that is encoded in the token ID itself, or between consignors. * @dev Follows the rules of hooks defined [here]( * https://docs.openzeppelin.com/contracts/4.x/extending-contracts#rules_of_hooks) * * ##### Requirements: * * - The contract must not be paused. * - Enforces the rules of `ERC1155Upgradeable._beforeTokenTransfer`. * - Enforces the rules of `ERC1155SupplyUpgradeable._beforeTokenTransfer`. * @param operator The address to transfer from. * @param from The address to transfer from. * @param to The address to transfer to. * @param ids The removal IDs to transfer. * @param amounts The amounts of removals to transfer. * @param data The data to pass to the receiver contract. */ function _beforeTokenTransfer( address operator, address from, address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data ) internal virtual override whenNotPaused { address market = address(_market); address certificate = address(_certificate); bool isValidTransfer = to == market || to == certificate || to == address(0) || (hasRole({role: CONSIGNOR_ROLE, account: _msgSender()}) && (to == certificate || hasRole({role: CONSIGNOR_ROLE, account: to}))); uint256 countOfRemovals = ids.length; for (uint256 i = 0; i < countOfRemovals; ++i) { uint256 id = ids[i]; uint256 amount = amounts[i]; if (!_isValidTransferAmount({amount: amount, to: to})) { revert ForbiddenTransfer(); } if (to == market) { _currentMarketBalance += amount; } if (from == market) { _currentMarketBalance -= amount; } if ( !isValidTransfer && to != RemovalIdLib.supplierAddress({removalId: id}) ) { revert ForbiddenTransfer(); } } super._beforeTokenTransfer({ operator: operator, from: from, to: to, ids: ids, amounts: amounts, data: data }); } /** * @notice Hook that is called after any token transfer. This includes minting and burning, as well as batched * variants. * @dev Updates the mapping from address to set of owned token IDs. * * The same hook is called on both single and batched variants. For single transfers, the length of the `id` and * `amount` arrays will be 1. * * ##### Requirements * * - When `from` and `to` are both non-zero, `amount`s of `from`'s tokens with IDs `id`s will be transferred to `to`. * - When `from` is zero, `amount`s tokens of token type `id` will be minted for `to`. * - When `to` is zero, `amount`s of `from`'s tokens with IDs `id`s will be burned. * - `from` and `to` are never both zero. * - `ids` and `amounts` have the same, non-zero length. * @param operator The address to transfer from. * @param from The address to transfer from. * @param to The address to transfer to. * @param ids The removal IDs to transfer. * @param amounts The amounts of removals to transfer. * @param data The data to pass to the receiver contract. */ function _afterTokenTransfer( address operator, address from, address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data ) internal virtual override { _updateOwnedTokenIds({from: from, to: to, ids: ids}); super._afterTokenTransfer({ operator: operator, from: from, to: to, ids: ids, amounts: amounts, data: data }); } /** * @notice Updates the mapping from address to set of owned token IDs. * @dev Called during `_afterTokenTransfer`. * @param from The address from which tokens were transferred. * @param to The address to which tokens were transferred. * @param ids The token IDs that were transferred. */ function _updateOwnedTokenIds( address from, address to, uint256[] memory ids ) internal { EnumerableSetUpgradeable.UintSet storage receiversOwnedRemovalIds = _addressToOwnedTokenIds[to]; EnumerableSetUpgradeable.UintSet storage sendersOwnedRemovalIds = _addressToOwnedTokenIds[from]; uint256 countOfRemovals = ids.length; // Skip overflow check as for loop is indexed starting at zero. unchecked { for (uint256 i = 0; i < countOfRemovals; ++i) { uint256 id = ids[i]; if (from != address(0)) { if (balanceOf({account: from, id: id}) == 0) { sendersOwnedRemovalIds.remove({value: id}); } } if (to != address(0)) { receiversOwnedRemovalIds.add({value: id}); } } } } /** * @notice Validates that the provided `id` should be minted. * @dev Reverts if a project ID has already been set for `id`. * @param id The ID to validate. */ function _validateRemoval(uint256 id) internal view { if (_removalIdToProjectId[id] != 0) { revert InvalidData(); } } /** * @notice Check if the amount and recipient constitute a valid transfer. * @dev Ensure that the amount of tokens in circulation always multiples of 1e14. * * ##### Examples: * - `_isValidTransferAmount({amount: 1e14, to: address(1)}) == true` * - `_isValidTransferAmount({amount: 0, to: address(1)}) == true` * - `_isValidTransferAmount({amount: 0, to: address(_certificate)}) == false` * - `_isValidTransferAmount({amount: 1, to: address(1)}) == false` * - `_isValidTransferAmount({amount: 1e14 - 1, to: address(_market)}) == false` * * ##### Requirements: * * - If the recipient is the Market or the Certificate, the amount must be divisible by 1e14 (100,000,000,000,000) * and non-zero. * - If the recipient is neither the Market nor the Certificate the amount may also be zero. */ function _isValidTransferAmount( uint256 amount, address to ) internal view returns (bool) { return to == address(_market) || to == address(_certificate) ? amount > 0 && amount % 1e14 == 0 : amount % 1e14 == 0; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.5.0) (access/AccessControlEnumerable.sol) pragma solidity ^0.8.0; import "./IAccessControlEnumerableUpgradeable.sol"; import "./AccessControlUpgradeable.sol"; import "../utils/structs/EnumerableSetUpgradeable.sol"; import "../proxy/utils/Initializable.sol"; /** * @dev Extension of {AccessControl} that allows enumerating the members of each role. */ abstract contract AccessControlEnumerableUpgradeable is Initializable, IAccessControlEnumerableUpgradeable, AccessControlUpgradeable { function __AccessControlEnumerable_init() internal onlyInitializing { } function __AccessControlEnumerable_init_unchained() internal onlyInitializing { } using EnumerableSetUpgradeable for EnumerableSetUpgradeable.AddressSet; mapping(bytes32 => EnumerableSetUpgradeable.AddressSet) private _roleMembers; /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IAccessControlEnumerableUpgradeable).interfaceId || super.supportsInterface(interfaceId); } /** * @dev Returns one of the accounts that have `role`. `index` must be a * value between 0 and {getRoleMemberCount}, non-inclusive. * * Role bearers are not sorted in any particular way, and their ordering may * change at any point. * * WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure * you perform all queries on the same block. See the following * https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post] * for more information. */ function getRoleMember(bytes32 role, uint256 index) public view virtual override returns (address) { return _roleMembers[role].at(index); } /** * @dev Returns the number of accounts that have `role`. Can be used * together with {getRoleMember} to enumerate all bearers of a role. */ function getRoleMemberCount(bytes32 role) public view virtual override returns (uint256) { return _roleMembers[role].length(); } /** * @dev Overload {_grantRole} to track enumerable memberships */ function _grantRole(bytes32 role, address account) internal virtual override { super._grantRole(role, account); _roleMembers[role].add(account); } /** * @dev Overload {_revokeRole} to track enumerable memberships */ function _revokeRole(bytes32 role, address account) internal virtual override { super._revokeRole(role, account); _roleMembers[role].remove(account); } /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[49] private __gap; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (access/AccessControl.sol) pragma solidity ^0.8.0; import "./IAccessControlUpgradeable.sol"; import "../utils/ContextUpgradeable.sol"; import "../utils/StringsUpgradeable.sol"; import "../utils/introspection/ERC165Upgradeable.sol"; import "../proxy/utils/Initializable.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 AccessControlUpgradeable is Initializable, ContextUpgradeable, IAccessControlUpgradeable, ERC165Upgradeable { function __AccessControl_init() internal onlyInitializing { } function __AccessControl_init_unchained() internal onlyInitializing { } 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(IAccessControlUpgradeable).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 ", StringsUpgradeable.toHexString(account), " is missing role ", StringsUpgradeable.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()); } } /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[49] private __gap; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (access/IAccessControlEnumerable.sol) pragma solidity ^0.8.0; import "./IAccessControlUpgradeable.sol"; /** * @dev External interface of AccessControlEnumerable declared to support ERC165 detection. */ interface IAccessControlEnumerableUpgradeable is IAccessControlUpgradeable { /** * @dev Returns one of the accounts that have `role`. `index` must be a * value between 0 and {getRoleMemberCount}, non-inclusive. * * Role bearers are not sorted in any particular way, and their ordering may * change at any point. * * WARNING: When using {getRoleMember} and {getRoleMemberCount}, make sure * you perform all queries on the same block. See the following * https://forum.openzeppelin.com/t/iterating-over-elements-on-enumerableset-in-openzeppelin-contracts/2296[forum post] * for more information. */ function getRoleMember(bytes32 role, uint256 index) external view returns (address); /** * @dev Returns the number of accounts that have `role`. Can be used * together with {getRoleMember} to enumerate all bearers of a role. */ function getRoleMemberCount(bytes32 role) external view returns (uint256); }
// 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 IAccessControlUpgradeable { /** * @dev Emitted when `newAdminRole` is set as ``role``'s admin role, replacing `previousAdminRole` * * `DEFAULT_ADMIN_ROLE` is the starting admin for all roles, despite * {RoleAdminChanged} not being emitted signaling this. * * _Available since v3.1._ */ event RoleAdminChanged(bytes32 indexed role, bytes32 indexed previousAdminRole, bytes32 indexed newAdminRole); /** * @dev Emitted when `account` is granted `role`. * * `sender` is the account that originated the contract call, an admin role * bearer except when using {AccessControl-_setupRole}. */ event RoleGranted(bytes32 indexed role, address indexed account, address indexed sender); /** * @dev Emitted when `account` is revoked `role`. * * `sender` is the account that originated the contract call: * - if using `revokeRole`, it is the admin role bearer * - if using `renounceRole`, it is the role bearer (i.e. `account`) */ event RoleRevoked(bytes32 indexed role, address indexed account, address indexed sender); /** * @dev Returns `true` if `account` has been granted `role`. */ function hasRole(bytes32 role, address account) external view returns (bool); /** * @dev Returns the admin role that controls `role`. See {grantRole} and * {revokeRole}. * * To change a role's admin, use {AccessControl-_setRoleAdmin}. */ function getRoleAdmin(bytes32 role) external view returns (bytes32); /** * @dev Grants `role` to `account`. * * If `account` had not been already granted `role`, emits a {RoleGranted} * event. * * Requirements: * * - the caller must have ``role``'s admin role. */ function grantRole(bytes32 role, address account) external; /** * @dev Revokes `role` from `account`. * * If `account` had been granted `role`, emits a {RoleRevoked} event. * * Requirements: * * - the caller must have ``role``'s admin role. */ function revokeRole(bytes32 role, address account) external; /** * @dev Revokes `role` from the calling account. * * Roles are often managed via {grantRole} and {revokeRole}: this function's * purpose is to provide a mechanism for accounts to lose their privileges * if they are compromised (such as when a trusted device is misplaced). * * If the calling account had been granted `role`, emits a {RoleRevoked} * event. * * Requirements: * * - the caller must be `account`. */ function renounceRole(bytes32 role, address account) external; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.1) (proxy/utils/Initializable.sol) pragma solidity ^0.8.2; import "../../utils/AddressUpgradeable.sol"; /** * @dev This is a base contract to aid in writing upgradeable contracts, or any kind of contract that will be deployed * behind a proxy. Since proxied contracts do not make use of a constructor, it's common to move constructor logic to an * external initializer function, usually called `initialize`. It then becomes necessary to protect this initializer * function so it can only be called once. The {initializer} modifier provided by this contract will have this effect. * * The initialization functions use a version number. Once a version number is used, it is consumed and cannot be * reused. This mechanism prevents re-execution of each "step" but allows the creation of new initialization steps in * case an upgrade adds a module that needs to be initialized. * * For example: * * [.hljs-theme-light.nopadding] * ``` * contract MyToken is ERC20Upgradeable { * function initialize() initializer public { * __ERC20_init("MyToken", "MTK"); * } * } * contract MyTokenV2 is MyToken, ERC20PermitUpgradeable { * function initializeV2() reinitializer(2) public { * __ERC20Permit_init("MyToken"); * } * } * ``` * * TIP: To avoid leaving the proxy in an uninitialized state, the initializer function should be called as early as * possible by providing the encoded function call as the `_data` argument to {ERC1967Proxy-constructor}. * * CAUTION: When used with inheritance, manual care must be taken to not invoke a parent initializer twice, or to ensure * that all initializers are idempotent. This is not verified automatically as constructors are by Solidity. * * [CAUTION] * ==== * Avoid leaving a contract uninitialized. * * An uninitialized contract can be taken over by an attacker. This applies to both a proxy and its implementation * contract, which may impact the proxy. To prevent the implementation contract from being used, you should invoke * the {_disableInitializers} function in the constructor to automatically lock it when it is deployed: * * [.hljs-theme-light.nopadding] * ``` * /// @custom:oz-upgrades-unsafe-allow constructor * constructor() { * _disableInitializers(); * } * ``` * ==== */ abstract contract Initializable { /** * @dev Indicates that the contract has been initialized. * @custom:oz-retyped-from bool */ uint8 private _initialized; /** * @dev Indicates that the contract is in the process of being initialized. */ bool private _initializing; /** * @dev Triggered when the contract has been initialized or reinitialized. */ event Initialized(uint8 version); /** * @dev A modifier that defines a protected initializer function that can be invoked at most once. In its scope, * `onlyInitializing` functions can be used to initialize parent contracts. * * Similar to `reinitializer(1)`, except that functions marked with `initializer` can be nested in the context of a * constructor. * * Emits an {Initialized} event. */ modifier initializer() { bool isTopLevelCall = !_initializing; require( (isTopLevelCall && _initialized < 1) || (!AddressUpgradeable.isContract(address(this)) && _initialized == 1), "Initializable: contract is already initialized" ); _initialized = 1; if (isTopLevelCall) { _initializing = true; } _; if (isTopLevelCall) { _initializing = false; emit Initialized(1); } } /** * @dev A modifier that defines a protected reinitializer function that can be invoked at most once, and only if the * contract hasn't been initialized to a greater version before. In its scope, `onlyInitializing` functions can be * used to initialize parent contracts. * * A reinitializer may be used after the original initialization step. This is essential to configure modules that * are added through upgrades and that require initialization. * * When `version` is 1, this modifier is similar to `initializer`, except that functions marked with `reinitializer` * cannot be nested. If one is invoked in the context of another, execution will revert. * * Note that versions can jump in increments greater than 1; this implies that if multiple reinitializers coexist in * a contract, executing them in the right order is up to the developer or operator. * * WARNING: setting the version to 255 will prevent any future reinitialization. * * Emits an {Initialized} event. */ modifier reinitializer(uint8 version) { require(!_initializing && _initialized < version, "Initializable: contract is already initialized"); _initialized = version; _initializing = true; _; _initializing = false; emit Initialized(version); } /** * @dev Modifier to protect an initialization function so that it can only be invoked by functions with the * {initializer} and {reinitializer} modifiers, directly or indirectly. */ modifier onlyInitializing() { require(_initializing, "Initializable: contract is not initializing"); _; } /** * @dev Locks the contract, preventing any future reinitialization. This cannot be part of an initializer call. * Calling this in the constructor of a contract will prevent that contract from being initialized or reinitialized * to any version. It is recommended to use this to lock implementation contracts that are designed to be called * through proxies. * * Emits an {Initialized} event the first time it is successfully executed. */ function _disableInitializers() internal virtual { require(!_initializing, "Initializable: contract is initializing"); if (_initialized < type(uint8).max) { _initialized = type(uint8).max; emit Initialized(type(uint8).max); } } /** * @dev Returns the highest version that has been initialized. See {reinitializer}. */ function _getInitializedVersion() internal view returns (uint8) { return _initialized; } /** * @dev Returns `true` if the contract is currently initializing. See {onlyInitializing}. */ function _isInitializing() internal view returns (bool) { return _initializing; } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (security/Pausable.sol) pragma solidity ^0.8.0; import "../utils/ContextUpgradeable.sol"; import "../proxy/utils/Initializable.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 PausableUpgradeable is Initializable, ContextUpgradeable { /** * @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. */ function __Pausable_init() internal onlyInitializing { __Pausable_init_unchained(); } function __Pausable_init_unchained() internal onlyInitializing { _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()); } /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[49] private __gap; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (token/ERC1155/ERC1155.sol) pragma solidity ^0.8.0; import "./IERC1155Upgradeable.sol"; import "./IERC1155ReceiverUpgradeable.sol"; import "./extensions/IERC1155MetadataURIUpgradeable.sol"; import "../../utils/AddressUpgradeable.sol"; import "../../utils/ContextUpgradeable.sol"; import "../../utils/introspection/ERC165Upgradeable.sol"; import "../../proxy/utils/Initializable.sol"; /** * @dev Implementation of the basic standard multi-token. * See https://eips.ethereum.org/EIPS/eip-1155 * Originally based on code by Enjin: https://github.com/enjin/erc-1155 * * _Available since v3.1._ */ contract ERC1155Upgradeable is Initializable, ContextUpgradeable, ERC165Upgradeable, IERC1155Upgradeable, IERC1155MetadataURIUpgradeable { using AddressUpgradeable for address; // Mapping from token ID to account balances mapping(uint256 => mapping(address => uint256)) private _balances; // Mapping from account to operator approvals mapping(address => mapping(address => bool)) private _operatorApprovals; // Used as the URI for all token types by relying on ID substitution, e.g. https://token-cdn-domain/{id}.json string private _uri; /** * @dev See {_setURI}. */ function __ERC1155_init(string memory uri_) internal onlyInitializing { __ERC1155_init_unchained(uri_); } function __ERC1155_init_unchained(string memory uri_) internal onlyInitializing { _setURI(uri_); } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override(ERC165Upgradeable, IERC165Upgradeable) returns (bool) { return interfaceId == type(IERC1155Upgradeable).interfaceId || interfaceId == type(IERC1155MetadataURIUpgradeable).interfaceId || super.supportsInterface(interfaceId); } /** * @dev See {IERC1155MetadataURI-uri}. * * This implementation returns the same URI for *all* token types. It relies * on the token type ID substitution mechanism * https://eips.ethereum.org/EIPS/eip-1155#metadata[defined in the EIP]. * * Clients calling this function must replace the `\{id\}` substring with the * actual token type ID. */ function uri(uint256) public view virtual override returns (string memory) { return _uri; } /** * @dev See {IERC1155-balanceOf}. * * Requirements: * * - `account` cannot be the zero address. */ function balanceOf(address account, uint256 id) public view virtual override returns (uint256) { require(account != address(0), "ERC1155: address zero is not a valid owner"); return _balances[id][account]; } /** * @dev See {IERC1155-balanceOfBatch}. * * Requirements: * * - `accounts` and `ids` must have the same length. */ function balanceOfBatch(address[] memory accounts, uint256[] memory ids) public view virtual override returns (uint256[] memory) { require(accounts.length == ids.length, "ERC1155: accounts and ids length mismatch"); uint256[] memory batchBalances = new uint256[](accounts.length); for (uint256 i = 0; i < accounts.length; ++i) { batchBalances[i] = balanceOf(accounts[i], ids[i]); } return batchBalances; } /** * @dev See {IERC1155-setApprovalForAll}. */ function setApprovalForAll(address operator, bool approved) public virtual override { _setApprovalForAll(_msgSender(), operator, approved); } /** * @dev See {IERC1155-isApprovedForAll}. */ function isApprovedForAll(address account, address operator) public view virtual override returns (bool) { return _operatorApprovals[account][operator]; } /** * @dev See {IERC1155-safeTransferFrom}. */ function safeTransferFrom( address from, address to, uint256 id, uint256 amount, bytes memory data ) public virtual override { require( from == _msgSender() || isApprovedForAll(from, _msgSender()), "ERC1155: caller is not token owner or approved" ); _safeTransferFrom(from, to, id, amount, data); } /** * @dev See {IERC1155-safeBatchTransferFrom}. */ function safeBatchTransferFrom( address from, address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data ) public virtual override { require( from == _msgSender() || isApprovedForAll(from, _msgSender()), "ERC1155: caller is not token owner or approved" ); _safeBatchTransferFrom(from, to, ids, amounts, data); } /** * @dev Transfers `amount` tokens of token type `id` from `from` to `to`. * * Emits a {TransferSingle} event. * * Requirements: * * - `to` cannot be the zero address. * - `from` must have a balance of tokens of type `id` of at least `amount`. * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the * acceptance magic value. */ function _safeTransferFrom( address from, address to, uint256 id, uint256 amount, bytes memory data ) internal virtual { require(to != address(0), "ERC1155: transfer to the zero address"); address operator = _msgSender(); uint256[] memory ids = _asSingletonArray(id); uint256[] memory amounts = _asSingletonArray(amount); _beforeTokenTransfer(operator, from, to, ids, amounts, data); uint256 fromBalance = _balances[id][from]; require(fromBalance >= amount, "ERC1155: insufficient balance for transfer"); unchecked { _balances[id][from] = fromBalance - amount; } _balances[id][to] += amount; emit TransferSingle(operator, from, to, id, amount); _afterTokenTransfer(operator, from, to, ids, amounts, data); _doSafeTransferAcceptanceCheck(operator, from, to, id, amount, data); } /** * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {_safeTransferFrom}. * * Emits a {TransferBatch} event. * * Requirements: * * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the * acceptance magic value. */ function _safeBatchTransferFrom( address from, address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data ) internal virtual { require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch"); require(to != address(0), "ERC1155: transfer to the zero address"); address operator = _msgSender(); _beforeTokenTransfer(operator, from, to, ids, amounts, data); for (uint256 i = 0; i < ids.length; ++i) { uint256 id = ids[i]; uint256 amount = amounts[i]; uint256 fromBalance = _balances[id][from]; require(fromBalance >= amount, "ERC1155: insufficient balance for transfer"); unchecked { _balances[id][from] = fromBalance - amount; } _balances[id][to] += amount; } emit TransferBatch(operator, from, to, ids, amounts); _afterTokenTransfer(operator, from, to, ids, amounts, data); _doSafeBatchTransferAcceptanceCheck(operator, from, to, ids, amounts, data); } /** * @dev Sets a new URI for all token types, by relying on the token type ID * substitution mechanism * https://eips.ethereum.org/EIPS/eip-1155#metadata[defined in the EIP]. * * By this mechanism, any occurrence of the `\{id\}` substring in either the * URI or any of the amounts in the JSON file at said URI will be replaced by * clients with the token type ID. * * For example, the `https://token-cdn-domain/\{id\}.json` URI would be * interpreted by clients as * `https://token-cdn-domain/000000000000000000000000000000000000000000000000000000000004cce0.json` * for token type ID 0x4cce0. * * See {uri}. * * Because these URIs cannot be meaningfully represented by the {URI} event, * this function emits no events. */ function _setURI(string memory newuri) internal virtual { _uri = newuri; } /** * @dev Creates `amount` tokens of token type `id`, and assigns them to `to`. * * Emits a {TransferSingle} event. * * Requirements: * * - `to` cannot be the zero address. * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the * acceptance magic value. */ function _mint( address to, uint256 id, uint256 amount, bytes memory data ) internal virtual { require(to != address(0), "ERC1155: mint to the zero address"); address operator = _msgSender(); uint256[] memory ids = _asSingletonArray(id); uint256[] memory amounts = _asSingletonArray(amount); _beforeTokenTransfer(operator, address(0), to, ids, amounts, data); _balances[id][to] += amount; emit TransferSingle(operator, address(0), to, id, amount); _afterTokenTransfer(operator, address(0), to, ids, amounts, data); _doSafeTransferAcceptanceCheck(operator, address(0), to, id, amount, data); } /** * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {_mint}. * * Emits a {TransferBatch} event. * * Requirements: * * - `ids` and `amounts` must have the same length. * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the * acceptance magic value. */ function _mintBatch( address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data ) internal virtual { require(to != address(0), "ERC1155: mint to the zero address"); require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch"); address operator = _msgSender(); _beforeTokenTransfer(operator, address(0), to, ids, amounts, data); for (uint256 i = 0; i < ids.length; i++) { _balances[ids[i]][to] += amounts[i]; } emit TransferBatch(operator, address(0), to, ids, amounts); _afterTokenTransfer(operator, address(0), to, ids, amounts, data); _doSafeBatchTransferAcceptanceCheck(operator, address(0), to, ids, amounts, data); } /** * @dev Destroys `amount` tokens of token type `id` from `from` * * Emits a {TransferSingle} event. * * Requirements: * * - `from` cannot be the zero address. * - `from` must have at least `amount` tokens of token type `id`. */ function _burn( address from, uint256 id, uint256 amount ) internal virtual { require(from != address(0), "ERC1155: burn from the zero address"); address operator = _msgSender(); uint256[] memory ids = _asSingletonArray(id); uint256[] memory amounts = _asSingletonArray(amount); _beforeTokenTransfer(operator, from, address(0), ids, amounts, ""); uint256 fromBalance = _balances[id][from]; require(fromBalance >= amount, "ERC1155: burn amount exceeds balance"); unchecked { _balances[id][from] = fromBalance - amount; } emit TransferSingle(operator, from, address(0), id, amount); _afterTokenTransfer(operator, from, address(0), ids, amounts, ""); } /** * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {_burn}. * * Emits a {TransferBatch} event. * * Requirements: * * - `ids` and `amounts` must have the same length. */ function _burnBatch( address from, uint256[] memory ids, uint256[] memory amounts ) internal virtual { require(from != address(0), "ERC1155: burn from the zero address"); require(ids.length == amounts.length, "ERC1155: ids and amounts length mismatch"); address operator = _msgSender(); _beforeTokenTransfer(operator, from, address(0), ids, amounts, ""); for (uint256 i = 0; i < ids.length; i++) { uint256 id = ids[i]; uint256 amount = amounts[i]; uint256 fromBalance = _balances[id][from]; require(fromBalance >= amount, "ERC1155: burn amount exceeds balance"); unchecked { _balances[id][from] = fromBalance - amount; } } emit TransferBatch(operator, from, address(0), ids, amounts); _afterTokenTransfer(operator, from, address(0), ids, amounts, ""); } /** * @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, "ERC1155: setting approval status for self"); _operatorApprovals[owner][operator] = approved; emit ApprovalForAll(owner, operator, approved); } /** * @dev Hook that is called before any token transfer. This includes minting * and burning, as well as batched variants. * * The same hook is called on both single and batched variants. For single * transfers, the length of the `ids` and `amounts` arrays will be 1. * * Calling conditions (for each `id` and `amount` pair): * * - When `from` and `to` are both non-zero, `amount` of ``from``'s tokens * of token type `id` will be transferred to `to`. * - When `from` is zero, `amount` tokens of token type `id` will be minted * for `to`. * - when `to` is zero, `amount` of ``from``'s tokens of token type `id` * will be burned. * - `from` and `to` are never both zero. * - `ids` and `amounts` have the same, non-zero length. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _beforeTokenTransfer( address operator, address from, address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data ) internal virtual {} /** * @dev Hook that is called after any token transfer. This includes minting * and burning, as well as batched variants. * * The same hook is called on both single and batched variants. For single * transfers, the length of the `id` and `amount` arrays will be 1. * * Calling conditions (for each `id` and `amount` pair): * * - When `from` and `to` are both non-zero, `amount` of ``from``'s tokens * of token type `id` will be transferred to `to`. * - When `from` is zero, `amount` tokens of token type `id` will be minted * for `to`. * - when `to` is zero, `amount` of ``from``'s tokens of token type `id` * will be burned. * - `from` and `to` are never both zero. * - `ids` and `amounts` have the same, non-zero length. * * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. */ function _afterTokenTransfer( address operator, address from, address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data ) internal virtual {} function _doSafeTransferAcceptanceCheck( address operator, address from, address to, uint256 id, uint256 amount, bytes memory data ) private { if (to.isContract()) { try IERC1155ReceiverUpgradeable(to).onERC1155Received(operator, from, id, amount, data) returns (bytes4 response) { if (response != IERC1155ReceiverUpgradeable.onERC1155Received.selector) { revert("ERC1155: ERC1155Receiver rejected tokens"); } } catch Error(string memory reason) { revert(reason); } catch { revert("ERC1155: transfer to non-ERC1155Receiver implementer"); } } } function _doSafeBatchTransferAcceptanceCheck( address operator, address from, address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data ) private { if (to.isContract()) { try IERC1155ReceiverUpgradeable(to).onERC1155BatchReceived(operator, from, ids, amounts, data) returns ( bytes4 response ) { if (response != IERC1155ReceiverUpgradeable.onERC1155BatchReceived.selector) { revert("ERC1155: ERC1155Receiver rejected tokens"); } } catch Error(string memory reason) { revert(reason); } catch { revert("ERC1155: transfer to non-ERC1155Receiver implementer"); } } } function _asSingletonArray(uint256 element) private pure returns (uint256[] memory) { uint256[] memory array = new uint256[](1); array[0] = element; return array; } /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[47] private __gap; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.6.0) (token/ERC1155/extensions/ERC1155Supply.sol) pragma solidity ^0.8.0; import "../ERC1155Upgradeable.sol"; import "../../../proxy/utils/Initializable.sol"; /** * @dev Extension of ERC1155 that adds tracking of total supply per id. * * Useful for scenarios where Fungible and Non-fungible tokens have to be * clearly identified. Note: While a totalSupply of 1 might mean the * corresponding is an NFT, there is no guarantees that no other token with the * same id are not going to be minted. */ abstract contract ERC1155SupplyUpgradeable is Initializable, ERC1155Upgradeable { function __ERC1155Supply_init() internal onlyInitializing { } function __ERC1155Supply_init_unchained() internal onlyInitializing { } mapping(uint256 => uint256) private _totalSupply; /** * @dev Total amount of tokens in with a given id. */ function totalSupply(uint256 id) public view virtual returns (uint256) { return _totalSupply[id]; } /** * @dev Indicates whether any token exist with a given id, or not. */ function exists(uint256 id) public view virtual returns (bool) { return ERC1155SupplyUpgradeable.totalSupply(id) > 0; } /** * @dev See {ERC1155-_beforeTokenTransfer}. */ function _beforeTokenTransfer( address operator, address from, address to, uint256[] memory ids, uint256[] memory amounts, bytes memory data ) internal virtual override { super._beforeTokenTransfer(operator, from, to, ids, amounts, data); if (from == address(0)) { for (uint256 i = 0; i < ids.length; ++i) { _totalSupply[ids[i]] += amounts[i]; } } if (to == address(0)) { for (uint256 i = 0; i < ids.length; ++i) { uint256 id = ids[i]; uint256 amount = amounts[i]; uint256 supply = _totalSupply[id]; require(supply >= amount, "ERC1155: burn amount exceeds totalSupply"); unchecked { _totalSupply[id] = supply - amount; } } } } /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[49] private __gap; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (token/ERC1155/extensions/IERC1155MetadataURI.sol) pragma solidity ^0.8.0; import "../IERC1155Upgradeable.sol"; /** * @dev Interface of the optional ERC1155MetadataExtension interface, as defined * in the https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[EIP]. * * _Available since v3.1._ */ interface IERC1155MetadataURIUpgradeable is IERC1155Upgradeable { /** * @dev Returns the URI for token type `id`. * * If the `\{id\}` substring is present in the URI, it must be replaced by * clients with the actual token type ID. */ function uri(uint256 id) external view returns (string memory); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.5.0) (token/ERC1155/IERC1155Receiver.sol) pragma solidity ^0.8.0; import "../../utils/introspection/IERC165Upgradeable.sol"; /** * @dev _Available since v3.1._ */ interface IERC1155ReceiverUpgradeable is IERC165Upgradeable { /** * @dev Handles the receipt of a single ERC1155 token type. This function is * called at the end of a `safeTransferFrom` after the balance has been updated. * * NOTE: To accept the transfer, this must return * `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))` * (i.e. 0xf23a6e61, or its own function selector). * * @param operator The address which initiated the transfer (i.e. msg.sender) * @param from The address which previously owned the token * @param id The ID of the token being transferred * @param value The amount of tokens being transferred * @param data Additional data with no specified format * @return `bytes4(keccak256("onERC1155Received(address,address,uint256,uint256,bytes)"))` if transfer is allowed */ function onERC1155Received( address operator, address from, uint256 id, uint256 value, bytes calldata data ) external returns (bytes4); /** * @dev Handles the receipt of a multiple ERC1155 token types. This function * is called at the end of a `safeBatchTransferFrom` after the balances have * been updated. * * NOTE: To accept the transfer(s), this must return * `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))` * (i.e. 0xbc197c81, or its own function selector). * * @param operator The address which initiated the batch transfer (i.e. msg.sender) * @param from The address which previously owned the token * @param ids An array containing ids of each token being transferred (order and length must match values array) * @param values An array containing amounts of each token being transferred (order and length must match ids array) * @param data Additional data with no specified format * @return `bytes4(keccak256("onERC1155BatchReceived(address,address,uint256[],uint256[],bytes)"))` if transfer is allowed */ function onERC1155BatchReceived( address operator, address from, uint256[] calldata ids, uint256[] calldata values, bytes calldata data ) external returns (bytes4); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.7.0) (token/ERC1155/IERC1155.sol) pragma solidity ^0.8.0; import "../../utils/introspection/IERC165Upgradeable.sol"; /** * @dev Required interface of an ERC1155 compliant contract, as defined in the * https://eips.ethereum.org/EIPS/eip-1155[EIP]. * * _Available since v3.1._ */ interface IERC1155Upgradeable is IERC165Upgradeable { /** * @dev Emitted when `value` tokens of token type `id` are transferred from `from` to `to` by `operator`. */ event TransferSingle(address indexed operator, address indexed from, address indexed to, uint256 id, uint256 value); /** * @dev Equivalent to multiple {TransferSingle} events, where `operator`, `from` and `to` are the same for all * transfers. */ event TransferBatch( address indexed operator, address indexed from, address indexed to, uint256[] ids, uint256[] values ); /** * @dev Emitted when `account` grants or revokes permission to `operator` to transfer their tokens, according to * `approved`. */ event ApprovalForAll(address indexed account, address indexed operator, bool approved); /** * @dev Emitted when the URI for token type `id` changes to `value`, if it is a non-programmatic URI. * * If an {URI} event was emitted for `id`, the standard * https://eips.ethereum.org/EIPS/eip-1155#metadata-extensions[guarantees] that `value` will equal the value * returned by {IERC1155MetadataURI-uri}. */ event URI(string value, uint256 indexed id); /** * @dev Returns the amount of tokens of token type `id` owned by `account`. * * Requirements: * * - `account` cannot be the zero address. */ function balanceOf(address account, uint256 id) external view returns (uint256); /** * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {balanceOf}. * * Requirements: * * - `accounts` and `ids` must have the same length. */ function balanceOfBatch(address[] calldata accounts, uint256[] calldata ids) external view returns (uint256[] memory); /** * @dev Grants or revokes permission to `operator` to transfer the caller's tokens, according to `approved`, * * Emits an {ApprovalForAll} event. * * Requirements: * * - `operator` cannot be the caller. */ function setApprovalForAll(address operator, bool approved) external; /** * @dev Returns true if `operator` is approved to transfer ``account``'s tokens. * * See {setApprovalForAll}. */ function isApprovedForAll(address account, address operator) external view returns (bool); /** * @dev Transfers `amount` tokens of token type `id` from `from` to `to`. * * Emits a {TransferSingle} event. * * Requirements: * * - `to` cannot be the zero address. * - If the caller is not `from`, it must have been approved to spend ``from``'s tokens via {setApprovalForAll}. * - `from` must have a balance of tokens of type `id` of at least `amount`. * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155Received} and return the * acceptance magic value. */ function safeTransferFrom( address from, address to, uint256 id, uint256 amount, bytes calldata data ) external; /** * @dev xref:ROOT:erc1155.adoc#batch-operations[Batched] version of {safeTransferFrom}. * * Emits a {TransferBatch} event. * * Requirements: * * - `ids` and `amounts` must have the same length. * - If `to` refers to a smart contract, it must implement {IERC1155Receiver-onERC1155BatchReceived} and return the * acceptance magic value. */ function safeBatchTransferFrom( address from, address to, uint256[] calldata ids, uint256[] calldata amounts, bytes calldata data ) external; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (utils/Address.sol) pragma solidity ^0.8.1; /** * @dev Collection of functions related to the address type */ library AddressUpgradeable { /** * @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 functionCallWithValue(target, data, 0, "Address: low-level call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], but with * `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCall( address target, bytes memory data, string memory errorMessage ) internal returns (bytes memory) { return functionCallWithValue(target, data, 0, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but also transferring `value` wei to `target`. * * Requirements: * * - the calling contract must have an ETH balance of at least `value`. * - the called Solidity function must be `payable`. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value ) internal returns (bytes memory) { return functionCallWithValue(target, data, value, "Address: low-level call with value failed"); } /** * @dev Same as {xref-Address-functionCallWithValue-address-bytes-uint256-}[`functionCallWithValue`], but * with `errorMessage` as a fallback revert reason when `target` reverts. * * _Available since v3.1._ */ function functionCallWithValue( address target, bytes memory data, uint256 value, string memory errorMessage ) internal returns (bytes memory) { require(address(this).balance >= value, "Address: insufficient balance for call"); (bool success, bytes memory returndata) = target.call{value: value}(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Same as {xref-Address-functionCall-address-bytes-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall(address target, bytes memory data) internal view returns (bytes memory) { return functionStaticCall(target, data, "Address: low-level static call failed"); } /** * @dev Same as {xref-Address-functionCall-address-bytes-string-}[`functionCall`], * but performing a static call. * * _Available since v3.3._ */ function functionStaticCall( address target, bytes memory data, string memory errorMessage ) internal view returns (bytes memory) { (bool success, bytes memory returndata) = target.staticcall(data); return verifyCallResultFromTarget(target, success, returndata, errorMessage); } /** * @dev Tool to verify that a low level call to smart-contract was successful, and revert (either by bubbling * the revert reason or using the provided one) in case of unsuccessful call or if target was not a contract. * * _Available since v4.8._ */ function verifyCallResultFromTarget( address target, bool success, bytes memory returndata, string memory errorMessage ) internal view returns (bytes memory) { if (success) { if (returndata.length == 0) { // only check isContract if the call was successful and the return data is empty // otherwise we already know that it was a contract require(isContract(target), "Address: call to non-contract"); } return returndata; } else { _revert(returndata, errorMessage); } } /** * @dev Tool to verify that a low level call was successful, and revert if it wasn't, either by bubbling the * revert reason or using the provided one. * * _Available since v4.3._ */ function verifyCallResult( bool success, bytes memory returndata, string memory errorMessage ) internal pure returns (bytes memory) { if (success) { return returndata; } else { _revert(returndata, errorMessage); } } function _revert(bytes memory returndata, string memory errorMessage) private pure { // Look for revert reason and bubble it up if present if (returndata.length > 0) { // The easiest way to bubble the revert reason is using memory via assembly /// @solidity memory-safe-assembly assembly { let returndata_size := mload(returndata) revert(add(32, returndata), returndata_size) } } else { revert(errorMessage); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/Context.sol) pragma solidity ^0.8.0; import "../proxy/utils/Initializable.sol"; /** * @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 ContextUpgradeable is Initializable { function __Context_init() internal onlyInitializing { } function __Context_init_unchained() internal onlyInitializing { } function _msgSender() internal view virtual returns (address) { return msg.sender; } function _msgData() internal view virtual returns (bytes calldata) { return msg.data; } /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[50] private __gap; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts v4.4.1 (utils/introspection/ERC165.sol) pragma solidity ^0.8.0; import "./IERC165Upgradeable.sol"; import "../../proxy/utils/Initializable.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 ERC165Upgradeable is Initializable, IERC165Upgradeable { function __ERC165_init() internal onlyInitializing { } function __ERC165_init_unchained() internal onlyInitializing { } /** * @dev See {IERC165-supportsInterface}. */ function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) { return interfaceId == type(IERC165Upgradeable).interfaceId; } /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[50] private __gap; }
// 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 IERC165Upgradeable { /** * @dev Returns true if this contract implements the interface defined by * `interfaceId`. See the corresponding * https://eips.ethereum.org/EIPS/eip-165#how-interfaces-are-identified[EIP section] * to learn more about how these ids are created. * * This function call must use less than 30 000 gas. */ function supportsInterface(bytes4 interfaceId) external view returns (bool); }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (utils/math/Math.sol) pragma solidity ^0.8.0; /** * @dev Standard math utilities missing in the Solidity language. */ library MathUpgradeable { enum Rounding { Down, // Toward negative infinity Up, // Toward infinity Zero // Toward zero } /** * @dev Returns the largest of two numbers. */ function max(uint256 a, uint256 b) internal pure returns (uint256) { return a > b ? a : b; } /** * @dev Returns the smallest of two numbers. */ function min(uint256 a, uint256 b) internal pure returns (uint256) { return a < b ? a : b; } /** * @dev Returns the average of two numbers. The result is rounded towards * zero. */ function average(uint256 a, uint256 b) internal pure returns (uint256) { // (a + b) / 2 can overflow. return (a & b) + (a ^ b) / 2; } /** * @dev Returns the ceiling of the division of two numbers. * * This differs from standard division with `/` in that it rounds up instead * of rounding down. */ function ceilDiv(uint256 a, uint256 b) internal pure returns (uint256) { // (a + b - 1) / b can overflow on addition, so we distribute. return a == 0 ? 0 : (a - 1) / b + 1; } /** * @notice Calculates floor(x * y / denominator) with full precision. Throws if result overflows a uint256 or denominator == 0 * @dev Original credit to Remco Bloemen under MIT license (https://xn--2-umb.com/21/muldiv) * with further edits by Uniswap Labs also under MIT license. */ function mulDiv( uint256 x, uint256 y, uint256 denominator ) internal pure returns (uint256 result) { unchecked { // 512-bit multiply [prod1 prod0] = x * y. Compute the product mod 2^256 and mod 2^256 - 1, then use // use the Chinese Remainder Theorem to reconstruct the 512 bit result. The result is stored in two 256 // variables such that product = prod1 * 2^256 + prod0. uint256 prod0; // Least significant 256 bits of the product uint256 prod1; // Most significant 256 bits of the product assembly { let mm := mulmod(x, y, not(0)) prod0 := mul(x, y) prod1 := sub(sub(mm, prod0), lt(mm, prod0)) } // Handle non-overflow cases, 256 by 256 division. if (prod1 == 0) { return prod0 / denominator; } // Make sure the result is less than 2^256. Also prevents denominator == 0. require(denominator > prod1); /////////////////////////////////////////////// // 512 by 256 division. /////////////////////////////////////////////// // Make division exact by subtracting the remainder from [prod1 prod0]. uint256 remainder; assembly { // Compute remainder using mulmod. remainder := mulmod(x, y, denominator) // Subtract 256 bit number from 512 bit number. prod1 := sub(prod1, gt(remainder, prod0)) prod0 := sub(prod0, remainder) } // Factor powers of two out of denominator and compute largest power of two divisor of denominator. Always >= 1. // See https://cs.stackexchange.com/q/138556/92363. // Does not overflow because the denominator cannot be zero at this stage in the function. uint256 twos = denominator & (~denominator + 1); assembly { // Divide denominator by twos. denominator := div(denominator, twos) // Divide [prod1 prod0] by twos. prod0 := div(prod0, twos) // Flip twos such that it is 2^256 / twos. If twos is zero, then it becomes one. twos := add(div(sub(0, twos), twos), 1) } // Shift in bits from prod1 into prod0. prod0 |= prod1 * twos; // Invert denominator mod 2^256. Now that denominator is an odd number, it has an inverse modulo 2^256 such // that denominator * inv = 1 mod 2^256. Compute the inverse by starting with a seed that is correct for // four bits. That is, denominator * inv = 1 mod 2^4. uint256 inverse = (3 * denominator) ^ 2; // Use the Newton-Raphson iteration to improve the precision. Thanks to Hensel's lifting lemma, this also works // in modular arithmetic, doubling the correct bits in each step. inverse *= 2 - denominator * inverse; // inverse mod 2^8 inverse *= 2 - denominator * inverse; // inverse mod 2^16 inverse *= 2 - denominator * inverse; // inverse mod 2^32 inverse *= 2 - denominator * inverse; // inverse mod 2^64 inverse *= 2 - denominator * inverse; // inverse mod 2^128 inverse *= 2 - denominator * inverse; // inverse mod 2^256 // Because the division is now exact we can divide by multiplying with the modular inverse of denominator. // This will give us the correct result modulo 2^256. Since the preconditions guarantee that the outcome is // less than 2^256, this is the final result. We don't need to compute the high bits of the result and prod1 // is no longer required. result = prod0 * inverse; return result; } } /** * @notice Calculates x * y / denominator with full precision, following the selected rounding direction. */ function mulDiv( uint256 x, uint256 y, uint256 denominator, Rounding rounding ) internal pure returns (uint256) { uint256 result = mulDiv(x, y, denominator); if (rounding == Rounding.Up && mulmod(x, y, denominator) > 0) { result += 1; } return result; } /** * @dev Returns the square root of a number. If the number is not a perfect square, the value is rounded down. * * Inspired by Henry S. Warren, Jr.'s "Hacker's Delight" (Chapter 11). */ function sqrt(uint256 a) internal pure returns (uint256) { if (a == 0) { return 0; } // For our first guess, we get the biggest power of 2 which is smaller than the square root of the target. // // We know that the "msb" (most significant bit) of our target number `a` is a power of 2 such that we have // `msb(a) <= a < 2*msb(a)`. This value can be written `msb(a)=2**k` with `k=log2(a)`. // // This can be rewritten `2**log2(a) <= a < 2**(log2(a) + 1)` // → `sqrt(2**k) <= sqrt(a) < sqrt(2**(k+1))` // → `2**(k/2) <= sqrt(a) < 2**((k+1)/2) <= 2**(k/2 + 1)` // // Consequently, `2**(log2(a) / 2)` is a good first approximation of `sqrt(a)` with at least 1 correct bit. uint256 result = 1 << (log2(a) >> 1); // At this point `result` is an estimation with one bit of precision. We know the true value is a uint128, // since it is the square root of a uint256. Newton's method converges quadratically (precision doubles at // every iteration). We thus need at most 7 iteration to turn our partial result with one bit of precision // into the expected uint128 result. unchecked { result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; result = (result + a / result) >> 1; return min(result, a / result); } } /** * @notice Calculates sqrt(a), following the selected rounding direction. */ function sqrt(uint256 a, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = sqrt(a); return result + (rounding == Rounding.Up && result * result < a ? 1 : 0); } } /** * @dev Return the log in base 2, rounded down, of a positive value. * Returns 0 if given 0. */ function log2(uint256 value) internal pure returns (uint256) { uint256 result = 0; unchecked { if (value >> 128 > 0) { value >>= 128; result += 128; } if (value >> 64 > 0) { value >>= 64; result += 64; } if (value >> 32 > 0) { value >>= 32; result += 32; } if (value >> 16 > 0) { value >>= 16; result += 16; } if (value >> 8 > 0) { value >>= 8; result += 8; } if (value >> 4 > 0) { value >>= 4; result += 4; } if (value >> 2 > 0) { value >>= 2; result += 2; } if (value >> 1 > 0) { result += 1; } } return result; } /** * @dev Return the log in base 2, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log2(uint256 value, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = log2(value); return result + (rounding == Rounding.Up && 1 << result < value ? 1 : 0); } } /** * @dev Return the log in base 10, rounded down, of a positive value. * Returns 0 if given 0. */ function log10(uint256 value) internal pure returns (uint256) { uint256 result = 0; unchecked { if (value >= 10**64) { value /= 10**64; result += 64; } if (value >= 10**32) { value /= 10**32; result += 32; } if (value >= 10**16) { value /= 10**16; result += 16; } if (value >= 10**8) { value /= 10**8; result += 8; } if (value >= 10**4) { value /= 10**4; result += 4; } if (value >= 10**2) { value /= 10**2; result += 2; } if (value >= 10**1) { result += 1; } } return result; } /** * @dev Return the log in base 10, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log10(uint256 value, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = log10(value); return result + (rounding == Rounding.Up && 10**result < value ? 1 : 0); } } /** * @dev Return the log in base 256, rounded down, of a positive value. * Returns 0 if given 0. * * Adding one to the result gives the number of pairs of hex symbols needed to represent `value` as a hex string. */ function log256(uint256 value) internal pure returns (uint256) { uint256 result = 0; unchecked { if (value >> 128 > 0) { value >>= 128; result += 16; } if (value >> 64 > 0) { value >>= 64; result += 8; } if (value >> 32 > 0) { value >>= 32; result += 4; } if (value >> 16 > 0) { value >>= 16; result += 2; } if (value >> 8 > 0) { result += 1; } } return result; } /** * @dev Return the log in base 10, following the selected rounding direction, of a positive value. * Returns 0 if given 0. */ function log256(uint256 value, Rounding rounding) internal pure returns (uint256) { unchecked { uint256 result = log256(value); return result + (rounding == Rounding.Up && 1 << (result * 8) < value ? 1 : 0); } } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.5.0) (utils/Multicall.sol) pragma solidity ^0.8.0; import "./AddressUpgradeable.sol"; import "../proxy/utils/Initializable.sol"; /** * @dev Provides a function to batch together multiple calls in a single external call. * * _Available since v4.1._ */ abstract contract MulticallUpgradeable is Initializable { function __Multicall_init() internal onlyInitializing { } function __Multicall_init_unchained() internal onlyInitializing { } /** * @dev Receives and executes a batch of function calls on this contract. */ function multicall(bytes[] calldata data) external virtual returns (bytes[] memory results) { results = new bytes[](data.length); for (uint256 i = 0; i < data.length; i++) { results[i] = _functionDelegateCall(address(this), data[i]); } return results; } /** * @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) private returns (bytes memory) { require(AddressUpgradeable.isContract(target), "Address: delegate call to non-contract"); // solhint-disable-next-line avoid-low-level-calls (bool success, bytes memory returndata) = target.delegatecall(data); return AddressUpgradeable.verifyCallResult(success, returndata, "Address: low-level delegate call failed"); } /** * @dev This empty reserved space is put in place to allow future versions to add new * variables without shifting down storage in the inheritance chain. * See https://docs.openzeppelin.com/contracts/4.x/upgradeable#storage_gaps */ uint256[50] private __gap; }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (utils/Strings.sol) pragma solidity ^0.8.0; import "./math/MathUpgradeable.sol"; /** * @dev String operations. */ library StringsUpgradeable { bytes16 private constant _SYMBOLS = "0123456789abcdef"; uint8 private constant _ADDRESS_LENGTH = 20; /** * @dev Converts a `uint256` to its ASCII `string` decimal representation. */ function toString(uint256 value) internal pure returns (string memory) { unchecked { uint256 length = MathUpgradeable.log10(value) + 1; string memory buffer = new string(length); uint256 ptr; /// @solidity memory-safe-assembly assembly { ptr := add(buffer, add(32, length)) } while (true) { ptr--; /// @solidity memory-safe-assembly assembly { mstore8(ptr, byte(mod(value, 10), _SYMBOLS)) } value /= 10; if (value == 0) break; } return buffer; } } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation. */ function toHexString(uint256 value) internal pure returns (string memory) { unchecked { return toHexString(value, MathUpgradeable.log256(value) + 1); } } /** * @dev Converts a `uint256` to its ASCII `string` hexadecimal representation with fixed length. */ function toHexString(uint256 value, uint256 length) internal pure returns (string memory) { bytes memory buffer = new bytes(2 * length + 2); buffer[0] = "0"; buffer[1] = "x"; for (uint256 i = 2 * length + 1; i > 1; --i) { buffer[i] = _SYMBOLS[value & 0xf]; value >>= 4; } require(value == 0, "Strings: hex length insufficient"); return string(buffer); } /** * @dev Converts an `address` with fixed length of 20 bytes to its not checksummed ASCII `string` hexadecimal representation. */ function toHexString(address addr) internal pure returns (string memory) { return toHexString(uint256(uint160(addr)), _ADDRESS_LENGTH); } }
// SPDX-License-Identifier: MIT // OpenZeppelin Contracts (last updated v4.8.0) (utils/structs/EnumerableSet.sol) // This file was procedurally generated from scripts/generate/templates/EnumerableSet.js. pragma solidity ^0.8.0; /** * @dev Library for managing * https://en.wikipedia.org/wiki/Set_(abstract_data_type)[sets] of primitive * types. * * Sets have the following properties: * * - Elements are added, removed, and checked for existence in constant time * (O(1)). * - Elements are enumerated in O(n). No guarantees are made on the ordering. * * ``` * contract Example { * // Add the library methods * using EnumerableSet for EnumerableSet.AddressSet; * * // Declare a set state variable * EnumerableSet.AddressSet private mySet; * } * ``` * * As of v3.3.0, sets of type `bytes32` (`Bytes32Set`), `address` (`AddressSet`) * and `uint256` (`UintSet`) are supported. * * [WARNING] * ==== * Trying to delete such a structure from storage will likely result in data corruption, rendering the structure * unusable. * See https://github.com/ethereum/solidity/pull/11843[ethereum/solidity#11843] for more info. * * In order to clean an EnumerableSet, you can either remove all elements one by one or create a fresh instance using an * array of EnumerableSet. * ==== */ library EnumerableSetUpgradeable { // To implement this library for multiple types with as little code // repetition as possible, we write it in terms of a generic Set type with // bytes32 values. // The Set implementation uses private functions, and user-facing // implementations (such as AddressSet) are just wrappers around the // underlying Set. // This means that we can only create new EnumerableSets for types that fit // in bytes32. struct Set { // Storage of set values bytes32[] _values; // Position of the value in the `values` array, plus 1 because index 0 // means a value is not in the set. mapping(bytes32 => uint256) _indexes; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function _add(Set storage set, bytes32 value) private returns (bool) { if (!_contains(set, value)) { set._values.push(value); // The value is stored at length-1, but we add 1 to all indexes // and use 0 as a sentinel value set._indexes[value] = set._values.length; return true; } else { return false; } } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function _remove(Set storage set, bytes32 value) private returns (bool) { // We read and store the value's index to prevent multiple reads from the same storage slot uint256 valueIndex = set._indexes[value]; if (valueIndex != 0) { // Equivalent to contains(set, value) // To delete an element from the _values array in O(1), we swap the element to delete with the last one in // the array, and then remove the last element (sometimes called as 'swap and pop'). // This modifies the order of the array, as noted in {at}. uint256 toDeleteIndex = valueIndex - 1; uint256 lastIndex = set._values.length - 1; if (lastIndex != toDeleteIndex) { bytes32 lastValue = set._values[lastIndex]; // Move the last value to the index where the value to delete is set._values[toDeleteIndex] = lastValue; // Update the index for the moved value set._indexes[lastValue] = valueIndex; // Replace lastValue's index to valueIndex } // Delete the slot where the moved value was stored set._values.pop(); // Delete the index for the deleted slot delete set._indexes[value]; return true; } else { return false; } } /** * @dev Returns true if the value is in the set. O(1). */ function _contains(Set storage set, bytes32 value) private view returns (bool) { return set._indexes[value] != 0; } /** * @dev Returns the number of values on the set. O(1). */ function _length(Set storage set) private view returns (uint256) { return set._values.length; } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function _at(Set storage set, uint256 index) private view returns (bytes32) { return set._values[index]; } /** * @dev Return the entire set in an array * * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that * this function has an unbounded cost, and using it as part of a state-changing function may render the function * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. */ function _values(Set storage set) private view returns (bytes32[] memory) { return set._values; } // Bytes32Set struct Bytes32Set { Set _inner; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function add(Bytes32Set storage set, bytes32 value) internal returns (bool) { return _add(set._inner, value); } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function remove(Bytes32Set storage set, bytes32 value) internal returns (bool) { return _remove(set._inner, value); } /** * @dev Returns true if the value is in the set. O(1). */ function contains(Bytes32Set storage set, bytes32 value) internal view returns (bool) { return _contains(set._inner, value); } /** * @dev Returns the number of values in the set. O(1). */ function length(Bytes32Set storage set) internal view returns (uint256) { return _length(set._inner); } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function at(Bytes32Set storage set, uint256 index) internal view returns (bytes32) { return _at(set._inner, index); } /** * @dev Return the entire set in an array * * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that * this function has an unbounded cost, and using it as part of a state-changing function may render the function * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. */ function values(Bytes32Set storage set) internal view returns (bytes32[] memory) { bytes32[] memory store = _values(set._inner); bytes32[] memory result; /// @solidity memory-safe-assembly assembly { result := store } return result; } // AddressSet struct AddressSet { Set _inner; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function add(AddressSet storage set, address value) internal returns (bool) { return _add(set._inner, bytes32(uint256(uint160(value)))); } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function remove(AddressSet storage set, address value) internal returns (bool) { return _remove(set._inner, bytes32(uint256(uint160(value)))); } /** * @dev Returns true if the value is in the set. O(1). */ function contains(AddressSet storage set, address value) internal view returns (bool) { return _contains(set._inner, bytes32(uint256(uint160(value)))); } /** * @dev Returns the number of values in the set. O(1). */ function length(AddressSet storage set) internal view returns (uint256) { return _length(set._inner); } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function at(AddressSet storage set, uint256 index) internal view returns (address) { return address(uint160(uint256(_at(set._inner, index)))); } /** * @dev Return the entire set in an array * * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that * this function has an unbounded cost, and using it as part of a state-changing function may render the function * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. */ function values(AddressSet storage set) internal view returns (address[] memory) { bytes32[] memory store = _values(set._inner); address[] memory result; /// @solidity memory-safe-assembly assembly { result := store } return result; } // UintSet struct UintSet { Set _inner; } /** * @dev Add a value to a set. O(1). * * Returns true if the value was added to the set, that is if it was not * already present. */ function add(UintSet storage set, uint256 value) internal returns (bool) { return _add(set._inner, bytes32(value)); } /** * @dev Removes a value from a set. O(1). * * Returns true if the value was removed from the set, that is if it was * present. */ function remove(UintSet storage set, uint256 value) internal returns (bool) { return _remove(set._inner, bytes32(value)); } /** * @dev Returns true if the value is in the set. O(1). */ function contains(UintSet storage set, uint256 value) internal view returns (bool) { return _contains(set._inner, bytes32(value)); } /** * @dev Returns the number of values in the set. O(1). */ function length(UintSet storage set) internal view returns (uint256) { return _length(set._inner); } /** * @dev Returns the value stored at position `index` in the set. O(1). * * Note that there are no guarantees on the ordering of values inside the * array, and it may change when more values are added or removed. * * Requirements: * * - `index` must be strictly less than {length}. */ function at(UintSet storage set, uint256 index) internal view returns (uint256) { return uint256(_at(set._inner, index)); } /** * @dev Return the entire set in an array * * WARNING: This operation will copy the entire storage to memory, which can be quite expensive. This is designed * to mostly be used by view accessors that are queried without any gas fees. Developers should keep in mind that * this function has an unbounded cost, and using it as part of a state-changing function may render the function * uncallable if the set grows to a point where copying to memory consumes too much gas to fit in a block. */ function values(UintSet storage set) internal view returns (uint256[] memory) { bytes32[] memory store = _values(set._inner); uint256[] memory result; /// @solidity memory-safe-assembly assembly { result := store } return result; } }
// SPDX-License-Identifier: MIT pragma solidity =0.8.17; import "@openzeppelin/contracts-upgradeable/security/PausableUpgradeable.sol"; import "@openzeppelin/contracts-upgradeable/access/AccessControlEnumerableUpgradeable.sol"; /** * @title A preset contract that enables pausable access control. * @author Nori Inc. * @notice This preset contract affords an inheriting contract a set of standard functionality that allows role-based * access control and pausable functions. * @dev This contract is inherited by most of the other contracts in this project. * * ##### Inherits: * * - [PausableUpgradeable](https://docs.openzeppelin.com/contracts/4.x/api/security#Pausable) * - [AccessControlEnumerableUpgradeable]( * https://docs.openzeppelin.com/contracts/4.x/api/access#AccessControlEnumerable) */ abstract contract AccessPresetPausable is PausableUpgradeable, AccessControlEnumerableUpgradeable { /** * @notice Role conferring pausing and unpausing of this contract. */ bytes32 public constant PAUSER_ROLE = keccak256("PAUSER_ROLE"); /** * @notice Pauses all functions that can mutate state. * @dev Used to effectively freeze a contract so that no state updates can occur. * * ##### Requirements: * * - The caller must have the `PAUSER_ROLE` role. */ function pause() external onlyRole(PAUSER_ROLE) { _pause(); } /** * @notice Unpauses all token transfers. * @dev Re-enables functionality that was paused by `pause`. * * ##### Requirements: * * - The caller must have the `PAUSER_ROLE` role. */ function unpause() external onlyRole(PAUSER_ROLE) { _unpause(); } /** * @notice Grants a role to an account. * @dev This function allows the role's admin to grant the role to other accounts. * * ##### Requirements: * * - The contract must not be paused. * @param role The role to grant. * @param account The account to grant the role to. */ function _grantRole(bytes32 role, address account) internal virtual override whenNotPaused { super._grantRole({role: role, account: account}); } /** * @notice Revokes a role from an account. * @dev This function allows the role's admin to revoke the role from other accounts. * ##### Requirements: * * - The contract must not be paused. * @param role The role to revoke. * @param account The account to revoke the role from. */ function _revokeRole(bytes32 role, address account) internal virtual override whenNotPaused { super._revokeRole({role: role, account: account}); } }
// SPDX-License-Identifier: MIT pragma solidity =0.8.17; /** * @notice Thrown when two arrays are not of equal length. * @param array1Name The name of the first array variable. * @param array2Name The name of the second array variable. */ error ArrayLengthMismatch(string array1Name, string array2Name); /** * @notice Thrown when an unsupported function is called. */ error FunctionDisabled(); /** * @notice Thrown when a function that can only be called by the Removal contract is called by any address other than * the Removal contract. */ error SenderNotRemovalContract(); /** * @notice Thrown when a function that can only be called by the Market contract is called by any address other than * the Market contract. */ error SenderNotMarketContract(); /** * @notice Thrown when a non-existent rNORI schedule is requested. * @param scheduleId The schedule ID that does not exist. */ error NonexistentSchedule(uint256 scheduleId); /** * @notice Thrown when an rNORI schedule already exists for the given `scheduleId`. * @param scheduleId The schedule ID that already exists. */ error ScheduleExists(uint256 scheduleId); /** * @notice Thrown when rNORI does not have enough unreleased tokens to fulfill a request. * @param scheduleId The schedule ID that does not have enough unreleased tokens. */ error InsufficientUnreleasedTokens(uint256 scheduleId); /** * @notice Thrown when rNORI does not have enough claimable tokens to fulfill a withdrawal. * @param account The account that does not have enough claimable tokens. * @param scheduleId The schedule ID that does not have enough claimable tokens. */ error InsufficientClaimableBalance(address account, uint256 scheduleId); /** * @notice Thrown when the caller does not have the role required to mint the tokens. * @param account the account that does not have the role. */ error InvalidMinter(address account); /** * @notice Thrown when the rNORI duration provides is zero. */ error InvalidZeroDuration(); /** * @notice Thrown when a `removalId` does not have removals for the specified `year`. * @param removalId The removal ID that does not have removals for the specified `year`. * @param year The year that does not have removals for the specified `removalId`. */ error RemovalNotFoundInYear(uint256 removalId, uint256 year); /** * @notice Thrown when the bytes contain unexpected uncapitalized characters. * @param country the country that contains unexpected uncapitalized characters. * @param subdivision the subdivision that contains unexpected uncapitalized characters. */ error UncapitalizedString(bytes2 country, bytes2 subdivision); /** * @notice Thrown when a methodology is greater than the maximum allowed value. * @param methodology the methodology that is greater than the maximum allowed value. */ error MethodologyTooLarge(uint8 methodology); /** * @notice Thrown when a methodology version is greater than the maximum allowed value. * @param methodologyVersion the methodology version that is greater than the maximum allowed value. */ error MethodologyVersionTooLarge(uint8 methodologyVersion); /** * @notice Thrown when a removal ID uses an unsupported version. * @param idVersion the removal ID version that is not supported. */ error UnsupportedIdVersion(uint8 idVersion); /** * @notice Thrown when a caller attempts to transfer a certificate. */ error ForbiddenTransferAfterMinting(); /** * @notice Thrown when there is insufficient supply in the market. */ error InsufficientSupply(); /** * @notice Thrown when the caller is not authorized to withdraw. */ error UnauthorizedWithdrawal(); /** * @notice Thrown when the supply of the market is too low to fulfill a request and the caller is not authorized to * access the reserve supply. */ error LowSupplyAllowlistRequired(); /** * @notice Thrown when the caller is not authorized to perform the action. */ error Unauthorized(); /** * @notice Thrown when transaction data contains invalid data. */ error InvalidData(); /** * @notice Thrown when the specified fee percentage is not a valid value. */ error InvalidNoriFeePercentage(); /** * @notice Thrown when a token is transferred, but the type of transfer is unsupported. */ error ForbiddenTransfer(); /** * @notice Thrown when the removal specified by `tokenId` has not been minted yet. * @param tokenId The removal token ID that is not minted yet. */ error RemovalNotYetMinted(uint256 tokenId); /** * @notice Thrown when the caller specifies the zero address for the Nori fee wallet. */ error NoriFeeWalletZeroAddress(); /** * @notice Thrown when a purchasing token decimals value is not between 6 and 18. * @param decimals The purchasing token decimals value that is invalid. */ error InvalidPurchasingTokenDecimals(uint256 decimals); /** * @notice Thrown when a swap attempt is made for zero removals or a fractional amount less than the purchasing token's * decimal precision - 2. * @param amount The purchase amount of the certificate that is invalid. */ error InvalidCertificateAmount(uint256 amount); /** * @notice Thrown when attempting to list for sale a removal that already belongs to the Certificate or Market * contracts. */ error RemovalAlreadySoldOrConsigned(uint256 tokenId); /** * @notice Thrown when replacement removal amounts do not sum to the specified total amount being replaced. */ error ReplacementAmountMismatch(); /** * @notice Thrown when attempting to replace more removals than the size of the deficit. */ error ReplacementAmountExceedsNrtDeficit(); /** * @notice Thrown when attempting to replace removals on behalf of a certificate that has not been minted yet. */ error CertificateNotYetMinted(uint256 tokenId); /** * @notice Thrown when an ERC20 token transfer fails. */ error ERC20TransferFailed(); /** * @notice Thrown when the price multiple is set below 100. */ error InvalidPriceMultiple();
// SPDX-License-Identifier: MIT pragma solidity =0.8.17; interface ICertificate { /** * @notice Used to decrement the discrepancy counter when removals are burned from this contract. */ function incrementNrtDeficit(uint256 amount) external; /** * @notice Returns the total number of certificates that have been minted. * @dev Includes burned certificates. * @return Total number of certificates that have been minted. */ function totalMinted() external view returns (uint256); }
// SPDX-License-Identifier: MIT pragma solidity =0.8.17; interface IMarket { /** * @notice Releases a removal from the market. * @dev This function is called by the Removal contract when releasing removals. * @param removalId The ID of the removal to release. */ function release(uint256 removalId) external; }
// SPDX-License-Identifier: MIT pragma solidity =0.8.17; interface IRemoval { /** * @notice Get the project ID for a given removal ID. * @param id The removal token ID for which to retrieve the project ID. * @return The project ID for the removal token ID. */ function getProjectId(uint256 id) external view returns (uint256); }
// SPDX-License-Identifier: MIT pragma solidity =0.8.17; import { UnsupportedIdVersion, MethodologyVersionTooLarge, MethodologyTooLarge, UncapitalizedString } from "./Errors.sol"; /** * @notice Decoded removal data. * @dev Every removal is minted using this struct. The struct then undergoes bit-packing to create the removal ID. * @param idVersion The removal ID version. * @param methodology The removal's methodology type. * @param methodologyVersion The removal methodology type's version. * @param vintage The vintage of the removal. * @param country The country that the removal occurred in. * @param subdivision The subdivision of the country that the removal occurred in. * @param supplierAddress The supplier's original wallet address. * @param subIdentifier A unique sub-identifier (e.g., the parcel/field identifier). */ struct DecodedRemovalIdV0 { uint8 idVersion; uint8 methodology; uint8 methodologyVersion; uint16 vintage; bytes2 country; bytes2 subdivision; address supplierAddress; uint32 subIdentifier; } /** * @title A library for working with Removal IDs. * @author Nori Inc. * @notice Library encapsulating the logic around encoding and decoding removal IDs. * @dev The token IDs used for a given ERC1155 token in Removal encode information about the carbon removal in the * following format(s), where the first byte encodes the format version: * * ##### Removal ID Version 0: * * | Bytes Label | Description | * | ----------- | ----------------------------------------------------------- | * | tokIdV | The token/removal ID version. | * | meth&v | The removal's methodology version. | * | vintage | The vintage of the removal. | * | country | The country that the removal occurred in. | * | subdiv | The subdivision of the country that the removal occurred in.| * | supplier | The supplier's original wallet address. | * | subid | A unique sub-identifier (e.g., the parcel/field identifier).| * * | tokIdV | meth&v | vintage | country | subdiv | supplier | subid | * | ------ | ------ | ------- | ------- | ------- | -------- | ------- | * | 1 byte | 1 byte | 2 bytes | 2 bytes | 2 bytes | 20 bytes | 4 bytes | */ library RemovalIdLib { using RemovalIdLib for DecodedRemovalIdV0; /** * @notice The number of bits per byte. */ uint256 public constant BITS_PER_BYTE = 8; /** * @notice The number of bytes allocated to the token/removal ID version. */ uint256 public constant ID_VERSION_FIELD_LENGTH = 1; /** * @notice The number of bytes allocated to the methodology version. */ uint256 public constant METHODOLOGY_DATA_FIELD_LENGTH = 1; /** * @notice The number of bytes allocated to the vintage. */ uint256 public constant VINTAGE_FIELD_LENGTH = 2; /** * @notice The number of bytes allocated to the ISO 3166-2 country code. */ uint256 public constant COUNTRY_CODE_FIELD_LENGTH = 2; /** * @notice The number of bytes allocated to the administrative region of the ISO 3166-2 subdivision. */ uint256 public constant ADMIN1_CODE_FIELD_LENGTH = 2; /** * @notice The number of bytes allocated to the supplier's original wallet address. */ uint256 public constant ADDRESS_FIELD_LENGTH = 20; /** * @notice The number of bytes allocated to the sub-identifier. */ uint256 public constant SUBID_FIELD_LENGTH = 4; /** * @notice The bit offset of the ID version. */ uint256 public constant ID_VERSION_OFFSET = 31; /** * @notice The bit offset of the methodology data. */ uint256 public constant METHODOLOGY_DATA_OFFSET = 30; /** * @notice The bit offset of the vintage. */ uint256 public constant VINTAGE_OFFSET = 28; /** * @notice The bit offset of the country code. */ uint256 public constant COUNTRY_CODE_OFFSET = 26; /** * @notice The bit offset of the administrative region code. */ uint256 public constant ADMIN1_CODE_OFFSET = 24; /** * @notice The bit offset of the original supplier wallet address. */ uint256 public constant ADDRESS_OFFSET = 4; /** * @notice The bit offset of the sub-identifier. */ uint256 public constant SUBID_OFFSET = 0; /** * @notice Check whether the provided character bytes are capitalized. * @param characters the character bytes to check. * @return valid True if the provided character bytes are capitalized, false otherwise. */ function isCapitalized(bytes2 characters) internal pure returns (bool valid) { assembly { let firstCharacter := byte(0, characters) let secondCharacter := byte(1, characters) valid := and( and(lt(firstCharacter, 0x5B), gt(firstCharacter, 0x40)), and(lt(secondCharacter, 0x5B), gt(secondCharacter, 0x40)) ) } } /** * @notice Validate the removal struct. * @param removal The removal struct to validate. */ function validate(DecodedRemovalIdV0 memory removal) internal pure { if (removal.idVersion != 0) { revert UnsupportedIdVersion({idVersion: removal.idVersion}); } if (removal.methodologyVersion > 15) { revert MethodologyVersionTooLarge({ methodologyVersion: removal.methodologyVersion }); } if (removal.methodology > 15) { revert MethodologyTooLarge({methodology: removal.methodology}); } if ( !(isCapitalized({characters: removal.country}) && isCapitalized({characters: removal.subdivision})) ) { revert UncapitalizedString({ country: removal.country, subdivision: removal.subdivision }); } } /** * @notice Packs data about a removal into a 256-bit removal ID for the removal. * @dev Performs some possible validations on the data before attempting to create the ID. * @param removal A removal in `DecodedRemovalIdV0` notation. * @return The removal ID. */ function createRemovalId(DecodedRemovalIdV0 memory removal) internal pure returns (uint256) { removal.validate(); uint256 methodologyData = (removal.methodology << 4) | removal.methodologyVersion; return (uint256(removal.idVersion) << (ID_VERSION_OFFSET * BITS_PER_BYTE)) | (uint256(methodologyData) << (METHODOLOGY_DATA_OFFSET * BITS_PER_BYTE)) | (uint256(removal.vintage) << (VINTAGE_OFFSET * BITS_PER_BYTE)) | (uint256(uint16(removal.country)) << (COUNTRY_CODE_OFFSET * BITS_PER_BYTE)) | (uint256(uint16(removal.subdivision)) << (ADMIN1_CODE_OFFSET * BITS_PER_BYTE)) | (uint256(uint160(removal.supplierAddress)) << (ADDRESS_OFFSET * BITS_PER_BYTE)) | (uint256(removal.subIdentifier) << (SUBID_OFFSET * BITS_PER_BYTE)); } /** * @notice Unpacks a V0 removal ID into its component data. * @param removalId The removal ID to unpack. * @return The removal ID in `DecodedRemovalIdV0` notation. */ function decodeRemovalIdV0(uint256 removalId) internal pure returns (DecodedRemovalIdV0 memory) { return DecodedRemovalIdV0( version({removalId: removalId}), methodology({removalId: removalId}), methodologyVersion({removalId: removalId}), vintage({removalId: removalId}), countryCode({removalId: removalId}), subdivisionCode({removalId: removalId}), supplierAddress({removalId: removalId}), subIdentifier({removalId: removalId}) ); } /** * @notice Extracts and returns the version field of a removal ID. * @param removalId The removal ID to extract the version field from. * @return The version field of the removal ID. */ function version(uint256 removalId) internal pure returns (uint8) { return uint8( _extractValue({ removalId: removalId, numBytesFieldLength: ID_VERSION_FIELD_LENGTH, numBytesOffsetFromRight: ID_VERSION_OFFSET }) ); } /** * @notice Extracts and returns the methodology field of a removal ID. * @param removalId The removal ID to extract the methodology field from. * @return The methodology field of the removal ID. */ function methodology(uint256 removalId) internal pure returns (uint8) { return uint8( _extractValue({ removalId: removalId, numBytesFieldLength: METHODOLOGY_DATA_FIELD_LENGTH, numBytesOffsetFromRight: METHODOLOGY_DATA_OFFSET }) >> 4 ); // methodology encoded in the first nibble } /** * @notice Extracts and returns the methodology version field of a removal ID. * @param removalId The removal ID to extract the methodology version field from. * @return The methodology version field of the removal ID. */ function methodologyVersion(uint256 removalId) internal pure returns (uint8) { return uint8( _extractValue({ removalId: removalId, numBytesFieldLength: METHODOLOGY_DATA_FIELD_LENGTH, numBytesOffsetFromRight: METHODOLOGY_DATA_OFFSET }) & (2**4 - 1) ); // methodology version encoded in the second nibble } /** * @notice Extracts and returns the vintage field of a removal ID. * @param removalId The removal ID to extract the vintage field from. * @return The vintage field of the removal ID. */ function vintage(uint256 removalId) internal pure returns (uint16) { return uint16( _extractValue({ removalId: removalId, numBytesFieldLength: VINTAGE_FIELD_LENGTH, numBytesOffsetFromRight: VINTAGE_OFFSET }) ); } /** * @notice Extracts and returns the country code field of a removal ID. * @param removalId The removal ID to extract the country code field from. * @return The country code field of the removal ID. */ function countryCode(uint256 removalId) internal pure returns (bytes2) { return bytes2( uint16( _extractValue({ removalId: removalId, numBytesFieldLength: COUNTRY_CODE_FIELD_LENGTH, numBytesOffsetFromRight: COUNTRY_CODE_OFFSET }) ) ); } /** * @notice Extracts and returns the subdivision field of a removal ID. * @param removalId The removal ID to extract the subdivision field from. * @return The subdivision field of the removal ID. */ function subdivisionCode(uint256 removalId) internal pure returns (bytes2) { return bytes2( uint16( _extractValue({ removalId: removalId, numBytesFieldLength: ADMIN1_CODE_FIELD_LENGTH, numBytesOffsetFromRight: ADMIN1_CODE_OFFSET }) ) ); } /** * @notice Extracts and returns the supplier address field of a removal ID. * @param removalId The removal ID to extract the supplier address field from. * @return The supplier address field of the removal ID. */ function supplierAddress(uint256 removalId) internal pure returns (address) { return address( uint160( _extractValue({ removalId: removalId, numBytesFieldLength: ADDRESS_FIELD_LENGTH, numBytesOffsetFromRight: ADDRESS_OFFSET }) ) ); } /** * @notice Extract and returns the `subIdentifier` field of a removal ID. * @param removalId The removal ID to extract the sub-identifier field from. * @return The sub-identifier field of the removal ID. */ function subIdentifier(uint256 removalId) internal pure returns (uint32) { return uint32( _extractValue({ removalId: removalId, numBytesFieldLength: SUBID_FIELD_LENGTH, numBytesOffsetFromRight: SUBID_OFFSET }) ); } /** * @notice Extract a field of the specified length in bytes, at the specified location, from a removal ID. * @param removalId The removal ID to extract the field from. * @param numBytesFieldLength The number of bytes in the field to extract. * @param numBytesOffsetFromRight The number of bytes to offset the field from the right. * @return The extracted field value. */ function _extractValue( uint256 removalId, uint256 numBytesFieldLength, uint256 numBytesOffsetFromRight ) private pure returns (uint256) { bytes32 mask = bytes32(2**(numBytesFieldLength * BITS_PER_BYTE) - 1) << (numBytesOffsetFromRight * BITS_PER_BYTE); bytes32 maskedValue = bytes32(removalId) & mask; return uint256(maskedValue >> (numBytesOffsetFromRight * BITS_PER_BYTE)); } }
{ "viaIR": true, "optimizer": { "enabled": true, "runs": 800 }, "outputSelection": { "*": { "*": [ "evm.bytecode", "evm.deployedBytecode", "devdoc", "userdoc", "metadata", "abi" ] } }, "metadata": { "useLiteralContent": true }, "libraries": {} }
Contract ABI
API[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"ForbiddenTransfer","type":"error"},{"inputs":[],"name":"InvalidData","type":"error"},{"inputs":[{"internalType":"uint8","name":"methodology","type":"uint8"}],"name":"MethodologyTooLarge","type":"error"},{"inputs":[{"internalType":"uint8","name":"methodologyVersion","type":"uint8"}],"name":"MethodologyVersionTooLarge","type":"error"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"RemovalAlreadySoldOrConsigned","type":"error"},{"inputs":[{"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"RemovalNotYetMinted","type":"error"},{"inputs":[{"internalType":"bytes2","name":"country","type":"bytes2"},{"internalType":"bytes2","name":"subdivision","type":"bytes2"}],"name":"UncapitalizedString","type":"error"},{"inputs":[{"internalType":"uint8","name":"idVersion","type":"uint8"}],"name":"UnsupportedIdVersion","type":"error"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":false,"internalType":"bool","name":"approved","type":"bool"}],"name":"ApprovalForAll","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint8","name":"version","type":"uint8"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"certificateRecipient","type":"address"},{"indexed":true,"internalType":"uint256","name":"certificateAmount","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"certificateId","type":"uint256"},{"indexed":false,"internalType":"uint256[]","name":"removalIds","type":"uint256[]"},{"indexed":false,"internalType":"uint256[]","name":"removalAmounts","type":"uint256[]"}],"name":"Migrate","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Paused","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"contract IMarket","name":"market","type":"address"},{"indexed":false,"internalType":"contract ICertificate","name":"certificate","type":"address"}],"name":"RegisterContractAddresses","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"id","type":"uint256"},{"indexed":true,"internalType":"address","name":"fromAddress","type":"address"},{"indexed":false,"internalType":"uint256","name":"amount","type":"uint256"}],"name":"ReleaseRemoval","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"certificateRecipient","type":"address"},{"indexed":true,"internalType":"uint256","name":"certificateAmount","type":"uint256"},{"indexed":true,"internalType":"uint256","name":"certificateId","type":"uint256"},{"indexed":false,"internalType":"uint256[]","name":"removalIds","type":"uint256[]"},{"indexed":false,"internalType":"uint256[]","name":"removalAmounts","type":"uint256[]"}],"name":"Retire","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"previousAdminRole","type":"bytes32"},{"indexed":true,"internalType":"bytes32","name":"newAdminRole","type":"bytes32"}],"name":"RoleAdminChanged","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleGranted","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"bytes32","name":"role","type":"bytes32"},{"indexed":true,"internalType":"address","name":"account","type":"address"},{"indexed":true,"internalType":"address","name":"sender","type":"address"}],"name":"RoleRevoked","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256[]","name":"ids","type":"uint256[]"},{"indexed":false,"internalType":"uint256[]","name":"values","type":"uint256[]"}],"name":"TransferBatch","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"address","name":"operator","type":"address"},{"indexed":true,"internalType":"address","name":"from","type":"address"},{"indexed":true,"internalType":"address","name":"to","type":"address"},{"indexed":false,"internalType":"uint256","name":"id","type":"uint256"},{"indexed":false,"internalType":"uint256","name":"value","type":"uint256"}],"name":"TransferSingle","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"string","name":"value","type":"string"},{"indexed":true,"internalType":"uint256","name":"id","type":"uint256"}],"name":"URI","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"address","name":"account","type":"address"}],"name":"Unpaused","type":"event"},{"inputs":[],"name":"CONSIGNOR_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"DEFAULT_ADMIN_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"PAUSER_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"RELEASER_ROLE","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256[]","name":"amounts","type":"uint256[]"},{"internalType":"uint256[]","name":"ids","type":"uint256[]"}],"name":"addBalance","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"uint256","name":"id","type":"uint256"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address[]","name":"accounts","type":"address[]"},{"internalType":"uint256[]","name":"ids","type":"uint256[]"}],"name":"balanceOfBatch","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"uint256","name":"id","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"consign","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256[]","name":"ids","type":"uint256[]"},{"internalType":"uint256[]","name":"amounts","type":"uint256[]"}],"name":"consignorBatchTransfer","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"id","type":"uint256"}],"name":"decodeRemovalIdV0","outputs":[{"components":[{"internalType":"uint8","name":"idVersion","type":"uint8"},{"internalType":"uint8","name":"methodology","type":"uint8"},{"internalType":"uint8","name":"methodologyVersion","type":"uint8"},{"internalType":"uint16","name":"vintage","type":"uint16"},{"internalType":"bytes2","name":"country","type":"bytes2"},{"internalType":"bytes2","name":"subdivision","type":"bytes2"},{"internalType":"address","name":"supplierAddress","type":"address"},{"internalType":"uint32","name":"subIdentifier","type":"uint32"}],"internalType":"struct DecodedRemovalIdV0","name":"","type":"tuple"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"uint256","name":"id","type":"uint256"}],"name":"exists","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getCertificateAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getMarketAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getMarketBalance","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"owner","type":"address"}],"name":"getOwnedTokenIds","outputs":[{"internalType":"uint256[]","name":"","type":"uint256[]"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"id","type":"uint256"}],"name":"getProjectId","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"getRoleAdmin","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"uint256","name":"index","type":"uint256"}],"name":"getRoleMember","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"}],"name":"getRoleMemberCount","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"grantRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"hasRole","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"string","name":"baseURI","type":"string"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"},{"internalType":"address","name":"operator","type":"address"}],"name":"isApprovedForAll","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256[]","name":"amounts","type":"uint256[]"},{"components":[{"internalType":"uint8","name":"idVersion","type":"uint8"},{"internalType":"uint8","name":"methodology","type":"uint8"},{"internalType":"uint8","name":"methodologyVersion","type":"uint8"},{"internalType":"uint16","name":"vintage","type":"uint16"},{"internalType":"bytes2","name":"country","type":"bytes2"},{"internalType":"bytes2","name":"subdivision","type":"bytes2"},{"internalType":"address","name":"supplierAddress","type":"address"},{"internalType":"uint32","name":"subIdentifier","type":"uint32"}],"internalType":"struct DecodedRemovalIdV0[]","name":"removals","type":"tuple[]"},{"internalType":"uint256","name":"projectId","type":"uint256"}],"name":"mintBatch","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes[]","name":"data","type":"bytes[]"}],"name":"multicall","outputs":[{"internalType":"bytes[]","name":"results","type":"bytes[]"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"account","type":"address"}],"name":"numberOfTokensOwnedByAddress","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"pause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"paused","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"contract IMarket","name":"market","type":"address"},{"internalType":"contract ICertificate","name":"certificate","type":"address"}],"name":"registerContractAddresses","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"id","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"}],"name":"release","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"renounceRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256[]","name":"ids","type":"uint256[]"},{"internalType":"uint256[]","name":"amounts","type":"uint256[]"},{"internalType":"address","name":"certificateRecipient","type":"address"},{"internalType":"uint256","name":"certificateAmount","type":"uint256"}],"name":"retire","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"role","type":"bytes32"},{"internalType":"address","name":"account","type":"address"}],"name":"revokeRole","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256[]","name":"ids","type":"uint256[]"},{"internalType":"uint256[]","name":"amounts","type":"uint256[]"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"safeBatchTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"from","type":"address"},{"internalType":"address","name":"to","type":"address"},{"internalType":"uint256","name":"id","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bytes","name":"data","type":"bytes"}],"name":"safeTransferFrom","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"operator","type":"address"},{"internalType":"bool","name":"approved","type":"bool"}],"name":"setApprovalForAll","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes4","name":"interfaceId","type":"bytes4"}],"name":"supportsInterface","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"id","type":"uint256"}],"name":"totalSupply","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"unpause","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"uri","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"}]
Deployed Bytecode
0x6080604052600436101561001257600080fd5b6000803560e01c8062fdd58e1461274a57806301ffc9a7146126a75780630231c1c2146122c85780630e89341c146121e7578063248a9ca3146121ba5780632eb2c2d6146120eb5780632f2ff15d1461202657806334697f4514611f4157806336568abe14611e23578063366a4120146119345780633d932dfb146119095780633f4ba83a1461186b57806342c6281d1461177d5780634e1273f4146115ee5780634f558e79146115c25780634fac7e41146115365780635562a315146113945780635c975abb146113715780636b425fc8146112dd578063789e8cdf146112a45780638456cb59146112495780639010d07c1461120357806391d14854146111b657806393ae796d14610efe578063964eec7014610edf578063a217fddf14610ec3578063a22cb46514610dbe578063ac28af2414610d83578063ac9650d814610b08578063bd85b03914610ade578063c39e3d6514610a5c578063c48c010514610a21578063ca15c873146109f6578063d547741f1461092c578063e63ab1e9146108f1578063e7334fe5146108c9578063e7f78c72146108a1578063e985e9c51461084c578063f242432a146107945763f62d1888146101d457600080fd5b346107915760208060031936011261078d5767ffffffffffffffff9060043582811161078957366023820112156107895761021990369060248160040135910161295e565b91835460ff808260081c16159283809461077d575b8015610767575b156106fc5760019560ff19938588868316178a556106eb575b506102a983895460081c16610262816132d4565b61026b816132d4565b6102a46024604051856102888c83985192818492860191016127eb565b8101637b69647d60e01b8c82015203600481018652018461289c565b6132d4565b80519182116106d75781906102bf609954612e22565b601f8111610667575b508690601f83116001146105e85789926105dd575b5050600019600383901b1c191690861b176099555b61032881875460081c16610305816132d4565b8360335416603355610316816132d4565b61031f816132d4565b6102a4816132d4565b6103306130fa565b85805260fb9182855260408720336000528552816040600020541615610594575b86805261012d928386526103683360408a2061314b565b506103716130fa565b7f65d7a28e3265b37a6474929f336521b332c1681b933f6cb9f3376673440d862a8089528187526040892033600052875283604060002054161561054b575b88528386526103c23360408a2061314b565b506103cb6130fa565b7fa269776b75ac4c5fa422bb11bec3ed3cee626848d07687372583174b209261fb80895281875260408920336000528752836040600020541615610502575b885283865261041c3360408a2061314b565b506104256130fa565b7f88f3509f0e42391f2d94ebfb2a37cbd0782b1b8f73715330017f4663290b8117928389528187526040892033600052875260406000205416156104b8575b505085528252610477336040862061314b565b50610480578280f35b825461ff00191683556040519182527f7f26b83ff96e1f2b6a682f133852f6798a09c465da95921460cefb384740249891a138808280f35b828852855260408720336000528552856040600020918254161790553333827f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d8980a43880610464565b80895281875260408920336000528752604060002088848254161790553333827f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d8c80a461040a565b80895281875260408920336000528752604060002088848254161790553333827f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d8c80a46103b0565b86805282855260408720336000528552604060002086828254161790553333887f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d8180a4610351565b0151905038806102dd565b60998a528893507f72a152ddfb8e864297c917af52ea6c1c68aead0fee1a62673fcc7e0c94979d009190601f1984168b5b8a8282106106515750508411610638575b505050811b016099556102f2565b015160001960f88460031b161c1916905538808061062a565b8385015186558c97909501949384019301610619565b909150609989527f72a152ddfb8e864297c917af52ea6c1c68aead0fee1a62673fcc7e0c94979d00601f840160051c8101918885106106cd575b84939291601f8b920160051c01915b8281106106be5750506102c8565b600081558594508a91016106b0565b90915081906106a1565b634e487b7160e01b88526041600452602488fd5b61ffff19166101011788553861024e565b60405162461bcd60e51b815260048101869052602e60248201527f496e697469616c697a61626c653a20636f6e747261637420697320616c72656160448201527f647920696e697469616c697a65640000000000000000000000000000000000006064820152608490fd5b50303b1580156102355750600182841614610235565b5060018284161061022e565b8380fd5b5080fd5b80fd5b50346107915760a0366003190112610791576107ae61277a565b6107b6612790565b60843567ffffffffffffffff8111610789576107d6903690600401612995565b906001600160a01b0392836101915416330361083a576108139381163381148015610816575b61080691506146f7565b6064359160443591613ae4565b80f35b5085526098602052604085203360005260205261080660ff604060002054166107fc565b604051631d9d0a4f60e31b8152600490fd5b50346107915760403660031901126107915761086661277a565b6040610870612790565b926001600160a01b0380931681526098602052209116600052602052602060ff604060002054166040519015158152f35b503461079157806003193601126107915760206001600160a01b036101925416604051908152f35b503461079157806003193601126107915760206001600160a01b036101915416604051908152f35b503461079157806003193601126107915760206040517f65d7a28e3265b37a6474929f336521b332c1681b933f6cb9f3376673440d862a8152f35b5034610791576040366003190112610791576109a860043561012d61094f612790565b9180855260209060fb825261096a6001604088200154612d17565b6109726130fa565b80865260fb82526001600160a01b036040872094169384600052825260ff604060002054166109ac575b855252604083206131e4565b5080f35b80865260fb825260408620846000528252604060002060ff1981541690553384827ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b8980a461099c565b5034610791576020366003190112610791576040602091600435815261012d83522054604051908152f35b503461079157806003193601126107915760206040517fa269776b75ac4c5fa422bb11bec3ed3cee626848d07687372583174b209261fb8152f35b503461079157608036600319011261079157610a7661277a565b610a7e612790565b67ffffffffffffffff9190604435838111610ada57610aa1903690600401612924565b606435938411610ada57610abc610813943690600401612924565b91610ac56129e4565b60405193610ad285612864565b868552614121565b8480fd5b5034610791576020366003190112610791576040602091600435815260c983522054604051908152f35b50346107915760208060031936011261078d5767ffffffffffffffff6004358181116107895790610b3e849236906004016127ba565b9091610b49826128be565b92610b57604051948561289c565b828452601f19610b66846128be565b01855b818110610d74575050845b838110610bdb575050505060405191838301848452825180915260408401948060408360051b870101940192955b828710610baf5785850386f35b909192938280610bcb600193603f198a8203018652885161280e565b9601920196019592919092610ba2565b8060059796971b820135601e1983360301811215610d70578201803590848211610d6c5787018136038113610d6c57610c1591369161295e565b303b15610d01578781888293519101305af4903d15610cfa573d610c3881612942565b90610c46604051928361289c565b81523d898983013e5b604051606081019181831087841117610ce457610cdc94610cc193604052602783527f416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c8b8401527f206661696c6564000000000000000000000000000000000000000000000000006040840152612f75565b610ccb8288612f4b565b52610cd68187612f4b565b50612f26565b959495610b74565b634e487b7160e01b600052604160045260246000fd5b6060610c4f565b60405162461bcd60e51b815260048101889052602660248201527f416464726573733a2064656c65676174652063616c6c20746f206e6f6e2d636f60448201527f6e747261637400000000000000000000000000000000000000000000000000006064820152608490fd5b8880fd5b8780fd5b60608682018901528701610b69565b503461079157806003193601126107915760206040517f88f3509f0e42391f2d94ebfb2a37cbd0782b1b8f73715330017f4663290b81178152f35b503461079157604036600319011261079157610dd861277a565b60243590811515809203610ebf576001600160a01b0390610df76130fa565b1690813314610e545733835260986020526040832082600052602052604060002060ff1981541660ff83161790556040519081527f17307eab39ab6107e8899845ad3d59bd9653f200f220920489ca2b5937696c3160203392a380f35b60405162461bcd60e51b815260206004820152602960248201527f455243313135353a2073657474696e6720617070726f76616c2073746174757360448201527f20666f722073656c6600000000000000000000000000000000000000000000006064820152608490fd5b8280fd5b5034610791578060031936011261079157602090604051908152f35b5034610791578060031936011261079157602061019654604051908152f35b5034610791576040366003190112610791576004356001600160a01b03808216809203610ebf576024803591821680920361078957610f3b6130fa565b3360009081527fc88390e7e62175be0932452175b6a7222b6b094ab0ef984a5153c620345d8975602090815260409091205490919060ff1615610fe25750916040917fa948457069516ab10917665b0b5d6b8043d77b39f57ca760ef0d3d4104277547937fffffffffffffffffffffffff0000000000000000000000000000000000000000610191848282541617905582610192918254161790558351928352820152a180f35b90610fec33612fd3565b6000604051610ffa81612880565b604281528381019160603684378151156111a35760308353815160019081101561119057607860218401536041905b8082116111225750506110e05760486110dc936110b1936110c09360405195869376020b1b1b2b9b9a1b7b73a3937b61d1030b1b1b7bab73a1604d1b8a86015261107c815180928c6037890191016127eb565b8401917f206973206d697373696e6720726f6c65200000000000000000000000000000006037840152518093868401906127eb565b0103602881018452018261289c565b60405193849362461bcd60e51b8552600485015283019061280e565b0390fd5b606485856040519162461bcd60e51b83528160048401528201527f537472696e67733a20686578206c656e67746820696e73756666696369656e746044820152fd5b9091600f8116601081101561117b576f181899199a1a9b1b9c1cb0b131b232b360811b901a6111518486612fc2565b5360041c918015611166576000190190611029565b87634e487b7160e01b60005260116004526000fd5b88634e487b7160e01b60005260326004526000fd5b634e487b7160e01b825260326004528682fd5b634e487b7160e01b815260326004528590fd5b5034610791576040366003190112610791576001600160a01b0360406111da612790565b92600435815260fb602052209116600052602052602060ff604060002054166040519015158152f35b5034610791576040366003190112610791576001600160a01b03611239602092600435815261012d8452604060243591206130e2565b9190546040519260031b1c168152f35b5034610791578060031936011261079157611262612bd2565b61126a6130fa565b600160ff1960335416176033557f62e78cea01bee320cd4e420270b5ea74000d11b0c9f74754ebdbfc544b05a2586020604051338152a180f35b50346107915760203660031901126107915760406020916001600160a01b036112cb61277a565b16815261019583522054604051908152f35b5034610791576060366003190112610791576112f761277a565b602435906113036129e4565b6001600160a01b03806101925416818316908114908115611362575b50611349579061081392916101915416916040519261133d84612864565b85845260443592613ae4565b60405163094f4a6b60e31b815260048101849052602490fd5b9050816101915416143861131f565b5034610791578060031936011261079157602060ff603354166040519015158152f35b50346107915760803660031901126107915767ffffffffffffffff600435818111610ebf576113c79036906004016127ba565b9091602435818111610ada576113e19036906004016127ba565b9092604435936001600160a01b039384861680960361153157606435946114066129e4565b6101925416946040519663144613ff60e31b88526020978a89826004818c5afa918215611524578b888c86938895966114e8575b50906114887fba5d618d168a3f9d48b5d1b95779e4cd5afa49565f8d387a128ec2f2ee0f589493926114796040519485946040865260408601916140e4565b90838203908401528d8c6140e4565b0390a48960405198890152604088015260608701528760808701528760a08701528760c087015260c0865260e086019086821090821117610ce457610813966114e1936114d99260405236916128d6565b9236916128d6565b9133614121565b9550935050505081813d831161151d575b611503818361289c565b81010312611519575182828b888c61148861143a565b8a80fd5b503d6114f9565b50604051903d90823e3d90fd5b600080fd5b50346107915760208060031936011261078d576001600160a01b0361155961277a565b16825261019581526040822091604051809384918482549182815201918452848420935b858282106115ac575050506115949250038361289c565b6115a86040519282849384528301906129b0565b0390f35b855484526001958601958895509301920161157d565b5034610791576020366003190112610791576040602091600435815260c9835220541515604051908152f35b50346107915760403660031901126107915767ffffffffffffffff600435818111610ebf5736602382011215610ebf5780600401359161162d836128be565b9161163b604051938461289c565b83835260209360248585019160051b83010191368311611779576024869101915b83831061176157505050506024359081116107895761167f903690600401612924565b9080518251036116f6576116938151612ef4565b935b81518110156116df57806116ca6001600160a01b036116b76116da9486612f4b565b51166116c38387612f4b565b5190612e5c565b6116d48288612f4b565b52612f26565b611695565b5050506115a86040519282849384528301906129b0565b60405162461bcd60e51b815260048101849052602960248201527f455243313135353a206163636f756e747320616e6420696473206c656e67746860448201527f206d69736d6174636800000000000000000000000000000000000000000000006064820152608490fd5b819061176c846127a6565b815201910190859061165c565b8680fd5b50346107915760203660031901126107915760043561179a6146b9565b506117a36146b9565b508060f81c906040516117b581612847565b82815260208101908260f41c600f168252604081018360f01c600f1681526060820161ffff90818660e01c168152608084019161ffff60f01b928391828960201b16825260a0870193838a60301b16855260c08801966001600160a01b0398898c60201c16895260e0019963ffffffff809c168b526040519c8d525160ff1660208d01525160ff1660408c0152511660608a015251166080880152511660a0860152511660c0840152511660e082015261010090f35b5034610791578060031936011261079157611884612bd2565b60335460ff8116156118c45760ff19166033557f5db9ee0a495bf2e6ff9c91a7834c1ba4fdd244a5e8aa4e537bd38aeae4b073aa6020604051338152a180f35b60405162461bcd60e51b815260206004820152601460248201527f5061757361626c653a206e6f74207061757365640000000000000000000000006044820152606490fd5b5034610791576020366003190112610791576040602091600435815261019483522054604051908152f35b5034610791576040366003190112610791576004356024908135907f88f3509f0e42391f2d94ebfb2a37cbd0782b1b8f73715330017f4663290b81179283855260209360fb855260408620338752855260ff60408720541615611cf2575084916001600160a01b03948582821c166119ac8382612e5c565b80611c9f575b50508484106119bf578680f35b60405163e7334fe560e01b808252908281600481305afa908115611b61576119f09185918b91611b44575b50612e5c565b80611b6c575b5050848410611a03578680f35b6040516373fbc63960e11b808252908281600481305afa908115611b6157611a339185918b91611b445750612e5c565b611a3c57508680f35b87611a5186611a4b818a6131d7565b986131d7565b946040519283528383600481305afa928315611b0a578293611b15575b50611a7a8686856147a4565b88610192541690813b15610ebf578291829160405180948193633cfe604560e11b83528b60048401525af18015611b0a57611af2575b505090611ae7967fa76ba9683000f0598aec5ed73132d1bdb673107c3e609fcbff0dfb9296467c43926040519586521693a3612fb5565b503880808080808680f35b611afe90939293612833565b610d7057908738611ab0565b6040513d84823e3d90fd5b611b36919350843d8611611b3d575b611b2e818361289c565b81019061469a565b9138611a6e565b503d611b24565b611b5b9150853d8711611b3d57611b2e818361289c565b386119ea565b6040513d8b823e3d90fd5b611b7a8688979394976131d7565b9080821015611c975750905b6040518381528681600481305afa8015611c6f57858491611bae938d91611c7a575b506147a4565b88886101915416803b1561078d57819087604051809481936337bdc99b60e01b83528a60048401525af18015611c6f57611c5c575b506040519283528583600481305afa8015611b6157611c37938a91611c3f575b50847fa76ba9683000f0598aec5ed73132d1bdb673107c3e609fcbff0dfb9296467c43888b604051948786521693a3612fb5565b9238806119f6565b611c569150873d8911611b3d57611b2e818361289c565b38611c03565b611c6890999199612833565b9738611be3565b6040513d8c823e3d90fd5b611c9191508a3d8c11611b3d57611b2e818361289c565b38611ba8565b905090611b86565b9194509080861015611cec575084905b611cba8284836147a4565b827fa76ba9683000f0598aec5ed73132d1bdb673107c3e609fcbff0dfb9296467c4386604051858152a39238806119b2565b90611caf565b849086611cfe33612fd3565b9160405190611d0c82612880565b60428252848201926060368537825115611e105760308453825190600191821015611dfd5790607860218501536041915b818311611d91575050506110e05760486110dc936110b1936110c09360405195869376020b1b1b2b9b9a1b7b73a3937b61d1030b1b1b7bab73a1604d1b8a86015261107c815180928c6037890191016127eb565b909192600f81166010811015611dea576f181899199a1a9b1b9c1cb0b131b232b360811b901a611dc18587612fc2565b5360041c928015611dd757600019019190611d3d565b634e487b7160e01b825260116004528882fd5b634e487b7160e01b835260326004528983fd5b634e487b7160e01b815260326004528790fd5b634e487b7160e01b815260326004528690fd5b5034610791576040366003190112610791576004356001600160a01b03611e48612790565b16338103611ed6576109a891611e5c6130fa565b80845260fb6020526040842082855260205260ff604085205416611e8c575b835261012d602052604083206131e4565b80845260fb602052604084208285526020526040842060ff1981541690553382827ff6391f5c32d9c69d2a47ea670b442974b53935d1edc7fd64eb21e047a839171b8780a4611e7b565b60405162461bcd60e51b815260206004820152602f60248201527f416363657373436f6e74726f6c3a2063616e206f6e6c792072656e6f756e636560448201527f20726f6c657320666f722073656c6600000000000000000000000000000000006064820152608490fd5b503461079157606036600319011261079157611f5b61277a565b67ffffffffffffffff91906024803584811161078957611f7f9036906004016127ba565b919094604435908111610ada57611f9a9036906004016127ba565b9091611fa46129e4565b855b828110611fd9575050946114d9611fc392610813969736916128d6565b9060405192611fd184612864565b8584526133dd565b611fe48184866139f0565b3587526101946020526040872054156120055761200090612f26565b611fa6565b6120109192846139f0565b60405163ac0522ad60e01b815290356004820152fd5b5034610791576040366003190112610791576109a860043561012d612049612790565b9180855260209060fb82526120646001604088200154612d17565b61206c6130fa565b80865260fb82526001600160a01b0360408720941693848752825260ff604087205416156120a1575b8552526040832061314b565b80865260fb8252604080872085885283528620805460ff191660011790553384827f2f8788117e7eff1d82e926ec794901d17c78024a50270940304540a733656f0d8980a4612095565b50346107915760a03660031901126107915761210561277a565b61210d612790565b67ffffffffffffffff604435818111610ada5761212e903690600401612924565b6064358281116121b657612146903690600401612924565b916084359081116121b65761215f903690600401612995565b926001600160a01b0394856101915416330361083a576108139581163381148015612194575b61218f91506146f7565b614121565b50875260986020526040872033885260205261218f60ff604089205416612185565b8580fd5b50346107915760203660031901126107915760016040602092600435815260fb8452200154604051908152f35b50346107915760208060031936011261078d5760405191828160995461220c81612e22565b938484526001918683821691826000146122a657505060011461224c575b50506122389250038361289c565b6115a860405192828493845283019061280e565b90859250609982527f72a152ddfb8e864297c917af52ea6c1c68aead0fee1a62673fcc7e0c94979d005b85831061228e5750506122389350820101388061222a565b80548389018501528794508693909201918101612276565b925093505061223894915060ff191682840152151560051b820101388061222a565b5034610791576080366003190112610791576122e261277a565b60243567ffffffffffffffff8111610ebf576123029036906004016127ba565b67ffffffffffffffff60449392933511610789573660236044350112156107895767ffffffffffffffff6044356004013511610789573660246044356004013560081b604435010111610789576123576129e4565b61236660443560040135612ef4565b90845b604435600401358110612386575061081393611fc39136916128d6565b6101006023198260081b60443501360301126121b6576040518061010081011067ffffffffffffffff610100830111176126935761010081016040526123d560248360081b6044350101614769565b8082526123ea60448460081b81350101614769565b602083015261240260648460081b6044350101614769565b604083015260848360081b60443501013561ffff81168103610d6c57606083015261243660a48460081b6044350101614777565b608083015261244e60c48460081b6044350101614777565b60a083015261246660e48460081b60443501016127a6565b60c0830152604435600884901b01610104013563ffffffff81169003610d705760ff906101048460081b60443501013560e0840152168061267b575060ff604082015116600f90818111612663575060ff60208301511690811161264b575061ffff60f01b80608083015116906124f6828060001a9060011a605b6040821191101690605b604082119110161690565b8061261c575b156125fa57505063ffffffff60e060f080602085015160041b1660ff6040860151161760ff60f81b855160f81b1661ffff841b6060870151851b16917bffff0000000000000000000000000000000000000000000000000000608088015160201c16931b17171779ffff00000000000000000000000000000000000000000000000060a085015160301c161777ffffffffffffffffffffffffffffffffffffffff0000000060c085015160201b161792015116179081875261019460205260408720546125e85781600192885261019460205260643560408920556125e18286612f4b565b5201612369565b604051635cb045db60e01b8152600490fd5b60a0604493015116604051916381036ebb60e01b835260048301526024820152fd5b506126468160a0850151168060001a9060011a605b6040821191101690605b604082119110161690565b6124fc565b602490604051906346ac6e0f60e01b82526004820152fd5b602490604051906324b1529d60e11b82526004820152fd5b60249060405190633e60769b60e21b82526004820152fd5b634e487b7160e01b87526041600452602487fd5b50346107915760203660031901126107915760043563ffffffff60e01b811680910361078d57602090635a05180f60e01b81149081156126ed575b506040519015158152f35b637965db0b60e01b811491508115612707575b50826126e2565b636cdb3d1360e11b811491508115612739575b8115612728575b5082612700565b6301ffc9a760e01b14905082612721565b6303a24d0760e21b8114915061271a565b503461079157604036600319011261079157602061277261276961277a565b60243590612e5c565b604051908152f35b600435906001600160a01b038216820361153157565b602435906001600160a01b038216820361153157565b35906001600160a01b038216820361153157565b9181601f840112156115315782359167ffffffffffffffff8311611531576020808501948460051b01011161153157565b60005b8381106127fe5750506000910152565b81810151838201526020016127ee565b90602091612827815180928185528580860191016127eb565b601f01601f1916010190565b67ffffffffffffffff8111610ce457604052565b610100810190811067ffffffffffffffff821117610ce457604052565b6020810190811067ffffffffffffffff821117610ce457604052565b6080810190811067ffffffffffffffff821117610ce457604052565b90601f8019910116810190811067ffffffffffffffff821117610ce457604052565b67ffffffffffffffff8111610ce45760051b60200190565b92916128e1826128be565b916128ef604051938461289c565b829481845260208094019160051b810192831161153157905b8282106129155750505050565b81358152908301908301612908565b9080601f830112156115315781602061293f933591016128d6565b90565b67ffffffffffffffff8111610ce457601f01601f191660200190565b92919261296a82612942565b91612978604051938461289c565b829481845281830111611531578281602093846000960137010152565b9080601f830112156115315781602061293f9335910161295e565b90815180825260208080930193019160005b8281106129d0575050505090565b8351855293810193928101926001016129c2565b3360009081527fba06a78ec98734fb5637b51b6458f4ba0a229fe2bbc86ce5d18073647cb408f3602090815260408083205490927fa269776b75ac4c5fa422bb11bec3ed3cee626848d07687372583174b209261fb9160ff1615612a485750505050565b612a5133612fd3565b91845190612a5e82612880565b60428252848201926060368537825115612bbe5760308453825190600191821015612bbe5790607860218501536041915b818311612b5057505050612b0e5760486110dc938693612af293612ae3985198899376020b1b1b2b9b9a1b7b73a3937b61d1030b1b1b7bab73a1604d1b8a86015261107c815180928c6037890191016127eb565b0103602881018752018561289c565b5192839262461bcd60e51b84526004840152602483019061280e565b60648486519062461bcd60e51b825280600483015260248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e746044820152fd5b909192600f81166010811015612baa576f181899199a1a9b1b9c1cb0b131b232b360811b901a612b808587612fc2565b5360041c928015612b9657600019019190612a8f565b634e487b7160e01b82526011600452602482fd5b634e487b7160e01b83526032600452602483fd5b634e487b7160e01b81526032600452602490fd5b3360009081527fc81858b0fc5e8d7d2c7a341b4e13a62a27b51e1da1072bf5f7fee8fdef673e94602090815260408083205490927f65d7a28e3265b37a6474929f336521b332c1681b933f6cb9f3376673440d862a9160ff1615612c365750505050565b612c3f33612fd3565b91845190612c4c82612880565b60428252848201926060368537825115612bbe5760308453825190600191821015612bbe5790607860218501536041915b818311612cd157505050612b0e5760486110dc938693612af293612ae3985198899376020b1b1b2b9b9a1b7b73a3937b61d1030b1b1b7bab73a1604d1b8a86015261107c815180928c6037890191016127eb565b909192600f81166010811015612baa576f181899199a1a9b1b9c1cb0b131b232b360811b901a612d018587612fc2565b5360041c928015612b9657600019019190612c7d565b60009080825260209060fb8252604092838120338252835260ff848220541615612d415750505050565b612d4a33612fd3565b91845190612d5782612880565b60428252848201926060368537825115612bbe5760308453825190600191821015612bbe5790607860218501536041915b818311612ddc57505050612b0e5760486110dc938693612af293612ae3985198899376020b1b1b2b9b9a1b7b73a3937b61d1030b1b1b7bab73a1604d1b8a86015261107c815180928c6037890191016127eb565b909192600f81166010811015612baa576f181899199a1a9b1b9c1cb0b131b232b360811b901a612e0c8587612fc2565b5360041c928015612b9657600019019190612d88565b90600182811c92168015612e52575b6020831014612e3c57565b634e487b7160e01b600052602260045260246000fd5b91607f1691612e31565b6001600160a01b0316908115612e8957600052609760205260406000209060005260205260406000205490565b60405162461bcd60e51b815260206004820152602a60248201527f455243313135353a2061646472657373207a65726f206973206e6f742061207660448201527f616c6964206f776e6572000000000000000000000000000000000000000000006064820152608490fd5b90612efe826128be565b612f0b604051918261289c565b8281528092612f1c601f19916128be565b0190602036910137565b6000198114612f355760010190565b634e487b7160e01b600052601160045260246000fd5b8051821015612f5f5760209160051b010190565b634e487b7160e01b600052603260045260246000fd5b90919015612f81575090565b815115612f915750805190602001fd5b60405162461bcd60e51b8152602060048201529081906110dc90602483019061280e565b91908201809211612f3557565b908151811015612f5f570160200190565b604051906060820182811067ffffffffffffffff821117610ce457604052602a8252602082016040368237825115612f5f57603090538151600190811015612f5f57607860218401536029905b8082116130745750506130305790565b606460405162461bcd60e51b815260206004820152602060248201527f537472696e67733a20686578206c656e67746820696e73756666696369656e746044820152fd5b9091600f811660108110156130cd576f181899199a1a9b1b9c1cb0b131b232b360811b901a6130a38486612fc2565b5360041c9180156130b8576000190190613020565b60246000634e487b7160e01b81526011600452fd5b60246000634e487b7160e01b81526032600452fd5b8054821015612f5f5760005260206000200190600090565b60ff6033541661310657565b60405162461bcd60e51b815260206004820152601060248201527f5061757361626c653a20706175736564000000000000000000000000000000006044820152606490fd5b919060018301600090828252806020526040822054156000146131d157845494680100000000000000008610156131bd57836131ad613194886001604098999a018555846130e2565b819391549060031b600019811b9283911b169119161790565b9055549382526020522055600190565b634e487b7160e01b83526041600452602483fd5b50925050565b91908203918211612f3557565b906001820190600092818452826020526040842054908115156000146132cd57600019918083018181116132b9578254908482019182116132a557808203613270575b5050508054801561325c5782019161323f83836130e2565b909182549160031b1b191690555582526020526040812055600190565b634e487b7160e01b86526031600452602486fd5b61329061328061319493866130e2565b90549060031b1c928392866130e2565b90558652846020526040862055388080613227565b634e487b7160e01b88526011600452602488fd5b634e487b7160e01b87526011600452602487fd5b5050505090565b156132db57565b60405162461bcd60e51b815260206004820152602b60248201527f496e697469616c697a61626c653a20636f6e7472616374206973206e6f74206960448201527f6e697469616c697a696e670000000000000000000000000000000000000000006064820152608490fd5b1561334d57565b60405162461bcd60e51b815260206004820152602860248201527f455243313135353a2069647320616e6420616d6f756e7473206c656e6774682060448201527f6d69736d617463680000000000000000000000000000000000000000000000006064820152608490fd5b90916133cf61293f936040845260408401906129b0565b9160208184039101526129b0565b9091936001600160a01b0390818316918215908115916138f4576134048651895114613346565b61340c6130fa565b61019190808254169161019290828254169184881492839084156138ea575b84156138e1575b841561383f575b508a5195159160008e5b8d898310613777575050505050505050505060005b855181101561349f578061346f61349a928a612f4b565b5161347a8289612f4b565b5160005260c96020526134936040600020918254612fb5565b9055612f26565b613458565b509091929460005b85518110156134f357806134be6134ee928a612f4b565b516134c98289612f4b565b5160005261349360206097815260409081600020908a60005252600020918254612fb5565b6134a7565b509195909460409584600088517f4a39dc06d4c0dbc64b70af90fd698a233a518aa5d07e595d983b8c0526c8f7fb33918061352f898d836133b8565b0390a484600052610195602052866000206000805286519160005b83811061374a57505050503b613562575b5050505050565b6135c492602092600087518096819582946135b56135a263bc197c8160e01b9c8d875233600488015287602488015260a0604488015260a48701906129b0565b60031993848783030160648801526129b0565b9184830301608485015261280e565b03925af16000918161371a575b5061369c57505060016135e2613963565b6308c379a014613666575b6135fd57505b388080808061355b565b5162461bcd60e51b815260206004820152603460248201527f455243313135353a207472616e7366657220746f206e6f6e2d4552433131353560448201527f526563656976657220696d706c656d656e7465720000000000000000000000006064820152608490fd5b61366e613981565b8061367957506135ed565b825162461bcd60e51b8152602060048201529081906110dc90602483019061280e565b6001600160e01b031916036136b157506135f3565b5162461bcd60e51b815260206004820152602860248201527f455243313135353a204552433131353552656365697665722072656a6563746560448201527f6420746f6b656e730000000000000000000000000000000000000000000000006064820152608490fd5b61373c91925060203d8111613743575b613734818361289c565b810190613943565b90386135d1565b503d61372a565b80826137586001938c612f4b565b5190613766575b500161354a565b613770908561314b565b503861375f565b826137858161378c93612f4b565b5192612f4b565b51888754168d148015613833575b156138245780151580613814575b1561083a5785856137ff575b6137e9575b5087871591826137d9575b505061083a576137d390612f26565b8e613443565b60201c168c1415905087386137c4565b6137f76101969182546131d7565b9055386137b9565b61019661380d838254612fb5565b90556137b4565b50655af3107a40008106156137a8565b655af3107a40008106156137a8565b50888454168d1461379a565b3360009081527fba06a78ec98734fb5637b51b6458f4ba0a229fe2bbc86ce5d18073647cb408f3602052604081205492955060ff909216917fa269776b75ac4c5fa422bb11bec3ed3cee626848d07687372583174b209261fb91836138a9575b5050509238613439565b8b1492509082156138bf575b505038808061389f565b60ff925090604091815260fb6020528181208b825260205220541638806138b5565b60009450613432565b898114945061342b565b60405162461bcd60e51b815260206004820152602160248201527f455243313135353a206d696e7420746f20746865207a65726f206164647265736044820152607360f81b6064820152608490fd5b9081602091031261153157516001600160e01b0319811681036115315790565b60009060033d1161397057565b905060046000803e60005160e01c90565b600060443d1061293f57604051600319913d83016004833e815167ffffffffffffffff918282113d6024840111176139df578184019485519384116139e7573d850101602084870101116139df575061293f9291016020019061289c565b949350505050565b50949350505050565b9190811015612f5f5760051b0190565b15613a0757565b60405162461bcd60e51b815260206004820152602560248201527f455243313135353a207472616e7366657220746f20746865207a65726f20616460448201527f64726573730000000000000000000000000000000000000000000000000000006064820152608490fd5b15613a7957565b60405162461bcd60e51b815260206004820152602a60248201527f455243313135353a20696e73756666696369656e742062616c616e636520666f60448201527f72207472616e73666572000000000000000000000000000000000000000000006064820152608490fd5b9290916001600160a01b038316151594613afd86613a00565b613b06826140ae565b93613b10846140ae565b613b186130fa565b6001600160a01b0361019154166001600160a01b03610192541690806001600160a01b03851614908192821561409b575b8215614089575b8215613fd5575b5088519260005b848110613ed15750505050506001600160a01b0387169586159182613e8d575b6001600160a01b03841615613dc5575b509084600052602097609789526040998a600020896000528a52878b60002054613bba82821015613a72565b8860005260978c528c6000208b6000528c52038b600020558660005260978a528a6000206001600160a01b0386166000528a528a600020613bfc898254612fb5565b90558a8981518981528a8d8201527fc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f626001600160a01b038916933392a46001600160a01b0385166000526101958a528a60002092896000528b6000209085519560009115915b878110613d74575050505050505050803b613c81575b50505050505050565b613ccc9360006001600160a01b0388958a519788968795869363f23a6e6160e01b9c8d865233600487015260248601526044850152606484015260a0608484015260a483019061280e565b0393165af160009181613d55575b50613d3e575050600190613cec613963565b6308c379a014613d0a575b506135fd57505b38808080808080613c78565b613d12613981565b9081613d1e5750613cf7565b6110dc845192839262461bcd60e51b84526004840152602483019061280e565b6001600160e01b0319160390506136b15750613cfe565b613d6d919250843d861161374357613734818361289c565b9038613cda565b808386613d8360019486612f4b565b5191613da7575b613d96575b5001613c62565b613da0908961314b565b5038613d8f565b613db1828a612e5c565b613d8a57613dbf82886131e4565b50613d8a565b9996939097949198959260005b8951811015613e7b578b613dea82613785818e612f4b565b518160005260c991602092808452604093846000205492848410613e265790613e2196959493929160005252039060002055612f26565b613dd2565b855162461bcd60e51b815260048101839052602860248201527f455243313135353a206275726e20616d6f756e74206578636565647320746f74604482015267616c537570706c7960c01b6064820152608490fd5b50929598919497909396995038613b8e565b9996939097949198959260005b8951811015613ec15780613eb1613ebc928e612f4b565b5161347a828d612f4b565b613e9a565b5092959891949790939699613b7e565b613edb818c612f4b565b51613ee68288612f4b565b516001600160a01b0361019154166001600160a01b038a16148015613fb7575b15613fa85780151580613f98575b1561083a57846001600160a01b038f86613f83575b1614613f6d575b5084159081613f4d575b5061083a57613f4890612f26565b613b5e565b6001600160a01b03915060201c166001600160a01b038816141538613f3a565b613f7b6101969182546131d7565b905538613f30565b610196613f91858254612fb5565b9055613f29565b50655af3107a4000810615613f14565b655af3107a4000810615613f14565b506001600160a01b0361019254166001600160a01b038a1614613f06565b3360009081527fba06a78ec98734fb5637b51b6458f4ba0a229fe2bbc86ce5d18073647cb408f3602052604081205492935060ff909216917fa269776b75ac4c5fa422bb11bec3ed3cee626848d07687372583174b209261fb918361403f575b5050509038613b57565b6001600160a01b03881614925090821561405e575b5050388080614035565b60ff925090604091815260fb6020528181206001600160a01b03881682526020522054163880614054565b6001600160a01b038616159250613b50565b6001600160a01b03861681149250613b49565b604051906040820182811067ffffffffffffffff821117610ce45760405260018252602082016020368237825115612f5f575290565b90918281527f07ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff83116115315760209260051b809284830137010190565b9161412f8151855114613346565b6141436001600160a01b0383161515613a00565b61414b6130fa565b6001600160a01b0361019154166001600160a01b03610192541690806001600160a01b038516149081928215614687575b8215614675575b82156145c1575b5083519260005b8481106144bd5750505050506001600160a01b038316928315958661447d575b6001600160a01b0384161561440a575b60005b835181101561425757806141db6142529286612f4b565b516134936141e9838b612f4b565b5191806000526097602090808252604092836000208d6000528352858d85600020549061421883831015613a72565b8360005284865286600020906000528552038460002055600052815281600020906001600160a01b038b1660005252600020918254612fb5565b6141c4565b5093949290956040968751876001600160a01b038516917f4a39dc06d4c0dbc64b70af90fd698a233a518aa5d07e595d983b8c0526c8f7fb33918061429d8b8b836133b8565b0390a46001600160a01b0383166000526101956020528760002090876000528860002085519360009015905b8581106143b057505050505050803b6142e5575b505050505050565b6135a260006001600160a01b036135b59461432d6020978b51998a988997889563bc197c8160e01b9e8f8852336004890152602488015260a0604488015260a48701906129b0565b0393165af160009181614390575b5061437b575050600161434c613963565b6308c379a014614368575b6135fd57505b3880808080806142dd565b614370613981565b806136795750614357565b6001600160e01b031916036136b1575061435d565b6143a991925060203d811161374357613734818361289c565b903861433b565b80826143be6001938b612f4b565b51906143ec575b6001600160a01b0389166143db575b50016142c9565b6143e5908761314b565b50386143d4565b6143f68187612e5c565b6143c55761440481866131e4565b506143c5565b959290600097949295975b865181101561446f576144288188612f4b565b51614433828b612f4b565b518160005260c991602092808452604093846000205492848410613e26579061446a96959493929160005252039060002055612f26565b614415565b5090929596949193966141c1565b969260009692959491965b86518110156144af578061449f6144aa9288612f4b565b5161347a828a612f4b565b614488565b5092969590939491956141b1565b6144c78187612f4b565b516144d2828b612f4b565b516001600160a01b0361019154166001600160a01b038a161480156145a3575b156145945780151580614584575b1561083a578361456f575b846001600160a01b038b1614614559575b5084159081614539575b5061083a5761453490612f26565b614191565b6001600160a01b03915060201c166001600160a01b038816141538614526565b6145676101969182546131d7565b90553861451c565b61019661457d828254612fb5565b905561450b565b50655af3107a4000810615614500565b655af3107a4000810615614500565b506001600160a01b0361019254166001600160a01b038a16146144f2565b3360009081527fba06a78ec98734fb5637b51b6458f4ba0a229fe2bbc86ce5d18073647cb408f3602052604081205492935060ff909216917fa269776b75ac4c5fa422bb11bec3ed3cee626848d07687372583174b209261fb918361462b575b505050903861418a565b6001600160a01b03881614925090821561464a575b5050388080614621565b60ff925090604091815260fb6020528181206001600160a01b03881682526020522054163880614640565b6001600160a01b038616159250614183565b6001600160a01b0386168114925061417c565b9081602091031261153157516001600160a01b03811681036115315790565b604051906146c682612847565b8160e06000918281528260208201528260408201528260608201528260808201528260a08201528260c08201520152565b156146fe57565b60405162461bcd60e51b815260206004820152602e60248201527f455243313135353a2063616c6c6572206973206e6f7420746f6b656e206f776e60448201527f6572206f7220617070726f7665640000000000000000000000000000000000006064820152608490fd5b359060ff8216820361153157565b35907fffff0000000000000000000000000000000000000000000000000000000000008216820361153157565b9091926001600160a01b03821615614bc3576147bf836140ae565b916147c9856140ae565b9460006040516147d881612864565b526147e16130fa565b6001600160a01b0361019154166101926001600160a01b038154169082159182908315614bba575b8315614bb1575b8315614b11575b508751936001600160a01b038716149060005b8b8a878310614a3f57505050505050505060005b84518110156148eb576148518186612f4b565b5161485c8289612f4b565b51908060005260c9602081815260406000205492848410614895579061489095949392916000525203604060002055612f26565b61483e565b60405162461bcd60e51b815260048101839052602860248201527f455243313135353a206275726e20616d6f756e74206578636565647320746f74604482015267616c537570706c7960c01b6064820152608490fd5b509194509192806000526020916097835260406000206001600160a01b03851660005283526040600020548181106149ee579181600092610195959483855260978652604085206001600160a01b03891686528652036040842055604051918252838201526001600160a01b038516907fc3d58168c5ae7397731d063d5bbf3d657854427343f4c083240f7aacaa2d0f6260403392a4600060405161498f81612864565b52526001600160a01b03811660005260406000209082519260005b8481106149b8575050505050565b806149c560019284612f4b565b516149d08186612e5c565b156149dd575b50016149aa565b6149e790866131e4565b50386149d6565b60405162461bcd60e51b8152600481018590526024808201527f455243313135353a206275726e20616d6f756e7420657863656564732062616c604482015263616e636560e01b6064820152608490fd5b8261378581614a4d93612f4b565b516001600160a01b036101915416158015614aff575b15614af05780151580614ae0575b1561083a578484614acb575b614ab5575b5085159081614a9f575b5061083a57614a9a90612f26565b61482a565b6001600160a01b03915060201c16151538614a8c565b614ac36101969182546131d7565b905538614a82565b610196614ad9838254612fb5565b9055614a7d565b50655af3107a4000810615614a71565b655af3107a4000810615614a71565b506001600160a01b0386541615614a63565b3360009081527fba06a78ec98734fb5637b51b6458f4ba0a229fe2bbc86ce5d18073647cb408f3602052604090205491935060ff909116907fa269776b75ac4c5fa422bb11bec3ed3cee626848d07687372583174b209261fb9082614b7a575b50509138614817565b1591508115614b8c575b503880614b71565b905060005260fb60205260406000206000805260205260ff6040600020541638614b84565b60019350614810565b80159350614809565b60405162461bcd60e51b815260206004820152602360248201527f455243313135353a206275726e2066726f6d20746865207a65726f206164647260448201526265737360e81b6064820152608490fdfea26469706673582212204db63cb87bb9dd1b784c54e687d4a134bedb26b52f28dd61d5ad95641c2589b064736f6c63430008110033
Loading...
Loading
Loading...
Loading
Loading...
Loading
Loading...
Loading
A contract address hosts a smart contract, which is a set of code stored on the blockchain that runs when predetermined conditions are met. Learn more about addresses in our Knowledge Base.