dao.sql 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. -- TODO: Update these once finished
  2. -- # DAO::mint()
  3. --
  4. -- First one person will create the DAO
  5. --
  6. -- $ drk dao create_dao \
  7. -- PROPOSER_LIMIT \
  8. -- QUORUM \
  9. -- APPROVAL_RATIO_BASE \
  10. -- APPROVAL_RATIO_QUOTIENT \
  11. -- GOV_TOKEN_ID > dao.dat
  12. --
  13. -- dat.dat contains:
  14. --
  15. -- * DAO parameters as listed above
  16. -- * secret key for the DAO
  17. -- * bulla blind
  18. --
  19. -- We can view the data like so:
  20. --
  21. -- $ drk dao view_dao < dao.dat
  22. --
  23. -- Now everyone inside the DAO exchanges dao.dat out of band will import
  24. -- it into their wallets.
  25. --
  26. -- $ drk dao import_dao DAO_NAME < dao.dat
  27. -- Imported DAO ccb8XXX8af6
  28. --
  29. -- Where ccb8XXX8af6 is the DAO's name.
  30. --
  31. -- Next one person will mint it on chain
  32. --
  33. -- $ drk dao mint DAO_NAME
  34. -- Broadcasted DAO ccb8XXX8af6
  35. --
  36. -- And then the others will receive confirmation that the DAO they imported
  37. -- into their wallet has also been accepted on chain.
  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. -- # DAO::propose()
  47. --
  48. -- Create a proposal for the DAO
  49. --
  50. -- $ drk dao propose \
  51. -- DAO_NAME \
  52. -- RECV_PUBKEY \
  53. -- AMOUNT \
  54. -- SERIAL \
  55. -- SENDCOIN_TOKEN_ID
  56. --
  57. -- If we don't have enough tokens to meet the proposer_limit threshold
  58. -- then this call will simply fail with an error message. Nothing will
  59. -- be added to the database or sent to the network.
  60. --
  61. -- The other participants should automatically receive the proposal
  62. -- ready to vote on it.
  63. -- # DAO::vote()
  64. --
  65. -- You have received a proposal which is active. You can now vote on it.
  66. --
  67. -- $ drk dao proposals DAO_NAME
  68. -- [0] f6cae63ced53d02b372206a8d3ed5ac03fde18da306a520285fd56e8d031f6cf
  69. -- [1] 1372622f4a38be6eb1c90fa67864474c6603d9f8d4228106e20e2d0d04f2395e
  70. -- [2] 88b18cbc38dbd3af8d25237af3903e985f70ea06d1e25966bf98e3f08e23c992
  71. --
  72. -- $ drk dao show_proposal 1
  73. -- Proposal: 1372622f4a38be6eb1c90fa67864474c6603d9f8d4228106e20e2d0d04f2395e
  74. -- destination: ...
  75. -- amount: ...
  76. -- token_id: ...
  77. -- dao_name: DAO_NAME
  78. -- dao_bulla: ...
  79. -- Current yes votes: X
  80. -- Current no votes: Y
  81. -- Total votes: X + Y
  82. -- [================ ] 45.56%
  83. -- DAO quorum threshold: Z
  84. -- DAO approval ratio: 60%
  85. --
  86. -- $ drk dao vote 1 yes
  87. -- # DAO::exec()
  88. --
  89. -- Once there are enough yes votes to satisfy the quorum and approval ratio,
  90. -- then any DAO member can execute the payment out of the treasury.
  91. --
  92. -- $ drk dao exec 1
  93. --
  94. -- FUTURE NOTE: We have to assume that 2 people could try to exec at once.
  95. -- So if our exec fails, then the tx fee we pay should be returned
  96. -- to our wallet.
  97. -- We should design our tables for exec accordingly.
  98. -- For now I didn't put anything, but we should keep this minor
  99. -- point in mind and ruminate on it for later.
  100. PRAGMA foreign_keys = ON;
  101. CREATE TABLE IF NOT EXISTS Fd8kfCuqU8BoFFp6GcXv5pC8XXRkBK7gUPQX5XDz7iXj_dao_daos (
  102. -- Bulla identifier of the DAO
  103. bulla BLOB PRIMARY KEY NOT NULL,
  104. -- Unique name identifier of the DAO
  105. name TEXT UNIQUE NOT NULL,
  106. -- DAO parameters
  107. params BLOB NOT NULL,
  108. -- These values are NULL until the DAO is minted on chain and received
  109. -- Leaf position of the DAO in the Merkle tree of DAOs
  110. leaf_position BLOB,
  111. -- The transaction hash where the DAO was deployed
  112. tx_hash BLOB,
  113. -- The call index in the transaction where the DAO was deployed
  114. call_index INTEGER
  115. );
  116. -- The merkle tree containing DAO bullas
  117. CREATE TABLE IF NOT EXISTS Fd8kfCuqU8BoFFp6GcXv5pC8XXRkBK7gUPQX5XDz7iXj_dao_trees (
  118. daos_tree BLOB NOT NULL,
  119. proposals_tree BLOB NOT NULL
  120. );
  121. CREATE TABLE IF NOT EXISTS Fd8kfCuqU8BoFFp6GcXv5pC8XXRkBK7gUPQX5XDz7iXj_dao_proposals (
  122. -- Bulla identifier of the proposal
  123. bulla BLOB PRIMARY KEY NOT NULL,
  124. -- Bulla identifier of the DAO this proposal is for
  125. dao_bulla BLOB NOT NULL,
  126. -- The on chain representation of the proposal
  127. proposal BLOB NOT NULL,
  128. -- Plaintext proposal call data the members share between them
  129. data BLOB,
  130. -- These values are NULL until the proposal is minted on chain and received
  131. -- Leaf position of the proposal in the Merkle tree of proposals
  132. leaf_position BLOB,
  133. -- Money merkle tree snapshot for reproducing the snapshot Merkle root
  134. money_snapshot_tree BLOB,
  135. -- The transaction hash where the proposal was deployed
  136. tx_hash BLOB,
  137. -- The call index in the transaction where the proposal was deployed
  138. call_index INTEGER,
  139. FOREIGN KEY(dao_bulla) REFERENCES Fd8kfCuqU8BoFFp6GcXv5pC8XXRkBK7gUPQX5XDz7iXj_dao_daos(bulla) ON DELETE CASCADE ON UPDATE CASCADE
  140. );
  141. CREATE TABLE IF NOT EXISTS Fd8kfCuqU8BoFFp6GcXv5pC8XXRkBK7gUPQX5XDz7iXj_dao_votes (
  142. vote_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
  143. proposal_bulla BLOB NOT NULL,
  144. vote_option INTEGER NOT NULL,
  145. yes_vote_blind BLOB NOT NULL,
  146. all_vote_value BLOB NOT NULL,
  147. all_vote_blind BLOB NOT NULL,
  148. -- these values are NULL until the vote is minted on chain
  149. -- and received by the DAO
  150. tx_hash BLOB,
  151. call_index INTEGER,
  152. -- My code has votes merkle tree and position for votes, but
  153. -- that might be a mistake...
  154. FOREIGN KEY(proposal_bulla) REFERENCES Fd8kfCuqU8BoFFp6GcXv5pC8XXRkBK7gUPQX5XDz7iXj_dao_proposals(bulla) ON DELETE CASCADE ON UPDATE CASCADE
  155. );