|
| 1 | +// SPDX-License-Identifier: MIT |
| 2 | + |
| 3 | +pragma solidity ^0.8.0; |
| 4 | + |
| 5 | +import { Pack } from "@thirdweb-dev/contracts/prebuilts/pack/Pack.sol"; |
| 6 | +import { ITokenBundle } from "@thirdweb-dev/contracts/extension/interface/ITokenBundle.sol"; |
| 7 | + |
| 8 | +import { Wallet } from "./utils/Wallet.sol"; |
| 9 | +import "./mocks/MockERC20.sol"; |
| 10 | +import "./mocks/MockERC721.sol"; |
| 11 | +import "./mocks/MockERC1155.sol"; |
| 12 | +import "./mocks/WETH9.sol"; |
| 13 | + |
| 14 | +import { Forwarder } from "@thirdweb-dev/contracts/infra/forwarder/Forwarder.sol"; |
| 15 | +import { TWRegistry } from "@thirdweb-dev/contracts/infra/TWRegistry.sol"; |
| 16 | +import { TWFactory } from "@thirdweb-dev/contracts/infra/TWFactory.sol"; |
| 17 | + |
| 18 | + |
| 19 | +contract TestPack is Wallet { |
| 20 | + Pack internal pack; |
| 21 | + |
| 22 | + Wallet internal tokenOwner; |
| 23 | + string internal packUri; |
| 24 | + ITokenBundle.Token[] internal packContents; |
| 25 | + uint256[] internal numOfRewardUnits; |
| 26 | + |
| 27 | + string public constant NAME = "NAME"; |
| 28 | + string public constant SYMBOL = "SYMBOL"; |
| 29 | + string public constant CONTRACT_URI = "CONTRACT_URI"; |
| 30 | + |
| 31 | + MockERC20 public erc20; |
| 32 | + MockERC721 public erc721; |
| 33 | + MockERC1155 public erc1155; |
| 34 | + WETH9 public weth; |
| 35 | + |
| 36 | + address public forwarder; |
| 37 | + address public registry; |
| 38 | + address public factory; |
| 39 | + address public fee; |
| 40 | + |
| 41 | + address public royaltyRecipient = address(0x30001); |
| 42 | + uint128 public royaltyBps = 500; // 5% |
| 43 | + event ProxyAddress(address indexed proxyAddress); |
| 44 | + |
| 45 | + function setUp( |
| 46 | + address _erc20, |
| 47 | + address _erc721, |
| 48 | + address _erc1155, |
| 49 | + address _weth, |
| 50 | + address _forwarder, |
| 51 | + address _registry, |
| 52 | + address _factory, |
| 53 | + address recipient |
| 54 | + ) public { |
| 55 | + erc20 = MockERC20(_erc20); |
| 56 | + erc721 = MockERC721(_erc721); |
| 57 | + erc1155 = MockERC1155(_erc1155); |
| 58 | + weth = WETH9(payable(_weth)); |
| 59 | + forwarder = _forwarder; |
| 60 | + registry = _registry; |
| 61 | + factory = _factory; |
| 62 | + |
| 63 | + string memory _contractType = "Pack"; |
| 64 | + bytes memory _initializer = abi.encodeCall( |
| 65 | + Pack.initialize, |
| 66 | + (address(this), NAME, SYMBOL, CONTRACT_URI, forwarders(), royaltyRecipient, royaltyBps) |
| 67 | + ); |
| 68 | + address proxyAddress = TWFactory(factory).deployProxy(bytes32(bytes(_contractType)), _initializer); |
| 69 | + emit ProxyAddress(proxyAddress); |
| 70 | + |
| 71 | + pack = Pack(payable(proxyAddress)); |
| 72 | + |
| 73 | + tokenOwner = Wallet(address(this)); |
| 74 | + packUri = "ipfs://"; |
| 75 | + |
| 76 | + packContents.push( |
| 77 | + ITokenBundle.Token({ |
| 78 | + assetContract: address(erc721), |
| 79 | + tokenType: ITokenBundle.TokenType.ERC721, |
| 80 | + tokenId: 0, |
| 81 | + totalAmount: 1 |
| 82 | + }) |
| 83 | + ); |
| 84 | + numOfRewardUnits.push(1); |
| 85 | + |
| 86 | + packContents.push( |
| 87 | + ITokenBundle.Token({ |
| 88 | + assetContract: address(erc1155), |
| 89 | + tokenType: ITokenBundle.TokenType.ERC1155, |
| 90 | + tokenId: 0, |
| 91 | + totalAmount: 100 |
| 92 | + }) |
| 93 | + ); |
| 94 | + numOfRewardUnits.push(20); |
| 95 | + |
| 96 | + packContents.push( |
| 97 | + ITokenBundle.Token({ |
| 98 | + assetContract: address(erc20), |
| 99 | + tokenType: ITokenBundle.TokenType.ERC20, |
| 100 | + tokenId: 0, |
| 101 | + totalAmount: 1000 ether |
| 102 | + }) |
| 103 | + ); |
| 104 | + numOfRewardUnits.push(50); |
| 105 | + |
| 106 | + packContents.push( |
| 107 | + ITokenBundle.Token({ |
| 108 | + assetContract: address(erc721), |
| 109 | + tokenType: ITokenBundle.TokenType.ERC721, |
| 110 | + tokenId: 1, |
| 111 | + totalAmount: 1 |
| 112 | + }) |
| 113 | + ); |
| 114 | + numOfRewardUnits.push(1); |
| 115 | + |
| 116 | + packContents.push( |
| 117 | + ITokenBundle.Token({ |
| 118 | + assetContract: address(erc721), |
| 119 | + tokenType: ITokenBundle.TokenType.ERC721, |
| 120 | + tokenId: 2, |
| 121 | + totalAmount: 1 |
| 122 | + }) |
| 123 | + ); |
| 124 | + numOfRewardUnits.push(1); |
| 125 | + |
| 126 | + packContents.push( |
| 127 | + ITokenBundle.Token({ |
| 128 | + assetContract: address(erc20), |
| 129 | + tokenType: ITokenBundle.TokenType.ERC20, |
| 130 | + tokenId: 0, |
| 131 | + totalAmount: 1000 ether |
| 132 | + }) |
| 133 | + ); |
| 134 | + numOfRewardUnits.push(100); |
| 135 | + |
| 136 | + packContents.push( |
| 137 | + ITokenBundle.Token({ |
| 138 | + assetContract: address(erc721), |
| 139 | + tokenType: ITokenBundle.TokenType.ERC721, |
| 140 | + tokenId: 3, |
| 141 | + totalAmount: 1 |
| 142 | + }) |
| 143 | + ); |
| 144 | + numOfRewardUnits.push(1); |
| 145 | + |
| 146 | + packContents.push( |
| 147 | + ITokenBundle.Token({ |
| 148 | + assetContract: address(erc721), |
| 149 | + tokenType: ITokenBundle.TokenType.ERC721, |
| 150 | + tokenId: 4, |
| 151 | + totalAmount: 1 |
| 152 | + }) |
| 153 | + ); |
| 154 | + numOfRewardUnits.push(1); |
| 155 | + |
| 156 | + packContents.push( |
| 157 | + ITokenBundle.Token({ |
| 158 | + assetContract: address(erc721), |
| 159 | + tokenType: ITokenBundle.TokenType.ERC721, |
| 160 | + tokenId: 5, |
| 161 | + totalAmount: 1 |
| 162 | + }) |
| 163 | + ); |
| 164 | + numOfRewardUnits.push(1); |
| 165 | + |
| 166 | + packContents.push( |
| 167 | + ITokenBundle.Token({ |
| 168 | + assetContract: address(erc1155), |
| 169 | + tokenType: ITokenBundle.TokenType.ERC1155, |
| 170 | + tokenId: 1, |
| 171 | + totalAmount: 500 |
| 172 | + }) |
| 173 | + ); |
| 174 | + numOfRewardUnits.push(50); |
| 175 | + |
| 176 | + erc20.mint(address(tokenOwner), 2000 ether); |
| 177 | + erc721.mint(address(tokenOwner), 6); |
| 178 | + erc1155.mint(address(tokenOwner), 0, 100); |
| 179 | + erc1155.mint(address(tokenOwner), 1, 500); |
| 180 | + |
| 181 | + tokenOwner.setAllowanceERC20(address(erc20), address(pack), type(uint256).max); |
| 182 | + tokenOwner.setApprovalForAllERC721(address(erc721), address(pack), true); |
| 183 | + tokenOwner.setApprovalForAllERC1155(address(erc1155), address(pack), true); |
| 184 | + |
| 185 | + // pack.grantRole(keccak256("MINTER_ROLE"), address(tokenOwner)); |
| 186 | + (uint256 packId, uint256 totalSupply) = pack.createPack(packContents, numOfRewardUnits, packUri, 0, 2, recipient); |
| 187 | + } |
| 188 | + |
| 189 | + function forwarders() public view returns (address[] memory) { |
| 190 | + address[] memory _forwarders = new address[](1); |
| 191 | + _forwarders[0] = forwarder; |
| 192 | + return _forwarders; |
| 193 | + } |
| 194 | +} |
0 commit comments