Skip to content

Commit

Permalink
DAO Fingerprints EQD1PIvZLeDmgICYjkzEbvyIZRWNQNS6izrxQJuoXZk_uF2y
Browse files Browse the repository at this point in the history
  • Loading branch information
inozemtsev-roman committed Feb 26, 2024
1 parent 9d7bd10 commit b30676f
Show file tree
Hide file tree
Showing 37 changed files with 7,427 additions and 52 deletions.
71 changes: 71 additions & 0 deletions DAO/DAO/contract/contracts/dao.tact
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import "@stdlib/deploy";
import "@stdlib/ownable";
import "./messages/dao-messages";


contract Dao with Deployable {

owner: Address;
registry: Address;
proposalOwner: Address;
daoIndex: Int as uint32;
metadata: Address;
fwdMsgFee: Int as uint64;

init(registry: Address, daoIndex: Int) {
self.registry = registry;
self.daoIndex = daoIndex;

self.owner = newAddress(0, 0x0);
self.proposalOwner = newAddress(0, 0x0);
self.metadata = newAddress(0, 0x0);
self.fwdMsgFee = ton("1000000");
}

receive(init: DaoInit) {
require(self.owner == newAddress(0, 0x0), "Already initialized");
require(sender() == self.registry, "Invalid sender");

self.owner = init.owner;
self.proposalOwner = init.proposalOwner;
self.metadata = init.metadata;
self.fwdMsgFee = init.fwdMsgFee;
}

receive(msg: SetOwner) {
require(sender() == self.owner, "Invalid sender");
self.owner = msg.newOwner;
}

receive(msg: SetProposalOwner) {
require(sender() == self.owner, "Invalid sender");
self.proposalOwner = msg.newProposalOwner;
}

receive(msg: SetMetadata) {
require(sender() == self.owner, "Invalid sender");
self.metadata = msg.newMetadata;
}

receive(msg: SetFwdMsgFee) {
require(sender() == self.registry, "Only registry can change fwd msg fee");
self.fwdMsgFee = msg.newFwdMsgFee;
}

receive(msg: FwdMsg) {
require(sender() == self.owner || sender() == self.proposalOwner, "Invalid sender");
require(context().value >= self.fwdMsgFee, "Below min fee for dao forward message");
send(msg.fwdMsg);
}

get fun state(): DaoContractState {
return DaoContractState {
registry: self.registry,
owner: self.owner,
proposalOwner: self.proposalOwner,
metadata: self.metadata,
daoIndex: self.daoIndex,
fwdMsgFee: self.fwdMsgFee
};
}
}
40 changes: 40 additions & 0 deletions DAO/DAO/contract/contracts/messages/dao-messages.tact
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

// ---------------------------------------
// Dao
// ---------------------------------------
message SetOwner {
newOwner: Address;
}

message SetProposalOwner {
newProposalOwner: Address;
}

message SetFwdMsgFee {
newFwdMsgFee: Int as uint64;
}

message SetMetadata {
newMetadata: Address;
}

message FwdMsg {
fwdMsg: SendParameters;
}

message DaoInit {
owner: Address;
proposalOwner: Address;
metadata: Address;
fwdMsgFee: Int as uint64;
}

struct DaoContractState {

registry: Address;
owner: Address;
proposalOwner: Address;
metadata: Address;
daoIndex: Int as uint32;
fwdMsgFee: Int as uint64;
}
40 changes: 40 additions & 0 deletions DAO/DAO/contract/contracts/messages/registry-messages.tact
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

// ---------------------------------------
// Registry
// ---------------------------------------
message DeployAndInitDao {
owner: Address;
proposalOwner: Address;
metadata: Address;
}

message SendDaoInit {
owner: Address;
proposalOwner: Address;
metadata: Address;
}

message SetDeployAndInitDaoFee {
newDeployAndInitDaoFee: Int as uint64;
}

message SetNewDaoFwdMsgFee {
newDaosfwdMsgFee: Int as uint64;
}

message SendToDaoSetFwdMsgFee {
daoId: Int as uint32;
newFwdMsgFee: Int as uint64;
}

message SetRegistryAdmin {
newAdmin: Address;
}

struct RegistryContractState {
registryId: Int as uint32;
nextDaoId: Int as uint32;
admin: Address;
deployAndInitDaoFee: Int as uint64;
newDaosfwdMsgFee: Int as uint64;
}
15 changes: 15 additions & 0 deletions DAO/DAO/contract/contracts/messages/router-messages.tact
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

