Skip to content

Commit

Permalink
FU oracle operator CLI (#10570)
Browse files Browse the repository at this point in the history
refs: #10567

## Description

This sets up a CLI for transaction oracle operators. It has tests but I don't expect them to pass yet.

I think this is worth landing to get the CLI scaffolded and the refactorings of agoric-cli to client-utils that support it. In particular moving the `AGORIC_NET` convention down to `client-utils` in a cli.js module and other network config helpers in network-config.js.

It will also help to DRY out the 'test-lib' code in a3p proposals that was copied from agoric-cli (e.g. `rpc.js`)  cc @anilhelvaci 

### Security Considerations
agoric-cli will source its network config lookup function from another package. That's a potential supply chain weakness but it's the same org as the agoric-cli and it's very unlikely only one would be compromised if either were.

### Scaling Considerations
none

### Documentation Considerations
Includes CLI help and a demonstration test

### Testing Considerations
I added a test that runs in CI but doesn't cause a failure so that this can live in master while we build it out

### Upgrade Considerations
none
  • Loading branch information
mergify[bot] authored Nov 27, 2024
2 parents 23120a9 + 18a8219 commit a2e9363
Show file tree
Hide file tree
Showing 42 changed files with 379 additions and 205 deletions.
2 changes: 1 addition & 1 deletion a3p-integration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@
"@agoric/synthetic-chain": "^0.4.3",
"@types/better-sqlite3": "^7.6.11"
},
"packageManager": "[email protected].1",
"packageManager": "[email protected].3",
"license": "Apache-2.0"
}
2 changes: 1 addition & 1 deletion a3p-integration/proposals/f:fast-usdc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,5 @@
"scripts": {
"agops": "yarn --cwd /usr/src/agoric-sdk/ --silent agops"
},
"packageManager": "yarn@4.2.2"
"packageManager": "yarn@4.5.3"
}
15 changes: 15 additions & 0 deletions a3p-integration/proposals/f:fast-usdc/test-cli.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

# FIXME these commands are run against the `@agoric/fast-usdc` pulled from NPM
# but should be run against the local SDK. The `yarn link` command described in
# a3p-integration/README.md is supposed to make that work but it's not working.

yarn @agoric/fast-usdc operator accept >| accept.json
cat accept.json
yarn agoric wallet send --offer accept.json --from gov1 --keyring-backend="test"
ACCEPT_OFFER_ID=$(agoric wallet extract-id --offer accept.json)

# FIXME attest something
yarn @agoric/fast-usdc operator attest --previousOfferId "$ACCEPT_OFFER_ID" >| attest.json
cat attest.json
yarn agoric wallet send --offer attest.json --from gov1 --keyring-backend="test"
3 changes: 3 additions & 0 deletions a3p-integration/proposals/f:fast-usdc/test.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
#!/bin/bash
yarn ava

# TODO get CLI test passing and part of CI
./test-cli.sh || echo "CLI test failed"
4 changes: 2 additions & 2 deletions a3p-integration/proposals/f:fast-usdc/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4140,11 +4140,11 @@ __metadata:

"typescript@patch:typescript@npm%3A5.1.6 - 5.6.x#optional!builtin<compat/typescript>":
version: 5.6.3
resolution: "typescript@patch:typescript@npm%3A5.6.3#optional!builtin<compat/typescript>::version=5.6.3&hash=b45daf"
resolution: "typescript@patch:typescript@npm%3A5.6.3#optional!builtin<compat/typescript>::version=5.6.3&hash=8c6c40"
bin:
tsc: bin/tsc
tsserver: bin/tsserver
checksum: 10c0/ac8307bb06bbfd08ae7137da740769b7d8c3ee5943188743bb622c621f8ad61d244767480f90fbd840277fbf152d8932aa20c33f867dea1bb5e79b187ca1a92f
checksum: 10c0/7c9d2e07c81226d60435939618c91ec2ff0b75fbfa106eec3430f0fcf93a584bc6c73176676f532d78c3594fe28a54b36eb40b3d75593071a7ec91301533ace7
languageName: node
linkType: hard

Expand Down
2 changes: 1 addition & 1 deletion a3p-integration/proposals/n:upgrade-next/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"scripts": {
"agops": "yarn --cwd /usr/src/agoric-sdk/ --silent agops"
},
"packageManager": "[email protected].1",
"packageManager": "[email protected].3",
"devDependencies": {
"eslint": "^8.57.0",
"npm-run-all": "^4.1.5",
Expand Down
2 changes: 1 addition & 1 deletion a3p-integration/proposals/p:upgrade-19/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"scripts": {
"agops": "yarn --cwd /usr/src/agoric-sdk/ --silent agops"
},
"packageManager": "yarn@4.2.2",
"packageManager": "yarn@4.5.3",
"devDependencies": {
"eslint": "^8.57.0",
"npm-run-all": "^4.1.5",
Expand Down
4 changes: 2 additions & 2 deletions a3p-integration/proposals/p:upgrade-19/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5899,11 +5899,11 @@ __metadata:

"typescript@patch:typescript@npm%3A5.1.6 - 5.6.x#optional!builtin<compat/typescript>, typescript@patch:typescript@npm%3A^5.6.3#optional!builtin<compat/typescript>":
version: 5.6.3
resolution: "typescript@patch:typescript@npm%3A5.6.3#optional!builtin<compat/typescript>::version=5.6.3&hash=b45daf"
resolution: "typescript@patch:typescript@npm%3A5.6.3#optional!builtin<compat/typescript>::version=5.6.3&hash=8c6c40"
bin:
tsc: bin/tsc
tsserver: bin/tsserver
checksum: 10c0/ac8307bb06bbfd08ae7137da740769b7d8c3ee5943188743bb622c621f8ad61d244767480f90fbd840277fbf152d8932aa20c33f867dea1bb5e79b187ca1a92f
checksum: 10c0/7c9d2e07c81226d60435939618c91ec2ff0b75fbfa106eec3430f0fcf93a584bc6c73176676f532d78c3594fe28a54b36eb40b3d75593071a7ec91301533ace7
languageName: node
linkType: hard

Expand Down
2 changes: 1 addition & 1 deletion a3p-integration/proposals/s:stake-bld/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"ava": {
"concurrency": 1
},
"packageManager": "[email protected].1",
"packageManager": "[email protected].3",
"devDependencies": {
"@types/node": "^22.0.0"
}
Expand Down
2 changes: 1 addition & 1 deletion a3p-integration/proposals/z:acceptance/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
"scripts": {
"agops": "yarn --cwd /usr/src/agoric-sdk/ --silent agops"
},
"packageManager": "[email protected].1",
"packageManager": "[email protected].3",
"devDependencies": {
"eslint": "^8.57.0",
"npm-run-all": "^4.1.5",
Expand Down
2 changes: 1 addition & 1 deletion multichain-testing/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"starship:stop": "make stop",
"postinstall": "patch-package"
},
"packageManager": "yarn@4.1.1",
"packageManager": "yarn@4.5.3",
"devDependencies": {
"@agoric/cosmic-proto": "0.4.1-dev-08f8549.0",
"@cosmjs/crypto": "^0.32.4",
Expand Down
7 changes: 3 additions & 4 deletions packages/agoric-cli/src/commands/auction.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
// @ts-check
/* eslint-env node */
import { InvalidArgumentError } from 'commander';
import { fetchEnvNetworkConfig, makeVstorageKit } from '@agoric/client-utils';
import { Fail } from '@endo/errors';
import { makeVstorageKit } from '@agoric/client-utils';
import { InvalidArgumentError } from 'commander';
import { outputActionAndHint } from '../lib/wallet.js';
import { getNetworkConfig } from '../lib/network-config.js';

/**
* @import {ParamTypesMap, ParamTypesMapFromRecord} from '@agoric/governance/src/contractGovernance/typedParamManager.js'
* @import {ParamValueForType} from '@agoric/governance/src/types.js'
*/

const networkConfig = await getNetworkConfig({ env: process.env, fetch });
const networkConfig = await fetchEnvNetworkConfig({ env: process.env, fetch });

/**
* @template {ParamTypesMap} M
Expand Down
5 changes: 2 additions & 3 deletions packages/agoric-cli/src/commands/gov.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
// @ts-check
/* eslint-disable func-names */
/* eslint-env node */
import { makeVstorageKit } from '@agoric/client-utils';
import { fetchEnvNetworkConfig, makeVstorageKit } from '@agoric/client-utils';
import { execFileSync as execFileSyncAmbient } from 'child_process';
import { Command, CommanderError } from 'commander';
import { normalizeAddressWithOptions, pollBlocks } from '../lib/chain.js';
import { getNetworkConfig } from '../lib/network-config.js';
import {
findContinuingIds,
getCurrent,
Expand All @@ -26,7 +25,7 @@ const collectValues = (val, memo) => {

const defaultKeyring = process.env.AGORIC_KEYRING_BACKEND || 'test';

const networkConfig = await getNetworkConfig({ env: process.env, fetch });
const networkConfig = await fetchEnvNetworkConfig({ env: process.env, fetch });

/**
* @param {import('anylogger').Logger} _logger
Expand Down
7 changes: 3 additions & 4 deletions packages/agoric-cli/src/commands/inter.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,19 @@
*/

// @ts-check
import { makeWalletUtils } from '@agoric/client-utils';
import { fetchEnvNetworkConfig, makeWalletUtils } from '@agoric/client-utils';
import { makeOfferSpecShape } from '@agoric/inter-protocol/src/auction/auctionBook.js';
import { Offers } from '@agoric/inter-protocol/src/clientSupport.js';
import { objectMap } from '@agoric/internal';
import { M, matches } from '@endo/patterns';
import { CommanderError, InvalidArgumentError } from 'commander';
import { normalizeAddressWithOptions, pollBlocks } from '../lib/chain.js';
import { getCurrent, outputActionAndHint, sendAction } from '../lib/wallet.js';
import {
asBoardRemote,
bigintReplacer,
makeAmountFormatter,
} from '../lib/format.js';
import { getNetworkConfig } from '../lib/network-config.js';
import { getCurrent, outputActionAndHint, sendAction } from '../lib/wallet.js';

const { values } = Object;

Expand Down Expand Up @@ -232,7 +231,7 @@ export const makeInterCommand = (
try {
// XXX pass fetch to getNetworkConfig() explicitly
// await null above makes this await safe
const networkConfig = await getNetworkConfig({ env, fetch });
const networkConfig = await fetchEnvNetworkConfig({ env, fetch });
return makeWalletUtils({ fetch, delay }, networkConfig);
} catch (err) {
// CommanderError is a class constructor, and so
Expand Down
9 changes: 6 additions & 3 deletions packages/agoric-cli/src/commands/oracle.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/* eslint-disable func-names */
/* eslint-env node */
import {
fetchEnvNetworkConfig,
makeVstorageKit,
makeWalletUtils,
storageHelper,
Expand All @@ -14,14 +15,13 @@ import * as cp from 'child_process';
import { Command } from 'commander';
import { inspect } from 'util';
import { normalizeAddressWithOptions } from '../lib/chain.js';
import { getNetworkConfig } from '../lib/network-config.js';
import { bigintReplacer } from '../lib/format.js';
import {
getCurrent,
outputAction,
sendAction,
sendHint,
} from '../lib/wallet.js';
import { bigintReplacer } from '../lib/format.js';

/** @import {PriceAuthority, PriceDescription, PriceQuote, PriceQuoteValue, PriceQuery,} from '@agoric/zoe/tools/types.js'; */

Expand Down Expand Up @@ -86,7 +86,10 @@ export const makeOracleCommand = (logger, io = {}) => {

const rpcTools = async () => {
// XXX pass fetch to getNetworkConfig() explicitly
const networkConfig = await getNetworkConfig({ env: process.env, fetch });
const networkConfig = await fetchEnvNetworkConfig({
env: process.env,
fetch,
});
const utils = await makeVstorageKit({ fetch }, networkConfig);

const lookupPriceAggregatorInstance = ([brandIn, brandOut]) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/agoric-cli/src/commands/perf.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
makeFollower,
makeLeaderFromRpcAddresses,
} from '@agoric/casting';
import { fetchEnvNetworkConfig } from '@agoric/client-utils';
import { slotToRemotable } from '@agoric/internal/src/storage-test-utils.js';
import { boardSlottingMarshaller } from '@agoric/vats/tools/board-utils.js';
import { Command } from 'commander';
Expand All @@ -17,12 +18,11 @@ import {
execSwingsetTransaction,
normalizeAddressWithOptions,
} from '../lib/chain.js';
import { getNetworkConfig } from '../lib/network-config.js';

// tight for perf testing but less than this tends to hang.
const SLEEP_SECONDS = 0.1;

const networkConfig = await getNetworkConfig({ env: process.env, fetch });
const networkConfig = await fetchEnvNetworkConfig({ env: process.env, fetch });

/**
* @param {import('anylogger').Logger} logger
Expand Down
11 changes: 7 additions & 4 deletions packages/agoric-cli/src/commands/psm.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
// @ts-check
/* eslint-disable func-names */
/* eslint-env node */
import { makeVstorageKit, storageHelper } from '@agoric/client-utils';
import {
fetchEnvNetworkConfig,
makeVstorageKit,
storageHelper,
} from '@agoric/client-utils';
import { Offers } from '@agoric/inter-protocol/src/clientSupport.js';
import { Command } from 'commander';
import { getNetworkConfig } from '../lib/network-config.js';
import { outputExecuteOfferAction } from '../lib/wallet.js';
import { asPercent } from '../lib/format.js';
import { outputExecuteOfferAction } from '../lib/wallet.js';

const networkConfig = await getNetworkConfig({ env: process.env, fetch });
const networkConfig = await fetchEnvNetworkConfig({ env: process.env, fetch });

// Adapted from https://gist.github.com/dckc/8b5b2f16395cb4d7f2ff340e0bc6b610#file-psm-tool

Expand Down
5 changes: 2 additions & 3 deletions packages/agoric-cli/src/commands/reserve.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
// @ts-check
/* eslint-disable func-names */
/* eslint-env node */
import { makeVstorageKit } from '@agoric/client-utils';
import { fetchEnvNetworkConfig, makeVstorageKit } from '@agoric/client-utils';
import { Offers } from '@agoric/inter-protocol/src/clientSupport.js';
import { Command } from 'commander';
import { getNetworkConfig } from '../lib/network-config.js';
import { outputActionAndHint } from '../lib/wallet.js';

const networkConfig = await getNetworkConfig({ env: process.env, fetch });
const networkConfig = await fetchEnvNetworkConfig({ env: process.env, fetch });

/**
* @param {import('anylogger').Logger} _logger
Expand Down
7 changes: 3 additions & 4 deletions packages/agoric-cli/src/commands/test-upgrade.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
// @ts-check
/* eslint-env node */
import { makeWalletUtils } from '@agoric/client-utils';
import { fetchEnvNetworkConfig, makeWalletUtils } from '@agoric/client-utils';
import { Fail } from '@endo/errors';
import { CommanderError } from 'commander';
import { normalizeAddressWithOptions } from '../lib/chain.js';
import { getNetworkConfig } from '../lib/network-config.js';
import { sendAction } from '../lib/wallet.js';
import { bigintReplacer } from '../lib/format.js';
import { sendAction } from '../lib/wallet.js';

/**
* Make commands for testing.
Expand Down Expand Up @@ -39,7 +38,7 @@ export const makeTestCommand = (
try {
// XXX pass fetch to getNetworkConfig() explicitly
// await null above makes this await safe
const networkConfig = await getNetworkConfig({ env, fetch });
const networkConfig = await fetchEnvNetworkConfig({ env, fetch });
return makeWalletUtils({ fetch, delay }, networkConfig);
} catch (err) {
// CommanderError is a class constructor, and so
Expand Down
5 changes: 2 additions & 3 deletions packages/agoric-cli/src/commands/vaults.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
// @ts-check
/* eslint-disable func-names */
/* eslint-env node */
import { makeVstorageKit } from '@agoric/client-utils';
import { fetchEnvNetworkConfig, makeVstorageKit } from '@agoric/client-utils';
import {
lookupOfferIdForVault,
Offers,
} from '@agoric/inter-protocol/src/clientSupport.js';
import { Command } from 'commander';
import { normalizeAddressWithOptions } from '../lib/chain.js';
import { getCurrent, outputExecuteOfferAction } from '../lib/wallet.js';
import { getNetworkConfig } from '../lib/network-config.js';

const networkConfig = await getNetworkConfig({ env: process.env, fetch });
const networkConfig = await fetchEnvNetworkConfig({ env: process.env, fetch });

/**
* @param {import('anylogger').Logger} logger
Expand Down
9 changes: 4 additions & 5 deletions packages/agoric-cli/src/commands/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
makeLeader,
makeLeaderFromRpcAddresses,
} from '@agoric/casting';
import { makeVstorageKit } from '@agoric/client-utils';
import { makeVstorageKit, fetchEnvNetworkConfig } from '@agoric/client-utils';
import { execFileSync } from 'child_process';
import fs from 'fs';
import util from 'util';
Expand All @@ -19,15 +19,14 @@ import {
fetchSwingsetParams,
normalizeAddressWithOptions,
} from '../lib/chain.js';
import { getNetworkConfig } from '../lib/network-config.js';
import { coalesceWalletState, getCurrent } from '../lib/wallet.js';
import {
summarize,
fmtRecordOfLines,
parseFiniteNumber,
summarize,
} from '../lib/format.js';
import { coalesceWalletState, getCurrent } from '../lib/wallet.js';

const networkConfig = await getNetworkConfig({ env: process.env, fetch });
const networkConfig = await fetchEnvNetworkConfig({ env: process.env, fetch });

const SLEEP_SECONDS = 3;

Expand Down
3 changes: 2 additions & 1 deletion packages/agoric-cli/src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@

/** @import { ChildProcess } from 'child_process' */

export { getNetworkConfig } from './lib/network-config.js';
// Backwards compatibility
export { fetchEnvNetworkConfig as getNetworkConfig } from '@agoric/client-utils';

export const getSDKBinaries = ({
jsPfx = '../..',
Expand Down
Loading

0 comments on commit a2e9363

Please sign in to comment.