router

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2024 License: MIT Imports: 33 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PermaswapClosed = false

	// penalty config
	CumulativeFailures = 3
	ExpirationDuration = 3600
)

Variables

View Source
var (
	WsErrNotFoundPath          = NewWsErr("err_not_found_path")
	WsErrNotFoundSalt          = NewWsErr("err_not_found_salt")
	WsErrNotFoundLp            = NewWsErr("err_not_found_lp")
	WsErrNoAuthorization       = NewWsErr("err_no_authorization")
	WsErrCanNotUpdateLp        = NewWsErr("err_can_not_update_lp")
	WsErrDuplicateRegistration = NewWsErr("err_duplicate_registration")
	WsErrInvalidMsg            = NewWsErr("err_invalid_msg")
	WsErrInvalidToken          = NewWsErr("err_invalid_token")
	WsErrInvalidOrder          = NewWsErr("err_invalid_order")
	WsErrInvalidAddress        = NewWsErr("err_invalid_address")
	WsErrInvalidSignature      = NewWsErr("err_invalid_signature")
	WsErrInvalidPathsOrBundle  = NewWsErr("err_invalid_paths_or_bundle")
	WsErrNotNFTOwner           = NewWsErr("err_not_nft_owner")
	WsErrInvalidNFTData        = NewWsErr("err_invalid_nft_data")
	WsErrInvalidLpClient       = NewWsErr("err_invalid_lp_client")
	WsErrBlackListed           = NewWsErr("err_blacklisted")
)

Functions

func CalPrice

func CalPrice(
	paths []coreSchema.Path, tokens map[string]*everSchema.Token,
	tokenInTag, tokenOutTag, userAddr string,
) (price, tokenInAmount, tokenOutAmount *big.Float)

func ClosedMiddleware

func ClosedMiddleware() gin.HandlerFunc

func ConvertPathsToBundle

func ConvertPathsToBundle(paths []coreSchema.Path, tokens map[string]*everSchema.Token, expireAt int64, salt string) (bundle everSchema.Bundle, err error)

func GetLpClientInfoConf

func GetLpClientInfoConf(chainID int64) (lpClients map[string]*schema.LpClientInfo)

func GetTokenPriceByRedstone

func GetTokenPriceByRedstone(tokenSymbol string, currency string, timestamp string) (float64, error)

func VerifyBundleAndPaths

func VerifyBundleAndPaths(bundle everSchema.Bundle, paths []coreSchema.Path, tokens map[string]*everSchema.Token) (err error)

func VerifyBundleByAddr

func VerifyBundleByAddr(bundle everSchema.BundleWithSigs, address string, chainID int64) (accid string, accsig map[string]string, err error)

func VerifySig

func VerifySig(accType, accID string, msg, sig string, chainID int) (err error)

Types

type Config

type Config struct {
	Name         string
	Desc         string
	Domain       string
	Ip           string
	AccountType  string `toml:"account_type"`
	KeyFile      string `toml:"key_file"`
	Port         string
	Mysql        string
	ChainId      int64  `toml:"chain_id"`
	EverpayApi   string `toml:"everpay_api"`
	NftWhitelist bool   `toml:"nft_whitelist"`
	NftApi       string `toml:"nft_api"`

	FeeRatio     string `toml:"fee_ratio"`
	FeeRecipient string `toml:"fee_recipient"`
	Pools        []Pool
}

type NFT

type NFT struct {
	ContractAddr string `json:"contractAddr"`
	TokenId      string `json:"tokenId"`
	Collection   string `json:"collection"`
	Name         string `json:"name"`
	Owner        string `json:"owner"`
}

func (*NFT) ID

func (n *NFT) ID() string

type NFTInfo

type NFTInfo struct {
	ApiURL string

	NFTs               map[string]*NFT
	NFTToOwner         map[string]string
	OwnerToNFTs        map[string][]string
	Whitelist          []string
	NFTOwnerChangeChan chan *NFTOwnerChangeMsg //notify the change of nft owner
	// contains filtered or unexported fields
}

func NewNFTInfo

func NewNFTInfo(apiURL string, whitelist []string, c chan *NFTOwnerChangeMsg) *NFTInfo

func (*NFTInfo) GetNFTInfo

func (n *NFTInfo) GetNFTInfo() (map[string]string, map[string][]string, []string)

func (*NFTInfo) GetOwners

func (n *NFTInfo) GetOwners() map[string]int

func (*NFTInfo) Passed

func (n *NFTInfo) Passed(account string) bool

func (*NFTInfo) Run

func (n *NFTInfo) Run()

func (*NFTInfo) SetWhitelist

func (n *NFTInfo) SetWhitelist(whitelist []string)

type NFTOwnerChangeMsg

type NFTOwnerChangeMsg struct {
	NFTID string
	From  string
	To    string
}

type Order

type Order struct {
	ChainID     int64
	UserMsg     *schema.UserMsgSubmit
	Status      string
	InternalErr *everSchema.InternalErr
	EverHash    string
	Timestamp   int64
	Bundle      *everSchema.BundleWithSigs
	Lps         map[string]*coreSchema.Lp // lpID -> lp
	// contains filtered or unexported fields
}

Order doing in order goroutines 1. make LP signature 2. submit order to everPay 3. update order status & notice update core

func NewOrder

func NewOrder(ChainID int64,
	userMsg *schema.UserMsgSubmit, bundle everSchema.BundleWithSigs,
	lps map[string]*coreSchema.Lp, router *Router, lpSessions map[string]string, dryRun bool,
) *Order

NewOrder lpSessions: lp addr -> lp session id

func (*Order) Run

func (o *Order) Run()

type Penalty

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

func NewPenalty

func NewPenalty() *Penalty

func (*Penalty) AddFailRecord

func (p *Penalty) AddFailRecord(accid string, timestamp int64, everHash string, reason string)

func (*Penalty) ClearUpExpired

func (p *Penalty) ClearUpExpired()

func (*Penalty) GetBlackList

func (p *Penalty) GetBlackList() map[string]int64

func (*Penalty) GetFailureRecords

func (p *Penalty) GetFailureRecords() map[string][]schema.FailureRecord

func (*Penalty) GetPenalty

func (p *Penalty) GetPenalty() (map[string]int64, map[string][]schema.FailureRecord)

func (*Penalty) IsBlackListed

func (p *Penalty) IsBlackListed(accid string) bool

type Pool

type Pool struct {
	X   string
	Y   string
	Fee string
}

type Price

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

func NewPrice

func NewPrice(tokens map[string]*everSchema.Token) *Price

func (*Price) GetPrice

func (p *Price) GetPrice(tokenTag string) (price float64, ok bool)

func (*Price) Run

func (p *Price) Run()

type Router

type Router struct {
	NFTWhiteList   bool
	NFTInfo        *NFTInfo
	NFTOwnerChange chan *NFTOwnerChangeMsg

	Stats *Stats

	LpClientInfo map[string]*schema.LpClientInfo
	// contains filtered or unexported fields
}

func New

func New(config *Config, haloConfig *halo.Config, everSDK *sdk.SDK, haloSDK *halosdk.SDK, dryRun bool) *Router

func (*Router) CheckNFTOrNot

func (r *Router) CheckNFTOrNot() bool

func (*Router) Close

func (r *Router) Close()

func (*Router) Join

func (r *Router) Join()

func (*Router) Run

func (r *Router) Run(port, haloAPIURLPrefix string)

type Stats

type Stats struct {
	Price *Price

	AccIDToVolume24hs map[string][]*schema.Volume
	AccIDToRewards    map[string][]*schema.PermaLpReward
	AccIDToTVLs       map[string][]*schema.TVL

	PoolIDToVolume24h map[string]*schema.Volume
	PoolIDToTVL       map[string]*schema.TVL
	// contains filtered or unexported fields
}

func NewStats

func NewStats(tokens map[string]*everSchema.Token, pools map[string]*coreSchema.Pool, w *WDB) *Stats

func (*Stats) GetRewardsByAccid

func (s *Stats) GetRewardsByAccid(accid string) (rewards []schema.PermaLpReward)

func (*Stats) GetTVLByPoolID

func (s *Stats) GetTVLByPoolID(poolid string) (tvl schema.TVL)

func (*Stats) GetTVLsByAccid

func (s *Stats) GetTVLsByAccid(accid string) (tvls []schema.TVL)

func (*Stats) GetVolumeByPoolID

func (s *Stats) GetVolumeByPoolID(poolid string) (volume schema.Volume)

func (*Stats) GetVolumesByAccid

func (s *Stats) GetVolumesByAccid(accid string) (volumes []schema.Volume)

func (*Stats) Run

func (s *Stats) Run()

type WDB

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

func NewWDB

func NewWDB(dsn string) *WDB

func (*WDB) CreatePermaOrder

func (w *WDB) CreatePermaOrder(order *schema.PermaOrder, tx *gorm.DB) error

func (*WDB) CreatePermaVolume

func (w *WDB) CreatePermaVolume(volume *schema.PermaVolume, tx *gorm.DB) error

func (*WDB) GetOrders

func (w *WDB) GetOrders(page, count int, start, end time.Time) (orders []*schema.PermaOrder, err error)

func (*WDB) GetOrdersByUser

func (w *WDB) GetOrdersByUser(accid string, page, count int, start, end time.Time) (orders []*schema.PermaOrder, err error)

func (*WDB) GetPermaReward

func (w *WDB) GetPermaReward(lpid string, tx *gorm.DB) (reward *schema.PermaLpReward, err error)

func (*WDB) GetPermaRewards

func (w *WDB) GetPermaRewards(accid string, tx *gorm.DB) (rewards []*schema.PermaLpReward, err error)

func (*WDB) GetVolumesByTime

func (w *WDB) GetVolumesByTime(start, end time.Time) (volumes []*schema.PermaVolume, err error)

func (*WDB) LoadNFTWhiteList

func (w *WDB) LoadNFTWhiteList() (list []*schema.NFTWhiteList, err error)

func (*WDB) LoadPermaLpsSnapshot

func (w *WDB) LoadPermaLpsSnapshot() (lpsSnapshot *schema.PermaLpsSnapshot, err error)

func (*WDB) Migrate

func (w *WDB) Migrate()

func (*WDB) SavePermaLpsSnapshot

func (w *WDB) SavePermaLpsSnapshot(lpsSnapshot *schema.PermaLpsSnapshot, tx *gorm.DB) (err error)

func (*WDB) SumPoolVolumesByTime

func (w *WDB) SumPoolVolumesByTime(start, end time.Time) (res []*schema.SumPermaVolumeRes, err error)

func (*WDB) SumVolumesByTime

func (w *WDB) SumVolumesByTime(start, end time.Time) (res []*schema.SumPermaVolumeRes, err error)

func (*WDB) TotalOrdersNumByUser

func (w *WDB) TotalOrdersNumByUser(accid string) (num int64, err error)

func (*WDB) UpdatePermaLpReward

func (w *WDB) UpdatePermaLpReward(lpReward *schema.PermaLpReward, tx *gorm.DB) (err error)

type WsErr

type WsErr struct {
	Event string `json:"event"`
	Msg   string `json:"msg"`
}

func NewWsErr

func NewWsErr(msg string) WsErr

func (WsErr) Error

func (w WsErr) Error() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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