diff --git a/.gitignore b/.gitignore index 666d8d1ba..dc7ec084a 100644 --- a/.gitignore +++ b/.gitignore @@ -10,6 +10,9 @@ node_modules # production /build +bundles +dist +*.out # misc .DS_Store @@ -63,6 +66,5 @@ agoric/_agstate/yarn-links/ .vscode/ frontend/src/service/conf/defaults.js frontend/src/service/conf/defaults.js -agoric/contract/src/proposal/chain-storage-proposal.js-clean.js agoric/Makefile.paths.local diff --git a/README.md b/README.md index 045ce9b94..1a2e674d6 100644 --- a/README.md +++ b/README.md @@ -87,3 +87,25 @@ To run the application for more than one user follow these steps: 3. `yarn start` 4. Navigate to `localhost:3000` on each session and approve the app in both wallets 10. Enjoy! + + + +## to start up the backend on a local chain + +1. Start the chain + 1. make local-testnet +2. Update KEPLR_ADDRESS in Makefile.paths + 1. try to make the committee below, but it'll give you an aswer that some account doesn't exist + 2. copy that address into Makefile.paths.local +3. fund the account + 1. make fund-account +4. make the committee + 1. make kread-committee +5. provision the fee collector wallet + 1. make provision-fee-collector +6. start the KREAd contract + 1. make clean start-kread + +To confirm it started, +- in chain log you should see "CONTRACT INIT SUCCESS" +- after that `agd query vstorage children published` should include "kread" diff --git a/agoric/Makefile b/agoric/Makefile index 1a3313e94..d25f90212 100644 --- a/agoric/Makefile +++ b/agoric/Makefile @@ -1,16 +1,26 @@ +# accounts based on mnemonics in mn2-start.test.js +ROYALTY_ADDRESS=agoric1yjc8llu3fugm7tgqye4rd5n92l9x2dhe30dazp +PLATFORM_ADDRESS=agoric1enwuyn2hzyyvt39x87tk9rhlkpqtyv9haj7mgs +COMMITTEE_ADDRESSES='{"kgov1": "agoric1890064p6j3xhzzdf8daknd6kpvhw766ds8flgw", "kgov2": "agoric1vqm5x5sj4lxmj2kem7x92tuhaum0k2yzyj6mgu"}' +COMMITTEE_NAME=kread-gov + +# config options +KREAD_REPO = SDK_PATH = -COSMIC_SWINGSET_PATH = -VATS_PATH = KEPLR_ADDRESS = -KEPLR_ADDRESS2 = -FEE_ADDRESS = agoric1d33wj6vgjfdaefs6qzda8np8af6qfdzc433dsu -KREAD_REPO = -EVAL_PERMIT = -EVAL_CODE = -EVAL_CLEAN = - include Makefile.paths.local +COSMIC_SWINGSET_PATH = $(SDK_PATH)/packages/cosmic-swingset +VATS_PATH = $(SDK_PATH)/packages/vats + +EVAL_PERMIT = $(KREAD_REPO)/agoric/contract/src/proposal/powers.json +EVAL_CODE = $(KREAD_REPO)/agoric/contract/src/proposal/chain-storage-proposal.js +EVAL_CLEAN = $(EVAL_CODE)-clean.js +AG_DIR = $(KREAD_REPO)/agoric +PROP_DIR = $(AG_DIR)/contract/src/proposal + +NEXT_PROPOSAL=$$((`agd query gov proposals --output json | jq -cr '.proposals[-1] | [.proposal_id][0]'`+1)) + chain-reset: agoric start local-chain --reset --verbose @@ -38,6 +48,62 @@ wallet1: deploy: agoric deploy contract/kread-deploy-contract.js api/kread-deploy-api.js +dist/.keep dist/bundles/.keep: + mkdir -p dist/bundles + touch dist/.keep dist/bundles/.keep + @echo bundles will actually be stored in $(PWD)/dist/bundles + rm -rf $(HOME)/.agoric/cache + ln -s $(PWD)/dist/bundles $(HOME)/.agoric/cache + +build-proposals: dist/kread-committee-info.json dist/start-kread-info.json + +dist/kread-invite-committee-permit.json dist/kread-invite-committee.js dist/kread-committee-info.json: dist/.keep \ + contract/src/proposal/kread-committee-script.js + cd dist && \ + KREAD_COMMITTEE_ADDRESSES=$(COMMITTEE_ADDRESSES) \ + KREAD_COMMITTEE_NAME=$(COMMITTEE_NAME) \ + agoric run ../contract/src/proposal/kread-committee-script.js >kread-committee-info.txt + node contract/scripts/parseProposals.js dist/kread-committee-info.json \ + || rm dist/kread-committee-info.json + +dist/start-kread-permit.json dist/start-kread.js dist/start-kread-info.json: dist/.keep \ + contract/src/proposal/start-kread-script.js + cd dist && \ + KREAD_ROYALTY_ADDRESS=$(ROYALTY_ADDRESS) \ + KREAD_PLATFORM_ADDRESS=$(PLATFORM_ADDRESS) \ + agoric run ../contract/src/proposal/start-kread-script.js >start-kread-info.txt + node contract/scripts/parseProposals.js dist/start-kread-info.json \ + || rm dist/start-kread-info.json + +clean: + rm -rf dist + +# To start the KREAd contract: +# 1. start the chain using `make local-testnet' +# 2. TBD ... update KEPLR_ADDRESS in Makefile.paths +# 3. fund the account using `make fund-account` +# 4. make the committee using 'KREAD_COMMITTEE_NAME='kread' KREAD_COMMITTEE_ADDRESSES='{"voter": "agoric1ersatz"}' make kread-committee' +# 5. make provision-fee-collector +# 6. start the KREAd contract using 'KREAD_COMMITTEE_NAME='kread' KREAD_COMMITTEE_ADDRESSES='{"voter": "agoric1ersatz"}' make start-kread' + +kread-committee: dist/kread-committee-info.json + jq -r '.bundles[]' dist/kread-committee-info.json | sort -u > kread-committee-bundles.out + for b in `cat kread-committee-bundles.out` ; do \ + agoric publish --node 127.0.0.1:26657 $$b --chain-id agoriclocal --home $(COSMIC_SWINGSET_PATH)/t1/8000 ; \ + done + cd $(COSMIC_SWINGSET_PATH); \ + make scenario2-core-eval EVAL_PERMIT=$(AG_DIR)/dist/kread-invite-committee-permit.json \ + EVAL_CODE=$(AG_DIR)/dist/kread-invite-committee.js EVAL_CLEAN=$(AG_DIR)/dist/kread-invite-committee.js.t scenario2-vote VOTE_PROPOSAL=$(NEXT_PROPOSAL) \ + +start-kread: dist/start-kread-info.json + jq -r '.bundles[]' dist/start-kread-info.json | sort -u > start-kread-bundles.out + for b in `cat start-kread-bundles.out` ; do \ + agoric publish --node 127.0.0.1:26657 $$b --chain-id agoriclocal --home $(COSMIC_SWINGSET_PATH)/t1/8000 ; \ + done + cd $(COSMIC_SWINGSET_PATH); \ + make scenario2-core-eval EVAL_PERMIT=$(AG_DIR)/dist/start-kread-permit.json \ + EVAL_CODE=$(AG_DIR)/dist/start-kread.js EVAL_CLEAN=$(AG_DIR)/dist/start-kread.js.t scenario2-vote VOTE_PROPOSAL=$(NEXT_PROPOSAL) \ + kread-bundle: cd $(VATS_PATH); \ yarn bundle-source --cache-json bundles/ ${KREAD_REPO} kread; \ @@ -63,7 +129,7 @@ provision-fee-collector: fund-account: cd $(COSMIC_SWINGSET_PATH); \ make fund-acct ACCT_ADDR=$(KEPLR_ADDRESS) FUNDS=1000000000000uist; \ - make fund-acct ACCT_ADDR=$(KEPLR_ADDRESS) FUNDS=1000000000000ubld; \ + make fund-acct ACCT_ADDR=$(KEPLR_ADDRESS) FUNDS=1000000000000ubld; \ fund-pool: cd $(COSMIC_SWINGSET_PATH); \ @@ -73,23 +139,15 @@ fund-account-atom: cd $(COSMIC_SWINGSET_PATH); \ make fund-acct ACCT_ADDR=$(KEPLR_ADDRESS) FUNDS=100000000ibc/toyatom; \ -proposal: - cd $(COSMIC_SWINGSET_PATH); \ - make scenario2-core-eval EVAL_PERMIT=$(EVAL_PERMIT) EVAL_CLEAN=$(EVAL_CLEAN) scenario2-vote \ - -proposal-2: - cd $(COSMIC_SWINGSET_PATH); \ - make scenario2-core-eval EVAL_PERMIT=$(EVAL_PERMIT) EVAL_CLEAN=$(EVAL_CLEAN) scenario2-vote VOTE_PROPOSAL=2 \ - # note if you made changes to the contract code you must # copy the resulting hash from kread-bundle into the proposal # before running make proposal bootstrap: make provision-account; \ - make fund-account; \ + make fund-account; \ make kread-bundle; \ make proposal; \ fund+provision: make provision-account; \ - make fund-account; \ + make fund-account; \ diff --git a/agoric/Makefile.paths b/agoric/Makefile.paths index 5969f0ea9..f8873c3b6 100644 --- a/agoric/Makefile.paths +++ b/agoric/Makefile.paths @@ -1,9 +1,5 @@ SDK_PATH = /Users/carlostrigo/kryha/agoric/agoric-sdk -COSMIC_SWINGSET_PATH = /Users/carlostrigo/kryha/agoric/agoric-sdk/packages/cosmic-swingset -VATS_PATH = /Users/carlostrigo/kryha/agoric/agoric-sdk/packages/vats -KEPLR_ADDRESS = agoric1tq3v943uaycqp90qvuyaqzwdc3eh52xzrcl4p6 -KEPLR_ADDRESS2 = agoric1tq3v943uaycqp90qvuyaqzwdc3eh52xzrcl4p6 KREAD_REPO = /Users/carlostrigo/kryha/agoric/code/Agoric/agoric/contract/src/index.js -EVAL_PERMIT = /Users/carlostrigo/kryha/agoric/code/Agoric/agoric/contract/src/proposal/powers.json -EVAL_CODE = /Users/carlostrigo/kryha/agoric/code/Agoric/agoric/contract/src/proposal/chain-storage-proposal.js -EVAL_CLEAN = $(EVAL_CODE)-clean.js \ No newline at end of file + +# changes by making scenario2 +KEPLR_ADDRESS = agoric10s7qs6cznnmswahwzh9lak6pac6we5k86qvnt8 diff --git a/agoric/README.md b/agoric/README.md index 99e58d8f1..ae015c3a3 100644 --- a/agoric/README.md +++ b/agoric/README.md @@ -1,42 +1,46 @@ # KREAd deploy steps -To succesfully run the below steps making use of the makefile, it is important to have a local file `Makefile.paths.local` filled in with the required paths and addresses, an example can be found in `Makefile.paths`. +To succesfully run the below steps making use of the makefile, it is important to have a local file `Makefile.paths.local` filled in with the required paths and addresses, an example can be found in `Makefile.paths`. Steps to run: - ensure you are in the agoric folder otherwise cd to agoric folder +ensure you are in the agoric folder otherwise cd to agoric folder + ```sh cd agoric ``` -run agoric install +get the dependencies for current Mainnet: + ```sh -agoric install +agoric install agoric-upgrade-11 ``` run chain from: + ```sh make local-testnet ``` run client for chain: + ```sh make client-local-testnet ``` create kread-bundle and publish it to chain (this step requires the `client-local-testnet` otherwise it has no address to bundle and publish from): + ```sh make kread-bundle ``` -provision the account that is in the core eval proposal ('agoric1d33wj6vgjfdaefs6qzda8np8af6qfdzc433dsu') +provision the account that is in the core eval proposal + ```sh make provision-fee-collector ``` - -Copy the bundle id returned from the previous step into `chain-storage-proposal.js` (located it `agoric/contract/src/proposal`) it's on line 346, `b1-YOUR_NEW_STRING` - create and vote on proposal + ```sh make proposal ``` @@ -44,6 +48,7 @@ make proposal The proposal logs some board_id information to chain-logs which can be used to verify it ran correctly. Vstorage should contain the following after startup: + - kread bundle in bundles - kread instance in agoricNames/instances - KREAdCHARACTER and KREAdITEM brands in agoricNames/brands diff --git a/agoric/_agstate/agoric-servers/package.json b/agoric/_agstate/agoric-servers/package.json index 8cdd971a0..78ca33347 100644 --- a/agoric/_agstate/agoric-servers/package.json +++ b/agoric/_agstate/agoric-servers/package.json @@ -12,6 +12,6 @@ "author": "Agoric", "license": "Apache-2.0", "dependencies": { - "@agoric/cosmic-swingset": "@agoric/ertp" + "@agoric/cosmic-swingset": "agoric-upgrade-11" } } diff --git a/agoric/contract/.eslintrc.json b/agoric/contract/.eslintrc.json new file mode 100644 index 000000000..088647b61 --- /dev/null +++ b/agoric/contract/.eslintrc.json @@ -0,0 +1,47 @@ +{ + "env": { + "browser": true, + "es2021": true + }, + "extends": [ + "@agoric", + "eslint:recommended", + "plugin:@typescript-eslint/recommended", + "plugin:import/recommended" + ], + "parser": "@typescript-eslint/parser", + "parserOptions": { + "ecmaFeatures": { + "jsx": true + }, + "ecmaVersion": 12, + "sourceType": "module" + }, + "plugins": [ + "@typescript-eslint" + ], + "rules": { + // used for noting unhandled promises + "no-void": "off", + // mostly stylistic + "import/order": "off", + // mostly stylistic + "github/array-foreach": "off", + "@typescript-eslint/no-unused-vars": [ + "warn", + { + "argsIgnorePattern": "^_", + "varsIgnorePattern": "^_", + "caughtErrorsIgnorePattern": "^_" + } + ], + "@typescript-eslint/no-empty-interface": "warn", + "@typescript-eslint/explicit-module-boundary-types": "off", + "import/newline-after-import": [ + "error", + { + "count": 1 + } + ] + } +} diff --git a/agoric/contract/package.json b/agoric/contract/package.json index 857990539..53b05aa82 100644 --- a/agoric/contract/package.json +++ b/agoric/contract/package.json @@ -1,5 +1,5 @@ { - "name": "KREAd-contract", + "name": "kread-contract", "version": "0.1.0", "private": true, "description": "Contract for the KREAd nested NFTs", @@ -15,6 +15,7 @@ }, "devDependencies": { "ava": "^4.3.1", + "@agoric/internal": "agoric-upgrade-11", "@endo/eslint-plugin": "^0.4.4", "@jessie.js/eslint-plugin": "^0.4.0", "eslint": "^8.47.0", @@ -30,18 +31,22 @@ "prettier": "^2.2.1" }, "dependencies": { - "@agoric/assert": "beta", + "@agoric/assert": "agoric-upgrade-11", "@agoric/babel-parser": "^7.6.4", - "@agoric/deploy-script-support": "beta", - "@agoric/ertp": "beta", + "@agoric/deploy-script-support": "agoric-upgrade-11", + "@agoric/ertp": "agoric-upgrade-11", + "@agoric/governance": "agoric-upgrade-11", "@agoric/nat": "dev", - "@agoric/notifier": "beta", - "@agoric/store": "beta", - "@agoric/vat-data": "^0.5.2", - "@agoric/zoe": "beta", - "@agoric/vats": "beta", + "@agoric/notifier": "agoric-upgrade-11", + "@agoric/store": "agoric-upgrade-11", + "@agoric/time": "agoric-upgrade-11", + "@agoric/vat-data": "agoric-upgrade-11", + "@agoric/zoe": "agoric-upgrade-11", + "@agoric/zone": "agoric-upgrade-11", + "@agoric/vats": "agoric-upgrade-11", "@endo/bundle-source": "^2.1.1", "@endo/eventual-send": "^0.14.8", + "@endo/far": "^0.2.18", "@endo/init": "^0.5.37", "@endo/marshal": "^0.6.9", "@endo/ses-ava": "^0.2.40", @@ -56,11 +61,6 @@ "keywords": [], "author": "Kryha", "license": "Apache-2.0", - "eslintConfig": { - "extends": [ - "@agoric" - ] - }, "prettier": { "trailingComma": "all", "singleQuote": true @@ -68,7 +68,6 @@ "eslintIgnore": [ "characters.js", "items.js", - "chain-storage-proposal.js", - "chain-storage-proposal.js-clean.js" + "*-clean.js" ] } diff --git a/agoric/contract/scripts/parseProposals.js b/agoric/contract/scripts/parseProposals.js new file mode 100755 index 000000000..fbba9b0b3 --- /dev/null +++ b/agoric/contract/scripts/parseProposals.js @@ -0,0 +1,41 @@ +#!/usr/bin/env node +/* global process */ +import fs from 'fs'; + +const Fail = (template, ...args) => { + throw Error(String.raw(template, ...args.map((val) => String(val)))); +}; + +/** + * Parse output of `agoric run proposal-builder.js` + * + * @param {string} txt + * + * adapted from packages/boot/test/bootstrapTests/supports.js + */ +const parseProposalParts = (txt) => { + const evals = [ + ...txt.matchAll(/swingset-core-eval (?\S+) (?