Skip to content

Commit 6525445

Browse files
committed
test
1 parent afc9a32 commit 6525445

File tree

10 files changed

+694
-21
lines changed

10 files changed

+694
-21
lines changed
Lines changed: 194 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,194 @@
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+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// SPDX-License-Identifier: MIT
2+
3+
pragma solidity ^0.8.0;
4+
5+
import "@openzeppelin/contracts/token/ERC1155/presets/ERC1155PresetMinterPauser.sol";
6+
7+
contract MockERC1155 is ERC1155PresetMinterPauser {
8+
constructor() ERC1155PresetMinterPauser("ipfs://BaseURI") {}
9+
10+
function mint(address to, uint256 id, uint256 amount) public virtual {
11+
_mint(to, id, amount, "");
12+
}
13+
14+
function hasRole(bytes32, address) public pure override(AccessControl, IAccessControl) returns (bool) {
15+
return true;
16+
}
17+
18+
function mintBatch(address to, uint256[] memory ids, uint256[] memory amounts) public virtual {
19+
require(hasRole(MINTER_ROLE, _msgSender()), "ERC1155PresetMinterPauser: must have minter role to mint");
20+
21+
_mintBatch(to, ids, amounts, "");
22+
}
23+
24+
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
25+
return super.supportsInterface(interfaceId);
26+
}
27+
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// SPDX-License-Identifier: MIT
2+
3+
pragma solidity ^0.8.0;
4+
5+
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
6+
import "@openzeppelin/contracts/token/ERC20/presets/ERC20PresetMinterPauser.sol";
7+
import "@openzeppelin/contracts/token/ERC20/extensions/draft-ERC20Permit.sol";
8+
9+
contract MockERC20 is ERC20PresetMinterPauser, ERC20Permit {
10+
bool internal taxActive;
11+
12+
constructor() ERC20PresetMinterPauser("Mock Coin", "MOCK") ERC20Permit("Mock Coin") {}
13+
14+
function mint(address to, uint256 amount) public override(ERC20PresetMinterPauser) {
15+
_mint(to, amount);
16+
}
17+
18+
function toggleTax() external {
19+
taxActive = !taxActive;
20+
}
21+
22+
function _transfer(address from, address to, uint256 amount) internal override {
23+
if (taxActive) {
24+
uint256 tax = (amount * 10) / 100;
25+
amount -= tax;
26+
super._transfer(from, address(this), tax);
27+
}
28+
super._transfer(from, to, amount);
29+
}
30+
31+
function _beforeTokenTransfer(
32+
address from,
33+
address to,
34+
uint256 amount
35+
) internal override(ERC20PresetMinterPauser, ERC20) {
36+
super._beforeTokenTransfer(from, to, amount);
37+
}
38+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// SPDX-License-Identifier: MIT
2+
3+
pragma solidity ^0.8.0;
4+
5+
import "@openzeppelin/contracts/token/ERC721/extensions/ERC721Burnable.sol";
6+
7+
contract MockERC721 is ERC721Burnable {
8+
uint256 public nextTokenIdToMint;
9+
10+
constructor() ERC721("MockERC721", "MOCK") {}
11+
12+
function mint(address _receiver, uint256 _amount) external {
13+
uint256 tokenId = nextTokenIdToMint;
14+
nextTokenIdToMint += _amount;
15+
16+
for (uint256 i = 0; i < _amount; i += 1) {
17+
_mint(_receiver, tokenId);
18+
tokenId += 1;
19+
}
20+
}
21+
22+
function supportsInterface(bytes4 interfaceId) public view virtual override returns (bool) {
23+
return super.supportsInterface(interfaceId);
24+
}
25+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// SPDX-License-Identifier: MIT
2+
3+
pragma solidity ^0.8.11;
4+
5+
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
6+
7+
contract WETH9 is ERC20 {
8+
event Deposit(address indexed sender, uint256 amount);
9+
event Withdrawal(address indexed sender, uint256 amount);
10+
11+
constructor() ERC20("Wrapped Ether", "WETH") {}
12+
13+
receive() external payable virtual {
14+
deposit();
15+
}
16+
17+
function deposit() public payable {
18+
_mint(msg.sender, msg.value);
19+
emit Deposit(msg.sender, msg.value);
20+
}
21+
22+
function withdraw(uint256 amount) public {
23+
_burn(msg.sender, amount);
24+
payable(msg.sender).transfer(amount);
25+
emit Withdrawal(msg.sender, amount);
26+
}
27+
28+
function totalSupply() public view override returns (uint256) {
29+
return address(this).balance;
30+
}
31+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// SPDX-License-Identifier: MIT
2+
3+
pragma solidity ^0.8.11;
4+
5+
import "@openzeppelin/contracts/token/ERC721/utils/ERC721Holder.sol";
6+
import "@openzeppelin/contracts/token/ERC1155/utils/ERC1155Holder.sol";
7+
8+
import "../mocks/MockERC20.sol";
9+
import "../mocks/MockERC721.sol";
10+
import "../mocks/MockERC1155.sol";
11+
12+
contract Wallet is ERC721Holder, ERC1155Holder {
13+
function transferERC20(address token, address to, uint256 amount) public {
14+
MockERC20(token).transfer(to, amount);
15+
}
16+
17+
function setAllowanceERC20(address token, address spender, uint256 allowanceAmount) public {
18+
MockERC20(token).approve(spender, allowanceAmount);
19+
}
20+
21+
function burnERC20(address token, uint256 amount) public {
22+
MockERC20(token).burn(amount);
23+
}
24+
25+
function transferERC721(address token, address to, uint256 tokenId) public {
26+
MockERC721(token).transferFrom(address(this), to, tokenId);
27+
}
28+
29+
function setApprovalForAllERC721(address token, address operator, bool toApprove) public {
30+
MockERC721(token).setApprovalForAll(operator, toApprove);
31+
}
32+
33+
function burnERC721(address token, uint256 tokenId) public {
34+
MockERC721(token).burn(tokenId);
35+
}
36+
37+
function transferERC1155(address token, address to, uint256 tokenId, uint256 amount, bytes calldata data) external {
38+
MockERC1155(token).safeTransferFrom(address(this), to, tokenId, amount, data);
39+
}
40+
41+
function setApprovalForAllERC1155(address token, address operator, bool toApprove) public {
42+
MockERC1155(token).setApprovalForAll(operator, toApprove);
43+
}
44+
45+
function burnERC1155(address token, uint256 tokenId, uint256 amount) public {
46+
MockERC1155(token).burn(address(this), tokenId, amount);
47+
}
48+
}

0 commit comments

Comments
 (0)