Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HOLO-1536 save init payload (WIP) #318

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from
14 changes: 14 additions & 0 deletions src/drops/token/HolographDropERC721V2.sol
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ contract HolographDropERC721V2 is NonReentrant, ERC721H, IHolographDropERC721V2
*/
mapping(address => uint256) public totalMintsByAddress;

/// @notice Getter for the init payload
/// @dev This storage variable is set only once in the init and can be considered as immutable
bytes private INIT_PAYLOAD;

/**
* CUSTOM ERRORS
*/
Expand Down Expand Up @@ -225,6 +229,9 @@ contract HolographDropERC721V2 is NonReentrant, ERC721H, IHolographDropERC721V2
function init(bytes memory initPayload) external override returns (bytes4) {
require(!_isInitialized(), "HOLOGRAPH: already initialized");

// Store the init payload
INIT_PAYLOAD = initPayload;

DropsInitializerV2 memory initializer = abi.decode(initPayload, (DropsInitializerV2));

// Setup the owner role
Expand Down Expand Up @@ -273,6 +280,13 @@ contract HolographDropERC721V2 is NonReentrant, ERC721H, IHolographDropERC721V2
return interfaceId == type(IHolographDropERC721V2).interfaceId;
}

/**
* @notice Getter for the DropsInitializerV2 init payload
*/
function getInitProperties() external view returns (DropsInitializerV2 memory) {
return abi.decode(INIT_PAYLOAD, (DropsInitializerV2));
}

/**
* PUBLIC NON STATE CHANGING FUNCTIONS
* dynamic
Expand Down
3 changes: 2 additions & 1 deletion src/enforcer/HolographERC721.sol
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ contract HolographERC721 is Admin, Owner, HolographERC721Interface, Initializabl
* @dev bytes32(uint256(keccak256('eip1967.Holograph.sourceContract')) - 1)
*/
bytes32 constant _sourceContractSlot = 0x27d542086d1e831d40b749e7f5509a626c3047a36d160781c40d5acc83e5b074;

/**
* @dev Configuration for events to trigger for source smart contract.
*/
Expand Down Expand Up @@ -254,6 +254,7 @@ contract HolographERC721 is Admin, Owner, HolographERC721Interface, Initializabl
_symbol = contractSymbol;
_bps = contractBps;
_eventConfig = eventConfig;

if (!skipInit) {
require(sourceContract.init(initCode) == InitializableInterface.init.selector, "ERC721: could not init source");
(bool success, bytes memory returnData) = _royalties().delegatecall(
Expand Down
18 changes: 14 additions & 4 deletions src/token/CountdownERC721.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@ import {ERC721H} from "../abstract/ERC721H.sol";
import {NonReentrant} from "../abstract/NonReentrant.sol";

import {HolographERC721Interface} from "../interface/HolographERC721Interface.sol";
import {HolographerInterface} from "../interface/HolographerInterface.sol";
import {HolographInterface} from "../interface/HolographInterface.sol";
import {ICountdownERC721} from "../interface/ICountdownERC721.sol";
import {IDropsPriceOracle} from "../drops/interface/IDropsPriceOracle.sol";
import {HolographTreasuryInterface} from "../interface/HolographTreasuryInterface.sol";

import {AddressMintDetails} from "../drops/struct/AddressMintDetails.sol";
import {CountdownERC721Initializer} from "src/struct/CountdownERC721Initializer.sol";
Expand All @@ -19,7 +16,6 @@ import {CustomERC721SalesConfiguration} from "src/struct/CustomERC721SalesConfig
import {MetadataParams} from "src/struct/MetadataParams.sol";

import {Address} from "../drops/library/Address.sol";
import {MerkleProof} from "../drops/library/MerkleProof.sol";
import {Strings} from "./../drops/library/Strings.sol";
import {NFTMetadataRenderer} from "../library/NFTMetadataRenderer.sol";

Expand Down Expand Up @@ -64,6 +60,10 @@ contract CountdownERC721 is NonReentrant, ERC721H, ICountdownERC721 {
/// @dev This account tokens on behalf of those that purchase them offchain
address public minter;

/// @notice Getter for the init payload
/// @dev This storage variable is set only once in the init and can be considered as immutable
bytes private INIT_PAYLOAD;

/* -------------------------------------------------------------------------- */
/* METADATA VARAIBLES */
/* -------------------------------------------------------------------------- */
Expand Down Expand Up @@ -188,6 +188,9 @@ contract CountdownERC721 is NonReentrant, ERC721H, ICountdownERC721 {
sstore(_holographerSlot, caller())
}

// Store the init payload
INIT_PAYLOAD = initPayload;

// Decode the initializer payload to get the CountdownERC721Initializer struct
CountdownERC721Initializer memory initializer = abi.decode(initPayload, (CountdownERC721Initializer));

Expand Down Expand Up @@ -286,6 +289,13 @@ contract CountdownERC721 is NonReentrant, ERC721H, ICountdownERC721 {
return interfaceId == type(ICountdownERC721).interfaceId;
}

/**
* @notice Getter for the CountdownERC721Initializer init payload
*/
function getInitProperties() external view returns (CountdownERC721Initializer memory) {
return abi.decode(INIT_PAYLOAD, (CountdownERC721Initializer));
}

/* -------------------------------------------------------------------------- */
/* PUBLIC NON STATE CHANGING FUNCTIONS */
/* dynamic */
Expand Down
14 changes: 14 additions & 0 deletions src/token/CustomERC721.sol
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ contract CustomERC721 is NonReentrant, ContractMetadata, InitializableLazyMint,
/// @notice Getter for the end date
uint256 public END_DATE;

/// @notice Getter for the init payload
/// @dev This storage variable is set only once in the init and can be considered as immutable
bytes private INIT_PAYLOAD;

/// @notice Getter for the minter
/// @dev This account tokens on behalf of those that purchase them offchain
address public minter;
Expand Down Expand Up @@ -145,6 +149,9 @@ contract CustomERC721 is NonReentrant, ContractMetadata, InitializableLazyMint,
function init(bytes memory initPayload) external override returns (bytes4) {
require(!_isInitialized(), "HOLOGRAPH: already initialized");

// Store the init payload
INIT_PAYLOAD = initPayload;

// Enable sourceExternalCall to work on init, we set holographer here since it's only set after init
assembly {
sstore(_holographerSlot, caller())
Expand Down Expand Up @@ -293,6 +300,13 @@ contract CustomERC721 is NonReentrant, ContractMetadata, InitializableLazyMint,
return (_getOwner() == user);
}

/**
* @notice Getter for the CustomERC721Initializer init payload
*/
function getInitProperties() external view returns (CustomERC721Initializer memory) {
return abi.decode(INIT_PAYLOAD, (CustomERC721Initializer));
}

/**
* @notice Returns the theoretical maximum supply for the current time
* @dev The max supply is calculated based on the current time and the mint interval, by subtracting
Expand Down
14 changes: 14 additions & 0 deletions src/token/CxipERC721.sol
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ import "../interface/HolographerInterface.sol";
* @dev The entire logic and functionality of the smart contract is self-contained.
*/
contract CxipERC721 is ERC721H {
/// @notice Getter for the init payload
/// @dev This storage variable is set only once in the init and can be considered as immutable
bytes private INIT_PAYLOAD;

/**
* @dev Internal reference used for minting incremental token ids.
*/
Expand Down Expand Up @@ -148,6 +152,9 @@ contract CxipERC721 is ERC721H {
* @param initPayload abi encoded payload to use for contract initilaization
*/
function init(bytes memory initPayload) external override returns (bytes4) {
// Store the init payload
INIT_PAYLOAD = initPayload;

// we set this as default type since that's what Mint is currently using
_uriType = TokenUriType.IPFS;
address owner = abi.decode(initPayload, (address));
Expand All @@ -156,6 +163,13 @@ contract CxipERC721 is ERC721H {
return _init(initPayload);
}

/**
* @notice Getter for the CxipERC721 init payload
*/
function getInitProperties() external view returns (address) {
return abi.decode(INIT_PAYLOAD, (address));
}

/**
* @notice Get's the URI of the token.
* @return string The URI.
Expand Down
14 changes: 14 additions & 0 deletions src/token/HolographLegacyERC721.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ import "../interface/HolographerInterface.sol";
* @dev The entire logic and functionality of the smart contract is self-contained.
*/
contract HolographLegacyERC721 is ERC721H {
/// @notice Getter for the init payload
/// @dev This storage variable is set only once in the init and can be considered as immutable
bytes private INIT_PAYLOAD;

/**
* @dev Internal reference used for minting incremental token ids.
*/
Expand Down Expand Up @@ -49,6 +53,9 @@ contract HolographLegacyERC721 is ERC721H {
* @param initPayload abi encoded payload to use for contract initilaization
*/
function init(bytes memory initPayload) external override returns (bytes4) {
// Store the init payload
INIT_PAYLOAD = initPayload;

// we set this as default type since that's what Mint is currently using
_uriType = TokenUriType.IPFS;
address owner = abi.decode(initPayload, (address));
Expand All @@ -57,6 +64,13 @@ contract HolographLegacyERC721 is ERC721H {
return _init(initPayload);
}

/**
* @notice Getter for the HolographLegacyERC721 init payload
*/
function getInitProperties() external view returns (address) {
return abi.decode(INIT_PAYLOAD, (address));
}

/**
* @notice Get's the URI of the token.
* @return string The URI.
Expand Down
14 changes: 14 additions & 0 deletions src/token/SampleERC721.sol
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@ import "../interface/HolographERC721Interface.sol";
* @dev The entire logic and functionality of the smart contract is self-contained.
*/
contract SampleERC721 is StrictERC721H {
/// @notice Getter for the init payload
/// @dev This storage variable is set only once in the init and can be considered as immutable
bytes private INIT_PAYLOAD;

/**
* @dev Mapping of all token URIs.
*/
Expand All @@ -138,6 +142,9 @@ contract SampleERC721 is StrictERC721H {
* @param initPayload abi encoded payload to use for contract initilaization
*/
function init(bytes memory initPayload) external override returns (bytes4) {
// Store the init payload
INIT_PAYLOAD = initPayload;

// do your own custom logic here
address contractOwner = abi.decode(initPayload, (address));
_setOwner(contractOwner);
Expand All @@ -154,6 +161,13 @@ contract SampleERC721 is StrictERC721H {
return _tokenURIs[_tokenId];
}

/**
* @notice Getter for the SampleERC721 init payload
*/
function getInitProperties() external view returns (address) {
return abi.decode(INIT_PAYLOAD, (address));
}

/**
* @dev Sample mint where anyone can mint specific token, with a custom URI
*/
Expand Down
5 changes: 2 additions & 3 deletions test/foundry/deploy/04_Erc721Enforcer.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ contract Erc721Enforcer is Test {
string public constant tokenURI2 = "https://holograph.xyz/sample2.json";
string public constant tokenURI3 = "https://holograph.xyz/sample3.json";


/// @notice Set up the testing environment by initializing all necessary contracts and accounts.
function setUp() public {
vm.createSelectFork(LOCALHOST_RPC_URL);
Expand Down Expand Up @@ -284,7 +283,7 @@ contract Erc721Enforcer is Test {
/// @notice Should return contract URI as base64 string
function testContractURI() public {
string
memory expectedURI = "data:application/json;base64,eyJuYW1lIjoiU2FtcGxlIEVSQzcyMSBDb250cmFjdCAobG9jYWxob3N0KSIsImRlc2NyaXB0aW9uIjoiU2FtcGxlIEVSQzcyMSBDb250cmFjdCAobG9jYWxob3N0KSIsImltYWdlIjoiIiwiZXh0ZXJuYWxfbGluayI6IiIsInNlbGxlcl9mZWVfYmFzaXNfcG9pbnRzIjoxMDAwLCJmZWVfcmVjaXBpZW50IjoiMHg4NDZhZjRjODdmNWFmMWYzMDNlNWE1ZDIxNWQ4M2E2MTFiMDgwNjljIn0";
memory expectedURI = "data:application/json;base64,eyJuYW1lIjoiU2FtcGxlIEVSQzcyMSBDb250cmFjdCAobG9jYWxob3N0KSIsImRlc2NyaXB0aW9uIjoiU2FtcGxlIEVSQzcyMSBDb250cmFjdCAobG9jYWxob3N0KSIsImltYWdlIjoiIiwiZXh0ZXJuYWxfbGluayI6IiIsInNlbGxlcl9mZWVfYmFzaXNfcG9pbnRzIjoxMDAwLCJmZWVfcmVjaXBpZW50IjoiMHgxNGUwNjA1NDdhODQ4YjU0ODE5MTJmZGMzYTdiMGUyODdkN2I5MGZkIn0";
assertEq(holographERC721.contractURI(), expectedURI, "The contract URI does not match.");
}

Expand Down Expand Up @@ -348,7 +347,7 @@ contract Erc721Enforcer is Test {
emit Transfer(address(0), bob, tokenId2);

_mint(bob, tokenId2, tokenURI2);

assertEq(holographERC721.totalSupply(), 2);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.13;

import {Vm} from "forge-std/Test.sol";
import {console} from "forge-std/console.sol";

import {ICustomERC721Errors} from "test/foundry/interface/ICustomERC721Errors.sol";
import {HolographERC721Fixture} from "test/foundry/fixtures/HolographERC721Fixture.t.sol";

contract HolographERC721InitPayloadTest is HolographERC721Fixture, ICustomERC721Errors {
constructor() {}

function setUp() public override {
super.setUp();
}

function test_CountdownERC721InitPayload() public {
console.log(usedInitPayload.length);

(bool success, bytes memory initPayload) = address(countdownErc721).call(abi.encodeWithSignature("getInitProperties()"));

assertEq(success, true, "getInitProperties() call should succeed");
assertEq(initPayload, usedInitPayload, "initPayload should match usedInitPayload");
}
}
Loading
Loading