Skip to content

Commit

Permalink
Always use L1 token address for bridge balance
Browse files Browse the repository at this point in the history
  • Loading branch information
trunghai95 committed Jul 22, 2024
1 parent a80865b commit cf8994b
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
1 change: 1 addition & 0 deletions server/service_xlayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -579,6 +579,7 @@ func (s *bridgeService) GetWstEthTokenNotWithdrawn(ctx context.Context, req *pb.
Msg: "internal: wstETH processor is not inited",
}, nil
}
// Always use L1 token address for storage
tokenAddr := processor.GetTokenAddressList()[0]
valueL1, errL1 := s.storage.GetBridgeBalance(ctx, tokenAddr, utils.GetMainNetworkId(), false, nil)
valueL2, errL2 := s.storage.GetBridgeBalance(ctx, tokenAddr, utils.GetRollupNetworkId(), false, nil)
Expand Down
8 changes: 3 additions & 5 deletions utils/messagebridge/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ var (
// Current supported tokens: USDC, wstETH
type Processor struct {
contractToTokenMapping map[common.Address]common.Address
contractAddressList []common.Address
tokenAddressList []common.Address
// DecodeMetadata decodes the metadata of the message bridge, returns the actual destination address and bridged amount
DecodeMetadataFn func(metadata []byte) (common.Address, *big.Int)
}
Expand All @@ -40,11 +42,7 @@ func (u *Processor) GetContractAddressList() []common.Address {

// GetTokenAddressList returns the list of original token addresses
func (u *Processor) GetTokenAddressList() []common.Address {
result := make([]common.Address, 0)
for _, addr := range u.contractToTokenMapping {
result = append(result, addr)
}
return result
return u.tokenAddressList
}

// CheckContractAddress returns true if the input address is in the contract address list of this bridge
Expand Down
2 changes: 2 additions & 0 deletions utils/messagebridge/usdclxly.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ func InitUSDCLxLyProcessor(usdcContractAddresses, usdcTokenAddresses []common.Ad
if len(contractToTokenMapping) > 0 {
processorMap[USDC] = &Processor{
contractToTokenMapping: contractToTokenMapping,
contractAddressList: usdcContractAddresses,
tokenAddressList: usdcTokenAddresses,
DecodeMetadataFn: func(metadata []byte) (common.Address, *big.Int) {
// Metadata structure:
// - Destination address: 32 bytes
Expand Down
2 changes: 2 additions & 0 deletions utils/messagebridge/wsteth.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ func InitWstETHProcessor(wstETHContractAddresses, wstETHTokenAddresses []common.
if len(contractToTokenMapping) > 0 {
processorMap[WstETH] = &Processor{
contractToTokenMapping: contractToTokenMapping,
contractAddressList: wstETHContractAddresses,
tokenAddressList: wstETHTokenAddresses,
DecodeMetadataFn: func(metadata []byte) (common.Address, *big.Int) {
// Metadata structure:
// - Destination address: 32 bytes
Expand Down

0 comments on commit cf8994b

Please sign in to comment.