From f1862cf09f51cd0da2398f4361c4c45cf7f5a7ad Mon Sep 17 00:00:00 2001 From: defi-moses Date: Thu, 18 Apr 2024 11:03:22 +0100 Subject: [PATCH 1/3] fixing explorer UI and explorer indexer --- .../BridgeTransactionTable.tsx | 13 +++++-- .../components/misc/AssetImage.tsx | 20 +++++++---- .../components/misc/IconAndAmount.tsx | 7 ++-- packages/explorer-ui/package.json | 2 +- packages/explorer-ui/pages/tx/[kappa].tsx | 8 +++++ packages/explorer-ui/utils/addressToSymbol.ts | 6 ++-- .../constants/chains/index.ts | 7 ++++ .../constants/tokens/bridgeable.ts | 9 ++--- .../constants/tokens/index.ts | 35 +++++++++++-------- packages/synapse-constants/package.json | 4 +-- .../explorer/consumer/parser/rfqparser.go | 20 ++++++++--- 11 files changed, 90 insertions(+), 41 deletions(-) diff --git a/packages/explorer-ui/components/BridgeTransaction/BridgeTransactionTable.tsx b/packages/explorer-ui/components/BridgeTransaction/BridgeTransactionTable.tsx index aa5f3a9f96..f5fd7675d9 100644 --- a/packages/explorer-ui/components/BridgeTransaction/BridgeTransactionTable.tsx +++ b/packages/explorer-ui/components/BridgeTransaction/BridgeTransactionTable.tsx @@ -6,6 +6,7 @@ import { ChainInfo } from '@components/misc/ChainInfo' import { timeAgo } from '@utils/timeAgo' import { getBridgeTransactionUrl } from '@urls' import { ellipsizeString } from '@utils/ellipsizeString' +import { addressToSymbol } from '@utils/addressToSymbol' export function BridgeTransactionTable({ queryResult }) { const handlePending = (date) => { @@ -37,7 +38,10 @@ export function BridgeTransactionTable({ queryResult }) { formattedValue={fromInfo.formattedValue} tokenAddress={fromInfo.tokenAddress} chainId={fromInfo.chainID} - tokenSymbol={fromInfo.tokenSymbol} + tokenSymbol={addressToSymbol({ + tokenAddress: fromInfo.tokenAddress, + chainId: fromInfo.chainID, + }) || fromInfo.tokenSymbol} iconSize="w-4 h-4" textSize="text-sm" styledCoin={true} @@ -48,8 +52,11 @@ export function BridgeTransactionTable({ queryResult }) { + // temporary fix until either symbolToToken works better as a function or explorer indexer has the right token addresses + + // ) } } diff --git a/packages/explorer-ui/components/misc/IconAndAmount.tsx b/packages/explorer-ui/components/misc/IconAndAmount.tsx index 172dc22246..25126dcaba 100644 --- a/packages/explorer-ui/components/misc/IconAndAmount.tsx +++ b/packages/explorer-ui/components/misc/IconAndAmount.tsx @@ -2,7 +2,7 @@ import { getCoinTextColor } from '@styles/coins' import { formatAmount } from '@utils/formatAmount' import { AssetImage } from '@components/misc/AssetImage' import { addressToSymbol } from '@utils/addressToSymbol' -import { TOKEN_HASH_MAP } from 'synapse-constants' +import { TOKEN_HASH_MAP, tokenAddressToToken } from 'synapse-constants' import { addressToDecimals } from '@utils/addressToDecimals' export function IconAndAmount({ @@ -14,7 +14,7 @@ export function IconAndAmount({ iconSize = 'w-6 h-6', styledCoin = false, }) { - const t = chainId && tokenAddress && TOKEN_HASH_MAP[chainId]?.[tokenAddress] + const t = chainId && tokenAddress && tokenAddressToToken( chainId, tokenAddress ) let styledCoinClass if (styledCoin === true) { @@ -27,7 +27,7 @@ export function IconAndAmount({ let amount let showToken if (tokenSymbol) { - const displaySymbol = addressToSymbol({ tokenAddress, chainId }) + const displaySymbol = addressToSymbol({ tokenAddress, chainId }) || tokenSymbol showToken =
{displaySymbol}
amount = formattedValue } else { @@ -46,6 +46,7 @@ export function IconAndAmount({
diff --git a/packages/explorer-ui/package.json b/packages/explorer-ui/package.json index 9309b40591..861f5f092a 100644 --- a/packages/explorer-ui/package.json +++ b/packages/explorer-ui/package.json @@ -36,7 +36,7 @@ "recharts": "^2.3.2", "sharp": "^0.31.3", "swr": "^1.3.0", - "synapse-constants": "^1.3.8", + "synapse-constants": "^1.3.16", "tailwind-merge": "^1.3.0", "tiny-warning": "^1.0.3", "viem": "^1.19.13", diff --git a/packages/explorer-ui/pages/tx/[kappa].tsx b/packages/explorer-ui/pages/tx/[kappa].tsx index cfb72b7859..c33b616772 100644 --- a/packages/explorer-ui/pages/tx/[kappa].tsx +++ b/packages/explorer-ui/pages/tx/[kappa].tsx @@ -18,6 +18,7 @@ import { BridgeTransactionTable } from '@components/BridgeTransaction/BridgeTran const CHAINS_BY_ID = CHAINS.CHAINS_BY_ID const CCTP_CONTRACTS = CHAINS.CCTP_CONTRACTS const BRIDGE_CONTRACTS = CHAINS.BRIDGE_CONTRACTS +const FASTBRIDGE_CONTRACTS = CHAINS.FASTBRIDGE_CONTRACTS const link = new HttpLink({ uri: API_URL, @@ -51,6 +52,13 @@ export default function BridgeTransaction({ queryResult }) { CCTP_CONTRACTS[chainID] ) } + else if (eventType == 12 || eventType == 13) { + return ( + CHAINS_BY_ID[chainID].explorerUrl + + '/address/' + + FASTBRIDGE_CONTRACTS[chainID] + ) + } return ( CHAINS_BY_ID[chainID].explorerUrl + '/address/' + diff --git a/packages/explorer-ui/utils/addressToSymbol.ts b/packages/explorer-ui/utils/addressToSymbol.ts index 7359046b15..ec4e00f5fa 100644 --- a/packages/explorer-ui/utils/addressToSymbol.ts +++ b/packages/explorer-ui/utils/addressToSymbol.ts @@ -1,4 +1,4 @@ -import { TOKEN_HASH_MAP } from 'synapse-constants' +import { TOKEN_HASH_MAP, tokenAddressToToken } from 'synapse-constants' export function addressToSymbol({ tokenAddress, chainId }) { if ( @@ -7,9 +7,11 @@ export function addressToSymbol({ tokenAddress, chainId }) { ) { return 'AVWETH' } + if (tokenAddress === '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE') { + return 'ETH' + } const symbol = tokenAddress && chainId && TOKEN_HASH_MAP[chainId][tokenAddress]?.symbol - return symbol } diff --git a/packages/synapse-constants/constants/chains/index.ts b/packages/synapse-constants/constants/chains/index.ts index 4ce0994651..d5c4637039 100644 --- a/packages/synapse-constants/constants/chains/index.ts +++ b/packages/synapse-constants/constants/chains/index.ts @@ -116,3 +116,10 @@ export const CCTP_CONTRACTS = { [ChainId.POLYGON]: '0x12715a66773BD9C54534a01aBF01d05F6B4Bd35E', [ChainId.OPTIMISM]: '0x12715a66773BD9C54534a01aBF01d05F6B4Bd35E', } + +export const FASTBRIDGE_CONTRACTS = { + [ChainId.ARBITRUM]: '0x5523D3c98809DdDB82C686E152F5C58B1B0fB59E', + [ChainId.BASE]: '0x5523D3c98809DdDB82C686E152F5C58B1B0fB59E', + [ChainId.ETH]: '0x5523D3c98809DdDB82C686E152F5C58B1B0fB59E', + [ChainId.OPTIMISM]: '0x5523D3c98809DdDB82C686E152F5C58B1B0fB59E', +} diff --git a/packages/synapse-constants/constants/tokens/bridgeable.ts b/packages/synapse-constants/constants/tokens/bridgeable.ts index befa22b996..4a4c6724bd 100644 --- a/packages/synapse-constants/constants/tokens/bridgeable.ts +++ b/packages/synapse-constants/constants/tokens/bridgeable.ts @@ -42,6 +42,7 @@ import { Token } from '../types' import * as CHAINS from '../chains/master' const zeroAddress = '0x0000000000000000000000000000000000000000' +const nullAddress = '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE' export const GOHM = new Token({ addresses: { @@ -772,12 +773,12 @@ export const NETH = new Token({ export const ETH = new Token({ addresses: { - [CHAINS.ETH.id]: zeroAddress, - [CHAINS.OPTIMISM.id]: zeroAddress, + [CHAINS.ETH.id]: nullAddress, + [CHAINS.OPTIMISM.id]: nullAddress, [CHAINS.BOBA.id]: zeroAddress, [CHAINS.CANTO.id]: '0x5FD55A1B9FC24967C4dB09C513C3BA0DFa7FF687', - [CHAINS.BASE.id]: zeroAddress, - [CHAINS.ARBITRUM.id]: zeroAddress, + [CHAINS.BASE.id]: nullAddress, + [CHAINS.ARBITRUM.id]: nullAddress, [CHAINS.DFK.id]: '0xfBDF0E31808d0aa7b9509AA6aBC9754E48C58852', [CHAINS.BLAST.id]: zeroAddress, }, diff --git a/packages/synapse-constants/constants/tokens/index.ts b/packages/synapse-constants/constants/tokens/index.ts index ce335f3152..7b8326afd9 100644 --- a/packages/synapse-constants/constants/tokens/index.ts +++ b/packages/synapse-constants/constants/tokens/index.ts @@ -51,7 +51,6 @@ export const findChainIdsWithPausedToken = (routeSymbol: string) => { PAUSED_TOKENS_BY_CHAIN, (result, tokens, chainId) => { if (_.includes(tokens, routeSymbol)) { - const result: string[] = [] result.push(chainId) } return result @@ -114,10 +113,19 @@ export const BRIDGABLE_TOKENS = getBridgeableTokens() export const tokenSymbolToToken = (chainId: number, symbol: string) => { if (chainId) { - const token = BRIDGABLE_TOKENS[chainId].find((token) => { - return token.symbol === symbol - }) - return token as Token | undefined + if (symbol === 'ETH') { + return ETH + } else if (symbol === 'WETH') { + return WETH + } else if (symbol === 'USDC') { + return USDC + } else { + const foundToken = BRIDGABLE_TOKENS[chainId]?.find( + (token: Token) => token.symbol === symbol + ) + return foundToken + } + return undefined } } export const tokenAddressToToken = ( @@ -125,13 +133,13 @@ export const tokenAddressToToken = ( tokenAddress: string ): Token | undefined => { if (chainId) { - if (tokenAddress === WETH.addresses[chainId]) { + if (tokenAddress === '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE') { + return ETH + } else if (tokenAddress === WETH.addresses[chainId]) { return WETH } else { - const token = BRIDGABLE_TOKENS[chainId].find((token: Token) => { - return token.addresses[chainId] === tokenAddress - }) - return token || undefined + const foundToken = TOKEN_HASH_MAP[chainId][tokenAddress] + return foundToken || undefined } } } @@ -236,14 +244,13 @@ const getLegacyTokensByChain = () => { } const getPoolByRouterIndex = () => { - const poolTokens: TokenByKey = {} + const poolTokensByRouterIndex: TokenByKey = {} Object.values(allPool).map((token) => { - const poolTokens: { [key: string]: any } = {} if (token.routerIndex !== undefined) { - poolTokens[token.routerIndex] = token + poolTokensByRouterIndex[token.routerIndex] = token } }) - return poolTokens + return poolTokensByRouterIndex } export const POOL_CHAINS_BY_NAME = getChainsByPoolName() diff --git a/packages/synapse-constants/package.json b/packages/synapse-constants/package.json index 84f6e7e05f..01f1e22703 100644 --- a/packages/synapse-constants/package.json +++ b/packages/synapse-constants/package.json @@ -1,6 +1,6 @@ { "name": "synapse-constants", - "version": "1.3.8", + "version": "1.3.16", "description": "This is an npm package that maintains all synapse constants", "main": "dist/index.js", "module": "dist/index.js", @@ -45,4 +45,4 @@ "webpack": "^5.89.0", "webpack-cli": "^5.1.4" } -} +} \ No newline at end of file diff --git a/services/explorer/consumer/parser/rfqparser.go b/services/explorer/consumer/parser/rfqparser.go index 0445e39c27..366bf2ac0f 100644 --- a/services/explorer/consumer/parser/rfqparser.go +++ b/services/explorer/consumer/parser/rfqparser.go @@ -166,13 +166,19 @@ func (p *RFQParser) applyPriceData(ctx context.Context, rfqEvent *model.RFQEvent one := 1.0 tokenPrice = &one } - - if rfqEvent.OriginAmount != nil { + // We can maybe hardcode this to be the integer of the event type if the second item is incorrect. + if rfqEvent.EventType == rfqTypes.BridgeRequestedEvent.Int() { amountUSD := GetAmountUSD(rfqEvent.OriginAmount, *rfqEvent.TokenDecimal, tokenPrice) if amountUSD != nil { logger.Warnf("RFQ GetAmountUSD properly found the token price for coingecko token: %s", coinGeckoID) rfqEvent.AmountUSD = *amountUSD } + } else if rfqEvent.EventType == rfqTypes.BridgeRelayedEvent.Int() { + amountUSD := GetAmountUSD(rfqEvent.DestinationAmount, *rfqEvent.TokenDecimal, tokenPrice) + if amountUSD != nil { + logger.Warnf("RFQ GetAmountUSD properly found the token price for coingecko token: %s", coinGeckoID) + rfqEvent.AmountUSD = *amountUSD + } } } @@ -222,13 +228,17 @@ func eventToRFQEvent(event rfqTypes.EventLog, chainID uint32) model.RFQEvent { func rfqEventToBridgeEvent(rfqEvent model.RFQEvent) model.BridgeEvent { bridgeType := bridgeTypes.BridgeRequestedEvent - + token := rfqEvent.OriginToken + amount := rfqEvent.OriginAmount destinationKappa := rfqEvent.TransactionID + var kappa *string if rfqEvent.EventType == rfqTypes.BridgeRelayedEvent.Int() { bridgeType = bridgeTypes.BridgeRelayedEvent destinationKappa = "" kappa = &rfqEvent.TransactionID + token = rfqEvent.DestinationToken + amount = rfqEvent.DestinationAmount } // Adjust sender and recipient based on null values @@ -247,8 +257,8 @@ func rfqEventToBridgeEvent(rfqEvent model.RFQEvent) model.BridgeEvent { EventType: bridgeType.Int(), BlockNumber: rfqEvent.BlockNumber, TxHash: rfqEvent.TxHash, - Token: rfqEvent.OriginToken, - Amount: rfqEvent.OriginAmount, + Token: token, + Amount: amount, EventIndex: rfqEvent.EventIndex, DestinationKappa: destinationKappa, Sender: sender, From b8ed18783b0229d20a648e864d34eaf49441eb1b Mon Sep 17 00:00:00 2001 From: defi-moses Date: Tue, 23 Apr 2024 19:21:41 +0100 Subject: [PATCH 2/3] fix for case sensitivity --- packages/explorer-ui/utils/addressToSymbol.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/explorer-ui/utils/addressToSymbol.ts b/packages/explorer-ui/utils/addressToSymbol.ts index ec4e00f5fa..15b41f8f74 100644 --- a/packages/explorer-ui/utils/addressToSymbol.ts +++ b/packages/explorer-ui/utils/addressToSymbol.ts @@ -1,4 +1,4 @@ -import { TOKEN_HASH_MAP, tokenAddressToToken } from 'synapse-constants' +import { TOKEN_HASH_MAP } from 'synapse-constants' export function addressToSymbol({ tokenAddress, chainId }) { if ( @@ -7,7 +7,9 @@ export function addressToSymbol({ tokenAddress, chainId }) { ) { return 'AVWETH' } - if (tokenAddress === '0xEeeeeEeeeEeEeeEeEeEeeEEEeeeeEeeeeeeeEEeE') { + if ( + tokenAddress.toLowerCase() === '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee' + ) { return 'ETH' } From d09c881f999a0b74dd028070306911e9684c0087 Mon Sep 17 00:00:00 2001 From: defi-moses Date: Tue, 23 Apr 2024 19:35:55 +0100 Subject: [PATCH 3/3] small linting fixes --- services/explorer/consumer/parser/rfqparser.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/services/explorer/consumer/parser/rfqparser.go b/services/explorer/consumer/parser/rfqparser.go index 366bf2ac0f..65da0f5bd7 100644 --- a/services/explorer/consumer/parser/rfqparser.go +++ b/services/explorer/consumer/parser/rfqparser.go @@ -111,7 +111,7 @@ func (p *RFQParser) MatureLogs(ctx context.Context, rfqEvent *model.RFQEvent, iF timeStampBig := uint64(*timeStamp) rfqEvent.TimeStamp = &timeStampBig - var curCoinGeckoId string + var curCoinGeckoID string tokenAddressStr := common.HexToAddress(rfqEvent.OriginToken).Hex() const ethAddress = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee" @@ -119,16 +119,16 @@ func (p *RFQParser) MatureLogs(ctx context.Context, rfqEvent *model.RFQEvent, iF rfqEvent.TokenSymbol = "ETH" rfqEvent.TokenDecimal = new(uint8) *rfqEvent.TokenDecimal = 18 - curCoinGeckoId = ethCoinGeckoID + curCoinGeckoID = ethCoinGeckoID } else { // Assuming any other token is USDC rfqEvent.TokenSymbol = "USDC" rfqEvent.TokenDecimal = new(uint8) *rfqEvent.TokenDecimal = 6 - curCoinGeckoId = usdcCoinGeckoID + curCoinGeckoID = usdcCoinGeckoID } // find the price data for that specific token - p.applyPriceData(ctx, rfqEvent, curCoinGeckoId) + p.applyPriceData(ctx, rfqEvent, curCoinGeckoID) // Would store into bridge database with a new goroutine but saw unreliable storage of events w/parent context cancellation. bridgeEvent := rfqEventToBridgeEvent(*rfqEvent)