Skip to content

Commit

Permalink
Merge pull request #17 from Agoric/ta/v1-contract
Browse files Browse the repository at this point in the history
v1 contract
  • Loading branch information
turadg authored Aug 15, 2024
2 parents a2b4e7d + 4101d0b commit 2379c1a
Show file tree
Hide file tree
Showing 21 changed files with 3,075 additions and 864 deletions.
215 changes: 195 additions & 20 deletions contract/Makefile
Original file line number Diff line number Diff line change
@@ -1,19 +1,29 @@
CHAINID=agoriclocal
USER1ADDR=$(shell agd keys show user1 -a --keyring-backend="test")
USER1ADDR=$(shell agd keys show alice -a --keyring-backend="test")
ACCT_ADDR=$(USER1ADDR)
BLD=000000ubld

ATOM_DENOM=ibc/BA313C4A19DFBF943586C0387E6B11286F9E416B4DD27574E6909CABE0E342FA
ATOM=000000$(ATOM_DENOM)

# your deployer address made from make add-address
ADDR=agoric1mqvg26gpv6xzch2v0wpv569md3c2z4cdxq9clz
PROVISION_POOL_ADDR=agoric1megzytg65cyrgzs6fvzxgrcqvwwl7ugpt62346

PROPOSAL=1
VOTE_OPTION=yes

CLIENTADDR=agoric12j5kzvrwunqvrga5vm4zpy3mkeh3lvyld0amz5
CLIENT_OSMO_ADDR=osmo1rhvgsqq96n3qyv3u0zlwleyaunpmal6uhnam4z

.PHONY: list
# https://stackoverflow.com/a/73159833/7963
list:
@make -npq : 2> /dev/null | grep -v PHONY |\
awk -v RS= -F: '$$1 ~ /^[^#%]+$$/ { print $$1 }'

balance-q:
agd keys show user1 -a --keyring-backend="test"
agd keys show alice -a --keyring-backend="test"
agd query bank balances $(ACCT_ADDR)

GAS_ADJUSTMENT=1.2
Expand All @@ -25,18 +35,18 @@ mint100:
make FUNDS=1000$(ATOM) fund-acct
cd /usr/src/agoric-sdk && \
yarn --silent agops vaults open --wantMinted 100 --giveCollateral 100 >/tmp/want-ist.json && \
yarn --silent agops perf satisfaction --executeOffer /tmp/want-ist.json --from user1 --keyring-backend=test
yarn --silent agops perf satisfaction --executeOffer /tmp/want-ist.json --from alice --keyring-backend=test

# Keep mint4k around a while for compatibility
mint4k:
make FUNDS=1000$(ATOM) fund-acct
cd /usr/src/agoric-sdk && \
yarn --silent agops vaults open --wantMinted 4000 --giveCollateral 1000 >/tmp/want4k.json && \
yarn --silent agops perf satisfaction --executeOffer /tmp/want4k.json --from user1 --keyring-backend=test
yarn --silent agops perf satisfaction --executeOffer /tmp/want4k.json --from alice --keyring-backend=test

FUNDS=321$(BLD)
fund-acct:
agd tx bank send validator $(ACCT_ADDR) $(FUNDS) \
agd tx bank send alice $(ACCT_ADDR) $(FUNDS) \
$(SIGN_BROADCAST_OPTS) \
-o json >,tx.json
jq '{code: .code, height: .height}' ,tx.json
Expand All @@ -49,24 +59,19 @@ gov-voting-q:
agd query gov proposals --status=voting_period --output json | \
jq -c '.proposals[].proposal_id'

PROPOSAL=1
VOTE_OPTION=yes
vote:
agd tx gov vote $(PROPOSAL) $(VOTE_OPTION) --from=validator \
# agd tx gov vote $(PROPOSAL) $(VOTE_OPTION) --from=validator
agd tx gov vote $(PROPOSAL) $(VOTE_OPTION) --from=alice \
$(SIGN_BROADCAST_OPTS) \
-o json >,tx.json
jq '{code: .code, height: .height}' ,tx.json

instance-q:
agd query vstorage data published.agoricNames.instance -o json

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


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

# bundle-X.json.installed show that bundle-X.json was installed
# see also e2e-tools.js
Expand All @@ -88,10 +93,180 @@ 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

########################################
########################################
################ Dapp dev
########################################
########################################

# HARD CODED
cpfiles:
kubectl cp bundles/deploy-board-aux-permit.json default/agoriclocal-genesis-0:/root/bundles/deploy-board-aux-permit.json
kubectl cp bundles/deploy-board-aux.js default/agoriclocal-genesis-0:/root/bundles/deploy-board-aux.js
kubectl cp bundles/deploy-orca-permit.json default/agoriclocal-genesis-0:/root/bundles/deploy-orca-permit.json
kubectl cp bundles/deploy-orca.js default/agoriclocal-genesis-0:/root/bundles/deploy-orca.js
kubectl cp bundles/bundle-orca.js default/agoriclocal-genesis-0:/root/bundles/bundle-orca.js
kubectl cp bundles/bundle-list-ship default/agoriclocal-genesis-0:/root/bundles/bundle-list-ship

