-
Notifications
You must be signed in to change notification settings - Fork 754
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
Conversation
@BenFaruna yeah go for it! |
@ivpavici I have made the change to the codebase and substituted StarknetChainId for ChainId. 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. |
2fce1c8
to
72cd2d2
Compare
GM @ivpavici |
a5012d6
to
6afdcce
Compare
There was a problem hiding this 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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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}` & {}); |
There was a problem hiding this comment.
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:
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 */
.
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
waiting for resolution
The initial idea was to open for L3 chains, but once this request is closed, we can close this action. |
@BenFaruna thanks for your effort! sent you a small reward for participation! |
Sorry I couldn't complete, I got swarmed after the initial commits 😓 |
Motivation and Resolution
Users can set any custom L2/L3 chain ID
...
RPC version (if applicable)
...
Usage related changes
Development related changes
Checklist: