Skip to content

Commit

Permalink
create standard chain definition separate from chain-registry
Browse files Browse the repository at this point in the history
  • Loading branch information
NoahSaso committed Oct 9, 2024
1 parent 7181ae0 commit 3d2b040
Show file tree
Hide file tree
Showing 278 changed files with 720 additions and 689 deletions.
7 changes: 3 additions & 4 deletions packages/dispatch/scripts/deploy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,9 @@ const main = async () => {
const queryClient = await makeReactQueryClient()

const {
chain_name: chainName,
bech32_prefix: bech32Prefix,
network_type: networkType,
slip44,
chainName,
bech32Prefix,
chainRegistry: { network_type: networkType, slip44 } = {},
} = getChainForChainId(chainId)

await queryClient.prefetchQuery(chainQueries.dynamicGasPrice({ chainId }))
Expand Down
14 changes: 7 additions & 7 deletions packages/dispatch/scripts/polytone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,19 +114,19 @@ const main = async () => {
])

const srcSigner = await DirectSecp256k1HdWallet.fromMnemonic(MNEMONIC, {
prefix: srcChain.bech32_prefix,
prefix: srcChain.bech32Prefix,
})
const srcSender = (await srcSigner.getAccounts())[0].address

const destSigner = await DirectSecp256k1HdWallet.fromMnemonic(MNEMONIC, {
prefix: destChain.bech32_prefix,
prefix: destChain.bech32Prefix,
})
const destSender = (await destSigner.getAccounts())[0].address

log()
log(
chalk.underline(
`Connecting ${srcChain.chain_name} to ${destChain.chain_name} with ${srcSender} and ${destSender}...`
`Connecting ${srcChain.chainName} to ${destChain.chainName} with ${srcSender} and ${destSender}...`
)
)

