From fbef6411fbcae072486e0c6a8370c628d2dee646 Mon Sep 17 00:00:00 2001 From: 0xPatrick Date: Tue, 4 Jun 2024 14:36:28 -0400 Subject: [PATCH 01/19] fix(vlocalchain): sdkerrors.Wrap is deprecated --- golang/cosmos/x/vlocalchain/handler.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/golang/cosmos/x/vlocalchain/handler.go b/golang/cosmos/x/vlocalchain/handler.go index ff11eb722cd..0f9a917e18b 100644 --- a/golang/cosmos/x/vlocalchain/handler.go +++ b/golang/cosmos/x/vlocalchain/handler.go @@ -3,6 +3,7 @@ package vlocalchain import ( "fmt" + sdkioerrors "cosmossdk.io/errors" "github.com/Agoric/agoric-sdk/golang/cosmos/x/vlocalchain/keeper" sdk "github.com/cosmos/cosmos-sdk/types" sdkerrors "github.com/cosmos/cosmos-sdk/types/errors" @@ -14,7 +15,7 @@ func NewHandler(keeper keeper.Keeper) sdk.Handler { switch msg := msg.(type) { default: errMsg := fmt.Sprintf("Unrecognized vlocalchain Msg type: %T", msg) - return nil, sdkerrors.Wrap(sdkerrors.ErrUnknownRequest, errMsg) + return nil, sdkioerrors.Wrap(sdkerrors.ErrUnknownRequest, errMsg) } } } From 183c0727da0414d81df8027ce658cd70f4936d2a Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Tue, 4 Jun 2024 13:52:53 -0700 Subject: [PATCH 02/19] feat(typeGuards): CosmosChainInfoShape Co-Authored-By: Dan Connolly --- packages/orchestration/src/typeGuards.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/packages/orchestration/src/typeGuards.js b/packages/orchestration/src/typeGuards.js index 79d48ad3f1c..5c556ca228e 100644 --- a/packages/orchestration/src/typeGuards.js +++ b/packages/orchestration/src/typeGuards.js @@ -37,3 +37,19 @@ export const IBCTransferOptionsShape = M.splitRecord( memo: M.string(), }, ); + +export const CosmosChainInfoShape = M.splitRecord( + { + chainId: M.string(), + connections: M.record(), + stakingTokens: M.arrayOf({ denom: M.string() }), + }, + { + icaEnabled: M.boolean(), + icqEnabled: M.boolean(), + pfmEnabled: M.boolean(), + ibcHooksEnabled: M.boolean(), + allowedMessages: M.arrayOf(M.string()), + allowedQueries: M.arrayOf(M.string()), + }, +); From f7ed627e369f7b0430a891491543029b34a7e2d7 Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Tue, 4 Jun 2024 13:53:01 -0700 Subject: [PATCH 03/19] feat(typeGuards): DelegationShape Co-Authored-By: Dan Connolly --- packages/orchestration/src/typeGuards.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/orchestration/src/typeGuards.js b/packages/orchestration/src/typeGuards.js index 5c556ca228e..9ba142f57ec 100644 --- a/packages/orchestration/src/typeGuards.js +++ b/packages/orchestration/src/typeGuards.js @@ -24,7 +24,11 @@ export const ChainAmountShape = harden({ denom: M.string(), value: M.nat() }); export const AmountArgShape = M.or(AmountShape, ChainAmountShape); -export const DelegationShape = M.record(); // TODO: DelegationShape fields +export const DelegationShape = harden({ + delegatorAddress: M.string(), + validatorAddress: M.string(), + shares: M.string(), // TODO: bigint? +}); export const IBCTransferOptionsShape = M.splitRecord( {}, From 303318dacd06e758bdfa693a316fa2db7584235c Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Tue, 4 Jun 2024 15:13:15 -0700 Subject: [PATCH 04/19] test: clarify intentional type errors --- packages/orchestration/test/utils/address.test.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/orchestration/test/utils/address.test.ts b/packages/orchestration/test/utils/address.test.ts index b637687d5b9..5e624feb000 100644 --- a/packages/orchestration/test/utils/address.test.ts +++ b/packages/orchestration/test/utils/address.test.ts @@ -7,11 +7,11 @@ import { } from '../../src/utils/address.js'; test('makeICAChannelAddress', t => { - // @ts-expect-error expected two arguments + // @ts-expect-error intentional t.throws(() => makeICAChannelAddress(), { message: 'hostConnectionId is required', }); - // @ts-expect-error expected two arguments + // @ts-expect-error intentional t.throws(() => makeICAChannelAddress('connection-0'), { message: 'controllerConnectionId is required', }); @@ -74,7 +74,7 @@ test('findAddressField', t => { }); test('makeICQChannelAddress', t => { - // @ts-expect-error expected 1 argument + // @ts-expect-error intentional t.throws(() => makeICQChannelAddress(), { message: 'controllerConnectionId is required', }); From 8c6c757f744be6d284ca809d009c8b1869f05c03 Mon Sep 17 00:00:00 2001 From: Dan Connolly Date: Tue, 21 May 2024 15:39:43 -0500 Subject: [PATCH 05/19] chore: include stakingTokens denom in CosmosChainInfo --- packages/orchestration/src/cosmos-api.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/packages/orchestration/src/cosmos-api.ts b/packages/orchestration/src/cosmos-api.ts index 134628e4462..702a2d30e46 100644 --- a/packages/orchestration/src/cosmos-api.ts +++ b/packages/orchestration/src/cosmos-api.ts @@ -77,6 +77,11 @@ export type CosmosChainInfo = { */ allowedMessages: TypeUrl[]; allowedQueries: TypeUrl[]; + + /** + * cf https://github.com/cosmos/chain-registry/blob/master/chain.schema.json#L117 + */ + stakingTokens?: Array<{ denom: string }>; }; export interface StakingAccountQueries { From 9d38e2eb19496b85e6abdf7fcd7cf16c4581b3ce Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Tue, 4 Jun 2024 14:18:07 -0700 Subject: [PATCH 06/19] feat: registerChain --- packages/orchestration/src/facade.js | 59 ++++++++++----- packages/orchestration/test/facade.test.ts | 86 ++++++++++++++++++++++ 2 files changed, 126 insertions(+), 19 deletions(-) create mode 100644 packages/orchestration/test/facade.test.ts diff --git a/packages/orchestration/src/facade.js b/packages/orchestration/src/facade.js index 33fb0107e33..6ee549fd326 100644 --- a/packages/orchestration/src/facade.js +++ b/packages/orchestration/src/facade.js @@ -1,7 +1,11 @@ /** @file Orchestration service */ +import { makeScalarBigMapStore } from '@agoric/vat-data'; import { E } from '@endo/far'; +import { M } from '@endo/patterns'; +import { wellKnownChainInfo } from './chain-info.js'; import { prepareCosmosOrchestrationAccount } from './exos/cosmosOrchestrationAccount.js'; +import { CosmosChainInfoShape } from './typeGuards.js'; /** * @import {Zone} from '@agoric/zone'; @@ -82,27 +86,21 @@ const makeLocalChainFacade = localchain => { }; /** - * @template {string} C - * @param {C} name + * @template {CosmosChainInfo} CCI + * @param {CCI} chainInfo * @param {object} io * @param {Remote} io.orchestration * @param {Remote} io.timer * @param {ZCF} io.zcf * @param {Zone} io.zone - * @returns {Chain} + * @returns {Chain} */ -const makeRemoteChainFacade = (name, { orchestration, timer, zcf, zone }) => { - const chainInfo = /** @type {CosmosChainInfo} */ ({ - allegedName: name, - chainId: 'fixme', - connections: {}, - icaEnabled: true, - icqEnabled: true, - pfmEnabled: true, - ibcHooksEnabled: true, - allowedMessages: [], - allowedQueries: [], - }); +const makeRemoteChainFacade = ( + chainInfo, + { orchestration, timer, zcf, zone }, +) => { + const name = chainInfo.chainId; + const makeRecorderKit = () => anyVal; const makeCosmosOrchestrationAccount = prepareCosmosOrchestrationAccount( zone.subZone(name), @@ -112,7 +110,7 @@ const makeRemoteChainFacade = (name, { orchestration, timer, zcf, zone }) => { return { getChainInfo: async () => chainInfo, - /** @returns {Promise>} */ + /** @returns {Promise>} */ makeAccount: async () => { console.log('makeAccount for', name); @@ -165,12 +163,33 @@ export const makeOrchestrationFacade = ({ orchestrationService, }); + const chainInfos = makeScalarBigMapStore('chainInfos', { + keyShape: M.string(), + valueShape: CosmosChainInfoShape, + }); + return { + /** + * Register a new chain in a heap store. The name will override a name in + * well known chain names. + * + * This registration will not surve a reincarnation of the vat so if the + * chain is not yet in the well known names at that point, it will have to + * be registered again. In an unchanged contract `start` the call will + * happen again naturally. + * + * @param {string} name + * @param {ChainInfo} chainInfo + */ + registerChain(name, chainInfo) { + chainInfos.init(name, chainInfo); + }, /** * @template Context * @template {any[]} Args - * @param {string} durableName - * @param {Context} ctx + * @param {string} durableName - the orchestration flow identity in the zone + * (to resume across upgrades) + * @param {Context} ctx - values to pass through the async flow membrane * @param {(orc: Orchestrator, ctx2: Context, ...args: Args) => object} fn * @returns {(...args: Args) => Promise} */ @@ -182,7 +201,9 @@ export const makeOrchestrationFacade = ({ return makeLocalChainFacade(localchain); } - return makeRemoteChainFacade(name, { + const chainInfo = chainInfos.get(name); + + return makeRemoteChainFacade(chainInfo, { orchestration: orchestrationService, timer: timerService, zcf, diff --git a/packages/orchestration/test/facade.test.ts b/packages/orchestration/test/facade.test.ts new file mode 100644 index 00000000000..bfe30bf6a9a --- /dev/null +++ b/packages/orchestration/test/facade.test.ts @@ -0,0 +1,86 @@ +import { test as anyTest } from '@agoric/zoe/tools/prepare-test-env-ava.js'; + +import { setupZCFTest } from '@agoric/zoe/test/unitTests/zcf/setupZcfTest.js'; +import type { CosmosChainInfo } from '../src/cosmos-api.js'; +import { makeOrchestrationFacade } from '../src/facade.js'; +import type { Chain } from '../src/orchestration-api.js'; +import { commonSetup } from './supports.js'; + +const test = anyTest; + +export const mockChainInfo: CosmosChainInfo = harden({ + chainId: 'mock-1', + connections: {}, + icaEnabled: false, + icqEnabled: false, + pfmEnabled: false, + ibcHooksEnabled: false, + allowedMessages: [], + allowedQueries: [], + stakingTokens: [{ denom: 'umock' }], +}); + +test('chain info', async t => { + const { bootstrap } = await commonSetup(t); + + const zone = bootstrap.rootZone; + + const { zcf } = await setupZCFTest(); + + const { registerChain, orchestrate } = makeOrchestrationFacade({ + localchain: bootstrap.localchain, + orchestrationService: bootstrap.orchestration, + storageNode: bootstrap.storage.rootNode, + timerService: bootstrap.timer, + zcf, + zone, + }); + + registerChain('mock', mockChainInfo); + + const handle = orchestrate('mock', {}, async orc => { + return orc.getChain('mock'); + }); + + const result = (await handle()) as Chain<'mock'>; + t.deepEqual(await result.getChainInfo(), mockChainInfo); +}); + +test('contract upgrade', async t => { + const { bootstrap } = await commonSetup(t); + + const zone = bootstrap.rootZone; + + const { zcf } = await setupZCFTest(); + + // Register once + { + const { registerChain } = makeOrchestrationFacade({ + localchain: bootstrap.localchain, + orchestrationService: bootstrap.orchestration, + storageNode: bootstrap.storage.rootNode, + timerService: bootstrap.timer, + zcf, + zone, + }); + registerChain('mock', mockChainInfo); + + // cannot register again in this incarnation + t.throws(() => registerChain('mock', mockChainInfo), { + message: 'key "mock" already registered in collection "chainInfos"', + }); + } + + // Simulate running again in a new incarnation with the same zone + { + const { registerChain } = makeOrchestrationFacade({ + localchain: bootstrap.localchain, + orchestrationService: bootstrap.orchestration, + storageNode: bootstrap.storage.rootNode, + timerService: bootstrap.timer, + zcf, + zone, + }); + registerChain('mock', mockChainInfo); + } +}); From bdd68cfaef52d49f90346c483474a2e18a6312b5 Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Tue, 4 Jun 2024 14:54:17 -0700 Subject: [PATCH 07/19] chore(types): Chain parameterized by ChainInfo --- packages/orchestration/src/chain-info.js | 60 +++++++++++++++++ packages/orchestration/src/chain-info.ts | 64 ------------------- packages/orchestration/src/cosmos-api.ts | 12 ++++ packages/orchestration/src/facade.js | 14 ++-- .../orchestration/src/orchestration-api.ts | 30 +++++---- packages/orchestration/test/facade.test.ts | 2 +- 6 files changed, 102 insertions(+), 80 deletions(-) create mode 100644 packages/orchestration/src/chain-info.js delete mode 100644 packages/orchestration/src/chain-info.ts diff --git a/packages/orchestration/src/chain-info.js b/packages/orchestration/src/chain-info.js new file mode 100644 index 00000000000..fe7352ca004 --- /dev/null +++ b/packages/orchestration/src/chain-info.js @@ -0,0 +1,60 @@ +// UNTIL https://github.com/Agoric/agoric-sdk/issues/8879 + +/** @file temporary static lookup of chain info */ + +/** @import {CosmosChainInfo, EthChainInfo} from './types.js'; */ + +/** @typedef {CosmosChainInfo | EthChainInfo} ChainInfo */ + +// TODO generate this automatically with a build script drawing on data sources such as https://github.com/cosmos/chain-registry + +export const wellKnownChainInfo = + /** @satisfies {Record} */ ( + harden({ + // https://github.com/cosmos/chain-registry/blob/master/stride/chain.json + stride: { + chainId: 'stride-1', + connections: {}, + icaEnabled: true, + icqEnabled: true, + pfmEnabled: true, + ibcHooksEnabled: true, + allowedMessages: [], + allowedQueries: [], + stakingTokens: [{ denom: 'ustride' }], + }, + cosmos: { + chainId: 'cosmoshub-4', + connections: {}, + icaEnabled: true, + icqEnabled: true, + pfmEnabled: true, + ibcHooksEnabled: true, + allowedMessages: [], + allowedQueries: [], + stakingTokens: [{ denom: 'uatom' }], + }, + celestia: { + chainId: 'celestia', + connections: {}, + icaEnabled: true, + icqEnabled: true, + pfmEnabled: true, + ibcHooksEnabled: true, + allowedMessages: [], + allowedQueries: [], + stakingTokens: [{ denom: 'utia' }], + }, + osmosis: { + chainId: 'osmosis-1', + connections: {}, + icaEnabled: true, + icqEnabled: true, + pfmEnabled: true, + ibcHooksEnabled: true, + allowedMessages: [], + allowedQueries: [], + stakingTokens: [{ denom: 'uosmo' }], + }, + }) + ); diff --git a/packages/orchestration/src/chain-info.ts b/packages/orchestration/src/chain-info.ts deleted file mode 100644 index c916d8f8019..00000000000 --- a/packages/orchestration/src/chain-info.ts +++ /dev/null @@ -1,64 +0,0 @@ -/** - * @file static declaration of known chain types will allow type support for - * additional chain-specific operations like `liquidStake` - */ - -import type { - CosmosChainInfo, - EthChainInfo, - IcaAccount, - ICQConnection, - LiquidStakingMethods, - StakingAccountActions, - StakingAccountQueries, -} from './types.js'; - -export type ChainInfo = CosmosChainInfo | EthChainInfo; - -// TODO generate this automatically with a build script drawing on data sources such as https://github.com/cosmos/chain-registry - -// XXX methods ad-hoc and not fully accurate -export type KnownChains = Record & { - stride: { - info: CosmosChainInfo; - methods: IcaAccount & - ICQConnection & - StakingAccountActions & - StakingAccountQueries & - LiquidStakingMethods; - }; - cosmos: { - info: CosmosChainInfo; - methods: IcaAccount & - ICQConnection & - StakingAccountActions & - StakingAccountQueries; - }; - agoric: { - info: CosmosChainInfo; - methods: { - // TODO reference type from #8624 `packages/vats/src/localchain.js` - /** - * Register a hook to intercept an incoming IBC Transfer and handle it. - * Calling without arguments will unregister the hook. - */ - interceptTransfer: (tap?: { - upcall: (args: any) => Promise; - }) => Promise; - }; - }; - celestia: { - info: CosmosChainInfo; - methods: IcaAccount & - ICQConnection & - StakingAccountActions & - StakingAccountQueries; - }; - osmosis: { - info: CosmosChainInfo; - methods: IcaAccount & - ICQConnection & - StakingAccountActions & - StakingAccountQueries; - }; -}; diff --git a/packages/orchestration/src/cosmos-api.ts b/packages/orchestration/src/cosmos-api.ts index 702a2d30e46..04cebb79777 100644 --- a/packages/orchestration/src/cosmos-api.ts +++ b/packages/orchestration/src/cosmos-api.ts @@ -224,3 +224,15 @@ export type IBCMsgTransferOptions = { timeoutTimestamp?: MsgTransfer['timeoutTimestamp']; memo?: string; }; + +export type CosmosChainAccountMethods = + (CCI extends { + icaEnabled: true; + } + ? IcaAccount + : {}) & + CCI extends { + stakingTokens: {}; + } + ? StakingAccountActions + : {}; diff --git a/packages/orchestration/src/facade.js b/packages/orchestration/src/facade.js index 6ee549fd326..480a608a4c8 100644 --- a/packages/orchestration/src/facade.js +++ b/packages/orchestration/src/facade.js @@ -13,7 +13,7 @@ import { CosmosChainInfoShape } from './typeGuards.js'; * @import {LocalChain} from '@agoric/vats/src/localchain.js'; * @import {Remote} from '@agoric/internal'; * @import {OrchestrationService} from './service.js'; - * @import {Chain, ChainInfo, CosmosChainInfo, KnownChains, OrchestrationAccount, Orchestrator} from './types.js'; + * @import {Chain, ChainInfo, CosmosChainInfo, OrchestrationAccount, Orchestrator} from './types.js'; */ /** @type {any} */ @@ -93,7 +93,7 @@ const makeLocalChainFacade = localchain => { * @param {Remote} io.timer * @param {ZCF} io.zcf * @param {Zone} io.zone - * @returns {Chain} + * @returns {Chain} */ const makeRemoteChainFacade = ( chainInfo, @@ -110,7 +110,7 @@ const makeRemoteChainFacade = ( return { getChainInfo: async () => chainInfo, - /** @returns {Promise>} */ + /** @returns {Promise>} */ makeAccount: async () => { console.log('makeAccount for', name); @@ -127,6 +127,7 @@ const makeRemoteChainFacade = ( // FIXME look up real values const bondDenom = name; + // @ts-expect-error XXX dynamic method availability return makeCosmosOrchestrationAccount(address, bondDenom, { account: icaAccount, storageNode: anyVal, @@ -201,7 +202,12 @@ export const makeOrchestrationFacade = ({ return makeLocalChainFacade(localchain); } - const chainInfo = chainInfos.get(name); + // TODO look up well known realistically https://github.com/Agoric/agoric-sdk/issues/9063 + const chainInfo = chainInfos.has(name) + ? chainInfos.get(name) + : // @ts-expect-error may be undefined + wellKnownChainInfo[name]; + assert(chainInfo, `unknown chain ${name}`); return makeRemoteChainFacade(chainInfo, { orchestration: orchestrationService, diff --git a/packages/orchestration/src/orchestration-api.ts b/packages/orchestration/src/orchestration-api.ts index 0f022b3c336..9653caae2ae 100644 --- a/packages/orchestration/src/orchestration-api.ts +++ b/packages/orchestration/src/orchestration-api.ts @@ -12,7 +12,15 @@ import type { } from '@agoric/ertp/src/types.js'; import type { LocalChainAccount } from '@agoric/vats/src/localchain.js'; import type { Timestamp } from '@agoric/time'; -import type { IBCMsgTransferOptions, KnownChains } from './types.js'; +import type { + ChainInfo, + CosmosChainAccountMethods, + CosmosChainInfo, + IBCMsgTransferOptions, + wellKnownChainInfo, +} from './types.js'; + +type KnownChains = typeof wellKnownChainInfo; /** * A denom that designates a path to a token type on some blockchain. @@ -57,8 +65,8 @@ export type ChainAddress = { addressEncoding: 'bech32' | 'ethereum'; }; -export type OrchestrationAccount = - OrchestrationAccountI & KnownChains[C]['methods']; +export type OrchestrationAccount = OrchestrationAccountI & + (CI extends CosmosChainInfo ? CosmosChainAccountMethods : never); /** * An object for access the core functions of a remote chain. @@ -66,15 +74,15 @@ export type OrchestrationAccount = * Note that "remote" can mean the local chain; it's just that * accounts are treated as remote/arms length for consistency. */ -export interface Chain { - getChainInfo: () => Promise; +export interface Chain { + getChainInfo: () => Promise; // "makeAccount" suggests an operation within a vat /** * Creates a new account on the remote chain. * @returns an object that controls a new remote account on Chain */ - makeAccount: () => Promise>; + makeAccount: () => Promise>; // FUTURE supply optional port object; also fetch port object // TODO provide a way to get the local denom/brand/whatever for this chain @@ -84,9 +92,9 @@ export interface Chain { * Provided in the callback to `orchestrate()`. */ export interface Orchestrator { - // TODO we need a way to work with a chain its native way vs generic way - // E.g. an Osmosis delegate that looks Cosmos-y or no different from an Ethereum delegate - getChain: (chainName: C) => Promise>; + getChain: ( + chainName: C, + ) => Promise>; makeLocalAccount: () => Promise; /** @@ -104,9 +112,9 @@ export interface Orchestrator { /** The well-known Brand on Agoric for the direct asset */ brand?: Brand; /** The Chain at which the argument `denom` exists (where the asset is currently held) */ - chain: Chain; + chain: Chain; /** The Chain that is the issuer of the underlying asset */ - base: Chain; + base: Chain; /** the Denom for the underlying asset on its issuer chain */ baseDenom: Denom; }; diff --git a/packages/orchestration/test/facade.test.ts b/packages/orchestration/test/facade.test.ts index bfe30bf6a9a..10fdfa1c162 100644 --- a/packages/orchestration/test/facade.test.ts +++ b/packages/orchestration/test/facade.test.ts @@ -42,7 +42,7 @@ test('chain info', async t => { return orc.getChain('mock'); }); - const result = (await handle()) as Chain<'mock'>; + const result = (await handle()) as Chain; t.deepEqual(await result.getChainInfo(), mockChainInfo); }); From 82115f1dfc6e834beecdc8def2b2a684d3952d06 Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Tue, 4 Jun 2024 15:35:19 -0700 Subject: [PATCH 08/19] fix: get bondDenom from chainInfo --- packages/orchestration/src/facade.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/orchestration/src/facade.js b/packages/orchestration/src/facade.js index 480a608a4c8..dc4840b9aac 100644 --- a/packages/orchestration/src/facade.js +++ b/packages/orchestration/src/facade.js @@ -112,8 +112,6 @@ const makeRemoteChainFacade = ( getChainInfo: async () => chainInfo, /** @returns {Promise>} */ makeAccount: async () => { - console.log('makeAccount for', name); - // FIXME look up real values const hostConnectionId = 'connection-1'; const controllerConnectionId = 'connection-2'; @@ -125,8 +123,12 @@ const makeRemoteChainFacade = ( const address = await E(icaAccount).getAddress(); - // FIXME look up real values - const bondDenom = name; + const [{ denom: bondDenom }] = chainInfo.stakingTokens || [ + { + denom: null, + }, + ]; + assert(bondDenom, 'missing bondDenom'); // @ts-expect-error XXX dynamic method availability return makeCosmosOrchestrationAccount(address, bondDenom, { account: icaAccount, From 6d597fd83d7f0a003bcc5a5cd1a138b74114d01f Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Tue, 4 Jun 2024 15:11:13 -0700 Subject: [PATCH 09/19] chore: facade reconciliation --- packages/orchestration/src/facade.js | 31 +++++++++++++++++----------- packages/vats/src/localchain.js | 2 +- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/packages/orchestration/src/facade.js b/packages/orchestration/src/facade.js index dc4840b9aac..b9ea70bfeea 100644 --- a/packages/orchestration/src/facade.js +++ b/packages/orchestration/src/facade.js @@ -19,7 +19,8 @@ import { CosmosChainInfoShape } from './typeGuards.js'; /** @type {any} */ const anyVal = null; -// FIXME should be configurable +// FIXME look up real values +// UNTIL https://github.com/Agoric/agoric-sdk/issues/9063 const mockLocalChainInfo = { allegedName: 'agoric', allowedMessages: [], @@ -43,36 +44,41 @@ const makeLocalChainFacade = localchain => { return mockLocalChainInfo; }, - // @ts-expect-error FIXME promise resolution through membrane async makeAccount() { const account = await E(localchain).makeAccount(); return { - deposit(payment) { + async deposit(payment) { console.log('deposit got', payment); - return E(account).deposit(payment); + await E(account).deposit(payment); }, - async getAddress() { - const addressStr = await E(account).getAddress(); + getAddress() { + const addressStr = account.getAddress(); return { address: addressStr, chainId: mockLocalChainInfo.chainId, addressEncoding: 'bech32', }; }, - getBalance(_denom) { - // FIXME map denom to Brand - const brand = /** @type {any} */ (null); - return E(account).getBalance(brand); + async getBalance(denomArg) { + // FIXME look up real values + // UNTIL https://github.com/Agoric/agoric-sdk/issues/9211 + const [brand, denom] = + typeof denomArg === 'string' + ? [/** @type {any} */ (null), denomArg] + : [denomArg, 'FIXME']; + + const natAmount = await account.getBalance(brand); + return harden({ denom, value: natAmount.value }); }, getBalances() { throw new Error('not yet implemented'); }, - send(toAccount, amount) { + async send(toAccount, amount) { // FIXME implement console.log('send got', toAccount, amount); }, - transfer(amount, destination, opts) { + async transfer(amount, destination, opts) { // FIXME implement console.log('transfer got', amount, destination, opts); }, @@ -113,6 +119,7 @@ const makeRemoteChainFacade = ( /** @returns {Promise>} */ makeAccount: async () => { // FIXME look up real values + // UNTIL https://github.com/Agoric/agoric-sdk/issues/9063 const hostConnectionId = 'connection-1'; const controllerConnectionId = 'connection-2'; diff --git a/packages/vats/src/localchain.js b/packages/vats/src/localchain.js index b2fbefc48b9..1ec1441d6f8 100644 --- a/packages/vats/src/localchain.js +++ b/packages/vats/src/localchain.js @@ -45,7 +45,7 @@ const prepareLocalChainAccount = zone => (address, powers) => ({ address, ...powers, reserved: undefined }), { // Information that the account creator needs. - async getAddress() { + getAddress() { return this.state.address; }, /** @param {Brand<'nat'>} brand */ From dc0b9257f1222bac27e3d6e3cdd37923626d1306 Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Wed, 5 Jun 2024 10:42:52 -0700 Subject: [PATCH 10/19] chore: update type-coverage --- packages/ERTP/package.json | 2 +- packages/base-zone/package.json | 2 +- packages/boot/package.json | 2 +- packages/builders/package.json | 2 +- packages/cosmic-swingset/package.json | 2 +- packages/inter-protocol/package.json | 2 +- packages/internal/package.json | 2 +- packages/network/package.json | 2 +- packages/orchestration/package.json | 2 +- packages/smart-wallet/package.json | 2 +- packages/swing-store/package.json | 2 +- packages/vats/package.json | 2 +- packages/xsnap/package.json | 2 +- 13 files changed, 13 insertions(+), 13 deletions(-) diff --git a/packages/ERTP/package.json b/packages/ERTP/package.json index 74514915f05..76bc34e84e4 100644 --- a/packages/ERTP/package.json +++ b/packages/ERTP/package.json @@ -86,6 +86,6 @@ "access": "public" }, "typeCoverage": { - "atLeast": 91.21 + "atLeast": 91.22 } } diff --git a/packages/base-zone/package.json b/packages/base-zone/package.json index a1788d2de70..7adeeb7da22 100644 --- a/packages/base-zone/package.json +++ b/packages/base-zone/package.json @@ -56,6 +56,6 @@ "workerThreads": false }, "typeCoverage": { - "atLeast": 90.77 + "atLeast": 91.11 } } diff --git a/packages/boot/package.json b/packages/boot/package.json index d0b8d8bf54e..0cbfd4b5ae2 100644 --- a/packages/boot/package.json +++ b/packages/boot/package.json @@ -90,6 +90,6 @@ "workerThreads": false }, "typeCoverage": { - "atLeast": 86.74 + "atLeast": 87.28 } } diff --git a/packages/builders/package.json b/packages/builders/package.json index d9531fcee5b..0acd618d6c7 100644 --- a/packages/builders/package.json +++ b/packages/builders/package.json @@ -78,6 +78,6 @@ "workerThreads": false }, "typeCoverage": { - "atLeast": 74.23 + "atLeast": 74.36 } } diff --git a/packages/cosmic-swingset/package.json b/packages/cosmic-swingset/package.json index 5484a44753d..f60ec2e7204 100644 --- a/packages/cosmic-swingset/package.json +++ b/packages/cosmic-swingset/package.json @@ -68,6 +68,6 @@ "timeout": "20m" }, "typeCoverage": { - "atLeast": 80.48 + "atLeast": 80.49 } } diff --git a/packages/inter-protocol/package.json b/packages/inter-protocol/package.json index ebcc5ed2654..e95cbab9e9d 100644 --- a/packages/inter-protocol/package.json +++ b/packages/inter-protocol/package.json @@ -82,6 +82,6 @@ "access": "public" }, "typeCoverage": { - "atLeast": 95.87 + "atLeast": 95.85 } } diff --git a/packages/internal/package.json b/packages/internal/package.json index dc0d6adf6a6..0c893089470 100755 --- a/packages/internal/package.json +++ b/packages/internal/package.json @@ -56,6 +56,6 @@ "access": "public" }, "typeCoverage": { - "atLeast": 93.81 + "atLeast": 93.89 } } diff --git a/packages/network/package.json b/packages/network/package.json index c5c152cf2f8..7ba9f082f1b 100644 --- a/packages/network/package.json +++ b/packages/network/package.json @@ -65,6 +65,6 @@ "workerThreads": false }, "typeCoverage": { - "atLeast": 89.39 + "atLeast": 89.7 } } diff --git a/packages/orchestration/package.json b/packages/orchestration/package.json index a861179efe0..05a1cee587c 100644 --- a/packages/orchestration/package.json +++ b/packages/orchestration/package.json @@ -82,6 +82,6 @@ "access": "public" }, "typeCoverage": { - "atLeast": 97.38 + "atLeast": 97.17 } } diff --git a/packages/smart-wallet/package.json b/packages/smart-wallet/package.json index 2084c60f9d3..a98c41b6656 100644 --- a/packages/smart-wallet/package.json +++ b/packages/smart-wallet/package.json @@ -68,6 +68,6 @@ "access": "public" }, "typeCoverage": { - "atLeast": 94.35 + "atLeast": 94.3 } } diff --git a/packages/swing-store/package.json b/packages/swing-store/package.json index ff77bd5432b..a1972774c41 100644 --- a/packages/swing-store/package.json +++ b/packages/swing-store/package.json @@ -49,6 +49,6 @@ "timeout": "2m" }, "typeCoverage": { - "atLeast": 76.3 + "atLeast": 76.31 } } diff --git a/packages/vats/package.json b/packages/vats/package.json index d374c13c81f..d143015f69b 100644 --- a/packages/vats/package.json +++ b/packages/vats/package.json @@ -77,6 +77,6 @@ "workerThreads": false }, "typeCoverage": { - "atLeast": 91.27 + "atLeast": 91.11 } } diff --git a/packages/xsnap/package.json b/packages/xsnap/package.json index 0f9480f5d7f..3d67a418912 100644 --- a/packages/xsnap/package.json +++ b/packages/xsnap/package.json @@ -74,6 +74,6 @@ "workerThreads": false }, "typeCoverage": { - "atLeast": 94.04 + "atLeast": 93.95 } } From a744db8d7ca4cd238391904b9ce47c42111eadf1 Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Wed, 5 Jun 2024 09:30:49 -0700 Subject: [PATCH 11/19] lint(types): suppress error in export augmentation --- packages/ERTP/exported.d.ts | 1 + packages/governance/exported.d.ts | 1 + packages/internal/exported.d.ts | 1 + packages/notifier/exported.d.ts | 1 + packages/store/exported.d.ts | 1 + 5 files changed, 5 insertions(+) diff --git a/packages/ERTP/exported.d.ts b/packages/ERTP/exported.d.ts index c3dab4e11ff..4ab07be2621 100644 --- a/packages/ERTP/exported.d.ts +++ b/packages/ERTP/exported.d.ts @@ -19,6 +19,7 @@ import { Purse as _Purse, } from './src/types.js'; declare global { + // @ts-ignore TS2666: Exports and export assignments are not permitted in module augmentations. export { _Amount as Amount, _Brand as Brand, diff --git a/packages/governance/exported.d.ts b/packages/governance/exported.d.ts index a3336ac36dd..383c9944117 100644 --- a/packages/governance/exported.d.ts +++ b/packages/governance/exported.d.ts @@ -16,6 +16,7 @@ import { GovernableStartFn as _GovernableStartFn, } from './src/types.js'; declare global { + // @ts-ignore TS2666: Exports and export assignments are not permitted in module augmentations. export { _CommitteeElectoratePublic as CommitteeElectoratePublic, _GovernableStartFn as GovernableStartFn, diff --git a/packages/internal/exported.d.ts b/packages/internal/exported.d.ts index 043f11db074..792693d4958 100644 --- a/packages/internal/exported.d.ts +++ b/packages/internal/exported.d.ts @@ -15,6 +15,7 @@ import { } from './src/lib-chainStorage.js'; declare global { + // @ts-ignore TS2666: Exports and export assignments are not permitted in module augmentations. export { _ERef as ERef, _Marshaller as Marshaller, diff --git a/packages/notifier/exported.d.ts b/packages/notifier/exported.d.ts index 4709364a419..9b5fff20c15 100644 --- a/packages/notifier/exported.d.ts +++ b/packages/notifier/exported.d.ts @@ -21,6 +21,7 @@ import { } from './src/types.js'; declare global { + // @ts-ignore TS2666: Exports and export assignments are not permitted in module augmentations. export { _EachTopic as EachTopic, _IterableEachTopic as IterableEachTopic, diff --git a/packages/store/exported.d.ts b/packages/store/exported.d.ts index 800f1a2c54a..563c422026e 100644 --- a/packages/store/exported.d.ts +++ b/packages/store/exported.d.ts @@ -12,6 +12,7 @@ import { } from './src/types.js'; import { Pattern as _Pattern } from '@endo/patterns'; declare global { + // @ts-ignore TS2666: Exports and export assignments are not permitted in module augmentations. export { _LegacyMap as LegacyMap, _LegacyWeakMap as LegacyWeakMap, From 717a4c98aeadaa83897567b46d12b654b0a2cc72 Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Wed, 5 Jun 2024 09:32:28 -0700 Subject: [PATCH 12/19] fix(types): DataOnly import of Callable --- packages/internal/src/types.d.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/internal/src/types.d.ts b/packages/internal/src/types.d.ts index e54952e4ab2..9130d2a39e9 100644 --- a/packages/internal/src/types.d.ts +++ b/packages/internal/src/types.d.ts @@ -1,6 +1,7 @@ /* eslint-disable max-classes-per-file */ -import type { Callable, RemotableBrand } from '@endo/eventual-send'; +import type { RemotableBrand } from '@endo/eventual-send'; import type { Primitive } from '@endo/pass-style'; +import type { Callable } from './utils.js'; export declare class Callback any> { private iface: I; From c3aa4987ba156863bf7e589c97095552e701070f Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Wed, 5 Jun 2024 09:37:05 -0700 Subject: [PATCH 13/19] chore(deps): bump @types/estree to working version the one pulled in by `@rollup/pluginutils` was missing exports --- package.json | 1 + yarn.lock | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 5176862c300..c953447f0f7 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ }, "resolutions": { "**/protobufjs": "^7.2.6", + "**/@types/estree": "^1.0.0", "**/@typescript-eslint/typescript-estree": "^7.7.1" }, "engines": { diff --git a/yarn.lock b/yarn.lock index d096a8503d0..cbed3f4d19d 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3389,10 +3389,10 @@ "@types/estree" "*" "@types/json-schema" "*" -"@types/estree@*", "@types/estree@0.0.39": - version "0.0.39" - resolved "https://registry.yarnpkg.com/@types/estree/-/estree-0.0.39.tgz#e177e699ee1b8c22d23174caaa7422644389509f" - integrity sha512-EYNwp3bU+98cpU4lAWYYL7Zz+2gryWH1qbdDTidVd6hkiR6weksdbMadyXKXNPEkQFhXM+hVO9ZygomHXp+AIw== +"@types/estree@*", "@types/estree@0.0.39", "@types/estree@^1.0.0": + version "1.0.5" + resolved "https://registry.yarnpkg.com/@types/estree/-/estree-1.0.5.tgz#a6ce3e556e00fd9895dd872dd172ad0d4bd687f4" + integrity sha512-/kYRxGDLWzHOB7q+wtSUQlFrtcdUccpfy+X+9iMBpHK8QLLhx2wIPYuS5DYtR9Wa/YlZAbIovy7qVdB1Aq6Lyw== "@types/express-serve-static-core@^4.17.33": version "4.17.35" From 077240b3f205151b97afc61a4615cf3a83d6f9a3 Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Wed, 5 Jun 2024 09:39:01 -0700 Subject: [PATCH 14/19] fix(types): errors detected with libcheck --- packages/vats/src/core/chain-behaviors.js | 3 +++ packages/vats/src/core/core-eval-env.d.ts | 12 +++++----- packages/vats/src/core/types-ambient.d.ts | 24 ++++++++++++------- packages/vats/src/types.d.ts | 2 +- .../zoe/src/contractFacet/types-ambient.d.ts | 3 ++- packages/zoe/src/zoeService/utils.d.ts | 3 +++ 6 files changed, 31 insertions(+), 16 deletions(-) diff --git a/packages/vats/src/core/chain-behaviors.js b/packages/vats/src/core/chain-behaviors.js index 48617e717b5..75b1951d96a 100644 --- a/packages/vats/src/core/chain-behaviors.js +++ b/packages/vats/src/core/chain-behaviors.js @@ -331,11 +331,14 @@ export const makeBridgeManager = async ({ const bridgeManager = E(vat).provideManagerForBridge(bridge); bridgeManagerP.resolve(bridgeManager); provisionBridgeManager.resolve( + // @ts-expect-error XXX EProxy E(bridgeManager).register(BRIDGE_ID.PROVISION), ); provisionWalletBridgeManager.resolve( + // @ts-expect-error XXX EProxy E(bridgeManager).register(BRIDGE_ID.PROVISION_SMART_WALLET), ); + // @ts-expect-error XXX EProxy walletBridgeManager.resolve(E(bridgeManager).register(BRIDGE_ID.WALLET)); }; harden(makeBridgeManager); diff --git a/packages/vats/src/core/core-eval-env.d.ts b/packages/vats/src/core/core-eval-env.d.ts index cb1f87b419b..83b01732d40 100644 --- a/packages/vats/src/core/core-eval-env.d.ts +++ b/packages/vats/src/core/core-eval-env.d.ts @@ -11,8 +11,8 @@ */ import type { VatData } from '@agoric/swingset-liveslots/src/vatDataTypes.js'; -import type { E, Far, getInterfaceOf, passStyleOf } from '@endo/far'; -import type { Assert, VirtualConsole } from 'ses'; +import type * as far from '@endo/far'; +import type { Assert } from 'ses'; import type { BootstrapModules } from './boot-chain.js'; // Provided by 'CORE_EVAL' handler in chain-behaviors.js @@ -22,10 +22,10 @@ declare global { var utils: BootstrapModules['utils']; // @endo/far exports - var E: E; - var Far: Far; - var getInterfaceOfFar: getInterfaceOfFar; - var passStyleOfFar: passStyleOfFar; + var E: typeof far.E; + var Far: typeof far.Far; + var getInterfaceOfFar: typeof far.getInterfaceOf; + var passStyleOfFar: typeof far.passStyleOf; // endowments var VatData: VatData; diff --git a/packages/vats/src/core/types-ambient.d.ts b/packages/vats/src/core/types-ambient.d.ts index 9a6b4ae680d..ec5043e8e29 100644 --- a/packages/vats/src/core/types-ambient.d.ts +++ b/packages/vats/src/core/types-ambient.d.ts @@ -202,13 +202,13 @@ type WellKnownName = { }; type ContractInstallationPromises< - StartFns extends Record, + StartFns extends Record, > = { [Property in keyof StartFns]: Promise>; }; type ContractInstancePromises< - StartFns extends Record, + StartFns extends Record, > = { [Property in keyof StartFns]: Promise< import('@agoric/zoe/src/zoeService/utils.js').Instance @@ -259,11 +259,13 @@ type WellKnownSpaces = { WellKnownName['installation'], Promise> > & + // @ts-expect-error XXX ContractInstallationPromises; }; instance: { produce: Record>; consume: Record> & + // @ts-expect-error XXX ContractInstancePromises; }; uiConfig: { @@ -281,6 +283,7 @@ type StartGovernedUpgradableOpts = { 'brands' | 'issuers' | 'governedParams' | 'electionManager' >; privateArgs: Omit< + // @ts-expect-error XXX import('@agoric/zoe/src/zoeService/utils').StartParams['privateArgs'], 'initialPoserInvitation' >; @@ -314,8 +317,9 @@ type StartUpgradable = < } >; -type StartedInstanceKit = - import('@agoric/zoe/src/zoeService/utils').StartedInstanceKit; +type StartedInstanceKit< + T extends import('@agoric/zoe/src/zoeService/utils').ContractStartFunction, +> = import('@agoric/zoe/src/zoeService/utils').StartedInstanceKit; type StartedInstanceKitWithLabel = { label: string; @@ -365,12 +369,14 @@ type ChainBootstrapSpaceT = { pegasusConnections: import('@agoric/vats').NameHubKit; pegasusConnectionsAdmin: import('@agoric/vats').NameAdmin; priceAuthorityVat: Awaited; - priceAuthority: PriceAuthority; + priceAuthority: import('@agoric/zoe/tools/types.js').PriceAuthority; priceAuthorityAdmin: import('@agoric/vats/src/priceAuthorityRegistry').PriceAuthorityRegistryAdmin; provisioning: Awaited | undefined; - provisionBridgeManager: import('../types.js').ScopedBridgeManager | undefined; + provisionBridgeManager: + | import('../types.js').ScopedBridgeManager<'provision'> + | undefined; provisionWalletBridgeManager: - | import('../types.js').ScopedBridgeManager + | import('../types.js').ScopedBridgeManager<'provisionWallet'> | undefined; storageBridgeManager: | import('../types.js').ScopedBridgeManager<'storage'> @@ -391,7 +397,9 @@ type ChainBootstrapSpaceT = { >; /** Used only for testing. Should not appear in any production proposals. */ testFirstAnchorKit: import('../vat-bank.js').AssetIssuerKit; - walletBridgeManager: import('../types.js').ScopedBridgeManager | undefined; + walletBridgeManager: + | import('../types.js').ScopedBridgeManager<'wallet'> + | undefined; walletFactoryStartResult: import('./startWalletFactory.js').WalletFactoryStartResult; provisionPoolStartResult: GovernanceFacetKit< typeof import('@agoric/inter-protocol/src/provisionPool.js').start diff --git a/packages/vats/src/types.d.ts b/packages/vats/src/types.d.ts index ec9ecc84191..11613498f5f 100644 --- a/packages/vats/src/types.d.ts +++ b/packages/vats/src/types.d.ts @@ -1,6 +1,6 @@ import type { BridgeIdValue, Remote } from '@agoric/internal'; import type { Bytes } from '@agoric/network'; -import type { PromiseVow, Remote } from '@agoric/vow'; +import type { PromiseVow } from '@agoric/vow'; import type { Guarded } from '@endo/exo'; export type Board = ReturnType< diff --git a/packages/zoe/src/contractFacet/types-ambient.d.ts b/packages/zoe/src/contractFacet/types-ambient.d.ts index 81b78ef8f06..f9c6d9b479d 100644 --- a/packages/zoe/src/contractFacet/types-ambient.d.ts +++ b/packages/zoe/src/contractFacet/types-ambient.d.ts @@ -244,7 +244,8 @@ type ContractStartFnResult = { }; // XXX redef, losing documentation -type ContractOf = import('../zoeService/utils').ContractOf; +type ContractOf any> = + import('../zoeService/utils').ContractOf; type AdminFacet = import('../zoeService/utils').AdminFacet; declare const OfferReturn: unique symbol; diff --git a/packages/zoe/src/zoeService/utils.d.ts b/packages/zoe/src/zoeService/utils.d.ts index 8ccd1043f87..6ef63ce49a8 100644 --- a/packages/zoe/src/zoeService/utils.d.ts +++ b/packages/zoe/src/zoeService/utils.d.ts @@ -104,13 +104,16 @@ export type StartInstance = ( issuerKeywordRecord?: Record>, // 'brands' and 'issuers' need not be passed in; Zoe provides them as StandardTerms terms?: Omit['terms'], 'brands' | 'issuers'>, + // @ts-expect-error XXX privateArgs?: Parameters[1], label?: string, + // @ts-expect-error XXX ) => Promise>; // XXX SF should extend ContractStartFunction but doing that triggers a bunch of tech debt type errors export type GetPublicFacet = ( instance: Instance | PromiseLike>, + // @ts-expect-error XXX ) => Promise['publicFacet']>; export type GetTerms = (instance: Instance) => Promise< From 0701b917ce04bc639a45274bfe3b93a16ac40574 Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Wed, 5 Jun 2024 10:41:19 -0700 Subject: [PATCH 15/19] chore: update type-coverage --- packages/inter-protocol/package.json | 2 +- packages/orchestration/package.json | 2 +- packages/smart-wallet/package.json | 2 +- packages/vats/package.json | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/inter-protocol/package.json b/packages/inter-protocol/package.json index e95cbab9e9d..c2325e54111 100644 --- a/packages/inter-protocol/package.json +++ b/packages/inter-protocol/package.json @@ -82,6 +82,6 @@ "access": "public" }, "typeCoverage": { - "atLeast": 95.85 + "atLeast": 95.81 } } diff --git a/packages/orchestration/package.json b/packages/orchestration/package.json index 05a1cee587c..029873261da 100644 --- a/packages/orchestration/package.json +++ b/packages/orchestration/package.json @@ -82,6 +82,6 @@ "access": "public" }, "typeCoverage": { - "atLeast": 97.17 + "atLeast": 97.1 } } diff --git a/packages/smart-wallet/package.json b/packages/smart-wallet/package.json index a98c41b6656..f2f805cafb1 100644 --- a/packages/smart-wallet/package.json +++ b/packages/smart-wallet/package.json @@ -68,6 +68,6 @@ "access": "public" }, "typeCoverage": { - "atLeast": 94.3 + "atLeast": 94.36 } } diff --git a/packages/vats/package.json b/packages/vats/package.json index d143015f69b..e61a97130f9 100644 --- a/packages/vats/package.json +++ b/packages/vats/package.json @@ -77,6 +77,6 @@ "workerThreads": false }, "typeCoverage": { - "atLeast": 91.11 + "atLeast": 91.21 } } From abaf1296b75819500a614c06f64ed1c980d79b40 Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Wed, 5 Jun 2024 12:49:51 -0700 Subject: [PATCH 16/19] chore: remove allowed{Messages,Queries} from chain info no value in runtime --- packages/orchestration/src/chain-info.js | 8 -------- packages/orchestration/src/cosmos-api.ts | 5 ----- packages/orchestration/src/facade.js | 2 -- packages/orchestration/src/typeGuards.js | 2 -- packages/orchestration/test/facade.test.ts | 2 -- 5 files changed, 19 deletions(-) diff --git a/packages/orchestration/src/chain-info.js b/packages/orchestration/src/chain-info.js index fe7352ca004..5629e52633a 100644 --- a/packages/orchestration/src/chain-info.js +++ b/packages/orchestration/src/chain-info.js @@ -19,8 +19,6 @@ export const wellKnownChainInfo = icqEnabled: true, pfmEnabled: true, ibcHooksEnabled: true, - allowedMessages: [], - allowedQueries: [], stakingTokens: [{ denom: 'ustride' }], }, cosmos: { @@ -30,8 +28,6 @@ export const wellKnownChainInfo = icqEnabled: true, pfmEnabled: true, ibcHooksEnabled: true, - allowedMessages: [], - allowedQueries: [], stakingTokens: [{ denom: 'uatom' }], }, celestia: { @@ -41,8 +37,6 @@ export const wellKnownChainInfo = icqEnabled: true, pfmEnabled: true, ibcHooksEnabled: true, - allowedMessages: [], - allowedQueries: [], stakingTokens: [{ denom: 'utia' }], }, osmosis: { @@ -52,8 +46,6 @@ export const wellKnownChainInfo = icqEnabled: true, pfmEnabled: true, ibcHooksEnabled: true, - allowedMessages: [], - allowedQueries: [], stakingTokens: [{ denom: 'uosmo' }], }, }) diff --git a/packages/orchestration/src/cosmos-api.ts b/packages/orchestration/src/cosmos-api.ts index 04cebb79777..5306de19b60 100644 --- a/packages/orchestration/src/cosmos-api.ts +++ b/packages/orchestration/src/cosmos-api.ts @@ -72,11 +72,6 @@ export type CosmosChainInfo = { icqEnabled: boolean; pfmEnabled: boolean; ibcHooksEnabled: boolean; - /** - * - */ - allowedMessages: TypeUrl[]; - allowedQueries: TypeUrl[]; /** * cf https://github.com/cosmos/chain-registry/blob/master/chain.schema.json#L117 diff --git a/packages/orchestration/src/facade.js b/packages/orchestration/src/facade.js index b9ea70bfeea..703639ebf86 100644 --- a/packages/orchestration/src/facade.js +++ b/packages/orchestration/src/facade.js @@ -23,8 +23,6 @@ const anyVal = null; // UNTIL https://github.com/Agoric/agoric-sdk/issues/9063 const mockLocalChainInfo = { allegedName: 'agoric', - allowedMessages: [], - allowedQueries: [], chainId: 'agoriclocal', connections: anyVal, ibcHooksEnabled: true, diff --git a/packages/orchestration/src/typeGuards.js b/packages/orchestration/src/typeGuards.js index 9ba142f57ec..c67b08fba39 100644 --- a/packages/orchestration/src/typeGuards.js +++ b/packages/orchestration/src/typeGuards.js @@ -53,7 +53,5 @@ export const CosmosChainInfoShape = M.splitRecord( icqEnabled: M.boolean(), pfmEnabled: M.boolean(), ibcHooksEnabled: M.boolean(), - allowedMessages: M.arrayOf(M.string()), - allowedQueries: M.arrayOf(M.string()), }, ); diff --git a/packages/orchestration/test/facade.test.ts b/packages/orchestration/test/facade.test.ts index 10fdfa1c162..4f2f8c5392a 100644 --- a/packages/orchestration/test/facade.test.ts +++ b/packages/orchestration/test/facade.test.ts @@ -15,8 +15,6 @@ export const mockChainInfo: CosmosChainInfo = harden({ icqEnabled: false, pfmEnabled: false, ibcHooksEnabled: false, - allowedMessages: [], - allowedQueries: [], stakingTokens: [{ denom: 'umock' }], }); From 75bb7dfbe2adabff3ee64713d9d6558788bbb8bf Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Wed, 5 Jun 2024 15:18:39 -0700 Subject: [PATCH 17/19] feat: chainInfo from agoricNames --- .../src/examples/swapExample.contract.js | 22 ++++++++----- .../src/examples/unbondExample.contract.js | 18 ++++++++--- packages/orchestration/src/facade.js | 31 ++++++++++++++----- .../orchestration/src/utils/mockChainInfo.js | 11 ++++--- .../test/examples/swapExample.test.ts | 1 + .../test/examples/unbondExample.test.ts | 1 + packages/orchestration/test/facade.test.ts | 3 ++ packages/orchestration/test/supports.ts | 18 +++++++++++ 8 files changed, 82 insertions(+), 23 deletions(-) diff --git a/packages/orchestration/src/examples/swapExample.contract.js b/packages/orchestration/src/examples/swapExample.contract.js index 8fdb4ac49de..448663f7eb1 100644 --- a/packages/orchestration/src/examples/swapExample.contract.js +++ b/packages/orchestration/src/examples/swapExample.contract.js @@ -15,12 +15,13 @@ import { orcUtils } from '../utils/orc.js'; * @import {Remote} from '@agoric/internal'; * @import {OrchestrationService} from '../service.js'; * @import {Baggage} from '@agoric/vat-data' - * @import {Zone} from '@agoric/zone'; + * @import {NameHub} from '@agoric/vats'; */ /** @type {ContractMeta} */ export const meta = { privateArgsShape: { + agoricNames: M.remotable('agoricNames'), localchain: M.remotable('localchain'), orchestrationService: M.or(M.remotable('orchestration'), null), storageNode: StorageNodeShape, @@ -42,6 +43,7 @@ export const makeNatAmountShape = (brand, min) => /** * @param {ZCF} zcf * @param {{ + * agoricNames: Remote; * localchain: Remote; * orchestrationService: Remote; * storageNode: Remote; @@ -54,16 +56,22 @@ export const start = async (zcf, privateArgs, baggage) => { const zone = makeDurableZone(baggage); - const { localchain, orchestrationService, storageNode, timerService } = - privateArgs; + const { + agoricNames, + localchain, + orchestrationService, + storageNode, + timerService, + } = privateArgs; const { orchestrate } = makeOrchestrationFacade({ - zone, - timerService, - zcf, + agoricNames, localchain, - storageNode, orchestrationService, + storageNode, + timerService, + zcf, + zone, }); /** deprecated historical example */ diff --git a/packages/orchestration/src/examples/unbondExample.contract.js b/packages/orchestration/src/examples/unbondExample.contract.js index 48a2a1979d5..70ae1696114 100644 --- a/packages/orchestration/src/examples/unbondExample.contract.js +++ b/packages/orchestration/src/examples/unbondExample.contract.js @@ -8,6 +8,7 @@ import { makeOrchestrationFacade } from '../facade.js'; * @import {TimerService} from '@agoric/time'; * @import {Baggage} from '@agoric/vat-data'; * @import {LocalChain} from '@agoric/vats/src/localchain.js'; + * @import {NameHub} from '@agoric/vats'; * @import {Remote} from '@agoric/internal'; * @import {OrchestrationService} from '../service.js'; */ @@ -15,6 +16,7 @@ import { makeOrchestrationFacade } from '../facade.js'; /** * @param {ZCF} zcf * @param {{ + * agoricNames: Remote; * localchain: Remote; * orchestrationService: Remote; * storageNode: Remote; @@ -23,17 +25,23 @@ import { makeOrchestrationFacade } from '../facade.js'; * @param {Baggage} baggage */ export const start = async (zcf, privateArgs, baggage) => { - const { localchain, orchestrationService, storageNode, timerService } = - privateArgs; + const { + agoricNames, + localchain, + orchestrationService, + storageNode, + timerService, + } = privateArgs; const zone = makeDurableZone(baggage); const { orchestrate } = makeOrchestrationFacade({ + agoricNames, localchain, - zone, + orchestrationService, + storageNode, timerService, zcf, - storageNode, - orchestrationService, + zone, }); /** @type {OfferHandler} */ diff --git a/packages/orchestration/src/facade.js b/packages/orchestration/src/facade.js index 703639ebf86..1f73ae93120 100644 --- a/packages/orchestration/src/facade.js +++ b/packages/orchestration/src/facade.js @@ -3,11 +3,11 @@ import { makeScalarBigMapStore } from '@agoric/vat-data'; import { E } from '@endo/far'; import { M } from '@endo/patterns'; -import { wellKnownChainInfo } from './chain-info.js'; import { prepareCosmosOrchestrationAccount } from './exos/cosmosOrchestrationAccount.js'; import { CosmosChainInfoShape } from './typeGuards.js'; /** + * @import {NameHub} from '@agoric/vats'; * @import {Zone} from '@agoric/zone'; * @import {TimerService} from '@agoric/time'; * @import {LocalChain} from '@agoric/vats/src/localchain.js'; @@ -19,6 +19,10 @@ import { CosmosChainInfoShape } from './typeGuards.js'; /** @type {any} */ const anyVal = null; +// TODO define key hierarchy in shared constants +/** agoricNames key for ChainInfo hub */ +export const CHAIN_KEY = 'chain'; + // FIXME look up real values // UNTIL https://github.com/Agoric/agoric-sdk/issues/9063 const mockLocalChainInfo = { @@ -153,6 +157,7 @@ const makeRemoteChainFacade = ( * storageNode: Remote; * orchestrationService: Remote; * localchain: Remote; + * agoricNames: Remote; * }} powers */ export const makeOrchestrationFacade = ({ @@ -162,6 +167,7 @@ export const makeOrchestrationFacade = ({ storageNode, orchestrationService, localchain, + agoricNames, }) => { console.log('makeOrchestrationFacade got', { zone, @@ -176,6 +182,22 @@ export const makeOrchestrationFacade = ({ valueShape: CosmosChainInfoShape, }); + /** + * @param {string} name + * @returns {Promise} + */ + const getChainInfo = async name => { + // Either from registerChain or memoized remote lookup() + if (chainInfos.has(name)) { + return chainInfos.get(name); + } + + const chainInfo = await E(agoricNames).lookup(CHAIN_KEY, name); + assert(chainInfo, `unknown chain ${name}`); + chainInfos.init(name, chainInfo); + return chainInfo; + }; + return { /** * Register a new chain in a heap store. The name will override a name in @@ -209,12 +231,7 @@ export const makeOrchestrationFacade = ({ return makeLocalChainFacade(localchain); } - // TODO look up well known realistically https://github.com/Agoric/agoric-sdk/issues/9063 - const chainInfo = chainInfos.has(name) - ? chainInfos.get(name) - : // @ts-expect-error may be undefined - wellKnownChainInfo[name]; - assert(chainInfo, `unknown chain ${name}`); + const chainInfo = await getChainInfo(name); return makeRemoteChainFacade(chainInfo, { orchestration: orchestrationService, diff --git a/packages/orchestration/src/utils/mockChainInfo.js b/packages/orchestration/src/utils/mockChainInfo.js index d7fb12cea0e..42cfcca688f 100644 --- a/packages/orchestration/src/utils/mockChainInfo.js +++ b/packages/orchestration/src/utils/mockChainInfo.js @@ -1,5 +1,10 @@ /** - * @file Mocked Chain Info object until #8879 + * @file Mocked Chain Info object + * + * Until https://github.com/Agoric/agoric-sdk/issues/8879 + * + * Generated using + * https://github.com/Agoric/agoric-sdk/compare/pc/ibc-chain-info */ import { Order, @@ -67,9 +72,7 @@ const connectionEntries = harden({ }, }); -/** - * @returns {Pick} - */ +/** @returns {Pick} */ export const prepareMockChainInfo = () => { return harden({ chainId: 'agoriclocal', diff --git a/packages/orchestration/test/examples/swapExample.test.ts b/packages/orchestration/test/examples/swapExample.test.ts index ca1a8852fe5..e288dc9a982 100644 --- a/packages/orchestration/test/examples/swapExample.test.ts +++ b/packages/orchestration/test/examples/swapExample.test.ts @@ -28,6 +28,7 @@ test('start', async t => { { Stable: ist.issuer }, {}, { + agoricNames: bootstrap.agoricNames, localchain: bootstrap.localchain, orchestrationService: bootstrap.orchestration, storageNode: bootstrap.storage.rootNode, diff --git a/packages/orchestration/test/examples/unbondExample.test.ts b/packages/orchestration/test/examples/unbondExample.test.ts index b78e606fdf0..7540faf10d3 100644 --- a/packages/orchestration/test/examples/unbondExample.test.ts +++ b/packages/orchestration/test/examples/unbondExample.test.ts @@ -26,6 +26,7 @@ test('start', async t => { { Stable: ist.issuer }, {}, { + agoricNames: bootstrap.agoricNames, localchain: bootstrap.localchain, orchestrationService: bootstrap.orchestration, storageNode: bootstrap.storage.rootNode, diff --git a/packages/orchestration/test/facade.test.ts b/packages/orchestration/test/facade.test.ts index 4f2f8c5392a..8c2514d052e 100644 --- a/packages/orchestration/test/facade.test.ts +++ b/packages/orchestration/test/facade.test.ts @@ -26,6 +26,7 @@ test('chain info', async t => { const { zcf } = await setupZCFTest(); const { registerChain, orchestrate } = makeOrchestrationFacade({ + agoricNames: bootstrap.agoricNames, localchain: bootstrap.localchain, orchestrationService: bootstrap.orchestration, storageNode: bootstrap.storage.rootNode, @@ -54,6 +55,7 @@ test('contract upgrade', async t => { // Register once { const { registerChain } = makeOrchestrationFacade({ + agoricNames: bootstrap.agoricNames, localchain: bootstrap.localchain, orchestrationService: bootstrap.orchestration, storageNode: bootstrap.storage.rootNode, @@ -72,6 +74,7 @@ test('contract upgrade', async t => { // Simulate running again in a new incarnation with the same zone { const { registerChain } = makeOrchestrationFacade({ + agoricNames: bootstrap.agoricNames, localchain: bootstrap.localchain, orchestrationService: bootstrap.orchestration, storageNode: bootstrap.storage.rootNode, diff --git a/packages/orchestration/test/supports.ts b/packages/orchestration/test/supports.ts index d13338b260b..c0079ef920f 100644 --- a/packages/orchestration/test/supports.ts +++ b/packages/orchestration/test/supports.ts @@ -9,8 +9,13 @@ import { buildZoeManualTimer } from '@agoric/zoe/tools/manualTimer.js'; import { withAmountUtils } from '@agoric/zoe/tools/test-utils.js'; import { makeHeapZone } from '@agoric/zone'; import { E } from '@endo/far'; +import { makeNameHubKit } from '@agoric/vats'; +import { makeWellKnownSpaces } from '@agoric/vats/src/core/utils.js'; import { fakeNetworkEchoStuff } from './network-fakes.js'; import { prepareOrchestrationTools } from '../src/service.js'; +import { CHAIN_KEY } from '../src/facade.js'; +import type { CosmosChainInfo } from '../src/cosmos-api.js'; +import { wellKnownChainInfo } from '../src/chain-info.js'; export { makeFakeLocalchainBridge } from '@agoric/vats/tools/fake-bridge.js'; @@ -53,8 +58,21 @@ export const commonSetup = async t => { const { portAllocator } = fakeNetworkEchoStuff(rootZone.subZone('network')); const { public: orchestration } = makeOrchestrationKit({ portAllocator }); + const { nameHub: agoricNames, nameAdmin: agoricNamesAdmin } = + makeNameHubKit(); + const spaces = await makeWellKnownSpaces(agoricNamesAdmin, t.log, [ + CHAIN_KEY, + ]); + + // Simulate what BLD stakers would have configured + for (const [name, info] of Object.entries(wellKnownChainInfo)) { + // @ts-expect-error FIXME types + spaces.chain.produce[name].resolve(info); + } + return { bootstrap: { + agoricNames, bankManager, timer, localchain, From 72bf1bfea6e3f1b45a479235b2672cf26d7f3a6b Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Wed, 5 Jun 2024 15:51:48 -0700 Subject: [PATCH 18/19] test: extract commonPrivateArgs --- .../orchestration/test/examples/swapExample.test.ts | 9 ++------- .../orchestration/test/examples/unbondExample.test.ts | 10 ++-------- packages/orchestration/test/supports.ts | 7 +++++++ 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/packages/orchestration/test/examples/swapExample.test.ts b/packages/orchestration/test/examples/swapExample.test.ts index e288dc9a982..c10c4b2a994 100644 --- a/packages/orchestration/test/examples/swapExample.test.ts +++ b/packages/orchestration/test/examples/swapExample.test.ts @@ -16,6 +16,7 @@ test('start', async t => { const { bootstrap, brands: { ist }, + commonPrivateArgs, utils, } = await commonSetup(t); @@ -27,13 +28,7 @@ test('start', async t => { installation, { Stable: ist.issuer }, {}, - { - agoricNames: bootstrap.agoricNames, - localchain: bootstrap.localchain, - orchestrationService: bootstrap.orchestration, - storageNode: bootstrap.storage.rootNode, - timerService: bootstrap.timer, - }, + commonPrivateArgs, ); const inv = E(publicFacet).makeSwapAndStakeInvitation(); diff --git a/packages/orchestration/test/examples/unbondExample.test.ts b/packages/orchestration/test/examples/unbondExample.test.ts index 7540faf10d3..7b23042977a 100644 --- a/packages/orchestration/test/examples/unbondExample.test.ts +++ b/packages/orchestration/test/examples/unbondExample.test.ts @@ -13,8 +13,8 @@ type StartFn = test('start', async t => { const { - bootstrap, brands: { ist }, + commonPrivateArgs, } = await commonSetup(t); const { zoe, bundleAndInstall } = await setUpZoeForTest(); @@ -25,13 +25,7 @@ test('start', async t => { installation, { Stable: ist.issuer }, {}, - { - agoricNames: bootstrap.agoricNames, - localchain: bootstrap.localchain, - orchestrationService: bootstrap.orchestration, - storageNode: bootstrap.storage.rootNode, - timerService: bootstrap.timer, - }, + commonPrivateArgs, ); const inv = E(publicFacet).makeUnbondAndLiquidStakeInvitation(); diff --git a/packages/orchestration/test/supports.ts b/packages/orchestration/test/supports.ts index c0079ef920f..fea78fb9123 100644 --- a/packages/orchestration/test/supports.ts +++ b/packages/orchestration/test/supports.ts @@ -86,6 +86,13 @@ export const commonSetup = async t => { bld, ist, }, + commonPrivateArgs: { + agoricNames, + localchain, + orchestrationService: orchestration, + storageNode: storage.rootNode, + timerService: timer, + }, utils: { pourPayment, }, From 9fdd77faebb661bc4e055d7f22c79a20f2a1d9be Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Wed, 5 Jun 2024 15:55:49 -0700 Subject: [PATCH 19/19] test: extract facadeServices --- packages/orchestration/test/facade.test.ts | 19 +++++-------------- packages/orchestration/test/supports.ts | 6 ++++++ 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/packages/orchestration/test/facade.test.ts b/packages/orchestration/test/facade.test.ts index 8c2514d052e..0057a932502 100644 --- a/packages/orchestration/test/facade.test.ts +++ b/packages/orchestration/test/facade.test.ts @@ -19,18 +19,15 @@ export const mockChainInfo: CosmosChainInfo = harden({ }); test('chain info', async t => { - const { bootstrap } = await commonSetup(t); + const { bootstrap, facadeServices } = await commonSetup(t); const zone = bootstrap.rootZone; const { zcf } = await setupZCFTest(); const { registerChain, orchestrate } = makeOrchestrationFacade({ - agoricNames: bootstrap.agoricNames, - localchain: bootstrap.localchain, - orchestrationService: bootstrap.orchestration, + ...facadeServices, storageNode: bootstrap.storage.rootNode, - timerService: bootstrap.timer, zcf, zone, }); @@ -46,7 +43,7 @@ test('chain info', async t => { }); test('contract upgrade', async t => { - const { bootstrap } = await commonSetup(t); + const { bootstrap, facadeServices } = await commonSetup(t); const zone = bootstrap.rootZone; @@ -55,11 +52,8 @@ test('contract upgrade', async t => { // Register once { const { registerChain } = makeOrchestrationFacade({ - agoricNames: bootstrap.agoricNames, - localchain: bootstrap.localchain, - orchestrationService: bootstrap.orchestration, + ...facadeServices, storageNode: bootstrap.storage.rootNode, - timerService: bootstrap.timer, zcf, zone, }); @@ -74,11 +68,8 @@ test('contract upgrade', async t => { // Simulate running again in a new incarnation with the same zone { const { registerChain } = makeOrchestrationFacade({ - agoricNames: bootstrap.agoricNames, - localchain: bootstrap.localchain, - orchestrationService: bootstrap.orchestration, + ...facadeServices, storageNode: bootstrap.storage.rootNode, - timerService: bootstrap.timer, zcf, zone, }); diff --git a/packages/orchestration/test/supports.ts b/packages/orchestration/test/supports.ts index fea78fb9123..b87f4678bb7 100644 --- a/packages/orchestration/test/supports.ts +++ b/packages/orchestration/test/supports.ts @@ -93,6 +93,12 @@ export const commonSetup = async t => { storageNode: storage.rootNode, timerService: timer, }, + facadeServices: { + agoricNames, + localchain, + orchestrationService: orchestration, + timerService: timer, + }, utils: { pourPayment, },