From 7d8a7ab6d01044d7cea6f6c191586a2588bdaae5 Mon Sep 17 00:00:00 2001 From: Morty Date: Mon, 12 Aug 2024 23:58:52 +0800 Subject: [PATCH] fix: history fetcher monitor DepositWrappedToken event --- bridge-history-api/abi/backend_abi.go | 26 +++++++++++++++---- bridge-history-api/conf/config.json | 3 ++- bridge-history-api/internal/config/config.go | 1 + .../internal/logic/l1_event_parser.go | 8 ++++++ .../internal/logic/l1_fetcher.go | 8 +++++- 5 files changed, 39 insertions(+), 7 deletions(-) diff --git a/bridge-history-api/abi/backend_abi.go b/bridge-history-api/abi/backend_abi.go index e92274c905..096c340e0d 100644 --- a/bridge-history-api/abi/backend_abi.go +++ b/bridge-history-api/abi/backend_abi.go @@ -9,11 +9,12 @@ import ( ) var ( - IL1ETHGatewayABI *abi.ABI - IL1ERC20GatewayABI *abi.ABI - IL1ERC721GatewayABI *abi.ABI - IL1ERC1155GatewayABI *abi.ABI - L1BatchBridgeGatewayABI *abi.ABI + IL1ETHGatewayABI *abi.ABI + IL1ERC20GatewayABI *abi.ABI + IL1ERC721GatewayABI *abi.ABI + IL1ERC1155GatewayABI *abi.ABI + L1BatchBridgeGatewayABI *abi.ABI + L1WrappedTokenGatewayABI *abi.ABI IL2ETHGatewayABI *abi.ABI IL2ERC20GatewayABI *abi.ABI @@ -35,6 +36,7 @@ var ( L1DepositERC1155Sig common.Hash L1BatchDepositERC1155Sig common.Hash L1BridgeBatchDepositSig common.Hash + L1DepositWrappedTokenSig common.Hash L2WithdrawETHSig common.Hash L2WithdrawERC20Sig common.Hash @@ -68,6 +70,7 @@ func init() { IL1ERC721GatewayABI, _ = IL1ERC721GatewayMetaData.GetAbi() IL1ERC1155GatewayABI, _ = IL1ERC1155GatewayMetaData.GetAbi() L1BatchBridgeGatewayABI, _ = L1BatchBridgeGatewayMetaData.GetAbi() + L1WrappedTokenGatewayABI, _ = L1WrappedTokenGatewayMetaData.GetAbi() L1DepositETHSig = IL1ETHGatewayABI.Events["DepositETH"].ID L1DepositERC20Sig = IL1ERC20GatewayABI.Events["DepositERC20"].ID @@ -76,6 +79,7 @@ func init() { L1DepositERC1155Sig = IL1ERC1155GatewayABI.Events["DepositERC1155"].ID L1BatchDepositERC1155Sig = IL1ERC1155GatewayABI.Events["BatchDepositERC1155"].ID L1BridgeBatchDepositSig = L1BatchBridgeGatewayABI.Events["Deposit"].ID + L1DepositWrappedTokenSig = L1WrappedTokenGatewayABI.Events["DepositWrappedToken"].ID IL2ETHGatewayABI, _ = IL2ETHGatewayMetaData.GetAbi() IL2ERC20GatewayABI, _ = IL2ERC20GatewayMetaData.GetAbi() @@ -176,6 +180,11 @@ var L2BatchBridgeGatewayMetaData = &bind.MetaData{ ABI: "[{\"type\":\"constructor\",\"inputs\":[{\"name\":\"_counterpart\",\"type\":\"address\",\"internalType\":\"address\"},{\"name\":\"_messenger\",\"type\":\"address\",\"internalType\":\"address\"}],\"stateMutability\":\"nonpayable\"},{\"type\":\"receive\",\"stateMutability\":\"payable\"},{\"type\":\"function\",\"name\":\"DEFAULT_ADMIN_ROLE\",\"inputs\":[],\"outputs\":[{\"name\":\"\",\"type\":\"bytes32\",\"internalType\":\"bytes32\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"KEEPER_ROLE\",\"inputs\":[],\"outputs\":[{\"name\":\"\",\"type\":\"bytes32\",\"internalType\":\"bytes32\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"batchHashes\",\"inputs\":[{\"name\":\"\",\"type\":\"address\",\"internalType\":\"address\"},{\"name\":\"\",\"type\":\"uint256\",\"internalType\":\"uint256\"}],\"outputs\":[{\"name\":\"\",\"type\":\"bytes32\",\"internalType\":\"bytes32\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"counterpart\",\"inputs\":[],\"outputs\":[{\"name\":\"\",\"type\":\"address\",\"internalType\":\"address\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"distribute\",\"inputs\":[{\"name\":\"l2Token\",\"type\":\"address\",\"internalType\":\"address\"},{\"name\":\"batchIndex\",\"type\":\"uint64\",\"internalType\":\"uint64\"},{\"name\":\"nodes\",\"type\":\"bytes32[]\",\"internalType\":\"bytes32[]\"}],\"outputs\":[],\"stateMutability\":\"nonpayable\"},{\"type\":\"function\",\"name\":\"failedAmount\",\"inputs\":[{\"name\":\"\",\"type\":\"address\",\"internalType\":\"address\"}],\"outputs\":[{\"name\":\"\",\"type\":\"uint256\",\"internalType\":\"uint256\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"finalizeBatchDeposit\",\"inputs\":[{\"name\":\"l1Token\",\"type\":\"address\",\"internalType\":\"address\"},{\"name\":\"l2Token\",\"type\":\"address\",\"internalType\":\"address\"},{\"name\":\"batchIndex\",\"type\":\"uint256\",\"internalType\":\"uint256\"},{\"name\":\"hash\",\"type\":\"bytes32\",\"internalType\":\"bytes32\"}],\"outputs\":[],\"stateMutability\":\"nonpayable\"},{\"type\":\"function\",\"name\":\"getRoleAdmin\",\"inputs\":[{\"name\":\"role\",\"type\":\"bytes32\",\"internalType\":\"bytes32\"}],\"outputs\":[{\"name\":\"\",\"type\":\"bytes32\",\"internalType\":\"bytes32\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"getRoleMember\",\"inputs\":[{\"name\":\"role\",\"type\":\"bytes32\",\"internalType\":\"bytes32\"},{\"name\":\"index\",\"type\":\"uint256\",\"internalType\":\"uint256\"}],\"outputs\":[{\"name\":\"\",\"type\":\"address\",\"internalType\":\"address\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"getRoleMemberCount\",\"inputs\":[{\"name\":\"role\",\"type\":\"bytes32\",\"internalType\":\"bytes32\"}],\"outputs\":[{\"name\":\"\",\"type\":\"uint256\",\"internalType\":\"uint256\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"grantRole\",\"inputs\":[{\"name\":\"role\",\"type\":\"bytes32\",\"internalType\":\"bytes32\"},{\"name\":\"account\",\"type\":\"address\",\"internalType\":\"address\"}],\"outputs\":[],\"stateMutability\":\"nonpayable\"},{\"type\":\"function\",\"name\":\"hasRole\",\"inputs\":[{\"name\":\"role\",\"type\":\"bytes32\",\"internalType\":\"bytes32\"},{\"name\":\"account\",\"type\":\"address\",\"internalType\":\"address\"}],\"outputs\":[{\"name\":\"\",\"type\":\"bool\",\"internalType\":\"bool\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"initialize\",\"inputs\":[],\"outputs\":[],\"stateMutability\":\"nonpayable\"},{\"type\":\"function\",\"name\":\"isDistributed\",\"inputs\":[{\"name\":\"\",\"type\":\"bytes32\",\"internalType\":\"bytes32\"}],\"outputs\":[{\"name\":\"\",\"type\":\"bool\",\"internalType\":\"bool\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"messenger\",\"inputs\":[],\"outputs\":[{\"name\":\"\",\"type\":\"address\",\"internalType\":\"address\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"renounceRole\",\"inputs\":[{\"name\":\"role\",\"type\":\"bytes32\",\"internalType\":\"bytes32\"},{\"name\":\"account\",\"type\":\"address\",\"internalType\":\"address\"}],\"outputs\":[],\"stateMutability\":\"nonpayable\"},{\"type\":\"function\",\"name\":\"revokeRole\",\"inputs\":[{\"name\":\"role\",\"type\":\"bytes32\",\"internalType\":\"bytes32\"},{\"name\":\"account\",\"type\":\"address\",\"internalType\":\"address\"}],\"outputs\":[],\"stateMutability\":\"nonpayable\"},{\"type\":\"function\",\"name\":\"supportsInterface\",\"inputs\":[{\"name\":\"interfaceId\",\"type\":\"bytes4\",\"internalType\":\"bytes4\"}],\"outputs\":[{\"name\":\"\",\"type\":\"bool\",\"internalType\":\"bool\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"tokenMapping\",\"inputs\":[{\"name\":\"\",\"type\":\"address\",\"internalType\":\"address\"}],\"outputs\":[{\"name\":\"\",\"type\":\"address\",\"internalType\":\"address\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"updateTokenMapping\",\"inputs\":[{\"name\":\"l2Token\",\"type\":\"address\",\"internalType\":\"address\"},{\"name\":\"l1Token\",\"type\":\"address\",\"internalType\":\"address\"}],\"outputs\":[],\"stateMutability\":\"nonpayable\"},{\"type\":\"function\",\"name\":\"withdrawFailedAmount\",\"inputs\":[{\"name\":\"token\",\"type\":\"address\",\"internalType\":\"address\"},{\"name\":\"receiver\",\"type\":\"address\",\"internalType\":\"address\"}],\"outputs\":[],\"stateMutability\":\"nonpayable\"},{\"type\":\"event\",\"name\":\"BatchDistribute\",\"inputs\":[{\"name\":\"l1Token\",\"type\":\"address\",\"indexed\":true,\"internalType\":\"address\"},{\"name\":\"l2Token\",\"type\":\"address\",\"indexed\":true,\"internalType\":\"address\"},{\"name\":\"batchIndex\",\"type\":\"uint256\",\"indexed\":true,\"internalType\":\"uint256\"}],\"anonymous\":false},{\"type\":\"event\",\"name\":\"DistributeFailed\",\"inputs\":[{\"name\":\"l2Token\",\"type\":\"address\",\"indexed\":true,\"internalType\":\"address\"},{\"name\":\"batchIndex\",\"type\":\"uint256\",\"indexed\":true,\"internalType\":\"uint256\"},{\"name\":\"receiver\",\"type\":\"address\",\"indexed\":false,\"internalType\":\"address\"},{\"name\":\"amount\",\"type\":\"uint256\",\"indexed\":false,\"internalType\":\"uint256\"}],\"anonymous\":false},{\"type\":\"event\",\"name\":\"FinalizeBatchDeposit\",\"inputs\":[{\"name\":\"l1Token\",\"type\":\"address\",\"indexed\":true,\"internalType\":\"address\"},{\"name\":\"l2Token\",\"type\":\"address\",\"indexed\":true,\"internalType\":\"address\"},{\"name\":\"batchIndex\",\"type\":\"uint256\",\"indexed\":true,\"internalType\":\"uint256\"}],\"anonymous\":false},{\"type\":\"event\",\"name\":\"Initialized\",\"inputs\":[{\"name\":\"version\",\"type\":\"uint8\",\"indexed\":false,\"internalType\":\"uint8\"}],\"anonymous\":false},{\"type\":\"event\",\"name\":\"RoleAdminChanged\",\"inputs\":[{\"name\":\"role\",\"type\":\"bytes32\",\"indexed\":true,\"internalType\":\"bytes32\"},{\"name\":\"previousAdminRole\",\"type\":\"bytes32\",\"indexed\":true,\"internalType\":\"bytes32\"},{\"name\":\"newAdminRole\",\"type\":\"bytes32\",\"indexed\":true,\"internalType\":\"bytes32\"}],\"anonymous\":false},{\"type\":\"event\",\"name\":\"RoleGranted\",\"inputs\":[{\"name\":\"role\",\"type\":\"bytes32\",\"indexed\":true,\"internalType\":\"bytes32\"},{\"name\":\"account\",\"type\":\"address\",\"indexed\":true,\"internalType\":\"address\"},{\"name\":\"sender\",\"type\":\"address\",\"indexed\":true,\"internalType\":\"address\"}],\"anonymous\":false},{\"type\":\"event\",\"name\":\"RoleRevoked\",\"inputs\":[{\"name\":\"role\",\"type\":\"bytes32\",\"indexed\":true,\"internalType\":\"bytes32\"},{\"name\":\"account\",\"type\":\"address\",\"indexed\":true,\"internalType\":\"address\"},{\"name\":\"sender\",\"type\":\"address\",\"indexed\":true,\"internalType\":\"address\"}],\"anonymous\":false},{\"type\":\"event\",\"name\":\"UpdateTokenMapping\",\"inputs\":[{\"name\":\"l2Token\",\"type\":\"address\",\"indexed\":true,\"internalType\":\"address\"},{\"name\":\"oldL1Token\",\"type\":\"address\",\"indexed\":true,\"internalType\":\"address\"},{\"name\":\"newL1Token\",\"type\":\"address\",\"indexed\":true,\"internalType\":\"address\"}],\"anonymous\":false},{\"type\":\"error\",\"name\":\"ErrorBatchDistributed\",\"inputs\":[]},{\"type\":\"error\",\"name\":\"ErrorBatchHashMismatch\",\"inputs\":[]},{\"type\":\"error\",\"name\":\"ErrorCallerNotMessenger\",\"inputs\":[]},{\"type\":\"error\",\"name\":\"ErrorL1TokenMismatched\",\"inputs\":[]},{\"type\":\"error\",\"name\":\"ErrorMessageSenderNotCounterpart\",\"inputs\":[]},{\"type\":\"error\",\"name\":\"ErrorNoFailedDistribution\",\"inputs\":[]}]", } +// L1WrappedTokenGatewayMetaData contains all meta data concerning the L1WrappedTokenGateway contract. +var L1WrappedTokenGatewayMetaData = &bind.MetaData{ + ABI: "[{\"type\":\"constructor\",\"inputs\":[{\"name\":\"_weth\",\"type\":\"address\",\"internalType\":\"address\"},{\"name\":\"_gateway\",\"type\":\"address\",\"internalType\":\"address\"}],\"stateMutability\":\"nonpayable\"},{\"type\":\"receive\",\"stateMutability\":\"payable\"},{\"type\":\"function\",\"name\":\"WETH\",\"inputs\":[],\"outputs\":[{\"name\":\"\",\"type\":\"address\",\"internalType\":\"address\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"deposit\",\"inputs\":[{\"name\":\"_to\",\"type\":\"address\",\"internalType\":\"address\"},{\"name\":\"_amount\",\"type\":\"uint256\",\"internalType\":\"uint256\"}],\"outputs\":[],\"stateMutability\":\"payable\"},{\"type\":\"function\",\"name\":\"gateway\",\"inputs\":[],\"outputs\":[{\"name\":\"\",\"type\":\"address\",\"internalType\":\"address\"}],\"stateMutability\":\"view\"},{\"type\":\"function\",\"name\":\"sender\",\"inputs\":[],\"outputs\":[{\"name\":\"\",\"type\":\"address\",\"internalType\":\"address\"}],\"stateMutability\":\"view\"},{\"type\":\"event\",\"name\":\"DepositWrappedToken\",\"inputs\":[{\"name\":\"from\",\"type\":\"address\",\"indexed\":true,\"internalType\":\"address\"},{\"name\":\"to\",\"type\":\"address\",\"indexed\":true,\"internalType\":\"address\"},{\"name\":\"amount\",\"type\":\"uint256\",\"indexed\":false,\"internalType\":\"uint256\"}],\"anonymous\":false},{\"type\":\"error\",\"name\":\"ErrorCallNotFromFeeRefund\",\"inputs\":[]}]", +} + type ETHMessageEvent struct { From common.Address To common.Address @@ -319,3 +328,10 @@ type L2BatchBridgeGatewayDistributeFailed struct { Receiver common.Address Amount *big.Int } + +// WrappedTokenMessageEvent represents a L1 wrapped token deposit event +type WrappedTokenMessageEvent struct { + From common.Address + To common.Address + Amount *big.Int +} \ No newline at end of file diff --git a/bridge-history-api/conf/config.json b/bridge-history-api/conf/config.json index 97edb351a9..79304bfbe4 100644 --- a/bridge-history-api/conf/config.json +++ b/bridge-history-api/conf/config.json @@ -20,7 +20,8 @@ "GatewayRouterAddr": "0xF8B1378579659D8F7EE5f3C929c2f3E332E41Fd6", "MessageQueueAddr": "0x0d7E906BD9cAFa154b048cFa766Cc1E54E39AF9B", "BatchBridgeGatewayAddr": "0x5Bcfd99c34cf7E06fc756f6f5aE7400504852bc4", - "GasTokenGatewayAddr": "0x0000000000000000000000000000000000000000" + "GasTokenGatewayAddr": "0x0000000000000000000000000000000000000000", + "WrappedTokenGatewayAddr": "0x0000000000000000000000000000000000000000" }, "L2": { "confirmation": 0, diff --git a/bridge-history-api/internal/config/config.go b/bridge-history-api/internal/config/config.go index 1659ed4339..a7f848a33e 100644 --- a/bridge-history-api/internal/config/config.go +++ b/bridge-history-api/internal/config/config.go @@ -31,6 +31,7 @@ type FetcherConfig struct { MessageQueueAddr string `json:"MessageQueueAddr"` BatchBridgeGatewayAddr string `json:"BatchBridgeGatewayAddr"` GasTokenGatewayAddr string `json:"GasTokenGatewayAddr"` + WrappedTokenGatewayAddr string `json:"WrappedTokenGatewayAddr"` } // RedisConfig redis config diff --git a/bridge-history-api/internal/logic/l1_event_parser.go b/bridge-history-api/internal/logic/l1_event_parser.go index 4809436894..967222e302 100644 --- a/bridge-history-api/internal/logic/l1_event_parser.go +++ b/bridge-history-api/internal/logic/l1_event_parser.go @@ -168,6 +168,14 @@ func (e *L1EventParser) ParseL1SingleCrossChainEventLogs(ctx context.Context, lo lastMessage.L2TokenAddress = event.L2Token.String() lastMessage.TokenIDs = utils.ConvertBigIntArrayToString(event.TokenIDs) lastMessage.TokenAmounts = utils.ConvertBigIntArrayToString(event.TokenAmounts) + case backendabi.L1DepositWrappedTokenSig: + event := backendabi.WrappedTokenMessageEvent{} + if err := utils.UnpackLog(backendabi.L1WrappedTokenGatewayABI, &event, "DepositWrappedToken", vlog); err != nil { + log.Error("Failed to unpack DepositWrappedToken event", "err", err) + return nil, nil, err + } + lastMessage := l1DepositMessages[len(l1DepositMessages)-1] + lastMessage.Sender = event.From.String() case backendabi.L1SentMessageEventSig: event := backendabi.L1SentMessageEvent{} if err := utils.UnpackLog(backendabi.IL1ScrollMessengerABI, &event, "SentMessage", vlog); err != nil { diff --git a/bridge-history-api/internal/logic/l1_fetcher.go b/bridge-history-api/internal/logic/l1_fetcher.go index 181bae31be..7853fe87a5 100644 --- a/bridge-history-api/internal/logic/l1_fetcher.go +++ b/bridge-history-api/internal/logic/l1_fetcher.go @@ -113,6 +113,11 @@ func NewL1FetcherLogic(cfg *config.FetcherConfig, db *gorm.DB, client *ethclient addressList = append(addressList, common.HexToAddress(cfg.GasTokenGatewayAddr)) gatewayList = append(gatewayList, common.HexToAddress(cfg.GasTokenGatewayAddr)) } + + if common.HexToAddress(cfg.WrappedTokenGatewayAddr) != (common.Address{}) { + addressList = append(addressList, common.HexToAddress(cfg.WrappedTokenGatewayAddr)) + gatewayList = append(gatewayList, common.HexToAddress(cfg.WrappedTokenGatewayAddr)) + } log.Info("L1 Fetcher configured with the following address list", "addresses", addressList, "gateways", gatewayList) @@ -219,7 +224,7 @@ func (f *L1FetcherLogic) l1FetcherLogs(ctx context.Context, from, to uint64) ([] Topics: make([][]common.Hash, 1), } - query.Topics[0] = make([]common.Hash, 15) + query.Topics[0] = make([]common.Hash, 16) query.Topics[0][0] = backendabi.L1DepositETHSig query.Topics[0][1] = backendabi.L1DepositERC20Sig query.Topics[0][2] = backendabi.L1DepositERC721Sig @@ -235,6 +240,7 @@ func (f *L1FetcherLogic) l1FetcherLogs(ctx context.Context, from, to uint64) ([] query.Topics[0][12] = backendabi.L1DropTransactionEventSig query.Topics[0][13] = backendabi.L1ResetDequeuedTransactionEventSig query.Topics[0][14] = backendabi.L1BridgeBatchDepositSig + query.Topics[0][15] = backendabi.L1DepositWrappedTokenSig eventLogs, err := f.client.FilterLogs(ctx, query) if err != nil {