kubectl cp scripts/build-proposal.sh default/agoriclocal-genesis-0:/root/scripts/build-proposal.sh
kubectl cp scripts/install-bundles.sh default/agoriclocal-genesis-0:/root/scripts/install-bundles.sh
kubectl cp scripts/propose-start-contract.sh default/agoriclocal-genesis-0:/root/scripts/propose-start-contract.sh
kubectl cp ./src/platform-goals/start-contract.js default/agoriclocal-genesis-0:/root/scripts/start-contract.js
kubectl cp scripts/build-contract-deployer.js default/agoriclocal-genesis-0:/root/scripts/build-contract-deployer.js


kubectl cp ./Makefile default/agoriclocal-genesis-0:/root/Makefile
rmfiles:
kubectl exec -i agoriclocal-genesis-0 -c validator -- rm -rf ./bundles/bundle-orca.json
kubectl exec -i agoriclocal-genesis-0 -c validator -- rm -rf ./bundles/deploy-board-aux-permit.json
kubectl exec -i agoriclocal-genesis-0 -c validator -- rm -rf ./bundles/deploy-board-aux.js
kubectl exec -i agoriclocal-genesis-0 -c validator -- rm -rf ./bundles/deploy-orca-permit.json
kubectl exec -i agoriclocal-genesis-0 -c validator -- rm -rf ./bundles/deploy-orca.js

kubectl exec -i agoriclocal-genesis-0 -c validator -- rm -rf ./scripts/build-proposal.sh
kubectl exec -i agoriclocal-genesis-0 -c validator -- rm -rf ./scripts/install-bundles.sh
kubectl exec -i agoriclocal-genesis-0 -c validator -- rm -rf ./scripts/propose-start-contract.sh

kubectl exec -i agoriclocal-genesis-0 -c validator -- rm -rf ./bundles/bundle-list-ship
kubectl exec -i agoriclocal-genesis-0 -c validator -- rm -rf ./Makefile
kubectl exec -i agoriclocal-genesis-0 -c validator -- rm -rf ./bundles/*.json
kubectl exec -i agoriclocal-genesis-0 -c validator -- rm -rf ./bundles/*.js
kubectl exec -i agoriclocal-genesis-0 -c validator -- rm -rf ./scripts/*.js



# 1
fund-provision-pool:
kubectl exec -i agoriclocal-genesis-0 -c validator -- agd tx bank send faucet $(PROVISION_POOL_ADDR) 1000000000uist -y -b block;
sleep 5;

# 2
fund: fund-provision-pool check-balance
make fund-wallet;
make check-balance;
make provision-smart-wallet;
kubectl exec -i agoriclocal-genesis-0 -c validator -- agd tx bank send faucet ${CLIENTADDR} 10000000000000ubld -y;
sleep 5;
kubectl exec -i agoriclocal-genesis-0 -c validator -- agd tx bank send faucet ${CLIENTADDR} 10000000000000uist -y;
make fund-osmo

fund-osmo:
kubectl exec -i osmosislocal-genesis-0 -c validator -- osmosisd tx bank send faucet ${CLIENT_OSMO_ADDR} 9870000000uosmo --fees 1000uosmo -y;
check-balance:
kubectl exec -i agoriclocal-genesis-0 -c validator -- agd q bank balances $(ADDR)
fund-wallet:
kubectl exec -i agoriclocal-genesis-0 -c validator -- agd tx bank send faucet $(ADDR) 10000000000000uist -y -b block
kubectl exec -i agoriclocal-genesis-0 -c validator -- agd tx bank send faucet $(ADDR) 10000000000000ubld -y -b block

provision-smart-wallet:
kubectl exec -i agoriclocal-genesis-0 -c validator -- agd keys list
kubectl exec -i agoriclocal-genesis-0 -c validator -- agd tx swingset provision-one wallet $(ADDR) SMART_WALLET --from ${ADDR} -y -b block

local-provision-smart-wallet:
agd tx swingset provision-one wallet $(ADDR) SMART_WALLET --from $(ADDR) -y -b block --chain-id agoriclocal

fund-dev:
kubectl exec -i agoriclocal-genesis-0 -c validator -- agd tx bank send alice agoric1rwwley550k9mmk6uq6mm6z4udrg8kyuyvfszjk 100000000ubld -y
kubectl exec -i agoriclocal-genesis-0 -c validator -- agd tx bank send alice agoric1rwwley550k9mmk6uq6mm6z4udrg8kyuyvfszjk 100000000uist -y
local-fund:
agd tx bank send faucet $(ADDR) 999999999ubld -y
agd tx bank send faucet $(ADDR) 999999999uist -y
# add address
add-address:
kubectl exec -i agoriclocal-genesis-0 -c validator -- agd keys add alice || true


exec:
kubectl exec -it agoriclocal-genesis-0 -c validator -- bash

# 1
install-bundles:
bash scripts/install-bundles.sh

# copy bundle to container
cpb:
bash scripts/copy-bundles-to-container.sh


copy-project:
kubectl exec -i agoriclocal-genesis-0 -c validator -- rm -rf -v ./*
kubectl exec -i agoriclocal-genesis-0 -c validator -- mkdir -p /root/
kubectl cp . default/agoriclocal-genesis-0:/root/

PROPOSAL_ID=3
propose-start-v2:
make make-proposal-start;
sleep 3;
make proposal-start-vote;
make sleep 3;
make gov-q;

make-proposal-start:
kubectl exec -i agoriclocal-genesis-0 -c validator -- bash -c "make propose-start";
sleep 3; make gov-q

proposal-start-vote:
kubectl exec -i agoriclocal-genesis-0 -c validator -- bash -c "agd tx gov vote ${PROPOSAL_ID} $(VOTE_OPTION) --from=genesis $(SIGN_BROADCAST_OPTS) -o json >,tx.json ; jq '{code: .code, height: .height}' ,tx.json"

# debug bundle
bundle-debug:
bash scripts/bundle-debug.sh

# patch
copy-bn-js:
kubectl exec -i agoriclocal-genesis-0 -c validator -- rm -f -v /root/node_modules/bn.js/lib/bn.js
cp ./PATCH-bn.js ../node_modules/bn.js/lib/bn.js
kubectl cp ../node_modules/bn.js/lib/bn.js default/agoriclocal-genesis-0:/root/node_modules/bn.js/lib/bn.js

copy-vow-js:
cp ./PATCH-vat.js ../node_modules/@agoric/vow/vat.js
kubectl cp ../node_modules/@agoric/vow/vat.js default/agoriclocal-genesis-0:/root/node_modules/@agoric/vow/vat.js

# debug
# kubectl cp ../node_modules/@agoric/vow/vat.js default/agoriclocal-genesis-0:/root/node_modules/@agoric/orchestration/node_modules/@agoric/vow/vat.js
# kubectl cp ../node_modules/@agoric/vow/vat.js default/agoriclocal-genesis-0:/root/node_modules/@agoric/async-flow/node_modules/@agoric/vow/vat.js


# kubectl exec -i agoriclocal-genesis-0 -c validator -- cat /root/node_modules/bn.js/lib/bn.js | grep "PATCH"
patch:
patch ../node_modules/bn.js/lib/bn.js < ../xxpatches/bn.js+5.2.1.patch

cleanc:
kubectl exec -i agoriclocal-genesis-0 -c validator -- bash -c "rm -rf -v ./*"

build:
yarn build:deployer
buildc:
kubectl exec -i agoriclocal-genesis-0 -c validator -- bash -c "yarn build:deployer"
deployc:
kubectl exec -i agoriclocal-genesis-0 -c validator -- bash -c "yarn node scripts/deploy-contract.js --install src/orca.contract.js --eval src/orca.proposal.js"
deploy:
yarn node scripts/deploy-contract.js --install src/orca.contract.js --eval src/orca.proposal.js
test-orca:
yarn test ./test/orca-contract.test.js


# todo remove clean install steps after debugging
e2e:
make clean
make cleanc
yarn cache clean
kubectl exec -i agoriclocal-genesis-0 -c validator -- bash -c "yarn cache clean"
kubectl exec -i agoriclocal-genesis-0 -c validator -- bash -c "rm -rf -v /root/*"
yarn run build:deployer
make copy-project
kubectl exec -i agoriclocal-genesis-0 -c validator -- bash -c "yarn install"
kubectl exec -i agoriclocal-genesis-0 -c validator -- bash -c "yarn add @endo/[email protected]"
kubectl exec -i agoriclocal-genesis-0 -c validator -- bash -c "yarn add @agoric/[email protected]"
kubectl exec -i agoriclocal-genesis-0 -c validator -- bash -c "yarn add @agoric/[email protected]"
kubectl exec -i agoriclocal-genesis-0 -c validator -- bash -c "yarn add @agoric/[email protected]"
make copy-bn-js
kubectl exec -i agoriclocal-genesis-0 -c validator -- bash -c "yarn build:deployer"
kubectl exec -i agoriclocal-genesis-0 -c validator -- bash -c "yarn node scripts/deploy-contract.js --install src/orca.contract.js --eval src/orca.proposal.js"
kubectl exec -i agoriclocal-genesis-0 -c validator -- bash -c "yarn node scripts/deploy-contract.js --install src/orca.contract.js --eval src/orca.proposal.js"
# todo: figure out why this sequence # is always off by 1 forcing a retry

lint:
yarn lint --fix-dry-run --ignore-pattern "*patch*"
26 changes: 26 additions & 0 deletions contract/explode-bundle.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/bash
# Explode the content of an .js bundle into a directory.
# NB: Overwrites the existing directory.
#
# Usage: explode-bundle.sh <bundle.js>

JS_PATH=$1
# verify that the file exists
if [ ! -f "$JS_PATH" ]; then
echo "File not found: $JS_PATH"
exit 1
fi
JSON_PATH="$1on"
BUNDLE_NAME=$(basename "$JS_PATH" .js)
DIR=$(dirname "$JS_PATH")

echo "Exploding $BUNDLE_NAME in $DIR"

sed -n 's/^export default \(.*\);$/\1/p' "$JS_PATH" | jq '.' >"$JSON_PATH"

EXPLODED="$DIR/$BUNDLE_NAME"
rm -rf "$EXPLODED"
mkdir "$EXPLODED"
jq -r .endoZipBase64 <"$JSON_PATH" | base64 -d | tar xC "$EXPLODED"
find "$EXPLODED" -type f -exec du -h {} + | sort -hr >"$EXPLODED"/files.txt
open "$EXPLODED"/files.txt
33 changes: 19 additions & 14 deletions contract/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,20 @@
"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",
"start": "make clean start",
"start2": "make clean start2",
"build2": "yarn build:deployer2",
"build:deployer": "rollup -c rollup.config.mjs",
"build:deployer2": "echo \"deployer2\"; agoric run scripts/build-contract-deployer.js",
"deploy": "make dev-working",
"test": "ava",
"lint": "tsc && eslint '**/*.js'",
"lint:fix": "eslint --fix '**/*.js'"
},
"devDependencies": {
"@agoric/deploy-script-support": "dev",
"@agoric/eslint-config": "dev",
"@agoric/inter-protocol": "dev",
"@agoric/smart-wallet": "dev",
"@agoric/store": "dev",
"@agoric/swingset-liveslots": "dev",
Expand All @@ -30,18 +34,18 @@
"@cosmjs/amino": "^0.32.3",
"@cosmjs/proto-signing": "^0.32.3",
"@endo/eslint-plugin": "^2.2.0",
"@endo/nat": "^4.1.27",
"@endo/promise-kit": "^0.2.56",
"@endo/nat": "^5.0.9",
"@endo/promise-kit": "^1.1.4",
"@endo/ses-ava": "^1.2.4",
"@jessie.js/eslint-plugin": "^0.4.0",
"@jessie.js/eslint-plugin": "^0.4.1",
"@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",
"@rollup/plugin-typescript": "^11.1.6",
"@typescript-eslint/eslint-plugin": "^7.0.2",
"@typescript-eslint/parser": "^7.15.0",
"agoric": "^0.21.2-u12.0",
"agoric": "^0.21.2-upgrade-16-fi-dev-8879538.0",
"ava": "^5.3.1",
"eslint": "^8.57.0",
"eslint-config-airbnb-base": "^15.0.0",
Expand All @@ -68,11 +72,12 @@
"@agoric/vow": "dev",
"@agoric/zoe": "dev",
"@agoric/zone": "dev",
"@endo/bundle-source": "^3.2.3",
"@endo/far": "^1.1.2",
"@endo/init": "^0.5.60",
"@endo/marshal": "^1.5.0",
"@endo/patterns": "^1.4.0"
"@endo/bundle-source": "^3.3.0",
"@endo/errors": "^1.2.4",
"@endo/far": "^1.1.4",
"@endo/init": "^1.1.3",
"@endo/marshal": "^1.5.2",
"@endo/patterns": "^1.4.2"
},
"ava": {
"extensions": {
Expand All @@ -93,14 +98,14 @@
"keywords": [],
"repository": {
"type": "git",
"url": "git+https://github.com/Agoric/dapp-agoric-basics"
"url": "git+https://github.com/Agoric/dapp-orchestration-basics"
},
"author": "Agoric",
"license": "Apache-2.0",
"bugs": {
"url": "https://github.com/Agoric/dapp-agoric-basics/issues"
"url": "https://github.com/Agoric/dapp-orchestration-basics/issues"
},
"homepage": "https://github.com/Agoric/dapp-agoric-basics#readme",
"homepage": "https://github.com/Agoric/dapp-orchestration-basics#readme",
"eslintConfig": {
"parserOptions": {
"sourceType": "module",
Expand Down
Loading

0 comments on commit 2379c1a

Please sign in to comment.