Skip to content
This repository has been archived by the owner on Jun 29, 2023. It is now read-only.

Commit

Permalink
Merge pull request #5 from sei-protocol/feature/dynamic-chain-config
Browse files Browse the repository at this point in the history
Dynamic chain configs
  • Loading branch information
codebycarson authored Nov 4, 2022
2 parents 6f1c539 + 7c1c9b5 commit a6301ce
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 98 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ A library for Sei written in Typescript.
### Wallet
```import { connect, SUPPORTED_WALLETS } from '@sei-js/core/wallet```

| Property | Type | Description |
|---------------------|---------------------------------------------------|-------------------------------------------------------------------------------|
| connect() | (walletKey: string) => { accounts, offlineSigner} | Async function to connect to input wallet |
| SUPPORTED_WALLETS | string[] | A list of currently supported wallets which can be passed to connect() |
| KEPLR_CHAIN_SUGGEST | object | A pre defined object to be passed to keplrs experimentalChainSuggest function |
| Property | Type | Description |
|-------------------|-----------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------|
| connect() | (walletKey: string) => { accounts, offlineSigner} | Async function to connect to input wallet |
| SUPPORTED_WALLETS | string[] | A list of currently supported wallets which can be passed to connect() |
| getChainSuggest | (chainId?: string, restUrl?: string, rpcUrl?: string) -> object | A pre defined object to be passed to a wallets experimentalChainSuggest function. Takes optional parameters for chainId, restUrl, and rpcUrl. |

### Client
#### Query Client
Expand Down
173 changes: 84 additions & 89 deletions src/wallet/config.ts
Original file line number Diff line number Diff line change
@@ -1,99 +1,94 @@
import { SupportedWallet } from "./types";
import { SupportedWallet } from './types';

const baseDenomTokenId = `factory/sei1466nf3zuxpya8q9emxukd7vftaf6h4psr0a07srl5zw74zh84yjqpeheyc/uust2`;
const chainId = 'atlantic-1';
const restUrl = "https://sei-chain-incentivized.com/sei-chain-app"
const rpcUrl = "https://sei-chain-incentivized.com/sei-chain-tm/";
const prefix = "sei";

export const KEPLR_CHAIN_SUGGEST = {
chainId: chainId,
chainName: "Sei Testnet",
rpc: rpcUrl,
rest: restUrl,
bip44: {
coinType: 118,
},
bech32Config: {
bech32PrefixAccAddr: prefix,
bech32PrefixAccPub: `${prefix}pub`,
bech32PrefixValAddr: `${prefix}valoper`,
bech32PrefixValPub: `${prefix}valoperpub`,
bech32PrefixConsAddr: `${prefix}valcons`,
bech32PrefixConsPub: `${prefix}valconspub`,
},
currencies: [
{
coinDenom: "SEI",
coinMinimalDenom: "usei",
coinDecimals: 6,
},
{
coinDenom: "USDC",
coinMinimalDenom: "uusdc",
coinDecimals: 6,
coinGeckoId: "usd-coin",
},
{
coinDenom: "ATOM",
coinMinimalDenom: "uatom",
coinDecimals: 6,
coinGeckoId: "cosmos",
},
{
coinDenom: "WETH",
coinMinimalDenom:
"ibc/C2A89D98873BB55B62CE86700DFACA646EC80352E8D03CC6CF34DD44E46DC75D",
coinDecimals: 18,
coinGeckoId: "weth",
},
{
coinDenom: "WBTC",
coinMinimalDenom:
"ibc/42BCC21A2B784E813F8878739FD32B4AA2D0A68CAD94F4C88B9EA98609AB0CCD",
coinDecimals: 8,
coinGeckoId: "bitcoin",
},
{
coinDenom: "aUSDC",
coinMinimalDenom:
"ibc/6D45A5CD1AADE4B527E459025AC1A5AEF41AE99091EF3069F3FEAACAFCECCD21",
coinDecimals: 6,
coinGeckoId: "usd-coin",
},
{
coinDenom: "UST2",
coinMinimalDenom:
baseDenomTokenId,
coinDecimals: 6,
},
],
feeCurrencies: [
{
coinDenom: "SEI",
coinMinimalDenom: "usei",
coinDecimals: 6,
},
],
stakeCurrency: {
coinDenom: "SEI",
coinMinimalDenom: "usei",
coinDecimals: 6,
},
coinType: 118,
features: ["stargate", "ibc-transfer", "cosmwasm"],
}
const prefix = 'sei';

