Skip to content

Commit

Permalink
Merge dapp-offer-up
Browse files Browse the repository at this point in the history
  • Loading branch information
dckc committed Jan 31, 2024
2 parents 38730ea + db4e168 commit 9fde159
Show file tree
Hide file tree
Showing 49 changed files with 13,119 additions and 1 deletion.
24 changes: 24 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Lint and Test

on:
pull_request:

jobs:
all:
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v3
- name: Use Node.js 18.8.x
uses: actions/setup-node@v3
with:
# use node 18.8.x until Agoric/agoric-sdk#8636
node-version: '18.8.x'
- name: yarn install
run: yarn
- name: yarn lint
run: yarn lint
- name: yarn build
run: yarn build
- name: yarn test
run: yarn test
24 changes: 24 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
111 changes: 111 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
## Testing the contract (WIP)

```sh
cd contract
yarn # may take a while
yarn test
```

```
yarn run v1.22.21
$ ava --verbose
start proposal module evaluating
bundles/ add: assetContract from /home/connolly/projects/dapp-offer-up/contract/src/offer-up.contract.js
✔ bundle-source › bundleSource() bundles the contract for use with zoe (1s)
ℹ 7fffb45de65f0c887401d4a5c5185ad87d41e3842d6eb2e10559a06c747358fe0dc5ef41fd4c04457c5e9bb27ed85e48ea1ff8bdeac524063b7743205f4817e6
ℹ Object @Alleged: BundleInstallation {}
bundles/ bundled 85 files in bundle-assetContract.js at 2024-01-23T02:30:57.437Z
startOfferUpContract()...
✔ contract › Install the contract
ℹ Object @Alleged: BundleInstallation {}
✔ contract › Start the contract (901ms)
ℹ terms: {
tradePrice: {
brand: Object @Alleged: PlayMoney brand {},
value: 5n,
},
}
ℹ Object @Alleged: InstanceHandle {}
CoreEval script: started contract Object [Alleged: InstanceHandle] {}
✔ contract › Alice trades: give some play money, want items (939ms)
ℹ Object @Alleged: InstanceHandle {}
ℹ Alice gives {
Price: {
brand: Object @Alleged: PlayMoney brand {},
value: 5n,
},
}
ℹ Alice payout brand Object @Alleged: Item brand {}
ℹ Alice payout value Object @copyBag {
payload: [
[
'scroll',
1n,
],
[
'map',
1n,
],
],
}
CoreEval script: share via agoricNames: Object [Alleged: Item brand] {}
offerUp (re)started
----- OfferUp.2 2 trade give { Price: { brand: Object [Alleged: PlayMoney brand] {}, value: 5n } } want Object [copyBag] { payload: [ [ 'scroll', 1n ], [ 'map', 1n ] ] }
bundles/ add: centralSupply from /home/connolly/projects/dapp-offer-up/node_modules/@agoric/vats/src/centralSupply.js
bundles/ bundled 132 files in bundle-centralSupply.js at 2024-01-23T02:30:59.505Z
----- OfferUp.2 2 trade give {
Price: { brand: Object [Alleged: ZDEFAULT brand] {}, value: 250000n }
} want Object [copyBag] { payload: [ [ 'scroll', 1n ], [ 'map', 1n ] ] }
✔ contract › Trade in IST rather than play money (2.5s)
ℹ Alice gives {
Price: {
brand: Object @Alleged: ZDEFAULT brand {},
value: 250000n,
},
}
ℹ Alice payout brand Object @Alleged: Item brand {}
ℹ Alice payout value Object @copyBag {
payload: [
[
'scroll',
1n,
],
[
'map',
1n,
],
],
}
✔ contract › use the code that will go on chain to start the contract (2.5s)
ℹ Alice gives {
Price: {
brand: Object @Alleged: ZDEFAULT brand {},
value: 250000n,
},
}
ℹ Alice payout brand Object @Alleged: Item brand {}
ℹ Alice payout value Object @copyBag {
payload: [
[
'scroll',
1n,
],
[
'map',
1n,
],
],
}
----- OfferUp.2 2 trade give {
Price: { brand: Object [Alleged: ZDEFAULT brand] {}, value: 250000n }
} want Object [copyBag] { payload: [ [ 'scroll', 1n ], [ 'map', 1n ] ] }
6 tests passed
Done in 4.74s.
```

Any `Error#1: changed ...` diagnostics are benign reports of updated files
outdating the contract bundle. It's benign: the test will re-build the bundle
as necessary.
21 changes: 21 additions & 0 deletions README-local-chain.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Agoric Local Chain with docker-compose

To start a local agoric blockchain:

```sh
docker compose up -d
```

**NOTE**: The image, which is several Gb, has to be pulled
and extracted the first time you start the docker application
services.

Then use `docker-compose logs` etc. as usual.

Some useful recipies are included in `Makefile`.
Use `yarn make:help` to list them.
For example: `yarn docker:make mint4k`.

See also https://github.com/Agoric/documentation/pull/881

