Skip to content
Verified contractExactMIT

QuantumFusion

Address0x5d101f2e20120a30ef6ae13c3f94bd9d75b9df20
Balance

0 ETH

 

Transactions

2

 

Compiler

solc 0.8.17

 

Same code

Only this contract

 

Details

Compiler
solc 0.8.17+commit.8df45f5f
Language
solidity
Optimization
Yes, 200 runs
EVM version
london
Via IR
yes
License
MIT
Match
Exactcreation code: yes, runtime code: yes
Verified on Sourcify
Created in block
25,422,919
Creation transaction
0xa73b7b82a1…e7a2f2b09e

src/QuantumFusion.sol

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

import "utility-contracts/TwoStepOwnable.sol";

interface IQEFusion {
    function ownerOf(uint256 tokenId) external view returns (address);
    function getTokenTraits(uint256 tokenId) external view returns (uint8[9] memory);
    function fusionBurn(uint256 tokenId) external;
    function fusionMint(address to, uint8[9] calldata traits) external returns (uint256);
}

interface IQTraitsFusion {
    function isLegendary(uint8 entityType) external pure returns (bool);
    function isFused(uint8 entityType) external pure returns (bool);
    function generateFusedTraits(uint8 entityType, uint8[9] calldata p1, uint8[9] calldata p2, uint256 seed) external pure returns (uint8[9] memory);
}

interface IQCanvasFusion {
    function seedFusionFragments(uint256 newTokenId, uint256 parent1Id, uint256 parent2Id) external;
}

/**
 * @title QuantumFusion
 * @notice Burns two Quantum Entity tokens and mints a new fused entity whose
 *         type is determined by the parent pair.
 *
 *         Fusion rules:
 *         - Legendary + Legendary → 16 (Primordial Fusion)
 *         - Normal + Legendary    → 15 (Ascended Hybrid)
 *         - Rare (6/7) + Any      → 14 (Quantum Chimera)
 *         - Normal + Normal       → 13 (Synthesized Entity)
 *         - Fused tokens cannot be fused again.
 */
contract QuantumFusion is TwoStepOwnable {
    IQEFusion      public quantumEntities;
    IQTraitsFusion public quantumTraits;
    IQCanvasFusion public quantumCanvas;

    event Fused(
        uint256 indexed newTokenId,
        uint256 indexed parent1Id,
        uint256 indexed parent2Id,
        uint8 fusedEntityType
    );

    error NotTokenOwner();
    error CannotFuseWithSelf();
    error FusedTokensCannotBeFused();

    constructor(address _qe, address _qt, address _canvas) {
        quantumEntities = IQEFusion(_qe);
        quantumTraits   = IQTraitsFusion(_qt);
        quantumCanvas   = IQCanvasFusion(_canvas);
    }

    function _fusedType(uint8 et1, uint8 et2) internal view returns (uint8) {
        if (quantumTraits.isFused(et1) || quantumTraits.isFused(et2)) revert FusedTokensCannotBeFused();
        bool leg1 = quantumTraits.isLegendary(et1);
        bool leg2 = quantumTraits.isLegendary(et2);
        if (leg1 && leg2) return 16;
        if (leg1 || leg2) return 15;
        if (et1 == 6 || et1 == 7 || et2 == 6 || et2 == 7) return 14;
        return 13;
    }

    function fuse(uint256 tokenId1, uint256 tokenId2) external returns (uint256 newTokenId) {
        if (tokenId1 == tokenId2) revert CannotFuseWithSelf();
        if (quantumEntities.ownerOf(tokenId1) != msg.sender) revert NotTokenOwner();
        if (quantumEntities.ownerOf(tokenId2) != msg.sender) revert NotTokenOwner();

        uint8[9] memory traits1 = quantumEntities.getTokenTraits(tokenId1);
        uint8[9] memory traits2 = quantumEntities.getTokenTraits(tokenId2);
        uint8 fusedEntityType   = _fusedType(traits1[0], traits2[0]);

        uint256 seed = uint256(keccak256(abi.encodePacked(
            tokenId1, tokenId2, block.difficulty, block.timestamp, msg.sender
        )));
        uint8[9] memory fused = quantumTraits.generateFusedTraits(fusedEntityType, traits1, traits2, seed);

        quantumEntities.fusionBurn(tokenId1);
        quantumEntities.fusionBurn(tokenId2);

        newTokenId = quantumEntities.fusionMint(msg.sender, fused);

        if (address(quantumCanvas) != address(0)) {
            quantumCanvas.seedFusionFragments(newTokenId, tokenId1, tokenId2);
        }

        emit Fused(newTokenId, tokenId1, tokenId2, fusedEntityType);
    }

    function setQuantumEntities(address a) external onlyOwner { quantumEntities = IQEFusion(a); }
    function setQuantumTraits(address a)   external onlyOwner { quantumTraits   = IQTraitsFusion(a); }
    function setQuantumCanvas(address a)   external onlyOwner { quantumCanvas   = IQCanvasFusion(a); }
}

lib/seadrop/lib/utility-contracts/src/ConstructorInitializable.sol

// SPDX-License-Identifier: MIT
pragma solidity >=0.8.4;

