Last active
May 12, 2023 21:57
-
-
Save mayorcoded/8058645eb651330fc8b5950cbf2acb73 to your computer and use it in GitHub Desktop.
This gist creates a membership card for new members, and distributes reward to each new member.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// SPDX-License-Identifier: GPL-3.0 | |
pragma solidity >=0.7.0 <0.9.0; | |
contract Membership { | |
uint256 public totalAmount; | |
uint8 public constant EARLY_MEMBER = 10; | |
uint8 public constant PRO_MEMBER = 20; | |
uint8 public constant ELITE_MEMBER = 30; | |
uint8 public constant EARLY_MEMBER_REWARD = 10; | |
uint8 public constant PRO_MEMBER_REWARD = 20; | |
uint8 public constant ELITE_MEMBER_REWARD = 30; | |
//struct membership data | |
struct MembershipCard { | |
uint8 membership_level; | |
uint256 amount; | |
uint256 membership_reward; | |
} | |
mapping(address => MembershipCard) members; | |
// event for EVM logging | |
event JoinedClub(address indexed newMember, uint256 indexed reward); | |
function joinClub(uint256 amount, address newMember) external { | |
require(amount > 0, "insufficient amount to be a member"); | |
totalAmount += amount; | |
uint256 reward; | |
if(amount <= EARLY_MEMBER) { | |
reward = (EARLY_MEMBER_REWARD * amount) / totalAmount; | |
members[newMember] = MembershipCard ( | |
EARLY_MEMBER, | |
amount, | |
reward | |
); | |
} | |
if(amount <= PRO_MEMBER) { | |
reward = (PRO_MEMBER_REWARD * amount) / totalAmount; | |
members[newMember] = MembershipCard ( | |
EARLY_MEMBER, | |
amount, | |
reward | |
); | |
} | |
if(amount <= ELITE_MEMBER) { | |
reward = (ELITE_MEMBER_REWARD * amount) / totalAmount; | |
members[newMember] = MembershipCard ( | |
ELITE_MEMBER, | |
amount, | |
reward | |
); | |
} | |
emit JoinedClub(newMember, reward); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment