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
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
752c766
add chainlink contracts package
nkrishang Dec 14, 2022
ce926f0
Create PackVRFDirect: VRF with Direct payment
nkrishang Dec 14, 2022
383045a
Burn packs in the claimRewards function instead
nkrishang Dec 14, 2022
18d7d3a
Remove addPackContents to bring down size
nkrishang Dec 14, 2022
75aa773
Change contract type Pack - Pack_VRF
nkrishang Dec 14, 2022
45cbbd6
Move pack test to dir
nkrishang Dec 14, 2022
f6437b2
Bug fix: expect randomWords to initially be empty.
nkrishang Dec 14, 2022
ef95876
Move PackVRFDirect events to interface
nkrishang Dec 14, 2022
b81ae86
Tests for PackVRFDirect
nkrishang Dec 14, 2022
4ab0356
PackVRFDirect: Update docs
nkrishang Dec 14, 2022
5803945
Add benchmark test: fulfillRandomness
nkrishang Dec 14, 2022
f0bdedd
Make openerToReqId public
nkrishang Dec 14, 2022
6b72666
Offer convenience public fn canClaimRewards
nkrishang Dec 14, 2022
4b18522
pkg update
nkrishang Dec 14, 2022
4713a32
fix canClaimRewards
joaquim-verges Dec 15, 2022
30639d2
pkg release
joaquim-verges Dec 15, 2022
897d77b
Add openPackAdnClaimRewards
nkrishang Dec 15, 2022
1c8e10d
pkg release
nkrishang Dec 15, 2022
0ede9ff
Add tests for openPackAndClaimRewards
nkrishang Dec 15, 2022
963c0f0
allow VRF wrapper to call claim rewards
joaquim-verges Dec 16, 2022
306ecaf
prevent calling open twice while in flight
joaquim-verges Dec 16, 2022
7d2196d
Add openPackAndClaim to interface
nkrishang Dec 16, 2022
6346e3a
pkg release
nkrishang Dec 16, 2022
7937052
Add tests for not being able to open pack while repvious req is in fl…
nkrishang Dec 16, 2022
1e49696
fulfillRandomWords: low gas failsafe
kumaryash90 Dec 22, 2022
7776202
merge main
kumaryash90 Dec 22, 2022
62f6271
Merge branch 'main' into pack-vrf
kumaryash90 Jan 4, 2023
08e609d
add WIP comment
kumaryash90 Jan 4, 2023
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
85 changes: 85 additions & 0 deletions contracts/interfaces/IPackVRFDirect.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.11;

import "../extension/interface/ITokenBundle.sol";

/**
* The thirdweb `Pack` contract is a lootbox mechanism. An account can bundle up arbitrary ERC20, ERC721 and ERC1155 tokens into
* a set of packs. A pack can then be opened in return for a selection of the tokens in the pack. The selection of tokens distributed
* on opening a pack depends on the relative supply of all tokens in the packs.
*/

interface IPackVRFDirect is ITokenBundle {
/**
* @notice All info relevant to packs.
*
* @param perUnitAmounts Mapping from a UID -> to the per-unit amount of that asset i.e. `Token` at that index.
* @param openStartTimestamp The timestamp after which packs can be opened.
* @param amountDistributedPerOpen The number of reward units distributed per open.
*/
struct PackInfo {
uint256[] perUnitAmounts;
uint128 openStartTimestamp;
uint128 amountDistributedPerOpen;
}

/// @notice Emitted when a set of packs is created.
event PackCreated(uint256 indexed packId, address recipient, uint256 totalPacksCreated);

/// @notice Emitted when the opening of a pack is requested.
event PackOpenRequested(address indexed opener, uint256 indexed packId, uint256 amountToOpen, uint256 requestId);

/// @notice Emitted when Chainlink VRF fulfills a random number request.
event PackRandomnessFulfilled(uint256 indexed packId, uint256 indexed requestId);

/// @notice Emitted when a pack is opened.
event PackOpened(
uint256 indexed packId,
address indexed opener,
uint256 numOfPacksOpened,
Token[] rewardUnitsDistributed
);

/**
* @notice Creates a pack with the stated contents.
*
* @param contents The reward units to pack in the packs.
* @param numOfRewardUnits The number of reward units to create, for each asset specified in `contents`.
* @param packUri The (metadata) URI assigned to the packs created.
* @param openStartTimestamp The timestamp after which packs can be opened.
* @param amountDistributedPerOpen The number of reward units distributed per open.
* @param recipient The recipient of the packs created.
*
* @return packId The unique identifer of the created set of packs.
* @return packTotalSupply The total number of packs created.
*/
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)
string calldata packUri,
uint128 openStartTimestamp,
uint128 amountDistributedPerOpen,
address recipient
) external payable returns (uint256 packId, uint256 packTotalSupply);

/**
* @notice Lets a pack owner request to open a pack.
*
* @param packId The identifier of the pack to open.
* @param amountToOpen The number of packs to open at once.
*/
function openPack(uint256 packId, uint256 amountToOpen) external returns (uint256 requestId);

/// @notice Called by a pack opener to claim rewards from the opened pack.
function claimRewards() external returns (Token[] memory rewardUnits);

/// @notice Called by a pack opener to open a pack in a single transaction, instead of calling openPack and claimRewards separately.
function openPackAndClaimRewards(
uint256 _packId,
uint256 _amountToOpen,
uint32 _callBackGasLimit
) external returns (uint256);

/// @notice Returns whether a pack opener is ready to call `claimRewards`.
function canClaimRewards(address _opener) external view returns (bool);
}
Loading