chore(wallet)_: path processor specific const and functions moved to path processors' common package

This commit is contained in:
Sale Djenic 2024-11-20 08:28:18 +01:00
parent 9f5f29513c
commit 4062b6a1cb
30 changed files with 380 additions and 363 deletions

View File

@ -107,7 +107,7 @@ func (api *API) DeployCollectibles(ctx context.Context, chainID uint64, deployme
if err != nil {
return DeploymentDetails{}, err
}
transactOpts := txArgs.ToTransactOpts(utils.GetSigner(chainID, api.s.accountsManager, api.s.config.KeyStoreDir, txArgs.From, password))
transactOpts := txArgs.ToTransactOpts(utils.VerifyPasswordAndGetSigner(chainID, api.s.accountsManager, api.s.config.KeyStoreDir, txArgs.From, password))
ethClient, err := api.s.manager.rpcClient.EthClient(chainID)
if err != nil {
@ -196,7 +196,7 @@ func (api *API) DeployOwnerToken(ctx context.Context, chainID uint64,
return DeploymentDetails{}, err
}
transactOpts := txArgs.ToTransactOpts(utils.GetSigner(chainID, api.s.accountsManager, api.s.config.KeyStoreDir, txArgs.From, password))
transactOpts := txArgs.ToTransactOpts(utils.VerifyPasswordAndGetSigner(chainID, api.s.accountsManager, api.s.config.KeyStoreDir, txArgs.From, password))
deployerContractInst, err := api.NewCommunityTokenDeployerInstance(chainID)
if err != nil {
@ -280,7 +280,7 @@ func (api *API) DeployAssets(ctx context.Context, chainID uint64, deploymentPara
return DeploymentDetails{}, err
}
transactOpts := txArgs.ToTransactOpts(utils.GetSigner(chainID, api.s.accountsManager, api.s.config.KeyStoreDir, txArgs.From, password))
transactOpts := txArgs.ToTransactOpts(utils.VerifyPasswordAndGetSigner(chainID, api.s.accountsManager, api.s.config.KeyStoreDir, txArgs.From, password))
ethClient, err := api.s.manager.rpcClient.EthClient(chainID)
if err != nil {
@ -384,7 +384,7 @@ func (api *API) MintTokens(ctx context.Context, chainID uint64, contractAddress
return "", err
}
transactOpts := txArgs.ToTransactOpts(utils.GetSigner(chainID, api.s.accountsManager, api.s.config.KeyStoreDir, txArgs.From, password))
transactOpts := txArgs.ToTransactOpts(utils.VerifyPasswordAndGetSigner(chainID, api.s.accountsManager, api.s.config.KeyStoreDir, txArgs.From, password))
contractInst, err := NewTokenInstance(api.s, chainID, contractAddress)
if err != nil {
@ -446,7 +446,7 @@ func (api *API) RemoteBurn(ctx context.Context, chainID uint64, contractAddress
return "", err
}
transactOpts := txArgs.ToTransactOpts(utils.GetSigner(chainID, api.s.accountsManager, api.s.config.KeyStoreDir, txArgs.From, password))
transactOpts := txArgs.ToTransactOpts(utils.VerifyPasswordAndGetSigner(chainID, api.s.accountsManager, api.s.config.KeyStoreDir, txArgs.From, password))
var tempTokenIds []*big.Int
for _, v := range tokenIds {
@ -498,7 +498,7 @@ func (api *API) Burn(ctx context.Context, chainID uint64, contractAddress string
return "", err
}
transactOpts := txArgs.ToTransactOpts(utils.GetSigner(chainID, api.s.accountsManager, api.s.config.KeyStoreDir, txArgs.From, password))
transactOpts := txArgs.ToTransactOpts(utils.VerifyPasswordAndGetSigner(chainID, api.s.accountsManager, api.s.config.KeyStoreDir, txArgs.From, password))
newMaxSupply, err := api.s.prepareNewMaxSupply(ctx, chainID, contractAddress, burnAmount)
if err != nil {

View File

@ -508,7 +508,7 @@ func (s *Service) SetSignerPubKey(ctx context.Context, chainID uint64, contractA
return "", fmt.Errorf("signerPubKey is empty")
}
transactOpts := txArgs.ToTransactOpts(utils.GetSigner(chainID, s.accountsManager, s.config.KeyStoreDir, txArgs.From, password))
transactOpts := txArgs.ToTransactOpts(utils.VerifyPasswordAndGetSigner(chainID, s.accountsManager, s.config.KeyStoreDir, txArgs.From, password))
contractInst, err := s.NewOwnerTokenInstance(chainID, contractAddress)
if err != nil {

View File

@ -154,7 +154,7 @@ func (api *API) Release(ctx context.Context, chainID uint64, txArgs wallettypes.
return "", err
}
signFn := utils.GetSigner(chainID, api.accountsManager, api.config.KeyStoreDir, txArgs.From, password)
signFn := utils.VerifyPasswordAndGetSigner(chainID, api.accountsManager, api.config.KeyStoreDir, txArgs.From, password)
tx, err := api.ensResolver.Release(ctx, chainID, registryAddr, txArgs, username, signFn)
if err != nil {
return "", err
@ -239,7 +239,7 @@ func (api *API) Register(ctx context.Context, chainID uint64, txArgs wallettypes
return "", err
}
signFn := utils.GetSigner(chainID, api.accountsManager, api.config.KeyStoreDir, txArgs.From, password)
signFn := utils.VerifyPasswordAndGetSigner(chainID, api.accountsManager, api.config.KeyStoreDir, txArgs.From, password)
tx, err := api.ensResolver.Register(ctx, chainID, registryAddr, txArgs, username, pubkey, signFn)
if err != nil {
@ -350,7 +350,7 @@ func (api *API) SetPubKey(ctx context.Context, chainID uint64, txArgs wallettype
return "", err
}
signFn := utils.GetSigner(chainID, api.accountsManager, api.config.KeyStoreDir, txArgs.From, password)
signFn := utils.VerifyPasswordAndGetSigner(chainID, api.accountsManager, api.config.KeyStoreDir, txArgs.From, password)
tx, err := api.ensResolver.SetPubKey(ctx, chainID, resolverAddress, txArgs, username, pubkey, signFn)
if err != nil {
return "", err

View File

@ -1,6 +1,7 @@
package utils
import (
"crypto/ecdsa"
"math/big"
"strings"
@ -14,7 +15,14 @@ import (
prot_common "github.com/status-im/status-go/protocol/common"
)
func GetSigner(chainID uint64, accountsManager *account.GethManager, keyStoreDir string, from types.Address, password string) bind.SignerFn {
func GetSigner(chainID uint64, from types.Address, privateKey *ecdsa.PrivateKey) bind.SignerFn {
return func(addr common.Address, tx *ethTypes.Transaction) (*ethTypes.Transaction, error) {
s := ethTypes.NewLondonSigner(new(big.Int).SetUint64(chainID))
return ethTypes.SignTx(tx, s, privateKey)
}
}
func VerifyPasswordAndGetSigner(chainID uint64, accountsManager *account.GethManager, keyStoreDir string, from types.Address, password string) bind.SignerFn {
return func(addr common.Address, tx *ethTypes.Transaction) (*ethTypes.Transaction, error) {
selectedAccount, err := accountsManager.VerifyAccountPassword(keyStoreDir, from.Hex(), password)
if err != nil {

View File

@ -22,17 +22,6 @@ const (
SttSymbol = "STT"
UsdcSymbol = "USDC"
HopSymbol = "HOP"
ProcessorTransferName = "Transfer"
ProcessorBridgeHopName = "Hop"
ProcessorBridgeCelerName = "CBridge"
ProcessorSwapParaswapName = "Paraswap"
ProcessorERC721Name = "ERC721Transfer"
ProcessorERC1155Name = "ERC1155Transfer"
ProcessorENSRegisterName = "ENSRegister"
ProcessorENSReleaseName = "ENSRelease"
ProcessorENSPublicKeyName = "ENSPublicKey"
ProcessorStickersBuyName = "StickersBuy"
)
type ChainID uint64

View File

@ -10,14 +10,16 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/status-im/status-go/contracts/ierc20"
pathProcessorCommon "github.com/status-im/status-go/services/wallet/router/pathprocessor/common"
)
func IsProcessorBridge(name string) bool {
return name == ProcessorBridgeHopName || name == ProcessorBridgeCelerName
return name == pathProcessorCommon.ProcessorBridgeHopName || name == pathProcessorCommon.ProcessorBridgeCelerName
}
func IsProcessorSwap(name string) bool {
return name == ProcessorSwapParaswapName
return name == pathProcessorCommon.ProcessorSwapParaswapName
}
func PackApprovalInputData(amountIn *big.Int, approvalContractAddress *common.Address) ([]byte, error) {

View File

@ -14,11 +14,11 @@ import (
status_common "github.com/status-im/status-go/common"
statusErrors "github.com/status-im/status-go/errors"
walletCommon "github.com/status-im/status-go/services/wallet/common"
"github.com/status-im/status-go/services/wallet/requests"
"github.com/status-im/status-go/services/wallet/responses"
"github.com/status-im/status-go/services/wallet/routeexecution/storage"
"github.com/status-im/status-go/services/wallet/router"
pathProcessorCommon "github.com/status-im/status-go/services/wallet/router/pathprocessor/common"
"github.com/status-im/status-go/services/wallet/router/sendtype"
"github.com/status-im/status-go/services/wallet/transfer"
"github.com/status-im/status-go/services/wallet/wallettypes"
@ -118,9 +118,9 @@ func (m *Manager) SendRouterTransactionsWithSignatures(ctx context.Context, send
clearLocalData := true
if routeInputParams.SendType == sendtype.Swap {
// in case of swap don't clear local data if an approval is placed, but swap tx is not sent yet
if m.transactionManager.ApprovalRequiredForPath(walletCommon.ProcessorSwapParaswapName) &&
m.transactionManager.ApprovalPlacedForPath(walletCommon.ProcessorSwapParaswapName) &&
!m.transactionManager.TxPlacedForPath(walletCommon.ProcessorSwapParaswapName) {
if m.transactionManager.ApprovalRequiredForPath(pathProcessorCommon.ProcessorSwapParaswapName) &&
m.transactionManager.ApprovalPlacedForPath(pathProcessorCommon.ProcessorSwapParaswapName) &&
!m.transactionManager.TxPlacedForPath(pathProcessorCommon.ProcessorSwapParaswapName) {
clearLocalData = false
}
}

View File

@ -1,41 +0,0 @@
package pathprocessor
import (
"fmt"
"math/big"
"strings"
ethTypes "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/common"
"github.com/status-im/status-go/account"
"github.com/status-im/status-go/eth-node/types"
walletCommon "github.com/status-im/status-go/services/wallet/common"
)
func getSigner(chainID uint64, from types.Address, verifiedAccount *account.SelectedExtKey) bind.SignerFn {
return func(addr common.Address, tx *ethTypes.Transaction) (*ethTypes.Transaction, error) {
s := ethTypes.NewLondonSigner(new(big.Int).SetUint64(chainID))
return ethTypes.SignTx(tx, s, verifiedAccount.AccountKey.PrivateKey)
}
}
func makeKey(fromChain, toChain uint64, fromTokenSymbol, toTokenSymbol string, amount *big.Int) string {
key := fmt.Sprintf("%d-%d", fromChain, toChain)
if fromTokenSymbol != "" || toTokenSymbol != "" {
key = fmt.Sprintf("%s-%s-%s", key, fromTokenSymbol, toTokenSymbol)
}
if amount != nil {
key = fmt.Sprintf("%s-%s", key, amount.String())
}
return key
}
func getNameFromEnsUsername(ensUsername string) string {
suffix := "." + walletCommon.StatusDomain
if strings.HasSuffix(ensUsername, suffix) {
return ensUsername[:len(ensUsername)-len(suffix)]
}
return ensUsername
}

View File

@ -0,0 +1,27 @@
package common
import (
"fmt"
"math/big"
"strings"
// walletCommon "github.com/status-im/status-go/services/wallet/common"
)
func MakeKey(fromChain, toChain uint64, fromTokenSymbol, toTokenSymbol string, amount *big.Int) string {
key := fmt.Sprintf("%d-%d", fromChain, toChain)
if fromTokenSymbol != "" || toTokenSymbol != "" {
key = fmt.Sprintf("%s-%s-%s", key, fromTokenSymbol, toTokenSymbol)
}
if amount != nil {
key = fmt.Sprintf("%s-%s", key, amount.String())
}
return key
}
func GetNameFromEnsUsername(ensUsername string) string {
suffix := "." //+ walletCommon.StatusDomain
if strings.HasSuffix(ensUsername, suffix) {
return ensUsername[:len(ensUsername)-len(suffix)]
}
return ensUsername
}

View File

@ -1,4 +1,4 @@
package pathprocessor
package common
import (
"testing"
@ -8,14 +8,14 @@ import (
func TestGettingNameFromEnsUsername(t *testing.T) {
ensName := "test"
name := getNameFromEnsUsername(ensName)
name := GetNameFromEnsUsername(ensName)
require.Equal(t, ensName, name)
ensStatusName := "test.stateofus.eth"
name = getNameFromEnsUsername(ensStatusName)
name = GetNameFromEnsUsername(ensStatusName)
require.Equal(t, ensName, name)
ensNotStatusName := "test.eth"
name = getNameFromEnsUsername(ensNotStatusName)
name = GetNameFromEnsUsername(ensNotStatusName)
require.Equal(t, ensNotStatusName, name)
}

View File

@ -0,0 +1,17 @@
package common
const (
IncreaseEstimatedGasFactor = 1.2
SevenDaysInSeconds = 60 * 60 * 24 * 7
ProcessorTransferName = "Transfer"
ProcessorBridgeHopName = "Hop"
ProcessorBridgeCelerName = "CBridge"
ProcessorSwapParaswapName = "Paraswap"
ProcessorERC721Name = "ERC721Transfer"
ProcessorERC1155Name = "ERC1155Transfer"
ProcessorENSRegisterName = "ENSRegister"
ProcessorENSReleaseName = "ENSRelease"
ProcessorENSPublicKeyName = "ENSPublicKey"
ProcessorStickersBuyName = "StickersBuy"
)

View File

@ -1,6 +0,0 @@
package pathprocessor
const (
IncreaseEstimatedGasFactor = 1.2
SevenDaysInSeconds = 60 * 60 * 24 * 7
)

View File

@ -4,7 +4,8 @@ import (
"context"
"github.com/status-im/status-go/errors"
walletCommon "github.com/status-im/status-go/services/wallet/common"
pathProcessorCommon "github.com/status-im/status-go/services/wallet/router/pathprocessor/common"
)
// Abbreviartion `WPP` for the error code stands for `Wallet Path Processor`
@ -70,25 +71,25 @@ func createErrorResponse(processorName string, err error) error {
var customErrResp *errors.ErrorResponse
switch processorName {
case walletCommon.ProcessorTransferName:
case pathProcessorCommon.ProcessorTransferName:
customErrResp = ErrTransferCustomError
case walletCommon.ProcessorERC721Name:
case pathProcessorCommon.ProcessorERC721Name:
customErrResp = ErrERC721TransferCustomError
case walletCommon.ProcessorERC1155Name:
case pathProcessorCommon.ProcessorERC1155Name:
customErrResp = ErrERC1155TransferCustomError
case walletCommon.ProcessorBridgeHopName:
case pathProcessorCommon.ProcessorBridgeHopName:
customErrResp = ErrBridgeHopCustomError
case walletCommon.ProcessorBridgeCelerName:
case pathProcessorCommon.ProcessorBridgeCelerName:
customErrResp = ErrBridgeCellerCustomError
case walletCommon.ProcessorSwapParaswapName:
case pathProcessorCommon.ProcessorSwapParaswapName:
customErrResp = ErrSwapParaswapCustomError
case walletCommon.ProcessorENSRegisterName:
case pathProcessorCommon.ProcessorENSRegisterName:
customErrResp = ErrENSRegisterCustomError
case walletCommon.ProcessorENSReleaseName:
case pathProcessorCommon.ProcessorENSReleaseName:
customErrResp = ErrENSReleaseCustomError
case walletCommon.ProcessorENSPublicKeyName:
case pathProcessorCommon.ProcessorENSPublicKeyName:
customErrResp = ErrENSPublicKeyCustomError
case walletCommon.ProcessorStickersBuyName:
case pathProcessorCommon.ProcessorStickersBuyName:
customErrResp = ErrStickersBuyCustomError
default:
return genericErrResp

View File

@ -7,7 +7,7 @@ import (
s_errors "github.com/status-im/status-go/errors"
walletCommon "github.com/status-im/status-go/services/wallet/common"
"github.com/status-im/status-go/services/wallet/router/pathprocessor/common"
"github.com/stretchr/testify/require"
)
@ -17,17 +17,17 @@ func TestPlainError(t *testing.T) {
err := errors.New(errString)
processorNames := []string{
walletCommon.ProcessorTransferName,
walletCommon.ProcessorTransferName,
walletCommon.ProcessorBridgeHopName,
walletCommon.ProcessorBridgeCelerName,
walletCommon.ProcessorSwapParaswapName,
walletCommon.ProcessorERC721Name,
walletCommon.ProcessorERC1155Name,
walletCommon.ProcessorENSRegisterName,
walletCommon.ProcessorENSReleaseName,
walletCommon.ProcessorENSPublicKeyName,
walletCommon.ProcessorStickersBuyName,
common.ProcessorTransferName,
common.ProcessorTransferName,
common.ProcessorBridgeHopName,
common.ProcessorBridgeCelerName,
common.ProcessorSwapParaswapName,
common.ProcessorERC721Name,
common.ProcessorERC1155Name,
common.ProcessorENSRegisterName,
common.ProcessorENSReleaseName,
common.ProcessorENSPublicKeyName,
common.ProcessorStickersBuyName,
}
for _, processorName := range processorNames {
@ -64,7 +64,7 @@ func TestNonGenericErrorResponse(t *testing.T) {
Details: "Not Generic Error Response",
}
err := s_errors.CreateErrorResponseFromError(errResp)
ppErrResp := createErrorResponse(walletCommon.ProcessorTransferName, err)
ppErrResp := createErrorResponse(common.ProcessorTransferName, err)
castPPErrResp := ppErrResp.(*s_errors.ErrorResponse)
require.Equal(t, errResp.Code, castPPErrResp.Code)

View File

@ -23,8 +23,10 @@ import (
"github.com/status-im/status-go/rpc"
"github.com/status-im/status-go/params"
"github.com/status-im/status-go/services/utils"
walletCommon "github.com/status-im/status-go/services/wallet/common"
"github.com/status-im/status-go/services/wallet/router/pathprocessor/cbridge"
pathProcessorCommon "github.com/status-im/status-go/services/wallet/router/pathprocessor/common"
"github.com/status-im/status-go/services/wallet/thirdparty"
"github.com/status-im/status-go/services/wallet/token"
"github.com/status-im/status-go/services/wallet/wallettypes"
@ -65,11 +67,11 @@ func NewCelerBridgeProcessor(rpcClient *rpc.Client, transactor transactions.Tran
}
func createBridgeCellerErrorResponse(err error) error {
return createErrorResponse(walletCommon.ProcessorBridgeCelerName, err)
return createErrorResponse(pathProcessorCommon.ProcessorBridgeCelerName, err)
}
func (s *CelerBridgeProcessor) Name() string {
return walletCommon.ProcessorBridgeCelerName
return pathProcessorCommon.ProcessorBridgeCelerName
}
func (s *CelerBridgeProcessor) estimateAmt(from, to *params.Network, amountIn *big.Int, symbol string) (*cbridge.EstimateAmtResponse, error) {
@ -281,7 +283,7 @@ func (s *CelerBridgeProcessor) EstimateGas(params ProcessorInputParams) (uint64,
return 0, createBridgeCellerErrorResponse(err)
}
}
increasedEstimation := float64(estimation) * IncreaseEstimatedGasFactor
increasedEstimation := float64(estimation) * pathProcessorCommon.IncreaseEstimatedGasFactor
return uint64(increasedEstimation), nil
}
@ -429,7 +431,7 @@ func (s *CelerBridgeProcessor) sendOrBuildV2(sendArgs *wallettypes.SendTxArgs, s
}
func (s *CelerBridgeProcessor) Send(sendArgs *MultipathProcessorTxArgs, lastUsedNonce int64, verifiedAccount *account.SelectedExtKey) (types.Hash, uint64, error) {
tx, err := s.sendOrBuild(sendArgs, getSigner(sendArgs.ChainID, sendArgs.CbridgeTx.From, verifiedAccount), lastUsedNonce)
tx, err := s.sendOrBuild(sendArgs, utils.GetSigner(sendArgs.ChainID, sendArgs.CbridgeTx.From, verifiedAccount.AccountKey.PrivateKey), lastUsedNonce)
if err != nil {
return types.HexToHash(""), 0, createBridgeCellerErrorResponse(err)
}

View File

@ -31,8 +31,10 @@ import (
"github.com/status-im/status-go/rpc"
"github.com/status-im/status-go/rpc/chain"
"github.com/status-im/status-go/rpc/network"
"github.com/status-im/status-go/services/utils"
"github.com/status-im/status-go/services/wallet/bigint"
walletCommon "github.com/status-im/status-go/services/wallet/common"
pathProcessorCommon "github.com/status-im/status-go/services/wallet/router/pathprocessor/common"
"github.com/status-im/status-go/services/wallet/thirdparty"
"github.com/status-im/status-go/services/wallet/token"
"github.com/status-im/status-go/services/wallet/wallettypes"
@ -127,11 +129,11 @@ func NewHopBridgeProcessor(rpcClient rpc.ClientInterface, transactor transaction
}
func createBridgeHopErrorResponse(err error) error {
return createErrorResponse(walletCommon.ProcessorBridgeHopName, err)
return createErrorResponse(pathProcessorCommon.ProcessorBridgeHopName, err)
}
func (h *HopBridgeProcessor) Name() string {
return walletCommon.ProcessorBridgeHopName
return pathProcessorCommon.ProcessorBridgeHopName
}
func (h *HopBridgeProcessor) Clear() {
@ -202,7 +204,7 @@ func (h *HopBridgeProcessor) packTxInputDataInternally(params ProcessorInputPara
return []byte{}, createBridgeHopErrorResponse(err)
}
bonderKey := makeKey(params.FromChain.ChainID, params.ToChain.ChainID, "", "", params.AmountIn)
bonderKey := pathProcessorCommon.MakeKey(params.FromChain.ChainID, params.ToChain.ChainID, "", "", params.AmountIn)
bonderFeeIns, ok := h.bonderFee.Load(bonderKey)
if !ok {
return nil, ErrNoBonderFeeFound
@ -274,7 +276,7 @@ func (h *HopBridgeProcessor) EstimateGas(params ProcessorInputParams) (uint64, e
}
}
increasedEstimation := float64(estimation) * IncreaseEstimatedGasFactor
increasedEstimation := float64(estimation) * pathProcessorCommon.IncreaseEstimatedGasFactor
return uint64(increasedEstimation), nil
}
@ -320,7 +322,7 @@ func (h *HopBridgeProcessor) sendOrBuild(sendArgs *MultipathProcessorTxArgs, sig
return tx, createBridgeHopErrorResponse(err)
}
bonderKey := makeKey(sendArgs.HopTx.ChainID, sendArgs.HopTx.ChainIDTo, "", "", (*big.Int)(sendArgs.HopTx.Amount))
bonderKey := pathProcessorCommon.MakeKey(sendArgs.HopTx.ChainID, sendArgs.HopTx.ChainIDTo, "", "", (*big.Int)(sendArgs.HopTx.Amount))
bonderFeeIns, ok := h.bonderFee.Load(bonderKey)
if !ok {
return nil, ErrNoBonderFeeFound
@ -387,7 +389,7 @@ func (h *HopBridgeProcessor) sendOrBuildV2(sendArgs *wallettypes.SendTxArgs, sig
return tx, createBridgeHopErrorResponse(err)
}
bonderKey := makeKey(sendArgs.FromChainID, sendArgs.ToChainID, "", "", (*big.Int)(sendArgs.ValueIn))
bonderKey := pathProcessorCommon.MakeKey(sendArgs.FromChainID, sendArgs.ToChainID, "", "", (*big.Int)(sendArgs.ValueIn))
bonderFeeIns, ok := h.bonderFee.Load(bonderKey)
if !ok {
return nil, ErrNoBonderFeeFound
@ -419,7 +421,7 @@ func (h *HopBridgeProcessor) sendOrBuildV2(sendArgs *wallettypes.SendTxArgs, sig
}
func (h *HopBridgeProcessor) Send(sendArgs *MultipathProcessorTxArgs, lastUsedNonce int64, verifiedAccount *account.SelectedExtKey) (hash types.Hash, nonce uint64, err error) {
tx, err := h.sendOrBuild(sendArgs, getSigner(sendArgs.HopTx.ChainID, sendArgs.HopTx.From, verifiedAccount), lastUsedNonce)
tx, err := h.sendOrBuild(sendArgs, utils.GetSigner(sendArgs.HopTx.ChainID, sendArgs.HopTx.From, verifiedAccount.AccountKey.PrivateKey), lastUsedNonce)
if err != nil {
return types.Hash{}, 0, createBridgeHopErrorResponse(err)
}
@ -443,7 +445,7 @@ func (h *HopBridgeProcessor) BuildTransactionV2(sendArgs *wallettypes.SendTxArgs
}
func (h *HopBridgeProcessor) CalculateFees(params ProcessorInputParams) (*big.Int, *big.Int, error) {
bonderKey := makeKey(params.FromChain.ChainID, params.ToChain.ChainID, "", "", params.AmountIn)
bonderKey := pathProcessorCommon.MakeKey(params.FromChain.ChainID, params.ToChain.ChainID, "", "", params.AmountIn)
if params.TestsMode {
if val, ok := params.TestBonderFeeMap[params.FromToken.Symbol]; ok {
res := new(big.Int).Sub(params.AmountIn, val)
@ -454,7 +456,7 @@ func (h *HopBridgeProcessor) CalculateFees(params ProcessorInputParams) (*big.In
DestinationAmountOutMin: &bigint.BigInt{Int: res},
BonderFee: &bigint.BigInt{Int: val},
EstimatedRecieved: &bigint.BigInt{Int: res},
Deadline: time.Now().Add(SevenDaysInSeconds).Unix(),
Deadline: time.Now().Add(pathProcessorCommon.SevenDaysInSeconds).Unix(),
}
h.bonderFee.Store(bonderKey, bonderFee)
return val, walletCommon.ZeroBigIntValue(), nil
@ -508,7 +510,7 @@ func (h *HopBridgeProcessor) CalculateFees(params ProcessorInputParams) (*big.In
}
func (h *HopBridgeProcessor) CalculateAmountOut(params ProcessorInputParams) (*big.Int, error) {
bonderKey := makeKey(params.FromChain.ChainID, params.ToChain.ChainID, "", "", params.AmountIn)
bonderKey := pathProcessorCommon.MakeKey(params.FromChain.ChainID, params.ToChain.ChainID, "", "", params.AmountIn)
bonderFeeIns, ok := h.bonderFee.Load(bonderKey)
if !ok {
return nil, ErrNoBonderFeeFound

View File

@ -16,6 +16,7 @@ import (
"github.com/status-im/status-go/rpc"
"github.com/status-im/status-go/services/ens/ensresolver"
walletCommon "github.com/status-im/status-go/services/wallet/common"
pathProcessorCommon "github.com/status-im/status-go/services/wallet/router/pathprocessor/common"
"github.com/status-im/status-go/services/wallet/wallettypes"
"github.com/status-im/status-go/transactions"
)
@ -37,11 +38,11 @@ func NewENSPublicKeyProcessor(rpcClient *rpc.Client, transactor transactions.Tra
}
func createENSPublicKeyErrorResponse(err error) error {
return createErrorResponse(walletCommon.ProcessorENSPublicKeyName, err)
return createErrorResponse(pathProcessorCommon.ProcessorENSPublicKeyName, err)
}
func (s *ENSPublicKeyProcessor) Name() string {
return walletCommon.ProcessorENSPublicKeyName
return pathProcessorCommon.ProcessorENSPublicKeyName
}
func (s *ENSPublicKeyProcessor) AvailableFor(params ProcessorInputParams) (bool, error) {
@ -99,7 +100,7 @@ func (s *ENSPublicKeyProcessor) EstimateGas(params ProcessorInputParams) (uint64
return 0, createENSPublicKeyErrorResponse(err)
}
increasedEstimation := float64(estimation) * IncreaseEstimatedGasFactor
increasedEstimation := float64(estimation) * pathProcessorCommon.IncreaseEstimatedGasFactor
return uint64(increasedEstimation), nil
}

View File

@ -18,6 +18,7 @@ import (
"github.com/status-im/status-go/rpc"
"github.com/status-im/status-go/services/ens/ensresolver"
walletCommon "github.com/status-im/status-go/services/wallet/common"
pathProcessorCommon "github.com/status-im/status-go/services/wallet/router/pathprocessor/common"
"github.com/status-im/status-go/services/wallet/wallettypes"
"github.com/status-im/status-go/transactions"
)
@ -39,11 +40,11 @@ func NewENSRegisterProcessor(rpcClient *rpc.Client, transactor transactions.Tran
}
func createENSRegisterProcessorErrorResponse(err error) error {
return createErrorResponse(walletCommon.ProcessorENSRegisterName, err)
return createErrorResponse(pathProcessorCommon.ProcessorENSRegisterName, err)
}
func (s *ENSRegisterProcessor) Name() string {
return walletCommon.ProcessorENSRegisterName
return pathProcessorCommon.ProcessorENSRegisterName
}
func (s *ENSRegisterProcessor) GetPriceForRegisteringEnsName(chainID uint64) (*big.Int, error) {
@ -135,7 +136,7 @@ func (s *ENSRegisterProcessor) EstimateGas(params ProcessorInputParams) (uint64,
return 0, createENSRegisterProcessorErrorResponse(err)
}
increasedEstimation := float64(estimation) * IncreaseEstimatedGasFactor
increasedEstimation := float64(estimation) * pathProcessorCommon.IncreaseEstimatedGasFactor
return uint64(increasedEstimation), nil
}

View File

@ -16,6 +16,7 @@ import (
"github.com/status-im/status-go/rpc"
"github.com/status-im/status-go/services/ens/ensresolver"
walletCommon "github.com/status-im/status-go/services/wallet/common"
pathProcessorCommon "github.com/status-im/status-go/services/wallet/router/pathprocessor/common"
"github.com/status-im/status-go/services/wallet/wallettypes"
"github.com/status-im/status-go/transactions"
)
@ -37,11 +38,11 @@ func NewENSReleaseProcessor(rpcClient *rpc.Client, transactor transactions.Trans
}
func createENSReleaseErrorResponse(err error) error {
return createErrorResponse(walletCommon.ProcessorENSReleaseName, err)
return createErrorResponse(pathProcessorCommon.ProcessorENSReleaseName, err)
}
func (s *ENSReleaseProcessor) Name() string {
return walletCommon.ProcessorENSReleaseName
return pathProcessorCommon.ProcessorENSReleaseName
}
func (s *ENSReleaseProcessor) AvailableFor(params ProcessorInputParams) (bool, error) {
@ -58,7 +59,7 @@ func (s *ENSReleaseProcessor) PackTxInputData(params ProcessorInputParams) ([]by
return []byte{}, createENSReleaseErrorResponse(err)
}
name := getNameFromEnsUsername(params.Username)
name := pathProcessorCommon.GetNameFromEnsUsername(params.Username)
return registrarABI.Pack("release", walletCommon.UsernameToLabel(name))
}
@ -99,7 +100,7 @@ func (s *ENSReleaseProcessor) EstimateGas(params ProcessorInputParams) (uint64,
return 0, createENSReleaseErrorResponse(err)
}
increasedEstimation := float64(estimation) * IncreaseEstimatedGasFactor
increasedEstimation := float64(estimation) * pathProcessorCommon.IncreaseEstimatedGasFactor
return uint64(increasedEstimation), nil
}

View File

@ -15,7 +15,9 @@ import (
"github.com/status-im/status-go/contracts/ierc1155"
"github.com/status-im/status-go/eth-node/types"
"github.com/status-im/status-go/rpc"
"github.com/status-im/status-go/services/utils"
walletCommon "github.com/status-im/status-go/services/wallet/common"
pathProcessorCommon "github.com/status-im/status-go/services/wallet/router/pathprocessor/common"
"github.com/status-im/status-go/services/wallet/wallettypes"
"github.com/status-im/status-go/transactions"
)
@ -37,11 +39,11 @@ func NewERC1155Processor(rpcClient *rpc.Client, transactor transactions.Transact
}
func createERC1155ErrorResponse(err error) error {
return createErrorResponse(walletCommon.ProcessorERC1155Name, err)
return createErrorResponse(pathProcessorCommon.ProcessorERC1155Name, err)
}
func (s *ERC1155Processor) Name() string {
return walletCommon.ProcessorERC1155Name
return pathProcessorCommon.ProcessorERC1155Name
}
func (s *ERC1155Processor) AvailableFor(params ProcessorInputParams) (bool, error) {
@ -105,7 +107,7 @@ func (s *ERC1155Processor) EstimateGas(params ProcessorInputParams) (uint64, err
if err != nil {
return 0, createERC1155ErrorResponse(err)
}
increasedEstimation := float64(estimation) * IncreaseEstimatedGasFactor
increasedEstimation := float64(estimation) * pathProcessorCommon.IncreaseEstimatedGasFactor
return uint64(increasedEstimation), nil
}
@ -153,7 +155,7 @@ func (s *ERC1155Processor) sendOrBuild(sendArgs *MultipathProcessorTxArgs, signe
}
func (s *ERC1155Processor) Send(sendArgs *MultipathProcessorTxArgs, lastUsedNonce int64, verifiedAccount *account.SelectedExtKey) (hash types.Hash, usedNonce uint64, err error) {
tx, err := s.sendOrBuild(sendArgs, getSigner(sendArgs.ChainID, sendArgs.ERC1155TransferTx.From, verifiedAccount), lastUsedNonce)
tx, err := s.sendOrBuild(sendArgs, utils.GetSigner(sendArgs.ChainID, sendArgs.ERC1155TransferTx.From, verifiedAccount.AccountKey.PrivateKey), lastUsedNonce)
if err != nil {
return hash, 0, createERC1155ErrorResponse(err)
}

View File

@ -17,7 +17,9 @@ import (
"github.com/status-im/status-go/eth-node/types"
"github.com/status-im/status-go/params"
"github.com/status-im/status-go/rpc"
"github.com/status-im/status-go/services/utils"
walletCommon "github.com/status-im/status-go/services/wallet/common"
pathProcessorCommon "github.com/status-im/status-go/services/wallet/router/pathprocessor/common"
"github.com/status-im/status-go/services/wallet/token"
"github.com/status-im/status-go/services/wallet/wallettypes"
"github.com/status-im/status-go/transactions"
@ -44,11 +46,11 @@ func NewERC721Processor(rpcClient *rpc.Client, transactor transactions.Transacto
}
func createERC721ErrorResponse(err error) error {
return createErrorResponse(walletCommon.ProcessorERC721Name, err)
return createErrorResponse(pathProcessorCommon.ProcessorERC721Name, err)
}
func (s *ERC721Processor) Name() string {
return walletCommon.ProcessorERC721Name
return pathProcessorCommon.ProcessorERC721Name
}
func (s *ERC721Processor) AvailableFor(params ProcessorInputParams) (bool, error) {
@ -143,7 +145,7 @@ func (s *ERC721Processor) EstimateGas(params ProcessorInputParams) (uint64, erro
return 0, createERC721ErrorResponse(err)
}
increasedEstimation := float64(estimation) * IncreaseEstimatedGasFactor
increasedEstimation := float64(estimation) * pathProcessorCommon.IncreaseEstimatedGasFactor
return uint64(increasedEstimation), nil
}
@ -211,7 +213,7 @@ func (s *ERC721Processor) sendOrBuild(sendArgs *MultipathProcessorTxArgs, signer
}
func (s *ERC721Processor) Send(sendArgs *MultipathProcessorTxArgs, lastUsedNonce int64, verifiedAccount *account.SelectedExtKey) (hash types.Hash, usedNonce uint64, err error) {
tx, err := s.sendOrBuild(sendArgs, getSigner(sendArgs.ChainID, sendArgs.ERC721TransferTx.From, verifiedAccount), lastUsedNonce)
tx, err := s.sendOrBuild(sendArgs, utils.GetSigner(sendArgs.ChainID, sendArgs.ERC721TransferTx.From, verifiedAccount.AccountKey.PrivateKey), lastUsedNonce)
if err != nil {
return hash, 0, createERC721ErrorResponse(err)
}

View File

@ -17,6 +17,7 @@ import (
"github.com/status-im/status-go/eth-node/types"
"github.com/status-im/status-go/rpc"
walletCommon "github.com/status-im/status-go/services/wallet/common"
pathProcessorCommon "github.com/status-im/status-go/services/wallet/router/pathprocessor/common"
"github.com/status-im/status-go/services/wallet/wallettypes"
"github.com/status-im/status-go/transactions"
)
@ -36,11 +37,11 @@ func NewStickersBuyProcessor(rpcClient *rpc.Client, transactor transactions.Tran
}
func createStickersBuyErrorResponse(err error) error {
return createErrorResponse(walletCommon.ProcessorStickersBuyName, err)
return createErrorResponse(pathProcessorCommon.ProcessorStickersBuyName, err)
}
func (s *StickersBuyProcessor) Name() string {
return walletCommon.ProcessorStickersBuyName
return pathProcessorCommon.ProcessorStickersBuyName
}
func (s *StickersBuyProcessor) AvailableFor(params ProcessorInputParams) (bool, error) {
@ -124,7 +125,7 @@ func (s *StickersBuyProcessor) EstimateGas(params ProcessorInputParams) (uint64,
return 0, createStickersBuyErrorResponse(err)
}
increasedEstimation := float64(estimation) * IncreaseEstimatedGasFactor
increasedEstimation := float64(estimation) * pathProcessorCommon.IncreaseEstimatedGasFactor
return uint64(increasedEstimation), nil
}

View File

@ -13,6 +13,7 @@ import (
"github.com/status-im/status-go/eth-node/types"
"github.com/status-im/status-go/rpc"
walletCommon "github.com/status-im/status-go/services/wallet/common"
pathProcessorCommon "github.com/status-im/status-go/services/wallet/router/pathprocessor/common"
"github.com/status-im/status-go/services/wallet/thirdparty/paraswap"
walletToken "github.com/status-im/status-go/services/wallet/token"
"github.com/status-im/status-go/services/wallet/wallettypes"
@ -77,11 +78,11 @@ func createSwapParaswapErrorResponse(err error) error {
case "ESTIMATED_LOSS_GREATER_THAN_MAX_IMPACT":
return ErrPriceImpactTooHigh
}
return createErrorResponse(walletCommon.ProcessorSwapParaswapName, err)
return createErrorResponse(pathProcessorCommon.ProcessorSwapParaswapName, err)
}
func (s *SwapParaswapProcessor) Name() string {
return walletCommon.ProcessorSwapParaswapName
return pathProcessorCommon.ProcessorSwapParaswapName
}
func (s *SwapParaswapProcessor) Clear() {
@ -191,14 +192,14 @@ func (s *SwapParaswapProcessor) EstimateGas(params ProcessorInputParams) (uint64
return 0, createSwapParaswapErrorResponse(err)
}
key := makeKey(params.FromChain.ChainID, params.ToChain.ChainID, params.FromToken.Symbol, params.ToToken.Symbol, params.AmountIn)
key := pathProcessorCommon.MakeKey(params.FromChain.ChainID, params.ToChain.ChainID, params.FromToken.Symbol, params.ToToken.Symbol, params.AmountIn)
s.priceRoute.Store(key, &priceRoute)
return priceRoute.GasCost.Uint64(), nil
}
func (s *SwapParaswapProcessor) GetContractAddress(params ProcessorInputParams) (address common.Address, err error) {
key := makeKey(params.FromChain.ChainID, params.ToChain.ChainID, params.FromToken.Symbol, params.ToToken.Symbol, params.AmountIn)
key := pathProcessorCommon.MakeKey(params.FromChain.ChainID, params.ToChain.ChainID, params.FromToken.Symbol, params.ToToken.Symbol, params.AmountIn)
priceRouteIns, ok := s.priceRoute.Load(key)
if !ok {
err = ErrPriceRouteNotFound
@ -213,7 +214,7 @@ func (s *SwapParaswapProcessor) GetContractAddress(params ProcessorInputParams)
func (s *SwapParaswapProcessor) prepareTransaction(sendArgs *MultipathProcessorTxArgs) error {
slippageBP := uint(sendArgs.SwapTx.SlippagePercentage * 100) // convert to basis points
key := makeKey(sendArgs.SwapTx.ChainID, sendArgs.SwapTx.ChainIDTo, sendArgs.SwapTx.TokenIDFrom, sendArgs.SwapTx.TokenIDTo, sendArgs.SwapTx.ValueIn.ToInt())
key := pathProcessorCommon.MakeKey(sendArgs.SwapTx.ChainID, sendArgs.SwapTx.ChainIDTo, sendArgs.SwapTx.TokenIDFrom, sendArgs.SwapTx.TokenIDTo, sendArgs.SwapTx.ValueIn.ToInt())
priceRouteIns, ok := s.priceRoute.Load(key)
if !ok {
return ErrPriceRouteNotFound
@ -259,7 +260,7 @@ func (s *SwapParaswapProcessor) prepareTransaction(sendArgs *MultipathProcessorT
func (s *SwapParaswapProcessor) prepareTransactionV2(sendArgs *wallettypes.SendTxArgs) error {
slippageBP := uint(sendArgs.SlippagePercentage * 100) // convert to basis points
key := makeKey(sendArgs.FromChainID, sendArgs.ToChainID, sendArgs.FromTokenID, sendArgs.ToTokenID, sendArgs.ValueIn.ToInt())
key := pathProcessorCommon.MakeKey(sendArgs.FromChainID, sendArgs.ToChainID, sendArgs.FromTokenID, sendArgs.ToTokenID, sendArgs.ValueIn.ToInt())
priceRouteIns, ok := s.priceRoute.Load(key)
if !ok {
return ErrPriceRouteNotFound
@ -327,7 +328,7 @@ func (s *SwapParaswapProcessor) Send(sendArgs *MultipathProcessorTxArgs, lastUse
}
func (s *SwapParaswapProcessor) CalculateAmountOut(params ProcessorInputParams) (*big.Int, error) {
key := makeKey(params.FromChain.ChainID, params.ToChain.ChainID, params.FromToken.Symbol, params.ToToken.Symbol, params.AmountIn)
key := pathProcessorCommon.MakeKey(params.FromChain.ChainID, params.ToChain.ChainID, params.FromToken.Symbol, params.ToToken.Symbol, params.AmountIn)
priceRouteIns, ok := s.priceRoute.Load(key)
if !ok {
return nil, ErrPriceRouteNotFound

View File

@ -12,6 +12,7 @@ import (
"github.com/status-im/status-go/params"
"github.com/status-im/status-go/services/wallet/bigint"
walletCommon "github.com/status-im/status-go/services/wallet/common"
pathProcessorCommon "github.com/status-im/status-go/services/wallet/router/pathprocessor/common"
"github.com/status-im/status-go/services/wallet/thirdparty/paraswap"
mock_paraswap "github.com/status-im/status-go/services/wallet/thirdparty/paraswap/mock"
"github.com/status-im/status-go/services/wallet/token"
@ -44,7 +45,7 @@ func TestParaswapWithPartnerFee(t *testing.T) {
chainIDs := []uint64{walletCommon.EthereumMainnet, walletCommon.ArbitrumMainnet, walletCommon.OptimismMainnet, walletCommon.UnknownChainID}
for _, chainID := range chainIDs {
key := makeKey(chainID, chainID, fromToken.Symbol, toToken.Symbol, testPriceRoute.SrcAmount.Int)
key := pathProcessorCommon.MakeKey(chainID, chainID, fromToken.Symbol, toToken.Symbol, testPriceRoute.SrcAmount.Int)
processor.priceRoute.Store(key, testPriceRoute)
testInputParams := ProcessorInputParams{

View File

@ -7,6 +7,7 @@ import (
"github.com/status-im/status-go/params"
walletCommon "github.com/status-im/status-go/services/wallet/common"
"github.com/status-im/status-go/services/wallet/requests"
pathProcessorCommon "github.com/status-im/status-go/services/wallet/router/pathprocessor/common"
"github.com/status-im/status-go/services/wallet/token"
"github.com/stretchr/testify/assert"
@ -45,9 +46,9 @@ var optimism = params.Network{
}
var testEstimationMap = map[string]requests.Estimation{
walletCommon.ProcessorTransferName: {Value: uint64(1000)},
walletCommon.ProcessorBridgeHopName: {Value: uint64(5000)},
walletCommon.ProcessorSwapParaswapName: {Value: uint64(2000)},
pathProcessorCommon.ProcessorTransferName: {Value: uint64(1000)},
pathProcessorCommon.ProcessorBridgeHopName: {Value: uint64(5000)},
pathProcessorCommon.ProcessorSwapParaswapName: {Value: uint64(2000)},
}
type expectedResult struct {
@ -68,15 +69,15 @@ func TestPathProcessors(t *testing.T) {
TestsMode: true,
},
expected: map[string]expectedResult{
walletCommon.ProcessorTransferName: {
pathProcessorCommon.ProcessorTransferName: {
expected: false,
expectedError: ErrNoChainSet,
},
walletCommon.ProcessorBridgeHopName: {
pathProcessorCommon.ProcessorBridgeHopName: {
expected: false,
expectedError: ErrNoChainSet,
},
walletCommon.ProcessorSwapParaswapName: {
pathProcessorCommon.ProcessorSwapParaswapName: {
expected: false,
expectedError: ErrNoChainSet,
},
@ -91,15 +92,15 @@ func TestPathProcessors(t *testing.T) {
TestEstimationMap: testEstimationMap,
},
expected: map[string]expectedResult{
walletCommon.ProcessorTransferName: {
pathProcessorCommon.ProcessorTransferName: {
expected: false,
expectedError: ErrNoTokenSet,
},
walletCommon.ProcessorBridgeHopName: {
pathProcessorCommon.ProcessorBridgeHopName: {
expected: false,
expectedError: ErrNoTokenSet,
},
walletCommon.ProcessorSwapParaswapName: {
pathProcessorCommon.ProcessorSwapParaswapName: {
expected: false,
expectedError: ErrToAndFromTokensMustBeSet,
},
@ -117,15 +118,15 @@ func TestPathProcessors(t *testing.T) {
TestEstimationMap: testEstimationMap,
},
expected: map[string]expectedResult{
walletCommon.ProcessorTransferName: {
pathProcessorCommon.ProcessorTransferName: {
expected: true,
expectedError: nil,
},
walletCommon.ProcessorBridgeHopName: {
pathProcessorCommon.ProcessorBridgeHopName: {
expected: false,
expectedError: ErrFromAndToChainsMustBeDifferent,
},
walletCommon.ProcessorSwapParaswapName: {
pathProcessorCommon.ProcessorSwapParaswapName: {
expected: false,
expectedError: ErrToAndFromTokensMustBeSet,
},
@ -146,15 +147,15 @@ func TestPathProcessors(t *testing.T) {
TestEstimationMap: testEstimationMap,
},
expected: map[string]expectedResult{
walletCommon.ProcessorTransferName: {
pathProcessorCommon.ProcessorTransferName: {
expected: false,
expectedError: ErrToTokenShouldNotBeSet,
},
walletCommon.ProcessorBridgeHopName: {
pathProcessorCommon.ProcessorBridgeHopName: {
expected: false,
expectedError: ErrToTokenShouldNotBeSet,
},
walletCommon.ProcessorSwapParaswapName: {
pathProcessorCommon.ProcessorSwapParaswapName: {
expected: false,
expectedError: ErrFromAndToTokensMustBeDifferent,
},
@ -175,15 +176,15 @@ func TestPathProcessors(t *testing.T) {
TestEstimationMap: testEstimationMap,
},
expected: map[string]expectedResult{
walletCommon.ProcessorTransferName: {
pathProcessorCommon.ProcessorTransferName: {
expected: false,
expectedError: ErrToTokenShouldNotBeSet,
},
walletCommon.ProcessorBridgeHopName: {
pathProcessorCommon.ProcessorBridgeHopName: {
expected: false,
expectedError: ErrToTokenShouldNotBeSet,
},
walletCommon.ProcessorSwapParaswapName: {
pathProcessorCommon.ProcessorSwapParaswapName: {
expected: true,
expectedError: nil,
},
@ -198,15 +199,15 @@ func TestPathProcessors(t *testing.T) {
TestEstimationMap: testEstimationMap,
},
expected: map[string]expectedResult{
walletCommon.ProcessorTransferName: {
pathProcessorCommon.ProcessorTransferName: {
expected: false,
expectedError: ErrNoTokenSet,
},
walletCommon.ProcessorBridgeHopName: {
pathProcessorCommon.ProcessorBridgeHopName: {
expected: false,
expectedError: ErrNoTokenSet,
},
walletCommon.ProcessorSwapParaswapName: {
pathProcessorCommon.ProcessorSwapParaswapName: {
expected: false,
expectedError: ErrFromAndToChainsMustBeSame,
},
@ -224,15 +225,15 @@ func TestPathProcessors(t *testing.T) {
TestEstimationMap: testEstimationMap,
},
expected: map[string]expectedResult{
walletCommon.ProcessorTransferName: {
pathProcessorCommon.ProcessorTransferName: {
expected: false,
expectedError: nil,
},
walletCommon.ProcessorBridgeHopName: {
pathProcessorCommon.ProcessorBridgeHopName: {
expected: true,
expectedError: nil,
},
walletCommon.ProcessorSwapParaswapName: {
pathProcessorCommon.ProcessorSwapParaswapName: {
expected: false,
expectedError: ErrFromAndToChainsMustBeSame,
},
@ -253,15 +254,15 @@ func TestPathProcessors(t *testing.T) {
TestEstimationMap: testEstimationMap,
},
expected: map[string]expectedResult{
walletCommon.ProcessorTransferName: {
pathProcessorCommon.ProcessorTransferName: {
expected: false,
expectedError: ErrToTokenShouldNotBeSet,
},
walletCommon.ProcessorBridgeHopName: {
pathProcessorCommon.ProcessorBridgeHopName: {
expected: false,
expectedError: ErrToTokenShouldNotBeSet,
},
walletCommon.ProcessorSwapParaswapName: {
pathProcessorCommon.ProcessorSwapParaswapName: {
expected: false,
expectedError: ErrFromAndToChainsMustBeSame,
},
@ -282,15 +283,15 @@ func TestPathProcessors(t *testing.T) {
TestEstimationMap: testEstimationMap,
},
expected: map[string]expectedResult{
walletCommon.ProcessorTransferName: {
pathProcessorCommon.ProcessorTransferName: {
expected: false,
expectedError: ErrToTokenShouldNotBeSet,
},
walletCommon.ProcessorBridgeHopName: {
pathProcessorCommon.ProcessorBridgeHopName: {
expected: false,
expectedError: ErrToTokenShouldNotBeSet,
},
walletCommon.ProcessorSwapParaswapName: {
pathProcessorCommon.ProcessorSwapParaswapName: {
expected: false,
expectedError: ErrFromAndToChainsMustBeSame,
},
@ -303,11 +304,11 @@ func TestPathProcessors(t *testing.T) {
t.Run(fmt.Sprintf("%s[%s]", processorName, tt.name), func(t *testing.T) {
var processor PathProcessor
if processorName == walletCommon.ProcessorTransferName {
if processorName == pathProcessorCommon.ProcessorTransferName {
processor = NewTransferProcessor(nil, nil)
} else if processorName == walletCommon.ProcessorBridgeHopName {
} else if processorName == pathProcessorCommon.ProcessorBridgeHopName {
processor = NewHopBridgeProcessor(nil, nil, nil, nil)
} else if processorName == walletCommon.ProcessorSwapParaswapName {
} else if processorName == pathProcessorCommon.ProcessorSwapParaswapName {
processor = NewSwapParaswapProcessor(nil, nil, nil)
}

View File

@ -14,6 +14,7 @@ import (
"github.com/status-im/status-go/eth-node/types"
"github.com/status-im/status-go/rpc"
walletCommon "github.com/status-im/status-go/services/wallet/common"
pathProcessorCommon "github.com/status-im/status-go/services/wallet/router/pathprocessor/common"
"github.com/status-im/status-go/services/wallet/wallettypes"
"github.com/status-im/status-go/transactions"
)
@ -28,11 +29,11 @@ func NewTransferProcessor(rpcClient *rpc.Client, transactor transactions.Transac
}
func createTransferErrorResponse(err error) error {
return createErrorResponse(walletCommon.ProcessorTransferName, err)
return createErrorResponse(pathProcessorCommon.ProcessorTransferName, err)
}
func (s *TransferProcessor) Name() string {
return walletCommon.ProcessorTransferName
return pathProcessorCommon.ProcessorTransferName
}
func (s *TransferProcessor) AvailableFor(params ProcessorInputParams) (bool, error) {
@ -111,7 +112,7 @@ func (s *TransferProcessor) EstimateGas(params ProcessorInputParams) (uint64, er
}
increasedEstimation := float64(estimation) * IncreaseEstimatedGasFactor
increasedEstimation := float64(estimation) * pathProcessorCommon.IncreaseEstimatedGasFactor
return uint64(increasedEstimation), nil
}

View File

@ -24,6 +24,7 @@ import (
"github.com/status-im/status-go/services/wallet/responses"
"github.com/status-im/status-go/services/wallet/router/fees"
"github.com/status-im/status-go/services/wallet/router/pathprocessor"
pathProcessorCommon "github.com/status-im/status-go/services/wallet/router/pathprocessor/common"
"github.com/status-im/status-go/services/wallet/router/routes"
"github.com/status-im/status-go/services/wallet/router/sendtype"
"github.com/status-im/status-go/services/wallet/token"
@ -840,7 +841,7 @@ func (r *Router) checkBalancesForTheBestRoute(ctx context.Context, bestRoute rou
}
}
if path.ProcessorName == walletCommon.ProcessorBridgeHopName {
if path.ProcessorName == pathProcessorCommon.ProcessorBridgeHopName {
if path.TxBonderFees.ToInt().Cmp(path.AmountOut.ToInt()) > 0 {
return hasPositiveBalance, ErrLowAmountInForHopBridge
}

File diff suppressed because it is too large Load Diff

View File

@ -5,6 +5,7 @@ import (
"github.com/status-im/status-go/params"
walletCommon "github.com/status-im/status-go/services/wallet/common"
pathProcessorCommon "github.com/status-im/status-go/services/wallet/router/pathprocessor/common"
)
type SendType int
@ -37,24 +38,24 @@ func (s SendType) IsStickersTransfer() bool {
func (s SendType) CanUseProcessor(pathProcessorName string) bool {
switch s {
case Transfer:
return pathProcessorName == walletCommon.ProcessorTransferName ||
return pathProcessorName == pathProcessorCommon.ProcessorTransferName ||
walletCommon.IsProcessorBridge(pathProcessorName)
case Bridge:
return walletCommon.IsProcessorBridge(pathProcessorName)
case Swap:
return walletCommon.IsProcessorSwap(pathProcessorName)
case ERC721Transfer:
return pathProcessorName == walletCommon.ProcessorERC721Name
return pathProcessorName == pathProcessorCommon.ProcessorERC721Name
case ERC1155Transfer:
return pathProcessorName == walletCommon.ProcessorERC1155Name
return pathProcessorName == pathProcessorCommon.ProcessorERC1155Name
case ENSRegister:
return pathProcessorName == walletCommon.ProcessorENSRegisterName
return pathProcessorName == pathProcessorCommon.ProcessorENSRegisterName
case ENSRelease:
return pathProcessorName == walletCommon.ProcessorENSReleaseName
return pathProcessorName == pathProcessorCommon.ProcessorENSReleaseName
case ENSSetPubKey:
return pathProcessorName == walletCommon.ProcessorENSPublicKeyName
return pathProcessorName == pathProcessorCommon.ProcessorENSPublicKeyName
case StickersBuy:
return pathProcessorName == walletCommon.ProcessorStickersBuyName
return pathProcessorName == pathProcessorCommon.ProcessorStickersBuyName
default:
return true
}
@ -63,7 +64,7 @@ func (s SendType) CanUseProcessor(pathProcessorName string) bool {
func (s SendType) ProcessZeroAmountInProcessor(amountIn *big.Int, amountOut *big.Int, processorName string) bool {
if amountIn.Cmp(walletCommon.ZeroBigIntValue()) == 0 {
if s == Transfer {
if processorName != walletCommon.ProcessorTransferName {
if processorName != pathProcessorCommon.ProcessorTransferName {
return false
}
} else if s == Swap {

View File

@ -16,6 +16,7 @@ import (
"github.com/status-im/status-go/services/wallet/requests"
"github.com/status-im/status-go/services/wallet/responses"
"github.com/status-im/status-go/services/wallet/router/pathprocessor"
pathProcessorCommon "github.com/status-im/status-go/services/wallet/router/pathprocessor/common"
"github.com/status-im/status-go/services/wallet/router/routes"
"github.com/status-im/status-go/services/wallet/wallettypes"
"github.com/status-im/status-go/transactions"
@ -180,13 +181,13 @@ func buildTxForPath(transactor transactions.TransactorIface, path *routes.Path,
if !path.FromToken.IsNative() {
sendArgs.Value = (*hexutil.Big)(big.NewInt(0))
if path.ProcessorName == walletCommon.ProcessorTransferName ||
path.ProcessorName == walletCommon.ProcessorStickersBuyName ||
path.ProcessorName == walletCommon.ProcessorENSRegisterName ||
path.ProcessorName == walletCommon.ProcessorENSReleaseName ||
path.ProcessorName == walletCommon.ProcessorENSPublicKeyName ||
path.ProcessorName == walletCommon.ProcessorERC721Name ||
path.ProcessorName == walletCommon.ProcessorERC1155Name {
if path.ProcessorName == pathProcessorCommon.ProcessorTransferName ||
path.ProcessorName == pathProcessorCommon.ProcessorStickersBuyName ||
path.ProcessorName == pathProcessorCommon.ProcessorENSRegisterName ||
path.ProcessorName == pathProcessorCommon.ProcessorENSReleaseName ||
path.ProcessorName == pathProcessorCommon.ProcessorENSPublicKeyName ||
path.ProcessorName == pathProcessorCommon.ProcessorERC721Name ||
path.ProcessorName == pathProcessorCommon.ProcessorERC1155Name {
// TODO: update functions from `TransactorIface` to use `ToContractAddress` (as an address of the contract a transaction should be sent to)
// and `To` (as the destination address, recipient) of `SendTxArgs` struct appropriately
toContractAddr := types.Address(path.FromToken.Address)
@ -250,7 +251,7 @@ func (tm *TransactionManager) BuildTransactionsFromRoute(route routes.Route, pat
response.Hashes = append(response.Hashes, txDetails.ApprovalTxData.HashToSign)
// if approval is needed for swap, we cannot build the swap tx before the approval tx is mined
if path.ProcessorName == walletCommon.ProcessorSwapParaswapName {
if path.ProcessorName == pathProcessorCommon.ProcessorSwapParaswapName {
continue
}
}
@ -367,7 +368,7 @@ func (tm *TransactionManager) SendRouterTransactions(ctx context.Context, multiT
transactions = append(transactions, response)
// if approval is needed for swap, then we need to wait for the approval tx to be mined before sending the swap tx
if desc.RouterPath.ProcessorName == walletCommon.ProcessorSwapParaswapName {
if desc.RouterPath.ProcessorName == pathProcessorCommon.ProcessorSwapParaswapName {
continue
}
}