Skip to content
This repository was archived by the owner on Oct 8, 2024. It is now read-only.

Commit bc9a147

Browse files
authored
V0.6.2 - Improve Linear Pricing (#78)
* make list limit update check against uint32 max * add refund mechanism + tests * update const back to prod * add verify package * more packages
1 parent ec40d7a commit bc9a147

File tree

8 files changed

+654
-819
lines changed

8 files changed

+654
-819
lines changed

contracts/Archetype.sol

Lines changed: 49 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: MIT
2-
// Archetype v0.6.1
2+
// Archetype v0.6.2
33
//
44
// d8888 888 888
55
// d88888 888 888
@@ -148,23 +148,38 @@ contract Archetype is
148148
});
149149
}
150150

151-
ArchetypeLogic.validateMint(invite, config, auth, _minted, signature, args);
151+
uint128 cost = uint128(
152+
ArchetypeLogic.computePrice(
153+
invite,
154+
config.discounts,
155+
args.quantity,
156+
args.listSupply,
157+
args.affiliate != address(0)
158+
)
159+
);
160+
161+
ArchetypeLogic.validateMint(invite, config, auth, _minted, signature, args, cost);
152162

153163
if (invite.limit < invite.maxSupply) {
154164
_minted[_msgSender()][auth.key] += quantity;
155165
}
156-
if (invite.maxSupply < config.maxSupply) {
166+
if (invite.maxSupply < UINT32_MAX) {
157167
_listSupply[auth.key] += quantity;
158168
}
169+
159170
ArchetypeLogic.updateBalances(
160171
invite,
161172
config,
162173
_ownerBalance,
163174
_affiliateBalance,
164-
args.listSupply,
165175
affiliate,
166-
quantity
176+
quantity,
177+
cost
167178
);
179+
180+
if (msg.value > cost) {
181+
_refund(_msgSender(), msg.value - cost);
182+
}
168183
}
169184

170185
function mintTo(
@@ -191,24 +206,40 @@ contract Archetype is
191206
});
192207
}
193208

194-
ArchetypeLogic.validateMint(i, config, auth, _minted, signature, args);
209+
uint128 cost = uint128(
210+
ArchetypeLogic.computePrice(
211+
i,
212+
config.discounts,
213+
args.quantity,
214+
args.listSupply,
215+
args.affiliate != address(0)
216+
)
217+
);
218+
219+
ArchetypeLogic.validateMint(i, config, auth, _minted, signature, args, cost);
220+
195221
_mint(to, quantity);
196222

197223
if (i.limit < i.maxSupply) {
198224
_minted[_msgSender()][auth.key] += quantity;
199225
}
200-
if (i.maxSupply < config.maxSupply) {
226+
if (i.maxSupply < UINT32_MAX) {
201227
_listSupply[auth.key] += quantity;
202228
}
229+
203230
ArchetypeLogic.updateBalances(
204231
i,
205232
config,
206233
_ownerBalance,
207234
_affiliateBalance,
208-
args.listSupply,
209235
affiliate,
210-
quantity
236+
quantity,
237+
cost
211238
);
239+
240+
if (msg.value > cost) {
241+
_refund(_msgSender(), msg.value - cost);
242+
}
212243
}
213244

214245
function burnToMint(uint256[] calldata tokenIds) external {
@@ -289,8 +320,8 @@ contract Archetype is
289320
bool affiliateUsed
290321
) external view returns (uint256) {
291322
DutchInvite storage i = invites[key];
292-
uint256 listSupply = _listSupply[key];
293-
return ArchetypeLogic.computePrice(i, config.discounts, quantity, listSupply, affiliateUsed);
323+
uint256 listSupply_ = _listSupply[key];
324+
return ArchetypeLogic.computePrice(i, config.discounts, quantity, listSupply_, affiliateUsed);
294325
}
295326

296327
//
@@ -512,6 +543,13 @@ contract Archetype is
512543
_;
513544
}
514545

546+
function _refund(address to, uint256 refund) internal {
547+
(bool success, ) = payable(to).call{ value: refund }("");
548+
if (!success) {
549+
revert TransferFailed();
550+
}
551+
}
552+
515553
// OPTIONAL ROYALTY ENFORCEMENT WITH OPENSEA
516554
function enableRoyaltyEnforcement() external _onlyOwner {
517555
if (options.royaltyEnforcementLocked) {

contracts/ArchetypeLogic.sol

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// SPDX-License-Identifier: MIT
2-
// ArchetypeLogic v0.6.1
2+
// ArchetypeLogic v0.6.2
33
//
44
// d8888 888 888
55
// d88888 888 888
@@ -138,6 +138,7 @@ struct ValidationArgs {
138138
address constant PLATFORM = 0x86B82972282Dd22348374bC63fd21620F7ED847B;
139139
address constant BATCH = 0x6Bc558A6DC48dEfa0e7022713c23D65Ab26e4Fa7;
140140
uint16 constant MAXBPS = 5000; // max fee or discount is 50%
141+
uint32 constant UINT32_MAX = 2**32 - 1;
141142

142143
library ArchetypeLogic {
143144
//
@@ -205,7 +206,8 @@ library ArchetypeLogic {
205206
Auth calldata auth,
206207
mapping(address => mapping(bytes32 => uint256)) storage minted,
207208
bytes calldata signature,
208-
ValidationArgs memory args
209+
ValidationArgs memory args,
210+
uint128 cost
209211
) public view {
210212
address msgSender = _msgSender();
211213
if (args.affiliate != address(0)) {
@@ -262,14 +264,6 @@ library ArchetypeLogic {
262264
revert MaxSupplyExceeded();
263265
}
264266

265-
uint256 cost = computePrice(
266-
i,
267-
config.discounts,
268-
args.quantity,
269-
args.listSupply,
270-
args.affiliate != address(0)
271-
);
272-
273267
if (i.tokenAddress != address(0)) {
274268
IERC20Upgradeable erc20Token = IERC20Upgradeable(i.tokenAddress);
275269
if (erc20Token.allowance(msgSender, address(this)) < cost) {
@@ -287,10 +281,6 @@ library ArchetypeLogic {
287281
if (msg.value < cost) {
288282
revert InsufficientEthSent();
289283
}
290-
291-
if (msg.value > cost) {
292-
revert ExcessiveEthSent();
293-
}
294284
}
295285
}
296286

@@ -356,17 +346,11 @@ library ArchetypeLogic {
356346
Config storage config,
357347
mapping(address => OwnerBalance) storage _ownerBalance,
358348
mapping(address => mapping(address => uint128)) storage _affiliateBalance,
359-
uint256 listSupply,
360349
address affiliate,
361-
uint256 quantity
350+
uint256 quantity,
351+
uint128 value
362352
) public {
363353
address tokenAddress = i.tokenAddress;
364-
uint128 value = uint128(msg.value);
365-
if (tokenAddress != address(0)) {
366-
value = uint128(
367-
computePrice(i, config.discounts, quantity, listSupply, affiliate != address(0))
368-
);
369-
}
370354

371355
uint128 affiliateWad;
372356
if (affiliate != address(0)) {

hardhat.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import "solidity-coverage";
55
import "@openzeppelin/hardhat-upgrades";
66
import "@nomiclabs/hardhat-web3";
77
import "@nomiclabs/hardhat-ethers";
8-
import "@nomiclabs/hardhat-etherscan";
8+
import "@nomicfoundation/hardhat-verify";
99
import "@nomiclabs/hardhat-truffle5";
1010
import "@nomiclabs/hardhat-waffle";
1111
import "@typechain/hardhat";

0 commit comments

Comments
 (0)