Skip to content

Commit

Permalink
Merge pull request #155 from Liqwid-Labs/staging
Browse files Browse the repository at this point in the history
Release 0.2.0
  • Loading branch information
emiflake authored Aug 13, 2022
2 parents 87b1094 + a6ad4c7 commit 4eb5fe2
Show file tree
Hide file tree
Showing 66 changed files with 13,729 additions and 8,589 deletions.
78 changes: 0 additions & 78 deletions .github/workflows/integrate.yaml

This file was deleted.

64 changes: 64 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,70 @@

This format is based on [Keep A Changelog](https://keepachangelog.com/en/1.0.0).

## Unreleased (Candidate for 1.0.0)

## 0.2.0 -- 2022-08-13

### Added

- Script exporting with `plutarch-script-export`

### Modified

- Bump plutarch to 1.2 and use `liqwid-nix` for flake derivation.

Included by [#150](https://github.com/Liqwid-Labs/agora/pull/150).

- Script building uses the lazy record `AgoraScripts` instead of explicit per-component parameters.

Included by [#150](https://github.com/Liqwid-Labs/agora/pull/150).

- Stake delegation.

Included by [#149](https://github.com/Liqwid-Labs/agora/pull/149).

- Fixed bug that checks the proposal thresholds in an incorrect way. Added negative tests for the governor scripts.

Included by [#146](https://github.com/Liqwid-Labs/agora/pull/146).

- Draft phase and cosigning for Proposals.

Included by [#136](https://github.com/Liqwid-Labs/agora/pull/136).

- Fixed bug with regards to moving from `VotingReady`.

Included by [#134](https://github.com/Liqwid-Labs/agora/pull/134).

- Fixed bug that made it impossible to create proposals. Added new stake locking mechanism for creating proposals.

Included by [#142](https://github.com/Liqwid-Labs/agora/pull/142).

NOTE: This changes the representation of the following types:

- `PProposalLock`
- `PStakeDatum`
- `PStakeRedeemer`
- `PProposalRedeemer`
- `PTreasuryRedeemer`
- `PGovernorDatum`

### Removed

- Side-stream utilies into `liqwid-Labs/liqwid-plutarch-extra`
- `Agora.MultiSig`--entire module.
- `scriptHashFromAddress` to `Plutarch.Api.V1.ScriptContext`.
- `findOutputsToAddress` to `Plutarch.Api.V1.ScriptContext`.
- `findTxOutDatum` to `Plutarch.Api.V1.ScriptContext`.
- `hasOnlyOneTokenOfCurrencySymbol` to `Plutarch.Api.V1.Value`.
- `mustBePJust` to `Plutarch.Extra.Maybe`.
- `mustBePDJust` to `Plutarch.Extra.Maybe`.
- `isScriptAddress` to `Plutarch.Api.V1.ScriptContext`.
- `isPubKey` to `Plutarch.Api.V1.ScriptContext`.
- `pisUniqBy'` to `Plutarch.Extra.List`.
- `pisUniq'` to `Plutarch.Extra.List`.
- `pon` to `Plutarch.Extra.Function`.
- `pbuiltinUncurry` to `Plutarch.Extra.Function`.

## 0.1.0 -- 2022-06-22

### Added
Expand Down
103 changes: 65 additions & 38 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,32 @@
# This really ought to be `/usr/bin/env bash`, but nix flakes don't like that.
SHELL := /bin/sh

.PHONY: hoogle format haddock usage tag format_nix format_haskell format_check lint ps_bridge bench bench_check scripts
.PHONY: hoogle format haddock usage tag format_nix format_haskell format_check \
lint refactor ps_bridge bench bench_check scripts test build ci

AGORA_TARGETS := agora agora-bench agora-purescript-bridge agora-scripts agora-specs agora-test agora-testlib
SOURCE_FILES := $(shell git ls-tree -r HEAD --full-tree --name-only)
SOURCE_FILES := $(wildcard $(SOURCE_FILES))
HASKELL_SOURCES := $(filter %.hs,$(SOURCE_FILES))
CABAL_SOURCES := $(filter %.cabal,$(SOURCE_FILES))
NIX_SOURCES := $(filter %.nix,$(SOURCE_FILES))
FORMAT_EXTENSIONS := -o -XQuasiQuotes -o -XTemplateHaskell -o -XTypeApplications \
-o -XImportQualifiedPost -o -XPatternSynonyms -o -XOverloadedRecordDot
HLINT_EXTS := -XQuasiQuotes

THREADS ?= 8
PS_BRIDGE_OUTPUT_DIR ?= agora-purescript-bridge/
BENCH_OUTPUT ?= bench.csv
TEST_CASE_TIMEOUT ?= 100

usage:
@echo "usage: make <command> [OPTIONS]"
@echo "usage: [env [<variable>=<value> ...]] make <command> [OPTIONS]"
@echo
@echo "Available variables:"
@echo " THREADS -- The number of threads for building the project"
@echo " PS_BRIDGE_OUTPUT_DIR -- The output directory of the purescript bridge"
@echo " BENCH_OUTPUT -- The output file of the benchmark report"
@echo " TEST_CASE_TIMEOUT -- Timeout for individual tests. Default unit: s"
@echo
@echo "Available commands:"
@echo " hoogle -- Start local hoogle"
@echo " format -- Format the project"
Expand All @@ -20,55 +39,63 @@ usage:
@echo " ps_bridge -- Generate purescript bridge files"
@echo " bench -- Generate bench report bench.csv"
@echo " bench_check -- Check if bench report is up-to-date"
@echo " scripts -- Export scripts to json files"
@echo " scripts -- Run the agora script server (dev mode)"
@echo " ci -- Run all the CI checks"

requires_nix_shell:
@ [ "$(IN_NIX_SHELL)" ] || echo "The $(MAKECMDGOALS) target must be run from inside a nix shell"
@ [ "$(IN_NIX_SHELL)" ] || (echo " run 'nix develop' first" && false)

hoogle:
hoogle: requires_nix_shell
pkill hoogle || true
hoogle generate --local=haddock --database=hoo/local.hoo
hoogle server --local -p 8081 >> /dev/null &
hoogle server --local --database=hoo/local.hoo -p 8082 >> /dev/null &

format: format_haskell format_nix

format_nix:
git ls-tree -r HEAD --full-tree --name-only | grep -E '.*\.nix' | xargs nixpkgs-fmt
format_nix: requires_nix_shell
nixpkgs-fmt $(NIX_SOURCES)

FORMAT_EXTENSIONS := -o -XQuasiQuotes -o -XTemplateHaskell -o -XTypeApplications -o -XImportQualifiedPost -o -XPatternSynonyms -o -XOverloadedRecordDot
format_haskell:
find -name '*.hs' -not -path './dist-*/*' | xargs fourmolu $(FORMAT_EXTENSIONS) -m inplace
git ls-tree -r HEAD --full-tree --name-only | grep -E '.*\.cabal' | xargs cabal-fmt -i
format_haskell: requires_nix_shell
fourmolu $(FORMAT_EXTENSIONS) -m inplace $(HASKELL_SOURCES)
cabal-fmt -i $(CABAL_SOURCES)

format_check:
find -name '*.hs' \
-not -path './dist*/*' \
-not -path './haddock/*' \
| xargs fourmolu $(FORMAT_EXTENSIONS) -m check
format_check: requires_nix_shell
fourmolu $(FORMAT_EXTENSIONS) -m check $(HASKELL_SOURCES)
nixpkgs-fmt --check $(NIX_SOURCES)
cabal-fmt --check $(CABAL_SOURCES)

haddock:
haddock: requires_nix_shell
cabal haddock --haddock-html --haddock-hoogle --builddir=haddock

tag:
hasktags -x $(AGORA_TARGETS)
tag: requires_nix_shell
hasktags -x $(HASKELL_SOURCES)

lint:
hlint $(AGORA_TARGETS)
lint: requires_nix_shell
hlint $(HLINT_EXTS) $(HASKELL_SOURCES)

PS_BRIDGE_OUTPUT_DIR := agora-purescript-bridge/
ps_bridge:
refactor: requires_nix_shell
for src in $(HASKELL_SOURCES) ; do \
hlint $(HLINT_EXTS) --refactor --refactor-options='-i -s' $$src ;\
done

ps_bridge: requires_nix_shell
cabal run exe:agora-purescript-bridge -- -o $(PS_BRIDGE_OUTPUT_DIR)

bench:
cabal run agora-bench

BENCH_TMPDIR := $(shell mktemp -d)
BENCH_TMPFILE := $(BENCH_TMPDIR)/bench.csv
bench_check:
(cabal run agora-bench -- -o "$(BENCH_TMPFILE)" \
|| $(bench) -o "$(BENCH_TMPFILE)") >> /dev/null
diff bench.csv $(BENCH_TMPFILE) \
|| (echo "bench.csv is outdated"; exit 1)
# TODO: do the clean-up even if `diff` fails.
rm -rf $(BENCH_TMPDIR)

scripts:
cabal run agora-scripts
bench: requires_nix_shell
cabal run agora-bench -- -o $(BENCH_OUTPUT)

bench_check: requires_nix_shell
cabal -v0 new-run agora-bench | diff bench.csv -

scripts: requires_nix_shell
cabal run agora-scripts -- -c

test: requires_nix_shell
cabal test --test-options="--hide-successes -t $(TEST_CASE_TIMEOUT) -j$(THREADS)"

build: requires_nix_shell
cabal build -j$(THREADS)

ci: format_check lint build bench_check test haddock
21 changes: 19 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Agora :classical_building:
![integrate.yaml badge](https://github.com/Liqwid-Labs/agora/actions/workflows/integrate.yaml/badge.svg?branch=master)

Agora is a set of Plutus scripts that compose together to form a governance system.

Expand All @@ -13,14 +12,26 @@ Goals:
Non-goals:

- Agora is not a DAO. It doesn't have tokenomics or even a token. It is simply a library for governance.
- Agora doesn't aim to provide any primitive tools for Plutus that are not governance-specific. For this, see [plutus-extra](https://github.com/Liqwid-Labs/plutus-extra/).
- Agora doesn't aim to provide any primitive tools for Plutus that are not governance-specific. For this, see [liqwid-plutarch-extra](https://github.com/Liqwid-Labs/liqwid-plutarch-extra/).

## Project setup

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).

## `agora-scripts` HTTP export server

To use scripts in a frontend, you can use the `agora-scripts` executable which allows you to query them on-demand.

The CTL repo [`agora-offchain`](https://github.com/mlabs-haskell/agora-offchain) already has the setup prepared for this feature.

In order to run the server, simply run the following command:

```sh
cabal run agora-scripts -- --enable-cors-middleware
```

## Documentation

Documentation for Agora is hosted on Notion. You can find the specs [here](https://liqwid.notion.site/e85c09d2c9a542b19aac8dd3d6caa98b?v=d863219cd6a14082a661c4959cabd6e7).
Expand Down Expand Up @@ -55,3 +66,9 @@ Please read [CONTRIBUTING.md](./CONTRIBUTING.md). Additionally, please follow th

- [ ] Rewards distribution
- [ ] Escrow staking pool solution

### Available support channels info

You can find help, more information and ongoing discusion about the project here:

- The [Agora & Liqwid Libs Discord](https://discord.gg/yGkjxrYueB) - Most Agora discussion happens here.
1 change: 0 additions & 1 deletion agora-bench/Bench.hs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import Data.ByteString.Short qualified as SBS
import Data.Csv (DefaultOrdered, ToNamedRecord, header, headerOrder, namedRecord, toNamedRecord, (.=))
import Data.List (intercalate)
import Data.Text (Text, pack)
import GHC.Generics (Generic)
import Plutarch.Evaluate (evalScript)
import PlutusLedgerApi.V1 (
ExBudget (ExBudget),
Expand Down
18 changes: 13 additions & 5 deletions agora-bench/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@ module Main (main) where
import Bench (specificationTreeToBenchmarks)
import Data.Csv (EncodeOptions (encUseCrLf), defaultEncodeOptions, encodeDefaultOrderedByNameWith)
import Data.Text.Lazy.Encoding (decodeUtf8)
import Data.Text.Lazy.IO as I (writeFile)
import Data.Text.Lazy.IO as I (putStr, writeFile)
import Options (Options (..), parseOptions)
import Prettyprinter (defaultLayoutOptions, layoutPretty, pretty)
import Prettyprinter.Render.String (renderString)
import Prettyprinter.Render.Text (renderLazy)
import Spec.AuthorityToken qualified as AuthorityToken
import Spec.Effect.GovernorMutation qualified as GovernorMutation
import Spec.Effect.TreasuryWithdrawal qualified as TreasuryWithdrawal
import Spec.Governor qualified as Governor
import Spec.Proposal qualified as Proposal
import Spec.Stake qualified as Stake
import Spec.Treasury qualified as Treasury
import System.IO (hIsTerminalDevice, stdout)
import Test.Specification (group)
import Prelude

Expand All @@ -22,11 +23,14 @@ import Prelude
main :: IO ()
main = do
options <- parseOptions
isTTY <- hIsTerminalDevice stdout

I.writeFile options.output $
(decodeUtf8 . encodeDefaultOrderedByNameWith encodeOptions) res
mapM_ (`I.writeFile` csv) options.output

mapM_ (putStrLn . renderString . layoutPretty defaultLayoutOptions . pretty) res
I.putStr $
if isTTY
then prettified
else csv
where
encodeOptions =
defaultEncodeOptions
Expand All @@ -49,3 +53,7 @@ main = do
, group "AuthorityToken" AuthorityToken.specs
, group "Governor" Governor.specs
]

csv = decodeUtf8 $ encodeDefaultOrderedByNameWith encodeOptions res

prettified = renderLazy $ layoutPretty defaultLayoutOptions $ pretty res
Loading

0 comments on commit 4eb5fe2

Please sign in to comment.