Expand Down Expand Up @@ -166,15 +166,15 @@ const main = async () => {
SigningCosmWasmClient.connectWithSigner(
getRpcForChainId(srcChainId),
srcSigner,
makeGetSignerOptions(queryClient)(srcChain.chain_name)
makeGetSignerOptions(queryClient)(srcChain.chainName)
),
ibcProtoRpcClientRouter.connect(srcChainId),
IbcClient.connectWithSigner(
getRpcForChainId(srcChainId),
srcSigner,
srcSender,
{
gasPrice: makeGetSignerOptions(queryClient)(srcChain.chain_name)
gasPrice: makeGetSignerOptions(queryClient)(srcChain.chainName)
.gasPrice!,
// How long it waits in between checking for a new block.
estimatedBlockTime: 3000,
Expand All @@ -187,15 +187,15 @@ const main = async () => {
SigningCosmWasmClient.connectWithSigner(
getRpcForChainId(destChainId),
destSigner,
makeGetSignerOptions(queryClient)(destChain.chain_name)
makeGetSignerOptions(queryClient)(destChain.chainName)
),
ibcProtoRpcClientRouter.connect(destChainId),
IbcClient.connectWithSigner(
getRpcForChainId(destChainId),
destSigner,
destSender,
{
gasPrice: makeGetSignerOptions(queryClient)(destChain.chain_name)
gasPrice: makeGetSignerOptions(queryClient)(destChain.chainName)
.gasPrice!,
// How long it waits in between checking for a new block.
estimatedBlockTime: 3000,
Expand Down
2 changes: 1 addition & 1 deletion packages/state/query/queries/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ export const fetchCryptographicMultisigAccount = async ({
chainId: string
address: string
}): Promise<CryptographicMultisigAccount> => {
const { bech32_prefix: bech32Prefix } = getChainForChainId(chainId)
const { bech32Prefix } = getChainForChainId(chainId)
const client = await cosmosProtoRpcClientRouter.connect(chainId)

const { account } = await client.auth.v1beta1.account({
Expand Down
6 changes: 3 additions & 3 deletions packages/state/query/queries/chain.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AssetList } from '@chain-registry/types'
import { Asset } from '@chain-registry/types'
import { fromBase64 } from '@cosmjs/encoding'
import { Coin } from '@cosmjs/stargate'
import { QueryClient, queryOptions, skipToken } from '@tanstack/react-query'
Expand Down Expand Up @@ -1268,12 +1268,12 @@ export const fetchChainRegistryAssets = async ({
chainId,
}: {
chainId: string
}): Promise<AssetList['assets']> =>
}): Promise<Asset[]> =>
(
await (
await fetch(
`https://raw.githubusercontent.com/cosmos/chain-registry/master/${
getChainForChainId(chainId).chain_name
getChainForChainId(chainId).chainName
}/assetlist.json`
)
).json()
Expand Down
4 changes: 2 additions & 2 deletions packages/state/query/queries/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export const fetchIsContract = async (
}
): Promise<boolean> => {
if (
!isValidBech32Address(address, getChainForChainId(chainId).bech32_prefix)
!isValidBech32Address(address, getChainForChainId(chainId).bech32Prefix)
) {
return false
}
Expand Down Expand Up @@ -312,7 +312,7 @@ export const generateInstantiate2Address = async (
dataHash,
creator,
toUtf8(salt),
getChainForChainId(chainId).bech32_prefix
getChainForChainId(chainId).bech32Prefix
)
}

Expand Down
2 changes: 1 addition & 1 deletion packages/state/query/queries/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const fetchProfileInfo = async (
.catch(() => null)
if (stargazeName) {
profile.name =
stargazeName + '.' + getChainForChainId(chainId).bech32_prefix
stargazeName + '.' + getChainForChainId(chainId).bech32Prefix
profile.nameSource = 'stargaze'
}
}
Expand Down
14 changes: 10 additions & 4 deletions packages/state/query/queries/skip.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { QueryClient, queryOptions } from '@tanstack/react-query'

import {
AnyChain,
GenericTokenSource,
SkipAsset,
SkipChain,
TokenType,
} from '@dao-dao/types'
import { convertSkipChainToAnyChain } from '@dao-dao/utils'

import { indexerQueries } from './indexer'

Expand All @@ -19,9 +21,9 @@ export const fetchSkipChain = async (
}: {
chainId: string
}
): Promise<SkipChain> => {
): Promise<AnyChain> => {
const chain = await queryClient.fetchQuery(
indexerQueries.snapper({
indexerQueries.snapper<SkipChain>({
query: 'skip-chain',
parameters: {
chainId,
Expand All @@ -33,7 +35,7 @@ export const fetchSkipChain = async (
throw new Error('No Skip chain found')
}

return chain
return convertSkipChainToAnyChain(chain)
}

/**
Expand Down Expand Up @@ -103,7 +105,11 @@ export const fetchSkipChainPfmEnabled = async (
{ chainId }: { chainId: string }
): Promise<boolean> => {
const chain = await fetchSkipChain(queryClient, { chainId })
return chain?.ibc_capabilities?.cosmos_pfm ?? chain?.pfm_enabled ?? false
return (
chain?.skipChain?.ibc_capabilities?.cosmos_pfm ??
chain?.skipChain?.pfm_enabled ??
false
)
}

export const skipQueries = {
Expand Down
2 changes: 1 addition & 1 deletion packages/state/query/queries/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ export const fetchTokenSource = async (
getChainForChainName(
getIbcTransferInfoFromChannel(currentChainId, channel)
.destinationChain.chain_name
).chain_id,
).chainId,
chainId
)

Expand Down
2 changes: 1 addition & 1 deletion packages/state/recoil/atoms/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const walletChainIdAtom = atom<string>({
localStorageEffect(JSON.stringify, (jsonValue: string) => {
const value = JSON.parse(jsonValue)
// If no configured chain matches, set to default.
return getConfiguredChains().some(({ chain }) => chain.chain_id === value)
return getConfiguredChains().some(({ chain }) => chain.chainId === value)
? value
: getSupportedChains()[0].chainId
}),
Expand Down
2 changes: 1 addition & 1 deletion packages/state/recoil/selectors/contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export const isContractSelector = selectorFamily<
if (
!isValidBech32Address(
contractAddress,
getChainForChainId(chainId).bech32_prefix
getChainForChainId(chainId).bech32Prefix
)
) {
return false
Expand Down
3 changes: 2 additions & 1 deletion packages/state/recoil/selectors/following.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ export const followingDaosSelector = selectorFamily<
const dao = deserializeDaoSource(daoSource)

// Only get followed DAOs that match the current network type.
const { network_type } = maybeGetChainForChainId(dao.chainId) ?? {}
const { network_type } =
maybeGetChainForChainId(dao.chainId)?.chainRegistry ?? {}
return network_type && (network_type === 'mainnet') === MAINNET
? dao
: []
Expand Down
3 changes: 2 additions & 1 deletion packages/state/recoil/selectors/inbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ export const inboxItemsSelector = selectorFamily<
} as InboxLoadedItemWithData)
)
.flatMap((item) => {
const { network_type } = maybeGetChainForChainId(item.chainId) ?? {}
const { network_type } =
maybeGetChainForChainId(item.chainId)?.chainRegistry ?? {}

return item &&
// Filter out items that were cleared.
Expand Down
4 changes: 2 additions & 2 deletions packages/state/recoil/selectors/token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ export const genericTokenBalancesSelector = selectorFamily<
: []
: isValidWalletAddress(
address,
getChainForChainId(chainId).bech32_prefix
getChainForChainId(chainId).bech32Prefix
)
? [
walletCw20BalancesSelector({
Expand Down Expand Up @@ -507,7 +507,7 @@ export const genericTokenSourceSelector = selectorFamily<
getChainForChainName(
getIbcTransferInfoFromChannel(currentChainId, channel)
.destinationChain.chain_name
).chain_id,
).chainId,
chainId
)

Expand Down
16 changes: 8 additions & 8 deletions packages/state/utils/DynamicGasPrice.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Chain } from '@chain-registry/types'
import { Decimal } from '@cosmjs/math'
import { GasPrice } from '@cosmjs/stargate'
import { QueryClient } from '@tanstack/react-query'

import { AnyChain } from '@dao-dao/types'
import { DecCoin } from '@dao-dao/types/protobuf/codegen/cosmos/base/v1beta1/coin'
import { GAS_OVERRIDES, maybeGetNativeTokenForChainId } from '@dao-dao/utils'

Expand All @@ -22,11 +22,11 @@ export class DynamicGasPrice implements GasPrice {

public constructor(
private readonly queryClient: QueryClient,
private readonly chain: Chain
private readonly chain: AnyChain
) {
const override =
this.chain.chain_id in GAS_OVERRIDES
? GAS_OVERRIDES[this.chain.chain_id as keyof typeof GAS_OVERRIDES]
this.chain.chainId in GAS_OVERRIDES
? GAS_OVERRIDES[this.chain.chainId as keyof typeof GAS_OVERRIDES]
: undefined

if (override) {
Expand All @@ -36,13 +36,13 @@ export class DynamicGasPrice implements GasPrice {
}
} else {
const feeDenom = maybeGetNativeTokenForChainId(
this.chain.chain_id
this.chain.chainId
)?.denomOrAddress
if (!feeDenom) {
throw new Error(`Chain ${chain.chain_id} has no fee token`)
throw new Error(`Chain ${chain.chainId} has no fee token`)
}

const feeToken = this.chain.fees?.fee_tokens.find(
const feeToken = this.chain.chainRegistry?.fees?.fee_tokens.find(
({ denom }) => denom === feeDenom
)

Expand All @@ -63,7 +63,7 @@ export class DynamicGasPrice implements GasPrice {
get dynamicGasPrice(): DecCoin | undefined {
return this.queryClient.getQueryData(
chainQueries.dynamicGasPrice({
chainId: this.chain.chain_id,
chainId: this.chain.chainId,
}).queryKey
)
}
Expand Down
2 changes: 1 addition & 1 deletion packages/state/utils/chain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export const makeGetSignerOptions =
const chain =
typeof chainOrName === 'string'
? getChainForChainName(chainOrName)
: chainOrName
: getChainForChainName(chainOrName.chain_name)

// Chains without fee tokens configured will error.
let gasPrice
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const AcceptSubDaoComponent: ActionComponent<
AcceptSubDaoData
> = ({ fieldNamePrefix, errors, isCreating, options: { AddressInput } }) => {
const { t } = useTranslation()
const { bech32_prefix: bech32Prefix } = useChain()
const { bech32Prefix } = useChain()
const { register } = useFormContext<AcceptSubDaoData>()

const addressFieldName = (fieldNamePrefix + 'address') as 'address'
Expand Down
Loading

0 comments on commit 3d2b040

Please sign in to comment.