Merge pull request #32 from Liqwid-Labs/emiflake/update-docs
Update docs & add stake assertion
This commit is contained in:
commit
bb1cabb5fd
6 changed files with 74 additions and 79 deletions
|
|
@ -18,7 +18,7 @@ Non-goals:
|
|||
|
||||
An up to date version of the [Nix package manager](nixos.org) (>=2.3) is required to build this project. For information on how to install, see the [NixOS website](https://nixos.org/download.html). Important: see also [this section](https://github.com/input-output-hk/plutus#nix-advice) on binary caches.
|
||||
|
||||
Open a development shell with `nix develop` and build the project with `cabal build`. Those pained by the need to remember to enter a Nix shell may consider using [nix-direnv](https://github.com/nix-community/nix-direnv).
|
||||
Open a development shell with `nix develop` and build the project with `cabal build`. Those pained by the need to remember to enter a Nix shell may consider using [nix-direnv](https://github.com/nix-community/nix-direnv).
|
||||
|
||||
## Documentation
|
||||
|
||||
|
|
@ -88,10 +88,6 @@ The treasury of a governance system is responsible for determining which users a
|
|||
|
||||
Users are required to 'lock' their GT in stakes, so that the system has some idea of their eligibility to vote on proposal.
|
||||
|
||||
### Staking pool
|
||||
|
||||
A staking pool can be introduced, for the purpose of tracking the aggregate status of all stakes in the system. Some systems may not require a staking pool.
|
||||
|
||||
### Proposal
|
||||
|
||||
A proposal suggests for some specified changes to be made to a Cardano system. It is voted upon by the community and, if passed, its effects are applied to the system.
|
||||
|
|
|
|||
|
|
@ -1,8 +1,7 @@
|
|||
digraph {
|
||||
"Staking pool" -> Stakes [label="tracks"]
|
||||
Stakes -> Proposals [label="are put on"]
|
||||
Stakes -> Proposals [label="vote on"]
|
||||
Proposals -> Effects [label="have"]
|
||||
Governor -> Effects [label="issues GATs to"]
|
||||
Users -> Stakes [label="lock GT in"]
|
||||
Users -> Treasury [label="claim GT from"]
|
||||
Effects -> Treasury [label="release GT from"]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,96 +1,83 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
|
||||
"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
|
||||
<!-- Generated by graphviz version 2.48.0 (0)
|
||||
<!-- Generated by graphviz version 2.49.3 (0)
|
||||
-->
|
||||
<!-- Pages: 1 -->
|
||||
<svg width="334pt" height="305pt"
|
||||
viewBox="0.00 0.00 333.89 305.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 301)">
|
||||
<polygon fill="white" stroke="transparent" points="-4,4 -4,-301 329.89,-301 329.89,4 -4,4"/>
|
||||
<!-- Staking pool -->
|
||||
<g id="node1" class="node">
|
||||
<title>Staking pool</title>
|
||||
<ellipse fill="none" stroke="black" cx="68.89" cy="-279" rx="68.79" ry="18"/>
|
||||
<text text-anchor="middle" x="68.89" y="-275.3" font-family="Times,serif" font-size="14.00">Staking pool</text>
|
||||
</g>
|
||||
<svg width="262pt" height="392pt"
|
||||
viewBox="0.00 0.00 261.95 392.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
|
||||
<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 388)">
|
||||
<polygon fill="white" stroke="transparent" points="-4,4 -4,-388 257.95,-388 257.95,4 -4,4"/>
|
||||
<!-- Stakes -->
|
||||
<g id="node2" class="node">
|
||||
<g id="node1" class="node">
|
||||
<title>Stakes</title>
|
||||
<ellipse fill="none" stroke="black" cx="94.89" cy="-192" rx="42.49" ry="18"/>
|
||||
<text text-anchor="middle" x="94.89" y="-188.3" font-family="Times,serif" font-size="14.00">Stakes</text>
|
||||
</g>
|
||||
<!-- Staking pool->Stakes -->
|
||||
<g id="edge1" class="edge">
|
||||
<title>Staking pool->Stakes</title>
|
||||
<path fill="none" stroke="black" d="M66.77,-260.91C66.15,-251.05 66.4,-238.55 69.89,-228 71.09,-224.39 72.81,-220.82 74.78,-217.43"/>
|
||||
<polygon fill="black" stroke="black" points="77.8,-219.21 80.45,-208.95 71.98,-215.32 77.8,-219.21"/>
|
||||
<text text-anchor="middle" x="92.39" y="-231.8" font-family="Times,serif" font-size="14.00">tracks</text>
|
||||
<ellipse fill="none" stroke="black" cx="181.95" cy="-279" rx="42.49" ry="18"/>
|
||||
<text text-anchor="middle" x="181.95" y="-275.3" font-family="Times,serif" font-size="14.00">Stakes</text>
|
||||
</g>
|
||||
<!-- Proposals -->
|
||||
<g id="node3" class="node">
|
||||
<g id="node2" class="node">
|
||||
<title>Proposals</title>
|
||||
<ellipse fill="none" stroke="black" cx="94.89" cy="-105" rx="55.79" ry="18"/>
|
||||
<text text-anchor="middle" x="94.89" y="-101.3" font-family="Times,serif" font-size="14.00">Proposals</text>
|
||||
<ellipse fill="none" stroke="black" cx="181.95" cy="-192" rx="55.79" ry="18"/>
|
||||
<text text-anchor="middle" x="181.95" y="-188.3" font-family="Times,serif" font-size="14.00">Proposals</text>
|
||||
</g>
|
||||
<!-- Stakes->Proposals -->
|
||||
<g id="edge2" class="edge">
|
||||
<g id="edge1" class="edge">
|
||||
<title>Stakes->Proposals</title>
|
||||
<path fill="none" stroke="black" d="M94.89,-173.8C94.89,-162.16 94.89,-146.55 94.89,-133.24"/>
|
||||
<polygon fill="black" stroke="black" points="98.39,-133.18 94.89,-123.18 91.39,-133.18 98.39,-133.18"/>
|
||||
<text text-anchor="middle" x="131.89" y="-144.8" font-family="Times,serif" font-size="14.00">are put on</text>
|
||||
<path fill="none" stroke="black" d="M181.95,-260.8C181.95,-249.16 181.95,-233.55 181.95,-220.24"/>
|
||||
<polygon fill="black" stroke="black" points="185.45,-220.18 181.95,-210.18 178.45,-220.18 185.45,-220.18"/>
|
||||
<text text-anchor="middle" x="208.45" y="-231.8" font-family="Times,serif" font-size="14.00">vote on</text>
|
||||
</g>
|
||||
<!-- Effects -->
|
||||
<g id="node4" class="node">
|
||||
<g id="node3" class="node">
|
||||
<title>Effects</title>
|
||||
<ellipse fill="none" stroke="black" cx="158.89" cy="-18" rx="42.79" ry="18"/>
|
||||
<text text-anchor="middle" x="158.89" y="-14.3" font-family="Times,serif" font-size="14.00">Effects</text>
|
||||
<ellipse fill="none" stroke="black" cx="116.95" cy="-105" rx="42.79" ry="18"/>
|
||||
<text text-anchor="middle" x="116.95" y="-101.3" font-family="Times,serif" font-size="14.00">Effects</text>
|
||||
</g>
|
||||
<!-- Proposals->Effects -->
|
||||
<g id="edge3" class="edge">
|
||||
<g id="edge2" class="edge">
|
||||
<title>Proposals->Effects</title>
|
||||
<path fill="none" stroke="black" d="M107.54,-87.21C116.89,-74.79 129.78,-57.67 140.3,-43.7"/>
|
||||
<polygon fill="black" stroke="black" points="143.27,-45.56 146.49,-35.47 137.68,-41.35 143.27,-45.56"/>
|
||||
<text text-anchor="middle" x="147.89" y="-57.8" font-family="Times,serif" font-size="14.00">have</text>
|
||||
</g>
|
||||
<!-- Governor -->
|
||||
<g id="node5" class="node">
|
||||
<title>Governor</title>
|
||||
<ellipse fill="none" stroke="black" cx="222.89" cy="-105" rx="53.89" ry="18"/>
|
||||
<text text-anchor="middle" x="222.89" y="-101.3" font-family="Times,serif" font-size="14.00">Governor</text>
|
||||
</g>
|
||||
<!-- Governor->Effects -->
|
||||
<g id="edge4" class="edge">
|
||||
<title>Governor->Effects</title>
|
||||
<path fill="none" stroke="black" d="M210.25,-87.21C200.9,-74.79 188.01,-57.67 177.49,-43.7"/>
|
||||
<polygon fill="black" stroke="black" points="180.11,-41.35 171.29,-35.47 174.51,-45.56 180.11,-41.35"/>
|
||||
<text text-anchor="middle" x="246.89" y="-57.8" font-family="Times,serif" font-size="14.00">issues GATs to</text>
|
||||
</g>
|
||||
<!-- Users -->
|
||||
<g id="node6" class="node">
|
||||
<title>Users</title>
|
||||
<ellipse fill="none" stroke="black" cx="212.89" cy="-279" rx="38.19" ry="18"/>
|
||||
<text text-anchor="middle" x="212.89" y="-275.3" font-family="Times,serif" font-size="14.00">Users</text>
|
||||
</g>
|
||||
<!-- Users->Stakes -->
|
||||
<g id="edge5" class="edge">
|
||||
<title>Users->Stakes</title>
|
||||
<path fill="none" stroke="black" d="M185.75,-266.08C173.12,-259.97 158.21,-251.95 145.89,-243 135.34,-235.33 124.85,-225.52 116.15,-216.63"/>
|
||||
<polygon fill="black" stroke="black" points="118.44,-213.96 109.01,-209.12 113.37,-218.78 118.44,-213.96"/>
|
||||
<text text-anchor="middle" x="181.89" y="-231.8" font-family="Times,serif" font-size="14.00">lock GT in</text>
|
||||
<path fill="none" stroke="black" d="M176.2,-173.75C172.31,-163.6 166.5,-150.86 158.95,-141 155.25,-136.17 150.77,-131.57 146.14,-127.38"/>
|
||||
<polygon fill="black" stroke="black" points="148.19,-124.54 138.3,-120.76 143.68,-129.88 148.19,-124.54"/>
|
||||
<text text-anchor="middle" x="183.95" y="-144.8" font-family="Times,serif" font-size="14.00">have</text>
|
||||
</g>
|
||||
<!-- Treasury -->
|
||||
<g id="node7" class="node">
|
||||
<g id="node6" class="node">
|
||||
<title>Treasury</title>
|
||||
<ellipse fill="none" stroke="black" cx="231.89" cy="-192" rx="51.99" ry="18"/>
|
||||
<text text-anchor="middle" x="231.89" y="-188.3" font-family="Times,serif" font-size="14.00">Treasury</text>
|
||||
<ellipse fill="none" stroke="black" cx="116.95" cy="-18" rx="51.99" ry="18"/>
|
||||
<text text-anchor="middle" x="116.95" y="-14.3" font-family="Times,serif" font-size="14.00">Treasury</text>
|
||||
</g>
|
||||
<!-- Users->Treasury -->
|
||||
<g id="edge6" class="edge">
|
||||
<title>Users->Treasury</title>
|
||||
<path fill="none" stroke="black" d="M216.74,-260.8C219.34,-249.16 222.83,-233.55 225.81,-220.24"/>
|
||||
<polygon fill="black" stroke="black" points="229.29,-220.7 228.05,-210.18 222.46,-219.17 229.29,-220.7"/>
|
||||
<text text-anchor="middle" x="274.89" y="-231.8" font-family="Times,serif" font-size="14.00">claim GT from</text>
|
||||
<!-- Effects->Treasury -->
|
||||
<g id="edge5" class="edge">
|
||||
<title>Effects->Treasury</title>
|
||||
<path fill="none" stroke="black" d="M116.95,-86.8C116.95,-75.16 116.95,-59.55 116.95,-46.24"/>
|
||||
<polygon fill="black" stroke="black" points="120.45,-46.18 116.95,-36.18 113.45,-46.18 120.45,-46.18"/>
|
||||
<text text-anchor="middle" x="174.45" y="-57.8" font-family="Times,serif" font-size="14.00">release GT from</text>
|
||||
</g>
|
||||
<!-- Governor -->
|
||||
<g id="node4" class="node">
|
||||
<title>Governor</title>
|
||||
<ellipse fill="none" stroke="black" cx="53.95" cy="-192" rx="53.89" ry="18"/>
|
||||
<text text-anchor="middle" x="53.95" y="-188.3" font-family="Times,serif" font-size="14.00">Governor</text>
|
||||
</g>
|
||||
<!-- Governor->Effects -->
|
||||
<g id="edge3" class="edge">
|
||||
<title>Governor->Effects</title>
|
||||
<path fill="none" stroke="black" d="M50.23,-173.63C48.99,-163.43 49.16,-150.69 54.95,-141 59.79,-132.9 67.26,-126.51 75.36,-121.54"/>
|
||||
<polygon fill="black" stroke="black" points="77.18,-124.54 84.3,-116.69 73.84,-118.38 77.18,-124.54"/>
|
||||
<text text-anchor="middle" x="106.95" y="-144.8" font-family="Times,serif" font-size="14.00">issues GATs to</text>
|
||||
</g>
|
||||
<!-- Users -->
|
||||
<g id="node5" class="node">
|
||||
<title>Users</title>
|
||||
<ellipse fill="none" stroke="black" cx="181.95" cy="-366" rx="38.19" ry="18"/>
|
||||
<text text-anchor="middle" x="181.95" y="-362.3" font-family="Times,serif" font-size="14.00">Users</text>
|
||||
</g>
|
||||
<!-- Users->Stakes -->
|
||||
<g id="edge4" class="edge">
|
||||
<title>Users->Stakes</title>
|
||||
<path fill="none" stroke="black" d="M181.95,-347.8C181.95,-336.16 181.95,-320.55 181.95,-307.24"/>
|
||||
<polygon fill="black" stroke="black" points="185.45,-307.18 181.95,-297.18 178.45,-307.18 185.45,-307.18"/>
|
||||
<text text-anchor="middle" x="217.95" y="-318.8" font-family="Times,serif" font-size="14.00">lock GT in</text>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
||||
|
|
|
|||
|
Before Width: | Height: | Size: 4.9 KiB After Width: | Height: | Size: 4.2 KiB |
|
|
@ -47,7 +47,7 @@ stake.lockedByProposals += (hash proposal.settings, vote)
|
|||
|
||||
This forms a mutual binding between the proposal and the stake.
|
||||
|
||||
A stake may be used to vote on an unlimited number of proposals. Consider a user staking 50GT. They may pledge that 50GT against a proposal `p` _and_ another proposal `p'`.
|
||||
A stake may be used to vote on an unlimited number of proposals. Consider a user staking 50GT. They may pledge that 50GT against a proposal `p` _and_ another proposal `q`.
|
||||
|
||||
Altering the amount positioned in a stake is not possible, for as long as that stake is locked against any proposals. This is to prevent vote manipulation. Consider:
|
||||
|
||||
|
|
@ -78,6 +78,11 @@ data Stake = Stake
|
|||
|
||||
When voting on a proposal, a user can check which stakes have delegated to them off-chain and include them in the voting transaction. _This will lock the delegator's stake_, however they will be themselves be able to unlock it as usual. It should be noted that delegation of stakes only extends to voting on proposals and not, for example, withdrawing GT from a stake.
|
||||
|
||||
## Destroying stake
|
||||
|
||||
In order to recover the ADA spent on creating the stake UTXO (and any other funds, which may have been locked by accident), stake UTXOs must be destroyable. As is the case with the depositing and withdrawal of GT from a stake, the stake must *not* be locked by any proposals, before it may be destroyed.
|
||||
|
||||
|
||||
## Staking pool
|
||||
|
||||
There are a number of reasons that a protocol would wish to track the global state of stakes in its system. For example, a protocol may wish to implement a proposal system where a certain proportion of the globally available GT must be staked in-favour of a proposal, in order to allow it to pass. This is the equivalent of mandating a certain voter turnout be met in a national referendum. The ability to do such a thing is conferred by the creation of a _staking pool_.
|
||||
|
|
|
|||
|
|
@ -60,6 +60,7 @@
|
|||
pkgs'.hlint
|
||||
pkgs'.haskellPackages.cabal-fmt
|
||||
pkgs'.nixpkgs-fmt
|
||||
pkgs'.graphviz
|
||||
];
|
||||
|
||||
inherit (plutarch) tools;
|
||||
|
|
|
|||
|
|
@ -215,6 +215,7 @@ stakeValidator stake =
|
|||
PJust txInInfo <- pmatch $ pfindTxInByTxOutRef # (pfield @"_0" # txOutRef) # txInfo'
|
||||
ownAddress <- plet $ pfield @"address" #$ pfield @"resolved" # txInInfo
|
||||
let continuingValue = pfield @"value" #$ pfield @"resolved" # txInInfo
|
||||
ownerSignsTransaction <- plet $ ptxSignedBy # ctx.txInfo # stakeDatum.owner
|
||||
stCurrencySymbol <- plet $ pconstant $ mintingPolicySymbol $ mkMintingPolicy (stakePolicy stake)
|
||||
mintedST <- plet $ psymbolValueOf # stCurrencySymbol # txInfo.mint
|
||||
spentST <- plet $ psymbolValueOf # stCurrencySymbol #$ pvalueSpent # txInfo'
|
||||
|
|
@ -227,12 +228,18 @@ stakeValidator stake =
|
|||
mintedST #== -1
|
||||
passert "Stake unlocked" $
|
||||
pnot #$ stakeLocked # stakeDatum'
|
||||
passert
|
||||
"Owner signs this transaction"
|
||||
ownerSignsTransaction
|
||||
popaque (pconstant ())
|
||||
PDepositWithdraw r -> P.do
|
||||
passert "ST at inputs must be 1" $
|
||||
spentST #== 1
|
||||
passert "Stake unlocked" $
|
||||
pnot #$ stakeLocked # stakeDatum'
|
||||
passert
|
||||
"Owner signs this transaction"
|
||||
ownerSignsTransaction
|
||||
passert "A UTXO must exist with the correct output" $
|
||||
anyOutput @(PStakeDatum gt) # txInfo'
|
||||
#$ plam
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue