Documentation ¶
Index ¶
- Constants
- func EncodeDataToSign(dstChainId uint64, dstAddr eth.Addr, data eth.Hash) []byte
- type AmountCalculator
- type Chain
- func (c Chain) GetChainId() uint64
- func (c Chain) GetERC20Balance(opts *bind.CallOpts, token, account eth.Addr) (*big.Int, error)
- func (c Chain) GetGasPrice() *big.Int
- func (c Chain) GetMsgFee(opts *bind.CallOpts, _message []byte) (*big.Int, error)
- func (c Chain) GetNativeBalance(account eth.Addr) (*big.Int, error)
- func (c Chain) GetNativeWrap() *common.Token
- func (c Chain) GetQuoteStatus(opts *bind.CallOpts, _quoteHash eth.Hash) (uint8, error)
- func (c Chain) GetRfqFee(opts *bind.CallOpts, _chainId uint64, _amount *big.Int) (*big.Int, error)
- func (c Chain) VerifyRfqEvent(tx, evID eth.Hash, evName string) (bool, error)
- type ChainManager
- func (cm *ChainManager) GetChain(chainId uint64) (*Chain, error)
- func (cm *ChainManager) GetERC20Balance(chainId uint64, token, account eth.Addr) (*big.Int, error)
- func (cm *ChainManager) GetGasPrice(chainId uint64) (*big.Int, error)
- func (cm *ChainManager) GetMsgFee(chainId uint64) (*big.Int, error)
- func (cm *ChainManager) GetNativeBalance(chainId uint64, account eth.Addr) (*big.Int, error)
- func (cm *ChainManager) GetNativeWrap(chainId uint64) (*common.Token, error)
- func (cm *ChainManager) GetQuoteStatus(chainId uint64, quoteHash eth.Hash) (uint8, error)
- func (cm *ChainManager) GetRfqContract(chainId uint64) (eth.Addr, error)
- func (cm *ChainManager) GetRfqFee(srcChainId, dstChainId uint64, amount *big.Int) (*big.Int, error)
- func (cm *ChainManager) VerifyRfqEvent(chainId uint64, tx eth.Hash, evName string) (bool, error)
- type ChainOverride
- type ChainQuerier
- type Client
- type DefaultAmtCalculator
- func (ac *DefaultAmtCalculator) CalRecvAmt(tokenIn, tokenOut *common.Token, amountIn, baseFeeForLMM *big.Int, ...) (amountOut, releaseAmt, fee *big.Int, err error)
- func (ac *DefaultAmtCalculator) CalSendAmt(tokenIn, tokenOut *common.Token, amountOut *big.Int) (*big.Int, *big.Int, *big.Int, error)
- func (ac *DefaultAmtCalculator) SetDstGasCost(gasCost uint64)
- func (ac *DefaultAmtCalculator) SetGasPrice(prices []*GasPrice)
- func (ac *DefaultAmtCalculator) SetGlobalFeePerc(feePerc uint32) error
- func (ac *DefaultAmtCalculator) SetMaxFeeUsdValue(maxFeeUsdValue uint64)
- func (ac *DefaultAmtCalculator) SetMinFeeUsdValue(minFeeUsdValue uint64)
- func (ac *DefaultAmtCalculator) SetPerChainPairFeePercOverride(overrides []*ChainOverride) error
- func (ac *DefaultAmtCalculator) SetPerTokenPairFeePercOverride(overrides []*TokenOverride) error
- func (ac *DefaultAmtCalculator) SetSrcGasCost(gasCost uint64)
- type DefaultLiquidityProvider
- func (d DefaultLiquidityProvider) AskForFreezing(chainId uint64, token eth.Addr, amount *big.Int, isNative bool) (int64, error)
- func (d *DefaultLiquidityProvider) DstTransfer(transferNative bool, _quote rfq.RFQQuote, opts ...ethutils.TxOption) (eth.Hash, error)
- func (d DefaultLiquidityProvider) FreezeLiquidity(chainId uint64, token eth.Addr, amount *big.Int, until int64, hash eth.Hash, ...) error
- func (d DefaultLiquidityProvider) GetLiquidityProviderAddr(chainId uint64) (eth.Addr, error)
- func (d DefaultLiquidityProvider) GetTokens() []*common.Token
- func (d DefaultLiquidityProvider) HasTokenPair(srcToken, dstToken *common.Token) bool
- func (d DefaultLiquidityProvider) IsPaused() bool
- func (d *DefaultLiquidityProvider) SetupTokenPairs(policies []string)
- func (d *DefaultLiquidityProvider) SrcRelease(_quote rfq.RFQQuote, _execMsgCallData []byte, opts ...ethutils.TxOption) (eth.Hash, error)
- func (d DefaultLiquidityProvider) UnfreezeLiquidity(chainId uint64, hash eth.Hash) error
- type DefaultRequestSigner
- type FeeConfig
- type GasPrice
- type LPConfig
- type LiqManager
- func (d *LiqManager) AskForFreezing(chainId uint64, token eth.Addr, amount *big.Int) (int64, error)
- func (d *LiqManager) ConfirmLiquidity(chainId uint64, token eth.Addr, amount *big.Int, until int64, hash eth.Hash) error
- func (d *LiqManager) GetChains() []uint64
- func (d *LiqManager) GetLP(chainId uint64) (*LiqProvider, error)
- func (d *LiqManager) GetLiqNeedApprove(chainId uint64) ([]*common.Token, []*big.Int, error)
- func (d *LiqManager) GetLiquidityProvider(chainId uint64) (eth.Addr, error)
- func (d *LiqManager) GetSigner(chainId uint64) (eth.Addr, ethutils.Signer, error)
- func (d *LiqManager) GetTokens() map[uint64][]*common.Token
- func (d *LiqManager) ReleaseInLiquidity(chainId uint64, token eth.Addr, amount *big.Int) error
- func (d *LiqManager) ReleaseNative(chainId uint64) (bool, error)
- func (d *LiqManager) ReserveLiquidity(chainId uint64, token eth.Addr, amount *big.Int, until int64, hash eth.Hash) error
- func (d *LiqManager) TransferOutLiquidity(chainId uint64, token eth.Addr, amount *big.Int, hash eth.Hash) error
- func (d *LiqManager) UnfreezeLiquidity(chainId uint64, hash eth.Hash) error
- func (d *LiqManager) UpdateLiqAmt(querier ChainQuerier)
- type LiqOpDetail
- type LiqProvider
- type Liquidity
- type LiquidityConfig
- type LiquidityProvider
- type PriceProvider
- type RequestSigner
- type RequestSignerConfig
- type RfqMmChainConfig
- type Server
- func (s *Server) DefaultProcessOrder()
- func (s *Server) Price(ctx context.Context, request *proto.PriceRequest) (response *proto.PriceResponse, err error)
- func (s *Server) Quote(ctx context.Context, request *proto.QuoteRequest) (response *proto.QuoteResponse, err error)
- func (s *Server) ReportConfigs()
- func (s *Server) Serve(ops ...grpc.ServerOption)
- func (s *Server) SignQuoteHash(ctx context.Context, request *proto.SignQuoteHashRequest) (*proto.SignQuoteHashResponse, error)
- func (s *Server) StopProcessing(reason string)
- func (s *Server) Tokens(ctx context.Context, request *proto.TokensRequest) (*proto.TokensResponse, error)
- func (s *Server) ValidateQuote(quote *proto.Quote, sig []byte) bool
- type ServerConfig
- type TokenOverride
- type Update
Constants ¶
View Source
const ( LiqOpAny = iota LiqOpReserve LiqOpConfirm )
View Source
const ( NativeTokenReference = "ffffffffffffffffffffffffffffffffffffffff" TPPolicyAll = "All" TPPolicyPrefixAny2Of = "Any2Of=" TPPolicyPrefixOneOf = "OneOf=" )
View Source
const ( DefaultReportRetryPeriod int64 = 5 DefaultProcessPeriod int64 = 5 DefaultPriceValidPeriod int64 = 300 DefaultDstTransferPeriod int64 = 3000 DefaultGrpcPort int64 = 5555 DefaultGrpcGatewayPort int64 = 6666 )
View Source
const BestPeriodMultiplier = 1.2
Variables ¶
This section is empty.
Functions ¶
Types ¶
type AmountCalculator ¶
type Chain ¶
type Chain struct { *ethclient.Client ChainId uint64 BlockDelay uint64 NativeWrap *common.Token RfqContract *rfq.Rfq RfqAddress eth.Addr IWETH *iweth.Iweth MsgFee *big.Int TxOptions []ethutils.TxOption GasPriceCache *dataCache }
func NewChain ¶
func NewChain(config *RfqMmChainConfig) *Chain
func (Chain) GetChainId ¶
func (Chain) GetERC20Balance ¶
func (Chain) GetGasPrice ¶
func (Chain) GetNativeWrap ¶
func (Chain) GetQuoteStatus ¶
type ChainManager ¶
type ChainManager struct {
// contains filtered or unexported fields
}
func NewChainManager ¶
func NewChainManager(configs []*RfqMmChainConfig) *ChainManager
func (*ChainManager) GetERC20Balance ¶
func (*ChainManager) GetGasPrice ¶
func (cm *ChainManager) GetGasPrice(chainId uint64) (*big.Int, error)
func (*ChainManager) GetMsgFee ¶
func (cm *ChainManager) GetMsgFee(chainId uint64) (*big.Int, error)
func (*ChainManager) GetNativeBalance ¶
func (*ChainManager) GetNativeWrap ¶
func (cm *ChainManager) GetNativeWrap(chainId uint64) (*common.Token, error)
func (*ChainManager) GetQuoteStatus ¶
func (*ChainManager) GetRfqContract ¶
func (cm *ChainManager) GetRfqContract(chainId uint64) (eth.Addr, error)
func (*ChainManager) VerifyRfqEvent ¶
type ChainOverride ¶
type ChainQuerier ¶
type ChainQuerier interface { GetRfqContract(chainId uint64) (eth.Addr, error) GetRfqFee(srcChainId, dstChainId uint64, amount *big.Int) (*big.Int, error) GetMsgFee(chainId uint64) (*big.Int, error) GetGasPrice(chainId uint64) (*big.Int, error) GetNativeWrap(chainId uint64) (*common.Token, error) GetERC20Balance(chainId uint64, token, account eth.Addr) (*big.Int, error) GetNativeBalance(chainId uint64, accoun eth.Addr) (*big.Int, error) GetQuoteStatus(chainId uint64, quoteHash eth.Hash) (uint8, error) VerifyRfqEvent(chainId uint64, tx eth.Hash, evName string) (bool, error) }
type Client ¶
func (*Client) Price ¶
func (c *Client) Price(ctx context.Context, in *proto.PriceRequest, opts ...grpc.CallOption) (*proto.PriceResponse, error)
func (*Client) Quote ¶
func (c *Client) Quote(ctx context.Context, in *proto.QuoteRequest, opts ...grpc.CallOption) (*proto.QuoteResponse, error)
type DefaultAmtCalculator ¶
type DefaultAmtCalculator struct { // fixed cost related fields DstGasCost uint64 SrcGasCost uint64 GasPrice map[uint64]uint64 // personalized fee related fieds // 100% = 1000000 FeePercGlobal uint32 PerChainPairOverride map[uint64]map[uint64]uint32 PerTokenPairOverride map[string]map[string]uint32 // helper Querier ChainQuerier PriceProvider PriceProvider }
func NewDefaultAmtCalculator ¶
func NewDefaultAmtCalculator(feeConfig *FeeConfig, querier ChainQuerier, priceProvider PriceProvider) *DefaultAmtCalculator
func (*DefaultAmtCalculator) CalRecvAmt ¶
func (*DefaultAmtCalculator) CalSendAmt ¶
func (*DefaultAmtCalculator) SetDstGasCost ¶
func (ac *DefaultAmtCalculator) SetDstGasCost(gasCost uint64)
func (*DefaultAmtCalculator) SetGasPrice ¶
func (ac *DefaultAmtCalculator) SetGasPrice(prices []*GasPrice)
func (*DefaultAmtCalculator) SetGlobalFeePerc ¶
func (ac *DefaultAmtCalculator) SetGlobalFeePerc(feePerc uint32) error
func (*DefaultAmtCalculator) SetMaxFeeUsdValue ¶
func (ac *DefaultAmtCalculator) SetMaxFeeUsdValue(maxFeeUsdValue uint64)
func (*DefaultAmtCalculator) SetMinFeeUsdValue ¶
func (ac *DefaultAmtCalculator) SetMinFeeUsdValue(minFeeUsdValue uint64)
func (*DefaultAmtCalculator) SetPerChainPairFeePercOverride ¶
func (ac *DefaultAmtCalculator) SetPerChainPairFeePercOverride(overrides []*ChainOverride) error
func (*DefaultAmtCalculator) SetPerTokenPairFeePercOverride ¶
func (ac *DefaultAmtCalculator) SetPerTokenPairFeePercOverride(overrides []*TokenOverride) error
func (*DefaultAmtCalculator) SetSrcGasCost ¶
func (ac *DefaultAmtCalculator) SetSrcGasCost(gasCost uint64)
type DefaultLiquidityProvider ¶
type DefaultLiquidityProvider struct {
// contains filtered or unexported fields
}
func NewDefaultLiquidityProvider ¶
func NewDefaultLiquidityProvider(cm *ChainManager, lm *LiqManager) *DefaultLiquidityProvider
func (DefaultLiquidityProvider) AskForFreezing ¶
func (*DefaultLiquidityProvider) DstTransfer ¶
func (DefaultLiquidityProvider) FreezeLiquidity ¶
func (DefaultLiquidityProvider) GetLiquidityProviderAddr ¶
func (d DefaultLiquidityProvider) GetLiquidityProviderAddr(chainId uint64) (eth.Addr, error)
func (DefaultLiquidityProvider) GetTokens ¶
func (d DefaultLiquidityProvider) GetTokens() []*common.Token
func (DefaultLiquidityProvider) HasTokenPair ¶
func (d DefaultLiquidityProvider) HasTokenPair(srcToken, dstToken *common.Token) bool
func (DefaultLiquidityProvider) IsPaused ¶
func (d DefaultLiquidityProvider) IsPaused() bool
func (*DefaultLiquidityProvider) SetupTokenPairs ¶
func (d *DefaultLiquidityProvider) SetupTokenPairs(policies []string)
policy str is one of {"All", "Any2Of=<chainId>-<symbol>,<chainId>-<symbol>...", "OneOf=<chainId>-<symbol>,<chainId>-<symbol>"}
func (*DefaultLiquidityProvider) SrcRelease ¶
func (DefaultLiquidityProvider) UnfreezeLiquidity ¶
func (d DefaultLiquidityProvider) UnfreezeLiquidity(chainId uint64, hash eth.Hash) error
type DefaultRequestSigner ¶
func NewRequestSigner ¶
func NewRequestSigner(config *RequestSignerConfig) *DefaultRequestSigner
func (*DefaultRequestSigner) Sign ¶
func (rs *DefaultRequestSigner) Sign(data []byte) ([]byte, error)
func (*DefaultRequestSigner) Verify ¶
func (rs *DefaultRequestSigner) Verify(data, sig []byte) bool
type FeeConfig ¶
type FeeConfig struct { DstGasCost uint64 SrcGasCost uint64 PercGlobal uint32 ChainOverrides []*ChainOverride TokenOverrides []*TokenOverride GasPrices []*GasPrice }
type LiqManager ¶
type LiqManager struct {
LPs map[uint64]*LiqProvider
}
func NewLiqManager ¶
func NewLiqManager(configs []*LPConfig) *LiqManager
func (*LiqManager) AskForFreezing ¶
func (*LiqManager) ConfirmLiquidity ¶
func (*LiqManager) GetChains ¶
func (d *LiqManager) GetChains() []uint64
func (*LiqManager) GetLP ¶
func (d *LiqManager) GetLP(chainId uint64) (*LiqProvider, error)
func (*LiqManager) GetLiqNeedApprove ¶
func (*LiqManager) GetLiquidityProvider ¶
func (d *LiqManager) GetLiquidityProvider(chainId uint64) (eth.Addr, error)
func (*LiqManager) ReleaseInLiquidity ¶
func (*LiqManager) ReleaseNative ¶
func (d *LiqManager) ReleaseNative(chainId uint64) (bool, error)
func (*LiqManager) ReserveLiquidity ¶
func (*LiqManager) TransferOutLiquidity ¶
func (*LiqManager) UnfreezeLiquidity ¶
func (d *LiqManager) UnfreezeLiquidity(chainId uint64, hash eth.Hash) error
func (*LiqManager) UpdateLiqAmt ¶
func (d *LiqManager) UpdateLiqAmt(querier ChainQuerier)
type LiqOpDetail ¶
type LiqProvider ¶
type LiqProvider struct {
// contains filtered or unexported fields
}
func NewLiqProvider ¶
func NewLiqProvider(config *LPConfig) *LiqProvider
type LiquidityConfig ¶
type LiquidityProvider ¶
type LiquidityProvider interface { // IsPaused returns whether the LiquidityProvider is paused or not IsPaused() bool // GetTokens returns a list of all supported tokens GetTokens() []*common.Token // SetupTokenPairs sets up supported token pairs based on a given policy list. SetupTokenPairs(policies []string) // HasTokenPair check if a given token pair is supported HasTokenPair(srcToken, dstToken *common.Token) bool // GetLiquidityProviderAddr returns the address of liquidity provider on specified chain GetLiquidityProviderAddr(chainId uint64) (eth.Addr, error) // AskForFreezing checks if there is sufficient liquidity for specified token on specified chain and returns freeze time AskForFreezing(chainId uint64, token eth.Addr, amount *big.Int, isNative bool) (int64, error) // FreezeLiquidity will freeze a certain liquidity for specified amount until specified timestamp with an index of hash. FreezeLiquidity(chainId uint64, token eth.Addr, amount *big.Int, until int64, hash eth.Hash, isNative bool) error // UnfreezeLiquidity will try to unfreeze a certain liquidity with specified hash. UnfreezeLiquidity(chainId uint64, hash eth.Hash) error // DstTransfer should send tx on dstChain to transfer dstToken to user DstTransfer(transferNative bool, _quote rfq.RFQQuote, opts ...ethutils.TxOption) (eth.Hash, error) // SrcRelease should send tx on srcChain to release srcToken to mm SrcRelease(_quote rfq.RFQQuote, _execMsgCallData []byte, opts ...ethutils.TxOption) (eth.Hash, error) }
type PriceProvider ¶
type RequestSigner ¶
type RequestSignerConfig ¶
type RfqMmChainConfig ¶
type RfqMmChainConfig struct { ChainId uint64 Name, Gateway string BlkInterval, BlkDelay, MaxBlkDelta, ForwardBlkDelay uint64 GasLimit uint64 AddGasEstimateRatio float64 // Legacy gas price flags AddGasGwei uint64 MinGasGwei uint64 MaxGasGwei uint64 ForceGasGwei string // EIP-1559 gas price flags MaxFeePerGasGwei uint64 MaxPriorityFeePerGasGwei uint64 // if ProxyPort > 0, a proxy with this port will be created to support some special chain such as harmony, celo. // chainID will be used to determined which type proxy to create, so make sure the chainID is supported in the "endpoint-proxy" // create a proxy to the Gateway, and eth-client will be created to "127.0.0.1:ProxyPort" // more detail, https://github.com/celer-network/endpoint-proxy ProxyPort int Rfq string Native *common.Token }
type Server ¶
type Server struct { Ctl chan bool RfqClient *rfqserver.Client Config *ServerConfig ChainCaller ChainQuerier LiquidityProvider LiquidityProvider AmountCalculator AmountCalculator RequestSigner RequestSigner }
func NewServer ¶
func NewServer(config *ServerConfig, client *rfqserver.Client, cm ChainQuerier, lp LiquidityProvider, ac AmountCalculator, rs RequestSigner) *Server
func (*Server) DefaultProcessOrder ¶
func (s *Server) DefaultProcessOrder()
func (*Server) Price ¶
func (s *Server) Price(ctx context.Context, request *proto.PriceRequest) (response *proto.PriceResponse, err error)
func (*Server) Quote ¶
func (s *Server) Quote(ctx context.Context, request *proto.QuoteRequest) (response *proto.QuoteResponse, err error)
func (*Server) ReportConfigs ¶
func (s *Server) ReportConfigs()
func (*Server) Serve ¶
func (s *Server) Serve(ops ...grpc.ServerOption)
func (*Server) SignQuoteHash ¶
func (s *Server) SignQuoteHash(ctx context.Context, request *proto.SignQuoteHashRequest) (*proto.SignQuoteHashResponse, error)
func (*Server) StopProcessing ¶
func (*Server) Tokens ¶
func (s *Server) Tokens(ctx context.Context, request *proto.TokensRequest) (*proto.TokensResponse, error)
type ServerConfig ¶
type ServerConfig struct { // the period for retrying report supported tokens to rfq server ReportRetryPeriod int64 // the period for processing pending orders ProcessPeriod int64 // indicates the period for a price to be valid PriceValidPeriod int64 // minimum dst transfer period, in order to give mm enough time for dst transfer DstTransferPeriod int64 // token pair policy list TPPolicyList []string // port num that mm grpc service would listen on GrpcPort int64 // port num that mm restful api would listen on GrpcGatewayPort int64 // light mm, which needs a relayer to interact with rfq server LightMM bool // if not set, will use localhost Host string }
type TokenOverride ¶
Source Files ¶
Click to show internal directories.
Click to hide internal directories.