db

package
v1.29.0 Latest Latest
Warning

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

Go to latest
Published: Oct 2, 2024 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package db provides the database interfaces and types for the RFQ API.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type APIDB

type APIDB interface {
	APIDBReader
	APIDBWriter
}

APIDB is the interface for the database service.

type APIDBReader

type APIDBReader interface {
	// GetQuotesByDestChainAndToken gets quotes from the database by destination chain and token.
	GetQuotesByDestChainAndToken(ctx context.Context, destChainID uint64, destTokenAddr string) ([]*Quote, error)
	// GetQuotesByOriginAndDestination gets quotes from the database by origin and destination.
	GetQuotesByOriginAndDestination(ctx context.Context, originChainID uint64, originTokenAddr string, destChainID uint64, destTokenAddr string) ([]*Quote, error)
	// GetQuotesByRelayerAddress gets quotes from the database by relayer address.
	GetQuotesByRelayerAddress(ctx context.Context, relayerAddress string) ([]*Quote, error)
	// GetActiveQuoteRequests gets active quote requests from the database.
	GetActiveQuoteRequests(ctx context.Context, matchStatuses ...ActiveQuoteRequestStatus) ([]*ActiveQuoteRequest, error)
	// GetAllQuotes retrieves all quotes from the database.
	GetAllQuotes(ctx context.Context) ([]*Quote, error)
}

APIDBReader is the interface for reading from the database.

type APIDBWriter

type APIDBWriter interface {
	// UpsertQuote upserts a quote in the database.
	UpsertQuote(ctx context.Context, quote *Quote) error
	// UpsertQuotes upserts multiple quotes in the database.
	UpsertQuotes(ctx context.Context, quotes []*Quote) error
	// InsertActiveQuoteRequest inserts an active quote request into the database.
	InsertActiveQuoteRequest(ctx context.Context, req *model.PutRFQRequest, requestID string) error
	// UpdateActiveQuoteRequestStatus updates the status of an active quote request in the database.
	UpdateActiveQuoteRequestStatus(ctx context.Context, requestID string, quoteID *string, status ActiveQuoteRequestStatus) error
	// InsertActiveQuoteResponse inserts an active quote response into the database.
	InsertActiveQuoteResponse(ctx context.Context, resp *model.WsRFQResponse, relayerAddr string, status ActiveQuoteResponseStatus) error
	// UpdateActiveQuoteResponseStatus updates the status of an active quote response in the database.
	UpdateActiveQuoteResponseStatus(ctx context.Context, quoteID string, status ActiveQuoteResponseStatus) error
}

APIDBWriter is the interface for writing to the database.

type ActiveQuoteRequest added in v1.29.0

type ActiveQuoteRequest struct {
	RequestID        string                   `gorm:"column:request_id;primaryKey"`
	IntegratorID     string                   `gorm:"column:integrator_id"`
	UserAddress      string                   `gorm:"column:user_address"`
	OriginChainID    uint64                   `gorm:"column:origin_chain_id"`
	OriginTokenAddr  string                   `gorm:"column:origin_token"`
	DestChainID      uint64                   `gorm:"column:dest_chain_id"`
	DestTokenAddr    string                   `gorm:"column:dest_token"`
	OriginAmount     decimal.Decimal          `gorm:"column:origin_amount"`
	ExpirationWindow time.Duration            `gorm:"column:expiration_window"`
	CreatedAt        time.Time                `gorm:"column:created_at"`
	Status           ActiveQuoteRequestStatus `gorm:"column:status"`
	ClosedAt         *time.Time               `gorm:"column:closed_at"`
	ClosedQuoteID    *string                  `gorm:"column:closed_quote_id"`
}

ActiveQuoteRequest is the database model for an active quote request.

func FromUserRequest added in v1.29.0

func FromUserRequest(req *model.PutRFQRequest, requestID string) (*ActiveQuoteRequest, error)

FromUserRequest converts a model.PutRFQRequest to an ActiveQuoteRequest.

type ActiveQuoteRequestStatus added in v1.29.0

type ActiveQuoteRequestStatus uint8

ActiveQuoteRequestStatus is the status of a quote request in the db. This is the primary mechanism for moving data through the app.

TODO: consider making this an interface and exporting that.

EXTREMELY IMPORTANT: DO NOT ADD NEW VALUES TO THIS ENUM UNLESS THEY ARE AT THE END.

const (
	// Received means the quote request has been received by the server.
	Received ActiveQuoteRequestStatus = iota + 1
	// Pending means the quote request is pending awaiting relayer responses.
	Pending
	// Expired means the quote request has expired without any valid responses.
	Expired
	// Closed means the quote request has been fulfilled.
	Closed
)

func (ActiveQuoteRequestStatus) GormDataType added in v1.29.0

func (q ActiveQuoteRequestStatus) GormDataType() string

GormDataType implements the gorm common interface for enums.

func (ActiveQuoteRequestStatus) Int added in v1.29.0

Int returns the int value of the quote request status.

