Skip to content

Commit

Permalink
Merge pull request #40 from district0x/matching-pool-erc20
Browse files Browse the repository at this point in the history
Matching pool erc20
  • Loading branch information
ginesdt committed Apr 23, 2024
2 parents 7f263e5 + f915206 commit b67356b
Show file tree
Hide file tree
Showing 26 changed files with 777 additions and 237 deletions.
152 changes: 81 additions & 71 deletions contracts/streamtide.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ pragma solidity ^0.8.0;
import "@openzeppelin/contracts-upgradeable/access/OwnableUpgradeable.sol";
import "@openzeppelin/contracts-upgradeable/proxy/utils/Initializable.sol";
import "@openzeppelin/contracts/utils/Context.sol";

import "@openzeppelin/contracts/token/ERC20/IERC20.sol";


contract MVPCLR is OwnableUpgradeable {

event AdminAdded(address _admin);
event AdminRemoved(address _admin);
event BlacklistedAdded(address _blacklisted);
Expand All @@ -21,9 +21,10 @@ contract MVPCLR is OwnableUpgradeable {
event RoundStarted(uint256 roundStart, uint256 roundId, uint256 roundDuration);
event RoundClosed(uint256 roundId); // Added event
event MatchingPoolDonation(address sender, uint256 value, uint256 roundId);
event Distribute(address to, uint256 amount, uint256 roundId);
event DistributeRound(uint256 roundId, uint256 amount);

event MatchingPoolDonationToken(address sender, uint256 value, uint256 roundId, address token);
event Distribute(address to, uint256 amount, uint256 roundId, address token);
event DistributeRound(uint256 roundId, uint256 amount, address token);


event Donate(
address sender,
Expand All @@ -48,35 +49,43 @@ contract MVPCLR is OwnableUpgradeable {
mapping(address => bool) public isAdmin;
mapping(address => bool) public isPatron;
mapping(address => bool) public isBlacklisted;

address public multisigAddress;

function construct(address _multisigAddress) external initializer {
__Ownable_init(); // Add this line to initialize the OwnableUpgradeable contract
multisigAddress = _multisigAddress;
roundId = 0;
lastActiveRoundId = 0;
}
__Ownable_init(); // Add this line to initialize the OwnableUpgradeable contract
multisigAddress = _multisigAddress;
roundId = 0;
lastActiveRoundId = 0;
}

function setMultisigAddress(address _multisigAddress) external onlyMultisig {
multisigAddress = _multisigAddress;
}
multisigAddress = _multisigAddress;
}

function fillUpMatchingPool() public payable onlyAdmin {
require(msg.value > 0, "MVPCLR:fillUpMatchingPool - No value provided");
emit MatchingPoolDonation(msg.sender, msg.value, roundId);
}
require(msg.value > 0, "MVPCLR:fillUpMatchingPool - No value provided");
emit MatchingPoolDonation(msg.sender, msg.value, roundId);
}

function fillUpMatchingPoolToken(address from, address token, uint amount) public onlyAdmin {
require(!roundIsClosed());
require(amount > 0, "MVPCLR:fillUpMatchingPoolToken - No amount provided");

IERC20(token).transferFrom(from, address(this), amount);

emit MatchingPoolDonationToken(from, amount, roundId, token);
}

function closeRound() public onlyAdmin {
roundDuration = 0;
// roundId = 0;
emit RoundClosed(lastActiveRoundId); // Added event emission
}
}

function roundIsClosed() public view returns (bool) {
return roundDuration == 0 || roundStart + roundDuration <= getBlockTimestamp();
}
}

function startRound(uint256 _roundDuration) public payable onlyAdmin {
require(roundIsClosed(), "MVPCLR: startRound - Previous round not yet closed");
Expand All @@ -88,34 +97,34 @@ contract MVPCLR is OwnableUpgradeable {
emit RoundStarted(roundStart, roundId, roundDuration);
emit MatchingPoolDonation(msg.sender, msg.value, roundId); // Emit event for the added funds

}
}

function addAdmin(address _admin) public onlyOwner {
isAdmin[_admin] = true;
emit AdminAdded(_admin);
}
}

function removeAdmin(address _admin) public onlyOwner {
require(isAdmin[_admin], "Admin not found"); // check if the address is an admin
delete isAdmin[_admin];
emit AdminRemoved(_admin);
}
}

function getBlockTimestamp() public view returns (uint256) {
return block.timestamp;
}
}

function addBlacklisted(address _address) public onlyAdmin {
isBlacklisted[_address] = true;
emit BlacklistedAdded(_address);
}
}


function removeBlacklisted(address _address) public onlyAdmin {
require(isBlacklisted[_address], "Address not blacklisted");
delete isBlacklisted[_address];
emit BlacklistedRemoved(_address);
}
}

function addPatrons(address payable[] calldata addresses) public onlyAdmin {
for (uint256 i = 0; i < addresses.length; i++) {
Expand All @@ -124,67 +133,68 @@ contract MVPCLR is OwnableUpgradeable {
isPatron[addr] = true;
}
emit PatronsAdded(addresses);
}
}

function donate(address[] memory patronAddresses, uint256[] memory amounts) public payable {
require(patronAddresses.length == amounts.length, "CLR:donate - Mismatch between number of patrons and amounts");
uint256 totalAmount = 0;
uint256 donationRoundId = roundIsClosed() ? 0 : roundId;
for (uint256 i = 0; i < patronAddresses.length; i++) {
address patronAddress = patronAddresses[i];
uint256 amount = amounts[i];
totalAmount += amount;
require(!isBlacklisted[_msgSender()], "Sender address is blacklisted");
require(isPatron[patronAddress], "CLR:donate - Not a valid recipient");
emit Donate(_msgSender(), amount, patronAddress, donationRoundId);
bool success = payable(patronAddress).send(amount);
require(success, "CLR:donate - Failed to send funds to recipient");
}

require(totalAmount <= msg.value, "CLR:donate - Total amount donated is greater than the value sent");
// transfer the donated funds to the contract
// payable(address(this)).transfer(msg.value);
}
require(patronAddresses.length == amounts.length, "CLR:donate - Mismatch between number of patrons and amounts");
uint256 totalAmount = 0;
uint256 donationRoundId = roundIsClosed() ? 0 : roundId;
for (uint256 i = 0; i < patronAddresses.length; i++) {
address patronAddress = patronAddresses[i];
uint256 amount = amounts[i];
totalAmount += amount;
require(!isBlacklisted[_msgSender()], "Sender address is blacklisted");
require(isPatron[patronAddress], "CLR:donate - Not a valid recipient");
emit Donate(_msgSender(), amount, patronAddress, donationRoundId);
bool success = payable(patronAddress).send(amount);
require(success, "CLR:donate - Failed to send funds to recipient");
}

require(totalAmount <= msg.value, "CLR:donate - Total amount donated is greater than the value sent");
// transfer the donated funds to the contract
// payable(address(this)).transfer(msg.value);
}

function distribute(address payable[] memory patrons, uint[] memory amounts) public onlyAdmin {
require(patrons.length == amounts.length, "Length of patrons and amounts must be the same");
uint256 totalAmount = 0; // Store total amount to be distributed

// Loop through the list of patrons and distribute the funds to each address
for (uint i = 0; i < patrons.length; i++) {
// Make sure the recipient address is a valid patron address
require(isPatron[patrons[i]], "CLR:distribute - Not a valid recipient");
patrons[i].transfer(amounts[i]); // Reverts transaction if transfer fails
emit Distribute(patrons[i], amounts[i], roundId);
totalAmount += amounts[i]; // Add the amount to totalAmount
}
function distribute(address payable[] memory patrons, uint[] memory amounts, address token) public onlyAdmin {
require(patrons.length == amounts.length, "Length of patrons and amounts must be the same");
uint256 totalAmount = 0; // Store total amount to be distributed

// Loop through the list of patrons and distribute the funds to each address
for (uint i = 0; i < patrons.length; i++) {
// Make sure the recipient address is a valid patron address
require(isPatron[patrons[i]], "CLR:distribute - Not a valid recipient");
if (token == address(0))
patrons[i].transfer(amounts[i]); // Reverts transaction if transfer fails
else
IERC20(token).transfer(patrons[i], amounts[i]);
emit Distribute(patrons[i], amounts[i], roundId, token);
totalAmount += amounts[i]; // Add the amount to totalAmount
}
// matchingPool -= totalAmount; // Subtract the total distributed amount from the matching pool
emit DistributeRound(roundId, totalAmount);
}
emit DistributeRound(roundId, totalAmount, token);
}

//only designated multisig address can call this function
function withdrawFunds(uint256 amount) external onlyMultisig {
require(address(this).balance >= amount, "Insufficient funds in contract");
payable(multisigAddress).transfer(amount);
}


require(address(this).balance >= amount, "Insufficient funds in contract");
payable(multisigAddress).transfer(amount);
}

