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

Add cluster API #65

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Conversation

NorbertBodziony
Copy link

This PR adds ability to synchronize wallet cluster via get/set API.

Why ?
New networks like Sonic and Eclipse leverage SVM, but current wallet standard API does not have a way for requesting cluster context change on the end of wallet. Synchronizing dapp cluster with wallet cluster improves both developer and user experience and makes usage of methods like signAndSendTransaction more robust.

This PR also includes sonic chains names file.

Once I get the initial ACK, I will adjust rest of packages to support the new cluster API.

Comment on lines +1 to +31
import type { IdentifierString } from '@wallet-standard/base';

/** Sonic Mainnet (beta) cluster, e.g. https://api.mainnet-beta.sonic.com */
export const SONIC_MAINNET_CHAIN = 'sonic:mainnet';

/** Sonic Devnet cluster, e.g. https://api.devnet.sonic.com */
export const SONIC_DEVNET_CHAIN = 'sonic:devnet';

/** Sonic Testnet cluster, e.g. https://api.testnet.sonic.com */
export const SONIC_TESTNET_CHAIN = 'sonic:testnet';

/** Sonic Localnet cluster, e.g. http://localhost:8899 */
export const SONIC_LOCALNET_CHAIN = 'sonic:localnet';

/** Array of all Sonic clusters */
export const SONIC_CHAINS = [
SONIC_MAINNET_CHAIN,
SONIC_DEVNET_CHAIN,
SONIC_TESTNET_CHAIN,
SONIC_LOCALNET_CHAIN,
] as const;

/** Type of all Sonic clusters */
export type SonicChain = (typeof SONIC_CHAINS)[number];

/**
* Check if a chain corresponds with one of the Sonic clusters.
*/
export function isSonicChain(chain: IdentifierString): chain is SonicChain {
return SONIC_CHAINS.includes(chain as SonicChain);
}
Copy link

@kespinola kespinola Jun 21, 2024

Choose a reason for hiding this comment

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

The data should be stored in a json file IMO.

packages/core/data/chains.json

identifier: {network}:{environment}:{endpoint}

[
  {
    "name": "sonic",
    "environments": [
      {
        "name": "devnet",
        "proofOfHistorySha": "abac...cerr3",
        "endpoints": [
          {
            "name": "sonic foundation",
            "url": "https://api.devnet.sonic.com"
          }
        ]
      }
    ]
  }
]

Copy link
Author

Choose a reason for hiding this comment

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

I am fine with that solution.

Choose a reason for hiding this comment

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

Should maybe be flatter where network is combined with environment but I can imagine wallets wanting to let users drill down to an rpc endpoint.

@jordaaash
Copy link
Collaborator

We try to avoid specifying behavior that wallets don't generally support. Are you aware of wallets with a public API for changing chains?

@NorbertBodziony
Copy link
Author

NorbertBodziony commented Sep 30, 2024

We try to avoid specifying behavior that wallets don't generally support. Are you aware of wallets with a public API for changing chains?

We recently (Nightly) added out of standard api for SVM networks

export interface IChangeNetworkSolana {
  genesisHash: string
  url?: string
}
export interface IChangeNetworkSolanaOutput {
  genesisHash: string
}
export type ChangeNetworkSolanaMethod = (
  input: IChangeNetworkSolana
) => Promise<IChangeNetworkSolanaOutput>

you can use it window.nightly.solana.changeNetwork({genesisHash})
IMO its unavoidable. Some wallets will just not support it just like change ChainId early on EVM

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.

3 participants