-
Notifications
You must be signed in to change notification settings - Fork 0
/
freedom.sol
224 lines (171 loc) · 10.2 KB
/
freedom.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
// This Smart Contract defines the cryptocurrency named Freedom (FREE)
// The goal of this project is to serve as a tool for freedom, fairness, peace and love
// This project shall inspire people to explore sufficiently decentralized crypto currencies and the corresponding concepts & technologies
// This project is inspired by the https://cultdao.io & by the https://cultmagazine.org (2022 & 2023)
// Please use self hosted wallets (at the moment https://metamask.io seems the best - still waiting for https://twitter.com/web3d3v wallet)
// Please make sure to use the right smart contract address & ensure you are connected with the right network
// Please make sure you are aware that there are many scammers out there. Do your own research and talk to people who already know more than you about self hosted wallets...
// This project can also serve as a mirror to be held in front of the people who blindly obey their unfair political regimes after the ones who supported freedom early are already rich and free
// SPDX-License-Identifier: GNU GPL v3
pragma solidity 0.8.2;
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
/// @custom:security-contact dm to https://twitter.com/Peer2peerE
contract Freedom is ERC20 {
struct Member {
uint256 appliedOn;
string proofLink;
uint256 amountOfReceivedApprovals;
uint256 approvedOn;
address[] approversForThisMember;
}
struct MemberMaster {
address walletAddressOfMember;
Member memberInfo;
}
mapping(address => Member) public members;
address[] public memberAndProspectAddresses;
uint256 public totalAmountOfApprovedMembers = 0;
uint256 public threshold = 1;
bool contractInitializationCompleted = false;
event MembershipApproved(address addressOfNewlyApprovedMember);
event MembershipNeedsMoreApprovals(address addressOfProspect, uint256 amountOfApprovalsReceived, uint256 currentThreshold);
event LOGIT(uint256 myText);
constructor() ERC20("Freedom", "FREE") {
uint32 fixedSupply = 24000000;
_mint(address(this), fixedSupply * (10 ** decimals())); // all 24.000.000 coins to the contract
}
modifier onlyApprovedMembers() {
require(members[msg.sender].approvedOn > 0, "only approved Members can do that");
_;
}
modifier onlyNotYetApprovedMembersCanBeApproved(address memberAddress) {
require(members[memberAddress].approvedOn == 0, "only not yet approved members can be approved");
_;
}
modifier onlyTokenholdersCanApprove {
require (balanceOf(msg.sender) > 0, "only holders can approve others");
_;
}
modifier onlyExecutedOnce() {
require(contractInitializationCompleted == false, "this ensures the dev of this smart contract only approves himself once");
_;
}
modifier notYetInApproversListOfProspect(address prospectAddress) {
for (uint256 i = 0; i < members[prospectAddress].approversForThisMember.length; i++) {
require(members[prospectAddress].approversForThisMember[i] != msg.sender, "we avoid duplicate approvals from one approver for one prospect");
}
_;
}
function applyForMembership(string calldata proofLink) public {
require(members[msg.sender].appliedOn == 0, "it seems this wallet already applied once.");
members[msg.sender].appliedOn = block.timestamp;
members[msg.sender].proofLink = proofLink;
memberAndProspectAddresses.push(msg.sender);
}
function approveMembership(address memberAddress) public notYetInApproversListOfProspect(memberAddress) onlyApprovedMembers onlyNotYetApprovedMembersCanBeApproved(memberAddress) onlyTokenholdersCanApprove {
require(members[memberAddress].appliedOn > 0, "this prospect seems not to have provided a great prooflink yet.");
require(msg.sender != memberAddress, "we avoid people to approve themselves - only the dev can do that once");
members[memberAddress].amountOfReceivedApprovals++;
members[memberAddress].approversForThisMember.push(msg.sender);
if (members[memberAddress].amountOfReceivedApprovals >= threshold) {
members[memberAddress].approvedOn = block.timestamp;
if (balanceOf(address(this)) >= 24 * (10 ** 18)){
this.transfer(memberAddress, 24 * (10 ** decimals())); // the welcome gift for everyone until fully distributed
}
totalAmountOfApprovedMembers = totalAmountOfApprovedMembers + 1;
if ((totalAmountOfApprovedMembers % 2) == 0) {
threshold++;
}
emit MembershipApproved(memberAddress);
} else {
emit MembershipNeedsMoreApprovals(memberAddress, members[memberAddress].amountOfReceivedApprovals, threshold);
}
}
function transferRewardToSuccessfulApprovers(address newApprovedMember) public {
for (uint i = 0; i < members[newApprovedMember].approversForThisMember.length; i++) {
if (balanceOf(address(this)) >= (1 * (10 ** 18))){
if (balanceOf(members[newApprovedMember].approversForThisMember[i]) < 240 * (10**18)){ // assumption: no one needs more than 240 FREE - decentralization rocks
this.transfer(members[newApprovedMember].approversForThisMember[i], 1 * (10 ** decimals())); // approvers reward
}
}
}
}
function approveMembershipOfDeveloper(string calldata proofLink) public onlyExecutedOnce {
members[msg.sender].appliedOn = block.timestamp;
members[msg.sender].proofLink = proofLink;
members[msg.sender].amountOfReceivedApprovals = 1; // by myself to initialize and to stay one of teh many
members[msg.sender].approversForThisMember.push(msg.sender); // as the developer I approve my own membership see onlyExecutedOnce
members[msg.sender].approvedOn = block.timestamp;
this.transfer(msg.sender, 24 * (10 ** decimals())); // the welcome gift for everyone until fully distributed
totalAmountOfApprovedMembers = totalAmountOfApprovedMembers + 1; // shall be 1 then
contractInitializationCompleted = true; // so this function can not be executed once again
memberAndProspectAddresses.push(msg.sender);
emit MembershipApproved(msg.sender);
}
function getMember(address memberAddress) public view returns(Member memory) {
return members[memberAddress];
}
function buyFreedom() public payable onlyApprovedMembers {
uint256 conversionRate = 0;
if (totalAmountOfApprovedMembers < 1000000 && totalAmountOfApprovedMembers >= 0) {
conversionRate = 1000000 - totalAmountOfApprovedMembers;
} else {
conversionRate = 1;
}
uint256 amountOfEtherReceived = msg.value;
uint256 amountOfFreedomToBeSent = amountOfEtherReceived * conversionRate;
require((balanceOf(msg.sender) + amountOfFreedomToBeSent) <= 240 * (10**18), "assumption: no one needs more than 240 FREE - decentralization rocks");
this.transfer(msg.sender, amountOfFreedomToBeSent);
}
function sellFreedom(uint256 amount) external onlyApprovedMembers {
require(allowance(msg.sender, address(this)) >= amount, "set allowance first");
require(amount >= (0.001 * (10 **18)), "you might send a higher amount to avoid arithmetic challenges");
uint256 conversionRate = 0;
if (totalAmountOfApprovedMembers < 1000000) {
conversionRate = 1000000 - totalAmountOfApprovedMembers;
} else {
conversionRate = 1;
}
uint256 amountOfEtherINWEIToBeSent = amount / conversionRate;
require(address(this).balance >= amountOfEtherINWEIToBeSent, "Not enough ETH liquidity available for this deal atm.");
IERC20(address(this)).transferFrom(msg.sender, address(this), amount);
emit LOGIT(amountOfEtherINWEIToBeSent);
payable(msg.sender).transfer(amountOfEtherINWEIToBeSent);
}
function getEtherBalanceOfSmartContract() public view returns(uint256) {
return address(this).balance;
}
function getProspects() public view returns(MemberMaster[] memory) {
MemberMaster[] memory prospects = new MemberMaster[](memberAndProspectAddresses.length);
for (uint256 i = 0; i < memberAndProspectAddresses.length; i++) {
if (members[memberAndProspectAddresses[i]].approvedOn == 0) {
prospects[i] = MemberMaster({ walletAddressOfMember: memberAndProspectAddresses[i], memberInfo: members[memberAndProspectAddresses[i]]});
}
}
return prospects;
}
function getApprovedMembers() public view returns(MemberMaster[] memory) {
MemberMaster[] memory approvedMembers = new MemberMaster[](memberAndProspectAddresses.length); // array can be bigger than it needs to be
// Member[] memory approvedMembers = new Member[](memberAndProspectAddresses.length); // array can be bigger than it needs to be
for (uint256 i = 0; i < memberAndProspectAddresses.length; i++) {
if (members[memberAndProspectAddresses[i]].approvedOn > 0) {
approvedMembers[i] = MemberMaster({ walletAddressOfMember: memberAndProspectAddresses[i], memberInfo: members[memberAndProspectAddresses[i]]});
}
}
return approvedMembers;
}
// function investInDAO(address smartContractAddressOfDAOToBeInvestedIn) public onlyTop1000Holders {
// might be implemented and deployed when modulus mainnet is available
// instead of ETH we would use CULT on modulus
// combine long-, mid-, and short- term bollinger bands - see also https://deno.land/x/bollinger_bands
// the following is just pseudo code which might serve as a reminder or inspiration
// struct DAOToBeInvestedIn {
// address smartContractAddressOfDAOToBeInvestedIn; // resp. CULT on Modulus
// uint256 numberOfUpvotes;
// uint256 numberOfDownvotes;
// }
// uint256 thresholdForDAOToBeInvestedInDecision;
// uint256 thresholdForRemovingDAOFromFurtherInvestments;
// }
}