Skip to content

Pack: using Chainlink VRF v2 (Direct Funding Method) #296

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

Merged
merged 28 commits into from
Jan 4, 2023
Merged

Conversation

nkrishang
Copy link
Contributor

Introduces PackVRFDirect: uses Chainlink VRF to get robust random numbers (instead of pseudo-random numbers from block variables) to make the process of selection of rewards fair i.e. the chance of receiving a reward is a true representation of how rare the reward is.

@nkrishang nkrishang added the enhancement New feature or request label Dec 14, 2022
@nkrishang nkrishang self-assigned this Dec 14, 2022
* Use other forwarders only if there's a strong reason to bypass this check.
*/
address[] memory forwarders = new address[](_trustedForwarders.length + 1);
uint256 i;

Check warning

Code scanning / Slither

Uninitialized local variables

PackVRFDirect.initialize(address,string,string,string,address[],address,uint256).i (contracts/pack/PackVRFDirect.sol#131) is a local variable never initialized
Comment on lines 30 to 495
}
}

/*///////////////////////////////////////////////////////////////
Getter functions
//////////////////////////////////////////////////////////////*/

/// @dev Returns the underlying contents of a pack.
function getPackContents(uint256 _packId)
public
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 = pack.perUnitAmounts;
}

/*///////////////////////////////////////////////////////////////
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
//////////////////////////////////////////////////////////////*/

/**
* @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(transferRole, address(0)) && from != address(0) && to != address(0)) {
require(hasRole(transferRole, from) || hasRole(transferRole, to), "!TRANSFER_ROLE");
}

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

PackVRFDirect (contracts/pack/PackVRFDirect.sol#30-495) should inherit from IThirdwebContract (contracts/interfaces/IThirdwebContract.sol#4-19)
*/
function createPack(
Token[] calldata contents,
uint256[] calldata numOfRewardUnits,

Check warning

Code scanning / Slither

Variable names too similar

Variable IPackVRFDirect.createPack(ITokenBundle.Token[],uint256[],string,uint128,uint128,address).numOfRewardUnits (contracts/interfaces/IPackVRFDirect.sol#58) is too similar to PackVRFDirect.escrowPackContents(ITokenBundle.Token[],uint256[],string,uint256,uint256,bool).sumOfRewardUnits (contracts/pack/PackVRFDirect.sol#326)
@kumaryash90 kumaryash90 merged commit 3f61125 into main Jan 4, 2023
@kumaryash90 kumaryash90 deleted the pack-vrf branch April 24, 2023 12:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants