Skip to content

Commit 3ce657a

Browse files
authored
Disable mint sdk (#220)
* refactor ERC721Drop and ERC721Multiwrap * refactor ERC1155Drop * run prettier * fix collectPriceOnClaim for signature-minting * run prettier
1 parent a8d9fab commit 3ce657a

22 files changed

+263
-340
lines changed

contracts/base/ERC1155Drop.sol

Lines changed: 90 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
// SPDX-License-Identifier: Apache-2.0
22
pragma solidity ^0.8.0;
33

4-
import "./ERC1155SignatureMint.sol";
5-
4+
import { ERC1155 } from "../eip/ERC1155.sol";
5+
6+
import "../extension/ContractMetadata.sol";
7+
import "../extension/Multicall.sol";
8+
import "../extension/Ownable.sol";
9+
import "../extension/Royalty.sol";
10+
import "../extension/BatchMintMetadata.sol";
11+
import "../extension/PrimarySale.sol";
12+
import "../extension/SignatureMintERC1155.sol";
613
import "../extension/DropSinglePhase1155.sol";
714
import "../extension/LazyMint.sol";
815
import "../extension/DelayedReveal.sol";
916

17+
import "../lib/CurrencyTransferLib.sol";
18+
import "../lib/TWStrings.sol";
19+
1020
/**
1121
* BASE: ERC1155Base
1222
* EXTENSION: SignatureMintERC1155, DropSinglePhase1155
@@ -24,9 +34,31 @@ import "../extension/DelayedReveal.sol";
2434
* via the drop mechanism.
2535
*/
2636

27-
contract ERC1155Drop is ERC1155SignatureMint, LazyMint, DelayedReveal, DropSinglePhase1155 {
37+
contract ERC1155Drop is
38+
ERC1155,
39+
ContractMetadata,
40+
Ownable,
41+
Royalty,
42+
Multicall,
43+
BatchMintMetadata,
44+
PrimarySale,
45+
SignatureMintERC1155,
46+
LazyMint,
47+
DelayedReveal,
48+
DropSinglePhase1155
49+
{
2850
using TWStrings for uint256;
2951

52+
/*//////////////////////////////////////////////////////////////
53+
Mappings
54+
//////////////////////////////////////////////////////////////*/
55+
56+
/**
57+
* @notice Returns the total supply of NFTs of a given tokenId
58+
* @dev Mapping from tokenId => total circulating supply of NFTs of that tokenId.
59+
*/
60+
mapping(uint256 => uint256) public totalSupply;
61+
3062
/*///////////////////////////////////////////////////////////////
3163
Constructor
3264
//////////////////////////////////////////////////////////////*/
@@ -37,7 +69,11 @@ contract ERC1155Drop is ERC1155SignatureMint, LazyMint, DelayedReveal, DropSingl
3769
address _royaltyRecipient,
3870
uint128 _royaltyBps,
3971
address _primarySaleRecipient
40-
) ERC1155SignatureMint(_name, _symbol, _royaltyRecipient, _royaltyBps, _primarySaleRecipient) {}
72+
) ERC1155(_name, _symbol) {
73+
_setupOwner(msg.sender);
74+
_setupDefaultRoyaltyInfo(_royaltyRecipient, _royaltyBps);
75+
_setupPrimarySaleRecipient(_primarySaleRecipient);
76+
}
4177

4278
/*///////////////////////////////////////////////////////////////
4379
Overriden metadata logic
@@ -95,7 +131,12 @@ contract ERC1155Drop is ERC1155SignatureMint, LazyMint, DelayedReveal, DropSingl
95131
address receiver = _req.to == address(0) ? msg.sender : _req.to;
96132

97133
// Collect price
98-
collectPriceOnClaim(primarySaleRecipient(), _req.quantity, _req.currency, _req.pricePerToken);
134+
collectPriceOnClaim(_req.primarySaleRecipient, _req.quantity, _req.currency, _req.pricePerToken);
135+
136+
// Set royalties, if applicable.
137+
if (_req.royaltyRecipient != address(0) && _req.royaltyBps != 0) {
138+
_setupRoyaltyInfoForToken(tokenIdToMint, _req.royaltyRecipient, _req.royaltyBps);
139+
}
99140

100141
// Mint tokens.
101142
_mint(receiver, tokenIdToMint, _req.quantity, "");
@@ -154,10 +195,23 @@ contract ERC1155Drop is ERC1155SignatureMint, LazyMint, DelayedReveal, DropSingl
154195
}
155196

156197
/// @notice The tokenId assigned to the next new NFT to be lazy minted.
157-
function nextTokenIdToMint() public view virtual override returns (uint256) {
198+
function nextTokenIdToMint() public view virtual returns (uint256) {
158199
return nextTokenIdToLazyMint;
159200
}
160201

202+
/*//////////////////////////////////////////////////////////////
203+
ERC165 Logic
204+
//////////////////////////////////////////////////////////////*/
205+
206+
/// @notice Returns whether this contract supports the given interface.
207+
function supportsInterface(bytes4 interfaceId) public view virtual override(ERC1155, IERC165) returns (bool) {
208+
return
209+
interfaceId == 0x01ffc9a7 || // ERC165 Interface ID for ERC165
210+
interfaceId == 0xd9b67a26 || // ERC165 Interface ID for ERC1155
211+
interfaceId == 0x0e89341c || // ERC165 Interface ID for ERC1155MetadataURI
212+
interfaceId == type(IERC2981).interfaceId; // ERC165 ID for ERC2981
213+
}
214+
161215
/*///////////////////////////////////////////////////////////////
162216
Internal functions
163217
//////////////////////////////////////////////////////////////*/
@@ -184,7 +238,7 @@ contract ERC1155Drop is ERC1155SignatureMint, LazyMint, DelayedReveal, DropSingl
184238
uint256 _quantityToClaim,
185239
address _currency,
186240
uint256 _pricePerToken
187-
) internal virtual override(DropSinglePhase1155, ERC1155SignatureMint) {
241+
) internal virtual override {
188242
if (_pricePerToken == 0) {
189243
return;
190244
}
@@ -210,6 +264,30 @@ contract ERC1155Drop is ERC1155SignatureMint, LazyMint, DelayedReveal, DropSingl
210264
_mint(_to, _tokenId, _quantityBeingClaimed, "");
211265
}
212266

267+
/// @dev Runs before every token transfer / mint / burn.
268+
function _beforeTokenTransfer(
269+
address operator,
270+
address from,
271+
address to,
272+
uint256[] memory ids,
273+
uint256[] memory amounts,
274+
bytes memory data
275+
) internal virtual override {
276+
super._beforeTokenTransfer(operator, from, to, ids, amounts, data);
277+
278+
if (from == address(0)) {
279+
for (uint256 i = 0; i < ids.length; ++i) {
280+
totalSupply[ids[i]] += amounts[i];
281+
}
282+
}
283+
284+
if (to == address(0)) {
285+
for (uint256 i = 0; i < ids.length; ++i) {
286+
totalSupply[ids[i]] -= amounts[i];
287+
}
288+
}
289+
}
290+
213291
/// @dev Checks whether primary sale recipient can be set in the given execution context.
214292
function _canSetPrimarySaleRecipient() internal view virtual override returns (bool) {
215293
return msg.sender == owner();
@@ -244,4 +322,9 @@ contract ERC1155Drop is ERC1155SignatureMint, LazyMint, DelayedReveal, DropSingl
244322
function _canReveal() internal view virtual returns (bool) {
245323
return msg.sender == owner();
246324
}
325+
326+
/// @dev Returns whether a given address is authorized to sign mint requests.
327+
function _canSignMintRequest(address _signer) internal view virtual override returns (bool) {
328+
return _signer == owner();
329+
}
247330
}

contracts/base/ERC1155SignatureMint.sol

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,7 @@ contract ERC1155SignatureMint is ERC1155Base, PrimarySale, SignatureMintERC1155
7979
address receiver = _req.to == address(0) ? msg.sender : _req.to;
8080

8181
// Collect price
82-
address saleRecipient = _req.primarySaleRecipient == address(0)
83-
? primarySaleRecipient()
84-
: _req.primarySaleRecipient;
85-
collectPriceOnClaim(saleRecipient, _req.quantity, _req.currency, _req.pricePerToken);
82+
collectPriceOnClaim(_req.primarySaleRecipient, _req.quantity, _req.currency, _req.pricePerToken);
8683

8784
// Set royalties, if applicable.
8885
if (_req.royaltyRecipient != address(0)) {
@@ -131,6 +128,7 @@ contract ERC1155SignatureMint is ERC1155Base, PrimarySale, SignatureMintERC1155
131128
require(msg.value == totalPrice, "Must send total price.");
132129
}
133130

134-
CurrencyTransferLib.transferCurrency(_currency, msg.sender, _primarySaleRecipient, totalPrice);
131+
address saleRecipient = _primarySaleRecipient == address(0) ? primarySaleRecipient() : _primarySaleRecipient;
132+
CurrencyTransferLib.transferCurrency(_currency, msg.sender, saleRecipient, totalPrice);
135133
}
136134
}

contracts/base/ERC20Drop.sol

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ contract ERC20Drop is
8282
address receiver = _req.to == address(0) ? msg.sender : _req.to;
8383

8484
// Collect price
85-
collectPriceOnClaim(_req);
85+
collectPriceOnClaim(_req.primarySaleRecipient, _req.quantity, _req.currency, _req.pricePerToken);
8686

8787
// Mint tokens.
8888
_mint(receiver, _req.quantity);
@@ -109,24 +109,9 @@ contract ERC20Drop is
109109
Internal (overrideable) functions
110110
//////////////////////////////////////////////////////////////*/
111111

112-
/// @dev Collects and distributes the primary sale value of tokens being minted with signature.
113-
function collectPriceOnClaim(MintRequest calldata _req) internal virtual {
114-
if (_req.pricePerToken == 0) {
115-
return;
116-
}
117-
118-
uint256 totalPrice = (_req.quantity * _req.pricePerToken) / 1 ether;
119-
require(totalPrice > 0, "quantity too low");
120-
121-
if (_req.currency == CurrencyTransferLib.NATIVE_TOKEN) {
122-
require(msg.value == totalPrice, "must send total price.");
123-
}
124-
125-
CurrencyTransferLib.transferCurrency(_req.currency, msg.sender, _req.primarySaleRecipient, totalPrice);
126-
}
127-
128112
/// @dev Collects and distributes the primary sale value of tokens being claimed.
129113
function collectPriceOnClaim(
114+
address _primarySaleRecipient,
130115
uint256 _quantityToClaim,
131116
address _currency,
132117
uint256 _pricePerToken
@@ -142,7 +127,8 @@ contract ERC20Drop is
142127
require(msg.value == totalPrice, "Must send total price.");
143128
}
144129

145-
CurrencyTransferLib.transferCurrency(_currency, msg.sender, primarySaleRecipient(), totalPrice);
130+
address saleRecipient = _primarySaleRecipient == address(0) ? primarySaleRecipient() : _primarySaleRecipient;
131+
CurrencyTransferLib.transferCurrency(_currency, msg.sender, saleRecipient, totalPrice);
146132
}
147133

148134
/// @dev Transfers the tokens being claimed.

contracts/base/ERC20DropVote.sol

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ contract ERC20DropVote is
8282
address receiver = _req.to == address(0) ? msg.sender : _req.to;
8383

8484
// Collect price
85-
collectPriceOnClaim(_req);
85+
collectPriceOnClaim(_req.primarySaleRecipient, _req.quantity, _req.currency, _req.pricePerToken);
8686

8787
// Mint tokens.
8888
_mint(receiver, _req.quantity);
@@ -109,24 +109,9 @@ contract ERC20DropVote is
109109
Internal (overrideable) functions
110110
//////////////////////////////////////////////////////////////*/
111111

112-
/// @dev Collects and distributes the primary sale value of tokens being minted with signature.
113-
function collectPriceOnClaim(MintRequest calldata _req) internal virtual {
114-
if (_req.pricePerToken == 0) {
115-
return;
116-
}
117-
118-
uint256 totalPrice = (_req.quantity * _req.pricePerToken) / 1 ether;
119-
require(totalPrice > 0, "quantity too low");
120-
121-
if (_req.currency == CurrencyTransferLib.NATIVE_TOKEN) {
122-
require(msg.value == totalPrice, "must send total price.");
123-
}
124-
125-
CurrencyTransferLib.transferCurrency(_req.currency, msg.sender, _req.primarySaleRecipient, totalPrice);
126-
}
127-
128112
/// @dev Collects and distributes the primary sale value of tokens being claimed.
129113
function collectPriceOnClaim(
114+
address _primarySaleRecipient,
130115
uint256 _quantityToClaim,
131116
address _currency,
132117
uint256 _pricePerToken
@@ -142,7 +127,8 @@ contract ERC20DropVote is
142127
require(msg.value == totalPrice, "Must send total price.");
143128
}
144129

145-
CurrencyTransferLib.transferCurrency(_currency, msg.sender, primarySaleRecipient(), totalPrice);
130+
address saleRecipient = _primarySaleRecipient == address(0) ? primarySaleRecipient() : _primarySaleRecipient;
131+
CurrencyTransferLib.transferCurrency(_currency, msg.sender, saleRecipient, totalPrice);
146132
}
147133

148134
/// @dev Transfers the tokens being claimed.

contracts/base/ERC20SignatureMint.sol

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ contract ERC20SignatureMint is ERC20Base, PrimarySale, SignatureMintERC20 {
6666
address receiver = _req.to == address(0) ? msg.sender : _req.to;
6767

6868
// Collect price
69-
collectPriceOnClaim(_req);
69+
collectPriceOnClaim(_req.primarySaleRecipient, _req.quantity, _req.currency, _req.pricePerToken);
7070

7171
// Mint tokens.
7272
_mint(receiver, _req.quantity);
@@ -88,19 +88,25 @@ contract ERC20SignatureMint is ERC20Base, PrimarySale, SignatureMintERC20 {
8888
return msg.sender == owner();
8989
}
9090

91-
/// @dev Collects and distributes the primary sale value of tokens being minted with signature.
92-
function collectPriceOnClaim(MintRequest calldata _req) internal virtual {
93-
if (_req.pricePerToken == 0) {
91+
/// @dev Collects and distributes the primary sale value of tokens being claimed.
92+
function collectPriceOnClaim(
93+
address _primarySaleRecipient,
94+
uint256 _quantityToClaim,
95+
address _currency,
96+
uint256 _pricePerToken
97+
) internal virtual {
98+
if (_pricePerToken == 0) {
9499
return;
95100
}
96101

97-
uint256 totalPrice = (_req.quantity * _req.pricePerToken) / 1 ether;
102+
uint256 totalPrice = (_quantityToClaim * _pricePerToken) / 1 ether;
98103
require(totalPrice > 0, "quantity too low");
99104

100-
if (_req.currency == CurrencyTransferLib.NATIVE_TOKEN) {
101-
require(msg.value == totalPrice, "must send total price.");
105+
if (_currency == CurrencyTransferLib.NATIVE_TOKEN) {
106+
require(msg.value == totalPrice, "Must send total price.");
102107
}
103108

104-
CurrencyTransferLib.transferCurrency(_req.currency, msg.sender, _req.primarySaleRecipient, totalPrice);
109+
address saleRecipient = _primarySaleRecipient == address(0) ? primarySaleRecipient() : _primarySaleRecipient;
110+
CurrencyTransferLib.transferCurrency(_currency, msg.sender, saleRecipient, totalPrice);
105111
}
106112
}

contracts/base/ERC20SignatureMintVote.sol

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ contract ERC20SignatureMintVote is ERC20Vote, PrimarySale, SignatureMintERC20 {
6666
address receiver = _req.to == address(0) ? msg.sender : _req.to;
6767

6868
// Collect price
69-
collectPriceOnClaim(_req);
69+
collectPriceOnClaim(_req.primarySaleRecipient, _req.quantity, _req.currency, _req.pricePerToken);
7070

7171
// Mint tokens.
7272
_mint(receiver, _req.quantity);
@@ -88,19 +88,25 @@ contract ERC20SignatureMintVote is ERC20Vote, PrimarySale, SignatureMintERC20 {
8888
return msg.sender == owner();
8989
}
9090

91-
/// @dev Collects and distributes the primary sale value of tokens being minted with signature.
92-
function collectPriceOnClaim(MintRequest calldata _req) internal virtual {
93-
if (_req.pricePerToken == 0) {
91+
/// @dev Collects and distributes the primary sale value of tokens being claimed.
92+
function collectPriceOnClaim(
93+
address _primarySaleRecipient,
94+
uint256 _quantityToClaim,
95+
address _currency,
96+
uint256 _pricePerToken
97+
) internal virtual {
98+
if (_pricePerToken == 0) {
9499
return;
95100
}
96101

97-
uint256 totalPrice = (_req.quantity * _req.pricePerToken) / 1 ether;
102+
uint256 totalPrice = (_quantityToClaim * _pricePerToken) / 1 ether;
98103
require(totalPrice > 0, "quantity too low");
99104

100-
if (_req.currency == CurrencyTransferLib.NATIVE_TOKEN) {
101-
require(msg.value == totalPrice, "must send total price.");
105+
if (_currency == CurrencyTransferLib.NATIVE_TOKEN) {
106+
require(msg.value == totalPrice, "Must send total price.");
102107
}
103108

104-
CurrencyTransferLib.transferCurrency(_req.currency, msg.sender, _req.primarySaleRecipient, totalPrice);
109+
address saleRecipient = _primarySaleRecipient == address(0) ? primarySaleRecipient() : _primarySaleRecipient;
110+
CurrencyTransferLib.transferCurrency(_currency, msg.sender, saleRecipient, totalPrice);
105111
}
106112
}

0 commit comments

Comments
 (0)