From 80f8beeb306452917cf4e224f41a7989a18112ae Mon Sep 17 00:00:00 2001 From: Mark Grothe Date: Mon, 28 Oct 2024 14:51:50 -0500 Subject: [PATCH 1/3] fix: ccip subgraph --- .../transactions/Bridge/BridgeConfig.ts | 48 ++++--------------- src/hooks/useBridgeTransactionHistory.tsx | 9 ++-- 2 files changed, 14 insertions(+), 43 deletions(-) diff --git a/src/components/transactions/Bridge/BridgeConfig.ts b/src/components/transactions/Bridge/BridgeConfig.ts index 4ffd6929b7..fec4f4a188 100644 --- a/src/components/transactions/Bridge/BridgeConfig.ts +++ b/src/components/transactions/Bridge/BridgeConfig.ts @@ -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[]; }; @@ -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', @@ -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', @@ -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', @@ -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', @@ -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) { @@ -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) { diff --git a/src/hooks/useBridgeTransactionHistory.tsx b/src/hooks/useBridgeTransactionHistory.tsx index ff079e4024..7d29af93e1 100644 --- a/src/hooks/useBridgeTransactionHistory.tsx +++ b/src/hooks/useBridgeTransactionHistory.tsx @@ -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; @@ -20,6 +17,7 @@ type SubgraphBridgeTransaction = { token: string; }[]; transactionHash: string; + destChainSelector: string; }; export type BridgeTransaction = { @@ -64,6 +62,7 @@ const sendRequestsQuery = gql` token } transactionHash + destChainSelector } } `; @@ -80,7 +79,7 @@ const getSendRequests = async (url: string, sender: string) => { return result.ccipsendRequests .map((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`); } From 436d5346aa5347a0e46fe746db1ac75b8085de37 Mon Sep 17 00:00:00 2001 From: Mark Grothe Date: Mon, 4 Nov 2024 10:50:11 -0600 Subject: [PATCH 2/3] fix: cleanup, error handling --- src/hooks/useBridgeTransactionHistory.tsx | 54 +++++++++++------------ 1 file changed, 26 insertions(+), 28 deletions(-) diff --git a/src/hooks/useBridgeTransactionHistory.tsx b/src/hooks/useBridgeTransactionHistory.tsx index 7d29af93e1..7aa1173ad3 100644 --- a/src/hooks/useBridgeTransactionHistory.tsx +++ b/src/hooks/useBridgeTransactionHistory.tsx @@ -12,6 +12,7 @@ type SubgraphBridgeTransaction = { message_sender: string; message_receiver: string; message_sequenceNumber: string; + message_sourceChainSelector: string; message_tokenAmounts: { amount: string; token: string; @@ -37,15 +38,6 @@ export type BridgeTransaction = { transactionHash: string; }; -const networkNameToChainId: { [networkName: string]: ChainId } = { - 'base-sepolia': ChainId.base_sepolia, - 'arbitrum-sepolia': ChainId.arbitrum_sepolia, - sepolia: ChainId.sepolia, - 'avalanche-testnet': ChainId.fuji, - mainnet: ChainId.mainnet, - 'arbitrum-one': ChainId.arbitrum_one, -}; - const sendRequestsQuery = gql` query getSendRequests($sender: String!) { ccipsendRequests(where: { message_sender: $sender }) { @@ -57,6 +49,7 @@ const sendRequestsQuery = gql` message_sender message_receiver message_sequenceNumber + message_sourceChainSelector message_tokenAmounts { amount token @@ -77,27 +70,32 @@ const getSendRequests = async (url: string, sender: string) => { ); return result.ccipsendRequests - .map((tx) => { - const sourceChainId = networkNameToChainId[tx.network]; - const destinationChainId = getChainIdFor(tx.destChainSelector); - if (!destinationChainId) { - throw new Error(`No destination chain found`); - } + .map((tx) => { + try { + // If this throws, it's because there was a tx to a chain that is not currently + // supported in the UI (should mainly just be testnets). Just filter out those txs. + const sourceChainId = getChainIdFor(tx.message_sourceChainSelector); + const destinationChainId = getChainIdFor(tx.destChainSelector); - return { - id: tx.id, - onRampAddress: tx.address, - sourceNetwork: tx.network, - sourceChainId, - destinationChainId, - blockTimestamp: Number(tx.blockTimestamp), - sender: tx.message_sender, - receiver: tx.message_receiver, - sequenceNumber: tx.message_sequenceNumber, - tokenAmounts: tx.message_tokenAmounts, - transactionHash: tx.transactionHash, - }; + return { + id: tx.id, + onRampAddress: tx.address, + sourceNetwork: tx.network, + sourceChainId, + destinationChainId, + blockTimestamp: Number(tx.blockTimestamp), + sender: tx.message_sender, + receiver: tx.message_receiver, + sequenceNumber: tx.message_sequenceNumber, + tokenAmounts: tx.message_tokenAmounts, + transactionHash: tx.transactionHash, + }; + } catch (e) { + console.error(e); + return null; + } }) + .filter((tx): tx is BridgeTransaction => tx !== null) .sort((a, b) => b.blockTimestamp - a.blockTimestamp); }; From 0a7bb07b8b52e05797cd7d082b3921271e3d75ec Mon Sep 17 00:00:00 2001 From: Mark Grothe Date: Mon, 4 Nov 2024 15:51:53 -0600 Subject: [PATCH 3/3] fix: testnet subgraphs --- src/components/transactions/Bridge/BridgeConfig.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/transactions/Bridge/BridgeConfig.ts b/src/components/transactions/Bridge/BridgeConfig.ts index c8f0dde1f3..e6ebcde389 100644 --- a/src/components/transactions/Bridge/BridgeConfig.ts +++ b/src/components/transactions/Bridge/BridgeConfig.ts @@ -122,7 +122,7 @@ const testnetConfig: Config[] = [ router: '0x0BF3dE8c5D3e8A2B34D2BEeB17ABfCeBaf363A59', tokenOracle: '0x98458D6A99489F15e6eB5aFa67ACFAcf6F211051', // mock oracle wrappedNativeOracle: AaveV3Sepolia.ASSETS.WETH.ORACLE, - subgraphUrl: 'https://api.studio.thegraph.com/query/75867/gho-ccip-sepolia/version/latest', + subgraphUrl: `https://gateway.thegraph.com/api/${process.env.NEXT_PUBLIC_SUBGRAPH_API_KEY}/subgraphs/id/8NWTrc4S6xwaBbajongofytQfQisqYm1zR2ghGEtRFSc`, feeTokens: [ { name: 'Gho Token', @@ -160,7 +160,7 @@ const testnetConfig: Config[] = [ router: '0x2a9C5afB0d0e4BAb2BCdaE109EC4b0c4Be15a165', tokenOracle: '0x1f885520b7BD528E46b390040F12E753Dce43004', // mock oracle wrappedNativeOracle: AaveV3ArbitrumSepolia.ASSETS.WETH.ORACLE, - subgraphUrl: 'https://api.studio.thegraph.com/query/75867/gho-ccip-arb-sepolia/version/latest', + subgraphUrl: `https://gateway.thegraph.com/api/${process.env.NEXT_PUBLIC_SUBGRAPH_API_KEY}/subgraphs/id/8bpqvL6XBCVhN4heE9rdEwgTketeZ2U5vVGEh5fDoUEH`, feeTokens: [ { name: 'Gho Token',