Skip to content
Open
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
76 changes: 48 additions & 28 deletions hardhat/contracts/Event.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import "@openzeppelin/contracts/access/Ownable.sol";
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/metatx/MinimalForwarderUpgradeable.sol";
import "./IMintNFT.sol";
import "./MintPoint.sol";
import "./IOperationController.sol";
import "./ERC2771ContextUpgradeable.sol";
import "hardhat/console.sol";
Expand Down Expand Up @@ -46,6 +47,8 @@ contract EventManager is OwnableUpgradeable, ERC2771ContextUpgradeable {

// Mint nft contract address
address private mintNFTAddr;
// Burn point contract address
address private burnPtsAddr;
// Relayer address for meta transaction
address private relayerAddr;
// price for mtx per mint. required gas * margin * gas limit multipler
Expand Down Expand Up @@ -101,6 +104,11 @@ contract EventManager is OwnableUpgradeable, ERC2771ContextUpgradeable {
mintNFTAddr = _mintNftAddr;
}

function setBurnPtsAddr(address _burnPtsAddr) public onlyOwner {
require(_burnPtsAddr != address(0), "burn point address is blank");
burnPtsAddr = _burnPtsAddr;
}

function setRelayerAddr(address _relayerAddr) public onlyOwner {
require(_relayerAddr != address(0), "relayer address is blank");
relayerAddr = _relayerAddr;
Expand Down Expand Up @@ -289,19 +297,25 @@ contract EventManager is OwnableUpgradeable, ERC2771ContextUpgradeable {
string memory _description,
string memory _date,
uint256 _mintLimit,
uint256 _tokenId,
bool _usePoint,
bool _useMtx,
bool _nonTransferable,
bytes32 _secretPhrase,
// uint256 _points,
IMintNFT.NFTAttribute[] memory _eventNFTAttributes
) external payable onlyCollaboratorAccess(_groupId) whenNotPaused {
require(
_mintLimit > 0 && _mintLimit <= maxMintLimit,
"mint limit is invalid"
);

if (_useMtx) {
uint256 depositPrice = (_mintLimit * tx.gasprice * mtxPrice);
require(_mintLimit > 0 && _mintLimit <= maxMintLimit, "mint limit is invalid");

if (_usePoint) {
MintPoint mintPoint = MintPoint(burnPtsAddr);
uint256 amount = _mintLimit;
require(
mintPoint.balanceOf(_msgSender(), _tokenId) >= amount,
"Not enough tokens to burn"
);
mintPoint.burn(_tokenId, amount);
} else if (_useMtx) {
uint256 depositPrice = _mintLimit * tx.gasprice * mtxPrice;
require(msg.value >= depositPrice, "Not enough value");
(bool success, ) = (relayerAddr).call{value: msg.value}("");
require(success, "transfer failed");
Expand All @@ -310,33 +324,39 @@ contract EventManager is OwnableUpgradeable, ERC2771ContextUpgradeable {
uint256 _newEventId = _eventRecordIds.current();
_eventRecordIds.increment();

eventRecords.push(
EventRecord({
eventRecordId: _newEventId,
groupId: _groupId,
name: _name,
description: _description,
date: _date,
useMtx: _useMtx
})
);
_createEventRecord(_newEventId, _groupId, _name, _description, _date, _useMtx);

IMintNFT _mintNFT = IMintNFT(mintNFTAddr);
_mintNFT.setEventInfo(
_newEventId,
_mintLimit,
_secretPhrase,
_eventNFTAttributes
);
IMintNFT mintNFTContract = IMintNFT(mintNFTAddr);
mintNFTContract.setEventInfo(_newEventId, _mintLimit, _secretPhrase, _eventNFTAttributes);

if (_nonTransferable) {
_mintNFT.changeNonTransferable(_newEventId, true);
mintNFTContract.changeNonTransferable(_newEventId, true);
}

emit CreateEvent(_msgSender(), _newEventId);
}

function _createEventRecord(
uint256 _newEventId,
uint256 _groupId,
string memory _name,
string memory _description,
string memory _date,
bool _useMtx
) internal {
EventRecord memory newEventRecord = EventRecord({
eventRecordId: _newEventId,
groupId: _groupId,
name: _name,
description: _description,
date: _date,
useMtx: _useMtx
});

eventRecords.push(newEventRecord);

eventIdsByGroupId[_groupId].push(_newEventId);
groupIdByEventId[_newEventId] = _groupId;

emit CreateEvent(_msgSender(), _newEventId);
}

function getEventRecordCount() public view returns (uint256) {
Expand Down
28 changes: 28 additions & 0 deletions hardhat/test/EventManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ describe("EventManager", function () {
"event-1 description",
"2022-07-3O",
100,
0,
false,
false,
false,
publicInputCalldata[0],
Expand All @@ -150,6 +152,8 @@ describe("EventManager", function () {
"event-1 description",
"2022-07-3O",
100,
0,
false,
false,
false,
publicInputCalldata[0],
Expand Down Expand Up @@ -184,6 +188,8 @@ describe("EventManager", function () {
"event2 description",
"2022-08-01",
100,
0,
false,
false,
false,
publicInputCalldata[0],
Expand All @@ -209,6 +215,8 @@ describe("EventManager", function () {
"event1 description",
"2022-07-3O",
10,
0,
false,
true,
false,
publicInputCalldata[0],
Expand All @@ -233,6 +241,8 @@ describe("EventManager", function () {
`event${i} description`,
"2022-07-3O",
11 + i,
0,
false,
true,
false,
publicInputCalldata[0],
Expand Down Expand Up @@ -336,6 +346,8 @@ describe("EventManager", function () {
"event1 description",
"2022-07-3O",
100,
0,
false,
false,
false,
publicInputCalldata[0],
Expand All @@ -356,6 +368,8 @@ describe("EventManager", function () {
"event1 description",
"2022-07-3O",
100,
0,
false,
false,
false,
publicInputCalldata[0],
Expand Down Expand Up @@ -411,6 +425,8 @@ describe("EventManager", function () {
"event1 description",
"2022-07-3O",
100,
0,
false,
false,
false,
publicInputCalldata[0],
Expand All @@ -431,6 +447,8 @@ describe("EventManager", function () {
"event1 description",
"2022-07-3O",
100,
0,
false,
false,
false,
publicInputCalldata[0],
Expand Down Expand Up @@ -469,6 +487,8 @@ describe("EventManager", function () {
"event1 description",
"2022-07-3O",
100,
0,
true,
false,
false,
publicInputCalldata[0],
Expand Down Expand Up @@ -669,6 +689,8 @@ describe("EventManager", function () {
`event${i} description`,
"2023-07-3O",
100,
0,
false,
false,
false,
publicInputCalldata[0],
Expand All @@ -686,6 +708,8 @@ describe("EventManager", function () {
`event_x description`,
"2023-07-3O",
100,
0,
false,
false,
false,
publicInputCalldata[0],
Expand Down Expand Up @@ -1274,6 +1298,8 @@ describe("EventManager", function () {
"event1 description",
"2022-07-3O",
100,
0,
false,
false,
false,
publicInputCalldata[0],
Expand All @@ -1288,6 +1314,8 @@ describe("EventManager", function () {
"event1 description",
"2022-07-3O",
100,
0,
false,
false,
false,
publicInputCalldata[0],
Expand Down
2 changes: 2 additions & 0 deletions hardhat/test/MTX.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ describe("MTX Event", function () {
"mtx event description",
"2022-07-30",
100,
0,
false,
false,
false,
publicInputCalldata[0],
Expand Down
28 changes: 28 additions & 0 deletions hardhat/test/MintNFT.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ type eventGroupParams = {
description: string;
date: string;
mintLimit: BigNumberish;
tokenId: BigNumberish;
usePoint: boolean;
useMtx: boolean;
nonTransferable: boolean;
secretPhrase: BytesLike;
Expand Down Expand Up @@ -165,6 +167,8 @@ const createEventRecord = async (
params.description,
params.date,
params.mintLimit,
params.tokenId,
params.usePoint,
params.useMtx,
params.nonTransferable,
params.secretPhrase,
Expand Down Expand Up @@ -205,6 +209,8 @@ describe("MintNFT", function () {
"event1 description",
"2022-07-3O",
10,
0,
false,
false,
false,
publicInputCalldata[0],
Expand Down Expand Up @@ -312,6 +318,8 @@ describe("MintNFT", function () {
description: "event1 description",
date: "2022-07-3O",
mintLimit: 10,
tokenId: 0,
usePoint: false,
useMtx: false,
nonTransferable: false,
secretPhrase: publicInputCalldata[0],
Expand All @@ -325,6 +333,8 @@ describe("MintNFT", function () {
description: "event2 description",
date: "2022-07-3O",
mintLimit: 10,
tokenId: 0,
usePoint: false,
useMtx: false,
nonTransferable: false,
secretPhrase: publicInputCalldata[0],
Expand All @@ -338,6 +348,8 @@ describe("MintNFT", function () {
description: "event3 description",
date: "2022-07-3O",
mintLimit: 10,
tokenId: 0,
usePoint: false,
useMtx: false,
nonTransferable: false,
secretPhrase: publicInputCalldata[0],
Expand Down Expand Up @@ -569,6 +581,8 @@ describe("MintNFT", function () {
"event2 description",
"2022-07-3O",
10,
0,
false,
false,
false,
publicInputCalldata2[0],
Expand Down Expand Up @@ -637,6 +651,8 @@ describe("nft revolution", () => {
description: "event1 description",
date: "2022-07-3O",
mintLimit: 10,
tokenId: 0,
usePoint: false,
useMtx: false,
nonTransferable: false,
secretPhrase: publicInputCalldata[0],
Expand All @@ -648,6 +664,8 @@ describe("nft revolution", () => {
description: "event2 description",
date: "2022-07-3O",
mintLimit: 1,
tokenId: 0,
usePoint: false,
useMtx: false,
nonTransferable: false,
secretPhrase: publicInputCalldata[0],
Expand Down Expand Up @@ -770,6 +788,8 @@ describe("bulk mint by event owner", () => {
description: "event1 description",
date: "2022-07-3O",
mintLimit: 10,
tokenId: 0,
usePoint: false,
useMtx: false,
nonTransferable: false,
secretPhrase: publicInputCalldata[0],
Expand All @@ -781,6 +801,8 @@ describe("bulk mint by event owner", () => {
description: "event1 description",
date: "2022-07-3O",
mintLimit: 10,
tokenId: 0,
usePoint: false,
useMtx: false,
nonTransferable: false,
secretPhrase: publicInputCalldata[0],
Expand Down Expand Up @@ -894,6 +916,8 @@ describe("mint locked flag", () => {
description: "event1 description",
date: "2022-07-3O",
mintLimit: 10,
tokenId: 0,
usePoint: false,
useMtx: false,
nonTransferable: false,
secretPhrase:
Expand Down Expand Up @@ -998,6 +1022,8 @@ describe("non transferable flag", () => {
"event1 description",
"2022-07-3O",
10,
0,
false,
false,
false,
correctProofCalldata,
Expand Down Expand Up @@ -1086,6 +1112,8 @@ describe("reset secret phrase", () => {
description: "event1 description",
date: "2022-07-3O",
mintLimit: 10,
tokenId: 0,
usePoint: false,
useMtx: false,
nonTransferable: false,
secretPhrase: correctProofCalldata,
Expand Down