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

QoL changes for dashboard + crosschain modules #185

Open
wants to merge 4 commits into
base: dev
Choose a base branch
from
Open
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
5 changes: 4 additions & 1 deletion src/module/token/minting/MintableERC1155.sol
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,10 @@ contract MintableERC1155 is
override
returns (bytes memory)
{
if (!OwnableRoles(address(this)).hasAllRoles(msg.sender, Role._MINTER_ROLE)) {
if (
OwnableRoles(address(this)).owner() != msg.sender
&& !OwnableRoles(address(this)).hasAllRoles(msg.sender, Role._MINTER_ROLE)
) {
revert MintableRequestUnauthorized();
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/module/token/minting/MintableERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,10 @@ contract MintableERC20 is
override
returns (bytes memory)
{
if (!OwnableRoles(address(this)).hasAllRoles(msg.sender, Role._MINTER_ROLE)) {
if (
OwnableRoles(address(this)).owner() != msg.sender
&& !OwnableRoles(address(this)).hasAllRoles(msg.sender, Role._MINTER_ROLE)
) {
revert MintableRequestUnauthorized();
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/module/token/minting/MintableERC721.sol
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,10 @@ contract MintableERC721 is
override
returns (bytes memory)
{
if (!OwnableRoles(address(this)).hasAllRoles(msg.sender, Role._MINTER_ROLE)) {
if (
OwnableRoles(address(this)).owner() != msg.sender
&& !OwnableRoles(address(this)).hasAllRoles(msg.sender, Role._MINTER_ROLE)
) {
revert MintableRequestUnauthorized();
}
}
Expand Down
18 changes: 18 additions & 0 deletions src/module/token/transferable/TransferableERC1155.sol
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@ contract TransferableERC1155 is Module, BeforeTransferCallbackERC1155, BeforeBat
/// @notice Emitted on attempt to transfer a token when transfers are disabled.
error TransferDisabled();

/*//////////////////////////////////////////////////////////////
EVENTS
//////////////////////////////////////////////////////////////*/

/// @notice Emitted on attempt to transfer a token when transfers are disabled.
event TransferEnableFor(address indexed target, bool enabled);

/*//////////////////////////////////////////////////////////////
MODULE CONFIG
//////////////////////////////////////////////////////////////*/
Expand All @@ -60,8 +67,18 @@ contract TransferableERC1155 is Module, BeforeTransferCallbackERC1155, BeforeBat

config.requiredInterfaces = new bytes4[](1);
config.requiredInterfaces[0] = 0xd9b67a26; // ERC1155

config.registerInstallationCallback = true;
}

/// @dev Called by a Core into an Module during the installation of the Module.
function onInstall(bytes calldata data) external {
_transferableStorage().transferEnabled = true;
}

/// @dev Called by a Core into an Module during the uninstallation of the Module.
function onUninstall(bytes calldata data) external {}

/*//////////////////////////////////////////////////////////////
CALLBACK FUNCTIONS
//////////////////////////////////////////////////////////////*/
Expand Down Expand Up @@ -120,6 +137,7 @@ contract TransferableERC1155 is Module, BeforeTransferCallbackERC1155, BeforeBat
/// @notice Set transferability for an operator for a token.
function setTransferableFor(address target, bool enableTransfer) external {
_transferableStorage().transferEnabledFor[target] = enableTransfer;
emit TransferEnableFor(target, enableTransfer);
}

/*//////////////////////////////////////////////////////////////
Expand Down
18 changes: 18 additions & 0 deletions src/module/token/transferable/TransferableERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ contract TransferableERC20 is Module, BeforeTransferCallbackERC20 {
/// @notice Emitted on attempt to transfer a token when transfers are disabled.
error TransferDisabled();

/*//////////////////////////////////////////////////////////////
EVENTS
//////////////////////////////////////////////////////////////*/

/// @notice Emitted on attempt to transfer a token when transfers are disabled.
event TransferEnableFor(address indexed target, bool enabled);

/*//////////////////////////////////////////////////////////////
MODULE CONFIG
//////////////////////////////////////////////////////////////*/
Expand All @@ -54,8 +61,18 @@ contract TransferableERC20 is Module, BeforeTransferCallbackERC20 {
FallbackFunction({selector: this.setTransferable.selector, permissionBits: Role._MANAGER_ROLE});
config.fallbackFunctions[3] =
FallbackFunction({selector: this.setTransferableFor.selector, permissionBits: Role._MANAGER_ROLE});

config.registerInstallationCallback = true;
}

/// @dev Called by a Core into an Module during the installation of the Module.
function onInstall(bytes calldata data) external {
_transferableStorage().transferEnabled = true;
}

/// @dev Called by a Core into an Module during the uninstallation of the Module.
function onUninstall(bytes calldata data) external {}

/*//////////////////////////////////////////////////////////////
CALLBACK FUNCTIONS
//////////////////////////////////////////////////////////////*/
Expand Down Expand Up @@ -93,6 +110,7 @@ contract TransferableERC20 is Module, BeforeTransferCallbackERC20 {
/// @notice Set transferability for an address for a token.
function setTransferableFor(address target, bool enableTransfer) external {
_transferableStorage().transferEnabledFor[target] = enableTransfer;
emit TransferEnableFor(target, enableTransfer);
}

/*//////////////////////////////////////////////////////////////
Expand Down
18 changes: 18 additions & 0 deletions src/module/token/transferable/TransferableERC721.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ contract TransferableERC721 is Module, BeforeTransferCallbackERC721 {
/// @notice Emitted on attempt to transfer a token when transfers are disabled.
error TransferDisabled();

/*//////////////////////////////////////////////////////////////
EVENTS
//////////////////////////////////////////////////////////////*/

/// @notice Emitted on attempt to transfer a token when transfers are disabled.
event TransferEnableFor(address indexed target, bool enabled);

/*//////////////////////////////////////////////////////////////
MODULE CONFIG
//////////////////////////////////////////////////////////////*/
Expand All @@ -57,8 +64,18 @@ contract TransferableERC721 is Module, BeforeTransferCallbackERC721 {

config.requiredInterfaces = new bytes4[](1);
config.requiredInterfaces[0] = 0x80ac58cd; // ERC721.

config.registerInstallationCallback = true;
}

/// @dev Called by a Core into an Module during the installation of the Module.
function onInstall(bytes calldata data) external {
_transferableStorage().transferEnabled = true;
}

/// @dev Called by a Core into an Module during the uninstallation of the Module.
function onUninstall(bytes calldata data) external {}

/*//////////////////////////////////////////////////////////////
CALLBACK FUNCTIONS
//////////////////////////////////////////////////////////////*/
Expand Down Expand Up @@ -96,6 +113,7 @@ contract TransferableERC721 is Module, BeforeTransferCallbackERC721 {
/// @notice Set transferability for an address for a token.
function setTransferableFor(address target, bool enableTransfer) external {
_transferableStorage().transferEnabledFor[target] = enableTransfer;
emit TransferEnableFor(target, enableTransfer);
}

/*//////////////////////////////////////////////////////////////
Expand Down
14 changes: 13 additions & 1 deletion test/module/minting/MintableERC1155.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ contract MintableERC1155Test is Test {
);

// Check minted balance
assertEq(core.balanceOf(address(0x123), tokenId), amount);
assertEq(core.balanceOf(tokenRecipient, tokenId), amount);

uint256 salePrice = (amount * mintRequest.pricePerUnit);
(uint256 primarySaleAmount, uint256 platformFeeAmount) =
Expand All @@ -198,6 +198,18 @@ contract MintableERC1155Test is Test {
assertEq(feeRecipient.balance, platformFeeAmount, "feeRecipient balance");
}

function test_simple_mint() public {
vm.prank(owner);
core.mint(owner, tokenId, amount, "", "");

assertEq(core.balanceOf(owner, tokenId), amount);

vm.prank(permissionedActor);
core.mint(permissionedActor, tokenId, amount, "", "");

assertEq(core.balanceOf(permissionedActor, tokenId), amount);
}

function test_mint_revert_unableToDecodeArgs() public {
vm.deal(tokenRecipient, 100 ether);

Expand Down
12 changes: 12 additions & 0 deletions test/module/minting/MintableERC20.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,18 @@ contract MintableERC20Test is Test {
assertEq(feeRecipient.balance, platformFeeAmount, "feeRecipient balance");
}

function test_simple_mint() public {
vm.prank(owner);
core.mint(owner, amount, "");

assertEq(core.balanceOf(owner), amount);

vm.prank(permissionedActor);
core.mint(permissionedActor, amount, "");

assertEq(core.balanceOf(permissionedActor), amount);
}

function test_mint_revert_unableToDecodeArgs() public {
vm.deal(tokenRecipient, 100 ether);

Expand Down
14 changes: 13 additions & 1 deletion test/module/minting/MintableERC721.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ contract MintableERC721Test is Test {
);

// Check minted balance
assertEq(core.balanceOf(address(0x123)), amount);
assertEq(core.balanceOf(tokenRecipient), amount);

uint256 salePrice = (amount * mintRequest.pricePerUnit);
(uint256 primarySaleAmount, uint256 platformFeeAmount) =
Expand All @@ -196,6 +196,18 @@ contract MintableERC721Test is Test {
assertEq(feeRecipient.balance, platformFeeAmount, "feeRecipient balance");
}

function test_simple_mint() public {
vm.prank(owner);
core.mint(owner, amount, "", "");

assertEq(core.balanceOf(owner), amount);

vm.prank(permissionedActor);
core.mint(permissionedActor, amount, "", "");

assertEq(core.balanceOf(permissionedActor), amount);
}

function test_mint_revert_unableToDecodeArgs() public {
vm.deal(tokenRecipient, 100 ether);

Expand Down