-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start replacing internals with WarpCore
- Loading branch information
Showing
49 changed files
with
431 additions
and
2,742 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,27 @@ | ||
import Image from 'next/image'; | ||
import { ComponentProps, useMemo } from 'react'; | ||
|
||
import { isNumeric } from '@hyperlane-xyz/utils'; | ||
import { ChainLogo as ChainLogoInner } from '@hyperlane-xyz/widgets'; | ||
|
||
import { parseCaip2Id } from '../../features/caip/chains'; | ||
import { getChainDisplayName } from '../../features/chains/utils'; | ||
import { getMultiProvider } from '../../features/multiProvider'; | ||
import { logger } from '../../utils/logger'; | ||
import { getChainDisplayName, tryGetChainMetadata } from '../../features/chains/utils'; | ||
|
||
type Props = Omit<ComponentProps<typeof ChainLogoInner>, 'chainId' | 'chainName'> & { | ||
chainCaip2Id?: ChainCaip2Id; | ||
}; | ||
export function ChainLogo(props: ComponentProps<typeof ChainLogoInner>) { | ||
const { chainName, ...rest } = props; | ||
const { chainId, chainDisplayName, icon } = useMemo(() => { | ||
if (!chainName) return {}; | ||
const chainDisplayName = getChainDisplayName(chainName); | ||
const logoUri = tryGetChainMetadata(chainName)?.logoURI; | ||
const icon = logoUri | ||
? (props: { width: number; height: number; title?: string }) => ( | ||
<Image src={logoUri} alt="" {...props} /> | ||
) | ||
: undefined; | ||
return { | ||
chainId, | ||
chainDisplayName, | ||
icon, | ||
}; | ||
}, [chainName]); | ||
|
||
export function ChainLogo(props: Props) { | ||
const { chainCaip2Id, ...rest } = props; | ||
const { chainId, chainName, icon } = useMemo(() => { | ||
if (!chainCaip2Id) return {}; | ||
try { | ||
const { reference } = parseCaip2Id(chainCaip2Id); | ||
const chainId = isNumeric(reference) ? parseInt(reference, 10) : undefined; | ||
const chainName = getChainDisplayName(chainCaip2Id); | ||
const logoUri = getMultiProvider().tryGetChainMetadata(reference)?.logoURI; | ||
const icon = logoUri | ||
? (props: { width: number; height: number; title?: string }) => ( | ||
<Image src={logoUri} alt="" {...props} /> | ||
) | ||
: undefined; | ||
return { | ||
chainId, | ||
chainName, | ||
icon, | ||
}; | ||
} catch (error) { | ||
logger.error('Failed to parse caip2 id', error); | ||
return {}; | ||
} | ||
}, [chainCaip2Id]); | ||
|
||
return <ChainLogoInner {...rest} chainId={chainId} chainName={chainName} icon={icon} />; | ||
return <ChainLogoInner {...rest} chainId={chainId} chainName={chainDisplayName} icon={icon} />; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
[] | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,9 @@ | ||
import { WarpTokenConfig } from '../features/tokens/types'; | ||
import { WarpCoreConfig } from '@hyperlane-xyz/sdk'; | ||
|
||
// A list of Warp UI token configs | ||
// Tokens can be defined here, in tokens.json, or in tokens.yaml | ||
// The input here is typically the output of the Hyperlane CLI warp deploy command | ||
export const tokenList: WarpTokenConfig = [ | ||
// Example collateral token for an EVM chain | ||
{ | ||
type: 'collateral', | ||
chainId: 5, | ||
address: '0xb4fbf271143f4fbf7b91a5ded31805e42b2208d6', | ||
hypCollateralAddress: '0x145de8760021c4ac6676376691b78038d3DE9097', | ||
name: 'Weth', | ||
symbol: 'WETH', | ||
decimals: 18, | ||
logoURI: '/logos/weth.png', // See public/logos/ | ||
}, | ||
|
||
// Example NFT (ERC721) token for an EVM chain | ||
{ | ||
chainId: 5, | ||
name: 'Test721', | ||
symbol: 'TEST721', | ||
decimals: 0, | ||
type: 'collateral', | ||
address: '0x77566D540d1E207dFf8DA205ed78750F9a1e7c55', | ||
hypCollateralAddress: '0xDcbc0faAA269Cf649AC8950838664BB7B355BD6B', | ||
isNft: true, | ||
}, | ||
]; | ||
export const tokenConfigs: WarpCoreConfig = { | ||
tokens: [], | ||
options: {}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,24 @@ | ||
# A list of Warp UI token configs | ||
# Tokens can be defined here, in tokens.json, or in tokens.ts | ||
# A list of Warp UI token configs and other options for the WarpCore | ||
# Configs can be defined here, in tokens.json, or in tokens.ts | ||
# The input here is typically the output of the Hyperlane CLI warp deploy command | ||
--- | ||
# Replace this [] with your token list | ||
[] | ||
# Example using a native token: | ||
# - type: native | ||
# chainId: 11155111 | ||
# name: 'Ether' | ||
# symbol: 'ETH' | ||
# decimals: 18 | ||
# hypNativeAddress: '0xEa44A29da87B5464774978e6A4F4072A4c048949' | ||
# logoURI: '/logos/weth.png' | ||
tokens: | ||
# Eth Mainnet HypNative token | ||
- chainName: sepolia | ||
standard: EvmHypNative | ||
decimals: 18 | ||
symbol: ETH | ||
name: Ether | ||
addressOrDenom: '0x767C51a91CC9dEF2F24C35c340649411D6390320' | ||
logoURI: '/logos/weth.png' | ||
connectedTokens: | ||
- ethereum|alfajores|0x8bF6Ca2Dca1DF703Cb9144cef6A4d86abA7776C4 | ||
- chainName: alfajores | ||
standard: EvmHypSynthetic | ||
decimals: 18 | ||
symbol: ETH | ||
name: Ether | ||
addressOrDenom: '0x8bF6Ca2Dca1DF703Cb9144cef6A4d86abA7776C4' | ||
logoURI: '/logos/weth.png' | ||
connectedTokens: | ||
- ethereum|sepolia|0x767C51a91CC9dEF2F24C35c340649411D6390320 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { z } from 'zod'; | ||
|
||
import { ChainMap, ChainMetadata, ChainMetadataSchema, chainMetadata } from '@hyperlane-xyz/sdk'; | ||
|
||
import ChainsJson from '../consts/chains.json'; | ||
import { chains as ChainsTS } from '../consts/chains.ts'; | ||
import ChainsYaml from '../consts/chains.yaml'; | ||
import { cosmosDefaultChain } from '../features/chains/cosmosDefault'; | ||
import { logger } from '../utils/logger'; | ||
|
||
export const ChainConfigSchema = z.record( | ||
ChainMetadataSchema.and(z.object({ mailbox: z.string().optional() })), | ||
); | ||
|
||
export function getChainConfigs() { | ||
// Chains must include a cosmos chain or CosmosKit throws errors | ||
const result = ChainConfigSchema.safeParse({ | ||
cosmoshub: cosmosDefaultChain, | ||
...ChainsJson, | ||
...ChainsYaml, | ||
...ChainsTS, | ||
}); | ||
if (!result.success) { | ||
logger.warn('Invalid chain config', result.error); | ||
throw new Error(`Invalid chain config: ${result.error.toString()}`); | ||
} | ||
const customChainConfigs = result.data as ChainMap<ChainMetadata & { mailbox?: Address }>; | ||
return { ...chainMetadata, ...customChainConfigs }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,43 @@ | ||
import { ChainMap, ChainMetadata, MultiProtocolProvider } from '@hyperlane-xyz/sdk'; | ||
import { ChainMap, ChainMetadata, MultiProtocolProvider, WarpCore } from '@hyperlane-xyz/sdk'; | ||
|
||
import type { RoutesMap } from '../features/routes/types'; | ||
import type { TokenMetadata } from '../features/tokens/types'; | ||
|
||
import Chains from './_chains.json'; | ||
import Routes from './_routes.json'; | ||
import Tokens from './_tokens.json'; | ||
import { getChainConfigs } from './chains'; | ||
import { getWarpCoreConfig } from './tokens'; | ||
|
||
export interface WarpContext { | ||
chains: ChainMap<ChainMetadata & { mailbox?: Address }>; | ||
tokens: TokenMetadata[]; | ||
routes: RoutesMap; | ||
multiProvider: MultiProtocolProvider<{ mailbox?: Address }>; | ||
warpCore: WarpCore; | ||
} | ||
|
||
let warpContext: WarpContext; | ||
|
||
export function getWarpContext() { | ||
if (!warpContext) { | ||
warpContext = { | ||
chains: Chains as any, | ||
tokens: Tokens as any, | ||
routes: Routes as any, | ||
multiProvider: new MultiProtocolProvider<{ mailbox?: Address }>(Chains as any), | ||
}; | ||
warpContext = initWarpContext(); | ||
} | ||
return warpContext; | ||
} | ||
|
||
export function setWarpContext(context: WarpContext) { | ||
warpContext = context; | ||
} | ||
|
||
export function initWarpContext() { | ||
const chains = getChainConfigs(); | ||
const multiProvider = new MultiProtocolProvider<{ mailbox?: Address }>(chains); | ||
const coreConfig = getWarpCoreConfig(); | ||
const warpCore = WarpCore.FromConfig(multiProvider, coreConfig); | ||
return { chains, multiProvider, warpCore }; | ||
} | ||
|
||
export function getMultiProvider() { | ||
return getWarpContext().multiProvider; | ||
} | ||
|
||
export function getWarpCore() { | ||
return getWarpContext().warpCore; | ||
} | ||
|
||
export function getTokens() { | ||
return getWarpCore().tokens; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { WarpCoreConfig, WarpCoreConfigSchema } from '@hyperlane-xyz/sdk'; | ||
|
||
import TokensJson from '../consts/tokens.json'; | ||
import { tokenConfigs as TokensTS } from '../consts/tokens.ts'; | ||
import TokensYaml from '../consts/tokens.yaml'; | ||
import { validateZodResult } from '../utils/zod.ts'; | ||
|
||
export function getWarpCoreConfig(): WarpCoreConfig { | ||
const resultJson = WarpCoreConfigSchema.safeParse({ TokensJson }); | ||
const configJson = validateZodResult(resultJson, 'warp core json config'); | ||
const resultYaml = WarpCoreConfigSchema.safeParse({ TokensYaml }); | ||
const configYaml = validateZodResult(resultYaml, 'warp core yaml config'); | ||
const resultTs = WarpCoreConfigSchema.safeParse({ TokensTS }); | ||
const configTs = validateZodResult(resultTs, 'warp core typescript config'); | ||
|
||
const tokens = [...configJson.tokens, ...configYaml.tokens, ...configTs.tokens]; | ||
const options = { ...configJson.options, ...configYaml.options, ...configTs.options }; | ||
return { tokens, options }; | ||
} |
Oops, something went wrong.