Skip to content

Commit

Permalink
Merge pull request #173 from Agoric/ta/fix-lint
Browse files Browse the repository at this point in the history
fix lint and getInstanceBoardId type
  • Loading branch information
turadg authored Sep 4, 2024
2 parents 643068f + 6b24e39 commit 45c6389
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/synthetic-chain/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@agoric/synthetic-chain",
"version": "0.2.0",
"version": "0.2.1",
"description": "Utilities to build a chain and test proposals atop it",
"bin": {
"synthetic-chain": "dist/cli/cli.js"
Expand Down
2 changes: 1 addition & 1 deletion packages/synthetic-chain/src/lib/commonUpgradeHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export const calculateWalletState = async (

export const executeOffer = async (
address: string,
offerPromise: Promise<string>,
offerPromise: string | Promise<string>,
) => {
const offerPath = await mkTemp('agops.XXX');
const offer = await offerPromise;
Expand Down
9 changes: 9 additions & 0 deletions packages/synthetic-chain/src/lib/econHelpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,16 @@ import { queryVstorage, getQuoteBody, getInstanceBoardId } from './vstorage.js';
const ORACLE_ADDRESSES = [GOV1ADDR, GOV2ADDR, GOV3ADDR];

// TODO return the id of the new vault so subsequent commands can use it
/**
*
* @param {string} address
* @param {string} mint
* @param {string} collateral
*/
export const openVault = (address, mint, collateral) => {
return executeOffer(
address,
// @ts-expect-error could return string[] but not in this case
agops.vaults('open', '--wantMinted', mint, '--giveCollateral', collateral),
);
};
Expand Down Expand Up @@ -40,12 +47,14 @@ export const adjustVault = (address, vaultId, vaultParams) => {
params = [...params, '--giveMinted', vaultParams.giveMinted];
}

// @ts-expect-error could return string[] but not in this case
return executeOffer(address, agops.vaults(...params));
};

export const closeVault = (address, vaultId, mint) => {
return executeOffer(
address,
// @ts-expect-error could return string[] but not in this case
agops.vaults(
'close',
'--vaultId',
Expand Down
2 changes: 2 additions & 0 deletions packages/synthetic-chain/src/lib/vat-status.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const makeSwingstore = db => {
const sql = dbTool(db);

/** @param {string} key */
// @ts-expect-error sqlite typedefs
const kvGet = key => sql.get`select * from kvStore where key = ${key}`.value;
/** @param {string} key */
const kvGetJSON = key => JSON.parse(kvGet(key));
Expand Down Expand Up @@ -77,6 +78,7 @@ export const getVatDetails = async vatName => {
const vatInfo = kStore.lookupVat(vatID);

const source = vatInfo.source();
// @ts-expect-error sqlite typedefs
const { incarnation } = vatInfo.currentSpan();
return { vatName, vatID, incarnation, ...source };
};
Expand Down
19 changes: 13 additions & 6 deletions packages/synthetic-chain/src/lib/vstorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@ import { agd } from './cliHelper.js';
const { freeze: harden } = Object; // XXX

// from '@agoric/internal/src/lib-chainStorage.js';
/** @type {(cell: unknown) => cell is { blockHeight: number;values: unknown[] }} cell */
const isStreamCell = cell =>
cell &&
typeof cell === 'object' &&
Array.isArray(cell.values) &&
typeof cell.blockHeight === 'string' &&
/^0$|^[1-9][0-9]*$/.test(cell.blockHeight);
!!(
cell &&
typeof cell === 'object' &&
'values' in cell &&
Array.isArray(cell.values) &&
'blockHeight' in cell &&
typeof cell.blockHeight === 'string' &&
/^0$|^[1-9][0-9]*$/.test(cell.blockHeight)
);
harden(isStreamCell);

/**
Expand Down Expand Up @@ -37,10 +42,12 @@ export const extractStreamCellValue = (data, index = -1) => {
};
harden(extractStreamCellValue);

/** @param {string} path */
export const queryVstorage = path =>
agd.query('vstorage', 'data', '--output', 'json', path);

// XXX use endo/marshal?
/** @param {string} path */
export const getQuoteBody = async path => {
const queryOut = await queryVstorage(path);

Expand All @@ -51,7 +58,7 @@ export const getQuoteBody = async path => {
/**
*
* @param {string} instanceName
* @returns {string | null} boardId of the named instance in agoricNames
* @returns {Promise<string | null>} boardId of the named instance in agoricNames
*/
export const getInstanceBoardId = async instanceName => {
const instanceRec = await queryVstorage(`published.agoricNames.instance`);
Expand Down
3 changes: 2 additions & 1 deletion packages/synthetic-chain/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"allowJs": true,
"checkJs": false, // opt in
"checkJs": true,
"strict": true,
"noImplicitAny": false,
"maxNodeModuleJsDepth": 2,
"module": "ES2022",
"moduleResolution": "Node",
Expand Down

0 comments on commit 45c6389

Please sign in to comment.