diff --git a/go.mod b/go.mod index efb5943..0ac7b40 100644 --- a/go.mod +++ b/go.mod @@ -9,7 +9,7 @@ require ( github.com/ethereum/go-ethereum v1.14.3 github.com/ethersphere/bee/v2 v2.2.0 github.com/ethersphere/beekeeper v0.17.8 - github.com/ethersphere/go-sw3-abi v0.6.6 + github.com/ethersphere/go-sw3-abi v0.6.5 github.com/spf13/cobra v1.8.0 github.com/stretchr/testify v1.8.4 k8s.io/apimachinery v0.22.16 diff --git a/go.sum b/go.sum index 0ec9c8b..5fc2884 100644 --- a/go.sum +++ b/go.sum @@ -103,8 +103,8 @@ github.com/ethersphere/bee/v2 v2.2.0 h1:UOrnGuacIlRD9RHSux9W13eI0ppsJvz6Xa0MTn6U github.com/ethersphere/bee/v2 v2.2.0/go.mod h1:9mrRirUnAJwSmnB9kJBx6Bo94LCgFrj2jYDJA20SIe0= github.com/ethersphere/beekeeper v0.17.8 h1:8hsokcCvmNMFcIc64RqgD+nwAQNtAWl9Xs90mgR2G7I= github.com/ethersphere/beekeeper v0.17.8/go.mod h1:HDermnHjOyI/1kHOVfoSdzVz0hIZzBVsDLKnFNDiCuk= -github.com/ethersphere/go-sw3-abi v0.6.6 h1:jYEYQjU3q7rAoD4k7mTjGxzDrYFFEh94YJbSWNNmjKM= -github.com/ethersphere/go-sw3-abi v0.6.6/go.mod h1:BmpsvJ8idQZdYEtWnvxA8POYQ8Rl/NhyCdF0zLMOOJU= +github.com/ethersphere/go-sw3-abi v0.6.5 h1:M5dcIe1zQYvGpY2K07UNkNU9Obc4U+A1fz68Ho/Q+XE= +github.com/ethersphere/go-sw3-abi v0.6.5/go.mod h1:BmpsvJ8idQZdYEtWnvxA8POYQ8Rl/NhyCdF0zLMOOJU= github.com/evanphx/json-patch v4.11.0+incompatible/go.mod h1:50XU6AFN0ol/bzJsmQLiYLvXMP4fmwYFNcr97nuDLSk= github.com/fjl/memsize v0.0.2 h1:27txuSD9or+NZlnOWdKUxeBzTAUkWCVh+4Gf2dWFOzA= github.com/fjl/memsize v0.0.2/go.mod h1:VvhXpOYNQvB+uIk2RvXzuaQtkQJzzIx6lSBe1xv7hi0= diff --git a/pkg/wallet/token.go b/pkg/wallet/token.go index d42770a..e5ab1b5 100644 --- a/pkg/wallet/token.go +++ b/pkg/wallet/token.go @@ -29,9 +29,9 @@ var chainToSwarmTokenMap = map[int64]Token{ Decimals: SwarmTokenDecimals, }, - // Mainnet + // Gnosis Mainnet 100: { - Contract: common.HexToAddress("0x19062190b1925b5b6689d7073fdfc8c2976ef8cb"), + Contract: common.HexToAddress("0xdBF3Ea6F5beE45c02255B2c26a16F300502F68da"), Symbol: "xBZZ", Decimals: SwarmTokenDecimals, }, diff --git a/pkg/wallet/wallet.go b/pkg/wallet/wallet.go index 66bf5ca..71e948a 100644 --- a/pkg/wallet/wallet.go +++ b/pkg/wallet/wallet.go @@ -17,7 +17,7 @@ import ( "github.com/ethersphere/go-sw3-abi/sw3abi" ) -var erc20ABI = mustParseABI(sw3abi.ERC20ABIv0_3_1) +var erc20ABI = mustParseABI(sw3abi.ERC20ABIv0_6_5) type TokenWallet interface { Balance( @@ -176,10 +176,13 @@ func (w *erc20Wallet) Balance( return nil, fmt.Errorf("failed to call contract, %w", err) } + if len(resp) == 0 { + return nil, fmt.Errorf("empty response from contract call: contract=%s", token.Contract.Hex()) + } + var balance *big.Int - err = erc20ABI.UnpackIntoInterface(&balance, "balanceOf", resp) - if err != nil { + if err = erc20ABI.UnpackIntoInterface(&balance, "balanceOf", resp); err != nil { return nil, fmt.Errorf("failed to unpack abi, %w", err) } @@ -204,16 +207,15 @@ func (w *erc20Wallet) Transfer( // Custom handling for LocalnetChainID. if chainID.Int64() == LocalnetChainID { - localnetMintFunction, decodeErr := hex.DecodeString("40c10f19") // mint(address,uint256) - if decodeErr != nil { + mint, err := hex.DecodeString("40c10f19") // mint(address,uint256) + if err != nil { return fmt.Errorf("failed decode string %w", err) } // Replace the first 4 bytes of the call data (transfer) with the localnet mint function. - copy(callData[:4], localnetMintFunction) + copy(callData[:4], mint) } - err = w.trxSender.Send(ctx, token.Contract, nil, callData) - if err != nil { + if err = w.trxSender.Send(ctx, token.Contract, nil, callData); err != nil { return fmt.Errorf("failed to make ERC20 token transfer, %w", err) }