Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(wallet)_: include l1 fees info (for the tx and approval) in the response #6271

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions contracts/gas-price-oracle/address.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ var ErrorNotAvailableOnChainID = errors.New("not available for chainID")
var contractAddressByChainID = map[uint64]common.Address{
wallet_common.OptimismMainnet: common.HexToAddress("0x8527c030424728cF93E72bDbf7663281A44Eeb22"),
wallet_common.OptimismSepolia: common.HexToAddress("0x5230210c2b4995FD5084b0F5FD0D7457aebb5010"),
wallet_common.ArbitrumMainnet: common.HexToAddress("0x8527c030424728cF93E72bDbf7663281A44Eeb22"),
wallet_common.ArbitrumSepolia: common.HexToAddress("0x5230210c2b4995FD5084b0F5FD0D7457aebb5010"),
wallet_common.BaseMainnet: common.HexToAddress("0x8527c030424728cF93E72bDbf7663281A44Eeb22"),
wallet_common.BaseSepolia: common.HexToAddress("0x5230210c2b4995FD5084b0F5FD0D7457aebb5010"),
}
Expand Down
2 changes: 1 addition & 1 deletion services/wallet/router/pathprocessor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ type PathProcessor interface {
// PackTxInputData packs tx for sending
PackTxInputData(params ProcessorInputParams) ([]byte, error)
// EstimateGas estimates the gas
EstimateGas(params ProcessorInputParams) (uint64, error)
EstimateGas(params ProcessorInputParams, input []byte) (uint64, error)
// CalculateAmountOut calculates the amount out
CalculateAmountOut(params ProcessorInputParams) (*big.Int, error)
// Send sends the tx, returns the hash and the used nonce (lastUsedNonce is -1 if it's the first tx)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ func (c *CelerBridgeProcessor) PackTxInputData(params ProcessorInputParams) ([]b
}
}

