Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Loyalty points #456

Merged
merged 8 commits into from
Aug 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions contracts/base/ERC20SignatureMint.sol
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ contract ERC20SignatureMint is ERC20Base, PrimarySale, SignatureMintERC20 {
address receiver = _req.to;

// Collect price
_collectPriceOnClaim(_req.primarySaleRecipient, _req.quantity, _req.currency, _req.pricePerToken);
_collectPriceOnClaim(_req.primarySaleRecipient, _req.currency, _req.price);

// Mint tokens.
_mint(receiver, _req.quantity);
Expand All @@ -86,22 +86,20 @@ contract ERC20SignatureMint is ERC20Base, PrimarySale, SignatureMintERC20 {
/// @dev Collects and distributes the primary sale value of tokens being claimed.
function _collectPriceOnClaim(
address _primarySaleRecipient,
uint256 _quantityToClaim,
address _currency,
uint256 _pricePerToken
uint256 _price
) internal virtual {
if (_pricePerToken == 0) {
if (_price == 0) {
return;
}

uint256 totalPrice = (_quantityToClaim * _pricePerToken) / 1 ether;
require(totalPrice > 0, "quantity too low");

if (_currency == CurrencyTransferLib.NATIVE_TOKEN) {
require(msg.value == totalPrice, "Must send total price.");
require(msg.value == _price, "Must send total price.");
} else {
require(msg.value == 0, "msg value not zero");
}

address saleRecipient = _primarySaleRecipient == address(0) ? primarySaleRecipient() : _primarySaleRecipient;
CurrencyTransferLib.transferCurrency(_currency, msg.sender, saleRecipient, totalPrice);
CurrencyTransferLib.transferCurrency(_currency, msg.sender, saleRecipient, _price);
}
}
16 changes: 7 additions & 9 deletions contracts/base/ERC20SignatureMintVote.sol
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ contract ERC20SignatureMintVote is ERC20Vote, PrimarySale, SignatureMintERC20 {
address receiver = _req.to == address(0) ? msg.sender : _req.to;

// Collect price
_collectPriceOnClaim(_req.primarySaleRecipient, _req.quantity, _req.currency, _req.pricePerToken);
_collectPriceOnClaim(_req.primarySaleRecipient, _req.currency, _req.price);

// Mint tokens.
_mint(receiver, _req.quantity);
Expand All @@ -93,22 +93,20 @@ contract ERC20SignatureMintVote is ERC20Vote, PrimarySale, SignatureMintERC20 {
/// @dev Collects and distributes the primary sale value of tokens being claimed.
function _collectPriceOnClaim(
address _primarySaleRecipient,
uint256 _quantityToClaim,
address _currency,
uint256 _pricePerToken
uint256 _price
) internal virtual {
if (_pricePerToken == 0) {
if (_price == 0) {
return;
}

uint256 totalPrice = (_quantityToClaim * _pricePerToken) / 1 ether;
require(totalPrice > 0, "quantity too low");

if (_currency == CurrencyTransferLib.NATIVE_TOKEN) {
require(msg.value == totalPrice, "Must send total price.");
require(msg.value == _price, "Must send total price.");
} else {
require(msg.value == 0, "msg value not zero");
}

address saleRecipient = _primarySaleRecipient == address(0) ? primarySaleRecipient() : _primarySaleRecipient;
CurrencyTransferLib.transferCurrency(_currency, msg.sender, saleRecipient, totalPrice);
CurrencyTransferLib.transferCurrency(_currency, msg.sender, saleRecipient, _price);
}
}
4 changes: 2 additions & 2 deletions contracts/extension/SignatureMintERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ abstract contract SignatureMintERC20 is EIP712, ISignatureMintERC20 {

bytes32 private constant TYPEHASH =
keccak256(
"MintRequest(address to,address primarySaleRecipient,uint256 quantity,uint256 pricePerToken,address currency,uint128 validityStartTimestamp,uint128 validityEndTimestamp,bytes32 uid)"
"MintRequest(address to,address primarySaleRecipient,uint256 quantity,uint256 price,address currency,uint128 validityStartTimestamp,uint128 validityEndTimestamp,bytes32 uid)"
);

/// @dev Mapping from mint request UID => whether the mint request is processed.
Expand Down Expand Up @@ -62,7 +62,7 @@ abstract contract SignatureMintERC20 is EIP712, ISignatureMintERC20 {
_req.to,
_req.primarySaleRecipient,
_req.quantity,
_req.pricePerToken,
_req.price,
_req.currency,
_req.validityStartTimestamp,
_req.validityEndTimestamp,
Expand Down
13 changes: 7 additions & 6 deletions contracts/extension/SignatureMintERC20Upgradeable.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,18 @@ abstract contract SignatureMintERC20Upgradeable is Initializable, EIP712Upgradea

bytes32 private constant TYPEHASH =
keccak256(
"MintRequest(address to,address primarySaleRecipient,uint256 quantity,uint256 pricePerToken,address currency,uint128 validityStartTimestamp,uint128 validityEndTimestamp,bytes32 uid)"
"MintRequest(address to,address primarySaleRecipient,uint256 quantity,uint256 price,address currency,uint128 validityStartTimestamp,uint128 validityEndTimestamp,bytes32 uid)"
);

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

function __SignatureMintERC20_init() internal onlyInitializing {
__EIP712_init("SignatureMintERC20", "1");
function __SignatureMintERC20_init(string memory _name) internal onlyInitializing {
__EIP712_init(_name, "1");
__SignatureMintERC20_init_unchained(_name);
}

function __SignatureMintERC20_init_unchained() internal onlyInitializing {}
function __SignatureMintERC20_init_unchained(string memory) internal onlyInitializing {}

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

minted[_req.uid] = true;
}
Expand All @@ -68,7 +69,7 @@ abstract contract SignatureMintERC20Upgradeable is Initializable, EIP712Upgradea
_req.to,
_req.primarySaleRecipient,
_req.quantity,
_req.pricePerToken,
_req.price,
_req.currency,
_req.validityStartTimestamp,
_req.validityEndTimestamp,
Expand Down
2 changes: 1 addition & 1 deletion contracts/extension/interface/ISignatureMintERC20.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ interface ISignatureMintERC20 {
address to;
address primarySaleRecipient;
uint256 quantity;
uint256 pricePerToken;
uint256 price;
address currency;
uint128 validityStartTimestamp;
uint128 validityEndTimestamp;
Expand Down
24 changes: 24 additions & 0 deletions contracts/interfaces/ILoyaltyPoints.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// SPDX-License-Identifier: Apache-2.0
pragma solidity ^0.8.11;

interface ILoyaltyPoints {
/// @dev Emitted when an account with MINTER_ROLE mints an NFT.
event TokensMinted(address indexed mintedTo, uint256 quantityMinted);

/// @notice Returns the total tokens minted to `owner` in the contract's lifetime.
function getTotalMintedInLifetime(address owner) external view returns (uint256);

/**
* @notice Lets an account with MINTER_ROLE mint an NFT.
*
* @param to The address to mint tokens to.
* @param amount The amount of tokens to mint.
*/
function mintTo(address to, uint256 amount) external;

/// @notice Let's a loyalty pointsß owner or approved operator cancel the given amount of loyalty points.
function cancel(address owner, uint256 amount) external;

/// @notice Let's an approved party revoke a holder's loyalty points (no approval needed).
function revoke(address owner, uint256 amount) external;
}
Loading
Loading