Skip to content

Commit

Permalink
Rename PRESAVE -> PLATFORM_AIRDROP
Browse files Browse the repository at this point in the history
  • Loading branch information
Vectorized committed Dec 6, 2023
1 parent c7b1931 commit f09b3dd
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 50 deletions.
52 changes: 26 additions & 26 deletions contracts/modules/SuperMinterV1_1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,12 @@ contract SuperMinterV1_1 is ISuperMinterV1_1, EIP712 {
);

/**
* @dev For EIP-712 presave signature digest calculation.
* @dev For EIP-712 platform airdrop signature digest calculation.
*/
bytes32 public constant PRESAVE_TYPEHASH =
bytes32 public constant PLATFORM_AIRDROP_TYPEHASH =
// prettier-ignore
keccak256(
"Presave("
"PlatformAirdrop("
"address edition,"
"uint8 tier,"
"uint8 scheduleNum,"
Expand Down Expand Up @@ -138,9 +138,9 @@ contract SuperMinterV1_1 is ISuperMinterV1_1, EIP712 {
uint8 public constant VERIFY_SIGNATURE = 2;

/**
* @dev The Presave mint mode.
* @dev The platform airdrop mint mode.
*/
uint8 public constant PRESAVE = 3;
uint8 public constant PLATFORM_AIRDROP = 3;

/**
* @dev The denominator of all BPS calculations.
Expand Down Expand Up @@ -262,11 +262,11 @@ contract SuperMinterV1_1 is ISuperMinterV1_1, EIP712 {
_validateSigner(c.signer);
c.merkleRoot = bytes32(0);
c.maxMintablePerAccount = type(uint32).max;
} else if (mode == PRESAVE) {
} else if (mode == PLATFORM_AIRDROP) {
_validateSigner(c.signer);
c.merkleRoot = bytes32(0);
c.maxMintablePerAccount = type(uint32).max;
c.price = 0; // Presave mode doesn't have a price.
c.price = 0; // Platform airdrop mode doesn't have a price.
} else {
revert InvalidMode();
}
Expand Down Expand Up @@ -341,7 +341,7 @@ contract SuperMinterV1_1 is ISuperMinterV1_1, EIP712 {
uint8 mode = d.mode;
if (mode == VERIFY_MERKLE) _verifyMerkle(d, p);
else if (mode == VERIFY_SIGNATURE) _verifyAndClaimSignature(d, p);
else if (mode == PRESAVE) revert InvalidMode();
else if (mode == PLATFORM_AIRDROP) revert InvalidMode();

_incrementMinted(mode, d, p);

Expand Down Expand Up @@ -423,17 +423,17 @@ contract SuperMinterV1_1 is ISuperMinterV1_1, EIP712 {
/**
* @inheritdoc ISuperMinterV1_1
*/
function presave(Presave calldata p) public {
function platformAirdrop(PlatformAirdrop calldata p) public {
MintData storage d = _getMintData(LibOps.packId(p.edition, p.tier, p.scheduleNum));

/* ------------------- CHECKS AND UPDATES ------------------- */

_requireMintOpen(d);

if (d.mode != PRESAVE) revert InvalidMode();
_verifyAndClaimPresaveSignature(d, p);
if (d.mode != PLATFORM_AIRDROP) revert InvalidMode();
_verifyAndClaimPlatfromAidropSignature(d, p);

_incrementPresaveMinted(d, p);
_incrementPlatformAirdropMinted(d, p);

/* ------------------------- MINT --------------------------- */

Expand All @@ -446,7 +446,7 @@ contract SuperMinterV1_1 is ISuperMinterV1_1, EIP712 {
}
}

emit Presaved(p.edition, p.tier, p.scheduleNum, p.to, p.signedQuantity);
emit PlatformAirdropped(p.edition, p.tier, p.scheduleNum, p.to, p.signedQuantity);
}

// Per edition mint parameter setters:
Expand All @@ -466,8 +466,8 @@ contract SuperMinterV1_1 is ISuperMinterV1_1, EIP712 {
MintData storage d = _getMintData(mintId);
// If the tier is GA and the `mode` is `VERIFY_SIGNATURE`, we'll use `gaPrice[platform]`.
if (tier == GA_TIER && d.mode != VERIFY_SIGNATURE) revert NotConfigurable();
// Presave mints will not have a price.
if (d.mode == PRESAVE) revert NotConfigurable();
// Platform airdropped mints will not have a price.
if (d.mode == PLATFORM_AIRDROP) revert NotConfigurable();
d.price = price;
emit PriceSet(edition, tier, scheduleNum, price);
}
Expand Down Expand Up @@ -566,8 +566,8 @@ contract SuperMinterV1_1 is ISuperMinterV1_1, EIP712 {
if (tier == GA_TIER) revert NotConfigurable();
// Signature mints will have `type(uint32).max`.
if (d.mode == VERIFY_SIGNATURE) revert NotConfigurable();
// Presave mints will have `type(uint32).max`.
if (d.mode == PRESAVE) revert NotConfigurable();
// Platform airdrops will have `type(uint32).max`.
if (d.mode == PLATFORM_AIRDROP) revert NotConfigurable();
_validateMaxMintablePerAccount(value);
d.maxMintablePerAccount = value;
emit MaxMintablePerAccountSet(edition, tier, scheduleNum, value);
Expand Down Expand Up @@ -753,11 +753,11 @@ contract SuperMinterV1_1 is ISuperMinterV1_1, EIP712 {
/**
* @inheritdoc ISuperMinterV1_1
*/
function computePresaveDigest(Presave calldata p) public view returns (bytes32) {
function computePlatformAirdropDigest(PlatformAirdrop calldata p) public view returns (bytes32) {
// prettier-ignore
return
_hashTypedData(keccak256(abi.encode(
PRESAVE_TYPEHASH,
PLATFORM_AIRDROP_TYPEHASH,
p.edition,
p.tier,
p.scheduleNum,
Expand Down Expand Up @@ -1119,9 +1119,9 @@ contract SuperMinterV1_1 is ISuperMinterV1_1, EIP712 {
/**
* @dev Increments the number minted in the mint and the number minted by the collector.
* @param d The mint data storage pointer.
* @param p The presave parameters.
* @param p The platform airdrop parameters.
*/
function _incrementPresaveMinted(MintData storage d, Presave calldata p) internal {
function _incrementPlatformAirdropMinted(MintData storage d, PlatformAirdrop calldata p) internal {
unchecked {
uint256 mintId = LibOps.packId(p.edition, p.tier, p.scheduleNum);
uint256 toLength = p.to.length;
Expand Down Expand Up @@ -1165,14 +1165,14 @@ contract SuperMinterV1_1 is ISuperMinterV1_1, EIP712 {
}

/**
* @dev Verify the presave signature, and mark the signed claim ticket as claimed.
* @dev Verify the platform airdrop signature, and mark the signed claim ticket as claimed.
* @param d The mint data storage pointer.
* @param p The presave parameters.
* @param p The platform airdrop parameters.
*/
function _verifyAndClaimPresaveSignature(MintData storage d, Presave calldata p) internal {
// Unlike regular signature mints, presave mints only used `signedQuantity`.
function _verifyAndClaimPlatfromAidropSignature(MintData storage d, PlatformAirdrop calldata p) internal {
// Unlike regular signature mints, platform airdrops only use `signedQuantity`.
address signer = _effectiveSigner(d);
if (!SignatureCheckerLib.isValidSignatureNowCalldata(signer, computePresaveDigest(p), p.signature))
if (!SignatureCheckerLib.isValidSignatureNowCalldata(signer, computePlatformAirdropDigest(p), p.signature))
revert InvalidSignature();
if (block.timestamp > p.signedDeadline) revert SignatureExpired();
uint256 mintId = LibOps.packId(p.edition, p.tier, p.scheduleNum);
Expand Down
36 changes: 21 additions & 15 deletions contracts/modules/interfaces/ISuperMinterV1_1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,9 @@ interface ISuperMinterV1_1 is IERC165 {
}

/**
* @dev A struct containing the arguments for presave.
* @dev A struct containing the arguments for platformAirdrop.
*/
struct Presave {
struct PlatformAirdrop {
// The mint ID.
address edition;
// The tier of the mint.
Expand Down Expand Up @@ -241,7 +241,7 @@ interface ISuperMinterV1_1 is IERC165 {
bytes32 affiliateMerkleRoot;
// The Merkle root hash, required if `mode` is `VERIFY_MERKLE`.
bytes32 merkleRoot;
// The signer address, required if `mode` is `VERIFY_SIGNATURE` or `PRESAVE`.
// The signer address, required if `mode` is `VERIFY_SIGNATURE` or `PLATFORM_AIRDROP`.
// This value will be the platform signer instead if it is configured to be `address(1)`.
address signer;
// Whether the platform signer is being used instead
Expand Down Expand Up @@ -363,14 +363,20 @@ interface ISuperMinterV1_1 is IERC165 {
);

/**
* @dev Emitted when tokens are minted for presave.
* @dev Emitted when tokens are platform airdropped.
* @param edition The address of the Sound Edition.
* @param tier The tier.
* @param scheduleNum The edition-tier schedule number.
* @param to The recipients of the tokens minted.
* @param signedQuantity The amount of tokens per address.
*/
event Presaved(address indexed edition, uint8 tier, uint8 scheduleNum, address[] to, uint32 signedQuantity);
event PlatformAirdropped(
address indexed edition,
uint8 tier,
uint8 scheduleNum,
address[] to,
uint32 signedQuantity
);

/**
* @dev Emitted when the platform fee configuration for `tier` is updated.
Expand Down Expand Up @@ -589,10 +595,10 @@ interface ISuperMinterV1_1 is IERC165 {
function mintTo(MintTo calldata p) external payable;

/**
* @dev Performs a presave mint.
* @param p The presave parameters.
* @dev Performs a platform airdrop.
* @param p The platform airdrop parameters.
*/
function presave(Presave calldata p) external;
function platformAirdrop(PlatformAirdrop calldata p) external;

/**
* @dev Sets the price of the mint.
Expand Down Expand Up @@ -796,10 +802,10 @@ interface ISuperMinterV1_1 is IERC165 {
function MINT_TO_TYPEHASH() external pure returns (bytes32);

/**
* @dev The EIP-712 typehash for presave mints.
* @dev The EIP-712 typehash for platform airdrop mints.
* @return The constant value.
*/
function PRESAVE_TYPEHASH() external pure returns (bytes32);
function PLATFORM_AIRDROP_TYPEHASH() external pure returns (bytes32);

/**
* @dev The default mint mode.
Expand All @@ -820,10 +826,10 @@ interface ISuperMinterV1_1 is IERC165 {
function VERIFY_SIGNATURE() external pure returns (uint8);

/**
* @dev The mint mode for presave.
* @dev The mint mode for platform airdrop.
* @return The constant value.
*/
function PRESAVE() external pure returns (uint8);
function PLATFORM_AIRDROP() external pure returns (uint8);

/**
* @dev The denominator used in BPS fee calculations.
Expand Down Expand Up @@ -884,11 +890,11 @@ interface ISuperMinterV1_1 is IERC165 {
function computeMintToDigest(MintTo calldata p) external view returns (bytes32);

/**
* @dev Returns the EIP-712 digest of the mint-to data for presave mints.
* @param p The presave parameters.
* @dev Returns the EIP-712 digest of the mint-to data for platform airdrops.
* @param p The platform airdrop parameters.
* @return The computed value.
*/
function computePresaveDigest(Presave calldata p) external view returns (bytes32);
function computePlatformAirdropDigest(PlatformAirdrop calldata p) external view returns (bytes32);

/**
* @dev Returns the total price and fees for the mint.
Expand Down
18 changes: 9 additions & 9 deletions tests/modules/SuperMinterV1_1.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ contract SuperMinterV1_1Tests is TestConfigV2_1 {
}
}

function test_presave(uint256) public {
function test_platformAirdrop(uint256) public {
(address signer, uint256 privateKey) = _randomSigner();

ISuperMinterV1_1.MintCreation memory c;
Expand All @@ -267,12 +267,12 @@ contract SuperMinterV1_1Tests is TestConfigV2_1 {
c.tier = uint8(_random() % 2);
c.endTime = uint32(block.timestamp + 1000);
c.maxMintablePerAccount = uint32(_random()); // Doesn't matter, will be auto set to max.
c.mode = sm.PRESAVE();
c.mode = sm.PLATFORM_AIRDROP();
c.signer = signer;
assertEq(sm.createEditionMint(c), 0);

unchecked {
ISuperMinterV1_1.Presave memory p;
ISuperMinterV1_1.PlatformAirdrop memory p;
p.edition = address(edition);
p.tier = c.tier;
p.scheduleNum = 0;
Expand All @@ -285,24 +285,24 @@ contract SuperMinterV1_1Tests is TestConfigV2_1 {
}
LibSort.sort(p.to);
LibSort.uniquifySorted(p.to);
p.signature = _generatePresaveSignature(p, privateKey);
p.signature = _generatePlatformAirdropSignature(p, privateKey);

uint256 expectedMinted = p.signedQuantity * p.to.length;
if (expectedMinted > c.maxMintable) {
vm.expectRevert(ISuperMinterV1_1.ExceedsMintSupply.selector);
sm.presave(p);
sm.platformAirdrop(p);
return;
}

sm.presave(p);
sm.platformAirdrop(p);
assertEq(sm.mintInfo(address(edition), p.tier, p.scheduleNum).minted, expectedMinted);
for (uint256 i; i < p.to.length; ++i) {
assertEq(edition.balanceOf(p.to[i]), p.signedQuantity);
assertEq(sm.numberMinted(address(edition), p.tier, p.scheduleNum, p.to[i]), p.signedQuantity);
}

vm.expectRevert(ISuperMinterV1_1.SignatureAlreadyUsed.selector);
sm.presave(p);
sm.platformAirdrop(p);
}
}

Expand Down Expand Up @@ -1038,11 +1038,11 @@ contract SuperMinterV1_1Tests is TestConfigV2_1 {
signature = abi.encodePacked(r, s, v);
}

function _generatePresaveSignature(ISuperMinterV1_1.Presave memory p, uint256 privateKey)
function _generatePlatformAirdropSignature(ISuperMinterV1_1.PlatformAirdrop memory p, uint256 privateKey)
internal
returns (bytes memory signature)
{
bytes32 digest = sm.computePresaveDigest(p);
bytes32 digest = sm.computePlatformAirdropDigest(p);
(uint8 v, bytes32 r, bytes32 s) = vm.sign(privateKey, digest);
signature = abi.encodePacked(r, s, v);
}
Expand Down

0 comments on commit f09b3dd

Please sign in to comment.