-
Notifications
You must be signed in to change notification settings - Fork 527
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
Yash/pack #175
Yash/pack #175
Conversation
|
function openPack(uint256 _packId, uint256 _amountToOpen) | ||
external | ||
nonReentrant | ||
whenNotPaused | ||
returns (Token[] memory) | ||
{ | ||
address opener = _msgSender(); | ||
|
||
require(opener == tx.origin, "opener must be eoa"); | ||
require(balanceOf(opener, _packId) >= _amountToOpen, "opening more than owned"); | ||
|
||
PackInfo memory pack = packInfo[_packId]; | ||
require(pack.openStartTimestamp < block.timestamp, "cannot open yet"); | ||
|
||
Token[] memory rewardUnits = getRewardUnits(_packId, _amountToOpen, pack.amountDistributedPerOpen, pack); | ||
|
||
_burn(_msgSender(), _packId, _amountToOpen); | ||
|
||
_transferTokenBatch(address(this), _msgSender(), rewardUnits); | ||
|
||
emit PackOpened(_packId, _msgSender(), _amountToOpen, rewardUnits); | ||
|
||
return rewardUnits; | ||
} |
Check warning
Code scanning / Slither
Dangerous usage of `tx.origin`
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -75,8 +78,22 @@ | |||
address _to, | |||
Token[] memory _tokens | |||
) internal { | |||
uint256 nativeTokenValue; |
Check warning
Code scanning / Slither
Uninitialized local variables
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Getter functions | ||
//////////////////////////////////////////////////////////////*/ | ||
|
||
/// @dev Returns the underlying contents of a pack. | ||
function getPackContents(uint256 _packId) | ||
external | ||
view | ||
returns (Token[] memory contents, uint256[] memory perUnitAmounts) | ||
{ | ||
PackInfo memory pack = packInfo[_packId]; | ||
uint256 total = getTokenCountOfBundle(_packId); | ||
contents = new Token[](total); | ||
perUnitAmounts = new uint256[](total); | ||
|
||
for (uint256 i = 0; i < total; i += 1) { | ||
contents[i] = getTokenOfBundle(_packId, i); | ||
perUnitAmounts[i] = pack.perUnitAmounts[i]; | ||
} | ||
} | ||
|
||
/*/////////////////////////////////////////////////////////////// | ||
Internal functions | ||
//////////////////////////////////////////////////////////////*/ | ||
|
||
/// @dev Returns whether owner can be set in the given execution context. | ||
function _canSetOwner() internal view override returns (bool) { | ||
return hasRole(DEFAULT_ADMIN_ROLE, _msgSender()); | ||
} | ||
|
||
/// @dev Returns whether royalty info can be set in the given execution context. | ||
function _canSetRoyaltyInfo() internal view override returns (bool) { | ||
return hasRole(DEFAULT_ADMIN_ROLE, _msgSender()); | ||
} | ||
|
||
/// @dev Returns whether contract metadata can be set in the given execution context. | ||
function _canSetContractURI() internal view override returns (bool) { | ||
return hasRole(DEFAULT_ADMIN_ROLE, _msgSender()); | ||
} | ||
|
||
/*/////////////////////////////////////////////////////////////// | ||
Miscellaneous | ||
//////////////////////////////////////////////////////////////*/ | ||
|
||
function generateRandomValue() internal view returns (uint256 random) { | ||
random = uint256(keccak256(abi.encodePacked(_msgSender(), blockhash(block.number - 1), block.difficulty))); | ||
} | ||
|
||
/** | ||
* @dev See {ERC1155-_beforeTokenTransfer}. | ||
*/ | ||
function _beforeTokenTransfer( | ||
address operator, | ||
address from, | ||
address to, | ||
uint256[] memory ids, | ||
uint256[] memory amounts, | ||
bytes memory data | ||
) internal virtual override { | ||
super._beforeTokenTransfer(operator, from, to, ids, amounts, data); | ||
|
||
// if transfer is restricted on the contract, we still want to allow burning and minting | ||
if (!hasRole(TRANSFER_ROLE, address(0)) && from != address(0) && to != address(0)) { | ||
require(hasRole(TRANSFER_ROLE, from) || hasRole(TRANSFER_ROLE, to), "restricted to TRANSFER_ROLE holders."); | ||
} | ||
|
||
if (from == address(0)) { | ||
for (uint256 i = 0; i < ids.length; ++i) { | ||
totalSupply[ids[i]] += amounts[i]; | ||
} | ||
} | ||
|
||
if (to == address(0)) { | ||
for (uint256 i = 0; i < ids.length; ++i) { | ||
totalSupply[ids[i]] -= amounts[i]; | ||
} | ||
} | ||
} | ||
|
||
/// @dev See EIP-2771 | ||
function _msgSender() | ||
internal | ||
view | ||
virtual | ||
override(ContextUpgradeable, ERC2771ContextUpgradeable) | ||
returns (address sender) | ||
{ | ||
return ERC2771ContextUpgradeable._msgSender(); | ||
} | ||
|
||
/// @dev See EIP-2771 | ||
function _msgData() | ||
internal | ||
view | ||
virtual | ||
override(ContextUpgradeable, ERC2771ContextUpgradeable) | ||
returns (bytes calldata) | ||
{ | ||
return ERC2771ContextUpgradeable._msgData(); | ||
} | ||
} |
Check warning
Code scanning / Slither
Missing inheritance
@@ -15,8 +15,11 @@ | |||
import "../lib/CurrencyTransferLib.sol"; | |||
|
|||
contract TokenStore is TokenBundle, ERC721Holder, ERC1155Holder { | |||
/// @dev The address interpreted as native token of the chain. | |||
address public constant NATIVE_TOKEN = 0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE; |
Check warning
Code scanning / Slither
Variable names too similar
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approve
No description provided.