Skip to content

Commit

Permalink
remove checksum asset from erc20AddressToForeignCoinAssetMap to reduc…
Browse files Browse the repository at this point in the history
…e the list
  • Loading branch information
ws4charlie committed Dec 10, 2024
1 parent b00ffe7 commit 3bba7d3
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 46 deletions.
23 changes: 22 additions & 1 deletion pkg/contracts/solana/inbound_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,28 @@ func Test_ParseInboundAsDepositAndCall(t *testing.T) {
// solana e2e deployer account
sender := "37yGiHAnLvWZUNVwu9esp74YQFqxU1qHCbABkDvRddUQ"
// example contract deployed during e2e test, read from tx result
expectedReceiver := []byte{117, 160, 106, 140, 37, 135, 57, 218, 223, 226, 53, 45, 87, 151, 61, 239, 158, 231, 162, 186}
expectedReceiver := []byte{
117,
160,
106,
140,
37,
135,
57,
218,
223,
226,
53,
45,
87,
151,
61,
239,
158,
231,
162,
186,
}
expectedMsg := []byte("hello lamports")
expectedDeposit := &Deposit{
Sender: sender,
Expand Down
28 changes: 9 additions & 19 deletions zetaclient/chains/evm/observer/inbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ var (
ethcommon.HexToAddress("0xdac17f958d2ee523a2206206994597c13d831ec7"): "0xdac17f958d2ee523a2206206994597c13d831ec7",
// DAI.ETH
ethcommon.HexToAddress("0x6b175474e89094c44da98b954eedeac495271d0f"): "0x6b175474e89094c44da98b954eedeac495271d0f",
// ULTI.ETH
ethcommon.HexToAddress("0x0E7779e698052f8fe56C415C3818FCf89de9aC6D"): "0x0E7779e698052f8fe56C415C3818FCf89de9aC6D",
},

// BSC mainnet
Expand All @@ -61,8 +59,6 @@ var (
ethcommon.HexToAddress("0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d"): "0x8ac76a51cc950d9822d68b83fe1ad97b32cd580d",
// USDT.BSC
ethcommon.HexToAddress("0x55d398326f99059ff775485246999027b3197955"): "0x55d398326f99059ff775485246999027b3197955",
// ULTI.BSC
ethcommon.HexToAddress("0x0E7779e698052f8fe56C415C3818FCf89de9aC6D"): "0x0E7779e698052f8fe56C415C3818FCf89de9aC6D",
},

// Polygon mainnet
Expand All @@ -78,32 +74,26 @@ var (
// USDC.AMOY
ethcommon.HexToAddress("0x41e94eb019c0762f9bfcf9fb1e58725bfb0e7582"): "0x41e94eb019c0762f9bfcf9fb1e58725bfb0e7582",
},

// Base mainnet
chains.BaseMainnet.ChainId: {
// USDC.BASE
ethcommon.HexToAddress("0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913"): "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
},
}
)