// ---------------------------------------
// Router
// ---------------------------------------
message RouteDeployAndInitDao {
prodMsgValue: Int as uint64;
devMsgValue: Int as uint64;

prodRegistry: Address;
devRegistry: Address;

owner: Address;
proposalOwner: Address;
metadata: Address;
}
98 changes: 98 additions & 0 deletions DAO/DAO/contract/contracts/registry.tact
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
import "@stdlib/deploy";
import "@stdlib/ownable";
import "./messages/registry-messages";
import "./dao";


contract Registry with Deployable {

registryId: Int as uint32;
nextDaoId: Int as uint32;
admin: Address;
deployAndInitDaoFee: Int as uint64;
newDaosfwdMsgFee: Int as uint64;

init(registryId: Int) {
self.registryId = registryId;
self.nextDaoId = 0;
self.admin = newAddress(0, 0x0);
self.deployAndInitDaoFee = ton("1");
self.newDaosfwdMsgFee = ton("0.1");
}

receive(deployAndInitDao: DeployAndInitDao) {
require(context().value >= self.deployAndInitDaoFee, "Below min fee for create dao");

let init: StateInit = self.getDaoStateInit(self.nextDaoId);
let daoAddress: Address = contractAddress(init);

send(SendParameters{
to: daoAddress,
value: 0,
bounce: false,
mode: SendRemainingValue,
body: DaoInit{owner: deployAndInitDao.owner, proposalOwner: deployAndInitDao.proposalOwner,
metadata: deployAndInitDao.metadata, fwdMsgFee: self.newDaosfwdMsgFee}.toCell(),
code: init.code,
data: init.data
});

self.nextDaoId = self.nextDaoId + 1;
}

receive(msg: SetDeployAndInitDaoFee) {
require(sender() == self.admin, "Only admin can set the create dao fee");
self.deployAndInitDaoFee = msg.newDeployAndInitDaoFee;
}

// effects daos which were not created yet
receive(msg: SetNewDaoFwdMsgFee) {
require(sender() == self.admin, "Only admin can set the new dao fwd msg fee");
self.newDaosfwdMsgFee = msg.newDaosfwdMsgFee;
}

// effects already created daos
receive(msg: SendToDaoSetFwdMsgFee) {
require(sender() == self.admin, "Only admin can set the dao fwd msg fee");

let init: StateInit = self.getDaoStateInit(msg.daoId);
let daoAddress: Address = contractAddress(init);

send(SendParameters{
to: daoAddress,
value: 0,
bounce: false,
mode: SendRemainingValue,
body: SetFwdMsgFee{newFwdMsgFee: msg.newFwdMsgFee}.toCell()
});
}

receive(msg: SetRegistryAdmin) {
// to burn the admin set it to newAddress(-1, 0x0)
require(sender() == self.admin || self.admin == newAddress(0, 0x0), "Only admin can set new registry admin");
self.admin = msg.newAdmin;
}

fun getDaoStateInit(daoIndex: Int): StateInit {
return initOf Dao(myAddress(), daoIndex);
}

get fun state(): RegistryContractState {
return RegistryContractState {
registryId: self.registryId,
nextDaoId: self.nextDaoId,
admin: self.admin,
deployAndInitDaoFee: self.deployAndInitDaoFee,
newDaosfwdMsgFee: self.newDaosfwdMsgFee
};
}

get fun nextDaoId(): Int {
return self.nextDaoId;
}

get fun daoAddress(daoId: Int): Address {
let init: StateInit = self.getDaoStateInit(daoId);
return contractAddress(init);
}
}
37 changes: 37 additions & 0 deletions DAO/DAO/contract/contracts/router.tact
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import "@stdlib/deploy";
import "@stdlib/ownable";
import "./messages/router-messages";
import "./registry";


contract Router with Deployable {

init() {
}

receive(routeDeployAndInitDao: RouteDeployAndInitDao) {

send(SendParameters{
to: routeDeployAndInitDao.prodRegistry,
value: routeDeployAndInitDao.prodMsgValue,
bounce: false,
mode: 0,
body: DeployAndInitDao{owner: routeDeployAndInitDao.owner, proposalOwner: routeDeployAndInitDao.proposalOwner,
metadata: routeDeployAndInitDao.metadata}.toCell(),
code: null,
data: null
});

send(SendParameters{
to: routeDeployAndInitDao.devRegistry,
value: routeDeployAndInitDao.devMsgValue,
bounce: false,
mode: 0,
body: DeployAndInitDao{owner: routeDeployAndInitDao.owner, proposalOwner: routeDeployAndInitDao.proposalOwner,
metadata: routeDeployAndInitDao.metadata}.toCell(),
code: null,
data: null
});

}
}
Loading

0 comments on commit b30676f

Please sign in to comment.