Skip to content

Commit

Permalink
Merge pull request #7824 from Agoric/ta/refactor-clientSupport
Browse files Browse the repository at this point in the history
refactor clientSupport to not depend on agoric-cli package
  • Loading branch information
turadg committed Jun 22, 2023
2 parents b05c226 + d089675 commit 7632299
Show file tree
Hide file tree
Showing 19 changed files with 119 additions and 187 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-all-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
run: sudo apt install -y graphviz

- name: Check for cycles
run: scripts/check-dependency-cycles.sh 4
run: scripts/check-dependency-cycles.sh 3

##################
# Lint tests
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ dist
.vscode/
.idea/

/packages.png
/packages-graph*

chaintest
_testoutput.txt
4 changes: 4 additions & 0 deletions packages/agoric-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
"agoric": "src/entrypoint.js",
"agops": "src/bin-agops.js"
},
"exports": {
"./src/entrypoint.js": "./src/entrypoint.js",
"./src/helpers.js": "./src/helpers.js"
},
"files": [
"src",
"exported.js"
Expand Down
19 changes: 2 additions & 17 deletions packages/agoric-cli/src/commands/inter.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ import {
import { getNetworkConfig } from '../lib/rpc.js';
import {
getCurrent,
makeParseAmount,
makeWalletUtils,
outputActionAndHint,
sendAction,
Expand Down Expand Up @@ -415,14 +414,7 @@ inter auction status
async ({ generateOnly, dryRun, ...opts }) => {
const tools = await tryMakeUtils();

const parseAmount = makeParseAmount(
tools.agoricNames,
msg => new InvalidArgumentError(msg),
);
const offer = Offers.auction.Bid(tools.agoricNames.brand, {
...opts,
parseAmount,
});
const offer = Offers.auction.Bid(tools.agoricNames, opts);

if (generateOnly) {
outputActionAndHint(
Expand Down Expand Up @@ -463,14 +455,7 @@ inter auction status
async ({ generateOnly, ...opts }) => {
const tools = await tryMakeUtils();

const parseAmount = makeParseAmount(
tools.agoricNames,
msg => new InvalidArgumentError(msg),
);
const offer = Offers.auction.Bid(tools.agoricNames.brand, {
...opts,
parseAmount,
});
const offer = Offers.auction.Bid(tools.agoricNames, opts);
if (generateOnly) {
outputActionAndHint(
{ method: 'executeOffer', offer },
Expand Down
2 changes: 1 addition & 1 deletion packages/agoric-cli/src/commands/psm.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export const makePsmCommand = logger => {
console.warn('running with options', opts);
const { agoricNames, lookupPsmInstance } = await rpcTools();
const instance = await lookupPsmInstance(opts.pair);
const offer = Offers.psm.swap(instance, agoricNames.brand, opts);
const offer = Offers.psm.swap(agoricNames, instance, opts);
outputExecuteOfferAction(offer);
});

Expand Down
2 changes: 1 addition & 1 deletion packages/agoric-cli/src/commands/reserve.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const makeReserveCommand = (_logger, io = {}) => {
async ({ collateralBrand, ...opts }) => {
const { agoricNames } = await makeRpcUtils({ fetch });

const offer = Offers.reserve.AddCollateral(agoricNames.brand, {
const offer = Offers.reserve.AddCollateral(agoricNames, {
collateralBrandKey: collateralBrand,
...opts,
});
Expand Down
6 changes: 3 additions & 3 deletions packages/agoric-cli/src/commands/vaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const makeVaultsCommand = logger => {
logger.warn('running with options', opts);
const { agoricNames } = await makeRpcUtils({ fetch });

const offer = Offers.vaults.OpenVault(agoricNames.brand, {
const offer = Offers.vaults.OpenVault(agoricNames, {
giveCollateral: opts.giveCollateral,
wantMinted: opts.wantMinted,
offerId: opts.offerId,
Expand Down Expand Up @@ -104,7 +104,7 @@ export const makeVaultsCommand = logger => {
);

const offer = Offers.vaults.AdjustBalances(
agoricNames.brand,
agoricNames,
{
giveCollateral: opts.giveCollateral,
wantCollateral: opts.wantCollateral,
Expand Down Expand Up @@ -145,7 +145,7 @@ export const makeVaultsCommand = logger => {
);

const offer = Offers.vaults.CloseVault(
agoricNames.brand,
agoricNames,
{
giveMinted: opts.giveMinted,
offerId: opts.offerId,
Expand Down
42 changes: 0 additions & 42 deletions packages/agoric-cli/src/lib/wallet.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { boardSlottingMarshaller, makeRpcUtils } from './rpc.js';
/** @typedef {import('@agoric/smart-wallet/src/smartWallet.js').CurrentWalletRecord} CurrentWalletRecord */
/** @typedef {import('@agoric/vats/tools/board-utils.js').AgoricNamesRemotes} AgoricNamesRemotes */

const { values } = Object;
const { Fail } = assert;
const marshaller = boardSlottingMarshaller();

Expand Down Expand Up @@ -271,44 +270,3 @@ export const makeWalletUtils = async (
pollOffer,
};
};

/**
* @param {{
* brand: Record<string, Brand>,
* vbankAsset: Record<string, { brand: Brand, displayInfo: DisplayInfo }>,
* }} agoricNames
* @param {(msg: string) => Error} makeError error constructor
* @returns {(a: string) => Amount<'nat'>}
*/
export const makeParseAmount =
(agoricNames, makeError = msg => RangeError(msg)) =>
opt => {
assert.typeof(opt, 'string', 'parseAmount expected string');
const m = opt.match(/^(?<value>[\d_]+(\.[\d_]+)?)(?<brand>[A-Z]\w*?)$/);
if (!m || !m.groups) {
throw makeError(`invalid amount: ${opt}`);
}
const anyBrand = agoricNames.brand[m.groups.brand];
if (!anyBrand) {
throw makeError(`unknown brand: ${m.groups.brand}`);
}
const assetDesc = values(agoricNames.vbankAsset).find(
d => d.brand === anyBrand,
);
if (!assetDesc) {
throw makeError(`unknown brand: ${m.groups.brand}`);
}
const { displayInfo } = assetDesc;
if (!displayInfo.decimalPlaces || displayInfo.assetKind !== 'nat') {
throw makeError(`bad brand: ${displayInfo}`);
}
const value = BigInt(
Number(m.groups.value.replace(/_/g, '')) *
10 ** displayInfo.decimalPlaces,
);
/** @type {Brand<'nat'>} */
// @ts-expect-error dynamic cast
const natBrand = anyBrand;
const amt = { value, brand: natBrand };
return amt;
};
1 change: 0 additions & 1 deletion packages/inter-protocol/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
"@endo/far": "^0.2.18",
"@endo/marshal": "^0.8.5",
"@endo/nat": "^4.1.27",
"agoric": "^0.21.1",
"jessie.js": "^0.3.2"
},
"devDependencies": {
Expand Down
Loading

0 comments on commit 7632299

Please sign in to comment.