Skip to content

Commit a0fd4dd

Browse files
authored
Release v3.8.2 (#447)
* resolve deps error by cp file * silence compiler warnings * pkg release * fix test * solhint error
1 parent 1ef7c42 commit a0fd4dd

26 files changed

+146
-90
lines changed

contracts/pack/PackVRFDirect.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import "@openzeppelin/contracts-upgradeable/interfaces/IERC2981Upgradeable.sol";
2323
import "@openzeppelin/contracts/interfaces/IERC721Receiver.sol";
2424
import { IERC1155Receiver } from "@openzeppelin/contracts/interfaces/IERC1155Receiver.sol";
2525

26-
import "@chainlink/contracts/src/v0.8/vrf/VRFV2WrapperConsumerBase.sol";
26+
import "./VRFV2WrapperConsumerBase.sol";
2727

2828
// ========== Internal imports ==========
2929

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// SPDX-License-Identifier: MIT
2+
pragma solidity ^0.8.0;
3+
4+
import "@chainlink/contracts/src/v0.8/interfaces/LinkTokenInterface.sol";
5+
import "@chainlink/contracts/src/v0.8/interfaces/VRFV2WrapperInterface.sol";
6+
7+
/** *******************************************************************************
8+
* @notice Interface for contracts using VRF randomness through the VRF V2 wrapper
9+
* ********************************************************************************
10+
* @dev PURPOSE
11+
*
12+
* @dev Create VRF V2 requests without the need for subscription management. Rather than creating
13+
* @dev and funding a VRF V2 subscription, a user can use this wrapper to create one off requests,
14+
* @dev paying up front rather than at fulfillment.
15+
*
16+
* @dev Since the price is determined using the gas price of the request transaction rather than
17+
* @dev the fulfillment transaction, the wrapper charges an additional premium on callback gas
18+
* @dev usage, in addition to some extra overhead costs associated with the VRFV2Wrapper contract.
19+
* *****************************************************************************
20+
* @dev USAGE
21+
*
22+
* @dev Calling contracts must inherit from VRFV2WrapperConsumerBase. The consumer must be funded
23+
* @dev with enough LINK to make the request, otherwise requests will revert. To request randomness,
24+
* @dev call the 'requestRandomness' function with the desired VRF parameters. This function handles
25+
* @dev paying for the request based on the current pricing.
26+
*
27+
* @dev Consumers must implement the fullfillRandomWords function, which will be called during
28+
* @dev fulfillment with the randomness result.
29+
*/
30+
abstract contract VRFV2WrapperConsumerBase {
31+
// solhint-disable-next-line var-name-mixedcase
32+
LinkTokenInterface internal immutable LINK;
33+
// solhint-disable-next-line var-name-mixedcase
34+
VRFV2WrapperInterface internal immutable VRF_V2_WRAPPER;
35+
36+
/**
37+
* @param _link is the address of LinkToken
38+
* @param _vrfV2Wrapper is the address of the VRFV2Wrapper contract
39+
*/
40+
constructor(address _link, address _vrfV2Wrapper) {
41+
LINK = LinkTokenInterface(_link);
42+
VRF_V2_WRAPPER = VRFV2WrapperInterface(_vrfV2Wrapper);
43+
}
44+
45+
/**
46+
* @dev Requests randomness from the VRF V2 wrapper.
47+
*
48+
* @param _callbackGasLimit is the gas limit that should be used when calling the consumer's
49+
* fulfillRandomWords function.
50+
* @param _requestConfirmations is the number of confirmations to wait before fulfilling the
51+
* request. A higher number of confirmations increases security by reducing the likelihood
52+
* that a chain re-org changes a published randomness outcome.
53+
* @param _numWords is the number of random words to request.
54+
*
55+
* @return requestId is the VRF V2 request ID of the newly created randomness request.
56+
*/
57+
function requestRandomness(
58+
uint32 _callbackGasLimit,
59+
uint16 _requestConfirmations,
60+
uint32 _numWords
61+
) internal returns (uint256 requestId) {
62+
LINK.transferAndCall(
63+
address(VRF_V2_WRAPPER),
64+
VRF_V2_WRAPPER.calculateRequestPrice(_callbackGasLimit),
65+
abi.encode(_callbackGasLimit, _requestConfirmations, _numWords)
66+
);
67+
return VRF_V2_WRAPPER.lastRequestId();
68+
}
69+
70+
/**
71+
* @notice fulfillRandomWords handles the VRF V2 wrapper response. The consuming contract must
72+
* @notice implement it.
73+
*
74+
* @param _requestId is the VRF V2 request ID.
75+
* @param _randomWords is the randomness result.
76+
*/
77+
function fulfillRandomWords(uint256 _requestId, uint256[] memory _randomWords) internal virtual;
78+
79+
function rawFulfillRandomWords(uint256 _requestId, uint256[] memory _randomWords) external {
80+
require(msg.sender == address(VRF_V2_WRAPPER), "only VRF V2 wrapper can fulfill");
81+
fulfillRandomWords(_requestId, _randomWords);
82+
}
83+
}

contracts/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@thirdweb-dev/contracts",
33
"description": "Collection of smart contracts deployable via the thirdweb SDK, dashboard and CLI",
4-
"version": "3.8.1",
4+
"version": "3.8.2",
55
"license": "Apache-2.0",
66
"repository": {
77
"type": "git",

contracts/staking/EditionStake.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ contract EditionStake is
147147
uint256,
148148
uint256,
149149
bytes calldata
150-
) external returns (bytes4) {
150+
) external view returns (bytes4) {
151151
require(isStaking == 2, "Direct transfer");
152152
return this.onERC1155Received.selector;
153153
}

src/test/LoyaltyCard.t.sol

-2
Original file line numberDiff line numberDiff line change
@@ -313,8 +313,6 @@ contract LoyaltyCardTest is BaseTest {
313313
_mintrequest.currency = address(erc20);
314314
_signature = signMintRequest(_mintrequest, privateKey);
315315

316-
uint256 erc20BalanceOfSeller = erc20.balanceOf(address(saleRecipient));
317-
318316
vm.prank(recipient);
319317
erc20.approve(address(loyaltyCard), 5);
320318

src/test/airdrop/AirdropERC1155.t.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ contract AirdropERC1155GasTest is BaseTest {
135135
uint256,
136136
uint256,
137137
bytes calldata
138-
) external returns (bytes4) {
138+
) external pure returns (bytes4) {
139139
return this.onERC1155Received.selector;
140140
}
141141
}

src/test/airdrop/AirdropERC20.t.sol

+17-4
Original file line numberDiff line numberDiff line change
@@ -150,25 +150,38 @@ contract AirdropERC20GasTest is BaseTest {
150150

151151
function test_transferNativeToken_toEOA() public {
152152
vm.prank(address(tokenOwner));
153-
address(0x123).call{ value: 1 ether }("");
153+
(bool success, bytes memory data) = address(0x123).call{ value: 1 ether }("");
154+
155+
// Silence warning: Return value of low-level calls not used.
156+
(success, data) = (success, data);
154157
}
155158

156159
function test_transferNativeToken_toContract() public {
157160
vm.prank(address(tokenOwner));
158-
address(this).call{ value: 1 ether }("");
161+
(bool success, bytes memory data) = address(this).call{ value: 1 ether }("");
162+
163+
// Silence warning: Return value of low-level calls not used.
164+
(success, data) = (success, data);
159165
}
160166

161167
function test_transferNativeToken_toEOA_gasOverride() public {
162168
vm.prank(address(tokenOwner));
163169
console.log(gasleft());
164-
address(0x123).call{ value: 1 ether, gas: 100_000 }("");
170+
(bool success, bytes memory data) = address(0x123).call{ value: 1 ether, gas: 100_000 }("");
171+
172+
// Silence warning: Return value of low-level calls not used.
173+
(success, data) = (success, data);
174+
165175
console.log(gasleft());
166176
}
167177

168178
function test_transferNativeToken_toContract_gasOverride() public {
169179
vm.prank(address(tokenOwner));
170180
console.log(gasleft());
171-
address(this).call{ value: 1 ether, gas: 100_000 }("");
181+
(bool success, bytes memory data) = address(this).call{ value: 1 ether, gas: 100_000 }("");
172182
console.log(gasleft());
183+
184+
// Silence warning: Return value of low-level calls not used.
185+
(success, data) = (success, data);
173186
}
174187
}

src/test/airdrop/AirdropERC721.t.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ contract AirdropERC721GasTest is BaseTest {
116116
address,
117117
uint256,
118118
bytes calldata
119-
) external view returns (bytes4) {
119+
) external pure returns (bytes4) {
120120
return this.onERC721Received.selector;
121121
}
122122
}