/**
 * @author emo.eth
 * @notice Abstract smart contract that provides an onlyUninitialized modifier which only allows calling when
 *         from within a constructor of some sort, whether directly instantiating an inherting contract,
 *         or when delegatecalling from a proxy
 */
abstract contract ConstructorInitializable {
    error AlreadyInitialized();

    modifier onlyConstructor() {
        if (address(this).code.length != 0) {
            revert AlreadyInitialized();
        }
        _;
    }
}

lib/seadrop/lib/utility-contracts/src/TwoStepOwnable.sol

// SPDX-License-Identifier: MIT
pragma solidity >=0.8.4;

import {ConstructorInitializable} from "./ConstructorInitializable.sol";

/**
@notice A two-step extension of Ownable, where the new owner must claim ownership of the contract after owner initiates transfer
Owner can cancel the transfer at any point before the new owner claims ownership.
Helpful in guarding against transferring ownership to an address that is unable to act as the Owner.
*/
abstract contract TwoStepOwnable is ConstructorInitializable {
    address private _owner;

    event OwnershipTransferred(
        address indexed previousOwner,
        address indexed newOwner
    );

    address internal potentialOwner;

    event PotentialOwnerUpdated(address newPotentialAdministrator);

    error NewOwnerIsZeroAddress();
    error NotNextOwner();
    error OnlyOwner();

    modifier onlyOwner() {
        _checkOwner();
        _;
    }

    constructor() {
        _initialize();
    }

    function _initialize() private onlyConstructor {
        _transferOwnership(msg.sender);
    }

    ///@notice Initiate ownership transfer to newPotentialOwner. Note: new owner will have to manually acceptOwnership
    ///@param newPotentialOwner address of potential new owner
    function transferOwnership(address newPotentialOwner)
        public
        virtual
        onlyOwner
    {
        if (newPotentialOwner == address(0)) {
            revert NewOwnerIsZeroAddress();
        }
        potentialOwner = newPotentialOwner;
        emit PotentialOwnerUpdated(newPotentialOwner);
    }

    ///@notice Claim ownership of smart contract, after the current owner has initiated the process with transferOwnership
    function acceptOwnership() public virtual {
        address _potentialOwner = potentialOwner;
        if (msg.sender != _potentialOwner) {
            revert NotNextOwner();
        }
        delete potentialOwner;
        emit PotentialOwnerUpdated(address(0));
        _transferOwnership(_potentialOwner);
    }

    ///@notice cancel ownership transfer
    function cancelOwnershipTransfer() public virtual onlyOwner {
        delete potentialOwner;
        emit PotentialOwnerUpdated(address(0));
    }

    function owner() public view virtual returns (address) {
        return _owner;
    }

    /**
     * @dev Throws if the sender is not the owner.
     */
    function _checkOwner() internal view virtual {
        if (_owner != msg.sender) {
            revert OnlyOwner();
        }
    }

    /**
     * @dev Leaves the contract without owner. It will not be possible to call
     * `onlyOwner` functions anymore. Can only be called by the current owner.
     *
     * NOTE: Renouncing ownership will leave the contract without an owner,
     * thereby removing any functionality that is only available to the owner.
     */
    function renounceOwnership() public virtual onlyOwner {
        _transferOwnership(address(0));
    }

    /**
     * @dev Transfers ownership of the contract to a new account (`newOwner`).
     * Internal function without access restriction.
     */
    function _transferOwnership(address newOwner) internal virtual {
        address oldOwner = _owner;
        _owner = newOwner;
        emit OwnershipTransferred(oldOwner, newOwner);
    }
}
Compiler settingsShow
{
  "viaIR": true,
  "metadata": {
    "bytecodeHash": "ipfs",
    "useLiteralContent": false
  },
  "optimizer": {
    "runs": 200,
    "enabled": true
  },
  "evmVersion": "london",
  "remappings": [
    "@openzeppelin/=lib/openzeppelin-contracts/",
    "openzeppelin-contracts/=lib/openzeppelin-contracts/contracts/",
    "erc721a-seadrop/=lib/seadrop/",
    "seadrop/=lib/seadrop/src/",
    "forge-std/=lib/forge-std/src/",
    "solmate/=lib/seadrop/lib/solmate/src/",
    "utility-contracts/=lib/seadrop/lib/utility-contracts/src/",
    "ERC721A/=lib/seadrop/lib/ERC721A/contracts/",
    "ERC721A-Upgradeable/=lib/seadrop/lib/ERC721A-Upgradeable/contracts/",
    "create2-helpers/=lib/seadrop/lib/create2-helpers/",
    "create2-scripts/=lib/seadrop/lib/create2-helpers/script/",
    "ds-test/=lib/seadrop/lib/ds-test/src/",
    "erc4626-tests/=lib/openzeppelin-contracts/lib/erc4626-tests/",
    "murky/=lib/seadrop/lib/murky/src/",
    "openzeppelin-contracts-upgradeable/=lib/seadrop/lib/openzeppelin-contracts-upgradeable/",
    "openzeppelin/=lib/openzeppelin-contracts/contracts/",
    "operator-filter-registry/=lib/seadrop/lib/operator-filter-registry/src/"
  ]
}

Source code and metadata: Sourcify.

The source code belongs to the authors of the contract.