Skip to content

Commit

Permalink
Merge cfe785b into 6aff0a6
Browse files Browse the repository at this point in the history
  • Loading branch information
Defi-Moses authored Oct 31, 2024
2 parents 6aff0a6 + cfe785b commit b8e8a66
Show file tree
Hide file tree
Showing 15 changed files with 520 additions and 80 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
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
60 changes: 38 additions & 22 deletions services/explorer/consumer/parser/rfqparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,25 +63,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, fmt.Errorf(ErrUnknownTopic)
}(log)

if err != nil {
Expand All @@ -108,25 +115,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 +240,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 b8e8a66

Please sign in to comment.