dao.sql 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. -- # DAO::mint()
  2. --
  3. -- First one person will create the DAO
  4. --
  5. -- $ drk dao create_dao \
  6. -- PROPOSER_LIMIT \
  7. -- QUORUM \
  8. -- APPROVAL_RATIO_BASE \
  9. -- APPROVAL_RATIO_QUOTIENT \
  10. -- GOV_TOKEN_ID > dao.dat
  11. --
  12. -- dat.dat contains:
  13. --
  14. -- * DAO parameters as listed above
  15. -- * secret key for the DAO
  16. -- * bulla blind
  17. --
  18. -- We can view the data like so:
  19. --
  20. -- $ drk dao view < dao.dat
  21. --
  22. -- Now everyone inside the DAO exchanges dao.dat out of band will import
  23. -- it into their wallets.
  24. --
  25. -- $ drk dao import DAO_NAME < dao.dat
  26. -- Imported DAO ccb8XXX8af6
  27. --
  28. -- Where ccb8XXX8af6 is the DAO's name.
  29. --
  30. -- Next one person will mint it on chain
  31. --
  32. -- $ drk dao mint DAO_NAME > dao_mint_tx
  33. -- $ drk broadcast < dao_mint_tx
  34. --
  35. -- And then the others will receive confirmation that the DAO they imported
  36. -- into their wallet has also been accepted on chain.
  37. --
  38. -- # Minting and Receiving Coin
  39. --
  40. -- Assume that the governance tokens have been created and distributed
  41. -- appropriately among DAO members. We will skip that part here.
  42. --
  43. -- Now the DAO can receive coins into its treasury. These coins simply
  44. -- have both the coin's spend_hook and user_data fields set correctly
  45. -- otherwise they are rejected as invalid/malformed.
  46. --
  47. -- # DAO::propose()
  48. --
  49. -- Create a transfer proposal for the DAO
  50. --
  51. -- $ drk dao propose-transfer \
  52. -- DAO_NAME \
  53. -- DURATION \
  54. -- AMOUNT \
  55. -- SENDCOIN_TOKEN_ID \
  56. -- RECV_PUBKEY
  57. --
  58. -- If we don't have enough tokens to meet the proposer_limit threshold
  59. -- then this call will simply fail with an error message. Nothing will
  60. -- be added to the database or sent to the network.
  61. --
  62. -- Once a proposal has been generated, it can be exported and shared
  63. -- to other participants.
  64. --
  65. -- $ drk dao proposal PROPOSAL_BULLA --export > dao_transfer_proposal.dat
  66. -- $ drk dao proposal-import < dao_transfer_proposal.dat
  67. --
  68. -- We can now mint the proposal on-chain
  69. --
  70. -- $ drk dao proposal PROPOSAL_BULLA --mint-proposal > dao_proposal_tx
  71. -- $ drk broadcast < dao_proposal_tx
  72. --
  73. -- # DAO::vote()
  74. --
  75. -- You have received a proposal which is active. You can now vote on it.
  76. --
  77. -- $ drk dao proposals DAO_NAME
  78. -- 0. f6cae63ced53d02b372206a8d3ed5ac03fde18da306a520285fd56e8d031f6cf
  79. -- 1. 1372622f4a38be6eb1c90fa67864474c6603d9f8d4228106e20e2d0d04f2395e
  80. -- 2. 88b18cbc38dbd3af8d25237af3903e985f70ea06d1e25966bf98e3f08e23c992
  81. --
  82. -- $ drk dao show_proposal f6cae...1f6cf
  83. -- Proposal parameters
  84. -- ===================
  85. -- Bulla: f6cae...1f6cf
  86. -- DAO Bulla: 2Wmyc...zQeke
  87. -- Proposal leaf position: Position(1)
  88. -- Proposal transaction hash: 07148...52f96
  89. -- Proposal call index: 0
  90. -- Creation block window: 0
  91. -- Duration: 30 (Block windows)
  92. --
  93. -- Invoked contracts:
  94. -- Contract: Fd8kf...z7iXj
  95. -- Function: 4
  96. -- Data:
  97. -- Recipient: DQeQR...q31Fz
  98. -- Amount: 690000000 (6.9)
  99. -- Token: GY8xX...xY8Qu
  100. -- Spend hook: 6iW9n...2GLuT
  101. -- User data: 0x35431...e3678
  102. -- Blind: 13EHb...xR6ng
  103. --
  104. -- Contract: BZHKG...4yf4o
  105. -- Function: 3
  106. -- Data: -
  107. --
  108. -- Votes:
  109. -- ...
  110. -- Total tokens votes: X + Y
  111. -- Total tokens Yes votes: X (60%)
  112. -- Total tokens No votes: Y
  113. -- Voting status: Ongoing
  114. -- Current proposal outcome: Rejected
  115. --
  116. -- $ drk dao vote f6cae...1f6cf 1 > dao_vote_tx
  117. -- $ drk broadcast < dao_vote_tx
  118. --
  119. -- # DAO::exec()
  120. --
  121. -- Once there are enough yes votes to satisfy the quorum and approval ratio,
  122. -- then any DAO member can execute the proposal.
  123. --
  124. -- $ drk dao exec f6cae...1f6cf > dao_exec_tx
  125. -- $ drk broadcast < dao_exec_tx
  126. PRAGMA foreign_keys = ON;
  127. CREATE TABLE IF NOT EXISTS Fd8kfCuqU8BoFFp6GcXv5pC8XXRkBK7gUPQX5XDz7iXj_dao_daos (
  128. -- Bulla identifier of the DAO
  129. bulla BLOB PRIMARY KEY NOT NULL,
  130. -- Unique name identifier of the DAO
  131. name TEXT UNIQUE NOT NULL,
  132. -- DAO parameters
  133. params BLOB NOT NULL,
  134. -- These values are NULL until the DAO is minted on chain and received
  135. -- Leaf position of the DAO in the Merkle tree of DAOs
  136. leaf_position BLOB,
  137. -- The transaction hash where the DAO was deployed
  138. tx_hash BLOB,
  139. -- The call index in the transaction where the DAO was deployed
  140. call_index INTEGER
  141. );
  142. -- The merkle tree containing DAO bullas
  143. CREATE TABLE IF NOT EXISTS Fd8kfCuqU8BoFFp6GcXv5pC8XXRkBK7gUPQX5XDz7iXj_dao_trees (
  144. daos_tree BLOB NOT NULL,
  145. proposals_tree BLOB NOT NULL
  146. );
  147. CREATE TABLE IF NOT EXISTS Fd8kfCuqU8BoFFp6GcXv5pC8XXRkBK7gUPQX5XDz7iXj_dao_proposals (
  148. -- Bulla identifier of the proposal
  149. bulla BLOB PRIMARY KEY NOT NULL,
  150. -- Bulla identifier of the DAO this proposal is for
  151. dao_bulla BLOB NOT NULL,
  152. -- The on chain representation of the proposal
  153. proposal BLOB NOT NULL,
  154. -- Plaintext proposal call data the members share between them
  155. data BLOB,
  156. -- These values are NULL until the proposal is minted on chain and received
  157. -- Leaf position of the proposal in the Merkle tree of proposals
  158. leaf_position BLOB,
  159. -- Money merkle tree snapshot for reproducing the snapshot Merkle root
  160. money_snapshot_tree BLOB,
  161. -- Money nullifiers SMT snapshot for reproducing the snapshot Merkle root
  162. nullifiers_smt_snapshot BLOB,
  163. -- The transaction hash where the proposal was deployed
  164. tx_hash BLOB,
  165. -- The call index in the transaction where the proposal was deployed
  166. call_index INTEGER,
  167. -- This value is NULL until the proposal is executed on chain and received
  168. exec_tx_hash BLOB,
  169. FOREIGN KEY(dao_bulla) REFERENCES Fd8kfCuqU8BoFFp6GcXv5pC8XXRkBK7gUPQX5XDz7iXj_dao_daos(bulla) ON DELETE CASCADE ON UPDATE CASCADE
  170. );
  171. CREATE TABLE IF NOT EXISTS Fd8kfCuqU8BoFFp6GcXv5pC8XXRkBK7gUPQX5XDz7iXj_dao_votes (
  172. -- Numeric identifier of the vote
  173. vote_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
  174. -- Bulla identifier of the proposal this vote is for
  175. proposal_bulla BLOB NOT NULL,
  176. -- The vote
  177. vote_option INTEGER NOT NULL,
  178. -- Blinding factor for the yes vote
  179. yes_vote_blind BLOB NOT NULL,
  180. -- Value of all votes
  181. all_vote_value BLOB NOT NULL,
  182. -- Blinding facfor of all votes
  183. all_vote_blind BLOB NOT NULL,
  184. -- Transaction hash where this vote was casted
  185. tx_hash BLOB NOT NULL,
  186. -- Call index in the transaction where this vote was casted
  187. call_index INTEGER NOT NULL,
  188. -- Vote input nullifiers
  189. nullifiers BLOB NOT NULL,
  190. FOREIGN KEY(proposal_bulla) REFERENCES Fd8kfCuqU8BoFFp6GcXv5pC8XXRkBK7gUPQX5XDz7iXj_dao_proposals(bulla) ON DELETE CASCADE ON UPDATE CASCADE
  191. );