Skip to content

Commit

Permalink
fix(types): chain-info const (#9496)
Browse files Browse the repository at this point in the history
refs: #9063 

## Description

When we started fetching the data by JSON, the import of JSON lost the
string values, widening to `string`. This made the string templates
fail. It also widened true and false to `boolean`, which would prevent
the feature inference for what a Chain can do.

This wraps in `const` so the actual values propagate in the type.

### Security Considerations

none
### Scaling Considerations
none

<!-- Does this change require or encourage significant increase in
consumption of CPU cycles, RAM, on-chain storage, message exchanges, or
other scarce resources? If so, can that be prevented or mitigated? -->

### Documentation Considerations
none

<!-- Give our docs folks some hints about what needs to be described to
downstream users.

Backwards compatibility: what happens to existing data or deployments
when this code is shipped? Do we need to instruct users to do something
to upgrade their saved data? If there is no upgrade path possible, how
bad will that be for users?

-->

### Testing Considerations
CI
<!-- Every PR should of course come with tests of its own functionality.
What additional tests are still needed beyond those unit tests? How does
this affect CI, other test automation, or the testnet?
-->

### Upgrade Considerations
none
<!-- What aspects of this PR are relevant to upgrading live production
systems, and how should they be addressed? -->
  • Loading branch information
mergify[bot] authored Jun 12, 2024
2 parents 4fca040 + 1daa3e2 commit 83d470b
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 32 deletions.
15 changes: 8 additions & 7 deletions packages/orchestration/scripts/fetch-chain-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,28 +105,29 @@ for (const name of chainNames) {
chainId: chain.chain_id,
stakingTokens: chain.staking?.staking_tokens,
};
// UNTIL https://github.com/Agoric/agoric-sdk/issues/9326
if (name === 'osmosis') {
chainInfo[name].icqEnabled = true;
}
}
// UNTIL https://github.com/Agoric/agoric-sdk/issues/9326
chainInfo.osmosis = { ...chainInfo.osmosis, icqEnabled: true };

// iterate this after chainInfo is filled out
for (const name of chainNames) {
console.log('processing connections', name);

const ibcData = client.getChainIbcData(name);
chainInfo[name].connections = Object.fromEntries(
const connections = Object.fromEntries(
ibcData
.map(datum => toConnectionEntry(datum, name))
// sort alphbetically for consistency
// eslint-disable-next-line no-nested-ternary
.sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)),
);
chainInfo[name] = { ...chainInfo[name], connections };
}

const src = `/** @file Generated by fetch-chain-info.ts */\nexport default ${JSON.stringify(chainInfo, null, 2)};`;
const record = JSON.stringify(chainInfo, null, 2);
const src = `/** @file Generated by fetch-chain-info.ts */\nexport default /** @type {const} } */ (${record});`;
const prettySrc = await prettier.format(src, {
parser: 'typescript',
parser: 'babel', // 'typescript' fails to preserve parens for typecast
singleQuote: true,
trailingComma: 'all',
});
Expand Down
20 changes: 8 additions & 12 deletions packages/orchestration/src/cosmos-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import type {
import type { State as IBCConnectionState } from '@agoric/cosmic-proto/ibc/core/connection/v1/connection.js';
import type { Brand, Purse } from '@agoric/ertp/src/types.js';
import type { Port } from '@agoric/network';
import { IBCChannelID } from '@agoric/vats';
import { IBCChannelID, type IBCConnectionID } from '@agoric/vats';
import type {
LocalIbcAddress,
RemoteIbcAddress,
Expand All @@ -38,25 +38,21 @@ export type CosmosValidatorAddress = ChainAddress & {

/** Represents an IBC Connection between two chains, which can contain multiple Channels. */
export type IBCConnectionInfo = {
// XXX really IBCConnectionID but our chain info fetcher doesn't know
id: string; // e.g. connection-0
id: IBCConnectionID; // e.g. connection-0
client_id: string; // '07-tendermint-0'
state: IBCConnectionState;
counterparty: {
client_id: string;
// XXX really IBCConnectionID but our chain info fetcher doesn't know
connection_id: string;
connection_id: IBCConnectionID;
prefix: {
key_prefix: string;
};
};
transferChannel: {
portId: string;
// XXX really IBCChannelID but our chain info fetcher doesn't know
channelId: string;
channelId: IBCChannelID;
counterPartyPortId: string;
// XXX really IBCChannelID but our chain info fetcher doesn't know
counterPartyChannelId: string;
counterPartyChannelId: IBCChannelID;
ordering: Order;
state: IBCChannelState;
version: string; // e.eg. 'ics20-1'
Expand All @@ -66,7 +62,7 @@ export type IBCConnectionInfo = {
/**
* Info for a Cosmos-based chain.
*/
export type CosmosChainInfo = {
export type CosmosChainInfo = Readonly<{
chainId: string;

connections?: Record<string, IBCConnectionInfo>; // chainId or wellKnownName
Expand All @@ -76,8 +72,8 @@ export type CosmosChainInfo = {
/**
* cf https://github.com/cosmos/chain-registry/blob/master/chain.schema.json#L117
*/
stakingTokens?: Array<{ denom: string }>;
};
stakingTokens?: Readonly<Array<{ denom: string }>>;
}>;

export interface StakingAccountQueries {
/**
Expand Down
4 changes: 2 additions & 2 deletions packages/orchestration/src/ethereum-api.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* Info for an Ethereum-based chain.
*/
export type EthChainInfo = {
export type EthChainInfo = Readonly<{
chainId: string;
allegedName: string;
};
}>;
7 changes: 2 additions & 5 deletions packages/orchestration/src/facade.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,8 @@ const makeRemoteChainFacade = (
makeAccount: async () => {
const icaAccount = await E(orchestration).makeAccount(
chainInfo.chainId,
// XXX IBCConnectionInfo concessions for JSON encoding
/** @type {IBCConnectionID} */ (connectionInfo.id),
/** @type {IBCConnectionID} */ (
connectionInfo.counterparty.connection_id
),
connectionInfo.id,
connectionInfo.counterparty.connection_id,
);

const address = await E(icaAccount).getAddress();
Expand Down
4 changes: 2 additions & 2 deletions packages/orchestration/src/fetched-chain-info.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/** @file Generated by fetch-chain-info.ts */
export default {
export default /** @type {const} } */ ({
agoric: {
chainId: 'agoric-3',
stakingTokens: [
Expand Down Expand Up @@ -2011,4 +2011,4 @@ export default {
},
},
},
};
});
6 changes: 2 additions & 4 deletions packages/orchestration/src/proposals/start-stakeAtom.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,8 @@ export const startStakeAtom = async ({
issuerKeywordRecord: harden({ ATOM: atomIssuer }),
terms: {
chainId: cosmoshub.chainId,
hostConnectionId: /** @type {IBCConnectionID} */ (connectionInfo.id),
controllerConnectionId: /** @type {IBCConnectionID} */ (
connectionInfo.counterparty.connection_id
),
hostConnectionId: connectionInfo.id,
controllerConnectionId: connectionInfo.counterparty.connection_id,
bondDenom: cosmoshub.stakingTokens[0].denom,
},
privateArgs: {
Expand Down

0 comments on commit 83d470b

Please sign in to comment.