From cab13bc28222e67205a4af0fc56b588c05d24da7 Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Wed, 4 Sep 2024 11:16:28 -0700 Subject: [PATCH 1/3] lint: checkJs --- packages/synthetic-chain/src/lib/commonUpgradeHelpers.ts | 2 +- packages/synthetic-chain/src/lib/econHelpers.js | 9 +++++++++ packages/synthetic-chain/src/lib/vat-status.js | 2 ++ packages/synthetic-chain/tsconfig.json | 3 ++- 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/packages/synthetic-chain/src/lib/commonUpgradeHelpers.ts b/packages/synthetic-chain/src/lib/commonUpgradeHelpers.ts index 63b6bef8..740d309f 100644 --- a/packages/synthetic-chain/src/lib/commonUpgradeHelpers.ts +++ b/packages/synthetic-chain/src/lib/commonUpgradeHelpers.ts @@ -122,7 +122,7 @@ export const calculateWalletState = async ( export const executeOffer = async ( address: string, - offerPromise: Promise, + offerPromise: string | Promise, ) => { const offerPath = await mkTemp('agops.XXX'); const offer = await offerPromise; diff --git a/packages/synthetic-chain/src/lib/econHelpers.js b/packages/synthetic-chain/src/lib/econHelpers.js index 2f56d029..231e011f 100644 --- a/packages/synthetic-chain/src/lib/econHelpers.js +++ b/packages/synthetic-chain/src/lib/econHelpers.js @@ -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), ); }; @@ -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', diff --git a/packages/synthetic-chain/src/lib/vat-status.js b/packages/synthetic-chain/src/lib/vat-status.js index 345a856b..e08997fd 100644 --- a/packages/synthetic-chain/src/lib/vat-status.js +++ b/packages/synthetic-chain/src/lib/vat-status.js @@ -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)); @@ -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 }; }; diff --git a/packages/synthetic-chain/tsconfig.json b/packages/synthetic-chain/tsconfig.json index 4f0ad6de..a8ec7c73 100644 --- a/packages/synthetic-chain/tsconfig.json +++ b/packages/synthetic-chain/tsconfig.json @@ -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", From ebf02886227a19bea20dc7d3df53cdf737b5f127 Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Wed, 4 Sep 2024 11:08:09 -0700 Subject: [PATCH 2/3] chore(types): fix getInstanceBoardId --- packages/synthetic-chain/src/lib/vstorage.js | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/packages/synthetic-chain/src/lib/vstorage.js b/packages/synthetic-chain/src/lib/vstorage.js index 0cbf22bd..d2fcdc09 100644 --- a/packages/synthetic-chain/src/lib/vstorage.js +++ b/packages/synthetic-chain/src/lib/vstorage.js @@ -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); /** @@ -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); @@ -51,7 +58,7 @@ export const getQuoteBody = async path => { /** * * @param {string} instanceName - * @returns {string | null} boardId of the named instance in agoricNames + * @returns {Promise} boardId of the named instance in agoricNames */ export const getInstanceBoardId = async instanceName => { const instanceRec = await queryVstorage(`published.agoricNames.instance`); From 6b24e395dcebdd8817cfd1be04f4764d9d336bfe Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Wed, 4 Sep 2024 11:20:31 -0700 Subject: [PATCH 3/3] chore: release 0.2.1 --- packages/synthetic-chain/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/synthetic-chain/package.json b/packages/synthetic-chain/package.json index fdb26ac6..e7fd20b7 100644 --- a/packages/synthetic-chain/package.json +++ b/packages/synthetic-chain/package.json @@ -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"