export const getChainSuggest = (
chainId: string = 'atlantic-1',
restUrl: string = 'https://sei-chain-incentivized.com/sei-chain-app',
rpcUrl: string = 'https://sei-chain-incentivized.com/sei-chain-tm/'
) => {
return {
chainId: chainId,
chainName: 'Sei Testnet',
rpc: rpcUrl,
rest: restUrl,
bip44: {
coinType: 118
},
bech32Config: {
bech32PrefixAccAddr: prefix,
bech32PrefixAccPub: `${prefix}pub`,
bech32PrefixValAddr: `${prefix}valoper`,
bech32PrefixValPub: `${prefix}valoperpub`,
bech32PrefixConsAddr: `${prefix}valcons`,
bech32PrefixConsPub: `${prefix}valconspub`
},
currencies: [
{
coinDenom: 'SEI',
coinMinimalDenom: 'usei',
coinDecimals: 6
},
{
coinDenom: 'USDC',
coinMinimalDenom: 'uusdc',
coinDecimals: 6,
coinGeckoId: 'usd-coin'
},
{
coinDenom: 'ATOM',
coinMinimalDenom: 'uatom',
coinDecimals: 6,
coinGeckoId: 'cosmos'
},
{
coinDenom: 'WETH',
coinMinimalDenom: 'ibc/C2A89D98873BB55B62CE86700DFACA646EC80352E8D03CC6CF34DD44E46DC75D',
coinDecimals: 18,
coinGeckoId: 'weth'
},
{
coinDenom: 'WBTC',
coinMinimalDenom: 'ibc/42BCC21A2B784E813F8878739FD32B4AA2D0A68CAD94F4C88B9EA98609AB0CCD',
coinDecimals: 8,
coinGeckoId: 'bitcoin'
},
{
coinDenom: 'aUSDC',
coinMinimalDenom: 'ibc/6D45A5CD1AADE4B527E459025AC1A5AEF41AE99091EF3069F3FEAACAFCECCD21',
coinDecimals: 6,
coinGeckoId: 'usd-coin'
},
{
coinDenom: 'UST2',
coinMinimalDenom: baseDenomTokenId,
coinDecimals: 6
}
],
feeCurrencies: [
{
coinDenom: 'SEI',
coinMinimalDenom: 'usei',
coinDecimals: 6
}
],
stakeCurrency: {
coinDenom: 'SEI',
coinMinimalDenom: 'usei',
coinDecimals: 6
},
coinType: 118,
features: ['stargate', 'ibc-transfer', 'cosmwasm']
};
};

const KEPLR_WALLET: SupportedWallet = {
windowKey: "keplr",
windowKey: 'keplr'
};

const LEAP_WALLET: SupportedWallet = {
windowKey: "leap",
windowKey: 'leap'
};

export const SUPPORTED_WALLETS: SupportedWallet[] = [
KEPLR_WALLET,
LEAP_WALLET,
];
export const SUPPORTED_WALLETS: SupportedWallet[] = [KEPLR_WALLET, LEAP_WALLET];
8 changes: 4 additions & 4 deletions src/wallet/connection.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { KEPLR_CHAIN_SUGGEST } from './config';
import { getChainSuggest } from './config';
import { WalletConnect, WalletWindowKey } from './types';

declare global {
Expand All @@ -8,16 +8,16 @@ declare global {
}
}

export const connect = async (inputWallet: WalletWindowKey): Promise<WalletConnect | undefined> => {
export const connect = async (inputWallet: WalletWindowKey, chainId?: string, restUrl?: string, rpcUrl?: string): Promise<WalletConnect | undefined> => {
switch (inputWallet) {
case 'keplr':
await window.keplr.experimentalSuggestChain(KEPLR_CHAIN_SUGGEST);
await window.keplr.experimentalSuggestChain(getChainSuggest(chainId, restUrl, rpcUrl));
break;
}

if (typeof window === 'undefined' || !window) return;

const offlineSigner = await window[inputWallet].getOfflineSigner('atlantic-1');
const offlineSigner = await window[inputWallet].getOfflineSigner(chainId);
const accounts = await offlineSigner.getAccounts();

return { offlineSigner, accounts };
Expand Down

0 comments on commit a6301ce

Please sign in to comment.