Skip to content

Commit

Permalink
Merge 8e2e6f2 into a330c8b
Browse files Browse the repository at this point in the history
  • Loading branch information
Defi-Moses authored Oct 31, 2024
2 parents a330c8b + 8e2e6f2 commit 7ee27c7
Show file tree
Hide file tree
Showing 14 changed files with 510 additions and 62 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
39 changes: 32 additions & 7 deletions services/explorer/consumer/parser/rfqparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,26 @@ func (p *RFQParser) ParseLog(log ethTypes.Log, chainID uint32) (*model.RFQEvent,
return nil, fmt.Errorf("could not parse fastbridge bridge relayed: %w", err)
}
return iFace, nil

case fastbridge.Topic(rfqTypes.BridgeRefundedEvent):
iFace, err := p.Filterer.ParseBridgeDepositRefunded(log)
if err != nil {
return nil, fmt.Errorf("could not parse fastbridge bridge refunded: %w", err)
}
return iFace, nil
case fastbridge.Topic(rfqTypes.BridgeProvenEvent):
iFace, err := p.Filterer.ParseBridgeProofProvided(log)
if err != nil {
return nil, fmt.Errorf("could not parse fastbridge bridge proven: %w", err)
}
return iFace, nil
case fastbridge.Topic(rfqTypes.BridgeClaimedEvent):
iFace, err := p.Filterer.ParseBridgeDepositClaimed(log)
if err != nil {
return nil, fmt.Errorf("could not parse fastbridge bridge claimed: %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())

return nil, fmt.Errorf(ErrUnknownTopic)
}
}(log)
Expand Down Expand Up @@ -108,25 +124,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 +249,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
270 changes: 270 additions & 0 deletions services/explorer/contracts/fastbridge/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,3 +191,273 @@ func (e FastBridgeBridgeRelayed) GetSendChainGas() *bool {
func (e FastBridgeBridgeRelayed) GetSender() *string {
return nil
}

// GetBlockNumber gets the block number for the event.
func (e FastBridgeBridgeDepositRefunded) GetBlockNumber() uint64 {
return e.Raw.BlockNumber
}

// GetTxHash gets the tx hash for the event.
func (e FastBridgeBridgeDepositRefunded) GetTxHash() common.Hash {
return e.Raw.TxHash
}

// GetContractAddress gets the contract address the event occurred on.
func (e FastBridgeBridgeDepositRefunded) GetContractAddress() common.Address {
return e.Raw.Address
}

// GetEventType gets the event type for the event.
func (e FastBridgeBridgeDepositRefunded) GetEventType() fastbridge.EventType {
return fastbridge.BridgeRefundedEvent
}

// GetEventIndex gets the event index for the event.
func (e FastBridgeBridgeDepositRefunded) GetEventIndex() uint64 {
return uint64(e.Raw.TxIndex)
}

// GetTransactionID gets the transaction id for the event.
func (e FastBridgeBridgeDepositRefunded) GetTransactionID() [32]byte {
return e.TransactionId
}

// GetSender gets the sender for the event.
func (e FastBridgeBridgeDepositRefunded) GetSender() *string {
return nil
}

// GetRequest gets the request for the event.
func (e FastBridgeBridgeDepositRefunded) GetRequest() *[]byte {
return nil
}

// GetOriginChainID gets the origin chain id for the event.
func (e FastBridgeBridgeDepositRefunded) GetOriginChainID() *big.Int {
return nil
}

// GetDestChainID gets the destination chain id for the event.
func (e FastBridgeBridgeDepositRefunded) GetDestChainID() *big.Int {
return nil
}

// GetOriginToken gets the origin token for the event.
func (e FastBridgeBridgeDepositRefunded) GetOriginToken() common.Address {
return common.Address{}
}

// GetDestToken gets the destination token for the event.
func (e FastBridgeBridgeDepositRefunded) GetDestToken() common.Address {
return common.Address{}
}

// GetOriginAmount gets the origin amount for the event.
func (e FastBridgeBridgeDepositRefunded) GetOriginAmount() *big.Int {
return nil
}

// GetDestAmount gets the destination amount for the event.
func (e FastBridgeBridgeDepositRefunded) GetDestAmount() *big.Int {
return nil
}

// GetSendChainGas gets the send chain gas for the event.
func (e FastBridgeBridgeDepositRefunded) GetSendChainGas() *bool {
return nil
}

// GetChainGasAmount gets the chain gas amount for the event.
func (e FastBridgeBridgeDepositRefunded) GetChainGasAmount() *big.Int {
return nil
}

// GetRelayer gets the relayer address for the event.
func (e FastBridgeBridgeDepositRefunded) GetRelayer() *string {
return nil
}

// GetTo gets the to address for the event.
func (e FastBridgeBridgeDepositRefunded) GetTo() *string {
return nil
}

// GetTxHash gets the tx hash for the event.
func (e FastBridgeBridgeProofProvided) GetTxHash() common.Hash {
return e.Raw.TxHash
}

// GetContractAddress gets the contract address the event occurred on.
func (e FastBridgeBridgeProofProvided) GetContractAddress() common.Address {
return e.Raw.Address
}

// GetBlockNumber gets the block number for the event.
func (e FastBridgeBridgeProofProvided) GetBlockNumber() uint64 {
return e.Raw.BlockNumber
}

// GetEventType gets the event type for the event.
func (e FastBridgeBridgeProofProvided) GetEventType() fastbridge.EventType {
return fastbridge.BridgeProvenEvent
}

// GetEventIndex gets the event index for the event.
func (e FastBridgeBridgeProofProvided) GetEventIndex() uint64 {
return uint64(e.Raw.TxIndex)
}

// GetTransactionID gets the transaction id for the event.
func (e FastBridgeBridgeProofProvided) GetTransactionID() [32]byte {
return e.TransactionId
}

// GetSender gets the sender for the event.
func (e FastBridgeBridgeProofProvided) GetSender() *string {
return nil
}

// GetRequest gets the request for the event.
func (e FastBridgeBridgeProofProvided) GetRequest() *[]byte {
return nil
}

// GetOriginChainID gets the origin chain id for the event.
func (e FastBridgeBridgeProofProvided) GetOriginChainID() *big.Int {
return nil
}

// GetDestChainID gets the destination chain id for the event.
func (e FastBridgeBridgeProofProvided) GetDestChainID() *big.Int {
return nil
}

// GetOriginToken gets the origin token for the event.
func (e FastBridgeBridgeProofProvided) GetOriginToken() common.Address {
return common.Address{}
}

// GetDestToken gets the destination token for the event.
func (e FastBridgeBridgeProofProvided) GetDestToken() common.Address {
return common.Address{}
}

// GetOriginAmount gets the origin amount for the event.
func (e FastBridgeBridgeProofProvided) GetOriginAmount() *big.Int {
return nil
}

// GetDestAmount gets the destination amount for the event.
func (e FastBridgeBridgeProofProvided) GetDestAmount() *big.Int {
return nil
}

// GetSendChainGas gets the send chain gas for the event.
func (e FastBridgeBridgeProofProvided) GetSendChainGas() *bool {
return nil
}

// GetChainGasAmount gets the chain gas amount for the event.
func (e FastBridgeBridgeProofProvided) GetChainGasAmount() *big.Int {
return nil
}

// GetRelayer gets the relayer address for the event.
func (e FastBridgeBridgeProofProvided) GetRelayer() *string {
return nil
}

// GetTo gets the to address for the event.
func (e FastBridgeBridgeProofProvided) GetTo() *string {
return nil
}

// GetTxHash gets the tx hash for the event.
func (e FastBridgeBridgeDepositClaimed) GetTxHash() common.Hash {
return e.Raw.TxHash
}

// GetContractAddress gets the contract address the event occurred on.
func (e FastBridgeBridgeDepositClaimed) GetContractAddress() common.Address {
return e.Raw.Address
}

// GetBlockNumber gets the block number for the event.
func (e FastBridgeBridgeDepositClaimed) GetBlockNumber() uint64 {
return e.Raw.BlockNumber
}

// GetEventType gets the event type for the event.
func (e FastBridgeBridgeDepositClaimed) GetEventType() fastbridge.EventType {
return fastbridge.BridgeClaimedEvent
}

// GetEventIndex gets the event index for the event.
func (e FastBridgeBridgeDepositClaimed) GetEventIndex() uint64 {
return uint64(e.Raw.TxIndex)
}

// GetTransactionID gets the transaction id for the event.
func (e FastBridgeBridgeDepositClaimed) GetTransactionID() [32]byte {
return e.TransactionId
}

// GetSender gets the sender for the event.
func (e FastBridgeBridgeDepositClaimed) GetSender() *string {
return nil
}

// GetRequest gets the request for the event.
func (e FastBridgeBridgeDepositClaimed) GetRequest() *[]byte {
return nil
}

// GetOriginChainID gets the origin chain id for the event.
func (e FastBridgeBridgeDepositClaimed) GetOriginChainID() *big.Int {
return nil
}

// GetDestChainID gets the destination chain id for the event.
func (e FastBridgeBridgeDepositClaimed) GetDestChainID() *big.Int {
return nil
}

// GetOriginToken gets the origin token for the event.
func (e FastBridgeBridgeDepositClaimed) GetOriginToken() common.Address {
return common.Address{}
}

// GetDestToken gets the destination token for the event.
func (e FastBridgeBridgeDepositClaimed) GetDestToken() common.Address {
return common.Address{}
}

// GetOriginAmount gets the origin amount for the event.
func (e FastBridgeBridgeDepositClaimed) GetOriginAmount() *big.Int {
return nil
}

// GetDestAmount gets the destination amount for the event.
func (e FastBridgeBridgeDepositClaimed) GetDestAmount() *big.Int {
return nil
}

// GetSendChainGas gets the send chain gas for the event.
func (e FastBridgeBridgeDepositClaimed) GetSendChainGas() *bool {
return nil
}

// GetChainGasAmount gets the chain gas amount for the event.
func (e FastBridgeBridgeDepositClaimed) GetChainGasAmount() *big.Int {
return nil
}

// GetRelayer gets the relayer address for the event.
func (e FastBridgeBridgeDepositClaimed) GetRelayer() *string {
return nil
}

// GetTo gets the to address for the event.
func (e FastBridgeBridgeDepositClaimed) GetTo() *string {
return nil
}
Loading

0 comments on commit 7ee27c7

Please sign in to comment.