Skip to content

Commit

Permalink
fix(token): change mainnet contract address to Gnosis
Browse files Browse the repository at this point in the history
  • Loading branch information
gacevicljubisa committed Oct 23, 2024
1 parent b5d500f commit 5489457
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
4 changes: 2 additions & 2 deletions pkg/wallet/token.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
18 changes: 10 additions & 8 deletions pkg/wallet/wallet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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)
}

Expand All @@ -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)

Check failure on line 210 in pkg/wallet/wallet.go

View workflow job for this annotation

GitHub Actions / lint

shadow: declaration of "err" shadows declaration at line 198 (govet)
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)
}

Expand Down

0 comments on commit 5489457

Please sign in to comment.