Skip to content

Commit 770ce11

Browse files
committed
feat: replace FeeManager implementation with wallet-sdk gas package
1 parent 21a5a1a commit 770ce11

38 files changed

+1546
-1365
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ require (
9696
github.com/prometheus/client_model v0.6.1
9797
github.com/schollz/peerdiscovery v1.7.0
9898
github.com/status-im/extkeys v1.4.0
99-
github.com/status-im/go-wallet-sdk v0.0.0-20250924175027-d5faf23a5ef7
99+
github.com/status-im/go-wallet-sdk v0.0.0-20251017215230-2ff9d97b6bb3
100100
github.com/waku-org/go-waku v0.10.1-0.20251003225121-06c9af60f35b
101101
github.com/waku-org/waku-go-bindings v0.0.0-20250714110306-6feba5b0df4d
102102
github.com/wk8/go-ordered-map/v2 v2.1.7

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2094,8 +2094,8 @@ github.com/status-im/extkeys v1.4.0 h1:HiB/vQXZrGveZbGy3W6hI4T0CfCt0uP4xvGwjXL4c
20942094
github.com/status-im/extkeys v1.4.0/go.mod h1:AZGS9vJKbME5tovNqYH/LrfHu8t9ad9nxl76fbLG5PY=
20952095
github.com/status-im/go-sqlcipher/v4 v4.5.4-status.3 h1:/73h1w1hUfb3wVyTlNrUIwahZxatgesCHa6lwO57C2M=
20962096
github.com/status-im/go-sqlcipher/v4 v4.5.4-status.3/go.mod h1:mF2UmIpBnzFeBdu/ypTDb/LdbS0nk0dfSN1WUsWTjMA=
2097-
github.com/status-im/go-wallet-sdk v0.0.0-20250924175027-d5faf23a5ef7 h1:/v5gYWYI3qHClTNkgGwAyd9bvrujdHAw7d0ax1a3zOU=
2098-
github.com/status-im/go-wallet-sdk v0.0.0-20250924175027-d5faf23a5ef7/go.mod h1:mFt4aWzn/gR/IOWL75oEowJNQaBvpe3DxYQo0woAdCE=
2097+
github.com/status-im/go-wallet-sdk v0.0.0-20251017215230-2ff9d97b6bb3 h1:xHX/+hAaDB5kpoap2/SQpuUp+/wwfPdOT6ThfIOWexg=
2098+
github.com/status-im/go-wallet-sdk v0.0.0-20251017215230-2ff9d97b6bb3/go.mod h1:IzWMgrX6WmAAYqDSoF1sZZ8e9EdeIK5FRyDqXc/hs30=
20992099
github.com/status-im/gomoji v1.1.3-0.20220213022530-e5ac4a8732d4 h1:CtobZoiNdHpx+xurFxnuJ1xsGm3oKMfcZkB3vmomJmA=
21002100
github.com/status-im/gomoji v1.1.3-0.20220213022530-e5ac4a8732d4/go.mod h1:hmpnZzkzSZJbFYWAUkrPV8I36x7mdYiPhPqnALP4fKA=
21012101
github.com/status-im/keycard-go v0.0.0-20190316090335-8537d3370df4/go.mod h1:RZLeN1LMWmRsyYjvAu+I6Dm9QmlDaIIt+Y+4Kd7Tp+Q=

node/status_node_services.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,12 @@ func (b *StatusNode) WakuV2ExtService() *wakuv2ext.Service {
159159

160160
func (b *StatusNode) connectorService() *connector.Service {
161161
if b.connectorSrvc == nil {
162+
logger := b.logger.Named("connector")
162163
b.connectorSrvc = connector.NewService(
163-
b.logger.Named("connector"),
164+
logger,
164165
b.walletDB,
165166
b.rpcClient,
166-
fees.NewFeeManager(b.rpcClient),
167+
fees.NewFeeManager(b.rpcClient, logger.Named("feeManager")),
167168
b.rpcClient.GetNetworkManager(),
168169
&connector.Config{
169170
WSHost: b.config.WSHost,

rpc/chain/client.go

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
"github.com/ethereum/go-ethereum"
1515
"github.com/ethereum/go-ethereum/accounts/abi/bind"
1616
"github.com/ethereum/go-ethereum/common"
17-
"github.com/ethereum/go-ethereum/common/hexutil"
1817
"github.com/ethereum/go-ethereum/core"
1918
"github.com/ethereum/go-ethereum/core/types"
2019
"github.com/ethereum/go-ethereum/core/vm"
@@ -26,7 +25,6 @@ import (
2625
"github.com/status-im/status-go/healthmanager/rpcstatus"
2726
"github.com/status-im/status-go/rpc/chain/ethclient"
2827
"github.com/status-im/status-go/services/rpcstats"
29-
walletCommon "github.com/status-im/status-go/services/wallet/common"
3028

3129
sdkethclient "github.com/status-im/go-wallet-sdk/pkg/ethclient"
3230
)
@@ -592,10 +590,6 @@ func (c *ClientWithFallback) FeeHistory(ctx context.Context, blockCount uint64,
592590
}
593591

594592
func (c *ClientWithFallback) EstimateGas(ctx context.Context, msg ethereum.CallMsg) (uint64, error) {
595-
if c.ChainID == walletCommon.StatusNetworkSepolia {
596-
return c.LineaEstimateGas(ctx, msg)
597-
}
598-
599593
res, err := c.makeCall(
600594
ctx, MakeCallFunctor{
601595
MethodName: "eth_EstimateGas",
@@ -611,32 +605,20 @@ func (c *ClientWithFallback) EstimateGas(ctx context.Context, msg ethereum.CallM
611605
return res.(uint64), nil
612606
}
613607

614-
func (c *ClientWithFallback) LineaEstimateGas(ctx context.Context, msg ethereum.CallMsg) (uint64, error) {
615-
if c.ChainID != walletCommon.StatusNetworkSepolia {
616-
return 0, errors.New("LineaEstimateGas should be used for Status network only")
617-
}
618-
619-
const method = "linea_estimateGas"
608+
func (c *ClientWithFallback) LineaEstimateGas(ctx context.Context, msg ethereum.CallMsg) (*sdkethclient.LineaEstimateGasResult, error) {
620609
res, err := c.makeCall(
621610
ctx, MakeCallFunctor{
622-
MethodName: method,
611+
MethodName: "linea_estimateGas",
623612
Func: func(client ethclient.EthClientInterface) (interface{}, error) {
624-
var result struct {
625-
GasLimit hexutil.Uint64 `json:"gasLimit"`
626-
}
627-
err := client.CallContext(ctx, &result, method, walletCommon.ToCallArg(msg))
628-
if err != nil {
629-
return nil, err
630-
}
631-
632-
return uint64(result.GasLimit), nil
613+
return client.LineaEstimateGas(ctx, msg)
633614
},
634615
},
635616
)
636617
if err != nil {
637-
return 0, err
618+
return nil, err
638619
}
639-
return res.(uint64), nil
620+
621+
return res.(*sdkethclient.LineaEstimateGasResult), nil
640622
}
641623

642624
func (c *ClientWithFallback) SendTransaction(ctx context.Context, tx *types.Transaction) error {

rpc/chain/ethclient/eth_client.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ type BaseEthClientInterface interface {
5858
ethereum.GasEstimator
5959
FeeHistory(ctx context.Context, blockCount uint64, lastBlock *big.Int, rewardPercentiles []float64) (*ethereum.FeeHistory, error)
6060
BlockNumber(ctx context.Context) (uint64, error)
61+
LineaEstimateGas(ctx context.Context, msg ethereum.CallMsg) (*ethclient.LineaEstimateGasResult, error)
6162
// Internal calls
6263
Close()
6364
}

services/communitytokens/service.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"math/big"
99

1010
"github.com/pkg/errors"
11+
"go.uber.org/zap"
1112

1213
"github.com/ethereum/go-ethereum/accounts/abi/bind"
1314
"github.com/ethereum/go-ethereum/common"
@@ -50,20 +51,23 @@ type Service struct {
5051
transactor *transactions.Transactor
5152
feeManager *fees.FeeManager
5253
ethClientGetter rpc.EthClientGetter
54+
logger *zap.Logger
5355
}
5456

5557
// Returns a new Collectibles Service.
5658
func NewService(rpcClient *rpc.Client, accountsManager *accsmanagement.AccountsManager, config *params.NodeConfig, appDb *sql.DB,
5759
walletFeed *event.Feed, transactor *transactions.Transactor) *Service {
60+
logger := logutils.ZapLogger().Named("communitytokens")
5861
return &Service{
5962
manager: NewManager(rpcClient),
6063
accountsManager: accountsManager,
6164
config: config,
6265
db: communitytokensdatabase.NewCommunityTokensDatabase(appDb),
6366
walletFeed: walletFeed,
6467
transactor: transactor,
65-
feeManager: fees.NewFeeManager(rpcClient),
68+
feeManager: fees.NewFeeManager(rpcClient, logger.Named("feeManager")),
6669
ethClientGetter: rpcClient,
70+
logger: logger,
6771
}
6872
}
6973

@@ -93,14 +97,14 @@ func (s *Service) handleWalletEvent(event walletevent.Event) {
9397
var p pendingtxtracker.StatusChangedPayload
9498
err := json.Unmarshal([]byte(event.Message), &p)
9599
if err != nil {
96-
logutils.ZapLogger().Error(errors.Wrap(err, fmt.Sprintf("can't parse transaction message %v\n", event.Message)).Error())
100+
s.logger.Error(errors.Wrap(err, fmt.Sprintf("can't parse transaction message %v\n", event.Message)).Error())
97101
return
98102
}
99103
if p.Status == ac.Pending {
100104
return
101105
}
102106
if p.SendDetails == nil {
103-
logutils.ZapLogger().Error(errors.Wrap(err, fmt.Sprintf("cannot resolve details for tx hash %v on chain %v\n", p.Hash, p.ChainID)).Error())
107+
s.logger.Error(errors.Wrap(err, fmt.Sprintf("cannot resolve details for tx hash %v on chain %v\n", p.Hash, p.ChainID)).Error())
104108
return
105109
}
106110

@@ -152,7 +156,7 @@ func (s *Service) handleAirdropCommunityToken(status string, toAddress common.Ad
152156
publishErr := s.publishTokenActionToPrivilegedMembers(communityToken.CommunityID, uint64(communityToken.ChainID),
153157
communityToken.Address, protobuf.CommunityTokenAction_AIRDROP)
154158
if publishErr != nil {
155-
logutils.ZapLogger().Warn("can't publish airdrop action")
159+
s.logger.Warn("can't publish airdrop action")
156160
}
157161
}
158162
return communityToken, err
@@ -166,7 +170,7 @@ func (s *Service) handleRemoteDestructCollectible(status string, toAddress commo
166170
publishErr := s.publishTokenActionToPrivilegedMembers(communityToken.CommunityID, uint64(communityToken.ChainID),
167171
communityToken.Address, protobuf.CommunityTokenAction_REMOTE_DESTRUCT)
168172
if publishErr != nil {
169-
logutils.ZapLogger().Warn("can't publish remote destruct action")
173+
s.logger.Warn("can't publish remote destruct action")
170174
}
171175
}
172176
return communityToken, err
@@ -193,7 +197,7 @@ func (s *Service) handleBurnCommunityToken(status string, toAddress common.Addre
193197
publishErr := s.publishTokenActionToPrivilegedMembers(communityToken.CommunityID, uint64(communityToken.ChainID),
194198
communityToken.Address, protobuf.CommunityTokenAction_BURN)
195199
if publishErr != nil {
196-
logutils.ZapLogger().Warn("can't publish burn action")
200+
s.logger.Warn("can't publish burn action")
197201
}
198202
}
199203
return communityToken, err

services/connector/commands/send_transaction.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,15 +96,15 @@ func (c *SendTransactionCommand) Execute(ctx context.Context, request RPCRequest
9696
}
9797

9898
if !fetchedFees.EIP1559Enabled {
99-
params.GasPrice = (*hexutil.Big)(fetchedFees.GasPrice)
100-
} else {
101-
maxFees, priorityFee, _, err := fetchedFees.FeeFor(fees.GasFeeMedium)
102-
if err != nil {
103-
return "", err
104-
}
105-
params.MaxFeePerGas = (*hexutil.Big)(maxFees)
106-
params.MaxPriorityFeePerGas = (*hexutil.Big)(priorityFee)
99+
return "", fees.ErrEIP1559IncompaibleChain
107100
}
101+
102+
maxFees, priorityFee, _, err := fetchedFees.FeeFor(fees.GasFeeMedium)
103+
if err != nil {
104+
return "", err
105+
}
106+
params.MaxFeePerGas = (*hexutil.Big)(maxFees)
107+
params.MaxPriorityFeePerGas = (*hexutil.Big)(priorityFee)
108108
}
109109

110110
if params.Nonce == nil {

services/connector/commands/send_transaction_test.go

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,21 @@ func TestSendTransactionWithSignalTimout(t *testing.T) {
8989
state.ethClientGetter.EXPECT().EthClient(uint64(1)).AnyTimes().Return(mockedChainClient, nil)
9090
state.feeManager.EXPECT().SuggestedFees(gomock.Any(), uint64(1), common.Address(accountAddress)).Times(1).Return(
9191
&fees.SuggestedFees{
92-
GasPrice: big.NewInt(1),
93-
EIP1559Enabled: false,
92+
GasPrice: big.NewInt(1),
93+
BaseFee: big.NewInt(1),
94+
MaxPriorityFeePerGas: big.NewInt(1),
95+
MaxFeesLevels: &fees.MaxFeesLevels{
96+
Low: (*hexutil.Big)(big.NewInt(1)),
97+
LowPriority: (*hexutil.Big)(big.NewInt(1)),
98+
LowEstimatedTime: 1,
99+
Medium: (*hexutil.Big)(big.NewInt(1)),
100+
MediumPriority: (*hexutil.Big)(big.NewInt(1)),
101+
MediumEstimatedTime: 1,
102+
High: (*hexutil.Big)(big.NewInt(1)),
103+
HighPriority: (*hexutil.Big)(big.NewInt(1)),
104+
HighEstimatedTime: 1,
105+
},
106+
EIP1559Enabled: true,
94107
}, false, false, nil)
95108

96109
_, err = state.cmd.Execute(state.ctx, request)
@@ -136,8 +149,21 @@ func TestSendTransactionWithSignalAccepted(t *testing.T) {
136149
state.ethClientGetter.EXPECT().EthClient(uint64(1)).AnyTimes().Return(mockedChainClient, nil)
137150
state.feeManager.EXPECT().SuggestedFees(gomock.Any(), uint64(1), common.Address(accountAddress)).Times(1).Return(
138151
&fees.SuggestedFees{
139-
GasPrice: big.NewInt(1),
140-
EIP1559Enabled: false,
152+
GasPrice: big.NewInt(1),
153+
BaseFee: big.NewInt(1),
154+
MaxPriorityFeePerGas: big.NewInt(1),
155+
MaxFeesLevels: &fees.MaxFeesLevels{
156+
Low: (*hexutil.Big)(big.NewInt(1)),
157+
LowPriority: (*hexutil.Big)(big.NewInt(1)),
158+
LowEstimatedTime: 1,
159+
Medium: (*hexutil.Big)(big.NewInt(1)),
160+
MediumPriority: (*hexutil.Big)(big.NewInt(1)),
161+
MediumEstimatedTime: 1,
162+
High: (*hexutil.Big)(big.NewInt(1)),
163+
HighPriority: (*hexutil.Big)(big.NewInt(1)),
164+
HighEstimatedTime: 1,
165+
},
166+
EIP1559Enabled: true,
141167
}, false, false, nil)
142168

143169
response, err := state.cmd.Execute(state.ctx, request)
@@ -180,8 +206,21 @@ func TestSendTransactionWithSignalRejected(t *testing.T) {
180206
state.ethClientGetter.EXPECT().EthClient(uint64(1)).AnyTimes().Return(mockedChainClient, nil)
181207
state.feeManager.EXPECT().SuggestedFees(gomock.Any(), uint64(1), common.Address(accountAddress)).Times(1).Return(
182208
&fees.SuggestedFees{
183-
GasPrice: big.NewInt(1),
184-
EIP1559Enabled: false,
209+
GasPrice: big.NewInt(1),
210+
BaseFee: big.NewInt(1),
211+
MaxPriorityFeePerGas: big.NewInt(1),
212+
MaxFeesLevels: &fees.MaxFeesLevels{
213+
Low: (*hexutil.Big)(big.NewInt(1)),
214+
LowPriority: (*hexutil.Big)(big.NewInt(1)),
215+
LowEstimatedTime: 1,
216+
Medium: (*hexutil.Big)(big.NewInt(1)),
217+
MediumPriority: (*hexutil.Big)(big.NewInt(1)),
218+
MediumEstimatedTime: 1,
219+
High: (*hexutil.Big)(big.NewInt(1)),
220+
HighPriority: (*hexutil.Big)(big.NewInt(1)),
221+
HighEstimatedTime: 1,
222+
},
223+
EIP1559Enabled: true,
185224
}, false, false, nil)
186225

187226
_, err = state.cmd.Execute(state.ctx, request)

services/wallet/api.go

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -344,26 +344,19 @@ func (api *API) GetEstimatedLatestBlockNumber(ctx context.Context, chainID uint6
344344
// @deprecated we should remove it once clients fully switched to wallet router, `GetSuggestedRoutesAsync` should be used instead
345345
func (api *API) GetTransactionEstimatedTime(ctx context.Context, chainID uint64, maxFeePerGas *big.Float) (fees.TransactionEstimation, error) {
346346
logutils.ZapLogger().Debug("call to getTransactionEstimatedTime")
347-
return api.s.router.GetFeesManager().TransactionEstimatedTime(ctx, chainID, gweiToWei(maxFeePerGas)), nil
348-
}
349-
350-
func (api *API) GetTransactionEstimatedTimeV2(ctx context.Context, chainID uint64, gasPrice *hexutil.Big, maxFeePerGas *hexutil.Big, maxPriorityFeePerGas *hexutil.Big) (uint, error) {
351-
logutils.ZapLogger().Debug("call to getTransactionEstimatedTimeV2")
352-
isEIP1559Enabled, err := api.s.router.GetFeesManager().IsEIP1559Enabled(ctx, chainID)
353-
if err != nil {
354-
return 0, err
355-
}
356-
if !isEIP1559Enabled {
357-
return api.s.router.GetFeesManager().TransactionEstimatedTimeV2Legacy(ctx, chainID, gasPrice.ToInt()), nil
358-
}
359-
return api.s.router.GetFeesManager().TransactionEstimatedTimeV2(ctx, chainID, maxFeePerGas.ToInt(), maxPriorityFeePerGas.ToInt()), nil
347+
return api.s.router.GetFeesManager().EstimatedTimeLevel(ctx, chainID, gweiToWei(maxFeePerGas))
360348
}
361349

362350
func gweiToWei(val *big.Float) *big.Int {
363351
res, _ := new(big.Float).Mul(val, big.NewFloat(1000000000)).Int(nil)
364352
return res
365353
}
366354

355+
func (api *API) GetTransactionEstimatedTimeV2(ctx context.Context, chainID uint64, gasPrice *hexutil.Big, maxFeePerGas *hexutil.Big, maxPriorityFeePerGas *hexutil.Big) (uint, error) {
356+
logutils.ZapLogger().Debug("call to getTransactionEstimatedTimeV2")
357+
return api.s.router.GetFeesManager().EstimatedTime(ctx, chainID, maxFeePerGas.ToInt(), maxPriorityFeePerGas.ToInt())
358+
}
359+
367360
func (api *API) GetSuggestedRoutes(ctx context.Context, input *requests.RouteInputParams) (*router.SuggestedRoutes, error) {
368361
logutils.ZapLogger().Debug("call to GetSuggestedRoutes")
369362

0 commit comments

Comments
 (0)