See also the [Agoric Gov Proposal Builder](https://cosgov.org/).
25 changes: 24 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,24 @@
# dapp-agoric-basics
# dapp-agoric-basics

This is a simple app for the [Agoric smart contract platform](https://docs.agoric.com/).

<img alt="Vite + React + Agoric page with Connect Wallet button"
style="border: 1px solid" width="300"
src="https://docs.agoric.com/assets/img/new_002_small2.2dfb7462.png" />

The contract lets you make an offer to give a small amount of [IST](https://inter.trade/) in exchange for
a few NFTs.

## Getting started

See [Your First Agoric Dapp](https://docs.agoric.com/guides/getting-started/) tutorial.

## Contributing: Development, Testing

The UI is a React app started with the [vite](https://vitejs.dev/) `react-ts` template.
On top of that, we add

- Watching [blockchain state queries](https://docs.agoric.com/guides/getting-started/contract-rpc.html#querying-vstorage)
- [Signing and sending offers](https://docs.agoric.com/guides/getting-started/contract-rpc.html#signing-and-broadcasting-offers)

See [CONTRIBUTING](./CONTRIBUTING.md) for more on testing.
Empty file added _agstate/.keep
Empty file.
19 changes: 19 additions & 0 deletions _agstate/agoric-servers/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "offer-up-agservers",
"version": "0.0.1",
"description": "Agoric server instances for dapp-offer-up",
"private": true,
"type": "module",
"scripts": {
"build": "exit 0",
"test": "exit 0",
"lint": "exit 0",
"lint-check": "exit 0",
"lint-fix": "exit 0"
},
"author": "Agoric",
"license": "Apache-2.0",
"dependencies": {
"@agoric/cosmic-swingset": "^0.41.3"
}
}
1 change: 1 addition & 0 deletions api/README-no-api.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This dapp has no API.
5 changes: 5 additions & 0 deletions api/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"$note": "@agoric/[email protected] expects an api/package.json",
"name": "offer-up-api",
"version": "0.1.0"
}
3 changes: 3 additions & 0 deletions contract/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
start-offer-up-permit.json
start-offer-up.js
bundles/
121 changes: 121 additions & 0 deletions contract/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
CHAINID=agoriclocal
USER1ADDR=$(shell agd keys show user1 -a --keyring-backend="test")
ACCT_ADDR=$(USER1ADDR)
BLD=000000ubld

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

.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 query bank balances $(ACCT_ADDR)

GAS_ADJUSTMENT=1.2
SIGN_BROADCAST_OPTS=--keyring-backend=test --chain-id=$(CHAINID) \
--gas=auto --gas-adjustment=$(GAS_ADJUSTMENT) \
--yes -b block

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

# https://agoric.explorers.guru/proposal/61
lower-bundle-cost: bundles/lower-bundle-cost.json ./scripts/voteLatestProposalAndWait.sh
agd tx gov submit-proposal param-change bundles/lower-bundle-cost.json \
$(SIGN_BROADCAST_OPTS) \
--from user1
./scripts/voteLatestProposalAndWait.sh
# agd query swingset params


bundles/swingset-params.json:
mkdir -p bundles/
agd query swingset params -o json >$@

.ONESHELL:
bundles/lower-bundle-cost.json: bundles/swingset-params.json
@read PARAMS < bundles/swingset-params.json; export PARAMS
node - <<- EOF >$@
const storageByte = '20000000';
const paramChange = {
title: 'Lower Bundle Cost to 0.02 IST/Kb (a la mainnet 61)',
description: '0.02 IST/Kb',
deposit: '10000000ubld',
changes: [{
subspace: 'swingset',
key: 'beans_per_unit',
value: '...',
}],
};
const params = JSON.parse(process.env.PARAMS);
const ix = params.beans_per_unit.findIndex(({key}) => key === 'storageByte');
params.beans_per_unit[ix].beans = storageByte;
paramChange.changes[0].value = params.beans_per_unit;
console.log(JSON.stringify(paramChange, null, 2));
EOF

# 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

FUNDS=321$(BLD)
fund-acct:
agd tx bank send validator $(ACCT_ADDR) $(FUNDS) \
$(SIGN_BROADCAST_OPTS) \
-o json >,tx.json
jq '{code: .code, height: .height}' ,tx.json

gov-q:
agd query gov proposals --output json | \
jq -c '.proposals[] | [.proposal_id,.voting_end_time,.status]'

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 \
$(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

print-key: /root/.agoric/user1.key
@echo Import the following mnemonic into Keplr:
@cat $<
@echo
@echo -n 'The resulting address should be: '
@agd keys show user1 -a --keyring-backend="test"
@echo

SCRIPT=start-offer-up.js
PERMIT=start-offer-up-permit.json
start-contract: $(SCRIPT) $(PERMIT) install-bundles
scripts/propose-start-contract.sh

install-bundles: bundles/bundle-list
./scripts/install-bundles.sh

build-proposal: bundles/bundle-list

bundles/bundle-list $(SCRIPT) $(PERMIT):
./scripts/build-proposal.sh


clean:
@rm -rf $(SCRIPT) $(PERMIT) bundles/
19 changes: 19 additions & 0 deletions contract/jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// 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", "exported.js", "globals.d.ts"]
}
Loading

0 comments on commit 9fde159

Please sign in to comment.