// ERC20AddressToForeignCoinAsset
func ERC20AddressToForeignCoinAsset(chainID int64, erc20Address ethcommon.Address) string {
// PatchZRC20Asset returns a patched asset string for the given chainID and erc20Address
// so that it matches the asset string in the foreign coin store.
func PatchZRC20Asset(chainID int64, erc20Address ethcommon.Address) string {
addressToAsset, found := erc20AddressToForeignCoinAssetMap[chainID]
switch {
case found:
if found {
// if found, convert the address to asset in foreigh coin store
asset, found := addressToAsset[erc20Address]
if found {
return asset
}

// use the checksum address as asset string by default
return erc20Address.Hex()
default:
// use the checksum address as asset string by default
return erc20Address.Hex()
}

// use the checksum address as asset string by default
return erc20Address.Hex()
}

// WatchInbound watches evm chain for incoming txs and post votes to zetacore
Expand Down Expand Up @@ -745,10 +735,10 @@ func (ob *Observer) BuildInboundVoteMsgForDepositedEvent(
return nil
}

// convert erc20Address to asset in foreign coin store to avoid checksum mismatch
// get patched asset string so that it matches the asset in the foreign coin store
// TODO: remove once the checksum conversion is fixed in the protocol
// https://github.com/zeta-chain/node/issues/3274
asset := ERC20AddressToForeignCoinAsset(ob.Chain().ChainId, event.Asset)
asset := PatchZRC20Asset(ob.Chain().ChainId, event.Asset)

message := hex.EncodeToString(event.Message)
ob.Logger().Inbound.Info().
Expand Down
23 changes: 2 additions & 21 deletions zetaclient/chains/evm/observer/inbound_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (
clienttypes "github.com/zeta-chain/node/zetaclient/types"
)

func Test_ERC20AddressToForeignCoinAsset(t *testing.T) {
func Test_PatchZRC20Asset(t *testing.T) {
tests := []struct {
name string
chainID int64
Expand Down Expand Up @@ -65,12 +65,6 @@ func Test_ERC20AddressToForeignCoinAsset(t *testing.T) {
erc20Address: ethcommon.HexToAddress("0x6b175474e89094c44da98b954eedeac495271d0f"),
assetString: "0x6b175474e89094c44da98b954eedeac495271d0f",
},
{
name: "ULTI.ETH",
chainID: chains.Ethereum.ChainId,
erc20Address: ethcommon.HexToAddress("0x0E7779e698052f8fe56C415C3818FCf89de9aC6D"),
assetString: "0x0E7779e698052f8fe56C415C3818FCf89de9aC6D",
},
// BSC Mainnet
{
name: "USDC.BSC",
Expand All @@ -84,12 +78,6 @@ func Test_ERC20AddressToForeignCoinAsset(t *testing.T) {
erc20Address: ethcommon.HexToAddress("0x55d398326f99059ff775485246999027b3197955"),
assetString: "0x55d398326f99059ff775485246999027b3197955",
},
{
name: "ULTI.BSC",
chainID: chains.BscMainnet.ChainId,
erc20Address: ethcommon.HexToAddress("0x0E7779e698052f8fe56C415C3818FCf89de9aC6D"),
assetString: "0x0E7779e698052f8fe56C415C3818FCf89de9aC6D",
},
// Polygon Mainnet
{
name: "USDT.POL",
Expand All @@ -110,18 +98,11 @@ func Test_ERC20AddressToForeignCoinAsset(t *testing.T) {
erc20Address: ethcommon.HexToAddress("0x41e94eb019c0762f9bfcf9fb1e58725bfb0e7582"),
assetString: "0x41e94eb019c0762f9bfcf9fb1e58725bfb0e7582",
},
// Base Mainnet
{
name: "USDC.BASE",
chainID: chains.BaseMainnet.ChainId,
erc20Address: ethcommon.HexToAddress("0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913"),
assetString: "0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913",
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
asset := observer.ERC20AddressToForeignCoinAsset(tt.chainID, tt.erc20Address)
asset := observer.PatchZRC20Asset(tt.chainID, tt.erc20Address)
require.Equal(t, tt.assetString, asset)
})
}
Expand Down
9 changes: 4 additions & 5 deletions zetaclient/chains/evm/observer/v2_inbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,10 @@ func (ob *Observer) newDepositInboundVote(event *gatewayevm.GatewayEVMDeposited)
isCrossChainCall = true
}

// convert erc20Address to asset in foreign coin store to avoid checksum mismatch
// convert erc20Address to asset in foreign coin store to avoid checksum mismatch
// get patched asset string so that it matches the one in the foreign coin store
// TODO: remove once the checksum conversion is fixed in the protocol
// https://github.com/zeta-chain/node/issues/3274
asset := ERC20AddressToForeignCoinAsset(ob.Chain().ChainId, event.Asset)
asset := PatchZRC20Asset(ob.Chain().ChainId, event.Asset)
if asset != event.Asset.Hex() {
ob.Logger().
Inbound.Info().
Expand Down Expand Up @@ -465,10 +464,10 @@ func (ob *Observer) newDepositAndCallInboundVote(event *gatewayevm.GatewayEVMDep
coinType = coin.CoinType_Gas
}

// convert erc20Address to asset in foreign coin store to avoid checksum mismatch
// get patched asset string so that it matches the one in the foreign coin store
// TODO: remove once the checksum conversion is fixed in the protocol
// https://github.com/zeta-chain/node/issues/3274
asset := ERC20AddressToForeignCoinAsset(ob.Chain().ChainId, event.Asset)
asset := PatchZRC20Asset(ob.Chain().ChainId, event.Asset)
if asset != event.Asset.Hex() {
ob.Logger().
Inbound.Info().
Expand Down

0 comments on commit 3bba7d3

Please sign in to comment.