Skip to content

Instantly share code, notes, and snippets.

@derekalia
Created March 10, 2019 20:46
Show Gist options
  • Save derekalia/755fe3d9f1eebefc5043d65d27e27f57 to your computer and use it in GitHub Desktop.
Save derekalia/755fe3d9f1eebefc5043d65d27e27f57 to your computer and use it in GitHub Desktop.
pragma solidity ^0.5.2;
import "openzeppelin-solidity/contracts/math/SafeMath.sol";
import "openzeppelin-solidity/contracts/ownership/Ownable.sol";
import "openzeppelin-solidity/contracts/token/ERC20/ERC20.sol";
import "openzeppelin-solidity/contracts/token/ERC721/ERC721Full.sol";
import "openzeppelin-solidity/contracts/drafts/Counter.sol";
contract Tribe is ERC721Full, Ownable {
using SafeMath for uint256;
using SafeMath for uint8;
using Counter for Counter.Counter;
Counter.Counter private tokenId;
mapping(uint => uint) tierPrice;
mapping(address => mapping(uint => bool)) userSubscription;
mapping(address => uint8) moderatorsPercentage;
string tribeName;
string tribeSymbol;
uint contentPool;
uint bankPool;
uint moderatorPool;
address daiContract;
address safeContract;
address [] moderators;
constructor (
string memory _name,
string memory _symbol,
uint _contentPool,
uint _bankPool,
uint _moderatorPool,
address _daiContract,
address _safe,
address[] memory _modAddressArray,
uint8[] memory _modPercentageArray,
uint[] memory tierPriceArray
) ERC721Full(_name, _symbol) public {
require(_contentPool.add(_bankPool.add(_moderatorPool)) == 100, 'Did not equal 100');
contentPool = _contentPool;
bankPool = _bankPool;
moderatorPool= _moderatorPool;
uint modPercentTotal = 0;
require(_modAddressArray.length == _modPercentageArray.length, 'not equal');
for(uint i = 0; i < _modAddressArray.length; i++){
moderatorsPercentage[_modAddressArray[i]] = _modPercentageArray[i];
uint8 value = _modPercentageArray[i];
modPercentTotal = modPercentTotal.add(value);
moderators.push(_modAddressArray[i]);
}
require(modPercentTotal == 100, 'mod total not equal to 100');
for(uint i = 0; i < tierPriceArray.length; i++){
tierPrice[i] = tierPriceArray[i];
}
daiContract = _daiContract;
tribeName = _name;
tribeSymbol = _symbol;
safeContract = _safe;
}
function addSubscriber(address subscriber, uint tier) public onlyOwner returns (bool){
//get the tier price
uint amountInDai = tierPrice[tier];
//require transfer of dai to this contract
require(ERC20(daiContract).transferFrom(subscriber, address(this), amountInDai), 'Didn’t get the amount of dai');
userSubscription[subscriber][tier] = true;
// uint256 userTokenId = tokenId.next();
// _mint(subscriber, userTokenId);
// _setTokenURI(userTokenId, tokenURI);
return true;
}
function addSubscriberProxy(address subscriber, uint tier) public onlyOwner returns (bool){
userSubscription[subscriber][tier] = true;
return true;
}
function createNFT(address owner, string memory tokenURI) public onlyOwner returns (bool){
uint256 userTokenId = tokenId.next();
_mint(owner, userTokenId);
_setTokenURI(userTokenId, tokenURI);
return true;
}
function removeSubscriber(address subscriber, uint tier) public onlyOwner {
userSubscription[subscriber][tier] = false;
}
function getUserStatus(address subscriber, uint tier) public view returns (bool){
return userSubscription[subscriber][tier];
}
function getModeratorCount() public view returns (uint){
return moderators.length;
}
function getModeratorAddress(uint index) public view returns (address){
return moderators[index];
}
function getModeratorPercent(address mod) public view returns (uint8){
return moderatorsPercentage[mod];
}
function getContentPool() public view returns (uint){
return contentPool;
}
function getModeratorPool() public view returns (uint){
return moderatorPool;
}
function getTierPrice(uint index) public view returns (uint){
return tierPrice[index];
}
function contentPoolPayout(address[] memory usersArray, uint[] memory payoutArray ) public onlyOwner{
require(usersArray.length == payoutArray.length, 'not equal arrays');
for(uint i = 0; i < usersArray.length; i++){
require(ERC20(daiContract).transferFrom(address(this),usersArray[i],payoutArray[i]), 'Could not send the amount to the user');
}
}
function modPoolPayout(address[] memory modArray, uint[] memory payoutArray) public onlyOwner{
require(modArray.length == payoutArray.length, 'not equal arrays');
for(uint i = 0; i < modArray.length; i++){
require(ERC20(daiContract).transferFrom(address(this),modArray[i],payoutArray[i]), 'Could not send the amount to the mod');
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment