router

package
v0.179.25 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 30, 2024 License: MPL-2.0 Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const ERC1155TransferString = "ERC1155Transfer"
View Source
const ERC721TransferString = "ERC721Transfer"
View Source
const EstimatePubKey = "" /* 132-byte string literal not displayed */
View Source
const EstimateUsername = "RandomUsername"

Variables

This section is empty.

Functions

This section is empty.

Types

type FeeHistory

type FeeHistory struct {
	BaseFeePerGas []string `json:"baseFeePerGas"`
}

type FeeManager

type FeeManager struct {
	RPCClient *rpc.Client
}

func (*FeeManager) GetL1Fee

func (f *FeeManager) GetL1Fee(ctx context.Context, chainID uint64, input []byte) (uint64, error)

Returns L1 fee for placing a transaction to L1 chain, appicable only for txs made from L2.

func (*FeeManager) SuggestedFees

func (f *FeeManager) SuggestedFees(ctx context.Context, chainID uint64) (*SuggestedFees, error)

////////////////////////////////////////////////////////////////////////////// TODO: remove `suggestedFees` function once new router is in place

But we should check the client since this function is exposed to API as `GetSuggestedFees` call. Maybe we should keep it and remove it later when the client is ready for that change. //////////////////////////////////////////////////////////////////////////////

func (*FeeManager) TransactionEstimatedTime

func (f *FeeManager) TransactionEstimatedTime(ctx context.Context, chainID uint64, maxFeePerGas *big.Float) TransactionEstimation

type GasFeeMode

type GasFeeMode int
const (
	GasFeeLow GasFeeMode = iota
	GasFeeMedium
	GasFeeHigh
)

type Graph

type Graph = []*Node

type GraphV2

type GraphV2 = []*NodeV2

type Node

type Node struct {
	Path     *Path
	Children Graph
}

type NodeV2

type NodeV2 struct {
	Path     *PathV2
	Children GraphV2
}

type Path

type Path struct {
	BridgeName              string
	From                    *params.Network
	To                      *params.Network
	MaxAmountIn             *hexutil.Big
	AmountIn                *hexutil.Big
	AmountInLocked          bool
	AmountOut               *hexutil.Big
	GasAmount               uint64
	GasFees                 *SuggestedFees
	BonderFees              *hexutil.Big
	TokenFees               *big.Float
	Cost                    *big.Float
	EstimatedTime           TransactionEstimation
	ApprovalRequired        bool
	ApprovalGasFees         *big.Float
	ApprovalAmountRequired  *hexutil.Big
	ApprovalContractAddress *common.Address
}

func (*Path) Equal

func (p *Path) Equal(o *Path) bool

type PathV2

type PathV2 struct {
	BridgeName     string
	From           *params.Network    // Source chain
	To             *params.Network    // Destination chain
	FromToken      *walletToken.Token // Token on the source chain
	AmountIn       *hexutil.Big       // Amount that will be sent from the source chain
	AmountInLocked bool               // Is the amount locked
	AmountOut      *hexutil.Big       // Amount that will be received on the destination chain

	SuggestedPriorityFees *PriorityFees // Suggested priority fees for the transaction

	TxBaseFee     *hexutil.Big // Base fee for the transaction
	TxPriorityFee *hexutil.Big // Priority fee for the transaction, by default we're using the Medium priority fee
	TxGasAmount   uint64       // Gas used for the transaction
	TxBonderFees  *hexutil.Big // Bonder fees for the transaction - used for Hop bridge
	TxTokenFees   *hexutil.Big // Token fees for the transaction - used for bridges (represent the difference between the amount in and the amount out)
	TxL1Fee       *hexutil.Big // L1 fee for the transaction - used for for transactions placed on L2 chains

	ApprovalRequired        bool            // Is approval required for the transaction
	ApprovalAmountRequired  *hexutil.Big    // Amount required for the approval transaction
	ApprovalContractAddress *common.Address // Address of the contract that needs to be approved
	ApprovalBaseFee         *hexutil.Big    // Base fee for the approval transaction
	ApprovalPriorityFee     *hexutil.Big    // Priority fee for the approval transaction
	ApprovalGasAmount       uint64          // Gas used for the approval transaction
	ApprovalL1Fee           *hexutil.Big    // L1 fee for the approval transaction - used for for transactions placed on L2 chains

	EstimatedTime TransactionEstimation
	// contains filtered or unexported fields
}

func (*PathV2) Equal

func (p *PathV2) Equal(o *PathV2) bool

type PriorityFees

type PriorityFees struct {
	Low    *big.Int `json:"low"`
	Medium *big.Int `json:"medium"`
	High   *big.Int `json:"high"`
}

type RouteInputParams

type RouteInputParams struct {
	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" validate:"required"`
	FromLockedAmount     map[uint64]*hexutil.Big `json:"fromLockedAmount"`
	TestnetMode          bool                    `json:"testnetMode"`
}

type Router

type Router struct {
	// contains filtered or unexported fields
}

func NewRouter

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

func (*Router) GetBridges

func (r *Router) GetBridges() map[string]bridge.Bridge

func (*Router) GetFeesManager

func (r *Router) GetFeesManager() *FeeManager

func (*Router) SuggestedRoutes

func (r *Router) SuggestedRoutes(
	ctx context.Context,
	sendType SendType,
	addrFrom common.Address,
	addrTo common.Address,
	amountIn *big.Int,
	tokenID string,
	toTokenID string,
	disabledFromChainIDs,
	disabledToChaindIDs,
	preferedChainIDs []uint64,
	gasFeeMode GasFeeMode,
	fromLockedAmount map[uint64]*hexutil.Big,
	testnetMode bool,
) (*SuggestedRoutes, error)

func (*Router) SuggestedRoutesV2

func (r *Router) SuggestedRoutesV2(ctx context.Context, input *RouteInputParams) (*SuggestedRoutesV2, error)

type SendType

type SendType int
const (
	Transfer SendType = iota
	ENSRegister
	ENSRelease
	ENSSetPubKey
	StickersBuy
	Bridge
	ERC721Transfer
	ERC1155Transfer
	Swap
)

func (SendType) EstimateGas

func (s SendType) EstimateGas(ensService *ens.Service, stickersService *stickers.Service, network *params.Network, from common.Address, tokenID string) uint64

func (SendType) FetchPrices

func (s SendType) FetchPrices(marketManager *market.Manager, tokenID string) (map[string]float64, error)

func (SendType) FindToken

func (s SendType) FindToken(tokenManager *token.Manager, collectibles *collectibles.Service, account common.Address, network *params.Network, tokenID string) *token.Token

func (SendType) IsCollectiblesTransfer

func (s SendType) IsCollectiblesTransfer() bool

type SuggestedFees

type SuggestedFees struct {
	GasPrice             *big.Float `json:"gasPrice"`
	BaseFee              *big.Float `json:"baseFee"`
	MaxPriorityFeePerGas *big.Float `json:"maxPriorityFeePerGas"`
	MaxFeePerGasLow      *big.Float `json:"maxFeePerGasLow"`
	MaxFeePerGasMedium   *big.Float `json:"maxFeePerGasMedium"`
	MaxFeePerGasHigh     *big.Float `json:"maxFeePerGasHigh"`
	L1GasFee             *big.Float `json:"l1GasFee,omitempty"`
	EIP1559Enabled       bool       `json:"eip1559Enabled"`
}

////////////////////////////////////////////////////////////////////////////// TODO: remove `SuggestedFees` struct once new router is in place //////////////////////////////////////////////////////////////////////////////

type SuggestedRoutes

type SuggestedRoutes struct {
	Best                  []*Path
	Candidates            []*Path
	TokenPrice            float64
	NativeChainTokenPrice float64
}

type SuggestedRoutesV2

type SuggestedRoutesV2 struct {
	Best                  []*PathV2
	Candidates            []*PathV2
	TokenPrice            float64
	NativeChainTokenPrice float64
}

type TransactionEstimation

type TransactionEstimation int
const (
	Unknown TransactionEstimation = iota
	LessThanOneMinute
	LessThanThreeMinutes
	LessThanFiveMinutes
	MoreThanFiveMinutes
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL