Skip to content

Instantly share code, notes, and snippets.

@RossPfeiffer
Created October 23, 2019 04:27
Show Gist options
  • Save RossPfeiffer/e1400be4d72ef2d41a264ae02febae0e to your computer and use it in GitHub Desktop.
Save RossPfeiffer/e1400be4d72ef2d41a264ae02febae0e to your computer and use it in GitHub Desktop.
pragma solidity ^ 0.5.12;
contract ColorToken{
address THIS = address(this);
address constant nulf = 0x0000000000000000000000000000000000000000;
string public name = "Color Token";
string public symbol = "RGB";
uint8 constant public decimals = 18;
uint _totalSupply/*===*/;
mapping(address => address payable) proxy;
mapping(address => address payable) proxyOwner;
mapping(address => uint256) coloredBonds;
mapping(address => uint256) redBonds;
mapping(address => uint256) greenBonds;
mapping(address => uint256) blueBonds;
mapping(address => uint256) lockedResolves;
mapping(address => uint256) coloredResolves;
mapping(address => uint256) redResolves;
mapping(address => uint256) greenResolves;
mapping(address => uint256) blueResolves;
mapping(address => mapping(address => uint)) approvals;
mapping(address => address) gateway;
mapping(address => uint256) pocket;
mapping(address => uint256) upline;
mapping(address => address) minecart;
mapping(address => address) votingForCR;
mapping(address => uint256) votesForCR;
mapping(address => uint) votingForMR;
mapping(uint => uint256) votesForMR;
BondContract bondContract;
ResolveContract resolveContract;
RNS rns;
address lastGateway;
address communityResolve;
uint _totalBonds;
uint pyrColorResolves;
uint masternodeRequirement = 0;
uint colorFee = 10; // 10%
constructor(address _bondContract) public{
bondContract = BondContract( _bondContract );
resolveContract = ResolveContract( bondContract.getResolveContract() );
rns = new RNS(THIS);
communityResolve = msg.sender;
lastGateway = THIS;
}
function totalSupply() public view returns (uint256) {
return _totalSupply/*===*/;
}
function balanceOf(address addr) public view returns (uint balance) {
if(proxyAddress(addr) == nulf)
return 0;
return PyramidProxy( proxyAddress(addr) ).getBalance();
}
/*function max1(uint x) internal pure returns (uint){
if(x>1e12)
return 1e12;
else
return x;
}*/
/*function proxy(address addr) returns(PyramidProxy){
proxies[proxyID[addr]]
}*/
function ensureProxy(address addr) internal{
if( proxyAddress(addr) == nulf){
PyramidProxy prox = new PyramidProxy( this, bondContract );
proxy[addr] = address(prox);
proxyOwner[ address(prox) ] = address(uint160(addr));
}
}
function fundCR() payable public {
pocket[THIS] += msg.value;
}
event MinecartPush(address indexed addr, address newMinecartLocation, uint upline, address nextUpline );
event GatewaySwitch(address newGateway );
function pushMinecart(address addr) public {
if( _coloredResolves(addr)>0 /*|| coloredBonds[addr]>0 || pocket[addr]>0 || upline[addr]>0*/){
address gate = gateway[addr];
if( gate != THIS && (gate == nulf || !checkMR(gate) ) ){
gateway[addr] = lastGateway;
emit GatewaySwitch(lastGateway);
}
address MINECART = minecart[addr];
address upCART = gateway[ MINECART ];
if( MINECART == THIS || MINECART == nulf){
minecart[addr] = addr;
MINECART = addr;
}else{
minecart[addr] = upCART;
MINECART = upCART;
}
//address dropOff = MINECART;
uint up = upline[ MINECART ];
pocket[ MINECART ] += up/5;
upline[ gateway[MINECART] ] += up - up/5;
upline[ MINECART ] = 0;
emit MinecartPush(addr, MINECART, up, upCART);
}
assertNewMR(_votingForMR(msg.sender));
assertNewCR(_votingForCR(msg.sender));
}
/*function getData(address A) public view returns (address,uint,uint){
return ( gateway[A], pocket[A], upline[A] );
}*/
/*function getData(address A) public view returns (address,uint,uint){
return (gateway[A], pocket[A], upline[A] );
}*/
function getData(address A, int numeric) public view returns (address,address,address,uint,uint,uint){
//address nulf = nulf;
if(numeric < 0){
if(A == nulf){
return ( address(bondContract), lastGateway, communityResolve, _totalBonds, pyrColorResolves, masternodeRequirement);
}else{
return (gateway[A], minecart[A], _votingForCR(A), pocket[A], upline[A], _votingForMR(A) );
}
}else{
return (nulf, nulf, nulf, _votesForCR(A), _votesForMR((uint)(numeric)), 0);
}
}
event Sell( address indexed addr, uint256 bondsSold, uint256 resolves, uint red, uint green, uint blue);
function publix(uint8 Type, uint numeric) public{
if(Type == 0){
sell(numeric);
}else if(Type==1){
stake(numeric);
}else if(Type==2){
unstake(numeric);
}else if(Type==3){
reinvest(numeric);
}else if(Type==4){
withdraw(numeric);
}else if(Type==5){
setVotingForMR(numeric);
}else if(Type==6){
pullAffiliateEarningsOnly();
}/*else if(Type==7){
}*/
}
function sell(uint amountToSell) internal{
address sender = msg.sender;
uint coloredBondsBefore = coloredBonds[sender];
uint regularBonds = bondBalance(sender) - coloredBondsBefore;
//if(amountToSell>)
uint coloredAmountToSell = amountToSell;
if(regularBonds>0){
uint regularBondsToBeSold;
if(amountToSell >= regularBonds){
regularBondsToBeSold = regularBonds;
coloredAmountToSell -= regularBonds;
}else{
regularBondsToBeSold = amountToSell;
coloredAmountToSell = 0;
}
PyramidProxy( proxyAddress(sender) ).publix(0, regularBondsToBeSold);
}
if(coloredAmountToSell>0){
(uint _red, uint _green, uint _blue) = RGB_bondRatio();
(uint mintedResolves,) = PyramidProxy( proxyAddress(sender) ).publix(0,coloredAmountToSell);
_totalBonds -= coloredAmountToSell;
/*uint _red = redBonds[sender] / coloredBondsBefore;
uint _green = greenBonds[sender] / coloredBondsBefore;
uint _blue = blueBonds[sender] / coloredBondsBefore;*/
resolvesAddColor(sender, mintedResolves, _red*1e6, _green*1e6, _blue*1e6);
votesForCR[ _votingForCR(sender) ] += mintedResolves;
if(!isContract(sender)) votesForMR[ _votingForMR(sender) ] += mintedResolves;
_totalSupply/*===*/ += mintedResolves;
coloredResolves[sender] += mintedResolves;
emit Sell(sender, coloredAmountToSell, mintedResolves, _red, _green, _blue );
bondsThinColor(sender, coloredBondsBefore - coloredAmountToSell, coloredBondsBefore);
}
pushMinecart(sender);
}
function _votesForCR(address addr) internal view returns(uint){return votesForCR[addr];}
function _votingForCR(address addr) internal view returns(address){return votingForCR[addr];}
function _votesForMR(uint MR) internal view returns(uint){return votesForMR[MR];}
function _votingForMR(address addr) internal view returns(uint){return votingForMR[addr];}
function stake(uint amountToStake) internal{
address sender = msg.sender;
colorShift(sender, address(bondContract), amountToStake );
pyrColorResolves += amountToStake;
PyramidProxy( proxyAddress(sender) ).publix(1, amountToStake );
pushMinecart(sender);
minecart[sender] = sender;/* a little bit of economic chaos theory going on here.
since most people at the edges will have most of the resolves,
they will be the most likely to stake. you don't need as many
minecart pushers near the top of the affiliate system*/
}
function unstake(uint amountToUnstake) internal{
address sender = msg.sender;
colorShift(address(bondContract), sender, amountToUnstake );//pyrColorResolves
pyrColorResolves -= amountToUnstake;
PyramidProxy(proxyAddress(sender)).publix(2, amountToUnstake );
pushMinecart(sender);
}/**/
event Reinvest( address indexed addr, uint256 affiliateEarningsSpent, uint256 bonds);
function reinvest(uint amount) internal{
address sender = msg.sender;
//address proxyAddr = proxyAddress( sender );
//uint bal = bondContract.balanceOf( proxyAddr );
/*uint red = redBonds[sender] / bal;
uint green = greenBonds[sender] / bal;
uint blue = blueBonds[sender] / bal;*/
(uint red, uint green, uint blue) = RGB_bondRatio();
uint createdBonds;
uint dissolvedResolves;
(createdBonds, dissolvedResolves) = PyramidProxy( proxyAddress(sender) ).publix(3,amount);
uint pock = pocket[sender];
pocket[sender] = 0;
_totalBonds += createdBonds;
createdBonds += buy( sender, pock, red, green, blue, false);
coloredBonds[sender] += createdBonds;
bondsAddColor(sender, createdBonds, red, green, blue);
// update core contract's Resolve color
//address pyrAddr = address(bondContract);
//uint currentResolves = pyrColorResolves;//resolveContract.balanceOf( pyrAddr );
pyrColorResolves -= dissolvedResolves;
resolvesThinColor( address(bondContract) , pyrColorResolves, pyrColorResolves + dissolvedResolves);
emit Reinvest( sender, pock, createdBonds);
pushMinecart(sender);
}
function withdraw(uint amount) internal{
address payable sender = msg.sender;
(uint dissolvedResolves,) = PyramidProxy(proxyAddress(sender)).publix(4,amount);
uint earned = pocket[sender];
pocket[sender] = 0;
// update core contract's Resolve color
//address pyrAddr = address(bondContract);
//uint currentResolves = resolveContract.balanceOf( pyrAddr );
pyrColorResolves -= dissolvedResolves;
resolvesThinColor(address(bondContract), pyrColorResolves, pyrColorResolves + dissolvedResolves);
pushMinecart(sender);
sender.transfer( earned );
}
function proxyAddress(address addr) public view returns(address payable addressOfProxxy){
return proxy[addr];//address( proxies[ proxyID[addr] ] );
}
function getProxyOwner(address proxyAddr) external view returns(address ownerAddress){
return proxyOwner[proxyAddr];
}
function unbindResolves(uint amount) public {
address sender = msg.sender;
uint totalResolves = resolveContract.balanceOf( proxyAddress(sender) );
resolvesThinColor( sender, totalResolves - amount, totalResolves);
PyramidProxy( proxyAddress(sender) ).transfer(sender, amount);
}
/*event AssertCR( address indexed sender, address addr);
event AssertMR( address indexed sender, uint MR);
event VoteForCandidate( address indexed sender, address addr, uint number);
event VoteForMR( address indexed sender, uint MR, uint number);*/
function setVotingForCR(address candidate) public {
address sender = msg.sender;
//Contracts can't vote for anyone. Because then people would just evenly split the pool fund most of the time
require( !isContract(sender) );//This could be enhanced, but this is a barebones demonstration of the powhr of resolve tokens
uint voteWeight = _coloredResolves(sender);//balanceOf(sender);
votesForCR[ _votingForCR( sender ) ] -= voteWeight;
votingForCR[ sender ] = candidate;
votesForCR[ candidate ] += voteWeight;
//emit VoteForCandidate(msg.sender, candidate, voteWeight);
}
function assertNewCR(address candidate) internal {
if( _votesForCR(candidate) > _votesForCR(communityResolve) ){
communityResolve = candidate;
//emit AssertCR(msg.sender, candidate);
}
}
function setVotingForMR(uint MR_votingFor) internal {
address sender = msg.sender;
if(!isContract(sender)) {
uint voteWeight = _coloredResolves(sender);
votesForMR[ _votingForMR( sender ) ] -= voteWeight;
votingForMR[ sender ] = MR_votingFor;
votesForMR[ MR_votingFor ] += voteWeight;
}
//emit VoteForMR(msg.sender, _votingForMR, voteWeight);
}
function assertNewMR(uint MR_votingFor) internal {
if( _votesForMR(MR_votingFor) > _votesForMR(masternodeRequirement) ){
masternodeRequirement = MR_votingFor;
//emit AssertMR(msg.sender, _votingForMR);
}
}
function pullAffiliateEarningsOnly() internal{
if(msg.sender == communityResolve){
pushMinecart(THIS);
uint money_gotten = pocket[ THIS ];
money_gotten += pocket[ msg.sender ];
pocket[ msg.sender ] = 0;
pocket[ THIS ] = 0;
msg.sender.transfer(money_gotten);
}else{
pushMinecart(msg.sender);
uint money_gotten = pocket[ msg.sender ];
pocket[ msg.sender ] = 0;
msg.sender.transfer(money_gotten);
}
}
// Function that is called when a user or another contract wants to transfer funds .
function transfer(address _to, uint _value, bytes memory _data) public returns (bool success) {
if( balanceOf(msg.sender)-_lockedResolves(msg.sender) < _value ) revert();
if( isContract(_to) ){
return transferToContract(_to, _value, _data);
}else{
return transferToAddress(_to, _value, _data);
}
}
// Standard function transfer similar to ERC20 transfer with no _data .
// Added due to backwards compatibility reasons .
function transfer(address _to, uint _value) public returns (bool success) {
if (balanceOf(msg.sender)-_lockedResolves(msg.sender) < _value) revert();
//standard function transfer similar to ERC20 transfer with no _data
//added due to backwards compatibility reasons
bytes memory empty;
if(isContract(_to)){
return transferToContract(_to, _value, empty);
}else{
return transferToAddress(_to, _value, empty);
}
}
//assemble the given address bytecode. If bytecode exists then the _addr is a contract.
function isContract(address _addr) internal view returns (bool is_contract) {
uint length = 0;
assembly {
//retrieve the size of the code on target address, this needs assembly
length := extcodesize(_addr)
}
if(length>0) {
return true;
}else {
return false;
}
}
//function that is called when transaction target is an address
function transferToAddress(address _to, uint _value, bytes memory _data) private returns (bool success) {
moveTokens(msg.sender,_to,_value);
return true;
}
//function that is called when transaction target is a contract
function transferToContract(address _to, uint _value, bytes memory _data) private returns (bool success) {
moveTokens(msg.sender,_to,_value);
ERC223ReceivingContract reciever = ERC223ReceivingContract(_to);
reciever.tokenFallback(msg.sender, _value, _data);
return true;
}
function moveTokens(address _from, address _to, uint _amount) internal{
uint coloredWeight = _coloredResolves(_from) * _amount / balanceOf(_from);
colorShift(_from, _to, _amount);
ensureProxy(_to);
votesForCR[ _votingForCR(_from) ] -= coloredWeight;
votesForCR[ _votingForCR(_to) ] += coloredWeight;
if(!isContract(_from)) votesForMR[ _votingForMR(_from) ] -= coloredWeight;
if(!isContract(_to)) votesForMR[ _votingForMR(_to) ] += coloredWeight;
PyramidProxy( proxyAddress(_from) ).transfer( proxyAddress(_to), _amount );
}
function RGB_scale(uint r, uint g, uint b, uint c, uint numerator, uint denominator) internal pure returns(uint,uint,uint,uint){
return (r * numerator / denominator, g * numerator / denominator, b * numerator / denominator, c * numerator / denominator );
}
function colorShift(address _from, address _to, uint _amount) internal{
//uint bal = proxy[_from].getBalance();
/*uint red_ratio = redResolves[_from] * _amount / bal;
uint green_ratio = greenResolves[_from] * _amount / bal;
uint blue_ratio = blueResolves[_from] * _amount / bal;*/
uint coloredResolveTotal;
if(_from == address(bondContract) ){
coloredResolveTotal = pyrColorResolves;
}else{
coloredResolveTotal = PyramidProxy( proxyAddress(_from) ).getBalance();
}
(uint red_ratio, uint green_ratio, uint blue_ratio, uint color_ratio) = RGB_scale(redResolves[_from], greenResolves[_from], blueResolves[_from], _coloredResolves(_from), _amount, coloredResolveTotal );
redResolves[_from] -= red_ratio;
greenResolves[_from] -= green_ratio;
blueResolves[_from] -= blue_ratio;
coloredResolves[_from] -= color_ratio;
redResolves[_to] += red_ratio;
greenResolves[_to] += green_ratio;
blueResolves[_to] += blue_ratio;/**/
coloredResolves[_to] += color_ratio;
}
function allowance(address src, address guy) public view returns (uint) {
return approvals[src][guy];
}
event Buy( address indexed addr, uint256 spent, uint256 bonds, uint red, uint green, uint blue);
function buy(address addr, uint ETH, uint _red, uint _green, uint _blue, bool regularBuy) internal returns(uint bondsCreated){
//address sender = msg.sender;
ensureProxy(addr);
/*_red = max1(_red);
_green = max1(_green);
_blue = max1(_blue);*/
if(_red>1e12) return _red = 1e12;
if(_green>1e12) return _green = 1e12;
if(_blue>1e12) return _blue = 1e12;
uint fee;
if(regularBuy){
fee = ETH / colorFee;
}
uint eth4Bonds = ETH - fee;
address payable proxyAddr = proxyAddress(addr);
proxyAddr.transfer(eth4Bonds);
(uint createdBonds,) = PyramidProxy( proxyAddr ).publix(5,0);/**/
_totalBonds += createdBonds;
bondsAddColor(addr,createdBonds, _red, _green, _blue);
coloredBonds[addr] += createdBonds;
if( regularBuy ){
fee = fee/2;
pocket[ gateway[addr] ] += fee;
upline[ gateway[addr] ] += fee - fee/5;
pocket[ THIS ] += fee/5;
//pushMinecart(sender);
emit Buy( addr, ETH, createdBonds, _red, _green, _blue);
}
//if( coloredResolves[sender] >= masternodeRequirement){
if(checkMR(addr)){
lastGateway = addr;
}
return createdBonds;/**/
}
function checkMR(address addr) internal view returns(bool){
return _coloredResolves(addr) >= masternodeRequirement;
}
function buy(address addr, uint _red, uint _green, uint _blue, address MASTERNODE) payable public returns(uint bondsCreated){
//if( bondBalance( MASTERNODE ) >= 10000*1e12 ){
if( checkMR(MASTERNODE) ){
gateway[msg.sender] = MASTERNODE;
}else{
gateway[msg.sender] = lastGateway;
}
return buy( addr, msg.value, _red, _green, _blue, true);
}
function transferFrom(address src, address dst, uint wad) public returns (bool){
address sender = msg.sender;
require(approvals[src][sender] >= wad);
require(PyramidProxy(proxyAddress(src)).getBalance() >= wad);
if (src != sender) {
approvals[src][sender] -= wad;
}
moveTokens(src,dst,wad);
return true;
}
event Approval(address indexed src, address indexed guy, uint wad);
function approve(address guy, uint wad) public returns (bool) {
address sender = msg.sender;
approvals[sender][guy] = wad;
emit Approval(sender, guy, wad);
return true;
}
function resolvesAddColor(address addr, uint amount , uint red, uint green, uint blue) internal{
redResolves[addr] += red * amount;
greenResolves[addr] += green * amount;
blueResolves[addr] += blue * amount;
}
function bondsAddColor(address addr, uint amount , uint red, uint green, uint blue) internal{
redBonds[addr] += red * amount;
greenBonds[addr] += green * amount;
blueBonds[addr] += blue * amount;
}
function resolvesThinColor(address addr, uint newWeight, uint oldWeight) internal{
(redResolves[addr], greenResolves[addr], blueResolves[addr], coloredResolves[addr]) = RGB_scale(redResolves[addr], greenResolves[addr], blueResolves[addr], _coloredResolves(addr), newWeight, oldWeight);
/*redResolves[addr] = redResolves[addr] * newWeight / oldWeight;
greenResolves[addr] = greenResolves[addr] * newWeight / oldWeight;
blueResolves[addr] = blueResolves[addr] * newWeight / oldWeight; */
}
function bondsThinColor(address addr, uint newWeight, uint oldWeight) internal{
(redBonds[addr], greenBonds[addr], blueBonds[addr], coloredBonds[addr]) = RGB_scale(redBonds[addr], greenBonds[addr], blueBonds[addr], coloredBonds[addr], newWeight, oldWeight);
/*redBonds[addr] = redBonds[addr] * newWeight / oldWeight;
greenBonds[addr] = greenBonds[addr] * newWeight / oldWeight;
blueBonds[addr] = blueBonds[addr] * newWeight / oldWeight; */
}
function RGB_bondRatio() public view returns(uint,uint,uint){
//uint bonds = bondBalance(msg.sender);
return RGB_bondRatio(msg.sender);//(redBonds[sender]/bonds, greenBonds[sender]/bonds, blueBonds[sender]/bonds);
}
function RGB_bondRatio(address addr) public view returns(uint,uint,uint){
uint bonds = coloredBonds[addr];
if (bonds==0){
return (0,0,0);
}
return (redBonds[addr]/bonds, greenBonds[addr]/bonds, blueBonds[addr]/bonds);
}
function RGB_resolveRatio(address addr) public view returns(uint,uint,uint){
uint resolves = _coloredResolves(addr);
if (resolves==0){
return (0,0,0);
}
return (redResolves[addr]/resolves, greenResolves[addr]/resolves, blueResolves[addr]/resolves);
}
function () payable external {
if (msg.value > 0) {
//address sender = msg.sender;
//uint totalHoldings = bondBalance(msg.sender);
(uint _red , uint _green, uint _blue) = RGB_bondRatio();
buy(msg.sender, _red, _green, _blue, lastGateway);
} else {
withdraw( bondContract.resolveEarnings( proxyAddress(msg.sender) ) );
}
}/**/
function bondBalance(address addr) public view returns(uint){
return bondContract.balanceOf( proxyAddress(addr) );
}
/*event BondTransfer(address from, address to, uint amount, uint red, uint green, uint blue);
function bondTransfer(address to, uint amount) public{
address sender = msg.sender;
uint sendersFormerTotalBonds = bondBalance(sender);
bondsThinColor( sender, sendersFormerTotalBonds - amount, sendersFormerTotalBonds);
(uint r, uint g, uint b) = RGB_bondRatio(sender);
bondsAddColor( to, amount, r, g, b );
PyramidProxy(proxy[sender]).bondTransfer( proxyAddress(to) , amount);
emit BondTransfer(sender, to, amount, r, g, b);
}*/
function _coloredResolves(address addr) internal view returns(uint){return coloredResolves[addr];}
function _lockedResolves(address addr) internal view returns(uint){return lockedResolves[addr];}
function nameStake(string memory _name, bool unstake_or_stake, uint amount, address candidate) public{
address sender = msg.sender;
require( !unstake_or_stake || amount <= balanceOf(sender) - _lockedResolves(sender) );
rns.API(msg.sender, _name, unstake_or_stake, amount, candidate);
if(unstake_or_stake){
lockedResolves[sender] += amount;
}else{
lockedResolves[sender] -= amount;
}
}
}
contract BondContract{
function balanceOf(address _owner) public view returns (uint256 balance);
function sellBonds(uint amount) public returns(uint,uint);
function getResolveContract() public view returns(address);
function pullResolves(uint amount) public;
function reinvestEarnings(uint amountFromEarnings) public returns(uint,uint);
function withdraw(uint amount) public returns(uint);
function fund() payable public returns(uint);
function resolveEarnings(address _owner) public view returns (uint256 amount);
//function bondTransfer( address to, uint amount ) public;
}
contract ResolveContract{
function balanceOf(address _owner) public view returns (uint256 balance);
function transfer(address _to, uint _value) public returns (bool success);
}
contract PyramidProxy{
ColorToken router;
BondContract bondContract;
ResolveContract resolveContract;
address public THIS = address(this);
constructor(ColorToken _router, BondContract _BondContract) public{
router = _router;
bondContract = _BondContract;
resolveContract = ResolveContract( _BondContract.getResolveContract() );
}
modifier routerOnly{
require(msg.sender == address(router) );
_;
}
function () payable external{
//ETH += msg.value;
}
function buy() internal/*___*/ returns(uint){
//uint _ETH = ETH;
//ETH = 0;
return bondContract.fund.value( THIS.balance )();
}
function cash2Owner() internal{
address payable owner = address(uint160( router.getProxyOwner( THIS ) ) );
//uint _ETH = ETH;
//ETH = 0;
owner.transfer( THIS.balance );
}
function getBalance() external/*___*/ view returns (uint balance) {
address bC = address(bondContract);
if( THIS == bC ){
return resolveContract.balanceOf( bC );
}else{
return resolveContract.balanceOf( THIS );
}
}
/*function resolveEarnings() internal view returns(uint){
return bondContract.resolveEarnings( THIS );
}*/
function publix(uint8 Type,uint numeric) external routerOnly() returns(uint, uint){
if(Type == 0){
return (sell(numeric),0);
}else if(Type==1){
stake(numeric);
return (0,0);
}else if(Type==2){
unstake(numeric);
return (0,0);
}else if(Type==3){
return reinvest(numeric);
}else if(Type==4){
return (withdraw(numeric),0);
}else if(Type==5){
return (buy(),0);
}
}
function reinvest(uint amount) internal/*___*/ returns(uint,uint){
return bondContract.reinvestEarnings( amount );
}
function withdraw(uint amount) internal/*___*/ returns(uint){
uint dissolvedResolves = bondContract.withdraw( amount );
cash2Owner();
return dissolvedResolves;
}
function sell(uint amount) internal/*___*/ returns (uint){
uint resolves;
(,resolves) = bondContract.sellBonds(amount);
cash2Owner();
return resolves;
}
function stake(uint amount) internal/*___*/{
resolveContract.transfer( address(bondContract), amount );
}
function transfer(address addr, uint amount) external/*___*/ routerOnly(){
resolveContract.transfer( addr, amount );
}
/*function bondTransfer(address to, uint amount) public routerOnly(){
bondContract.bondTransfer( to, amount );
}*/
function unstake(uint amount) internal/*___*/{
bondContract.pullResolves( amount );
}
}
contract ERC223ReceivingContract{
function tokenFallback(address _from, uint _value, bytes calldata _data) external;
}
contract RNS{
address owner;
mapping(uint => address) ownerOfName;
mapping(uint => string) name;
mapping(uint => mapping(address => mapping(address => uint))) name_voter_candidate;
modifier ownerOnly{
require(msg.sender == owner);
_;
}
constructor(address _owner) public{
owner = _owner;
}
event Stake(address user, string _name, uint amount, address candidate);
event Unstake(address user, string _name, uint amount, address candidate);
event NewNameOwner(uint nameID, address owner);
function API(address user, string calldata _name, bool unstake_or_stake, uint amount, address candidate) external ownerOnly(){
uint nameID = (uint)( keccak256( abi.encodePacked( _name , "these") ) );
if(unstake_or_stake){
//STAKE
name_voter_candidate[ nameID ][ user ][ candidate ] += amount;//update your votes for candidate on a particular name
if( bytes( name[nameID] ).length==0 ) name[nameID] = _name;
if(name_voter_candidate[ nameID ][ user ][ candidate ] > name_voter_candidate[ nameID ][ user ][ ownerOfName[nameID] ]){
ownerOfName[nameID] = candidate;
emit NewNameOwner( nameID, candidate);
}
}else{
//UNSTAKE
require( amount <= name_voter_candidate[ nameID ][ user ][ candidate ], "Not that many resolve tokens locked into that name" );
name_voter_candidate[ nameID ][ user ][ candidate ] -= amount;//update your votes for candidate on a particular name
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment