Skip to content

Commit

Permalink
[DO NOT MERGE] Explorer Updates (#3353)
Browse files Browse the repository at this point in the history
* explorer UI updated

* rfq-indexer update

* explorer backend update

* [goreleaser] trigger explorer version bump

* rfq indexer with the right contracts

* [goreleaser] adding catch

* response error fixes and wld decimals

* adding address

* feat(rfq-indexer): add `request` column to `BridgeRequested` for refunds (#3287)

* feat(rfq-relayer): add MaxRelayAmount (#3259)

* Feat: add quoteParams helper for test

* Feat: add MaxQuoteAmount to relconfig

* Feat: use MaxQuoteAmount

* Feat: handle MaxQuoteAmount in quoter test

* Replace: MaxQuoteAmount -> MaxRelayAmount

* Feat: shouldProcess() returns false if max relay amount exceeded

* Feat: add test for MaxRelayAmount

* add request field for refunds

* adding to events typing

---------

Co-authored-by: dwasse <wassermandaniel8@gmail.com>
Co-authored-by: defi-moses <jakedinero@protonmail.com>

* fix api docs

* linting fixes

* fixing irrelavent files

* wc fixes and tests solved

* fix linting errors

* [goreleaser]

* refining tests

* adding bridge Module to graphql

* Adding to all bridge watcher queries

* adding worldchain to the chart

* adding other rfq events to the rfq events db

* fixing wld coingecko ticker [goreleaser]

* [goreleaser] coingecko update and new topic parsing

* small lint fix

* [goreleaser] linting fixes

* fix(rfq-indexer): add missing fields (#3309)

* add missing fields

---------

Co-authored-by: abtestingalpha <abtestingalpha@gmail.com>

---------

Co-authored-by: vro <168573323+golangisfun123@users.noreply.github.com>
Co-authored-by: dwasse <wassermandaniel8@gmail.com>
Co-authored-by: abtestingalpha <abtestingalpha@gmail.com>
  • Loading branch information
4 people authored Nov 18, 2024
1 parent 0eae097 commit 52163dc
Show file tree
Hide file tree
Showing 16 changed files with 524 additions and 81 deletions.
1 change: 1 addition & 0 deletions packages/explorer-ui/graphql/queries/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ export const DAILY_STATISTICS_BY_CHAIN = gql`
blast
scroll
linea
worldchain
total
}
}
Expand Down
2 changes: 2 additions & 0 deletions packages/rfq-indexer/api/src/types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ export interface BridgeProofDisputedEvents {
transactionHash: ColumnType<string>
chainId: ColumnType<number>
chain: ColumnType<string>
originChainId: ColumnType<number>
originChain: ColumnType<string>
}
// Add any other shared types used across the API
export type EventType =
Expand Down
9 changes: 5 additions & 4 deletions services/explorer/backfill/chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ func (b *BackfillSuite) TestBackfill() {
redeemLog, err := b.storeTestLog(bridgeTx, uint32(testChainID.Uint64()), 2)
Nil(b.T(), err)

bridgeTx, err = bridgeRef.TestWithdraw(transactOpts.TransactOpts, common.BigToAddress(big.NewInt(gofakeit.Int64())), common.HexToAddress(testTokens[0].TokenAddress), big.NewInt(int64(gofakeit.Uint32())), big.NewInt(int64(gofakeit.Uint32())), [32]byte{byte(gofakeit.Uint64())})
baseNum := gofakeit.Uint32()
bridgeTx, err = bridgeRef.TestWithdraw(transactOpts.TransactOpts, common.BigToAddress(big.NewInt(gofakeit.Int64())), common.HexToAddress(testTokens[0].TokenAddress), big.NewInt(int64(baseNum)), big.NewInt(int64(float64(baseNum)*0.01)), [32]byte{byte(gofakeit.Uint64())})
Nil(b.T(), err)
b.storeEthTx(bridgeTx, testChainID, big.NewInt(int64(2)), 3)
withdrawLog, err := b.storeTestLog(bridgeTx, uint32(testChainID.Uint64()), 2)
Expand Down Expand Up @@ -203,7 +204,7 @@ func (b *BackfillSuite) TestBackfill() {
redeemV1Log, err := b.storeTestLog(bridgeTx, uint32(testChainID.Uint64()), 3)
Nil(b.T(), err)

bridgeTx, err = bridgeV1Ref.TestWithdraw(transactOpts.TransactOpts, common.BigToAddress(big.NewInt(gofakeit.Int64())), common.HexToAddress(testTokens[0].TokenAddress), big.NewInt(int64(gofakeit.Uint32())), big.NewInt(int64(gofakeit.Uint32())), [32]byte{byte(gofakeit.Uint64())})
bridgeTx, err = bridgeV1Ref.TestWithdraw(transactOpts.TransactOpts, common.BigToAddress(big.NewInt(gofakeit.Int64())), common.HexToAddress(testTokens[0].TokenAddress), big.NewInt(int64(baseNum)), big.NewInt(int64(float64(baseNum)*0.01)), [32]byte{byte(gofakeit.Uint64())})
Nil(b.T(), err)
b.storeEthTx(bridgeTx, testChainID, big.NewInt(int64(3)), 3)
withdrawV1Log, err := b.storeTestLog(bridgeTx, uint32(testChainID.Uint64()), 3)
Expand Down Expand Up @@ -878,7 +879,7 @@ func (b *BackfillSuite) withdrawParity(log *types.Log, parser *parser.BridgePars
BlockNumber: log.BlockNumber,
TxHash: log.TxHash.String(),
Token: parsedLog.Token.String(),
Amount: parsedLog.Amount,
Amount: new(big.Int).Sub(parsedLog.Amount, parsedLog.Fee),

Recipient: recipient,
Fee: parsedLog.Fee,
Expand Down Expand Up @@ -911,7 +912,7 @@ func (b *BackfillSuite) withdrawParity(log *types.Log, parser *parser.BridgePars
BlockNumber: log.BlockNumber,
TxHash: log.TxHash.String(),
Token: parsedLog.Token.String(),
Amount: parsedLog.Amount,
Amount: new(big.Int).Sub(parsedLog.Amount, parsedLog.Fee),

Recipient: recipient,
Fee: parsedLog.Fee,
Expand Down
63 changes: 40 additions & 23 deletions services/explorer/consumer/parser/rfqparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package parser
import (
"context"
"database/sql"
"errors"
"fmt"
"strings"
"time"
Expand All @@ -23,7 +24,7 @@ import (

const ethCoinGeckoID = "ethereum"

// RFQParser parsers rfq logs.
// RFQParser parsers all rfq logs.
type RFQParser struct {
// consumerDB is the database to store parsed data in
consumerDB db.ConsumerDB
Expand Down Expand Up @@ -63,25 +64,32 @@ func (p *RFQParser) ParserType() string {
func (p *RFQParser) ParseLog(log ethTypes.Log, chainID uint32) (*model.RFQEvent, rfqTypes.EventLog, error) {
logTopic := log.Topics[0]
iFace, err := func(log ethTypes.Log) (rfqTypes.EventLog, error) {
switch logTopic {
case fastbridge.Topic(rfqTypes.BridgeRequestedEvent):
iFace, err := p.Filterer.ParseBridgeRequested(log)
if err != nil {
return nil, fmt.Errorf("could not parse fastbridge bridge requested : %w", err)
}
return iFace, nil
case fastbridge.Topic(rfqTypes.BridgeRelayedEvent):
iFace, err := p.Filterer.ParseBridgeRelayed(log)
if err != nil {
return nil, fmt.Errorf("could not parse fastbridge bridge relayed: %w", err)
}
return iFace, nil

default:
logger.Warnf("ErrUnknownTopic in rfq: %s %s chain: %d address: %s", log.TxHash, logTopic.String(), chainID, log.Address.Hex())
// Get the topic hash safely
bridgeRequestedTopic, err := fastbridge.Topic(rfqTypes.BridgeRequestedEvent)
if err == nil && logTopic == bridgeRequestedTopic {
return p.Filterer.ParseBridgeRequested(log)
}

return nil, fmt.Errorf(ErrUnknownTopic)
bridgeRelayedTopic, err := fastbridge.Topic(rfqTypes.BridgeRelayedEvent)
if err == nil && logTopic == bridgeRelayedTopic {
return p.Filterer.ParseBridgeRelayed(log)
}
bridgeProofProvidedTopic, err := fastbridge.Topic(rfqTypes.BridgeProvenEvent)
if err == nil && logTopic == bridgeProofProvidedTopic {
return p.Filterer.ParseBridgeProofProvided(log)
}
bridgeDepositClaimedTopic, err := fastbridge.Topic(rfqTypes.BridgeClaimedEvent)
if err == nil && logTopic == bridgeDepositClaimedTopic {
return p.Filterer.ParseBridgeDepositClaimed(log)
}
bridgeDepositRefundedTopic, err := fastbridge.Topic(rfqTypes.BridgeRefundedEvent)
if err == nil && logTopic == bridgeDepositRefundedTopic {
return p.Filterer.ParseBridgeDepositRefunded(log)
}

logger.Warnf("ErrUnknownTopic in rfq: %s %s chain: %d address: %s",
log.TxHash, logTopic.String(), chainID, log.Address.Hex())
return nil, errors.New("unknown topic")
}(log)

if err != nil {
Expand All @@ -108,25 +116,26 @@ func (p *RFQParser) MatureLogs(ctx context.Context, rfqEvent *model.RFQEvent, iF
}

// If we have a timestamp, populate the following attributes of rfqEvent.
// This logic will have to be generalized as we support more tokens (we need to programatically find coingecko id based on token address)
timeStampBig := uint64(*timeStamp)
rfqEvent.TimeStamp = &timeStampBig

var curCoinGeckoID string
tokenAddressStr := common.HexToAddress(rfqEvent.OriginToken).Hex()
const ethAddress = "0xeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"

if strings.EqualFold(tokenAddressStr, ethAddress) {
switch {
case strings.EqualFold(tokenAddressStr, ethAddress) || strings.EqualFold(tokenAddressStr, "0x2170Ed0880ac9A755fd29B2688956BD959F933F8"):
rfqEvent.TokenSymbol = "ETH"
rfqEvent.TokenDecimal = new(uint8)
*rfqEvent.TokenDecimal = 18
curCoinGeckoID = ethCoinGeckoID
} else if strings.EqualFold(tokenAddressStr, "0x2cFc85d8E48F8EAB294be644d9E25C3030863003") || strings.EqualFold(tokenAddressStr, "0xdC6fF44d5d932Cbd77B52E5612Ba0529DC6226F1") {
case strings.EqualFold(tokenAddressStr, "0x2cFc85d8E48F8EAB294be644d9E25C3030863003") || strings.EqualFold(tokenAddressStr, "0xdC6fF44d5d932Cbd77B52E5612Ba0529DC6226F1"):
rfqEvent.TokenSymbol = "WLD"
rfqEvent.TokenDecimal = new(uint8)
*rfqEvent.TokenDecimal = 18
curCoinGeckoID = "worldchain"
} else {
// Assuming any other token is USDC
curCoinGeckoID = "worldcoin-wld"
default:
rfqEvent.TokenSymbol = "USDC"
rfqEvent.TokenDecimal = new(uint8)
*rfqEvent.TokenDecimal = 6
Expand Down Expand Up @@ -232,6 +241,14 @@ func eventToRFQEvent(event rfqTypes.EventLog, chainID uint32) model.RFQEvent {
}

func rfqEventToBridgeEvent(rfqEvent model.RFQEvent) model.BridgeEvent {
// Only convert BridgeRequestedEvent and BridgeRelayedEvent to bridge events
// Exclude BridgeDepositRefunded, BridgeProofProvided, and BridgeDepositClaimed
eventType := rfqEvent.EventType
if eventType != rfqTypes.BridgeRequestedEvent.Int() &&
eventType != rfqTypes.BridgeRelayedEvent.Int() {
return model.BridgeEvent{}
}

bridgeType := bridgeTypes.BridgeRequestedEvent
token := rfqEvent.OriginToken
amount := rfqEvent.OriginAmount
Expand Down
Loading

0 comments on commit 52163dc

Please sign in to comment.