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

fix: ccip history [skip cypress] #2233

Merged
merged 4 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 10 additions & 38 deletions src/components/transactions/Bridge/BridgeConfig.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ type Config = {
wrappedNativeOracle: string; // Used to get the fee price in USD
lockReleaseTokenPool?: string; // Only exists on Ethereum
burnMintTokenPool?: string; // Only exists on non-Ethereum networks
destinations: {
destinationChainId: ChainId;
onRamp: string;
}[];
feeTokens: TokenInfoWithBalance[];
};

Expand All @@ -48,12 +44,6 @@ const prodConfig: Config[] = [
tokenOracle: '0x3f12643d3f6f874d39c2a4c9f2cd6f2dbac877fc',
wrappedNativeOracle: AaveV3Ethereum.ASSETS.WETH.ORACLE,
subgraphUrl: `https://gateway-arbitrum.network.thegraph.com/api/${process.env.NEXT_PUBLIC_SUBGRAPH_API_KEY}/subgraphs/id/E11p8T4Ff1DHZbwSUC527hkUb5innVMdTuP6A2s1xtm1`,
destinations: [
{
destinationChainId: ChainId.arbitrum_one,
onRamp: '0x925228d7b82d883dde340a55fe8e6da56244a22c',
},
],
feeTokens: [
{
name: 'Gho Token',
Expand Down Expand Up @@ -92,12 +82,6 @@ const prodConfig: Config[] = [
tokenOracle: '0xb05984ad83c20b3ade7bf97a9a0cb539dde28dbb',
wrappedNativeOracle: AaveV3Arbitrum.ASSETS.WETH.ORACLE,
subgraphUrl: `https://gateway-arbitrum.network.thegraph.com/api/${process.env.NEXT_PUBLIC_SUBGRAPH_API_KEY}/subgraphs/id/GPpZfiGoDChLsiWoMG5fxXdRNEYrsVDrKJ39moGcbz6i`,
destinations: [
{
destinationChainId: ChainId.mainnet,
onRamp: '0xce11020d56e5fdbfe46d9fc3021641ffbbb5adee',
},
],
feeTokens: [
{
name: 'Gho Token',
Expand Down Expand Up @@ -139,12 +123,6 @@ const testnetConfig: Config[] = [
tokenOracle: '0x98458D6A99489F15e6eB5aFa67ACFAcf6F211051', // mock oracle
wrappedNativeOracle: AaveV3Sepolia.ASSETS.WETH.ORACLE,
subgraphUrl: 'https://api.studio.thegraph.com/query/75867/gho-ccip-sepolia/version/latest',
destinations: [
{
destinationChainId: ChainId.arbitrum_sepolia,
onRamp: '0x1f41c443cf68750d5c195e2ea7051521d981fc77',
},
],
feeTokens: [
{
name: 'Gho Token',
Expand Down Expand Up @@ -183,12 +161,6 @@ const testnetConfig: Config[] = [
tokenOracle: '0x2a9C5afB0d0e4BAb2BCdaE109EC4b0c4Be15a165', // mock oracle
wrappedNativeOracle: AaveV3ArbitrumSepolia.ASSETS.WETH.ORACLE,
subgraphUrl: 'https://api.studio.thegraph.com/query/75867/gho-ccip-arb-sepolia/version/latest',
destinations: [
{
destinationChainId: ChainId.sepolia,
onRamp: '0xc1ebd046a4086142479be3fc16a4791e2022909a',
},
],
feeTokens: [
{
name: 'Gho Token',
Expand Down Expand Up @@ -233,6 +205,16 @@ export function getChainSelectorFor(chainId: ChainId) {
return chainSelector;
}

export function getChainIdFor(chainSelector: string) {
const chainId = laneConfig.find(
(config) => config.chainSelector === chainSelector
)?.sourceChainId;
if (!chainId) {
throw new Error(`No chainId found for chainSelector ${chainSelector}`);
}
return chainId;
}

export function getRouterFor(chainId: ChainId) {
const router = laneConfig.find((config) => config.sourceChainId === chainId)?.router;
if (!router) {
Expand All @@ -245,16 +227,6 @@ export function getSupportedSourceChains() {
return laneConfig.map((config) => config.sourceChainId);
}

export function getDestinationChainFor(sourceChainId: ChainId, onRamp: string) {
const destinationChainId = laneConfig
.find((config) => config.sourceChainId === sourceChainId)
?.destinations.find((dest) => dest.onRamp === onRamp)?.destinationChainId;
if (!destinationChainId) {
throw new Error(`No destination chain found for onRamp ${onRamp}`);
}
return destinationChainId;
}

export function getConfigFor(sourceChainId: ChainId) {
const config = laneConfig.find((config) => config.sourceChainId === sourceChainId);
if (!config) {
Expand Down
9 changes: 4 additions & 5 deletions src/hooks/useBridgeTransactionHistory.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { ChainId } from '@aave/contract-helpers';
import { useQuery } from '@tanstack/react-query';
import request, { gql } from 'graphql-request';
import {
getDestinationChainFor,
laneConfig,
} from 'src/components/transactions/Bridge/BridgeConfig';
import { getChainIdFor, laneConfig } from 'src/components/transactions/Bridge/BridgeConfig';

type SubgraphBridgeTransaction = {
id: string;
Expand All @@ -20,6 +17,7 @@ type SubgraphBridgeTransaction = {
token: string;
}[];
transactionHash: string;
destChainSelector: string;
};

export type BridgeTransaction = {
Expand Down Expand Up @@ -64,6 +62,7 @@ const sendRequestsQuery = gql`
token
}
transactionHash
destChainSelector
}
}
`;
Expand All @@ -80,7 +79,7 @@ const getSendRequests = async (url: string, sender: string) => {
return result.ccipsendRequests
.map<BridgeTransaction>((tx) => {
const sourceChainId = networkNameToChainId[tx.network];
const destinationChainId = getDestinationChainFor(sourceChainId, tx.address);
const destinationChainId = getChainIdFor(tx.destChainSelector);
if (!destinationChainId) {
throw new Error(`No destination chain found`);
}
Expand Down