Skip to content
Verified contractExactMIT

MigrationMinter

Address0x295d30f69688fb33430fad6399e469fe385c1bb6
Balance

0 ETH

 

Transactions

179

 

Compiler

solc 0.8.30

 

Same code

2 more contracts

 

Details

Compiler
solc 0.8.30+commit.73712a01
Language
solidity
Optimization
Yes, 200 runs
EVM version
prague
License
MIT
Match
Exactcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
25,725,769
Creation transaction
0x08fd0638eb…6a3bf1598b

75 files

The source code is large: one file is shown at a time. Choose a file in the list.

project/contracts/migration/MigrationMinter.sol

// SPDX-License-Identifier: MIT
pragma solidity 0.8.30;

import {AccessControl} from "@openzeppelin/contracts/access/AccessControl.sol";
import {ReentrancyGuardTransient} from "@openzeppelin/contracts/utils/ReentrancyGuardTransient.sol";
import {IERC721} from "@openzeppelin/contracts/token/ERC721/IERC721.sol";
import {IEarthmetaERC721} from "../interfaces/IEarthmetaERC721.sol";
import {Roles} from "../lib/Roles.sol";
import {IErrors} from "../interfaces/IErrors.sol";

/// @title MigrationMinter
/// @author EarthMeta 2026.
/// @notice One-time migration helper that re-mints an EarthMeta ERC-721 collection
///         (City / Country / Land) 1:1 from the v1 → v2 migration snapshot. It
///         holds `MINTER_ROLE` on a single collection and batch-mints the snapshot
///         tokens to their recorded owners with their recorded metadata URIs.
/// @dev Deliberately NOT upgradeable: a disposable, single-purpose box. The
///      collection is fixed at construction (`immutable`, no setter needed). The
///      collection's admin must grant this contract `MINTER_ROLE`; after the
///      migration completes that role is revoked, permanently powering the helper
///      down. Uses a plain `AccessControl` + constructor and a transient
///      reentrancy guard for house-style consistency.
contract MigrationMinter is AccessControl, ReentrancyGuardTransient, IErrors {
    /// @notice The ERC-721 collection this helper mints into. Set once at
    ///         construction and never changed.
    IEarthmetaERC721 public immutable collection;

    /// @notice One token to (re)mint from the snapshot.
    /// @param tokenId The real-world (non-sequential) token id to mint.
    /// @param to The snapshot owner that should receive the token.
    /// @param uri The token's metadata URI (typically an `ipfs://` URI).
    struct MintReq {
        uint256 tokenId;
        address to;
        string uri;
    }

    /// @dev A token id already exists but belongs to someone other than the
    ///      snapshot owner — the batch was built from a different plan.
    error OwnerMismatch(uint256 tokenId, address actual, address expected);

    /// @notice A batch of snapshot tokens was minted.
    /// @param count The number of tokens newly minted in THIS batch
    ///        (tokens that already existed are skipped and not counted).
    event MintedBatch(uint256 count);

    /// @param collection_ The City/Country/Land collection to mint into.
    /// @param admin The DEFAULT_ADMIN (the Timelock in production). Also granted
    ///        `MIGRATOR_ROLE` so it can drive the mint; revoked after migration.
    constructor(address collection_, address admin) {
        if (collection_ == address(0) || admin == address(0)) revert ZeroAddress();
        collection = IEarthmetaERC721(collection_);
        _grantRole(DEFAULT_ADMIN_ROLE, admin);
        _grantRole(Roles.MIGRATOR_ROLE, admin);
    }

    // ─────────────────────────────────────────────────────────────────────────
    // Migration minting (MIGRATOR_ROLE, revoked after migration)
    // ─────────────────────────────────────────────────────────────────────────

    /// @notice Mint a batch of snapshot tokens into the collection.
    /// @dev Idempotent per token: any `tokenId` that already exists is skipped,
    ///      so a batch can be safely retried after a partial/failed run without
    ///      reverting on the already-minted tokens. Zero-address recipients are
    ///      rejected by the collection's own `mint`, so no extra check is needed.
    /// @param reqs The tokens to mint (id, owner, uri).
    function mintBatch(MintReq[] calldata reqs) external onlyRole(Roles.MIGRATOR_ROLE) nonReentrant {
        uint256 count;
        for (uint256 i = 0; i < reqs.length; i++) {
            MintReq calldata r = reqs[i];
            // Idempotent ONLY for a genuine retry: a token that already exists
            // must already belong to the snapshot owner. If it does not, the id
            // was minted from a different plan (or by another minter) and
            // skipping would silently deprive the rightful owner of the asset.
            if (collection.exists(r.tokenId)) {
                if (IERC721(address(collection)).ownerOf(r.tokenId) != r.to)
                    revert OwnerMismatch(r.tokenId, IERC721(address(collection)).ownerOf(r.tokenId), r.to);
                continue;
            }
            collection.mint(r.tokenId, r.to, r.uri);
            unchecked {
                ++count;
            }
        }
        emit MintedBatch(count);
    }

    // ─────────────────────────────────────────────────────────────────────────
    // Views
    // ─────────────────────────────────────────────────────────────────────────

    /// @notice Semantic contract version.
    /// @return The version string.
    function version() external pure returns (string memory) {
        return "2.0.0";
    }
}
Compiler settingsShow
{
  "libraries": {},
  "optimizer": {
    "runs": 200,
    "enabled": true
  },
  "evmVersion": "prague",
  "remappings": [
    "npm/@openzeppelin/[email protected]/:@openzeppelin/contracts/=npm/@openzeppelin/[email protected]/",
    "project/:@openzeppelin/contracts-upgradeable/=npm/@openzeppelin/[email protected]/",
    "project/:@openzeppelin/contracts/=npm/@openzeppelin/[email protected]/"
  ]
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.