Skip to content

Commit

Permalink
Merge pull request #169 from Agoric/ta/cleanup
Browse files Browse the repository at this point in the history
clean up, release and use
  • Loading branch information
turadg authored Aug 27, 2024
2 parents 37363b3 + 7a6bb65 commit 643068f
Show file tree
Hide file tree
Showing 41 changed files with 1,330 additions and 1,200 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ jobs:

- uses: actions/setup-node@v4
with:
# 18.19 causes this problem running tsx:
# The --loader flag was deprecated in Node v20.6.0
node-version: 18.18
node-version: 20

- name: Install deps
run: |
Expand Down
7 changes: 2 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,8 @@ web_modules/
# Optional stylelint cache
.stylelintcache

# Microbundle cache
.rpt2_cache/
.rts2_cache_cjs/
.rts2_cache_es/
.rts2_cache_umd/
# TsImp cache
.tsimp/

# Optional REPL history
.node_repl_history
Expand Down
2 changes: 1 addition & 1 deletion .node-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
18.18.0
20.17.0
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ docker run -p 26657:26657 -p 1317:1317 -p 9090:9090 ghcr.io/agoric/agoric-3-prop

The `-p` is short for [publish](https://docs.docker.com/network/#published-ports) to make the `agd` [daemon's ports](https://docs.cosmos.network/v0.46/core/grpc_rest.html) available on your host machine:

| Port | Purpose |
| --- | --- |
| 1317 | REST server |
| 9090 | gRPC server |
| 26657| Tendermint RPC endpoint |
| Port | Purpose |
| ----- | ----------------------- |
| 1317 | REST server |
| 9090 | gRPC server |
| 26657 | Tendermint RPC endpoint |

## Design

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
]
},
"license": "Apache-2.0",
"packageManager": "yarn@4.1.0",
"packageManager": "yarn@4.4.1",
"devDependencies": {
"prettier": "^3.2.5"
"prettier": "^3.3.3"
}
}
1 change: 1 addition & 0 deletions packages/synthetic-chain/.node-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
20.17.0
35 changes: 23 additions & 12 deletions packages/synthetic-chain/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
{
"name": "@agoric/synthetic-chain",
"version": "0.1.0",
"version": "0.2.0",
"description": "Utilities to build a chain and test proposals atop it",
"bin": "dist/cli/cli.js",
"bin": {
"synthetic-chain": "dist/cli/cli.js"
},
"main": "./dist/lib/index.js",
"type": "module",
"module": "./dist/lib/index.js",
Expand All @@ -14,32 +16,41 @@
"scripts": {
"prepare": "yarn build",
"build": "tsup",
"test": "NODE_OPTIONS='--loader=tsx --no-warnings' ava"
"test": "ava"
},
"engines": {
"node": "^18.19 || ^20.9"
},
"dependencies": {
"@endo/zip": "^1.0.1",
"better-sqlite3": "^9.4.0",
"@endo/zip": "^1.0.6",
"better-sqlite3": "^9.6.0",
"chalk": "^5.3.0",
"cosmjs-types": "^0.9.0",
"execa": "^8.0.1"
},
"devDependencies": {
"@agoric/cosmic-proto": "^0.4.1-dev-c5284e4.0",
"@types/better-sqlite3": "^7.6.9",
"@types/node": "^18.19.14",
"ava": "^5.3.1",
"tsup": "^8.0.2",
"tsx": "^4.7.1",
"typescript": "^5.3.3"
"@types/better-sqlite3": "^7.6.11",
"@types/node": "^18.19.46",
"ava": "^6.1.3",
"tsimp": "^2.0.11",
"tsup": "^8.2.4",
"typescript": "^5.5.4"
},
"ava": {
"extensions": {
"js": true,
"ts": "module"
}
},
"environmentVariables": {
"binary": "fake-agd",
"ATOM_DENOM": "uatom",
"CHAINID": "fakechain",
"HOME": "/tmp/fake-home"
},
"nodeArguments": [
"--import=tsimp"
]
},
"license": "Apache-2.0",
"publishConfig": {
Expand Down
4 changes: 2 additions & 2 deletions packages/synthetic-chain/src/lib/agd-lib.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import assert from 'node:assert';
import { ExecFileSyncOptionsWithStringEncoding } from 'node:child_process';
import { CHAINID, VALIDATORADDR } from './constants';
import { agd } from './cliHelper';
import { CHAINID, VALIDATORADDR } from './constants.js';
import { agd } from './cliHelper.js';

const { freeze } = Object;

Expand Down
12 changes: 3 additions & 9 deletions packages/synthetic-chain/src/lib/cliHelper.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { $, execaCommand } from 'execa';
import { BINARY } from './constants.js';
import { BINARY, SDK_ROOT } from './constants.js';

export const executeCommand = async (
command: string,
Expand Down Expand Up @@ -86,10 +86,7 @@ export const agoric = {
},
};

export const { stdout: agopsLocation } = await $({
shell: true,
cwd: '/usr/src/agoric-sdk',
})`yarn bin agops`;
export const agopsLocation = `${SDK_ROOT}/node_modules/.bin/agops`;

export const agops = {
vaults: async (...params: string[]) => {
Expand Down Expand Up @@ -123,10 +120,7 @@ export const agops = {
},
};

export const { stdout: bundleSourceLocation } = await $({
shell: true,
cwd: '/usr/src/agoric-sdk',
})`yarn bin bundle-source`;
export const bundleSourceLocation = `${SDK_ROOT}/node_modules/.bin/bundle-source`;

/**
* @returns Returns the filepath of the bundle
Expand Down
3 changes: 1 addition & 2 deletions packages/synthetic-chain/src/lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ export const VALIDATORADDR = 'agoric1estsewt6jqsx77pwcxkn5ah0jqgu8rhgflwfdl';

export const BINARY = NonNullish(process.env.binary);

export const PSM_PAIR = NonNullish(process.env.PSM_PAIR);
export const ATOM_DENOM = NonNullish(process.env.ATOM_DENOM);

export const CHAINID = NonNullish(process.env.CHAINID);
export const HOME = NonNullish(process.env.HOME);

export const SDK_ROOT = '/usr/src/agoric-sdk';
export const SDK_ROOT = process.env.AGORIC_SDK || '/usr/src/agoric-sdk';
21 changes: 3 additions & 18 deletions packages/synthetic-chain/src/lib/econHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { executeOffer, waitForBlock } from './commonUpgradeHelpers.js';
import { ATOM_DENOM, CHAINID, VALIDATORADDR } from './constants.js';
import { agd, agops, executeCommand, agopsLocation } from './cliHelper.js';
import { GOV1ADDR, GOV2ADDR, GOV3ADDR } from './constants.js';
import { queryVstorage, getQuoteBody } from './vstorage.js';
import { queryVstorage, getQuoteBody, getInstanceBoardId } from './vstorage.js';

const ORACLE_ADDRESSES = [GOV1ADDR, GOV2ADDR, GOV3ADDR];

Expand Down Expand Up @@ -83,24 +83,9 @@ export const getISTBalance = async (addr, denom = 'uist', unit = 1_000_000) => {
return Number(coin.amount) / unit;
};

export const getOracleInstance = async price => {
const instanceRec = await queryVstorage(`published.agoricNames.instance`);

const value = JSON.parse(instanceRec.value);
const body = JSON.parse(value.values.at(-1));

const feeds = JSON.parse(body.body.substring(1));
const feedName = `${price}-USD price feed`;

const key = Object.keys(feeds).find(k => feeds[k][0] === feedName);
if (key) {
return body.slots[key];
}
return null;
};

export const checkForOracle = async (t, name) => {
const instance = await getOracleInstance(name);
const instanceName = `${name}-USD price feed`;
const instance = await getInstanceBoardId(name);
t.truthy(instance);
};

Expand Down
1 change: 1 addition & 0 deletions packages/synthetic-chain/src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ export * from './core-eval.js';
export * from './econHelpers.js';
export * from './logging.js';
export * from './vat-status.js';
export * from './vstorage.js';
export * from './webAsset.js';
21 changes: 21 additions & 0 deletions packages/synthetic-chain/src/lib/vstorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,24 @@ export const getQuoteBody = async path => {
return JSON.parse(body.body.substring(1));
};

/**
*
* @param {string} instanceName
* @returns {string | null} boardId of the named instance in agoricNames
*/
export const getInstanceBoardId = async instanceName => {
const instanceRec = await queryVstorage(`published.agoricNames.instance`);

const value = JSON.parse(instanceRec.value);
const body = JSON.parse(value.values.at(-1));

const instances = JSON.parse(body.body.substring(1));

const key = Object.keys(instances).find(
k => instances[k][0] === instanceName,
);
if (key) {
return body.slots[key];
}
return null;
};
105 changes: 105 additions & 0 deletions packages/synthetic-chain/test/snapshots/test-exports.ts.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# Snapshot report for `test/test-exports.ts`

The actual snapshot is saved in `test-exports.ts.snap`.

Generated by [AVA](https://avajs.dev).

## exports

> Snapshot 1
@Module {
ATOM_DENOM: 'uatom',
BINARY: 'fake-agd',
CHAINID: 'fakechain',
GOV1ADDR: 'agoric1ee9hr0jyrxhy999y755mp862ljgycmwyp4pl7q',
GOV2ADDR: 'agoric1wrfh296eu2z34p6pah7q04jjuyj3mxu9v98277',
GOV3ADDR: 'agoric1ydzxwh6f893jvpaslmaz6l8j2ulup9a7x8qvvq',
HOME: '/tmp/fake-home',
SDK_ROOT: '/usr/src/agoric-sdk',
USER1ADDR: 'agoric1rwwley550k9mmk6uq6mm6z4udrg8kyuyvfszjk',
VALIDATORADDR: 'agoric1estsewt6jqsx77pwcxkn5ah0jqgu8rhgflwfdl',
addPreexistingOracles: AsyncFunction {},
addUser: AsyncFunction {},
adjustVault: Function adjustVault {},
agd: {
export: AsyncFunction [],
keys: AsyncFunction [],
query: AsyncFunction [],
tx: AsyncFunction [],
},
agops: {
auctioneer: AsyncFunction [],
ec: AsyncFunction [],
oracle: AsyncFunction [],
perf: AsyncFunction [],
vaults: AsyncFunction [],
},
agopsInter: Function agopsInter {},
agopsLocation: '/usr/src/agoric-sdk/node_modules/.bin/agops',
agoric: {
follow: AsyncFunction [],
run: AsyncFunction [],
wallet: AsyncFunction [],
},
bankSend: Function bankSend {},
bundleDetail: Function bundleDetail {},
bundleSource: AsyncFunction {},
bundleSourceLocation: '/usr/src/agoric-sdk/node_modules/.bin/bundle-source',
calculateWalletState: AsyncFunction {},
checkForOracle: AsyncFunction {},
closeVault: Function closeVault {},
createBid: Function createBid {},
dbTool: Function dbTool {},
ensureISTForInstall: AsyncFunction {},
evalBundles: AsyncFunction {},
executeCommand: AsyncFunction {},
executeOffer: AsyncFunction {},
extractStreamCellValue: Function extractStreamCellValue {},
flags: Function flags {},
generateOracleMap: Function generateOracleMap {},
getAuctionCollateral: AsyncFunction {},
getContractInfo: AsyncFunction {},
getISTBalance: AsyncFunction {},
getIncarnation: AsyncFunction {},
getInstanceBoardId: AsyncFunction {},
getLiveOffers: AsyncFunction {},
getPriceQuote: AsyncFunction {},
getProvisionPoolMetrics: AsyncFunction [],
getQuoteBody: AsyncFunction {},
getUser: AsyncFunction {},
getVatDetails: AsyncFunction {},
getVaultPrices: AsyncFunction {},
installBundle: AsyncFunction {},
loadedBundleIds: Function loadedBundleIds {},
makeAgd: Function makeAgd {},
makeFileRW: Function makeFileRW {},
makeFileRd: Function makeFileRd {},
makeWebCache: Function makeWebCache {},
makeWebRd: Function makeWebRd {},
mintIST: AsyncFunction {},
mkTemp: AsyncFunction {},
newOfferId: AsyncFunction [],
openVault: Function openVault {},
passCoreEvalProposal: AsyncFunction {},
proposalBuilder: AsyncFunction {},
provisionSmartWallet: AsyncFunction {},
pushPrices: AsyncFunction {},
queryVstorage: Function queryVstorage {},
readBundles: AsyncFunction {},
registerOraclesForBrand: AsyncFunction {},
smallCapsContext: Function smallCapsContext {},
staticConfig: {
collateralPrice: 6,
deposit: '10000000ubld',
installer: 'gov1',
proposer: 'validator',
swingstorePath: '~/.agoric/data/agoric/swingstore.sqlite',
},
step: AsyncFunction {},
submitProposal: AsyncFunction {},
txAbbr: Function txAbbr {},
voteLatestProposalAndWait: AsyncFunction {},
waitForBlock: AsyncFunction [],
wellKnownIdentities: AsyncFunction [],
}
Binary file not shown.
7 changes: 7 additions & 0 deletions packages/synthetic-chain/test/test-exports.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import test from 'ava';

import * as lib from '../src/lib/index.js';

test('exports', t => {
t.snapshot(lib);
});
2 changes: 1 addition & 1 deletion proposals/16:upgrade-8/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@
"scripts": {
"agops": "yarn --cwd /usr/src/agoric-sdk/ --silent agops"
},
"packageManager": "yarn@4.1.0"
"packageManager": "yarn@4.4.1"
}
2 changes: 1 addition & 1 deletion proposals/29:upgrade-9/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
"scripts": {
"agops": "yarn --cwd /usr/src/agoric-sdk/ --silent agops"
},
"packageManager": "yarn@4.1.0"
"packageManager": "yarn@4.4.1"
}
15 changes: 4 additions & 11 deletions proposals/29:upgrade-9/sanity.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,12 @@ import test from 'ava';

import fsp from 'node:fs/promises';

import {
agd,
agops,
agoric,
} from '@agoric/synthetic-chain';
import { agd, agops, agoric } from '@agoric/synthetic-chain';

import { getUser } from '@agoric/synthetic-chain';
import {
GOV1ADDR,
GOV2ADDR,
GOV3ADDR,
PSM_PAIR,
} from '@agoric/synthetic-chain';
import { GOV1ADDR, GOV2ADDR, GOV3ADDR } from '@agoric/synthetic-chain';

const PSM_PAIR = process.env.PSM_PAIR;

test(`there's only uist`, async t => {
const result = await agd.query(
Expand Down
Loading

0 comments on commit 643068f

Please sign in to comment.