Skip to content

Commit

Permalink
interim debugging tests, endo/patterns dep issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Jovonni committed Jun 5, 2024
1 parent 1d62e04 commit 01b8362
Show file tree
Hide file tree
Showing 19 changed files with 1,167 additions and 673 deletions.
80 changes: 3 additions & 77 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,81 +1,7 @@
# Simple Voting DAO Contract on Agoric
# Simple Agoric ORChAstration Template

<img src="./images/sequence-diagram.png" width="100%" />
<img src="./images/orca.png" width="100%" />

## Overview

This simple voting DAO contract is designed to manage decentralized governance through proposals and voting. It utilizes ERTP (Electronic Rights Transfer Protocol) for handling and verifying digital assets within the smart contract.

## Features

- **Token Minting**: The contract mints its own DAO tokens and Membership NFTs which are used to manage membership and voting rights.
- **Proposal Management**: Members can create basic governance proposals which are then voted on by token holders.
- **Voting System**: Uses DAO tokens to cast votes on proposals. Members can vote 'for' or 'against' each proposal.

## Contract API

### Setup and Initial Minting

- Tokens (DAO and Membership) are minted when the contract starts.
- Initial tokens are allocated to the first seat (contract initiator).

Tokens (DAO and Membership) are minted when the contract starts. Initial tokens are allocated to the first seat (contract initiator):
```javascript
daoTokenMint.mintGains({DaoTokens: {brand: daoTokenBrand, value: initialDaoTokens}});
```

### Creating Proposals

- `createProposal(title, details)`: Creates a new proposal and returns a unique identifier for the proposal.
```javascript
const proposalId = createProposal('Example Proposal Title', 'Example Proposal Description');
```

### Joining the DAO

- `makeJoinInvitation()`: Returns an invitation that can be used to join the DAO. When used, it mints a new Membership NFT and allocates a specified amount of DAO tokens to the new member.

```javascript
const joinInvitation = makeJoinInvitation();
```

### Voting on Proposals

- `makeVoteInvitation()`: Returns an invitation to vote on a proposal.

```javascript
const voteInvitation = makeVoteInvitation();
```

- `vote(voterSeat, { proposalId, voteFor })`: Casts a vote for or against a proposal identified by `proposalId`. The voter must have a Membership NFT and enough DAO tokens to participate. The proposal's ID must be exist in the contracts state.

```javascript
vote(voterSeat, { proposalId: 1, voteFor: true });
```

## Technical Details

### Contract Code Structure

1. **Token Minting**: Separate mints for DAO tokens (fungible) and Membership NFTs (non-fungible).
2. **Proposal Handling**: Proposals are stored in a Map, with methods to create and retrieve proposals.
3. **Voting Mechanics**: Voting checks token holdings and updates proposal records with votes cast.

## Test Setup

Simple tests cover:

- Contract installation and setup.
- Joining the DAO.
- Creating a proposal.
- Voting on a proposal.

Each test checks on token balances and proposal outcomes after operations are executed.

### Running Tests

```bash
yarn install
yarn build
yarn test
```
Lorem
1 change: 1 addition & 0 deletions contract/,tx.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"height":"1007","txhash":"13E7554F159251539A014512706124416E5A14781CB4C64497F0BB137372CF96","codespace":"","code":0,"data":"12260A242F636F736D6F732E62616E6B2E763162657461312E4D736753656E64526573706F6E7365","raw_log":"[{\"msg_index\":0,\"events\":[{\"type\":\"coin_received\",\"attributes\":[{\"key\":\"receiver\",\"value\":\"agoric1rwwley550k9mmk6uq6mm6z4udrg8kyuyvfszjk\"},{\"key\":\"amount\",\"value\":\"1000000000ibc/BA313C4A19DFBF943586C0387E6B11286F9E416B4DD27574E6909CABE0E342FA\"}]},{\"type\":\"coin_spent\",\"attributes\":[{\"key\":\"spender\",\"value\":\"agoric1estsewt6jqsx77pwcxkn5ah0jqgu8rhgflwfdl\"},{\"key\":\"amount\",\"value\":\"1000000000ibc/BA313C4A19DFBF943586C0387E6B11286F9E416B4DD27574E6909CABE0E342FA\"}]},{\"type\":\"message\",\"attributes\":[{\"key\":\"action\",\"value\":\"/cosmos.bank.v1beta1.MsgSend\"},{\"key\":\"sender\",\"value\":\"agoric1estsewt6jqsx77pwcxkn5ah0jqgu8rhgflwfdl\"},{\"key\":\"module\",\"value\":\"bank\"}]},{\"type\":\"transfer\",\"attributes\":[{\"key\":\"recipient\",\"value\":\"agoric1rwwley550k9mmk6uq6mm6z4udrg8kyuyvfszjk\"},{\"key\":\"sender\",\"value\":\"agoric1estsewt6jqsx77pwcxkn5ah0jqgu8rhgflwfdl\"},{\"key\":\"amount\",\"value\":\"1000000000ibc/BA313C4A19DFBF943586C0387E6B11286F9E416B4DD27574E6909CABE0E342FA\"}]}]}]","logs":[{"msg_index":0,"log":"","events":[{"type":"coin_received","attributes":[{"key":"receiver","value":"agoric1rwwley550k9mmk6uq6mm6z4udrg8kyuyvfszjk"},{"key":"amount","value":"1000000000ibc/BA313C4A19DFBF943586C0387E6B11286F9E416B4DD27574E6909CABE0E342FA"}]},{"type":"coin_spent","attributes":[{"key":"spender","value":"agoric1estsewt6jqsx77pwcxkn5ah0jqgu8rhgflwfdl"},{"key":"amount","value":"1000000000ibc/BA313C4A19DFBF943586C0387E6B11286F9E416B4DD27574E6909CABE0E342FA"}]},{"type":"message","attributes":[{"key":"action","value":"/cosmos.bank.v1beta1.MsgSend"},{"key":"sender","value":"agoric1estsewt6jqsx77pwcxkn5ah0jqgu8rhgflwfdl"},{"key":"module","value":"bank"}]},{"type":"transfer","attributes":[{"key":"recipient","value":"agoric1rwwley550k9mmk6uq6mm6z4udrg8kyuyvfszjk"},{"key":"sender","value":"agoric1estsewt6jqsx77pwcxkn5ah0jqgu8rhgflwfdl"},{"key":"amount","value":"1000000000ibc/BA313C4A19DFBF943586C0387E6B11286F9E416B4DD27574E6909CABE0E342FA"}]}]}],"info":"","gas_wanted":"93980","gas_used":"75297","tx":null,"timestamp":"","events":[{"type":"tx","attributes":[{"key":"ZmVl","value":"","index":true},{"key":"ZmVlX3BheWVy","value":"YWdvcmljMWVzdHNld3Q2anFzeDc3cHdjeGtuNWFoMGpxZ3U4cmhnZmx3ZmRs","index":true}]},{"type":"tx","attributes":[{"key":"YWNjX3NlcQ==","value":"YWdvcmljMWVzdHNld3Q2anFzeDc3cHdjeGtuNWFoMGpxZ3U4cmhnZmx3ZmRsLzU3","index":true}]},{"type":"tx","attributes":[{"key":"c2lnbmF0dXJl","value":"Vks3cTlTN09BSUt3eEhnNnhyR2p6WEwvcGNiWUZQTlBITmd0Z0draVBnZzZSaDY2bXljVFA3M2traERmTzhuMVFkajB4TEh2WnhWekpjWTRZcTRaekE9PQ==","index":true}]},{"type":"message","attributes":[{"key":"YWN0aW9u","value":"L2Nvc21vcy5iYW5rLnYxYmV0YTEuTXNnU2VuZA==","index":true}]},{"type":"coin_spent","attributes":[{"key":"c3BlbmRlcg==","value":"YWdvcmljMWVzdHNld3Q2anFzeDc3cHdjeGtuNWFoMGpxZ3U4cmhnZmx3ZmRs","index":true},{"key":"YW1vdW50","value":"MTAwMDAwMDAwMGliYy9CQTMxM0M0QTE5REZCRjk0MzU4NkMwMzg3RTZCMTEyODZGOUU0MTZCNEREMjc1NzRFNjkwOUNBQkUwRTM0MkZB","index":true}]},{"type":"coin_received","attributes":[{"key":"cmVjZWl2ZXI=","value":"YWdvcmljMXJ3d2xleTU1MGs5bW1rNnVxNm1tNno0dWRyZzhreXV5dmZzempr","index":true},{"key":"YW1vdW50","value":"MTAwMDAwMDAwMGliYy9CQTMxM0M0QTE5REZCRjk0MzU4NkMwMzg3RTZCMTEyODZGOUU0MTZCNEREMjc1NzRFNjkwOUNBQkUwRTM0MkZB","index":true}]},{"type":"transfer","attributes":[{"key":"cmVjaXBpZW50","value":"YWdvcmljMXJ3d2xleTU1MGs5bW1rNnVxNm1tNno0dWRyZzhreXV5dmZzempr","index":true},{"key":"c2VuZGVy","value":"YWdvcmljMWVzdHNld3Q2anFzeDc3cHdjeGtuNWFoMGpxZ3U4cmhnZmx3ZmRs","index":true},{"key":"YW1vdW50","value":"MTAwMDAwMDAwMGliYy9CQTMxM0M0QTE5REZCRjk0MzU4NkMwMzg3RTZCMTEyODZGOUU0MTZCNEREMjc1NzRFNjkwOUNBQkUwRTM0MkZB","index":true}]},{"type":"message","attributes":[{"key":"c2VuZGVy","value":"YWdvcmljMWVzdHNld3Q2anFzeDc3cHdjeGtuNWFoMGpxZ3U4cmhnZmx3ZmRs","index":true}]},{"type":"message","attributes":[{"key":"bW9kdWxl","value":"YmFuaw==","index":true}]}]}
16 changes: 12 additions & 4 deletions contract/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ vote:
instance-q:
agd query vstorage data published.agoricNames.instance -o json

