Skip to content

Commit

Permalink
Merge pull request #1 from Alexunderlett/main
Browse files Browse the repository at this point in the history
commit contract
  • Loading branch information
RainbowDAO authored Apr 15, 2022
2 parents a597550 + 3cc76eb commit ab30c47
Show file tree
Hide file tree
Showing 37 changed files with 3,131 additions and 0 deletions.
16 changes: 16 additions & 0 deletions applications/RainbowDAO Protocol/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
node_modules
.env
.env.backup
.phpunit.result.cache
docker-compose.override.yml
Homestead.json
Homestead.yaml
npm-debug.log
yarn-error.log
.idea
.vscode
.DS_Store
**/artifacts
package-lock.json
build

1 change: 1 addition & 0 deletions applications/RainbowDAO Protocol/.secret
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
lift mixture immense gift uncle believe calm pear prison employ kiss beauty
2 changes: 2 additions & 0 deletions applications/RainbowDAO Protocol/Front-end file/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

Front-end file
85 changes: 85 additions & 0 deletions applications/RainbowDAO Protocol/contract/Authority/Authority.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
pragma solidity ^0.6.0;
import "../interface/IDaoManage.sol";

contract Authority{
address public owner;
address public manage;

struct Act{
uint actId;
string contractName;
string funcName;
}
uint index;
mapping(address => mapping(uint => bool)) public ifAllowd;
mapping(string => mapping(string => uint)) public funcActId;
mapping(uint => Act) public actionInfo;

modifier onlyOwner(){
require(msg.sender == owner, "only owner");
_;
}

constructor(address _owner,address _manage) public {
owner = _owner;
manage = _manage;
}

function getActId(string memory _contractName, string memory _func) public view returns(uint){
return funcActId[_contractName][_func];
}

// function transferOwnerShip(address newOwner) onlyOwner public {

// }

function hasAuthority(address _account, string memory _contractName,string memory _func) public view returns(bool){
if(funcActId[_contractName][_func] != 0){
uint id = funcActId[_contractName][_func];
return ifAllowd[_account][id];
}

return false;
}

function addAct(string memory _contractName, string memory _func) public {
require(msg.sender == owner || hasAuthority(msg.sender,"Authority","addAct"), "No permission");
require(funcActId[_contractName][_func] !=0, "existed");

index++;
Act memory act = Act({
actId: index,
contractName: _contractName,
funcName: _func
});

actionInfo[index] = act;
funcActId[_contractName][_func] = index;
}

function removeAct(string memory _contractName, string memory _func) public {
require(msg.sender == owner || hasAuthority(msg.sender,"Authority","removeAct"), "No permission");
require(funcActId[_contractName][_func] == 0, "Not existed");
funcActId[_contractName][_func] = 0;
delete actionInfo[index];
}

function addAuthority(address _account,string memory _contractName, string memory _func) public {
require(msg.sender == owner || hasAuthority(msg.sender,"Authority","addAuthority"), "No permission");
require(funcActId[_contractName][_func] != 0, "Not existed");
uint actId = funcActId[_contractName][_func];
require(!ifAllowd[_account][actId], "Have authority");

ifAllowd[_account][actId] = true;
}

function removeAuthority(address _account,string memory _contractName, string memory _func) public {
require(msg.sender == owner || hasAuthority(msg.sender,"Authority","removeAuthority"), "No permission");
require(funcActId[_contractName][_func] != 0, "Not existed");
uint actId = funcActId[_contractName][_func];
require(ifAllowd[_account][actId], "No authority");

ifAllowd[_account][actId] = false;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
pragma solidity ^0.6.0;
pragma experimental ABIEncoderV2;
import "../Vault/Vault.sol";
import "../DaoManage/DaoManage.sol";
import "../Authority/Authority.sol";
// import "../lib/ERC20MODEL.sol";
import "../interface/IERC20MODEL.sol";
import "../interface/IDaoManage.sol";
import "../interface/IVault.sol";

contract DaoBaseInfo{
address public owner;
address public erc20Factory;
uint public index;

struct DaoInfo{
string name;
string logo;
string des;
address authority;
address manage;
address vault;
}
mapping(address => uint[]) public userDaos;
DaoInfo[] public array;

constructor(address _owner,address _erc20Factory) public {
owner = _owner;
erc20Factory = _erc20Factory;
}

modifier onlyOnwer(){
require(msg.sender == owner, "only owner");
_;
}

function creatDaoWithNewToken(string memory _name,string memory _logo,string memory _des,string memory _tokenName,string memory _symble,uint8 _decimals, uint _totalSupply, uint _support) public {
require(msg.sender != address(0), "Invalid address");
address _manage = address(new DaoManage(msg.sender,address(this),_name,_logo,_des,_support));
address _auth = address(new Authority(msg.sender,_manage));
address _vault = address(new Vault(msg.sender,address(this),_manage, _auth));
address _erc20 = IERC20MODEL(erc20Factory).creatToken(_name,_symble,_decimals,_vault,_totalSupply);

DaoInfo memory addr = DaoInfo({
name: _name,
logo: _logo,
des: _des,
authority: _auth,
manage: _manage,
vault: _vault
});

array.push(addr);
userDaos[msg.sender].push(index);
index++;
IDaoManage(_manage).init(_auth,_vault);
IVault(_vault).addToken(_erc20);
}

function creatDao(string memory _name,string memory _logo,string memory _des,address _token, uint _support) public {
require(msg.sender != address(0), "Invalid address");
address _manage = address(new DaoManage(msg.sender,address(this),_name,_logo,_des,_support));
address _auth = address(new Authority(msg.sender,_manage));
address _vault = address(new Vault(msg.sender,address(this),_manage, _auth));

DaoInfo memory addr = DaoInfo({
name: _name,
logo: _logo,
des: _des,
authority: _auth,
manage: _manage,
vault: _vault
});

array.push(addr);
userDaos[msg.sender].push(index);
index++;
IDaoManage(_manage).init(_auth,_vault);
IVault(_vault).addToken(_token);
}

function getArrayLength() public view returns(uint){
return array.length;
}

function getDaoInfo(uint index) public view returns(DaoInfo memory){
return array[index];
}

// function _init_contracts(string memory _name,string memory _logo, string memory _des) internal {

// }

function getOwnedDaos() public view returns(uint[] memory){
return userDaos[msg.sender];
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
pragma solidity ^0.6.0;
pragma experimental ABIEncoderV2;
import "../Vault/Vault.sol";
import "../DaoManage/DaoManage.sol";
import "../Authority/Authority.sol";
// import "../lib/ERC20MODEL.sol";
import "../interface/IERC20MODEL.sol";
import "../interface/IDaoManage.sol";
import "../interface/IVault.sol";

contract DaoFactory{
address public owner;
address public erc20Factory;
uint public index;

struct DaoInfo{
string name;
string logo;
string des;
address authority;
address manage;
address vault;
}
mapping(address => uint[]) public userDaos;
DaoInfo[] public array;

constructor(address _owner,address _erc20Factory) public {
owner = _owner;
erc20Factory = _erc20Factory;
}

modifier onlyOnwer(){
require(msg.sender == owner, "only owner");
_;
}

function creatDaoWithNewToken(string memory _name,string memory _logo,string memory _des,string memory _tokenName,string memory _symble,uint8 _decimals, uint _totalSupply, uint _support) public {
require(msg.sender != address(0), "Invalid address");
address _manage = address(new DaoManage(msg.sender,address(this),_name,_logo,_des,_support));
address _auth = address(new Authority(msg.sender,_manage));
address _vault = address(new Vault(msg.sender,address(this),_manage, _auth));
address _erc20 = IERC20MODEL(erc20Factory).creatToken(_name,_symble,_decimals,_vault,_totalSupply);

DaoInfo memory addr = DaoInfo({
name: _name,
logo: _logo,
des: _des,
authority: _auth,
manage: _manage,
vault: _vault
});

array.push(addr);
userDaos[msg.sender].push(index);
index++;
IDaoManage(_manage).init(_auth,_vault);
IVault(_vault).addToken(_erc20);
}

function creatDao(string memory _name,string memory _logo,string memory _des,address _token, uint _support) public {
require(msg.sender != address(0), "Invalid address");
address _manage = address(new DaoManage(msg.sender,address(this),_name,_logo,_des,_support));
address _auth = address(new Authority(msg.sender,_manage));
address _vault = address(new Vault(msg.sender,address(this),_manage, _auth));

DaoInfo memory addr = DaoInfo({
name: _name,
logo: _logo,
des: _des,
authority: _auth,
manage: _manage,
vault: _vault
});

array.push(addr);
userDaos[msg.sender].push(index);
index++;
IDaoManage(_manage).init(_auth,_vault);
IVault(_vault).addToken(_token);
}

function getArrayLength() public view returns(uint){
return array.length;
}

function getDaoInfo(uint index) public view returns(DaoInfo memory){
return array[index];
}

// function _init_contracts(string memory _name,string memory _logo, string memory _des) internal {

// }

function getOwnedDaos() public view returns(uint[] memory){
return userDaos[msg.sender];
}

}
Loading

0 comments on commit ab30c47

Please sign in to comment.