chore_: router moved to router package (part2)
This commit is contained in:
parent
4894808839
commit
7a016d0859
|
@ -17,14 +17,14 @@ import (
|
|||
communitytokendeployer "github.com/status-im/status-go/contracts/community-tokens/deployer"
|
||||
"github.com/status-im/status-go/eth-node/types"
|
||||
"github.com/status-im/status-go/protocol/protobuf"
|
||||
"github.com/status-im/status-go/services/wallet"
|
||||
"github.com/status-im/status-go/services/wallet/bigint"
|
||||
"github.com/status-im/status-go/services/wallet/router"
|
||||
"github.com/status-im/status-go/transactions"
|
||||
)
|
||||
|
||||
type CommunityTokenFees struct {
|
||||
GasUnits uint64 `json:"gasUnits"`
|
||||
SuggestedFees *wallet.SuggestedFees `json:"suggestedFees"`
|
||||
SuggestedFees *router.SuggestedFees `json:"suggestedFees"`
|
||||
}
|
||||
|
||||
func weiToGwei(val *big.Int) *big.Float {
|
||||
|
@ -373,7 +373,7 @@ func (s *Service) prepareCommunityTokenFees(ctx context.Context, from common.Add
|
|||
}, nil
|
||||
}
|
||||
|
||||
func (s *Service) suggestedFeesToSendTxArgs(from common.Address, to *common.Address, gas uint64, suggestedFees *wallet.SuggestedFees) transactions.SendTxArgs {
|
||||
func (s *Service) suggestedFeesToSendTxArgs(from common.Address, to *common.Address, gas uint64, suggestedFees *router.SuggestedFees) transactions.SendTxArgs {
|
||||
sendArgs := transactions.SendTxArgs{}
|
||||
sendArgs.From = types.Address(from)
|
||||
sendArgs.To = (*types.Address)(to)
|
||||
|
|
|
@ -29,9 +29,9 @@ import (
|
|||
"github.com/status-im/status-go/rpc"
|
||||
"github.com/status-im/status-go/services/communitytokens/communitytokensdatabase"
|
||||
"github.com/status-im/status-go/services/utils"
|
||||
"github.com/status-im/status-go/services/wallet"
|
||||
"github.com/status-im/status-go/services/wallet/bigint"
|
||||
wcommon "github.com/status-im/status-go/services/wallet/common"
|
||||
"github.com/status-im/status-go/services/wallet/router"
|
||||
"github.com/status-im/status-go/services/wallet/walletevent"
|
||||
"github.com/status-im/status-go/signal"
|
||||
"github.com/status-im/status-go/transactions"
|
||||
|
@ -48,7 +48,7 @@ type Service struct {
|
|||
walletFeed *event.Feed
|
||||
walletWatcher *walletevent.Watcher
|
||||
transactor *transactions.Transactor
|
||||
feeManager *wallet.FeeManager
|
||||
feeManager *router.FeeManager
|
||||
}
|
||||
|
||||
// Returns a new Collectibles Service.
|
||||
|
@ -62,7 +62,7 @@ func NewService(rpcClient *rpc.Client, accountsManager *account.GethManager, pen
|
|||
db: communitytokensdatabase.NewCommunityTokensDatabase(appDb),
|
||||
walletFeed: walletFeed,
|
||||
transactor: transactor,
|
||||
feeManager: &wallet.FeeManager{RPCClient: rpcClient},
|
||||
feeManager: &router.FeeManager{RPCClient: rpcClient},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ import (
|
|||
wcommon "github.com/status-im/status-go/services/wallet/common"
|
||||
"github.com/status-im/status-go/services/wallet/currency"
|
||||
"github.com/status-im/status-go/services/wallet/history"
|
||||
"github.com/status-im/status-go/services/wallet/router"
|
||||
"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/transfer"
|
||||
|
@ -35,7 +36,8 @@ import (
|
|||
)
|
||||
|
||||
func NewAPI(s *Service) *API {
|
||||
router := NewRouter(s)
|
||||
router := router.NewRouter(s.GetRPCClient(), s.GetTransactor(), s.GetTokenManager(), s.GetMarketManager(), s.GetCollectiblesService(),
|
||||
s.GetCollectiblesManager(), s.GetEnsService(), s.GetStickersService())
|
||||
return &API{s, s.reader, router}
|
||||
}
|
||||
|
||||
|
@ -43,7 +45,7 @@ func NewAPI(s *Service) *API {
|
|||
type API struct {
|
||||
s *Service
|
||||
reader *Reader
|
||||
router *Router
|
||||
router *router.Router
|
||||
}
|
||||
|
||||
func (api *API) StartWallet(ctx context.Context) error {
|
||||
|
@ -410,9 +412,9 @@ func (api *API) FetchTokenDetails(ctx context.Context, symbols []string) (map[st
|
|||
return api.s.marketManager.FetchTokenDetails(symbols)
|
||||
}
|
||||
|
||||
func (api *API) GetSuggestedFees(ctx context.Context, chainID uint64) (*SuggestedFees, error) {
|
||||
func (api *API) GetSuggestedFees(ctx context.Context, chainID uint64) (*router.SuggestedFees, error) {
|
||||
log.Debug("call to GetSuggestedFees")
|
||||
return api.s.feesManager.SuggestedFees(ctx, chainID)
|
||||
return api.router.GetFeesManager().SuggestedFees(ctx, chainID)
|
||||
}
|
||||
|
||||
func (api *API) GetEstimatedLatestBlockNumber(ctx context.Context, chainID uint64) (uint64, error) {
|
||||
|
@ -421,14 +423,14 @@ func (api *API) GetEstimatedLatestBlockNumber(ctx context.Context, chainID uint6
|
|||
}
|
||||
|
||||
// @deprecated
|
||||
func (api *API) GetTransactionEstimatedTime(ctx context.Context, chainID uint64, maxFeePerGas *big.Float) (TransactionEstimation, error) {
|
||||
func (api *API) GetTransactionEstimatedTime(ctx context.Context, chainID uint64, maxFeePerGas *big.Float) (router.TransactionEstimation, error) {
|
||||
log.Debug("call to getTransactionEstimatedTime")
|
||||
return api.s.feesManager.transactionEstimatedTime(ctx, chainID, maxFeePerGas), nil
|
||||
return api.router.GetFeesManager().TransactionEstimatedTime(ctx, chainID, maxFeePerGas), nil
|
||||
}
|
||||
|
||||
func (api *API) GetSuggestedRoutes(
|
||||
ctx context.Context,
|
||||
sendType SendType,
|
||||
sendType router.SendType,
|
||||
addrFrom common.Address,
|
||||
addrTo common.Address,
|
||||
amountIn *hexutil.Big,
|
||||
|
@ -437,17 +439,30 @@ func (api *API) GetSuggestedRoutes(
|
|||
disabledFromChainIDs,
|
||||
disabledToChaindIDs,
|
||||
preferedChainIDs []uint64,
|
||||
gasFeeMode GasFeeMode,
|
||||
gasFeeMode router.GasFeeMode,
|
||||
fromLockedAmount map[uint64]*hexutil.Big,
|
||||
) (*SuggestedRoutes, error) {
|
||||
) (*router.SuggestedRoutes, error) {
|
||||
log.Debug("call to GetSuggestedRoutes")
|
||||
return api.router.suggestedRoutes(ctx, sendType, addrFrom, addrTo, amountIn.ToInt(), tokenID, toTokenID, disabledFromChainIDs,
|
||||
disabledToChaindIDs, preferedChainIDs, gasFeeMode, fromLockedAmount)
|
||||
|
||||
testnetMode, err := api.s.accountsDB.GetTestNetworksEnabled()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return api.router.SuggestedRoutes(ctx, sendType, addrFrom, addrTo, amountIn.ToInt(), tokenID, toTokenID, disabledFromChainIDs,
|
||||
disabledToChaindIDs, preferedChainIDs, gasFeeMode, fromLockedAmount, testnetMode)
|
||||
}
|
||||
|
||||
func (api *API) GetSuggestedRoutesV2(ctx context.Context, input *RouteInputParams) (*SuggestedRoutesV2, error) {
|
||||
func (api *API) GetSuggestedRoutesV2(ctx context.Context, input *router.RouteInputParams) (*router.SuggestedRoutesV2, error) {
|
||||
log.Debug("call to GetSuggestedRoutesV2")
|
||||
return api.router.suggestedRoutesV2(ctx, input)
|
||||
testnetMode, err := api.s.accountsDB.GetTestNetworksEnabled()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
input.TestnetMode = testnetMode
|
||||
|
||||
return api.router.SuggestedRoutesV2(ctx, input)
|
||||
}
|
||||
|
||||
// Generates addresses for the provided paths, response doesn't include `HasActivity` value (if you need it check `GetAddressDetails` function)
|
||||
|
@ -604,7 +619,7 @@ func (api *API) CreateMultiTransaction(ctx context.Context, multiTransactionComm
|
|||
return nil, err
|
||||
}
|
||||
|
||||
cmdRes, err := api.s.transactionManager.SendTransactions(ctx, cmd, data, api.router.bridges, selectedAccount)
|
||||
cmdRes, err := api.s.transactionManager.SendTransactions(ctx, cmd, data, api.router.GetBridges(), selectedAccount)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -617,7 +632,7 @@ func (api *API) CreateMultiTransaction(ctx context.Context, multiTransactionComm
|
|||
return cmdRes, nil
|
||||
}
|
||||
|
||||
return nil, api.s.transactionManager.SendTransactionForSigningToKeycard(ctx, cmd, data, api.router.bridges)
|
||||
return nil, api.s.transactionManager.SendTransactionForSigningToKeycard(ctx, cmd, data, api.router.GetBridges())
|
||||
}
|
||||
|
||||
func (api *API) ProceedWithTransactionsSignatures(ctx context.Context, signatures map[string]transfer.SignatureDetails) (*transfer.MultiTransactionCommandResult, error) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package wallet
|
||||
package router
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
@ -195,7 +195,6 @@ func (f *FeeManager) getBaseFee(ctx context.Context, client chain.ClientInterfac
|
|||
case common.OptimismGoerli:
|
||||
case common.ArbitrumGoerli:
|
||||
config = params.GoerliChainConfig
|
||||
|
||||
}
|
||||
|
||||
baseFee := misc.CalcBaseFee(config, header)
|
||||
|
@ -238,7 +237,7 @@ func (f *FeeManager) getPriorityFees(ctx context.Context, client chain.ClientInt
|
|||
return priorityFee, nil
|
||||
}
|
||||
|
||||
func (f *FeeManager) transactionEstimatedTime(ctx context.Context, chainID uint64, maxFeePerGas *big.Float) TransactionEstimation {
|
||||
func (f *FeeManager) TransactionEstimatedTime(ctx context.Context, chainID uint64, maxFeePerGas *big.Float) TransactionEstimation {
|
||||
fees, err := f.getFeeHistorySorted(chainID)
|
||||
if err != nil {
|
||||
return Unknown
|
|
@ -1,4 +1,4 @@
|
|||
package wallet
|
||||
package router
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
@ -19,12 +19,17 @@ import (
|
|||
"github.com/status-im/status-go/contracts/ierc20"
|
||||
"github.com/status-im/status-go/params"
|
||||
"github.com/status-im/status-go/rpc"
|
||||
"github.com/status-im/status-go/services/ens"
|
||||
"github.com/status-im/status-go/services/stickers"
|
||||
"github.com/status-im/status-go/services/wallet/async"
|
||||
"github.com/status-im/status-go/services/wallet/bigint"
|
||||
"github.com/status-im/status-go/services/wallet/bridge"
|
||||
"github.com/status-im/status-go/services/wallet/collectibles"
|
||||
walletCommon "github.com/status-im/status-go/services/wallet/common"
|
||||
"github.com/status-im/status-go/services/wallet/market"
|
||||
"github.com/status-im/status-go/services/wallet/token"
|
||||
walletToken "github.com/status-im/status-go/services/wallet/token"
|
||||
"github.com/status-im/status-go/transactions"
|
||||
)
|
||||
|
||||
// //////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -272,14 +277,15 @@ func newSuggestedRoutes(
|
|||
}
|
||||
}
|
||||
|
||||
func NewRouter(s *Service) *Router {
|
||||
func NewRouter(rpcClient *rpc.Client, transactor *transactions.Transactor, tokenManager *token.Manager, marketManager *market.Manager,
|
||||
collectibles *collectibles.Service, collectiblesManager *collectibles.Manager, ensService *ens.Service, stickersService *stickers.Service) *Router {
|
||||
bridges := make(map[string]bridge.Bridge)
|
||||
transfer := bridge.NewTransferBridge(s.rpcClient, s.transactor)
|
||||
erc721Transfer := bridge.NewERC721TransferBridge(s.rpcClient, s.transactor)
|
||||
erc1155Transfer := bridge.NewERC1155TransferBridge(s.rpcClient, s.transactor)
|
||||
cbridge := bridge.NewCbridge(s.rpcClient, s.transactor, s.tokenManager)
|
||||
hop := bridge.NewHopBridge(s.rpcClient, s.transactor, s.tokenManager)
|
||||
paraswap := bridge.NewSwapParaswap(s.rpcClient, s.transactor, s.tokenManager)
|
||||
transfer := bridge.NewTransferBridge(rpcClient, transactor)
|
||||
erc721Transfer := bridge.NewERC721TransferBridge(rpcClient, transactor)
|
||||
erc1155Transfer := bridge.NewERC1155TransferBridge(rpcClient, transactor)
|
||||
cbridge := bridge.NewCbridge(rpcClient, transactor, tokenManager)
|
||||
hop := bridge.NewHopBridge(rpcClient, transactor, tokenManager)
|
||||
paraswap := bridge.NewSwapParaswap(rpcClient, transactor, tokenManager)
|
||||
bridges[transfer.Name()] = transfer
|
||||
bridges[erc721Transfer.Name()] = erc721Transfer
|
||||
bridges[hop.Name()] = hop
|
||||
|
@ -287,7 +293,25 @@ func NewRouter(s *Service) *Router {
|
|||
bridges[erc1155Transfer.Name()] = erc1155Transfer
|
||||
bridges[paraswap.Name()] = paraswap
|
||||
|
||||
return &Router{s, bridges, s.rpcClient}
|
||||
return &Router{
|
||||
rpcClient: rpcClient,
|
||||
tokenManager: tokenManager,
|
||||
marketManager: marketManager,
|
||||
collectiblesService: collectibles,
|
||||
collectiblesManager: collectiblesManager,
|
||||
ensService: ensService,
|
||||
stickersService: stickersService,
|
||||
feesManager: &FeeManager{rpcClient},
|
||||
bridges: bridges,
|
||||
}
|
||||
}
|
||||
|
||||
func (r *Router) GetFeesManager() *FeeManager {
|
||||
return r.feesManager
|
||||
}
|
||||
|
||||
func (r *Router) GetBridges() map[string]bridge.Bridge {
|
||||
return r.bridges
|
||||
}
|
||||
|
||||
func containsNetworkChainID(network *params.Network, chainIDs []uint64) bool {
|
||||
|
@ -301,9 +325,15 @@ func containsNetworkChainID(network *params.Network, chainIDs []uint64) bool {
|
|||
}
|
||||
|
||||
type Router struct {
|
||||
s *Service
|
||||
bridges map[string]bridge.Bridge
|
||||
rpcClient *rpc.Client
|
||||
rpcClient *rpc.Client
|
||||
tokenManager *token.Manager
|
||||
marketManager *market.Manager
|
||||
collectiblesService *collectibles.Service
|
||||
collectiblesManager *collectibles.Manager
|
||||
ensService *ens.Service
|
||||
stickersService *stickers.Service
|
||||
feesManager *FeeManager
|
||||
bridges map[string]bridge.Bridge
|
||||
}
|
||||
|
||||
func (r *Router) requireApproval(ctx context.Context, sendType SendType, approvalContractAddress *common.Address, account common.Address, network *params.Network, token *token.Token, amountIn *big.Int) (
|
||||
|
@ -385,12 +415,12 @@ func (r *Router) requireApproval(ctx context.Context, sendType SendType, approva
|
|||
}
|
||||
|
||||
func (r *Router) getBalance(ctx context.Context, network *params.Network, token *token.Token, account common.Address) (*big.Int, error) {
|
||||
client, err := r.s.rpcClient.EthClient(network.ChainID)
|
||||
client, err := r.rpcClient.EthClient(network.ChainID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return r.s.tokenManager.GetBalance(ctx, client, account, token.Address)
|
||||
return r.tokenManager.GetBalance(ctx, client, account, token.Address)
|
||||
}
|
||||
|
||||
func (r *Router) getERC1155Balance(ctx context.Context, network *params.Network, token *token.Token, account common.Address) (*big.Int, error) {
|
||||
|
@ -399,7 +429,7 @@ func (r *Router) getERC1155Balance(ctx context.Context, network *params.Network,
|
|||
return nil, errors.New("failed to convert token symbol to big.Int")
|
||||
}
|
||||
|
||||
balances, err := r.s.collectiblesManager.FetchERC1155Balances(
|
||||
balances, err := r.collectiblesManager.FetchERC1155Balances(
|
||||
ctx,
|
||||
account,
|
||||
walletCommon.ChainID(network.ChainID),
|
||||
|
@ -417,7 +447,7 @@ func (r *Router) getERC1155Balance(ctx context.Context, network *params.Network,
|
|||
return balances[0].Int, nil
|
||||
}
|
||||
|
||||
func (r *Router) suggestedRoutes(
|
||||
func (r *Router) SuggestedRoutes(
|
||||
ctx context.Context,
|
||||
sendType SendType,
|
||||
addrFrom common.Address,
|
||||
|
@ -430,18 +460,15 @@ func (r *Router) suggestedRoutes(
|
|||
preferedChainIDs []uint64,
|
||||
gasFeeMode GasFeeMode,
|
||||
fromLockedAmount map[uint64]*hexutil.Big,
|
||||
testnetMode bool,
|
||||
) (*SuggestedRoutes, error) {
|
||||
areTestNetworksEnabled, err := r.s.accountsDB.GetTestNetworksEnabled()
|
||||
|
||||
networks, err := r.rpcClient.NetworkManager.Get(false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
networks, err := r.s.rpcClient.NetworkManager.Get(false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
prices, err := sendType.FetchPrices(r.s, tokenID)
|
||||
prices, err := sendType.FetchPrices(r.marketManager, tokenID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -453,7 +480,7 @@ func (r *Router) suggestedRoutes(
|
|||
|
||||
for networkIdx := range networks {
|
||||
network := networks[networkIdx]
|
||||
if network.IsTest != areTestNetworksEnabled {
|
||||
if network.IsTest != testnetMode {
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -465,23 +492,23 @@ func (r *Router) suggestedRoutes(
|
|||
continue
|
||||
}
|
||||
|
||||
token := sendType.FindToken(r.s, addrFrom, network, tokenID)
|
||||
token := sendType.FindToken(r.tokenManager, r.collectiblesService, addrFrom, network, tokenID)
|
||||
if token == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
var toToken *walletToken.Token
|
||||
if sendType == Swap {
|
||||
toToken = sendType.FindToken(r.s, common.Address{}, network, toTokenID)
|
||||
toToken = sendType.FindToken(r.tokenManager, r.collectiblesService, common.Address{}, network, toTokenID)
|
||||
}
|
||||
|
||||
nativeToken := r.s.tokenManager.FindToken(network, network.NativeCurrencySymbol)
|
||||
nativeToken := r.tokenManager.FindToken(network, network.NativeCurrencySymbol)
|
||||
if nativeToken == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
group.Add(func(c context.Context) error {
|
||||
gasFees, err := r.s.feesManager.SuggestedFees(ctx, network.ChainID)
|
||||
gasFees, err := r.feesManager.SuggestedFees(ctx, network.ChainID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -514,14 +541,14 @@ func (r *Router) suggestedRoutes(
|
|||
}
|
||||
maxFees := gasFees.feeFor(gasFeeMode)
|
||||
|
||||
estimatedTime := r.s.feesManager.transactionEstimatedTime(ctx, network.ChainID, maxFees)
|
||||
estimatedTime := r.feesManager.TransactionEstimatedTime(ctx, network.ChainID, maxFees)
|
||||
for _, bridge := range r.bridges {
|
||||
if !sendType.canUseBridge(bridge) {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, dest := range networks {
|
||||
if dest.IsTest != areTestNetworksEnabled {
|
||||
if dest.IsTest != testnetMode {
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -566,7 +593,7 @@ func (r *Router) suggestedRoutes(
|
|||
continue
|
||||
}
|
||||
} else {
|
||||
gasLimit = sendType.EstimateGas(r.s, network, addrFrom, tokenID)
|
||||
gasLimit = sendType.EstimateGas(r.ensService, r.stickersService, network, addrFrom, tokenID)
|
||||
}
|
||||
|
||||
approvalContractAddress := bridge.GetContractAddress(network, token)
|
||||
|
@ -582,7 +609,7 @@ func (r *Router) suggestedRoutes(
|
|||
continue
|
||||
}
|
||||
|
||||
l1GasFeeWei, _ = r.s.feesManager.GetL1Fee(ctx, network.ChainID, tx)
|
||||
l1GasFeeWei, _ = r.feesManager.GetL1Fee(ctx, network.ChainID, tx)
|
||||
l1GasFeeWei += l1ApprovalFee
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package wallet
|
||||
package router
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
@ -10,9 +10,13 @@ import (
|
|||
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||
"github.com/status-im/status-go/eth-node/types"
|
||||
"github.com/status-im/status-go/params"
|
||||
"github.com/status-im/status-go/services/ens"
|
||||
"github.com/status-im/status-go/services/stickers"
|
||||
"github.com/status-im/status-go/services/wallet/bigint"
|
||||
"github.com/status-im/status-go/services/wallet/bridge"
|
||||
"github.com/status-im/status-go/services/wallet/collectibles"
|
||||
walletCommon "github.com/status-im/status-go/services/wallet/common"
|
||||
"github.com/status-im/status-go/services/wallet/market"
|
||||
"github.com/status-im/status-go/services/wallet/token"
|
||||
"github.com/status-im/status-go/transactions"
|
||||
)
|
||||
|
@ -35,13 +39,13 @@ func (s SendType) IsCollectiblesTransfer() bool {
|
|||
return s == ERC721Transfer || s == ERC1155Transfer
|
||||
}
|
||||
|
||||
func (s SendType) FetchPrices(service *Service, tokenID string) (map[string]float64, error) {
|
||||
func (s SendType) FetchPrices(marketManager *market.Manager, tokenID string) (map[string]float64, error) {
|
||||
symbols := []string{tokenID, "ETH"}
|
||||
if s.IsCollectiblesTransfer() {
|
||||
symbols = []string{"ETH"}
|
||||
}
|
||||
|
||||
pricesMap, err := service.marketManager.FetchPrices(symbols, []string{"USD"})
|
||||
pricesMap, err := marketManager.FetchPrices(symbols, []string{"USD"})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -55,9 +59,9 @@ func (s SendType) FetchPrices(service *Service, tokenID string) (map[string]floa
|
|||
return prices, nil
|
||||
}
|
||||
|
||||
func (s SendType) FindToken(service *Service, account common.Address, network *params.Network, tokenID string) *token.Token {
|
||||
func (s SendType) FindToken(tokenManager *token.Manager, collectibles *collectibles.Service, account common.Address, network *params.Network, tokenID string) *token.Token {
|
||||
if !s.IsCollectiblesTransfer() {
|
||||
return service.tokenManager.FindToken(network, tokenID)
|
||||
return tokenManager.FindToken(network, tokenID)
|
||||
}
|
||||
|
||||
parts := strings.Split(tokenID, ":")
|
||||
|
@ -66,7 +70,7 @@ func (s SendType) FindToken(service *Service, account common.Address, network *p
|
|||
if !success {
|
||||
return nil
|
||||
}
|
||||
uniqueID, err := service.collectibles.GetOwnedCollectible(walletCommon.ChainID(network.ChainID), account, contractAddress, collectibleTokenID)
|
||||
uniqueID, err := collectibles.GetOwnedCollectible(walletCommon.ChainID(network.ChainID), account, contractAddress, collectibleTokenID)
|
||||
if err != nil || uniqueID == nil {
|
||||
return nil
|
||||
}
|
||||
|
@ -127,28 +131,28 @@ func (s SendType) isAvailableFor(network *params.Network) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
func (s SendType) EstimateGas(service *Service, network *params.Network, from common.Address, tokenID string) uint64 {
|
||||
func (s SendType) EstimateGas(ensService *ens.Service, stickersService *stickers.Service, network *params.Network, from common.Address, tokenID string) uint64 {
|
||||
tx := transactions.SendTxArgs{
|
||||
From: (types.Address)(from),
|
||||
Value: (*hexutil.Big)(zero),
|
||||
}
|
||||
switch s {
|
||||
case ENSRegister:
|
||||
estimate, err := service.ens.API().RegisterEstimate(context.Background(), network.ChainID, tx, EstimateUsername, EstimatePubKey)
|
||||
estimate, err := ensService.API().RegisterEstimate(context.Background(), network.ChainID, tx, EstimateUsername, EstimatePubKey)
|
||||
if err != nil {
|
||||
return 400000
|
||||
}
|
||||
return estimate
|
||||
|
||||
case ENSRelease:
|
||||
estimate, err := service.ens.API().ReleaseEstimate(context.Background(), network.ChainID, tx, EstimateUsername)
|
||||
estimate, err := ensService.API().ReleaseEstimate(context.Background(), network.ChainID, tx, EstimateUsername)
|
||||
if err != nil {
|
||||
return 200000
|
||||
}
|
||||
return estimate
|
||||
|
||||
case ENSSetPubKey:
|
||||
estimate, err := service.ens.API().SetPubKeyEstimate(context.Background(), network.ChainID, tx, fmt.Sprint(EstimateUsername, ".stateofus.eth"), EstimatePubKey)
|
||||
estimate, err := ensService.API().SetPubKeyEstimate(context.Background(), network.ChainID, tx, fmt.Sprint(EstimateUsername, ".stateofus.eth"), EstimatePubKey)
|
||||
if err != nil {
|
||||
return 400000
|
||||
}
|
||||
|
@ -156,7 +160,7 @@ func (s SendType) EstimateGas(service *Service, network *params.Network, from co
|
|||
|
||||
case StickersBuy:
|
||||
packID := &bigint.BigInt{Int: big.NewInt(2)}
|
||||
estimate, err := service.stickers.API().BuyEstimate(context.Background(), network.ChainID, (types.Address)(from), packID)
|
||||
estimate, err := stickersService.API().BuyEstimate(context.Background(), network.ChainID, (types.Address)(from), packID)
|
||||
if err != nil {
|
||||
return 400000
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package wallet
|
||||
package router
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
@ -16,17 +16,18 @@ import (
|
|||
)
|
||||
|
||||
type RouteInputParams struct {
|
||||
SendType SendType `json:"sendType"`
|
||||
AddrFrom common.Address `json:"addrFrom"`
|
||||
AddrTo common.Address `json:"addrTo"`
|
||||
AmountIn *hexutil.Big `json:"amountIn"`
|
||||
TokenID string `json:"tokenID"`
|
||||
SendType SendType `json:"sendType" validate:"required"`
|
||||
AddrFrom common.Address `json:"addrFrom" validate:"required"`
|
||||
AddrTo common.Address `json:"addrTo" validate:"required"`
|
||||
AmountIn *hexutil.Big `json:"amountIn" validate:"required"`
|
||||
TokenID string `json:"tokenID" validate:"required"`
|
||||
ToTokenID string `json:"toTokenID"`
|
||||
DisabledFromChainIDs []uint64 `json:"disabledFromChainIDs"`
|
||||
DisabledToChaindIDs []uint64 `json:"disabledToChaindIDs"`
|
||||
PreferedChainIDs []uint64 `json:"preferedChainIDs"`
|
||||
GasFeeMode GasFeeMode `json:"gasFeeMode"`
|
||||
GasFeeMode GasFeeMode `json:"gasFeeMode" validate:"required"`
|
||||
FromLockedAmount map[uint64]*hexutil.Big `json:"fromLockedAmount"`
|
||||
TestnetMode bool `json:"testnetMode"`
|
||||
}
|
||||
|
||||
type PathV2 struct {
|
||||
|
@ -339,14 +340,8 @@ func findBestV2(routes [][]*PathV2, tokenPrice float64, nativeChainTokenPrice fl
|
|||
return best
|
||||
}
|
||||
|
||||
func (r *Router) suggestedRoutesV2(ctx context.Context, input *RouteInputParams) (*SuggestedRoutesV2, error) {
|
||||
|
||||
areTestNetworksEnabled, err := r.s.accountsDB.GetTestNetworksEnabled()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
networks, err := r.s.rpcClient.NetworkManager.Get(false)
|
||||
func (r *Router) SuggestedRoutesV2(ctx context.Context, input *RouteInputParams) (*SuggestedRoutesV2, error) {
|
||||
networks, err := r.rpcClient.NetworkManager.Get(false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -359,7 +354,7 @@ func (r *Router) suggestedRoutesV2(ctx context.Context, input *RouteInputParams)
|
|||
|
||||
for networkIdx := range networks {
|
||||
network := networks[networkIdx]
|
||||
if network.IsTest != areTestNetworksEnabled {
|
||||
if network.IsTest != input.TestnetMode {
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -371,14 +366,14 @@ func (r *Router) suggestedRoutesV2(ctx context.Context, input *RouteInputParams)
|
|||
continue
|
||||
}
|
||||
|
||||
token := input.SendType.FindToken(r.s, input.AddrFrom, network, input.TokenID)
|
||||
token := input.SendType.FindToken(r.tokenManager, r.collectiblesService, input.AddrFrom, network, input.TokenID)
|
||||
if token == nil {
|
||||
continue
|
||||
}
|
||||
|
||||
var toToken *walletToken.Token
|
||||
if input.SendType == Swap {
|
||||
toToken = input.SendType.FindToken(r.s, common.Address{}, network, input.ToTokenID)
|
||||
toToken = input.SendType.FindToken(r.tokenManager, r.collectiblesService, common.Address{}, network, input.ToTokenID)
|
||||
}
|
||||
|
||||
amountLocked := false
|
||||
|
@ -397,7 +392,7 @@ func (r *Router) suggestedRoutesV2(ctx context.Context, input *RouteInputParams)
|
|||
}
|
||||
|
||||
group.Add(func(c context.Context) error {
|
||||
client, err := r.s.rpcClient.EthClient(network.ChainID)
|
||||
client, err := r.rpcClient.EthClient(network.ChainID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -408,7 +403,7 @@ func (r *Router) suggestedRoutesV2(ctx context.Context, input *RouteInputParams)
|
|||
}
|
||||
|
||||
for _, dest := range networks {
|
||||
if dest.IsTest != areTestNetworksEnabled {
|
||||
if dest.IsTest != input.TestnetMode {
|
||||
continue
|
||||
}
|
||||
|
||||
|
@ -437,7 +432,7 @@ func (r *Router) suggestedRoutesV2(ctx context.Context, input *RouteInputParams)
|
|||
continue
|
||||
}
|
||||
} else {
|
||||
gasLimit = input.SendType.EstimateGas(r.s, network, input.AddrFrom, input.TokenID)
|
||||
gasLimit = input.SendType.EstimateGas(r.ensService, r.stickersService, network, input.AddrFrom, input.TokenID)
|
||||
}
|
||||
|
||||
approvalContractAddress := bridge.GetContractAddress(network, token)
|
||||
|
@ -454,15 +449,15 @@ func (r *Router) suggestedRoutesV2(ctx context.Context, input *RouteInputParams)
|
|||
continue
|
||||
}
|
||||
|
||||
l1FeeWei, _ = r.s.feesManager.GetL1Fee(ctx, network.ChainID, tx)
|
||||
l1FeeWei, _ = r.feesManager.GetL1Fee(ctx, network.ChainID, tx)
|
||||
}
|
||||
|
||||
baseFee, err := r.s.feesManager.getBaseFee(ctx, client)
|
||||
baseFee, err := r.feesManager.getBaseFee(ctx, client)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
priorityFees, err := r.s.feesManager.getPriorityFees(ctx, client, baseFee)
|
||||
priorityFees, err := r.feesManager.getPriorityFees(ctx, client, baseFee)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
@ -480,7 +475,7 @@ func (r *Router) suggestedRoutesV2(ctx context.Context, input *RouteInputParams)
|
|||
|
||||
maxFeesPerGas := new(big.Float)
|
||||
maxFeesPerGas.Add(new(big.Float).SetInt(baseFee), new(big.Float).SetInt(selctedPriorityFee))
|
||||
estimatedTime := r.s.feesManager.transactionEstimatedTime(ctx, network.ChainID, maxFeesPerGas)
|
||||
estimatedTime := r.feesManager.TransactionEstimatedTime(ctx, network.ChainID, maxFeesPerGas)
|
||||
if approvalRequired && estimatedTime < MoreThanFiveMinutes {
|
||||
estimatedTime += 1
|
||||
}
|
||||
|
@ -524,7 +519,7 @@ func (r *Router) suggestedRoutesV2(ctx context.Context, input *RouteInputParams)
|
|||
|
||||
group.Wait()
|
||||
|
||||
prices, err := input.SendType.FetchPrices(r.s, input.TokenID)
|
||||
prices, err := input.SendType.FetchPrices(r.marketManager, input.TokenID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -553,7 +548,7 @@ func (r *Router) suggestedRoutesV2(ctx context.Context, input *RouteInputParams)
|
|||
}
|
||||
}
|
||||
|
||||
nativeToken := r.s.tokenManager.FindToken(path.From, path.From.NativeCurrencySymbol)
|
||||
nativeToken := r.tokenManager.FindToken(path.From, path.From.NativeCurrencySymbol)
|
||||
if nativeToken == nil {
|
||||
return nil, errors.New("native token not found")
|
||||
}
|
|
@ -185,7 +185,6 @@ func NewService(
|
|||
cryptoOnRampManager: cryptoOnRampManager,
|
||||
collectiblesManager: collectiblesManager,
|
||||
collectibles: collectibles,
|
||||
feesManager: &FeeManager{rpcClient},
|
||||
gethManager: gethManager,
|
||||
marketManager: marketManager,
|
||||
transactor: transactor,
|
||||
|
@ -217,7 +216,6 @@ type Service struct {
|
|||
pendingTxManager *transactions.PendingTxTracker
|
||||
cryptoOnRampManager *CryptoOnRampManager
|
||||
transferController *transfer.Controller
|
||||
feesManager *FeeManager
|
||||
marketManager *market.Manager
|
||||
started bool
|
||||
collectiblesManager *collectibles.Manager
|
||||
|
@ -299,3 +297,35 @@ func (s *Service) KeycardPairings() *KeycardPairings {
|
|||
func (s *Service) Config() *params.NodeConfig {
|
||||
return s.config
|
||||
}
|
||||
|
||||
func (s *Service) GetRPCClient() *rpc.Client {
|
||||
return s.rpcClient
|
||||
}
|
||||
|
||||
func (s *Service) GetTransactor() *transactions.Transactor {
|
||||
return s.transactor
|
||||
}
|
||||
|
||||
func (s *Service) GetTokenManager() *token.Manager {
|
||||
return s.tokenManager
|
||||
}
|
||||
|
||||
func (s *Service) GetMarketManager() *market.Manager {
|
||||
return s.marketManager
|
||||
}
|
||||
|
||||
func (s *Service) GetCollectiblesService() *collectibles.Service {
|
||||
return s.collectibles
|
||||
}
|
||||
|
||||
func (s *Service) GetCollectiblesManager() *collectibles.Manager {
|
||||
return s.collectiblesManager
|
||||
}
|
||||
|
||||
func (s *Service) GetEnsService() *ens.Service {
|
||||
return s.ens
|
||||
}
|
||||
|
||||
func (s *Service) GetStickersService() *stickers.Service {
|
||||
return s.stickers
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue