Skip to content

Commit 0dece85

Browse files
authored
Merge pull request #1767 from 0chain/fix/alchemy-gas-estimation
Fix: gas estimation alchemy call
2 parents 38bb49e + 998bc48 commit 0dece85

File tree

2 files changed

+14
-18
lines changed

2 files changed

+14
-18
lines changed

zcnbridge/bridge.go

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,12 @@ import (
44
"context"
55
"encoding/hex"
66
"fmt"
7-
coreClient "github.com/0chain/gosdk/core/client"
87
"math/big"
98
"strings"
109
"time"
1110

11+
coreClient "github.com/0chain/gosdk/core/client"
12+
1213
"github.com/0chain/gosdk/zcnbridge/ethereum/uniswapnetwork"
1314
"github.com/0chain/gosdk/zcnbridge/ethereum/uniswaprouter"
1415

@@ -998,21 +999,18 @@ func (b *BridgeClient) getProviderType() int {
998999
}
9991000

10001001
// estimateTenderlyGasAmount performs gas amount estimation for the given transaction using Tenderly provider.
1001-
func (b *BridgeClient) estimateTenderlyGasAmount(ctx context.Context, from, to string, value int64) (float64, error) {
1002+
func (b *BridgeClient) estimateTenderlyGasAmount(ctx context.Context) (float64, error) {
10021003
return 8000000, nil
10031004
}
10041005

10051006
// estimateAlchemyGasAmount performs gas amount estimation for the given transaction using Alchemy provider
1006-
func (b *BridgeClient) estimateAlchemyGasAmount(ctx context.Context, from, to, data string, value int64) (float64, error) {
1007+
func (b *BridgeClient) estimateAlchemyGasAmount(ctx context.Context, to, data string) (float64, error) {
10071008
client := jsonrpc.NewClient(b.EthereumNodeURL)
10081009

1009-
valueHex := ConvertIntToHex(value)
1010-
1011-
resp, err := client.Call(ctx, "eth_estimateGas", &AlchemyGasEstimationRequest{
1012-
From: from,
1013-
To: to,
1014-
Value: valueHex,
1015-
Data: data})
1010+
resp, err := client.Call(ctx, "eth_estimateGas", []*AlchemyGasEstimationRequest{{
1011+
To: to,
1012+
Data: data,
1013+
}})
10161014
if err != nil {
10171015
return 0, errors.Wrap(err, "gas price estimation failed")
10181016
}
@@ -1060,9 +1058,9 @@ func (b *BridgeClient) EstimateBurnWZCNGasAmount(ctx context.Context, from, to,
10601058

10611059
pack := "0x" + hex.EncodeToString(packRaw)
10621060

1063-
return b.estimateAlchemyGasAmount(ctx, from, to, pack, 0)
1061+
return b.estimateAlchemyGasAmount(ctx, to, pack)
10641062
case TenderlyProvider:
1065-
return b.estimateTenderlyGasAmount(ctx, from, to, 0)
1063+
return b.estimateTenderlyGasAmount(ctx)
10661064
}
10671065

10681066
return 0, errors.New("used json-rpc does not allow to estimate gas amount")
@@ -1103,9 +1101,9 @@ func (b *BridgeClient) EstimateMintWZCNGasAmount(
11031101

11041102
pack := "0x" + hex.EncodeToString(packRaw)
11051103

1106-
return b.estimateAlchemyGasAmount(ctx, from, to, pack, 0)
1104+
return b.estimateAlchemyGasAmount(ctx, to, pack)
11071105
case TenderlyProvider:
1108-
return b.estimateTenderlyGasAmount(ctx, from, to, 0)
1106+
return b.estimateTenderlyGasAmount(ctx)
11091107
}
11101108

11111109
return 0, errors.New("used json-rpc does not allow to estimate gas amount")

zcnbridge/bridge_helper.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,8 @@ import (
1212

1313
// AlchemyGasEstimationRequest describes request used for Alchemy enhanced JSON-RPC API.
1414
type AlchemyGasEstimationRequest struct {
15-
From string `json:"from"`
16-
To string `json:"to"`
17-
Value string `json:"value"`
18-
Data string `json:"data"`
15+
To string `json:"to"`
16+
Data string `json:"data"`
1917
}
2018

2119
// GasEstimationRequest describes request used for Alchemy enhanced JSON-RPC API.

0 commit comments

Comments
 (0)