-
Notifications
You must be signed in to change notification settings - Fork 65
feat: enable hypercore in frontend #1857
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
base: master
Are you sure you want to change the base?
Changes from all commits
a0b6184
8b20af8
9a7bd0a
c77097b
1fe942e
ebb0d8f
8d6fd83
eb5fdfe
e5cd924
b7142ee
a96465d
42eb9d6
4c195c8
d0a421c
cef46c7
d55d9b0
b638e74
27064a6
37b534e
37b5548
6ba4eb4
ee5e280
987db84
624a0fc
d65e610
98a4e97
a07fca5
9d79391
1819c7b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -25,7 +25,7 @@ import { | |||||
| import { getMultiCallHandlerAddress } from "../_multicall-handler"; | ||||||
| import { | ||||||
| getIndirectBridgeQuoteMessage, | ||||||
| getIndirectDestinationRoutes, | ||||||
| getIndirectDestinationRoute, | ||||||
| } from "./utils-b2bi"; | ||||||
| import { | ||||||
| InvalidParamError, | ||||||
|
|
@@ -228,21 +228,19 @@ export async function getCrossSwapQuotesForExactInputB2BI( | |||||
| ): Promise<CrossSwapQuotes> { | ||||||
| const { depositEntryPoint } = _prepCrossSwapQuotesRetrievalB2B(crossSwap); | ||||||
|
|
||||||
| const indirectDestinationRoutes = getIndirectDestinationRoutes({ | ||||||
| const indirectDestinationRoute = getIndirectDestinationRoute({ | ||||||
| originChainId: crossSwap.inputToken.chainId, | ||||||
| destinationChainId: crossSwap.outputToken.chainId, | ||||||
| inputToken: crossSwap.inputToken.address, | ||||||
| outputToken: crossSwap.outputToken.address, | ||||||
| }); | ||||||
|
|
||||||
| if (indirectDestinationRoutes.length === 0) { | ||||||
| if (!indirectDestinationRoute) { | ||||||
| throw new InvalidParamError({ | ||||||
| message: "No indirect bridge routes found to specified destination chain", | ||||||
| }); | ||||||
| } | ||||||
|
|
||||||
| const [indirectDestinationRoute] = indirectDestinationRoutes; | ||||||
|
|
||||||
| // For EXACT_INPUT, we need to convert the amount to the intermediary output token decimals | ||||||
| // to get the initial bridgeable output amount. | ||||||
| let bridgeableOutputAmount = ConvertDecimals( | ||||||
|
|
@@ -329,21 +327,19 @@ export async function getCrossSwapQuotesForOutputB2BI( | |||||
| ): Promise<CrossSwapQuotes> { | ||||||
| const { depositEntryPoint } = _prepCrossSwapQuotesRetrievalB2B(crossSwap); | ||||||
|
|
||||||
| const indirectDestinationRoutes = getIndirectDestinationRoutes({ | ||||||
| const indirectDestinationRoute = getIndirectDestinationRoute({ | ||||||
| originChainId: crossSwap.inputToken.chainId, | ||||||
| destinationChainId: crossSwap.outputToken.chainId, | ||||||
| inputToken: crossSwap.inputToken.address, | ||||||
| outputToken: crossSwap.outputToken.address, | ||||||
| }); | ||||||
|
|
||||||
| if (indirectDestinationRoutes.length === 0) { | ||||||
| if (!indirectDestinationRoute) { | ||||||
| throw new InvalidParamError({ | ||||||
| message: "No indirect bridge routes found to specified destination chain", | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
| }); | ||||||
| } | ||||||
|
|
||||||
| const [indirectDestinationRoute] = indirectDestinationRoutes; | ||||||
|
|
||||||
| const outputAmountWithAppFee = crossSwap.appFeePercent | ||||||
| ? addMarkupToAmount(crossSwap.amount, crossSwap.appFeePercent) | ||||||
| : crossSwap.amount; | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,127 +28,112 @@ export function isIndirectDestinationRouteSupported(params: { | |
| inputToken: string; | ||
| outputToken: string; | ||
| }) { | ||
| return getIndirectDestinationRoutes(params).length > 0; | ||
| return !!getIndirectDestinationRoute(params); | ||
| } | ||
|
|
||
| export function getIndirectDestinationRoutes(params: { | ||
| export function getIndirectDestinationRoute(params: { | ||
| originChainId: number; | ||
| destinationChainId: number; | ||
| inputToken: string; | ||
| outputToken: string; | ||
| }): IndirectDestinationRoute[] { | ||
| }): IndirectDestinationRoute | undefined { | ||
| const indirectChainDestination = indirectChains.find( | ||
| (chain) => | ||
| chain.chainId === params.destinationChainId && | ||
| chain.intermediaryChains && | ||
| chain.intermediaryChain && | ||
| chain.outputTokens.some( | ||
| (token) => | ||
| token.address.toLowerCase() === params.outputToken.toLowerCase() | ||
| ) | ||
| ); | ||
|
|
||
| if (!indirectChainDestination) { | ||
| return []; | ||
| return; | ||
| } | ||
|
|
||
| const indirectDestinationRoutes = | ||
| indirectChainDestination.intermediaryChains.flatMap( | ||
| (_intermediaryChainId) => { | ||
| // Check if the indirect destination chain has token enabled | ||
| const isIntermediaryOutputTokenEnabled = | ||
| indirectChainDestination.outputTokens.some( | ||
| (token) => token.address === params.outputToken | ||
| ); | ||
| if (!isIntermediaryOutputTokenEnabled) { | ||
| return []; | ||
| } | ||
| const intermediaryChainId = indirectChainDestination.intermediaryChain; | ||
|
|
||
| // Check if input token is known | ||
| const inputToken = getTokenByAddress( | ||
| params.inputToken, | ||
| params.originChainId | ||
| ); | ||
| if (!inputToken) { | ||
| return []; | ||
| } | ||
| // Check if the indirect destination chain has token enabled | ||
| const isIntermediaryOutputTokenEnabled = | ||
| indirectChainDestination.outputTokens.some( | ||
| (token) => token.address === params.outputToken | ||
| ); | ||
| if (!isIntermediaryOutputTokenEnabled) { | ||
| return; | ||
| } | ||
|
|
||
| // Check if the indirect destination chain supports the intermediary chain | ||
| const indirectOutputToken = getTokenByAddress( | ||
| params.outputToken, | ||
| params.destinationChainId | ||
| ); | ||
| if (!indirectOutputToken) { | ||
| return []; | ||
| } | ||
| // Check if input token is known | ||
| const inputToken = getTokenByAddress(params.inputToken, params.originChainId); | ||
| if (!inputToken) { | ||
| return; | ||
| } | ||
|
|
||
| // Check if L1 token is known | ||
| const l1TokenAddress = | ||
| TOKEN_SYMBOLS_MAP[inputToken.symbol as keyof typeof TOKEN_SYMBOLS_MAP] | ||
| ?.addresses[HUB_POOL_CHAIN_ID]; | ||
| if (!l1TokenAddress) { | ||
| return []; | ||
| } | ||
| const l1Token = getTokenByAddress(l1TokenAddress, HUB_POOL_CHAIN_ID); | ||
| if (!l1Token) { | ||
| return []; | ||
| } | ||
| // Check if the indirect destination chain supports the intermediary chain | ||
| const indirectOutputToken = getTokenByAddress( | ||
| params.outputToken, | ||
| params.destinationChainId | ||
| ); | ||
| if (!indirectOutputToken) { | ||
| return; | ||
| } | ||
|
|
||
| // Check if intermediary output token is known | ||
| const intermediaryOutputTokenAddress = | ||
| l1Token.addresses[_intermediaryChainId]; | ||
| if (!intermediaryOutputTokenAddress) { | ||
| return []; | ||
| } | ||
| const intermediaryOutputToken = getTokenByAddress( | ||
| intermediaryOutputTokenAddress, | ||
| _intermediaryChainId | ||
| ); | ||
| if (!intermediaryOutputToken) { | ||
| return []; | ||
| } | ||
| // Check if L1 token is known | ||
| const l1TokenAddress = | ||
| TOKEN_SYMBOLS_MAP[inputToken.symbol as keyof typeof TOKEN_SYMBOLS_MAP] | ||
| ?.addresses[HUB_POOL_CHAIN_ID]; | ||
| if (!l1TokenAddress) { | ||
| return; | ||
| } | ||
| const l1Token = getTokenByAddress(l1TokenAddress, HUB_POOL_CHAIN_ID); | ||
| if (!l1Token) { | ||
| return; | ||
| } | ||
|
|
||
| // Check if there is a route from the origin chain to the intermediary chain | ||
| if ( | ||
| !isRouteEnabled( | ||
| params.originChainId, | ||
| _intermediaryChainId, | ||
| params.inputToken, | ||
| intermediaryOutputTokenAddress | ||
| ) | ||
| ) { | ||
| return []; | ||
| } | ||
| // Check if intermediary output token is known | ||
| const intermediaryOutputTokenAddress = l1Token.addresses[intermediaryChainId]; | ||
| if (!intermediaryOutputTokenAddress) { | ||
| return; | ||
| } | ||
| const intermediaryOutputToken = getTokenByAddress( | ||
| intermediaryOutputTokenAddress, | ||
| indirectChainDestination.intermediaryChain | ||
| ); | ||
| if (!intermediaryOutputToken) { | ||
| return; | ||
| } | ||
|
|
||
| return { | ||
| inputToken: { | ||
| symbol: inputToken.symbol, | ||
| name: inputToken.name, | ||
| decimals: inputToken.decimals, | ||
| address: inputToken.addresses[params.originChainId], | ||
| chainId: params.originChainId, | ||
| coingeckoId: inputToken.coingeckoId, | ||
| }, | ||
| intermediaryOutputToken: { | ||
| symbol: intermediaryOutputToken.symbol, | ||
| name: intermediaryOutputToken.name, | ||
| decimals: intermediaryOutputToken.decimals, | ||
| address: intermediaryOutputToken.addresses[_intermediaryChainId], | ||
| chainId: _intermediaryChainId, | ||
| coingeckoId: intermediaryOutputToken.coingeckoId, | ||
| }, | ||
| outputToken: { | ||
| symbol: indirectOutputToken.symbol, | ||
| name: indirectOutputToken.name, | ||
| decimals: indirectOutputToken.decimals, | ||
| address: indirectOutputToken.addresses[params.destinationChainId], | ||
| chainId: params.destinationChainId, | ||
| coingeckoId: indirectOutputToken.coingeckoId, | ||
| }, | ||
| }; | ||
| } | ||
| ); | ||
| // Check if there is a route from the origin chain to the intermediary chain | ||
| if ( | ||
| !isRouteEnabled( | ||
| params.originChainId, | ||
| intermediaryChainId, | ||
| params.inputToken, | ||
| intermediaryOutputTokenAddress | ||
| ) | ||
| ) { | ||
| return; | ||
| } | ||
|
|
||
| return indirectDestinationRoutes; | ||
| return { | ||
| inputToken: { | ||
| symbol: inputToken.symbol, | ||
| decimals: inputToken.decimals, | ||
| address: inputToken.addresses[params.originChainId], | ||
| chainId: params.originChainId, | ||
| }, | ||
| intermediaryOutputToken: { | ||
| symbol: intermediaryOutputToken.symbol, | ||
| decimals: intermediaryOutputToken.decimals, | ||
| address: intermediaryOutputToken.addresses[intermediaryChainId], | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The return type before the change was IndirectDestinationRoute[] and now it is IndirectDestinationRoute, what's the reason for the change of fields in the return type here? |
||
| chainId: intermediaryChainId, | ||
| }, | ||
| outputToken: { | ||
| symbol: indirectOutputToken.symbol, | ||
| decimals: indirectOutputToken.decimals, | ||
| address: indirectOutputToken.addresses[params.destinationChainId], | ||
| chainId: params.destinationChainId, | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| export function getIndirectBridgeQuoteMessage( | ||
|
|
@@ -227,7 +212,7 @@ function _buildIndirectBridgeQuoteMessageToHyperCore( | |
| function _buildBridgeQuoteMessageToHyperCore( | ||
| crossSwap: CrossSwap, | ||
| bridgeableOutputAmount: BigNumber, | ||
| indirectDestinationRoute: ReturnType<typeof getIndirectDestinationRoutes>[0], | ||
| indirectDestinationRoute: IndirectDestinationRoute, | ||
| appFee?: AppFee | ||
| ) { | ||
| const { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -27,19 +27,5 @@ export type ChainConfig = { | |
| toTokenSymbol: string; | ||
| externalProjectId?: string; | ||
| }[]; | ||
| intermediaryChains?: number[]; | ||
| outputTokens?: ( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's the reason behind excluding the input and output token of the route here? |
||
| | string | ||
| | { | ||
| symbol: string; | ||
| chainIds: number[]; | ||
| } | ||
| )[]; | ||
| inputTokens?: ( | ||
| | string | ||
| | { | ||
| symbol: string; | ||
| chainIds: number[]; | ||
| } | ||
| )[]; | ||
| intermediaryChain?: number; | ||
| }; | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ import { ExternalProjectConfig } from "../types"; | |
|
|
||
| export default { | ||
| name: "Hyperliquid", | ||
| fullName: "Hyperliquid", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What is the difference between name and fullName? |
||
| projectId: "hyperliquid", | ||
| explorer: "https://arbiscan.io", | ||
| logoPath: "./assets/logo.svg", | ||
|
|
||
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.