Skip to content

Commit

Permalink
added events to EIP2981TL contracts to make off-chain indexing easier
Browse files Browse the repository at this point in the history
  • Loading branch information
mpeyfuss committed Dec 27, 2023
1 parent 82dddb5 commit c980500
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/access/OwnableAccessControl.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ abstract contract OwnableAccessControl is Ownable {
/// @param role The bytes32 role created in the inheriting contract
event RoleChange(address indexed from, address indexed user, bool indexed approved, bytes32 role);

/// @param from - address that authorized the revoke
/// @param from Address that authorized the revoke
event AllRolesRevoked(address indexed from);

/*//////////////////////////////////////////////////////////////////////////
Expand Down
14 changes: 13 additions & 1 deletion src/royalties/EIP2981TL.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {IEIP2981} from "src/royalties/IEIP2981.sol";
/// while allowing for specific token overrides
/// @dev Follows EIP-2981 (https://eips.ethereum.org/EIPS/eip-2981)
/// @author transientlabs.xyz
/// @custom:version 3.0.0
/// @custom:version 3.1.0
abstract contract EIP2981TL is IEIP2981, ERC165 {
/*//////////////////////////////////////////////////////////////////////////
Types
Expand All @@ -29,6 +29,16 @@ abstract contract EIP2981TL is IEIP2981, ERC165 {
uint256 private _defaultPercentage;
mapping(uint256 => RoyaltySpec) private _tokenOverrides;

/*//////////////////////////////////////////////////////////////////////////
Events
//////////////////////////////////////////////////////////////////////////*/

/// @dev Event to emit when the default roylaty is updated
event DefaultRoyaltyUpdate(address indexed sender, address newRecipient, uint256 newPercentage);

/// @dev Event to emit when a token royalty is overriden
event TokenRoyaltyOverride(address indexed sender, uint256 indexed tokenId, address newRecipient, uint256 newPercentage);

/*//////////////////////////////////////////////////////////////////////////
Errors
//////////////////////////////////////////////////////////////////////////*/
Expand Down Expand Up @@ -61,6 +71,7 @@ abstract contract EIP2981TL is IEIP2981, ERC165 {
if (newPercentage > 10_000) revert MaxRoyaltyError();
_defaultRecipient = newRecipient;
_defaultPercentage = newPercentage;
emit DefaultRoyaltyUpdate(msg.sender, newRecipient, newPercentage);
}

/// @notice Function to override royalty spec on a specific token
Expand All @@ -72,6 +83,7 @@ abstract contract EIP2981TL is IEIP2981, ERC165 {
if (newPercentage > 10_000) revert MaxRoyaltyError();
_tokenOverrides[tokenId].recipient = newRecipient;
_tokenOverrides[tokenId].percentage = newPercentage;
emit TokenRoyaltyOverride(msg.sender, tokenId, newRecipient, newPercentage);
}

/*//////////////////////////////////////////////////////////////////////////
Expand Down
14 changes: 13 additions & 1 deletion src/upgradeable/royalties/EIP2981TLUpgradeable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {IEIP2981} from "src/royalties/IEIP2981.sol";
/// while allowing for specific token overrides
/// @dev Follows EIP-2981 (https://eips.ethereum.org/EIPS/eip-2981)
/// @author transientlabs.xyz
/// @custom:version 3.0.0
/// @custom:version 3.1.0
abstract contract EIP2981TLUpgradeable is IEIP2981, ERC165Upgradeable {
/*//////////////////////////////////////////////////////////////////////////
Types
Expand Down Expand Up @@ -47,6 +47,16 @@ abstract contract EIP2981TLUpgradeable is IEIP2981, ERC165Upgradeable {

uint256 public constant BASIS = 10_000;

/*//////////////////////////////////////////////////////////////////////////
Events
//////////////////////////////////////////////////////////////////////////*/

/// @dev Event to emit when the default roylaty is updated
event DefaultRoyaltyUpdate(address indexed sender, address newRecipient, uint256 newPercentage);

/// @dev Event to emit when a token royalty is overriden
event TokenRoyaltyOverride(address indexed sender, uint256 indexed tokenId, address newRecipient, uint256 newPercentage);

/*//////////////////////////////////////////////////////////////////////////
Errors
//////////////////////////////////////////////////////////////////////////*/
Expand Down Expand Up @@ -91,6 +101,7 @@ abstract contract EIP2981TLUpgradeable is IEIP2981, ERC165Upgradeable {
if (newPercentage > 10_000) revert MaxRoyaltyError();
$.defaultRecipient = newRecipient;
$.defaultPercentage = newPercentage;
emit DefaultRoyaltyUpdate(msg.sender, newRecipient, newPercentage);
}

/// @notice Function to override royalty spec on a specific token
Expand All @@ -103,6 +114,7 @@ abstract contract EIP2981TLUpgradeable is IEIP2981, ERC165Upgradeable {
if (newPercentage > 10_000) revert MaxRoyaltyError();
$.tokenOverrides[tokenId].recipient = newRecipient;
$.tokenOverrides[tokenId].percentage = newPercentage;
emit TokenRoyaltyOverride(msg.sender, tokenId, newRecipient, newPercentage);
}

/*//////////////////////////////////////////////////////////////////////////
Expand Down
9 changes: 9 additions & 0 deletions test/royalties/EIP2981TL.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ contract TestEIP2981TL is Test {
vm.expectRevert(EIP2981TL.ZeroAddressError.selector);
} else if (percentage > 10_000) {
vm.expectRevert(EIP2981TL.MaxRoyaltyError.selector);
} else {
vm.expectEmit(true, true, true, true);
emit EIP2981TL.DefaultRoyaltyUpdate(address(this), recipient, percentage);
}
mockContract = new MockEIP2981TL(recipient, uint256(percentage));
if (recipient != address(0) && percentage <= 10_000) {
Expand Down Expand Up @@ -45,6 +48,9 @@ contract TestEIP2981TL is Test {
vm.expectRevert(EIP2981TL.ZeroAddressError.selector);
} else if (percentage > 10_000) {
vm.expectRevert(EIP2981TL.MaxRoyaltyError.selector);
} else {
vm.expectEmit(true, true, true, true);
emit EIP2981TL.DefaultRoyaltyUpdate(address(this), recipient, percentage);
}
mockContract.setDefaultRoyalty(recipient, uint256(percentage));
if (recipient != address(0) && percentage <= 10_000) {
Expand All @@ -67,6 +73,9 @@ contract TestEIP2981TL is Test {
vm.expectRevert(EIP2981TL.ZeroAddressError.selector);
} else if (percentage > 10_000) {
vm.expectRevert(EIP2981TL.MaxRoyaltyError.selector);
} else {
vm.expectEmit(true, true, true, true);
emit EIP2981TL.TokenRoyaltyOverride(address(this), tokenId, recipient, percentage);
}
mockContract.setTokenRoyalty(tokenId, recipient, uint256(percentage));
if (recipient != address(0) && percentage <= 10_000) {
Expand Down
9 changes: 9 additions & 0 deletions test/upgradeable/royalties/EIP2981TLUpgradeable.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ contract TestEIP2981TLUpgradeable is Test {
vm.expectRevert(EIP2981TLUpgradeable.ZeroAddressError.selector);
} else if (percentage > 10_000) {
vm.expectRevert(EIP2981TLUpgradeable.MaxRoyaltyError.selector);
} else {
vm.expectEmit(true, true, true, true);
emit EIP2981TLUpgradeable.DefaultRoyaltyUpdate(address(this), recipient, percentage);
}
mockContract.initialize(recipient, uint256(percentage));
if (recipient != address(0) && percentage <= 10_000) {
Expand Down Expand Up @@ -48,6 +51,9 @@ contract TestEIP2981TLUpgradeable is Test {
vm.expectRevert(EIP2981TLUpgradeable.ZeroAddressError.selector);
} else if (percentage > 10_000) {
vm.expectRevert(EIP2981TLUpgradeable.MaxRoyaltyError.selector);
} else {
vm.expectEmit(true, true, true, true);
emit EIP2981TLUpgradeable.DefaultRoyaltyUpdate(address(this), recipient, percentage);
}
mockContract.setDefaultRoyalty(recipient, uint256(percentage));
if (recipient != address(0) && percentage <= 10_000) {
Expand All @@ -71,6 +77,9 @@ contract TestEIP2981TLUpgradeable is Test {
vm.expectRevert(EIP2981TLUpgradeable.ZeroAddressError.selector);
} else if (percentage > 10_000) {
vm.expectRevert(EIP2981TLUpgradeable.MaxRoyaltyError.selector);
} else {
vm.expectEmit(true, true, true, true);
emit EIP2981TLUpgradeable.TokenRoyaltyOverride(address(this), tokenId, recipient, percentage);
}
mockContract.setTokenRoyalty(tokenId, recipient, uint256(percentage));
if (recipient != address(0) && percentage <= 10_000) {
Expand Down

0 comments on commit c980500

Please sign in to comment.