src/test/benchmark/DropERC1155Benchmark.t.sol

-2
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,6 @@ contract DropERC1155BenchmarkTest is BaseTest {
111111

112112
vm.warp(1);
113113

114-
address receiver = address(0x92Bb439374a091c7507bE100183d8D1Ed2c9dAD3); // in allowlist
115-
116114
DropERC1155.ClaimCondition[] memory conditions = new DropERC1155.ClaimCondition[](5);
117115
conditions[0].maxClaimableSupply = 500;
118116
conditions[0].quantityLimitPerWallet = 10;

src/test/benchmark/DropERC20Benchmark.t.sol

-2
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,6 @@ contract DropERC20BenchmarkTest is BaseTest {
5555

5656
vm.warp(1);
5757

58-
address receiver = address(0x92Bb439374a091c7507bE100183d8D1Ed2c9dAD3); // in allowlist
59-
6058
DropERC20.ClaimCondition[] memory conditions = new DropERC20.ClaimCondition[](5);
6159
conditions[0].maxClaimableSupply = 500 ether;
6260
conditions[0].quantityLimitPerWallet = 10 ether;

src/test/benchmark/DropERC721Benchmark.t.sol

-4
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,6 @@ contract DropERC721BenchmarkTest is BaseTest {
109109

110110
vm.warp(1);
111111

112-
address receiver = address(0x92Bb439374a091c7507bE100183d8D1Ed2c9dAD3); // in allowlist
113-
114112
DropERC721.ClaimCondition[] memory conditions = new DropERC721.ClaimCondition[](5);
115113
conditions[0].maxClaimableSupply = 500;
116114
conditions[0].quantityLimitPerWallet = 10;
@@ -153,8 +151,6 @@ contract DropERC721BenchmarkTest is BaseTest {
153151
bytes memory encryptedBaseURI = "encryptedBaseURI://";
154152
bytes32 provenanceHash = bytes32("whatever");
155153

156-
uint256 nextTokenIdToMintBefore = drop.nextTokenIdToMint();
157-
158154
vm.prank(deployer);
159155
vm.resumeGasMetering();
160156
drop.lazyMint(amountToLazyMint, baseURI, abi.encode(encryptedBaseURI, provenanceHash));

src/test/benchmark/EditionStakeBenchmark.t.sol

-4
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,11 @@ contract EditionStakeBenchmarkTest is BaseTest {
7070
// stake 50 tokens with token-id 0
7171
vm.prank(stakerOne);
7272
stakeContract.stake(0, 50);
73-
uint256 timeOfLastUpdate_one = block.timestamp;
7473

7574
//=================== warp timestamp to claim rewards
7675
vm.roll(100);
7776
vm.warp(1000);
7877

79-
uint256 rewardBalanceBefore = stakeContract.getRewardTokenBalance();
8078
vm.prank(stakerOne);
8179
vm.resumeGasMetering();
8280
stakeContract.claimRewards(0);
@@ -92,8 +90,6 @@ contract EditionStakeBenchmarkTest is BaseTest {
9290
vm.prank(stakerTwo);
9391
stakeContract.stake(1, 20);
9492

95-
uint256 timeOfLastUpdate = block.timestamp;
96-
9793
//========== warp timestamp before withdraw
9894
vm.roll(100);
9995
vm.warp(1000);

src/test/benchmark/NFTStakeBenchmark.t.sol

-3
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,10 @@ contract NFTStakeBenchmarkTest is BaseTest {
7878
// stake 3 tokens
7979
vm.prank(stakerOne);
8080
stakeContract.stake(_tokenIdsOne);
81-
uint256 timeOfLastUpdate_one = block.timestamp;
8281

8382
//=================== warp timestamp to claim rewards
8483
vm.roll(100);
8584
vm.warp(1000);
86-
87-
uint256 rewardBalanceBefore = stakeContract.getRewardTokenBalance();
8885
vm.prank(stakerOne);
8986
vm.resumeGasMetering();
9087
stakeContract.claimRewards();

src/test/benchmark/PackBenchmark.t.sol

+1-2
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,6 @@ contract PackBenchmarkTest is BaseTest {
179179

180180
function test_benchmark_pack_createPack() public {
181181
vm.pauseGasMetering();
182-
uint256 packId = pack.nextTokenIdToMint();
183182
address recipient = address(1);
184183

185184
vm.prank(address(tokenOwner));
@@ -214,7 +213,7 @@ contract PackBenchmarkTest is BaseTest {
214213
address recipient = address(1);
215214

216215
vm.prank(address(tokenOwner));
217-
(, uint256 totalSupply) = pack.createPack(packContents, numOfRewardUnits, packUri, 0, 2, recipient);
216+
pack.createPack(packContents, numOfRewardUnits, packUri, 0, 2, recipient);
218217

219218
vm.prank(recipient, recipient);
220219
vm.resumeGasMetering();

src/test/benchmark/PackVRFDirectBenchmark.t.sol

+2-5
Original file line numberDiff line numberDiff line change
@@ -194,16 +194,13 @@ contract PackVRFDirectBenchmarkTest is BaseTest {
194194
function test_benchmark_packvrf_openPackAndClaimRewards() public {
195195
vm.pauseGasMetering();
196196
vm.warp(1000);
197-
uint256 packId = pack.nextTokenIdToMint();
198-
uint256 packsToOpen = 3;
199197
address recipient = address(1);
200198

201199
vm.prank(address(tokenOwner));
202-
(, uint256 totalSupply) = pack.createPack(packContents, numOfRewardUnits, packUri, 0, 2, recipient);
200+
pack.createPack(packContents, numOfRewardUnits, packUri, 0, 2, recipient);
203201

204202
vm.prank(recipient, recipient);
205203
vm.resumeGasMetering();
206-
uint256 requestId = pack.openPackAndClaimRewards(packId, packsToOpen, 2_500_000);
207204
}
208205

209206
function test_benchmark_packvrf_openPack() public {
@@ -214,7 +211,7 @@ contract PackVRFDirectBenchmarkTest is BaseTest {
214211
address recipient = address(1);
215212

216213
vm.prank(address(tokenOwner));
217-
(, uint256 totalSupply) = pack.createPack(packContents, numOfRewardUnits, packUri, 0, 2, recipient);
214+
pack.createPack(packContents, numOfRewardUnits, packUri, 0, 2, recipient);
218215

219216
vm.prank(recipient, recipient);
220217
vm.resumeGasMetering();

src/test/benchmark/SignatureDropBenchmark.t.sol

-2
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,6 @@ contract SignatureDropBenchmarkTest is BaseTest {
8686
function test_bechmark_signatureDrop_setClaimConditions() public {
8787
vm.pauseGasMetering();
8888
vm.warp(1);
89-
90-
address receiver = getActor(0);
9189
bytes32[] memory proofs = new bytes32[](0);
9290

9391
SignatureDrop.AllowlistProof memory alp;

src/test/benchmark/TokenERC1155Benchmark.t.sol

-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,6 @@ contract TokenERC1155BenchmarkTest is BaseTest {
169169
uint256 _amount = 100;
170170

171171
uint256 nextTokenId = tokenContract.nextTokenIdToMint();
172-
uint256 currentBalanceOfRecipient = tokenContract.balanceOf(recipient, nextTokenId);
173172

174173
vm.prank(deployerSigner);
175174
tokenContract.mintTo(recipient, type(uint256).max, _tokenURI, _amount);

src/test/benchmark/TokenStakeBenchmark.t.sol

-5
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,10 @@ contract TokenStakeBenchmarkTest is BaseTest {
7070
// stake 50 tokens with token-id 0
7171
vm.prank(stakerOne);
7272
stakeContract.stake(400);
73-
uint256 timeOfLastUpdate_one = block.timestamp;
7473

7574
//=================== warp timestamp to claim rewards
7675
vm.roll(100);
7776
vm.warp(1000);
78-
79-
uint256 rewardBalanceBefore = stakeContract.getRewardTokenBalance();
8077
vm.prank(stakerOne);
8178
vm.resumeGasMetering();
8279
stakeContract.claimRewards();
@@ -92,8 +89,6 @@ contract TokenStakeBenchmarkTest is BaseTest {
9289
vm.prank(stakerTwo);
9390
stakeContract.stake(200);
9491

95-
uint256 timeOfLastUpdate = block.timestamp;
96-
9792
//========== warp timestamp before withdraw
9893
vm.roll(100);
9994
vm.warp(1000);

src/test/marketplace/DirectListings.t.sol

+3-13
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ contract MarketplaceDirectListingsTest is BaseTest {
186186
);
187187

188188
vm.prank(seller);
189-
uint256 listingId = DirectListingsLogic(marketplace).createListing(listingParams);
189+
DirectListingsLogic(marketplace).createListing(listingParams);
190190

191191
// Total listings incremented
192192
assertEq(DirectListingsLogic(marketplace).totalListings(), 1);
@@ -462,11 +462,7 @@ contract MarketplaceDirectListingsTest is BaseTest {
462462
}
463463

464464
function test_royaltyEngine_tokenWithERC2981() public {
465-
(
466-
MockRoyaltyEngineV1 royaltyEngine,
467-
address payable[] memory customRoyaltyRecipients,
468-
uint256[] memory customRoyaltyAmounts
469-
) = _setupRoyaltyEngine();
465+
(MockRoyaltyEngineV1 royaltyEngine, , ) = _setupRoyaltyEngine();
470466

471467
// Add RoyaltyEngine to marketplace
472468
vm.prank(marketplaceDeployer);
@@ -585,11 +581,7 @@ contract MarketplaceDirectListingsTest is BaseTest {
585581
}
586582

587583
function test_revert_feesExceedTotalPrice() public {
588-
(
589-
MockRoyaltyEngineV1 royaltyEngine,
590-
address payable[] memory customRoyaltyRecipients,
591-
uint256[] memory customRoyaltyAmounts
592-
) = _setupRoyaltyEngine();
584+
(MockRoyaltyEngineV1 royaltyEngine, , ) = _setupRoyaltyEngine();
593585

594586
// Add RoyaltyEngine to marketplace
595587
vm.prank(marketplaceDeployer);
@@ -2074,9 +2066,7 @@ contract IssueC2_MarketplaceDirectListingsTest is BaseTest {
20742066
function test_state_buyFromListing_after_update() public {
20752067
(uint256 listingId, IDirectListings.Listing memory listing) = _setup_buyFromListing();
20762068

2077-
address buyFor = buyer;
20782069
uint256 quantityToBuy = listing.quantity;
2079-
address currency = listing.currency;
20802070
uint256 pricePerToken = listing.pricePerToken;
20812071
uint256 totalPrice = pricePerToken * quantityToBuy;
20822072

0 commit comments

Comments
 (0)