func (s *CelerBridgeProcessor) EstimateGas(params ProcessorInputParams) (uint64, error) {
func (s *CelerBridgeProcessor) EstimateGas(params ProcessorInputParams, input []byte) (uint64, error) {
if params.TestsMode {
if params.TestEstimationMap != nil {
if val, ok := params.TestEstimationMap[s.Name()]; ok {
Expand All @@ -248,11 +248,6 @@ func (s *CelerBridgeProcessor) EstimateGas(params ProcessorInputParams) (uint64,

value := new(big.Int)

input, err := s.PackTxInputData(params)
if err != nil {
return 0, createBridgeCellerErrorResponse(err)
}

contractAddress, err := s.GetContractAddress(params)
if err != nil {
return 0, createBridgeCellerErrorResponse(err)
Expand Down
12 changes: 5 additions & 7 deletions services/wallet/router/pathprocessor/processor_bridge_hop.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,9 @@ func (c *HopBridgeProcessor) getAppropriateABI(contractType string, chainID uint
}

func (h *HopBridgeProcessor) PackTxInputData(params ProcessorInputParams) ([]byte, error) {
if params.TestsMode {
return []byte{}, nil
}
_, contractType, err := hop.GetContractAddress(params.FromChain.ChainID, params.FromToken.Symbol)
if err != nil {
return []byte{}, createBridgeHopErrorResponse(err)
Expand Down Expand Up @@ -232,7 +235,7 @@ func (h *HopBridgeProcessor) packTxInputDataInternally(params ProcessorInputPara
return []byte{}, ErrContractTypeNotSupported
}

func (h *HopBridgeProcessor) EstimateGas(params ProcessorInputParams) (uint64, error) {
func (h *HopBridgeProcessor) EstimateGas(params ProcessorInputParams, input []byte) (uint64, error) {
if params.TestsMode {
if params.TestEstimationMap != nil {
if val, ok := params.TestEstimationMap[h.Name()]; ok {
Expand All @@ -247,12 +250,7 @@ func (h *HopBridgeProcessor) EstimateGas(params ProcessorInputParams) (uint64, e
value = params.AmountIn
}

contractAddress, contractType, err := hop.GetContractAddress(params.FromChain.ChainID, params.FromToken.Symbol)
if err != nil {
return 0, createBridgeHopErrorResponse(err)
}

input, err := h.packTxInputDataInternally(params, contractType)
contractAddress, _, err := hop.GetContractAddress(params.FromChain.ChainID, params.FromToken.Symbol)
if err != nil {
return 0, createBridgeHopErrorResponse(err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (s *ENSPublicKeyProcessor) PackTxInputData(params ProcessorInputParams) ([]
return resolverABI.Pack("setPubkey", walletCommon.NameHash(params.Username), x, y)
}

func (s *ENSPublicKeyProcessor) EstimateGas(params ProcessorInputParams) (uint64, error) {
func (s *ENSPublicKeyProcessor) EstimateGas(params ProcessorInputParams, input []byte) (uint64, error) {
if params.TestsMode {
if params.TestEstimationMap != nil {
if val, ok := params.TestEstimationMap[s.Name()]; ok {
Expand All @@ -78,11 +78,6 @@ func (s *ENSPublicKeyProcessor) EstimateGas(params ProcessorInputParams) (uint64
return 0, createENSPublicKeyErrorResponse(err)
}

input, err := s.PackTxInputData(params)
if err != nil {
return 0, createENSPublicKeyErrorResponse(err)
}

ethClient, err := s.contractMaker.RPCClient.EthClient(params.FromChain.ChainID)
if err != nil {
return 0, err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ func (s *ENSRegisterProcessor) PackTxInputData(params ProcessorInputParams) ([]b
return sntABI.Pack("approveAndCall", registryAddr, price, extraData)
}

func (s *ENSRegisterProcessor) EstimateGas(params ProcessorInputParams) (uint64, error) {
func (s *ENSRegisterProcessor) EstimateGas(params ProcessorInputParams, input []byte) (uint64, error) {
if params.TestsMode {
if params.TestEstimationMap != nil {
if val, ok := params.TestEstimationMap[s.Name()]; ok {
Expand All @@ -114,11 +114,6 @@ func (s *ENSRegisterProcessor) EstimateGas(params ProcessorInputParams) (uint64,
return 0, createENSRegisterProcessorErrorResponse(err)
}

input, err := s.PackTxInputData(params)
if err != nil {
return 0, createENSRegisterProcessorErrorResponse(err)
}

ethClient, err := s.contractMaker.RPCClient.EthClient(params.FromChain.ChainID)
if err != nil {
return 0, createENSRegisterProcessorErrorResponse(err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (s *ENSReleaseProcessor) PackTxInputData(params ProcessorInputParams) ([]by
return registrarABI.Pack("release", walletCommon.UsernameToLabel(name))
}

func (s *ENSReleaseProcessor) EstimateGas(params ProcessorInputParams) (uint64, error) {
func (s *ENSReleaseProcessor) EstimateGas(params ProcessorInputParams, input []byte) (uint64, error) {
if params.TestsMode {
if params.TestEstimationMap != nil {
if val, ok := params.TestEstimationMap[s.Name()]; ok {
Expand All @@ -78,11 +78,6 @@ func (s *ENSReleaseProcessor) EstimateGas(params ProcessorInputParams) (uint64,
return 0, createENSReleaseErrorResponse(err)
}

input, err := s.PackTxInputData(params)
if err != nil {
return 0, createENSReleaseErrorResponse(err)
}

ethClient, err := s.contractMaker.RPCClient.EthClient(params.FromChain.ChainID)
if err != nil {
return 0, createENSReleaseErrorResponse(err)
Expand Down
7 changes: 1 addition & 6 deletions services/wallet/router/pathprocessor/processor_erc1155.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (s *ERC1155Processor) PackTxInputData(params ProcessorInputParams) ([]byte,
)
}

func (s *ERC1155Processor) EstimateGas(params ProcessorInputParams) (uint64, error) {
func (s *ERC1155Processor) EstimateGas(params ProcessorInputParams, input []byte) (uint64, error) {
if params.TestsMode {
if params.TestEstimationMap != nil {
if val, ok := params.TestEstimationMap[s.Name()]; ok {
Expand All @@ -91,11 +91,6 @@ func (s *ERC1155Processor) EstimateGas(params ProcessorInputParams) (uint64, err

value := new(big.Int)

input, err := s.PackTxInputData(params)
if err != nil {
return 0, createERC1155ErrorResponse(err)
}

msg := ethereum.CallMsg{
From: params.FromAddr,
To: &params.FromToken.Address,
Expand Down
7 changes: 1 addition & 6 deletions services/wallet/router/pathprocessor/processor_erc721.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (s *ERC721Processor) PackTxInputData(params ProcessorInputParams) ([]byte,
return s.packTxInputDataInternally(params, functionNameTransferFrom)
}

func (s *ERC721Processor) EstimateGas(params ProcessorInputParams) (uint64, error) {
func (s *ERC721Processor) EstimateGas(params ProcessorInputParams, input []byte) (uint64, error) {
if params.TestsMode {
if params.TestEstimationMap != nil {
if val, ok := params.TestEstimationMap[s.Name()]; ok {
Expand All @@ -128,11 +128,6 @@ func (s *ERC721Processor) EstimateGas(params ProcessorInputParams) (uint64, erro

value := new(big.Int)

input, err := s.PackTxInputData(params)
if err != nil {
return 0, createERC721ErrorResponse(err)
}

msg := ethereum.CallMsg{
From: params.FromAddr,
To: &params.FromToken.Address,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ func (s *StickersBuyProcessor) PackTxInputData(params ProcessorInputParams) ([]b
return sntABI.Pack("approveAndCall", stickerMarketAddress, packInfo.Price, extraData)
}

func (s *StickersBuyProcessor) EstimateGas(params ProcessorInputParams) (uint64, error) {
func (s *StickersBuyProcessor) EstimateGas(params ProcessorInputParams, input []byte) (uint64, error) {
if params.TestsMode {
if params.TestEstimationMap != nil {
if val, ok := params.TestEstimationMap[s.Name()]; ok {
Expand All @@ -103,11 +103,6 @@ func (s *StickersBuyProcessor) EstimateGas(params ProcessorInputParams) (uint64,
return 0, createStickersBuyErrorResponse(err)
}

input, err := s.PackTxInputData(params)
if err != nil {
return 0, createStickersBuyErrorResponse(err)
}

ethClient, err := s.contractMaker.RPCClient.EthClient(params.FromChain.ChainID)
if err != nil {
return 0, createStickersBuyErrorResponse(err)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func (s *SwapParaswapProcessor) PackTxInputData(params ProcessorInputParams) ([]
return []byte{}, nil
}

func (s *SwapParaswapProcessor) EstimateGas(params ProcessorInputParams) (uint64, error) {
func (s *SwapParaswapProcessor) EstimateGas(params ProcessorInputParams, input []byte) (uint64, error) {
if params.TestsMode {
if params.TestEstimationMap != nil {
if val, ok := params.TestEstimationMap[s.Name()]; ok {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
mock_paraswap "github.com/status-im/status-go/services/wallet/thirdparty/paraswap/mock"
"github.com/status-im/status-go/services/wallet/token"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -136,7 +137,9 @@ func TestParaswapErrors(t *testing.T) {

for _, tc := range testCases {
expectClientFetchPriceRoute(client, paraswap.Route{}, errors.New(tc.clientError))
_, err := processor.EstimateGas(testInputParams)
inputData, err := processor.PackTxInputData(testInputParams)
assert.NoError(t, err)
_, err = processor.EstimateGas(testInputParams, inputData)
require.Equal(t, tc.processorError.Error(), err.Error())
}
}
12 changes: 9 additions & 3 deletions services/wallet/router/pathprocessor/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -322,20 +322,26 @@ func TestPathProcessors(t *testing.T) {
assert.Equal(t, expResult.expected, result)

if tt.input.TestEstimationMap != nil {
estimatedGas, err := processor.EstimateGas(tt.input)
inputData, err := processor.PackTxInputData(tt.input)
assert.NoError(t, err)
estimatedGas, err := processor.EstimateGas(tt.input, inputData)
assert.NoError(t, err)
assert.Greater(t, estimatedGas, uint64(0))

input := tt.input
input.TestEstimationMap = map[string]requests.Estimation{
"randomName": {Value: 10000},
}
estimatedGas, err = processor.EstimateGas(input)
inputData, err = processor.PackTxInputData(tt.input)
assert.NoError(t, err)
estimatedGas, err = processor.EstimateGas(input, inputData)
assert.Error(t, err)
assert.Equal(t, ErrNoEstimationFound, err)
assert.Equal(t, uint64(0), estimatedGas)
} else {
estimatedGas, err := processor.EstimateGas(tt.input)
inputData, err := processor.PackTxInputData(tt.input)
assert.NoError(t, err)
estimatedGas, err := processor.EstimateGas(tt.input, inputData)
assert.Error(t, err)
assert.Equal(t, ErrNoEstimationFound, err)
assert.Equal(t, uint64(0), estimatedGas)
Expand Down
10 changes: 4 additions & 6 deletions services/wallet/router/pathprocessor/processor_transfer.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ func (s *TransferProcessor) CalculateFees(params ProcessorInputParams) (*big.Int
}

func (s *TransferProcessor) PackTxInputData(params ProcessorInputParams) ([]byte, error) {
if params.TestsMode {
return []byte{}, nil
}
if params.FromToken.IsNative() {
return []byte{}, nil
} else {
Expand All @@ -68,7 +71,7 @@ func (s *TransferProcessor) PackTxInputData(params ProcessorInputParams) ([]byte
}
}

func (s *TransferProcessor) EstimateGas(params ProcessorInputParams) (uint64, error) {
func (s *TransferProcessor) EstimateGas(params ProcessorInputParams, input []byte) (uint64, error) {
if params.TestsMode {
if params.TestEstimationMap != nil {
if val, ok := params.TestEstimationMap[s.Name()]; ok {
Expand All @@ -81,11 +84,6 @@ func (s *TransferProcessor) EstimateGas(params ProcessorInputParams) (uint64, er
estimation := uint64(0)
var err error

input, err := s.PackTxInputData(params)
if err != nil {
return 0, createTransferErrorResponse(err)
}

if params.FromToken.IsNative() {
estimation, err = s.transactor.EstimateGas(params.FromChain, params.FromAddr, params.ToAddr, params.AmountIn, input)
if err != nil {
Expand Down
22 changes: 19 additions & 3 deletions services/wallet/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,13 @@ func (r *Router) resolveCandidates(ctx context.Context, input *requests.RouteInp
continue
}

gasLimit, err := pProcessor.EstimateGas(processorInputParams)
txPackedData, err := pProcessor.PackTxInputData(processorInputParams)
if err != nil {
appendProcessorErrorFn(pProcessor.Name(), input.SendType, processorInputParams.FromChain.ChainID, processorInputParams.ToChain.ChainID, processorInputParams.AmountIn, err)
continue
}

gasLimit, err := pProcessor.EstimateGas(processorInputParams, txPackedData)
if err != nil {
appendProcessorErrorFn(pProcessor.Name(), input.SendType, processorInputParams.FromChain.ChainID, processorInputParams.ToChain.ChainID, processorInputParams.AmountIn, err)
continue
Expand All @@ -803,12 +809,20 @@ func (r *Router) resolveCandidates(ctx context.Context, input *requests.RouteInp
continue
}

var approvalGasLimit uint64
var (
approvalGasLimit uint64
approvalPackedData []byte
)
if approvalRequired {
if processorInputParams.TestsMode {
approvalGasLimit = processorInputParams.TestApprovalGasEstimation
} else {
approvalGasLimit, err = r.estimateGasForApproval(processorInputParams, &approvalContractAddress)
approvalPackedData, err := walletCommon.PackApprovalInputData(processorInputParams.AmountIn, &approvalContractAddress)
if err != nil {
appendProcessorErrorFn(pProcessor.Name(), input.SendType, processorInputParams.FromChain.ChainID, processorInputParams.ToChain.ChainID, processorInputParams.AmountIn, err)
continue
}
approvalGasLimit, err = r.estimateGasForApproval(processorInputParams, approvalPackedData)
if err != nil {
appendProcessorErrorFn(pProcessor.Name(), input.SendType, processorInputParams.FromChain.ChainID, processorInputParams.ToChain.ChainID, processorInputParams.AmountIn, err)
continue
Expand All @@ -834,13 +848,15 @@ func (r *Router) resolveCandidates(ctx context.Context, input *requests.RouteInp
AmountOut: (*hexutil.Big)(amountOut),

// set params that we don't want to be recalculated with every new block creation
TxPackedData: txPackedData,
TxGasAmount: gasLimit,
TxBonderFees: (*hexutil.Big)(bonderFees),
TxTokenFees: (*hexutil.Big)(tokenFees),

ApprovalRequired: approvalRequired,
ApprovalAmountRequired: (*hexutil.Big)(approvalAmountRequired),
ApprovalContractAddress: &approvalContractAddress,
ApprovalPackedData: approvalPackedData,
ApprovalGasAmount: approvalGasLimit,

SubtractFees: amountOption.subtractFees,
Expand Down
Loading
Loading