Skip to content
This repository has been archived by the owner on Sep 9, 2022. It is now read-only.

Commit

Permalink
better interfaces, _isOwnerOrProxy helper
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderatallah committed Oct 16, 2019
1 parent 52bcaf3 commit 59d2e0c
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 33 deletions.
17 changes: 8 additions & 9 deletions contracts/IFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,13 @@ interface IFactory {
*/
function mint(uint256 _optionId, address _toAddress, uint256 _amount, bytes calldata _data) external;

/**
* @dev Transfers assets to the _to address, minting them out of the factory if needed.
* Should call the same logic under `mint`
* @param _from The address to transfer from (ignored)
* @param _to The address to transfer to
* @param _optionId the option id
* @param _amount amount of the option to mint
* @param _data Extra data to pass
*/
///////
// Get things to work on OpenSea with mock methods below
///////

function safeTransferFrom(address _from, address _to, uint256 _optionId, uint256 _amount, bytes calldata _data) external;

function balanceOf(address _owner, uint256 _optionId) external view returns (uint256);

function isApprovedForAll(address _owner, address _operator) external view returns (bool);
}
30 changes: 19 additions & 11 deletions contracts/ILootBox.sol
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,9 @@ interface ILootBox {
*/
function open(uint256 _optionId, address _toAddress, uint256 _amount) external;

/**
* @dev Transfers assets to the _to address, minting them out of the factory if needed.
* Should call the same logic under `mint`
* @param _from The address to transfer from (ignored)
* @param _to The address to transfer to
* @param _optionId the option id
* @param _amount amount of the option to mint
* @param _data Extra data to pass
*/
function safeTransferFrom(address _from, address _to, uint256 _optionId, uint256 _amount, bytes calldata _data) external;

////////
// ADMINISTRATION
////////

/**
* @dev If the tokens for some class are pre-minted and owned by the
Expand All @@ -76,4 +68,20 @@ interface ILootBox {
* creating/minting into the nft address
*/
function resetClass(uint256 _classId) external;

/**
* @dev Withdraw lootbox revenue
* Only accessible by contract owner
*/
function withdraw() external;

///////
// Get things to work on OpenSea with mock methods below
///////

function safeTransferFrom(address _from, address _to, uint256 _optionId, uint256 _amount, bytes calldata _data) external;

function balanceOf(address _owner, uint256 _optionId) external view returns (uint256);

function isApprovedForAll(address _owner, address _operator) external view returns (bool);
}
21 changes: 9 additions & 12 deletions contracts/MyFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ contract MyFactory is IFactory, Ownable {
address _owner,
uint256 _optionId
) public view returns (uint256) {
ProxyRegistry proxyRegistry = ProxyRegistry(proxyRegistryAddress);
if (owner() != _owner && address(proxyRegistry.proxies(owner())) != _owner) {
if (!_isOwnerOrProxy(_owner)) {
// Only the factory owner or owner's proxy can have supply
return 0;
}
Expand Down Expand Up @@ -145,16 +144,7 @@ contract MyFactory is IFactory, Ownable {
address _owner,
address _operator
) public view returns (bool) {
if (owner() == _owner && _owner == _operator) {
return true;
}

ProxyRegistry proxyRegistry = ProxyRegistry(proxyRegistryAddress);
if (owner() == _owner && address(proxyRegistry.proxies(_owner)) == _operator) {
return true;
}

return false;
return owner() == _owner && _isOwnerOrProxy(_operator);
}

function _canMint(
Expand All @@ -165,4 +155,11 @@ contract MyFactory is IFactory, Ownable {
uint256 optionId = uint256(_option);
return _amount > 0 && balanceOf(_fromAddress, optionId) >= _amount;
}

function _isOwnerOrProxy(
address _address
) internal view returns (bool) {
ProxyRegistry proxyRegistry = ProxyRegistry(proxyRegistryAddress);
return owner() == _address || address(proxyRegistry.proxies(owner())) == _address;
}
}
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5523,7 +5523,7 @@ ms@^2.1.1:

"multi-token-standard@github:ProjectOpenSea/multi-token-standard":
version "0.8.4"
resolved "https://codeload.github.com/ProjectOpenSea/multi-token-standard/tar.gz/fd5a9089307066067c46606b028fbeaff370c464"
resolved "https://codeload.github.com/ProjectOpenSea/multi-token-standard/tar.gz/de2d0af8852a588c1eb7160b1a5b742d5fa8ce90"

mute-stdout@^1.0.0:
version "1.0.1"
Expand Down

0 comments on commit 59d2e0c

Please sign in to comment.