Skip to content

Commit

Permalink
[goreleaser] fixing explorer UI and explorer indexer (#2512)
Browse files Browse the repository at this point in the history
* fixing explorer UI and explorer indexer

* fix for case sensitivity

* small linting fixes
  • Loading branch information
Defi-Moses authored Apr 23, 2024
1 parent 1fef431 commit 55ce3da
Show file tree
Hide file tree
Showing 11 changed files with 96 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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}
Expand All @@ -48,8 +52,11 @@ export function BridgeTransactionTable({ queryResult }) {
<IconAndAmount
formattedValue={toInfo.formattedValue}
tokenAddress={toInfo.tokenAddress}
chainId={toInfo.chainID}
tokenSymbol={toInfo.tokenSymbol}
chainId={fromInfo.destinationChainID}
tokenSymbol={addressToSymbol({
tokenAddress: toInfo.tokenAddress,
chainId: fromInfo.destinationChainID,
}) || toInfo.tokenSymbol}
iconSize="w-4 h-4"
textSize="text-sm"
styledCoin={true}
Expand Down
20 changes: 13 additions & 7 deletions packages/explorer-ui/components/misc/AssetImage.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { QuestionMarkCircleIcon } from '@heroicons/react/outline'
import { TOKEN_HASH_MAP, AVWETH } from 'synapse-constants'
import { TOKEN_HASH_MAP, AVWETH, tokenAddressToToken, ETH, USDC, tokenSymbolToToken } from 'synapse-constants'
import { getTokenAddressUrl } from '@urls'
import Image from 'next/image'

export function AssetImage({ tokenAddress, chainId, className }) {
export function AssetImage({ tokenAddress, chainId, className, tokenSymbol= '' }) {
tokenAddress = tokenAddress
if (hasRequiredData({ tokenAddress, chainId })) {
const t = chainId && tokenAddress && TOKEN_HASH_MAP[chainId]?.[tokenAddress]
return (
return(
<a href={getTokenAddressUrl({ tokenAddress, chainId })}>
<Image
className={`inline w-5 h-5 mr-2 rounded-md ${className}`}
Expand All @@ -33,10 +33,16 @@ export function AssetImage({ tokenAddress, chainId, className }) {
)
} else {
return (
<QuestionMarkCircleIcon
className={`inline w-5 h-5 mr-2 rounded-md ${className}`}
strokeWidth={2}
/>
// temporary fix until either symbolToToken works better as a function or explorer indexer has the right token addresses
<Image
className={`inline w-5 h-5 mr-2 rounded-md ${className}`}
src={USDC?.icon}
alt=""
/>
// <QuestionMarkCircleIcon
// className={`inline w-5 h-5 mr-2 rounded-md ${className}`}
// strokeWidth={2}
// />
)
}
}
Expand Down
7 changes: 4 additions & 3 deletions packages/explorer-ui/components/misc/IconAndAmount.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand All @@ -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) {
Expand All @@ -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 = <div className={styledCoinClass}>{displaySymbol}</div>
amount = formattedValue
} else {
Expand All @@ -46,6 +46,7 @@ export function IconAndAmount({
<div className="flex flex-row items-center ">
<AssetImage
tokenAddress={tokenAddress}
tokenSymbol={tokenSymbol}
chainId={chainId}
className={`${iconSize} inline mr-1 rounded-lg hover:opacity-[0.8] transition-all ease-in-out`}
/>
Expand Down
4 changes: 2 additions & 2 deletions packages/explorer-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"recharts": "^2.3.2",
"sharp": "^0.31.3",
"swr": "^1.3.0",
"synapse-constants": "^1.3.9",
"synapse-constants": "^1.3.16",
"tailwind-merge": "^1.3.0",
"tiny-warning": "^1.0.3",
"web-vitals": "^2.1.4"
Expand Down Expand Up @@ -83,4 +83,4 @@
"tailwindcss": "^3.0.24",
"ts-loader": "^9.5.1"
}
}
}
8 changes: 8 additions & 0 deletions packages/explorer-ui/pages/tx/[kappa].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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/' +
Expand Down
6 changes: 5 additions & 1 deletion packages/explorer-ui/utils/addressToSymbol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@ export function addressToSymbol({ tokenAddress, chainId }) {
) {
return 'AVWETH'
}
if (
tokenAddress.toLowerCase() === '0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee'
) {
return 'ETH'
}

const symbol =
tokenAddress && chainId && TOKEN_HASH_MAP[chainId][tokenAddress]?.symbol

return symbol
}
7 changes: 7 additions & 0 deletions packages/synapse-constants/constants/chains/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}
9 changes: 5 additions & 4 deletions packages/synapse-constants/constants/tokens/bridgeable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -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,
},
Expand Down
35 changes: 21 additions & 14 deletions packages/synapse-constants/constants/tokens/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -114,24 +113,33 @@ 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 = (
chainId: number,
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
}
}
}
Expand Down Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions packages/synapse-constants/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "synapse-constants",
"version": "1.3.9",
"version": "1.3.16",
"description": "This is an npm package that maintains all synapse constants",
"main": "dist/index.js",
"module": "dist/index.js",
Expand Down Expand Up @@ -45,4 +45,4 @@
"webpack": "^5.89.0",
"webpack-cli": "^5.1.4"
}
}
}
28 changes: 19 additions & 9 deletions services/explorer/consumer/parser/rfqparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,24 +111,24 @@ 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"

if strings.EqualFold(tokenAddressStr, ethAddress) {
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)
Expand Down Expand Up @@ -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
}
}
}

Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down

0 comments on commit 55ce3da

Please sign in to comment.