func (*ActiveQuoteRequestStatus) Scan added in v1.29.0

func (q *ActiveQuoteRequestStatus) Scan(src any) error

Scan implements the gorm common interface for enums.

func (ActiveQuoteRequestStatus) String added in v1.29.0

func (i ActiveQuoteRequestStatus) String() string

func (ActiveQuoteRequestStatus) Value added in v1.29.0

Value implements the gorm common interface for enums.

type ActiveQuoteResponse added in v1.29.0

type ActiveQuoteResponse struct {
	RequestID   string                    `gorm:"column:request_id"`
	QuoteID     string                    `gorm:"column:quote_id;primaryKey"`
	DestAmount  decimal.Decimal           `gorm:"column:dest_amount"`
	RelayerAddr string                    `gorm:"column:relayer_address"`
	UpdatedAt   time.Time                 `gorm:"column:updated_at"`
	Status      ActiveQuoteResponseStatus `gorm:"column:status"`
}

ActiveQuoteResponse is the database model for an active quote response.

func FromRelayerResponse added in v1.29.0

func FromRelayerResponse(resp *model.WsRFQResponse, relayerAddr string, status ActiveQuoteResponseStatus) (*ActiveQuoteResponse, error)

FromRelayerResponse converts a model.WsRFQResponse to an ActiveQuoteResponse.

type ActiveQuoteResponseStatus added in v1.29.0

type ActiveQuoteResponseStatus uint8

ActiveQuoteResponseStatus is the status of a quote request in the db. This is the primary mechanism for moving data through the app.

TODO: consider making this an interface and exporting that.

EXTREMELY IMPORTANT: DO NOT ADD NEW VALUES TO THIS ENUM UNLESS THEY ARE AT THE END.

const (
	// Considered means the quote request was considered by the relayer, but was not ultimately the fulfilling response.
	Considered ActiveQuoteResponseStatus = iota + 1
	// Returned means the quote request was returned by the relayer to the user.
	Returned
	// PastExpiration means the quote request was received, but past the expiration window.
	PastExpiration
	// Malformed means that the quote request was malformed.
	Malformed
	// Duplicate means that the quote request was a duplicate.
	Duplicate
)

func (ActiveQuoteResponseStatus) GormDataType added in v1.29.0

func (q ActiveQuoteResponseStatus) GormDataType() string

GormDataType implements the gorm common interface for enums.

func (ActiveQuoteResponseStatus) Int added in v1.29.0

Int returns the int value of the quote request status.

func (*ActiveQuoteResponseStatus) Scan added in v1.29.0

func (q *ActiveQuoteResponseStatus) Scan(src any) error

Scan implements the gorm common interface for enums.

func (ActiveQuoteResponseStatus) String added in v1.29.0

func (i ActiveQuoteResponseStatus) String() string

func (ActiveQuoteResponseStatus) Value added in v1.29.0

Value implements the gorm common interface for enums.

type Quote

type Quote struct {
	// OriginChainID is the chain which the relayer is willing to relay from
	OriginChainID uint64 `gorm:"column:origin_chain_id;index;primaryKey"`
	// OriginTokenAddr is the token address for which the relayer willing to relay from
	OriginTokenAddr string `gorm:"column:origin_token;index;primaryKey"`
	// DestChainID is the chain which the relayer is willing to relay to
	DestChainID uint64 `gorm:"column:dest_chain_id;index;primaryKey"`
	// DestToken is the token address for which the relayer willing to relay to
	DestTokenAddr string `gorm:"column:dest_token;index;primaryKey"`
	// DestAmount is the max amount of liquidity which exists for a given destination token, provided in the destination token decimals
	DestAmount decimal.Decimal `gorm:"column:dest_amount"`
	// MaxOriginAmount is the maximum amount of origin tokens bridgeable
	MaxOriginAmount decimal.Decimal `gorm:"column:max_origin_amount"`
	// FixedFee is the fixed fee for the quote, provided in the destination token terms
	FixedFee decimal.Decimal `gorm:"column:fixed_fee"`
	// Address of the relayer providing the quote
	RelayerAddr string `gorm:"column:relayer_address;primaryKey"`
	// OriginFastBridgeAddress is the address of the fast bridge contract on the origin chain
	OriginFastBridgeAddress string `gorm:"column:origin_fast_bridge_address"`
	// DestFastBridgeAddress is the address of the fast bridge contract on the destination chain
	DestFastBridgeAddress string `gorm:"column:dest_fast_bridge_address"`
	// UpdatedAt is the time that the quote was last upserted
	UpdatedAt time.Time
}

Quote is the database model for a quote.

Directories

Path Synopsis
sql
Package sql provides a common interface for starting sql-lite databases
Package sql provides a common interface for starting sql-lite databases
base
Package base contains the base sql implementation
Package base contains the base sql implementation
mysql
Package mysql contains a mysql db
Package mysql contains a mysql db
sqlite
Package sqlite implements the sqlite package
Package sqlite implements the sqlite package

Jump to

Keyboard shortcuts

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