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

Adds standard collect events #126

Merged
merged 1 commit into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions contracts/interfaces/modules/collect/ICollectModule.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,26 @@ import { Collect } from "contracts/lib/modules/Collect.sol";
/// @notice The collect module enables IP assets to be minted as NFTs mirroring
/// their binding IP assets in a franchise-configurable format.
interface ICollectModule {

/// @dev Emits when a Collect action is invoked.
/// TODO: Once global IPs are supported, we can index the collect NFTs as well.
event Collected(
uint256 indexed franchiseid_,
uint256 indexed ipAssetId_,
address indexed collector_,
address collectNft_,
uint256 collectNftId_,
bytes collectData_,
bytes collectNftData_
);

/// @dev Emits when a new collect NFT is deployed.
event NewCollectNFT(
uint256 indexed franchiseId_,
uint256 indexed ipAssetId_,
address collectNFT_
);

/// @notice Initializes the collect module for a specific IP asset.
/// @param initCollectParams_ Collect module init data, including IP asset
/// id, collect NFT impl address, and generic unformatted init data.
Expand Down
14 changes: 14 additions & 0 deletions contracts/modules/collect/CollectModuleBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,17 @@ abstract contract CollectModuleBase is AccessControlledUpgradeable, ICollectModu
// Perform any additional collect module processing.
_collect(collectParams_);

// Emit the Collect event.
emit Collected(
franchiseId,
ipAssetId,
collectParams_.collector,
collectNft,
collectNftId,
collectParams_.collectData,
collectParams_.collectNftData
);

return (collectNft, collectNftId);
}

Expand Down Expand Up @@ -174,6 +185,9 @@ abstract contract CollectModuleBase is AccessControlledUpgradeable, ICollectModu
data: initData_
}));
$.collectInfo[franchiseId_][ipAssetId_].collectNft = collectNft;

// Emit the event indicating a new Collect NFT was created.
emit NewCollectNFT(franchiseId_, ipAssetId_, collectNft);
}
return collectNft;
}
Expand Down
51 changes: 51 additions & 0 deletions test/foundry/modules/collect/BaseCollectModuleTest.sol
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,25 @@ import { Errors } from "contracts/lib/Errors.sol";
/// @notice Provides a set of reusable tests for ERC-721 implementations.
contract BaseCollectModuleTest is BaseTest {

// TODO: Currently, when compiling with 0.8.21, there is a known ICE bug that prevents us from emitting from the interface directly e.g. via ICollectModule.Collected - these two should be refactored in favor of emitting through the interface once we officially migrate to 0.8.22.
// See: https://github.com/ethereum/solidity/issues/14430
event Collected(
uint256 indexed franchiseid_,
uint256 indexed ipAssetId_,
address indexed collector_,
address collectNft_,
uint256 collectNftId_,
bytes collectData_,
bytes collectNftData_
);

// TODO: Refactor once we migrate to compiling via 0.8.22 as explained above.
event NewCollectNFT(
uint256 indexed franchiseId_,
uint256 indexed ipAssetId_,
address collectNFT_
);

// In the base collect module, an IP asset configured with a zero address
// collect NFT impl means that the module-wide default should be used.
address public constant DEFAULT_COLLECT_NFT_IMPL_CONFIG = address(0);
Expand Down Expand Up @@ -73,6 +92,22 @@ contract BaseCollectModuleTest is BaseTest {
/// @notice Tests that collects with the module-default collect NFT succeed.
function test_CollectModuleCollectDefaultCollectNFT(uint8 ipAssetType) createIpAsset(collector, ipAssetType) public {
assertEq(collectModule.getCollectNFT(franchiseId, ipAssetId), address(0));
vm.expectEmit(true, true, false, false, address(collectModule));
emit NewCollectNFT(
franchiseId,
ipAssetId,
defaultCollectNftImpl
);
vm.expectEmit(true, true, true, false, address(collectModule));
emit Collected(
franchiseId,
ipAssetId,
collector,
defaultCollectNftImpl,
0,
"",
""
);
(address collectNft, uint256 collectNftId) = _collect(franchiseId, ipAssetId);
assertEq(collectModule.getCollectNFT(franchiseId, ipAssetId), collectNft);
assertTrue(ICollectNFT(collectNft).ownerOf(collectNftId) == cal);
Expand All @@ -82,6 +117,22 @@ contract BaseCollectModuleTest is BaseTest {
/// @notice Tests that collects with customized collect NFTs succeed.
function test_CollectModuleCollectCustomCollectNFT(uint8 ipAssetType) public createIpAsset(collector, ipAssetType) {
assertEq(collectModule.getCollectNFT(franchiseId, ipAssetId), address(0));
vm.expectEmit(true, true, false, false, address(collectModule));
emit NewCollectNFT(
franchiseId,
ipAssetId,
defaultCollectNftImpl
);
vm.expectEmit(true, true, true, false, address(collectModule));
emit Collected(
franchiseId,
ipAssetId,
collector,
defaultCollectNftImpl,
0,
"",
""
);
(address collectNft, uint256 collectNftId) = _collect(franchiseId, ipAssetId);
assertEq(collectModule.getCollectNFT(franchiseId, ipAssetId), collectNft);
assertTrue(ICollectNFT(collectNft).ownerOf(collectNftId) == cal);
Expand Down