Skip to content

Commit

Permalink
Merge pull request #39 from AElfProject/feat/simple-dao-template
Browse files Browse the repository at this point in the history
Feature - Simple DAO Smart Contract Template
  • Loading branch information
zhifenglee-aelf authored Jul 4, 2024
2 parents 85fcb31 + 91aed46 commit bdbfb5a
Show file tree
Hide file tree
Showing 18 changed files with 3,294 additions and 1 deletion.
3 changes: 2 additions & 1 deletion templates/AElf.Contract.Template.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<ItemGroup>
<Content Include="HelloWorldContract\**\*" Exclude="HelloWorldContract\**\bin\**;HelloWorldContract\**\obj\**" />
<Content Include="LotteryGameContract\**\*" Exclude="LotteryGameContract\**\bin\**;LotteryGameContract\**\obj\**" />
<Content Include="SimpleDAOContract\**\*" Exclude="SimpleDAOContract\**\bin\**;SimpleDAOContract\**\obj\**" />
<Compile Remove="**\*" />
</ItemGroup>

Expand All @@ -29,4 +30,4 @@
<PackageReference Include="AElf.Cryptography" Version="1.5.0" />
</ItemGroup>

</Project>
</Project>
21 changes: 21 additions & 0 deletions templates/SimpleDAOContract/.template.config/template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"$schema": "http://json.schemastore.org/template",
"author": "AElf",
"classifications": [
"AElf/SmartContract"
],
"identity": "AElf.Contract.SimpleDAO.Template",
"name": "AElf Contract SimpleDAO Template",
"shortName": "aelf-simple-dao",
"tags": {
"language": "C#",
"type": "project"
},
"sourceName": "SimpleDAO",
"symbols": {
"NamespacePath": {
"type": "parameter",
"replaces": "AElf.Contracts.SimpleDAO"
}
}
}
12 changes: 12 additions & 0 deletions templates/SimpleDAOContract/src/ContractReference.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using AElf.Sdk.CSharp.State;
using AElf.Contracts.MultiToken;
using AElf.Types;

namespace AElf.Contracts.SimpleDAO
{
// The state class is access the blockchain state
public partial class SimpleDAOState
{
internal TokenContractContainer.TokenContractReferenceState TokenContract { get; set; }
}
}
110 changes: 110 additions & 0 deletions templates/SimpleDAOContract/src/Protobuf/contract/simple_dao.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
syntax = "proto3";

import "aelf/core.proto";
import "aelf/options.proto";
import "google/protobuf/empty.proto";
import "Protobuf/reference/acs12.proto";
import public "google/protobuf/timestamp.proto";

// The namespace of this class
option csharp_namespace = "AElf.Contracts.SimpleDAO";

service SimpleDAO {
// The name of the state class the smart contract is going to use to access
// blockchain state
option (aelf.csharp_state) = "AElf.Contracts.SimpleDAO.SimpleDAOState";
option (aelf.base) = "Protobuf/reference/acs12.proto";

// Actions -> Methods that change state of smart contract
// This method sets up the initial state of our StackUpDAO smart contract
rpc Initialize(InitializeInput) returns (google.protobuf.Empty);

// This method allows a user to create a proposal for other users to vote on.
// The method takes in a "CreateProposalInput" message which comprises of an
// address, a title, description and a vote threshold (i.e how many votes
// required for the proposal to pass)
rpc CreateProposal(CreateProposalInput) returns (google.protobuf.Empty);

// This method allows a user to vote on proposals towards a specific proposal.
// This method takes in a "VoteInput" message which takes in the address of
// the voter, specific proposal and a boolean which represents their vote
rpc Vote(VoteInput) returns (google.protobuf.Empty);

rpc Withdraw(WithdrawInput) returns (google.protobuf.Empty);

// Views -> Methods that does not change state of smart contract
// This method allows a user to fetch a list of proposals that had been
// created by members of the DAO
rpc GetAllProposals(google.protobuf.Empty) returns (ProposalList) {
option (aelf.is_view) = true;
}

// aelf requires explicit getter methods to access the state value,
// so we provide these three getter methods for accessing the state
// This method allows a user to fetch a proposal by proposalId
rpc GetProposal (google.protobuf.StringValue) returns (Proposal) {
option (aelf.is_view) = true;
}

// get the token symbol for this DAO
rpc GetTokenSymbol (google.protobuf.Empty) returns (google.protobuf.StringValue) {
option (aelf.is_view) = true;
}

rpc HasVoted (HasVotedInput) returns (google.protobuf.BoolValue) {
option (aelf.is_view) = true;
}
}

message Proposal {
string id = 1;
string title = 2;
string description = 3;
string status = 4; // e.g., "IN PROGRESS", "PASSED", "DENIED"
aelf.Address proposer = 5;
google.protobuf.Timestamp start_timestamp = 6;
google.protobuf.Timestamp end_timestamp = 7;
ProposalResult result = 8;
}

message ProposalResult {
int64 approve_counts = 1;
int64 reject_counts = 2;
int64 abstain_counts = 3;
}

message CreateProposalInput {
string title = 1;
string description = 2;
google.protobuf.Timestamp start_timestamp = 3;
google.protobuf.Timestamp end_timestamp = 4;
}

enum VoteOption {
APPROVED = 0;
REJECTED = 1;
ABSTAINED = 2;
}

message VoteInput {
string proposalId = 1;
VoteOption vote = 2;
int64 amount = 3;
}

message InitializeInput {
string tokenSymbol = 1;
}

message WithdrawInput {
string proposalId = 1;
}

message ProposalList {
repeated Proposal proposals = 1;
}

message HasVotedInput {
string proposalId = 1;
aelf.Address address = 2;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
syntax = "proto3";

import "aelf/core.proto";

option csharp_namespace = "AElf.Contracts.SimpleDAO";

message AuthorityInfo {
aelf.Address contract_address = 1;
aelf.Address owner_address = 2;
}
35 changes: 35 additions & 0 deletions templates/SimpleDAOContract/src/Protobuf/reference/acs12.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* AElf Standards ACS12(User Contract Standard)
*
* Used to manage user contract.
*/
syntax = "proto3";

package acs12;

import public "aelf/options.proto";
import public "google/protobuf/empty.proto";
import public "google/protobuf/wrappers.proto";
import "aelf/core.proto";

option (aelf.identity) = "acs12";
option csharp_namespace = "AElf.Standards.ACS12";

service UserContract{

}

//Specified method fee for user contract.
message UserContractMethodFees {
// List of fees to be charged.
repeated UserContractMethodFee fees = 2;
// Optional based on the implementation of SetConfiguration method.
bool is_size_fee_free = 3;
}

message UserContractMethodFee {
// The token symbol of the method fee.
string symbol = 1;
// The amount of fees to be charged.
int64 basic_fee = 2;
}
Loading

0 comments on commit bdbfb5a

Please sign in to comment.