...
space:空间,一个空间可以理解为一个运营方,负责跟踪提案、投票的全局设置,其包含多个提案,空间中有一些Meta data(头像,描述,主站信息等),DaoSpace用以负责描述空间信息,每个项目方均可通过调用DaoSpace::add来对其进行注册空间add来对其进行注册Space。
代码块 | ||
---|---|---|
| ||
// DaoSpace.move module DaoSpace { struct Space { voting_delay: u128, // The delay between when a proposal is created, and when the voting starts. A voting_delay of 0 means that as soon as the proposal is created, anyone can vote. A voting_delay of 3600 means that voting will start 3600 seconds after the proposal is created. voting_duration: u128, // The duration of the voting period, i.e. how long people will be able to vote for a proposal. proposalmeta_thresholddata: u128vector<u8>, // The minimum amount of voting power needed to be able to create a new proposal in the space. Used to avoid having anyone be able to create a proposal. voting_strategies: vector<u8>, //A list of voting strategy contracts addresses that define the voting strategies used by the space. The voting power of each user will be calculated as the sum of voting powers returned for each strategy in the list for that user. More information in the Voting Strategy section. authenticators: vector<address>// A list of accepted authenticators. These are the ways in which a user can authenticate themselves in order to vote or propose. For more information, refer to the Authenticators section. executor: Option::Option<Executor> // The execution strategy contract that will handle the execution of transactions inside proposals once voting is complete. More information about execution in the Execution Contract section 空间元数据,编码后存储在链上(可考虑存在链下) } struct NFTMeta { user: address, } struct NFTBody { weight: u128 } struct SpaceCapability { } public fun add(signer: &signer, voting_delay: u128, voting_duration: u128, meta_data: &vector<u8>): (u64, SpaceCapability); public fun modify(signer: &signer, voting_delay: u128, voting_duration: u128, cap: &SpaceCapability); public fun query(broker: address) : (u128, u128, u128); public fun register(signer: &signer, space_broker: address, cap: &SpaceCapability) : NFT<NFTMeta, NFTBody>; public fun unregister(signer: &signer, nft: NFT<NFTMeta, NFTBody>); public fun add_weight(signer: &signer, nft: &mut NFT<NFTMeta, NFTBody>); public fun reduce_weight(signer: &signer, nft: &mut NFT<NFTMeta, NFTBody>); } |
proposal:提案,即一个提案代表一次投票过程,该部分跟原有的流程类似,但是去掉了TokenType。
代码块 | ||
---|---|---|
| ||
// DaoProposal.move
module DaoProposal {
struct ProposalCapability {
proposal_id: u64,
}
struct Proposal<Action> {
... // 现有的一些结构
proposal_id: u64,
voting_system: u8, // 投票类型有单选投票、二次投票、排名投票、加权投票等投票类型
voting_start_time: u64,
voting_end_time: u64,
voting_block_num: u64, // 投票快照高度
voting_block_root: vector<u8>, // 投票快照高度的root hash
action: Option::Option<Action>, // 执行策略的结构参数
}
struct Vote {
/// vote for the proposal under the `proposer`.
proposer: address,
/// proposal id.
id: u64,
choie: u8, // 同意,反对,拒绝
weight: u128, // 投票权重
}
public fun create_proposal<Action>(...,
space_broker: address,
space_id: u64,
root_hash: &vector<u8>): ProposalCapability;
public fun cast_vote(
signer: &signer,
proposer_broker: address,
id: u64,
amount: u128,
choice: u8,
cap: &ProposalCapability
);
public fun extract_strategy<Action>(id: u64) : Action;
};
|
代码块 | ||
---|---|---|
| ||
// Dao.move module Dao { use DaoSpace; struct DaoSignerDelegate { cap: SignerCapability, // 托管的签名(这里一旦放进来,就没法再还回去了,且只有一份,没想好是放在space还是放在这里,暂时放这里) } struct DaoSpace { cap: SpaceCapability nft: Option::Option<NFT<DaoSpace::NFTMeta, DaoSpace::NFTData>>, } struct DaoProposal { cap: ProposalCapability } struct DaoProposalSet { proposal_set: HashSet<u64, DaoProposal> } // 执行策略:转账 struct ExecutionTransferStrategy<phontem TokenT> { amount: u128, to: address, } // 项目方创建space public fun |
...
new_space( signer: &signer, voting_delay: |
...
u64, voting_ |
...
period: |
...
u64, |
...
min_action_delay: u64) { // 项目方托管 SignerCapability 到该合约 // 通过DaoSpace合约创建对应的结构 // 将DaoSpace权限存到当前合约 } // 参与投票方/创建投票方注册到space public fun |
...
register_to_space( signer: &signer, broker: address) { // 创建对应的NFT } // 根据 space_broker 来创建对应的proposal public fun create_proposal<ExecutionStrategy>( signer: &signer, // 创建者 space_broker: |
...
(这里的Executor需要讨论一下Move设计方式)
proposal:提案,即一个提案代表一次投票过程,投票类型有单选投票、二次投票、排名投票、加权投票。
...
language | rust |
---|
...
u64, // space 代理人 block_num: u64, // 快照高度 root_hash: vector<u8> // 快照根hash ); // 投票 public fun do_vote( signer: &signer, broker: address, id: u64, amount: u128, choice: u8, proof: &vector<u8>, side_nodes: &vector<u8>) { } } |
二、流程
参考:
...