Skip to content

Commit 5bd29c0

Browse files
authored
Loyalty points (#456)
* Create LoyaltyPoints * abstract contract -> contract * In ISignatureMintERC20 pricePerToken -> price * Use token name to initialize EIP712 * remove usesd _quantity * Add tests for LoyaltyPoints * move LoyaltyPoints to /unaudited
1 parent 339cac7 commit 5bd29c0

File tree

11 files changed

+593
-70
lines changed

11 files changed

+593
-70
lines changed

contracts/base/ERC20SignatureMint.sol

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ contract ERC20SignatureMint is ERC20Base, PrimarySale, SignatureMintERC20 {
6161
address receiver = _req.to;
6262

6363
// Collect price
64-
_collectPriceOnClaim(_req.primarySaleRecipient, _req.quantity, _req.currency, _req.pricePerToken);
64+
_collectPriceOnClaim(_req.primarySaleRecipient, _req.currency, _req.price);
6565

6666
// Mint tokens.
6767
_mint(receiver, _req.quantity);
@@ -86,22 +86,20 @@ contract ERC20SignatureMint is ERC20Base, PrimarySale, SignatureMintERC20 {
8686
/// @dev Collects and distributes the primary sale value of tokens being claimed.
8787
function _collectPriceOnClaim(
8888
address _primarySaleRecipient,
89-
uint256 _quantityToClaim,
9089
address _currency,
91-
uint256 _pricePerToken
90+
uint256 _price
9291
) internal virtual {
93-
if (_pricePerToken == 0) {
92+
if (_price == 0) {
9493
return;
9594
}
9695

97-
uint256 totalPrice = (_quantityToClaim * _pricePerToken) / 1 ether;
98-
require(totalPrice > 0, "quantity too low");
99-
10096
if (_currency == CurrencyTransferLib.NATIVE_TOKEN) {
101-
require(msg.value == totalPrice, "Must send total price.");
97+
require(msg.value == _price, "Must send total price.");
98+
} else {
99+
require(msg.value == 0, "msg value not zero");
102100
}
103101

104102
address saleRecipient = _primarySaleRecipient == address(0) ? primarySaleRecipient() : _primarySaleRecipient;
105-
CurrencyTransferLib.transferCurrency(_currency, msg.sender, saleRecipient, totalPrice);
103+
CurrencyTransferLib.transferCurrency(_currency, msg.sender, saleRecipient, _price);
106104
}
107105
}

contracts/base/ERC20SignatureMintVote.sol

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

7070
// Collect price
71-
_collectPriceOnClaim(_req.primarySaleRecipient, _req.quantity, _req.currency, _req.pricePerToken);
71+
_collectPriceOnClaim(_req.primarySaleRecipient, _req.currency, _req.price);
7272

7373
// Mint tokens.
7474
_mint(receiver, _req.quantity);
@@ -93,22 +93,20 @@ contract ERC20SignatureMintVote is ERC20Vote, PrimarySale, SignatureMintERC20 {
9393
/// @dev Collects and distributes the primary sale value of tokens being claimed.
9494
function _collectPriceOnClaim(
9595
address _primarySaleRecipient,
96-
uint256 _quantityToClaim,
9796
address _currency,
98-
uint256 _pricePerToken
97+
uint256 _price
9998
) internal virtual {
100-
if (_pricePerToken == 0) {
99+
if (_price == 0) {
101100
return;
102101
}
103102

104-
uint256 totalPrice = (_quantityToClaim * _pricePerToken) / 1 ether;
105-
require(totalPrice > 0, "quantity too low");
106-
107103
if (_currency == CurrencyTransferLib.NATIVE_TOKEN) {
108-
require(msg.value == totalPrice, "Must send total price.");
104+
require(msg.value == _price, "Must send total price.");
105+
} else {
106+
require(msg.value == 0, "msg value not zero");
109107
}
110108

111109
address saleRecipient = _primarySaleRecipient == address(0) ? primarySaleRecipient() : _primarySaleRecipient;
112-
CurrencyTransferLib.transferCurrency(_currency, msg.sender, saleRecipient, totalPrice);
110+
CurrencyTransferLib.transferCurrency(_currency, msg.sender, saleRecipient, _price);
113111
}
114112
}

contracts/extension/SignatureMintERC20.sol

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ abstract contract SignatureMintERC20 is EIP712, ISignatureMintERC20 {
1111

1212
bytes32 private constant TYPEHASH =
1313
keccak256(
14-
"MintRequest(address to,address primarySaleRecipient,uint256 quantity,uint256 pricePerToken,address currency,uint128 validityStartTimestamp,uint128 validityEndTimestamp,bytes32 uid)"
14+
"MintRequest(address to,address primarySaleRecipient,uint256 quantity,uint256 price,address currency,uint128 validityStartTimestamp,uint128 validityEndTimestamp,bytes32 uid)"
1515
);
1616

1717
/// @dev Mapping from mint request UID => whether the mint request is processed.
@@ -62,7 +62,7 @@ abstract contract SignatureMintERC20 is EIP712, ISignatureMintERC20 {
6262
_req.to,
6363
_req.primarySaleRecipient,
6464
_req.quantity,
65-
_req.pricePerToken,
65+
_req.price,
6666
_req.currency,
6767
_req.validityStartTimestamp,
6868
_req.validityEndTimestamp,

contracts/extension/SignatureMintERC20Upgradeable.sol

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,18 @@ abstract contract SignatureMintERC20Upgradeable is Initializable, EIP712Upgradea
1313

1414
bytes32 private constant TYPEHASH =
1515
keccak256(
16-
"MintRequest(address to,address primarySaleRecipient,uint256 quantity,uint256 pricePerToken,address currency,uint128 validityStartTimestamp,uint128 validityEndTimestamp,bytes32 uid)"
16+
"MintRequest(address to,address primarySaleRecipient,uint256 quantity,uint256 price,address currency,uint128 validityStartTimestamp,uint128 validityEndTimestamp,bytes32 uid)"
1717
);
1818

1919
/// @dev Mapping from mint request UID => whether the mint request is processed.
2020
mapping(bytes32 => bool) private minted;
2121

22-
function __SignatureMintERC20_init() internal onlyInitializing {
23-
__EIP712_init("SignatureMintERC20", "1");
22+
function __SignatureMintERC20_init(string memory _name) internal onlyInitializing {
23+
__EIP712_init(_name, "1");
24+
__SignatureMintERC20_init_unchained(_name);
2425
}
2526

26-
function __SignatureMintERC20_init_unchained() internal onlyInitializing {}
27+
function __SignatureMintERC20_init_unchained(string memory) internal onlyInitializing {}
2728

2829
/// @dev Verifies that a mint request is signed by an account holding MINTER_ROLE (at the time of the function call).
2930
function verify(MintRequest calldata _req, bytes calldata _signature)
@@ -50,7 +51,7 @@ abstract contract SignatureMintERC20Upgradeable is Initializable, EIP712Upgradea
5051
"Request expired"
5152
);
5253
require(_req.to != address(0), "recipient undefined");
53-
require(_req.quantity > 0, "0 qty");
54+
require(_req.quantity > 0, "Minting zero qty");
5455

5556
minted[_req.uid] = true;
5657
}
@@ -68,7 +69,7 @@ abstract contract SignatureMintERC20Upgradeable is Initializable, EIP712Upgradea
6869
_req.to,
6970
_req.primarySaleRecipient,
7071
_req.quantity,
71-
_req.pricePerToken,
72+
_req.price,
7273
_req.currency,
7374
_req.validityStartTimestamp,
7475
_req.validityEndTimestamp,

contracts/extension/interface/ISignatureMintERC20.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ interface ISignatureMintERC20 {
2727
address to;
2828
address primarySaleRecipient;
2929
uint256 quantity;
30-
uint256 pricePerToken;
30+
uint256 price;
3131
address currency;
3232
uint128 validityStartTimestamp;
3333
uint128 validityEndTimestamp;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
pragma solidity ^0.8.11;
3+
4+
interface ILoyaltyPoints {
5+
/// @dev Emitted when an account with MINTER_ROLE mints an NFT.
6+
event TokensMinted(address indexed mintedTo, uint256 quantityMinted);
7+
8+
/// @notice Returns the total tokens minted to `owner` in the contract's lifetime.
9+
function getTotalMintedInLifetime(address owner) external view returns (uint256);
10+
11+
/**
12+
* @notice Lets an account with MINTER_ROLE mint an NFT.
13+
*
14+
* @param to The address to mint tokens to.
15+
* @param amount The amount of tokens to mint.
16+
*/
17+
function mintTo(address to, uint256 amount) external;
18+
19+
/// @notice Let's a loyalty pointsß owner or approved operator cancel the given amount of loyalty points.
20+
function cancel(address owner, uint256 amount) external;
21+
22+
/// @notice Let's an approved party revoke a holder's loyalty points (no approval needed).
23+
function revoke(address owner, uint256 amount) external;
24+
}

0 commit comments

Comments
 (0)