Skip to content

Commit 2d624ed

Browse files
committed
Add nonce to 721salefactory
1 parent f2d5f58 commit 2d624ed

4 files changed

Lines changed: 15 additions & 7 deletions

File tree

src/tokens/ERC721/utility/sale/ERC721SaleFactory.sol

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,14 @@ contract ERC721SaleFactory is IERC721SaleFactory, SequenceProxyFactory {
2323

2424
/// @inheritdoc IERC721SaleFactoryFunctions
2525
function deploy(
26+
uint256 nonce,
2627
address proxyOwner,
2728
address tokenOwner,
2829
address items,
2930
address implicitModeValidator,
3031
bytes32 implicitModeProjectId
3132
) external returns (address proxyAddr) {
32-
bytes32 salt = keccak256(abi.encode(tokenOwner, items, implicitModeValidator, implicitModeProjectId));
33+
bytes32 salt = keccak256(abi.encode(nonce, tokenOwner, items, implicitModeValidator, implicitModeProjectId));
3334
proxyAddr = _createProxy(salt, proxyOwner, "");
3435
ERC721Sale(proxyAddr).initialize(tokenOwner, items, implicitModeValidator, implicitModeProjectId);
3536
emit ERC721SaleDeployed(proxyAddr);
@@ -38,13 +39,14 @@ contract ERC721SaleFactory is IERC721SaleFactory, SequenceProxyFactory {
3839

3940
/// @inheritdoc IERC721SaleFactoryFunctions
4041
function determineAddress(
42+
uint256 nonce,
4143
address proxyOwner,
4244
address tokenOwner,
4345
address items,
4446
address implicitModeValidator,
4547
bytes32 implicitModeProjectId
4648
) external view returns (address proxyAddr) {
47-
bytes32 salt = keccak256(abi.encode(tokenOwner, items, implicitModeValidator, implicitModeProjectId));
49+
bytes32 salt = keccak256(abi.encode(nonce, tokenOwner, items, implicitModeValidator, implicitModeProjectId));
4850
return _computeProxyAddress(salt, proxyOwner, "");
4951
}
5052

src/tokens/ERC721/utility/sale/IERC721SaleFactory.sol

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ interface IERC721SaleFactoryFunctions {
55

66
/**
77
* Creates an ERC-721 Sale for given token contract
8+
* @param nonce Nonce for randomizing the deployment address.
89
* @param proxyOwner The owner of the ERC-721 Sale proxy
910
* @param tokenOwner The owner of the ERC-721 Sale implementation
1011
* @param items The ERC-721 Items contract address
@@ -14,6 +15,7 @@ interface IERC721SaleFactoryFunctions {
1415
* @notice The deployed contract must be granted the MINTER_ROLE on the ERC-721 Items contract.
1516
*/
1617
function deploy(
18+
uint256 nonce,
1719
address proxyOwner,
1820
address tokenOwner,
1921
address items,
@@ -23,6 +25,7 @@ interface IERC721SaleFactoryFunctions {
2325

2426
/**
2527
* Computes the address of a proxy instance.
28+
* @param nonce Nonce for randomizing the deployment address.
2629
* @param proxyOwner The owner of the ERC-721 Sale proxy
2730
* @param tokenOwner The owner of the ERC-721 Sale implementation
2831
* @param items The ERC-721 Items contract address
@@ -31,6 +34,7 @@ interface IERC721SaleFactoryFunctions {
3134
* @return proxyAddr The address of the ERC-721 Sale Proxy
3235
*/
3336
function determineAddress(
37+
uint256 nonce,
3438
address proxyOwner,
3539
address tokenOwner,
3640
address items,

test/tokens/ERC721/utility/sale/ERC721SaleBase.t.sol

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ contract ERC721SaleBaseTest is TestHelper, IERC721SaleSignals {
4646

4747
function setUpFromFactory() public {
4848
ERC721SaleFactory factory = new ERC721SaleFactory(address(this));
49-
sale = ERC721Sale(factory.deploy(proxyOwner, address(this), address(token), address(0), bytes32(0)));
49+
sale = ERC721Sale(factory.deploy(0, proxyOwner, address(this), address(token), address(0), bytes32(0)));
5050
token.grantRole(keccak256("MINTER_ROLE"), address(sale));
5151
}
5252

@@ -85,6 +85,7 @@ contract ERC721SaleBaseTest is TestHelper, IERC721SaleSignals {
8585
}
8686

8787
function testFactoryDetermineAddress(
88+
uint256 nonce,
8889
address _proxyOwner,
8990
address tokenOwner,
9091
address items,
@@ -95,9 +96,10 @@ contract ERC721SaleBaseTest is TestHelper, IERC721SaleSignals {
9596
vm.assume(tokenOwner != address(0));
9697
ERC721SaleFactory factory = new ERC721SaleFactory(address(this));
9798
address deployedAddr =
98-
factory.deploy(_proxyOwner, tokenOwner, items, implicitModeValidator, implicitModeProjectId);
99-
address predictedAddr =
100-
factory.determineAddress(_proxyOwner, tokenOwner, items, implicitModeValidator, implicitModeProjectId);
99+
factory.deploy(nonce, _proxyOwner, tokenOwner, items, implicitModeValidator, implicitModeProjectId);
100+
address predictedAddr = factory.determineAddress(
101+
nonce, _proxyOwner, tokenOwner, items, implicitModeValidator, implicitModeProjectId
102+
);
101103
assertEq(deployedAddr, predictedAddr);
102104
}
103105

test/tokens/ERC721/utility/sale/ERC721SaleMint.t.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ contract ERC721SaleMintTest is TestHelper, IERC721SaleSignals, IMerkleProofSingl
4040

4141
function setUpFromFactory() public {
4242
ERC721SaleFactory factory = new ERC721SaleFactory(address(this));
43-
sale = ERC721Sale(factory.deploy(proxyOwner, address(this), address(token), address(0), bytes32(0)));
43+
sale = ERC721Sale(factory.deploy(0, proxyOwner, address(this), address(token), address(0), bytes32(0)));
4444
token.grantRole(keccak256("MINTER_ROLE"), address(sale));
4545
}
4646

0 commit comments

Comments
 (0)