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

WIP: Loss StarknetChainID #1223

Closed
wants to merge 3 commits into from

Conversation

BenFaruna
Copy link

@BenFaruna BenFaruna commented Sep 10, 2024

Motivation and Resolution

Users can set any custom L2/L3 chain ID
...

RPC version (if applicable)

...

Usage related changes

  • Change 1.
  • ...

Development related changes

  • Change 1.
  • Changes in the chainId type from StarknetChainId to ChainId

Checklist:

  • Performed a self-review of the code
  • Rebased to the last commit of the target branch (or merged it into my branch)
  • Linked the issues which this PR resolves
  • Documented the changes in code (API docs will be generated automatically)
  • Updated the tests
  • All tests are passing

@BenFaruna BenFaruna changed the title WIP: Loss StarknetChainID WIP: Loss StarknetChainID #1081 Sep 10, 2024
@BenFaruna BenFaruna changed the title WIP: Loss StarknetChainID #1081 WIP: Loss StarknetChainID Sep 10, 2024
@BenFaruna
Copy link
Author

#1081
@ivpavici Changing the chain ID type from StarkentChainId has a ripple effect

image

About 15 files will need to be updated. Please let me know how you'd want me to move forward.

@ivpavici
Copy link
Collaborator

@BenFaruna yeah go for it!

@BenFaruna
Copy link
Author

@ivpavici I have made the change to the codebase and substituted StarknetChainId for ChainId.
image

The image above shows the result after running the tests. It's the same result I've been getting before I started making any changes. Please review the change and let me know if I need to make any extra changes to the codebase.

@BenFaruna
Copy link
Author

GM @ivpavici
Can I change this from a draft PR so it can be reviewed?

src/types/lib/index.ts Outdated Show resolved Hide resolved
@BenFaruna BenFaruna marked this pull request as ready for review October 2, 2024 02:22
@ivpavici ivpavici requested a review from penovicp October 2, 2024 11:58
Copy link
Collaborator

@penovicp penovicp left a comment

Choose a reason for hiding this comment

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

Left some suggestions.

For future commits check the commit message guidelines.

return this.chainId;
}

public async getSpecVersion() {
this.specVersion ??= (await this.fetchEndpoint('starknet_specVersion')) as StarknetChainId;
this.specVersion ??= (await this.fetchEndpoint('starknet_specVersion')) as ChainId;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
this.specVersion ??= (await this.fetchEndpoint('starknet_specVersion')) as ChainId;
this.specVersion ??= (await this.fetchEndpoint('starknet_specVersion'));

This looks like the cast can be removed. Also for rpc_0_7.

@@ -313,4 +312,6 @@ export type ContractVersion = {
compiler: CompilerVersion;
};

export type ChainId = '0x534e5f4d41494e' | '0x534e5f5345504f4c4941' | (`0x${string}` & {});
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would do this in a more verbose way:

Suggested change
export type ChainId = '0x534e5f4d41494e' | '0x534e5f5345504f4c4941' | (`0x${string}` & {});
export type StarknetChainId = ValuesType<{
SN_MAIN: '0x534e5f4d41494e'; // encodeShortString('SN_MAIN'),
SN_SEPOLIA: '0x534e5f5345504f4c4941'; // encodeShortString('SN_SEPOLIA')
}>;
export type ChainId = StarknetChainId | (`0x${string}` & {});

And also mark the existing StarknetChainId enum in src/constants.ts with /** @deprecated */.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yea agree on extraction of values from type, but regarding deprecation, dev can still use enum to initialise known Starknet Chain Id's, so I would leave the enum (const) part of it.

@@ -132,7 +132,7 @@ export const StarknetIdContract = {
/**
* Returns the Starknet ID contract address based on the provided chain ID.
*
* @param {StarknetChainId} chainId The chain ID of the Starknet network.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I would use the StarknetChainId type from my src/types/lib/index.ts comment as the input parameter type for the methods in this file. Note that there would be a naming conflict with the existing enum so the enum would need to be aliased.

Copy link
Author

Choose a reason for hiding this comment

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

Using the StarknetChainId in your previous comment as the input parameter type restricts the input value for functions that depend on it. This becomes an issue in src/provider/extensions/starknetId.ts because the getChainId function returns ChainId and not StarknetChainId.
Should I still go ahead with this change? @penovicp

Copy link
Collaborator

Choose a reason for hiding this comment

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

Yes. Cast the getChainId calls as StarknetChainId in that file.

Copy link
Author

Choose a reason for hiding this comment

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

Changing the input type from ChainId to StarknetChainId for the function in src/utils/starknetId.ts will result in changing some of the interfaces. After that, the code returns to its original state, allowing only the chain ID of mainnet and sepolia testnet. That defeats the purpose of this change
What do you think?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure what you mean.

The code for these starknetId utilities is hardcoded to only produce valid results for the mainnet and sepolia chain ids and it throws an error otherwise, this is why I said to use the more restricted type for the input. This PR should allow for a looser chain id to be used within the core of starknet.js such as the Account, Contract, Provider, etc. classes and keep it restricted for the starknetId code. From what I can see there are no starknetId specific interfaces so none should be affected.

Copy link
Author

Choose a reason for hiding this comment

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

I understand better now. Thank you @penovicp

Copy link
Collaborator

@tabaktoni tabaktoni left a comment

Choose a reason for hiding this comment

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

waiting for resolution

@tabaktoni
Copy link
Collaborator

The initial idea was to open for L3 chains, but once this request is closed, we can close this action.
For L3 chains We could create separate rpc channels.
The second resolution was from get-starknet but in the domain of starknet only defined chains are allowed.

@tabaktoni tabaktoni closed this Oct 31, 2024
@ivpavici
Copy link
Collaborator

@BenFaruna thanks for your effort! sent you a small reward for participation!

@BenFaruna
Copy link
Author

@BenFaruna thanks for your effort! sent you a small reward for participation!

Sorry I couldn't complete, I got swarmed after the initial commits 😓
Thank you for the consideration, I do appreciate it

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.

4 participants