Skip to content

Commit

Permalink
fix: change mainnet token contract to Gnosis (#36)
Browse files Browse the repository at this point in the history
  • Loading branch information
gacevicljubisa authored Oct 23, 2024
1 parent bb55820 commit 1bd1702
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
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
16 changes: 9 additions & 7 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)
mint, decodeErr := hex.DecodeString("40c10f19") // mint(address,uint256)
if decodeErr != 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 1bd1702

Please sign in to comment.