Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

types!: Chain takes KnownChainName generic parameter instead of ChainInfo #10213

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

0xpatrickdev
Copy link
Member

closes: #9992

Description

Changes generic parameter for Chain from ChainInfo to KnownChainName. The KnownChainName type is keyof KnownChains, the fetched-chain-info from cosmos chain-registry.

Security Considerations

n/a

Scaling Considerations

n/a, types

Documentation Considerations

Helps make typedoc docs more readable.

Testing Considerations

Updates existing type tests.

Upgrade Considerations

library code for an npm orch release

Copy link

cloudflare-workers-and-pages bot commented Oct 3, 2024

Deploying agoric-sdk with  Cloudflare Pages  Cloudflare Pages

Latest commit: a75f59e
Status: ✅  Deploy successful!
Preview URL: https://0a85f71d.agoric-sdk.pages.dev
Branch Preview URL: https://9992-chain-generic.agoric-sdk.pages.dev

View logs

@0xpatrickdev
Copy link
Member Author

Orchestrator is looking better:

image

getChain() with keyof KnownChains generic parameter:

image

Chain stil has all of the ChainInfo. Does this satisfy the ask of #9992?

image

@@ -126,6 +126,7 @@ const prepareOrchestratorKit = (
return asVow(() => chainByName.get(name));
}
if (name === 'agoric') {
// @ts-expect-error types of property 'chainId' are incompatible (string vs a chainId const)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wasn't sure on this one. Is it addressable?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is because the runtime supports more than KnownChains. A bunch of the places that were changed from string to KnownChainName I think should stay string and things that really expect a KnownChainName can look in knownChains to figure out whether it is or isn't.

The alternative is that we make developers do some build step in their local env to define KnownChainName that's different than the one in agoric-sdk. Let's punt on that because we can expect agoric-sdk to know all the chains pretty quickly. We can push NPM releases pretty fast. And in a pinch they could patch the package.

Though considering that… maybe we should just have a type ChainName and it default to all the known ones but someone can override it with another they know.

Let's discuss

Comment on lines 92 to 105
// "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<OrchestrationAccount<CI>>;
makeAccount: () => Promise<OrchestrationAccount<C>>;
// FUTURE supply optional port object; also fetch port object

query: CI extends { icqEnabled: true }
? ICQQueryFunction
: CI['chainId'] extends `agoric${string}`
? QueryManyFn
query: C extends 'agoric'
? QueryManyFn
: KnownChains[C] extends { icqEnabled: true }
? ICQQueryFunction
: never;

// TODO provide a way to get the local denom/brand/whatever for this chain
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we delete these or create issues? They seem like noise at this point

  // "makeAccount" suggests an operation within a vat
  // FUTURE supply optional port object; also fetch port object
  // TODO provide a way to get the local denom/brand/whatever for this chain

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree, issues or delete. Please figure out whether they're still relevant (if so file, if not delete)

@0xpatrickdev 0xpatrickdev marked this pull request as ready for review October 3, 2024 23:23
@0xpatrickdev 0xpatrickdev requested a review from a team as a code owner October 3, 2024 23:23
Copy link
Member

@turadg turadg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 to simplifying the generic parameter of Chain.

but I think there's more to figure out wrt KnownChainName. If you want to land this sooner, consider losing that type and we can consider introducing it later

@@ -126,6 +126,7 @@ const prepareOrchestratorKit = (
return asVow(() => chainByName.get(name));
}
if (name === 'agoric') {
// @ts-expect-error types of property 'chainId' are incompatible (string vs a chainId const)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is because the runtime supports more than KnownChains. A bunch of the places that were changed from string to KnownChainName I think should stay string and things that really expect a KnownChainName can look in knownChains to figure out whether it is or isn't.

The alternative is that we make developers do some build step in their local env to define KnownChainName that's different than the one in agoric-sdk. Let's punt on that because we can expect agoric-sdk to know all the chains pretty quickly. We can push NPM releases pretty fast. And in a pinch they could patch the package.

Though considering that… maybe we should just have a type ChainName and it default to all the known ones but someone can override it with another they know.

Let's discuss

Comment on lines 92 to 105
// "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<OrchestrationAccount<CI>>;
makeAccount: () => Promise<OrchestrationAccount<C>>;
// FUTURE supply optional port object; also fetch port object

query: CI extends { icqEnabled: true }
? ICQQueryFunction
: CI['chainId'] extends `agoric${string}`
? QueryManyFn
query: C extends 'agoric'
? QueryManyFn
: KnownChains[C] extends { icqEnabled: true }
? ICQQueryFunction
: never;

// TODO provide a way to get the local denom/brand/whatever for this chain
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree, issues or delete. Please figure out whether they're still relevant (if so file, if not delete)

Copy link
Member

@dckc dckc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't have much to add

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Orch docs have too much inline chaininfo
3 participants