From 3d8c3cafc99bf8f7e0f099a1755a13bb2494607a Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Tue, 4 Jun 2024 06:48:46 -0700 Subject: [PATCH 1/4] chore(deps): bump telescope to 1.7.1 --- packages/cosmic-proto/package.json | 2 +- packages/cosmic-proto/src/codegen/binary.ts | 2 +- packages/cosmic-proto/src/codegen/helpers.ts | 2 +- packages/cosmic-proto/src/codegen/index.ts | 2 +- packages/cosmic-proto/src/codegen/json-safe.ts | 8 +++----- packages/cosmic-proto/src/codegen/utf8.ts | 2 +- packages/cosmic-proto/src/codegen/varint.ts | 2 +- ....patch => @cosmology+telescope+1.7.1.patch} | 0 yarn.lock | 18 +++++++++--------- 9 files changed, 18 insertions(+), 20 deletions(-) rename patches/{@cosmology+telescope+1.7.0.patch => @cosmology+telescope+1.7.1.patch} (100%) diff --git a/packages/cosmic-proto/package.json b/packages/cosmic-proto/package.json index 131a39a950e..68dbd3e6103 100644 --- a/packages/cosmic-proto/package.json +++ b/packages/cosmic-proto/package.json @@ -132,7 +132,7 @@ "devDependencies": { "@agoric/cosmos": "^0.34.1", "@ava/typescript": "^4.1.0", - "@cosmology/telescope": "^1.7.0", + "@cosmology/telescope": "^1.7.1", "ava": "^5.3.1", "rimraf": "^5.0.0", "tsd": "^0.30.7", diff --git a/packages/cosmic-proto/src/codegen/binary.ts b/packages/cosmic-proto/src/codegen/binary.ts index eb9fd160328..524eb36d273 100644 --- a/packages/cosmic-proto/src/codegen/binary.ts +++ b/packages/cosmic-proto/src/codegen/binary.ts @@ -1,6 +1,6 @@ //@ts-nocheck /** - * This file and any referenced files were automatically generated by @cosmology/telescope@1.7.0 + * This file and any referenced files were automatically generated by @cosmology/telescope@1.7.1 * DO NOT MODIFY BY HAND. Instead, download the latest proto files for your chain * and run the transpile command or npm scripts command that is used to regenerate this bundle. */ diff --git a/packages/cosmic-proto/src/codegen/helpers.ts b/packages/cosmic-proto/src/codegen/helpers.ts index 71953a5059d..56f5f4f5dde 100644 --- a/packages/cosmic-proto/src/codegen/helpers.ts +++ b/packages/cosmic-proto/src/codegen/helpers.ts @@ -1,6 +1,6 @@ //@ts-nocheck /** - * This file and any referenced files were automatically generated by @cosmology/telescope@1.7.0 + * This file and any referenced files were automatically generated by @cosmology/telescope@1.7.1 * DO NOT MODIFY BY HAND. Instead, download the latest proto files for your chain * and run the transpile command or npm scripts command that is used to regenerate this bundle. */ diff --git a/packages/cosmic-proto/src/codegen/index.ts b/packages/cosmic-proto/src/codegen/index.ts index 4eb5f011238..80dd20e32b1 100644 --- a/packages/cosmic-proto/src/codegen/index.ts +++ b/packages/cosmic-proto/src/codegen/index.ts @@ -1,6 +1,6 @@ //@ts-nocheck /** - * This file and any referenced files were automatically generated by @cosmology/telescope@1.7.0 + * This file and any referenced files were automatically generated by @cosmology/telescope@1.7.1 * DO NOT MODIFY BY HAND. Instead, download the latest proto files for your chain * and run the transpile command or npm scripts command that is used to regenerate this bundle. */ diff --git a/packages/cosmic-proto/src/codegen/json-safe.ts b/packages/cosmic-proto/src/codegen/json-safe.ts index 1b6c380af1b..a026dbef565 100644 --- a/packages/cosmic-proto/src/codegen/json-safe.ts +++ b/packages/cosmic-proto/src/codegen/json-safe.ts @@ -1,14 +1,12 @@ //@ts-nocheck /** - * This file and any referenced files were automatically generated by @cosmology/telescope@1.7.0 + * This file and any referenced files were automatically generated by @cosmology/telescope@1.7.1 * DO NOT MODIFY BY HAND. Instead, download the latest proto files for your chain * and run the transpile command or npm scripts command that is used to regenerate this bundle. */ export type JsonSafe = { - [Prop in keyof T]: T[Prop] extends Uint8Array + [Prop in keyof T]: T[Prop] extends Uint8Array | bigint | Date ? string - : T[Prop] extends bigint - ? string - : T[Prop]; + : T[Prop]; }; diff --git a/packages/cosmic-proto/src/codegen/utf8.ts b/packages/cosmic-proto/src/codegen/utf8.ts index d994f852621..f2d864a1976 100644 --- a/packages/cosmic-proto/src/codegen/utf8.ts +++ b/packages/cosmic-proto/src/codegen/utf8.ts @@ -1,6 +1,6 @@ //@ts-nocheck /** - * This file and any referenced files were automatically generated by @cosmology/telescope@1.7.0 + * This file and any referenced files were automatically generated by @cosmology/telescope@1.7.1 * DO NOT MODIFY BY HAND. Instead, download the latest proto files for your chain * and run the transpile command or npm scripts command that is used to regenerate this bundle. */ diff --git a/packages/cosmic-proto/src/codegen/varint.ts b/packages/cosmic-proto/src/codegen/varint.ts index b8f8cb991d7..e379c6dcef1 100644 --- a/packages/cosmic-proto/src/codegen/varint.ts +++ b/packages/cosmic-proto/src/codegen/varint.ts @@ -1,6 +1,6 @@ //@ts-nocheck /** - * This file and any referenced files were automatically generated by @cosmology/telescope@1.7.0 + * This file and any referenced files were automatically generated by @cosmology/telescope@1.7.1 * DO NOT MODIFY BY HAND. Instead, download the latest proto files for your chain * and run the transpile command or npm scripts command that is used to regenerate this bundle. */ diff --git a/patches/@cosmology+telescope+1.7.0.patch b/patches/@cosmology+telescope+1.7.1.patch similarity index 100% rename from patches/@cosmology+telescope+1.7.0.patch rename to patches/@cosmology+telescope+1.7.1.patch diff --git a/yarn.lock b/yarn.lock index 5efad1e8bc3..d096a8503d0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1272,10 +1272,10 @@ resolved "https://registry.yarnpkg.com/@cosmjs/utils/-/utils-0.32.3.tgz#5dcaee6dd7cc846cdc073e9a7a7f63242f5f7e31" integrity sha512-WCZK4yksj2hBDz4w7xFZQTRZQ/RJhBX26uFHmmQFIcNUUVAihrLO+RerqJgk0dZqC42wstM9pEUQGtPmLcIYvg== -"@cosmology/ast@^1.7.0": - version "1.7.0" - resolved "https://registry.yarnpkg.com/@cosmology/ast/-/ast-1.7.0.tgz#f3ae766349c469ce1171b5f8a930b59b30dcde74" - integrity sha512-/0TR0Wk+uSs5rkfGCc1IzESVuSGMndbyIsRp0Rt0nzVv7MVvGKG6Vo+VvELgqHScmOsPINilOJvAdM+k2fGU8Q== +"@cosmology/ast@^1.7.1": + version "1.7.1" + resolved "https://registry.yarnpkg.com/@cosmology/ast/-/ast-1.7.1.tgz#a93e38d08c1c35d6e209cb04e580cd2b325a1110" + integrity sha512-dLqKUpxy9G8iS4Imd9JRDnP6Ca7EkyiqWWwgZacBLLuFK0mIDed0Fb8JP85pExV26XTC/Un3Nhi8yWiNQlKakQ== dependencies: "@babel/types" "7.23.6" "@cosmology/types" "^1.7.0" @@ -1315,16 +1315,16 @@ "@types/node" ">=13.7.0" long "^4.0.0" -"@cosmology/telescope@^1.7.0": - version "1.7.0" - resolved "https://registry.yarnpkg.com/@cosmology/telescope/-/telescope-1.7.0.tgz#c07722afb68b2c76eec61d1d641eede22b5b52af" - integrity sha512-5pQxnkeqFvRFMHog2yIYO6DSHExRnPEhbzPRUMFcHarbF6d00d81mAmqslD+5JOLC1Yp2FO9adKzAEhAwSeO7A== +"@cosmology/telescope@^1.7.1": + version "1.7.1" + resolved "https://registry.yarnpkg.com/@cosmology/telescope/-/telescope-1.7.1.tgz#1d4357bfc49c41a03c5fbe91fe60c028ffbdfcf6" + integrity sha512-mB/h8iGfVNi+ZV3KzEy6xFKVlAe9d9pOTz/Vu+OCMcrEFS/xHgWMs+eNDGAbWuaCp06qYyZSc0pN7rMVojnElg== dependencies: "@babel/generator" "^7.23.6" "@babel/parser" "^7.23.6" "@babel/traverse" "7.23.6" "@babel/types" "7.23.6" - "@cosmology/ast" "^1.7.0" + "@cosmology/ast" "^1.7.1" "@cosmology/proto-parser" "^1.7.0" "@cosmology/types" "^1.7.0" "@cosmology/utils" "^1.7.0" From a0d7115d42679f973ef2a1c1df51edce83e9a303 Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Tue, 4 Jun 2024 06:49:42 -0700 Subject: [PATCH 2/4] chore(types): handle Date in JsonSafe --- packages/cosmic-proto/test/helpers.test-d.ts | 10 ++++++++++ packages/vats/tools/fake-bridge.js | 1 - 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/cosmic-proto/test/helpers.test-d.ts b/packages/cosmic-proto/test/helpers.test-d.ts index 22b0d974ac4..867216efba3 100644 --- a/packages/cosmic-proto/test/helpers.test-d.ts +++ b/packages/cosmic-proto/test/helpers.test-d.ts @@ -1,6 +1,7 @@ import { expectType } from 'tsd'; import { typedJson } from '../src/helpers.js'; import type { ResponseTo } from '../src/helpers.ts'; +import type { JsonSafe } from '../src/codegen/json-safe.js'; // MsgSend { @@ -30,3 +31,12 @@ import type { ResponseTo } from '../src/helpers.ts'; response['@type'] = '/cosmos.bank.v1beta1.QueryAllBalancesRequest'; response.balances = [{ denom: 'ucosm', amount: '1' }]; } + +// JsonSafe +{ + const response: TypedJson<'/cosmos.staking.v1beta1.MsgUndelegateResponse'> = + null as any; + expectType(response.completionTime); + const responseJson: JsonSafe = null as any; + expectType(responseJson.completionTime); +} diff --git a/packages/vats/tools/fake-bridge.js b/packages/vats/tools/fake-bridge.js index 4ebc6257e8d..e6e5e621098 100644 --- a/packages/vats/tools/fake-bridge.js +++ b/packages/vats/tools/fake-bridge.js @@ -193,7 +193,6 @@ export const makeFakeLocalchainBridge = (zone, onToBridge = () => {}) => { return /** @type {JsonSafe} */ ({}); } case '/cosmos.staking.v1beta1.MsgUndelegate': { - // @ts-expect-error XXX JsonSafe doesn't handle Date return /** @type {JsonSafe} */ ({ completionTime: new Date().toJSON(), }); From 68fcfac22055670b375ec1dac9d2eb31d141ec7b Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Tue, 4 Jun 2024 07:07:36 -0700 Subject: [PATCH 3/4] feat(types): ResponseTo by template --- packages/cosmic-proto/src/helpers.ts | 31 +++++++++++-------- packages/cosmic-proto/test/helpers.test-d.ts | 32 +++++++++++++++++++- 2 files changed, 50 insertions(+), 13 deletions(-) diff --git a/packages/cosmic-proto/src/helpers.ts b/packages/cosmic-proto/src/helpers.ts index 49d75c0696c..f9335437f6f 100644 --- a/packages/cosmic-proto/src/helpers.ts +++ b/packages/cosmic-proto/src/helpers.ts @@ -1,3 +1,7 @@ +import type { + Bech32PrefixRequest, + Bech32PrefixResponse, +} from './codegen/cosmos/auth/v1beta1/query.js'; import type { QueryAllBalancesRequest, QueryAllBalancesResponse, @@ -39,15 +43,8 @@ export type Proto3Shape = { '/cosmos.staking.v1beta1.MsgUndelegateResponse': MsgUndelegateResponse; '/ibc.applications.transfer.v1.MsgTransfer': MsgTransfer; '/ibc.applications.transfer.v1.MsgTransferResponse': MsgTransferResponse; -}; - -// Often s/Request$/Response/ but not always -type ResponseMap = { - '/cosmos.bank.v1beta1.MsgSend': '/cosmos.bank.v1beta1.MsgSendResponse'; - '/cosmos.bank.v1beta1.QueryAllBalancesRequest': '/cosmos.bank.v1beta1.QueryAllBalancesResponse'; - '/cosmos.staking.v1beta1.MsgDelegate': '/cosmos.staking.v1beta1.MsgDelegateResponse'; - '/ibc.applications.transfer.v1.MsgTransfer': '/ibc.applications.transfer.v1.MsgTransferResponse'; - '/cosmos.staking.v1beta1.MsgUndelegate': '/cosmos.staking.v1beta1.MsgUndelegateResponse'; + '/cosmos.auth.v1beta1.Bech32PrefixRequest': Bech32PrefixRequest; + '/cosmos.auth.v1beta1.Bech32PrefixResponse': Bech32PrefixResponse; }; /** @@ -64,10 +61,20 @@ export type TypedJson = } : { '@type': string }; +/** General pattern for Request that has a corresponding Response */ +type RequestTypeUrl = `/${Base}Request`; +/** Pattern specific to Msg sends, in which "Msg" without "Response" implies it's a request */ +type TxMessageTypeUrl< + Package extends string, + Name extends Capitalize, +> = `/${Package}.Msg${Name}`; + export type ResponseTo = - T['@type'] extends keyof ResponseMap - ? TypedJson - : TypedJson; + T['@type'] extends RequestTypeUrl + ? TypedJson<`/${Base}Response`> + : T['@type'] extends TxMessageTypeUrl + ? TypedJson<`/${Package}.Msg${Name}Response`> + : TypedJson; export const typedJson = ( typeStr: T, diff --git a/packages/cosmic-proto/test/helpers.test-d.ts b/packages/cosmic-proto/test/helpers.test-d.ts index 867216efba3..b8e1bca98ab 100644 --- a/packages/cosmic-proto/test/helpers.test-d.ts +++ b/packages/cosmic-proto/test/helpers.test-d.ts @@ -1,6 +1,6 @@ import { expectType } from 'tsd'; import { typedJson } from '../src/helpers.js'; -import type { ResponseTo } from '../src/helpers.ts'; +import type { ResponseTo, TypedJson } from '../src/helpers.ts'; import type { JsonSafe } from '../src/codegen/json-safe.js'; // MsgSend @@ -32,6 +32,36 @@ import type { JsonSafe } from '../src/codegen/json-safe.js'; response.balances = [{ denom: 'ucosm', amount: '1' }]; } +// Bech32Prefix +{ + const request = typedJson('/cosmos.auth.v1beta1.Bech32PrefixRequest', {}); + const response: ResponseTo = null as any; + expectType<'/cosmos.auth.v1beta1.Bech32PrefixResponse'>(response['@type']); + response['@type'] = '/cosmos.auth.v1beta1.Bech32PrefixResponse'; +} + +// Delegation +{ + const request = typedJson('/cosmos.staking.v1beta1.MsgDelegate', { + amount: { denom: 'ucosm', amount: '1' }, + delegatorAddress: 'agoric1from', + validatorAddress: 'agoric1to', + }); + const response: ResponseTo = null as any; + expectType<'/cosmos.staking.v1beta1.MsgDelegateResponse'>(response['@type']); +} +{ + const request = typedJson('/cosmos.staking.v1beta1.MsgUndelegate', { + amount: { denom: 'ucosm', amount: '1' }, + delegatorAddress: 'agoric1from', + validatorAddress: 'agoric1to', + }); + const response: ResponseTo = null as any; + expectType<'/cosmos.staking.v1beta1.MsgUndelegateResponse'>( + response['@type'], + ); +} + // JsonSafe { const response: TypedJson<'/cosmos.staking.v1beta1.MsgUndelegateResponse'> = From 58b3abca9f1667c2d5e74ae8047c53e3c751b076 Mon Sep 17 00:00:00 2001 From: Turadg Aleahmad Date: Fri, 31 May 2024 08:37:30 -0700 Subject: [PATCH 4/4] docs: typo --- a3p-integration/proposals/c:stake-bld/stakeBld.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/a3p-integration/proposals/c:stake-bld/stakeBld.test.js b/a3p-integration/proposals/c:stake-bld/stakeBld.test.js index c58611d7974..13e6cb52c1f 100644 --- a/a3p-integration/proposals/c:stake-bld/stakeBld.test.js +++ b/a3p-integration/proposals/c:stake-bld/stakeBld.test.js @@ -70,6 +70,6 @@ test('basic', async t => { t.is(postDelegation.length, 2, 'new delegation now'); t.like(postDelegation[1], { balance: { amount: '10', denom: 'ubld' }, - // omit 'delegation' because it has 'delgatorAddress' which is different every test run + // omit 'delegation' because it has 'delegatorAddress' which is different every test run }); });