## Gear 合约开发案例解析 - DAO <p align="center"> <a href="https://gitpod.io/#https://github.com/gear-dapps/dao-light"> <img src="https://gitpod.io/button/open-in-gitpod.svg" width="240" alt="GEAR"> </a> </p> 代码仓库: https://github.com/gear-dapps/dao-light 本 PPT 链接: https://hackmd.io/@btwiuse/dao-light --- Decentralized autonomous organization <a href="https://algogene.com/community/post/109"> <img src="https://hackmd.io/_uploads/rJly5z2un.png" width="480" alt="multisig"> </a> --- <a href="https://www.alchemy.com/blog/types-of-daos"> <img src="https://hackmd.io/_uploads/Hy-VL72d2.png" width="480" alt="multisig"> </a> --- DAO 最大的用例是去中心化投资基金。 例如:一群投资者创建风险基金,将资本存入 DAO 智能合约中,并透明地在链上发起**提案**,然后通过集体**投票**决定将资本分配到哪里。 https://wiki.gear-tech.io/docs/examples/DAO/ --- <p align="center"> <a href="https://gitpod.io/#https://github.com/gear-dapps/dao-light"> <img src="https://gitpod.io/button/open-in-gitpod.svg" width="240" alt="GEAR"> </a> </p> 代码仓库: https://github.com/gear-dapps/dao-light --- ## build ``` $ make init $ make build ``` ## download ``` ./target/wasm32-unknown-unknown/release/dao_light_state.meta.wasm ./target/wasm32-unknown-unknown/release/dao_light.opt.wasm ./dao_light.meta.txt ``` ## deploy https://idea.gear-tech.io/ --- 初始化合约 ![](https://hackmd.io/_uploads/SyvIaNnd3.png) --- 合约初始状态 ![](https://hackmd.io/_uploads/ryJ5TEnOn.png) --- 发送消息与合约交互 ![](https://hackmd.io/_uploads/BySh6Vh_2.png) --- ## Deposit ``` /// Deposits tokens to DAO /// Arguments: /// * `amount`: the number of fungible tokens that user wants to deposit to DAO async fn deposit(&mut self, amount: u128) { let share = self.calculate_share(amount).await; transfer_tokens( &self.approved_token_program_id, &msg::source(), &exec::program_id(), amount, ) .await; self.members .entry(msg::source()) .and_modify(|member| member.shares += share) .or_insert(Member { shares: share, highest_index_yes_vote: None, }); ``` --- ## SubmitFundingProposal ``` /// The proposal of funding /// Requirements: /// * The proposal can be submitted only by the existing members or their delegate addresses /// * The receiver ID can't be the zero /// * The DAO must have enough funds to finance the proposal /// Arguments: /// * `receiver`: an actor that will be funded /// * `amount`: the number of fungible tokens that will be sent to the receiver /// * `quorum`: a certain threshold of YES votes in order for the proposal to pass /// * `details`: the proposal description async fn submit_funding_proposal( &mut self, applicant: &ActorId, amount: u128, quorum: u128, details: String, ) { self.check_for_membership(); ... ``` --- ## ProcessProposal ``` /// The proposal processing after the proposal completes during the grace period. /// If the proposal is accepted, the indicated amount of tokens are sent to the applicant. /// Requirements: /// * The previous proposal must be processed /// * The proposal must exist and be ready for processing /// * The proposal must not be already be processed /// Arguments: /// * `proposal_id`: the proposal ID async fn process_proposal(&mut self, proposal_id: u128) { if proposal_id > 0 && !self.proposals.get(&(&proposal_id - 1)).unwrap().processed { panic!("Previous proposal must be processed"); } ... ``` --- ## 课后作业 编译 - https://github.com/gear-dapps/fungible-token - https://github.com/gear-dapps/dao-light 并在 [Gear IDEA](https://idea.gear-tech.io/) Staging V7 测试网上部署 向 DAO 合约 存入代币 / 提交提案 / 执行提案 最后提交 DAO 合约访问链接 作业提交/课后答疑频道: https://t.me/Gear_CN --- # Questions <img src="https://hackmd.io/_uploads/SyK8P72d2.jpg" width="240" alt="GEAR"> <img src="https://hackmd.io/_uploads/By_kgE3_2.png" width="240" alt="VARA">
{"slideOptions":"{\"theme\":\"solarized\",\"spotlight\":{\"enabled\":false}}","description":"代码仓库: https://github.com/gear-dapps/multisig-wallet","title":"Gear 合约开发案例解析 - DAO","contributors":"[{\"id\":\"94262fbf-81ae-4ed7-933c-561a41bd977a\",\"add\":9261,\"del\":5129}]"}
    162 views