start-contract: start-contract-dao
start-contract: start-contract-orca

start-contract-dao:
start-contract-orca:
yarn node scripts/deploy-contract.js \
--install src/dao.contract.js \
--install src/orca.contract.js \
--eval src/platform-goals/board-aux.core.js \
--eval src/dao.proposal.js
--eval src/orca.proposal.js

# bundle-X.json.installed show that bundle-X.json was installed
# see also e2e-tools.js
Expand All @@ -87,3 +87,11 @@ bundles/deploy-swaparoo.js: src/swaparoo.proposal.js

clean:
@rm -rf bundles/

# yarn links for local @agoric/orchestrate, @agoric/vow, @agoric/vats
yl:
yarn link @agoric/orchestration ; yarn link @agoric/vow; yarn link @agoric/vats; yarn link @agoric/swingset-liveslots; yarn link @agoric/cosmic-proto; yarn link @agoric/time; yarn link @agoric/store; yarn link @endo/patterns;

# ln -s ../../agoric-sdk/packages/sharing-service node_modules/@agoric/sharing-service;
ss:
yarn add https://registry.npmjs.org/@agoric/sharing-service/-/sharing-service-0.2.12-u14.0.tgz
149 changes: 127 additions & 22 deletions contract/jsconfig.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,130 @@
// This file can contain .js-specific Typescript compiler config.
{
"compilerOptions": {
"target": "esnext",
"module": "ES2022",

"noEmit": true,
/*
// The following flags are for creating .d.ts files:
"noEmit": false,
"declaration": true,
"emitDeclarationOnly": true,
*/
"downlevelIteration": true,
"strictNullChecks": true,
"moduleResolution": "node"
},
"include": [
"src/**/*.js",
"test/**/*.js",
"tools/**/*.js",
"exported.js",
"globals.d.ts"
"name": "orca-contract",
"version": "0.1.0",
"private": true,
"description": "Agoric Orchestration Contract Templates",
"type": "module",
"scripts": {
"start:docker": "docker compose up -d",
"docker:logs": "docker compose logs --tail 200 -f",
"docker:bash": "docker compose exec agd bash",
"docker:make": "docker compose exec agd make -C /workspace/contract",
"make:help": "make list",
"start": "make clean start-contract",
"build": "yarn build:deployer",
"build:deployer": "node --preserve-symlinks ./node_modules/.bin/rollup -c rollup.config.mjs",
"test": "node --preserve-symlinks ./node_modules/.bin/ava --verbose",
"lint": "eslint '**/*.js'",
"lint:types": "tsc -p jsconfig.json",
"lint:fix": "eslint --fix '**/*.js'"
},
"devDependencies": {
"@agoric/deploy-script-support": "^0.10.4-u14.0",
"@agoric/eslint-config": "dev",
"@agoric/smart-wallet": "0.5.4-u14.0",
"@agoric/store": "0.9.3-dev-0f12662.0",
"@agoric/xsnap": "0.14.3-u14.0",
"@agoric/zone": "0.2.3-u14.0",
"@endo/eslint-plugin": "^0.5.2",
"@endo/nat": "^4.1.27",
"@endo/promise-kit": "0.2.56",
"@endo/ses-ava": "^1.4.0",
"@jessie.js/eslint-plugin": "^0.4.0",
"@rollup/plugin-commonjs": "^25.0.8",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-node-resolve": "^15.2.3",
"@rollup/plugin-replace": "^5.0.5",
"@typescript-eslint/eslint-plugin": "^6.7.0",
"@typescript-eslint/parser": "^6.7.0",
"agoric": "^0.21.2-u12.0",
"ava": "^5.3.1",
"eslint": "^8.47.0",
"eslint-config-airbnb-base": "^15.0.0",
"eslint-config-jessie": "^0.0.6",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-ava": "^14.0.0",
"eslint-plugin-github": "^4.10.0",
"eslint-plugin-import": "^2.25.3",
"eslint-plugin-jsdoc": "^46.4.3",
"eslint-plugin-prettier": "^5.0.0",
"import-meta-resolve": "^2.2.1",
"prettier": "^3.0.3",
"prettier-plugin-jsdoc": "^1.0.0",
"rollup": "^4.18.0",
"type-coverage": "^2.26.3",
"typescript": "~5.2.2"
},
"dependencies": {
"@agoric/assert": "^0.6.0",
"@agoric/cosmic-proto": "^0.4.1-dev-90906b1.0",
"@agoric/ertp": "^0.16.3-u14.0",
"@agoric/governance": "^0.10.4-u14.0",
"@agoric/inter-protocol": "0.16.2-u14.1",
"@agoric/internal": "^0.3.2",
"@agoric/notifier": "^0.6.2",
"@agoric/store": "0.9.3-dev-0f12662.0",
"@agoric/time": "^0.3.2",
"@agoric/vat-data": "^0.5.2",
"@agoric/zoe": "^0.26.3-u14.0",
"@agoric/zone": "0.2.3-u14.0",
"@endo/base64": "^1.0.5",
"@endo/bundle-source": "^2.5.2-upstream-rollup",
"@endo/far": "^1.1.2",
"@endo/init": "^0.5.60",
"@endo/marshal": "^1.5.0",
"@endo/patterns": "^1.4.0",
"@rollup/plugin-json": "^6.1.0",
"@rollup/plugin-replace": "^5.0.5",
"big-integer": "^1.6.52",
"elliptic": "^6.5.5",
"@agoric/orchestration": "^0.1.0",
"@agoric/vow": "^0.1.0",
"@agoric/vats": "^0.15.1"
},
"ava": {
"extensions": {
"js": true,
"ts": "module"
},
"files": [
"test/**/test-*.*",
"test/**/*.test.*"
],
"nodeArguments": [],
"require": [
"@endo/init/debug.js"
],
"timeout": "20m",
"workerThreads": false
},
"keywords": [],
"repository": {
"type": "git",
"url": "git+https://github.com/Agoric/dapp-agoric-basics"
},
"author": "Agoric",
"license": "Apache-2.0",
"bugs": {
"url": "https://github.com/Agoric/dapp-agoric-basics/issues"
},
"homepage": "https://github.com/Agoric/dapp-agoric-basics#readme",
"eslintConfig": {
"parserOptions": {
"sourceType": "module",
"ecmaVersion": 2021
},
"ignorePatterns": "bundles/**.js",
"extends": [
"@agoric"
]
},
"prettier": {
"trailingComma": "all",
"arrowParens": "avoid",
"singleQuote": true
},
"files": [
"*.js",
"src"
]
}
Loading

0 comments on commit 01b8362

Please sign in to comment.