diff --git a/README.md b/README.md index 35870f8..a0f2905 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/docs/diagrams/gov-overview.dot b/docs/diagrams/gov-overview.dot index 5b1ab3c..0ee05d6 100644 --- a/docs/diagrams/gov-overview.dot +++ b/docs/diagrams/gov-overview.dot @@ -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"] } diff --git a/docs/diagrams/gov-overview.svg b/docs/diagrams/gov-overview.svg index 008d286..b52362d 100644 --- a/docs/diagrams/gov-overview.svg +++ b/docs/diagrams/gov-overview.svg @@ -1,96 +1,83 @@ - - - - - - -Staking pool - -Staking pool - + + + - + Stakes - -Stakes - - - -Staking pool->Stakes - - -tracks + +Stakes - + Proposals - -Proposals + +Proposals - + Stakes->Proposals - - -are put on + + +vote on - + Effects - -Effects + +Effects - + Proposals->Effects - - -have - - - -Governor - -Governor - - - -Governor->Effects - - -issues GATs to - - - -Users - -Users - - - -Users->Stakes - - -lock GT in + + +have - + Treasury - -Treasury + +Treasury - - -Users->Treasury - - -claim GT from + + +Effects->Treasury + + +release GT from + + + +Governor + +Governor + + + +Governor->Effects + + +issues GATs to + + + +Users + +Users + + + +Users->Stakes + + +lock GT in diff --git a/docs/tech-design/staking-pool.md b/docs/tech-design/staking-pool.md index 2262bbb..200a807 100644 --- a/docs/tech-design/staking-pool.md +++ b/docs/tech-design/staking-pool.md @@ -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_. diff --git a/flake.nix b/flake.nix index 103fea2..ca4ede1 100644 --- a/flake.nix +++ b/flake.nix @@ -60,6 +60,7 @@ pkgs'.hlint pkgs'.haskellPackages.cabal-fmt pkgs'.nixpkgs-fmt + pkgs'.graphviz ]; inherit (plutarch) tools; diff --git a/src/Agora/Stake.hs b/src/Agora/Stake.hs index a4dcc24..cc87ae8 100644 --- a/src/Agora/Stake.hs +++ b/src/Agora/Stake.hs @@ -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