// receive donation for the matching pool
receive() external payable {
require(roundStart == 0 || getBlockTimestamp() < roundStart + roundDuration,"CLR:receive closed");
emit MatchingPoolDonation(_msgSender(), msg.value, roundId);
}
require(roundStart == 0 || getBlockTimestamp() < roundStart + roundDuration, "CLR:receive closed");
emit MatchingPoolDonation(_msgSender(), msg.value, roundId);
}

modifier onlyAdmin() {
require(isAdmin[msg.sender] == true, "Not an admin");
_;
}
require(isAdmin[msg.sender] == true, "Not an admin");
_;
}

modifier onlyMultisig() {
require(msg.sender == multisigAddress, "Not authorized");
_;
}
require(msg.sender == multisigAddress, "Not authorized");
_;
}

}
2 changes: 1 addition & 1 deletion resources/scss/components/form.scss
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
}
}
.select__menu {
border: 3px solid #a478f9;
border: 3px solid $lilac;
border-radius: 7px;
background-color: $bgSite;
}
Expand Down
4 changes: 2 additions & 2 deletions resources/scss/components/popUpGrant.scss
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@
width: calc(100% - 6px);
border-radius: 7px;
overflow: hidden;
box-shadow: 0px 0px 0px 3px #a478f9;
box-shadow: 0px 0px 0px 3px $lilac;
height: 277px;
margin-bottom: 11px;
text-align: left;
Expand Down Expand Up @@ -281,7 +281,7 @@
a {
text-decoration: underline;
text-decoration-thickness: 2px;
color: #a478f9;
color: $lilac;
&:hover {
color: #3b1d56;
}
Expand Down
3 changes: 0 additions & 3 deletions resources/scss/components/user.scss
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
position: absolute;
bottom: 0;
right: -9.5px;
z-index: 10;
}
}
&.lb {
Expand Down Expand Up @@ -71,7 +70,6 @@
position: absolute;
top: 6px;
right: 6px;
z-index: 10;
}
}
}
Expand All @@ -87,7 +85,6 @@
position: absolute;
top: -2px;
right: -3px;
z-index: 10;
}
}
@include media-breakpoint-up(md) {
Expand Down
12 changes: 10 additions & 2 deletions resources/scss/layouts/admin.scss
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
bottom: 5px;
right: 5px;
font-size: smaller;
background: #a478f9;
background: $lilac;
border-radius: 92px;
padding: 1px 4px;
color: white;
Expand Down Expand Up @@ -284,7 +284,7 @@
width: calc(100% - 6px);
border-radius: 7px;
overflow: hidden;
box-shadow: 0px 0px 0px 3px #a478f9;
box-shadow: 0px 0px 0px 3px $lilac;
height: 36px;
margin: 0 auto 21px;
.input-group {
Expand Down Expand Up @@ -421,6 +421,11 @@
.cel {
display: flex;
justify-content: space-between;

.amounts {
display: flex;
flex-direction: column;
}
}
margin-bottom: 14px;
background: $bgCard;
Expand Down Expand Up @@ -636,6 +641,9 @@
justify-content: space-between;
.cel {
width: calc(33.33% - 8.66px);
.amounts {
row-gap: 5px;
}
}
.data {
margin-bottom: 0;
Expand Down
17 changes: 13 additions & 4 deletions resources/scss/layouts/leaderboards.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
margin-right: 21.05px;
}
.data {
a {
width: 100%;
}
width: calc(100% - 80px);
font-size: 16px;
line-height: 22px;
Expand All @@ -31,17 +34,22 @@
li {
width: 100%;
display: flex;
align-items: center;
justify-content: space-between;
font-size: 16px;
line-height: 28px;
line-height: 22px;
margin-bottom: 8px;
h4 {
font-weight: $bold;
color: $blackWhite;
}
&:last-child {
margin-bottom: 0;
}

.amounts {
display: flex;
flex-direction: column;
}
}
}
}
Expand Down Expand Up @@ -84,7 +92,7 @@
margin-bottom: 11.62px;
display: flex;
flex-wrap: nowrap;
padding: 13.36px 13.83px 18.83px;
padding: 13.83px 13.83px 13.83px;
.user {
width: 56px;
margin-right: 23.66px;
Expand Down Expand Up @@ -115,6 +123,7 @@
width: 33.33%;
display: block;
text-align: center;
margin-bottom: 0px;
}
}
}
Expand Down Expand Up @@ -160,7 +169,7 @@
margin-bottom: 11.62px;
display: flex;
flex-wrap: nowrap;
padding: 13.36px 13.83px 18.83px;
padding: 13.83px 13.83px 13.83px;
.user {
width: 56px;
margin-right: 23.66px;
Expand Down

0 comments on commit b67356b

Please sign in to comment.