Skip to content

Commit

Permalink
[gms-1505] readme for erc1155 preset
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonzwli committed Mar 7, 2024
1 parent 9d34bf4 commit 451465d
Show file tree
Hide file tree
Showing 2 changed files with 124 additions and 0 deletions.
22 changes: 22 additions & 0 deletions contracts/token/erc1155/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# ERC1155 contracts

The ImmutableERC1155 contracts allows clients to mint multiple different tokens with different token ids within the same collection. The contract features methods to allow for minting multiples of multiple token ids to simplify the minting flow and reduce gas costs. This contract is built on top of the [Openzeppelin implemention of EIP-1155](https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/token/ERC1155/ERC1155.sol)

[Read more On the Threat Model](../../../audits/202312-threat-model-preset-erc1155.md)
[Read more On the EIP](https://eips.ethereum.org/EIPS/eip-1155)

## preset/draft-ImmutableERC1155

The draft-ImmutableERC1155 contract is the pre-release version of the Immutable's preset 1155 contract. It has been internally audited and is ready to be tested. Please note it is not yet supported by the rest of the Immutable ecosystem. The contract contains all external facing interfaces that are needed to interact(read and write) with deployed ERC1155 collections.

## abstract/ERC1155Permit

This is an abstract contract that is used as an ancestor to the preset 1155. It contains the permit feature for the preset, allowing token owners to give approval and permission to a secure and trusted actor. This action is gasless for the token owner but will require gas from the approved operator. Please note that using permits in an ERC1155 collections exposes all the tokens owned by an address to the approved operator. Please double check to make sure the operator is secure and trusted.

## abstract/IERC1155Permit

Provides the required interface for ERC1155Permit

## abstract/ImmutableERC1155Base

This is another abstract contract used as an ancestor to the preset 1155.. It implements many of the internal methods for the preset that are not directly public facing for everyday uses. It contains functionalities to update royalties, set URIs and manage collection roles.
102 changes: 102 additions & 0 deletions test/token/erc721/ImmutableERC721GasCost.t.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
pragma solidity 0.8.19;

import "forge-std/Test.sol";

import {MockWallet} from "../../../contracts/mocks/MockWallet.sol";
import {MockWalletFactory} from "../../../contracts/mocks/MockWalletFactory.sol";
import {MockFactory} from "../../../contracts/mocks/MockFactory.sol";
import {ImmutableERC721} from "../../../contracts/token/erc721/preset/ImmutableERC721.sol";
import {IImmutableERC721Errors} from "../../../contracts/errors/Errors.sol";
import {OperatorAllowlistEnforcementErrors} from "../../../contracts/errors/Errors.sol";
import {OperatorAllowlistUpgradeable} from "../../../contracts/allowlist/OperatorAllowlistUpgradeable.sol";
import {Sign} from "../../utils/Sign.sol";
import {DeployOperatorAllowlist} from "../../utils/DeployAllowlistProxy.sol";
import {DeploySCWallet} from "../../utils/DeploySCW.sol";
import {DeployMockMarketPlace} from "../../utils/DeployMockMarketPlace.sol";
import {MockMarketplace} from "../../../contracts/mocks/MockMarketplace.sol";
import {MockDisguisedEOA} from "../../../contracts/mocks/MockDisguisedEOA.sol";
import {MockOnReceive} from "../../../contracts/mocks/MockOnReceive.sol";


contract ImmutableERC721GasCost is Test {
OperatorAllowlistUpgradeable public allowlist;
ImmutableERC721 public immutableERC721;
DeploySCWallet public deploySCWScript;
DeployMockMarketPlace public deployMockMarketPlaceScript;
MockMarketplace public mockMarketPlace;
MockFactory mockEOAFactory;

uint256 feeReceiverKey = 1;

address public admin = makeAddr("roleAdmin");
address public upgrader = makeAddr("roleUpgrader");
address public registrar = makeAddr("roleRegisterar");
address public scwOwner = makeAddr("scwOwner");
address public minter = makeAddr("minter");

address feeReceiver = vm.addr(feeReceiverKey);
address proxyAddr;
address nonAuthorizedWallet;
address scwAddr;
address scwModuleAddr;

function setUp() public {
DeployOperatorAllowlist deployScript = new DeployOperatorAllowlist();
proxyAddr = deployScript.run(admin, upgrader, registrar);

allowlist = OperatorAllowlistUpgradeable(proxyAddr);

immutableERC721 = new ImmutableERC721(
admin,
"test",
"USDC",
"test-base-uri",
"test-contract-uri",
address(allowlist),
feeReceiver,
0
);

mockEOAFactory = new MockFactory();

nonAuthorizedWallet = address(0x2);

deploySCWScript = new DeploySCWallet();

deployMockMarketPlaceScript = new DeployMockMarketPlace();
mockMarketPlace = deployMockMarketPlaceScript.run(address(immutableERC721));

_giveMinterRole();
}

function testDeployment() public {
assertEq(address(immutableERC721.operatorAllowlist()), proxyAddr);
}

function _addSCWAddressAllowListAndApprove(address _address) private {
vm.startPrank(registrar);
allowlist.addWalletToAllowlist(_address);
immutableERC721.setApprovalForAll(_address, true);
vm.stopPrank();
}

function _giveMinterRole() public {
vm.prank(admin);
immutableERC721.grantMinterRole(minter);
bytes32 minterRole = immutableERC721.MINTER_ROLE();
assertTrue(immutableERC721.hasRole(minterRole, minter));
}

function testMint1To1() public {
vm.startPrank(minter);
immutableERC721.safeMint(minter, 1);
immutableERC721.safeMint(minter, 2);

immutableERC721.approve(admin, 1);
assertEq(immutableERC721.getApproved(1), admin);
immutableERC721.setApprovalForAll(admin, true);
assertTrue(immutableERC721.isApprovedForAll(minter, admin));
vm.stopPrank();
}

}

0 comments on commit 451465d

Please sign in to comment.