-
Notifications
You must be signed in to change notification settings - Fork 553
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
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 ce926f0
Create PackVRFDirect: VRF with Direct payment
nkrishang 383045a
Burn packs in the claimRewards function instead
nkrishang 18d7d3a
Remove addPackContents to bring down size
nkrishang 75aa773
Change contract type Pack - Pack_VRF
nkrishang 45cbbd6
Move pack test to dir
nkrishang f6437b2
Bug fix: expect randomWords to initially be empty.
nkrishang ef95876
Move PackVRFDirect events to interface
nkrishang b81ae86
Tests for PackVRFDirect
nkrishang 4ab0356
PackVRFDirect: Update docs
nkrishang 5803945
Add benchmark test: fulfillRandomness
nkrishang f0bdedd
Make openerToReqId public
nkrishang 6b72666
Offer convenience public fn canClaimRewards
nkrishang 4b18522
pkg update
nkrishang 4713a32
fix canClaimRewards
joaquim-verges 30639d2
pkg release
joaquim-verges 897d77b
Add openPackAdnClaimRewards
nkrishang 1c8e10d
pkg release
nkrishang 0ede9ff
Add tests for openPackAndClaimRewards
nkrishang 963c0f0
allow VRF wrapper to call claim rewards
joaquim-verges 306ecaf
prevent calling open twice while in flight
joaquim-verges 7d2196d
Add openPackAndClaim to interface
nkrishang 6346e3a
pkg release
nkrishang 7937052
Add tests for not being able to open pack while repvious req is in fl…
nkrishang 1e49696
fulfillRandomWords: low gas failsafe
kumaryash90 7776202
merge main
kumaryash90 62f6271
Merge branch 'main' into pack-vrf
kumaryash90 08e609d
add WIP comment
kumaryash90 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
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); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Check warning
Code scanning / Slither
Variable names too similar