dao.sql 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  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 < 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 DAO_NAME < dao.dat
  26. -- Imported DAO ccb8XXX8af6
  27. --
  28. -- Where ccb8XXX8af6 is the DAO's bulla.
  29. --
  30. -- Next one person will mint it on chain
  31. --
  32. -- $ drk dao mint DAO_NAME
  33. -- Broadcasted DAO ccb8XXX8af6
  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. -- # Minting and Receiving Coin
  38. --
  39. -- Assume that the governance tokens have been created and distributed
  40. -- appropriately among DAO members. We will skip that part here.
  41. --
  42. -- Now the DAO can receive coins into its treasury. These coins simply
  43. -- have both the coin's spend_hook and user_data fields set correctly
  44. -- otherwise they are rejected as invalid/malformed.
  45. -- # DAO::propose()
  46. --
  47. -- Create a proposal for the DAO
  48. --
  49. -- $ drk dao propose \
  50. -- DAO_NAME \
  51. -- RECV_PUBKEY \
  52. -- AMOUNT \
  53. -- SERIAL \
  54. -- SENDCOIN_TOKEN_ID
  55. --
  56. -- If we don't have enough tokens to meet the proposer_limit threshold
  57. -- then this call will simply fail with an error message. Nothing will
  58. -- be added to the database or sent to the network.
  59. --
  60. -- The other participants should automatically receive the proposal
  61. -- ready to vote on it.
  62. -- # DAO::vote()
  63. --
  64. -- You have received a proposal which is active. You can now vote on it.
  65. --
  66. -- $ drk dao proposals DAO_NAME
  67. -- [0] f6cae63ced53d02b372206a8d3ed5ac03fde18da306a520285fd56e8d031f6cf
  68. -- [1] 1372622f4a38be6eb1c90fa67864474c6603d9f8d4228106e20e2d0d04f2395e
  69. -- [2] 88b18cbc38dbd3af8d25237af3903e985f70ea06d1e25966bf98e3f08e23c992
  70. --
  71. -- $ drk dao show_proposal 1
  72. -- Proposal: 1372622f4a38be6eb1c90fa67864474c6603d9f8d4228106e20e2d0d04f2395e
  73. -- destination: ...
  74. -- amount: ...
  75. -- token_id: ...
  76. -- dao_name: DAO_NAME
  77. -- dao_bulla: ...
  78. -- Current yes votes: X
  79. -- Current no votes: Y
  80. -- Total votes: X + Y
  81. -- [================ ] 45.56%
  82. -- DAO quorum threshold: Z
  83. -- DAO approval ratio: 60%
  84. --
  85. -- $ drk dao vote 1 yes
  86. -- # DAO::exec()
  87. --
  88. -- Once there are enough yes votes to satisfy the quorum and approval ratio,
  89. -- then any DAO member can execute the payment out of the treasury.
  90. --
  91. -- $ drk dao exec 1
  92. --
  93. -- FUTURE NOTE: We have to assume that 2 people could try to exec at once.
  94. -- So if our exec fails, then the tx fee we pay should be returned
  95. -- to our wallet.
  96. -- We should design our tables for exec accordingly.
  97. -- For now I didn't put anything, but we should keep this minor
  98. -- point in mind and ruminate on it for later.
  99. PRAGMA foreign_keys = ON;
  100. CREATE TABLE IF NOT EXISTS Fd8kfCuqU8BoFFp6GcXv5pC8XXRkBK7gUPQX5XDz7iXj_dao_daos (
  101. dao_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
  102. name BLOB UNIQUE NOT NULL,
  103. proposer_limit BLOB NOT NULL,
  104. -- minimum threshold for total number of votes for proposal to pass.
  105. -- If there's too little activity then it cannot pass.
  106. quorum BLOB NOT NULL,
  107. -- Needed ratio of yes/total for proposal to pass.
  108. -- approval_ratio = approval_ratio_quot / approval_ratio_base
  109. approval_ratio_base INTEGER NOT NULL,
  110. approval_ratio_quot INTEGER NOT NULL,
  111. gov_token_id BLOB NOT NULL,
  112. secret BLOB NOT NULL,
  113. bulla_blind BLOB NOT NULL,
  114. -- these values are NULL until the DAO is minted on chain and received
  115. leaf_position BLOB,
  116. tx_hash BLOB,
  117. call_index INTEGER
  118. );
  119. -- The merkle tree containing DAO bullas
  120. CREATE TABLE IF NOT EXISTS Fd8kfCuqU8BoFFp6GcXv5pC8XXRkBK7gUPQX5XDz7iXj_dao_trees (
  121. daos_tree BLOB NOT NULL,
  122. proposals_tree BLOB NOT NULL
  123. );
  124. CREATE TABLE IF NOT EXISTS Fd8kfCuqU8BoFFp6GcXv5pC8XXRkBK7gUPQX5XDz7iXj_dao_proposals (
  125. proposal_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
  126. dao_id INTEGER NOT NULL,
  127. -- Public key of person that would receive the funds
  128. recv_public BLOB NOT NULL,
  129. -- Amount of funds that would be sent
  130. amount BLOB NOT NULL,
  131. -- Token ID we propose to send
  132. sendcoin_token_id BLOB NOT NULL,
  133. bulla_blind BLOB NOT NULL,
  134. -- these values are NULL until the proposal is minted on chain
  135. -- and received by the DAO
  136. leaf_position BLOB,
  137. money_snapshot_tree BLOB,
  138. tx_hash BLOB,
  139. call_index INTEGER,
  140. -- this is NULL until we have voted on this proposal
  141. our_vote_id INTEGER UNIQUE,
  142. FOREIGN KEY(our_vote_id) REFERENCES Fd8kfCuqU8BoFFp6GcXv5pC8XXRkBK7gUPQX5XDz7iXj_dao_votes(vote_id) ON DELETE CASCADE ON UPDATE CASCADE,
  143. FOREIGN KEY(dao_id) REFERENCES Fd8kfCuqU8BoFFp6GcXv5pC8XXRkBK7gUPQX5XDz7iXj_dao_daos(dao_id) ON DELETE CASCADE ON UPDATE CASCADE
  144. );
  145. CREATE TABLE IF NOT EXISTS Fd8kfCuqU8BoFFp6GcXv5pC8XXRkBK7gUPQX5XDz7iXj_dao_votes (
  146. vote_id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
  147. proposal_id INTEGER NOT NULL,
  148. vote_option INTEGER NOT NULL,
  149. yes_vote_blind BLOB NOT NULL,
  150. all_vote_value BLOB NOT NULL,
  151. all_vote_blind BLOB NOT NULL,
  152. -- these values are NULL until the vote is minted on chain
  153. -- and received by the DAO
  154. tx_hash BLOB,
  155. call_index INTEGER,
  156. -- My code has votes merkle tree and position for votes, but
  157. -- that might be a mistake...
  158. FOREIGN KEY(proposal_id) REFERENCES Fd8kfCuqU8BoFFp6GcXv5pC8XXRkBK7gUPQX5XDz7iXj_dao_proposals(proposal_id) ON DELETE CASCADE ON UPDATE CASCADE
  159. );