types

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2025 License: Apache-2.0 Imports: 7 Imported by: 3

Documentation

Index

Constants

View Source
const (
	MaxCPFieldLength = 256
)

Variables

View Source
var (
	ErrInvalidLengthCurrencyPair        = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflowCurrencyPair          = fmt.Errorf("proto: integer overflow")
	ErrUnexpectedEndOfGroupCurrencyPair = fmt.Errorf("proto: unexpected end of group")
)

Functions

func CurrencyPairString

func CurrencyPairString(base, quote string) string

CurrencyPairString constructs and returns the string representation of a currency pair.

func IsLegacyAssetString

func IsLegacyAssetString(asset string) bool

IsLegacyAssetString returns true if the asset string is of the following format: - contains no instances of fieldSeparator.

func SplitDefiAssetString

func SplitDefiAssetString(defiString string) (token, address, chainID string, err error)

SplitDefiAssetString splits a defi asset by the fieldSeparator and checks that it is the proper length. returns the split string as (token, address, chainID).

func ValidateDefiAssetString

func ValidateDefiAssetString(asset string) error

ValidateDefiAssetString checks that the asset string is formatted properly as a defi asset (tokenName,tokenAddress,chainID) - check that the length of fields separated by fieldSeparator is expectedSplitLength - check that the first split (tokenName) is formatted properly as a LegacyAssetString.

NOTE: this function assumes that coreValidate() has already been run.

func ValidateLegacyAssetString

func ValidateLegacyAssetString(asset string) error

ValidateLegacyAssetString checks if the asset string is formatted correctly, i.e. - asset string is fully uppercase - asset string does not contain the `fieldSeparator`

NOTE: this function assumes that coreValidate() has already been run.

Types

type CurrencyPair

type CurrencyPair struct {
	Base  string `protobuf:"bytes,1,opt,name=Base,proto3" json:"Base,omitempty"`
	Quote string `protobuf:"bytes,2,opt,name=Quote,proto3" json:"Quote,omitempty"`
}

CurrencyPair is the standard representation of a pair of assets, where one (Base) is priced in terms of the other (Quote)

func CurrencyPairFromString

func CurrencyPairFromString(s string) (CurrencyPair, error)

CurrencyPairFromString creates a currency pair from a string. Non-capitalized inputs are sanitized and the resulting currency pair is validated.

func NewCurrencyPair

func NewCurrencyPair(base, quote string) CurrencyPair

NewCurrencyPair returns a new CurrencyPair with the given base and quote strings.

func (*CurrencyPair) Descriptor

func (*CurrencyPair) Descriptor() ([]byte, []int)

func (*CurrencyPair) Equal

func (cp *CurrencyPair) Equal(other CurrencyPair) bool

Equal returns true iff the CurrencyPair is equal to the given CurrencyPair.

func (*CurrencyPair) GetBase

func (m *CurrencyPair) GetBase() string

func (*CurrencyPair) GetQuote

func (m *CurrencyPair) GetQuote() string

func (*CurrencyPair) Invert

func (cp *CurrencyPair) Invert() CurrencyPair

Invert returns an inverted version of cp (where the Base and Quote are swapped).

func (*CurrencyPair) LegacyDecimals

func (cp *CurrencyPair) LegacyDecimals() int

LegacyDecimals returns the number of decimals that the quote will be reported to. If the quote is Ethereum, then the number of decimals is 18. Otherwise, the decimals will be reported as 8.

func (*CurrencyPair) LegacyValidateBasic

func (cp *CurrencyPair) LegacyValidateBasic() error

LegacyValidateBasic checks that the Base / Quote strings in the CurrencyPair are formatted correctly, i.e. Base + Quote are non-empty, and are in upper-case.

func (*CurrencyPair) Marshal

func (m *CurrencyPair) Marshal() (dAtA []byte, err error)

func (*CurrencyPair) MarshalTo

func (m *CurrencyPair) MarshalTo(dAtA []byte) (int, error)

func (*CurrencyPair) MarshalToSizedBuffer

func (m *CurrencyPair) MarshalToSizedBuffer(dAtA []byte) (int, error)

func (*CurrencyPair) ProtoMessage

func (*CurrencyPair) ProtoMessage()

func (*CurrencyPair) Reset

func (m *CurrencyPair) Reset()

func (*CurrencyPair) Size

func (m *CurrencyPair) Size() (n int)

func (CurrencyPair) String

func (cp CurrencyPair) String() string

String returns a string representation of the CurrencyPair, in the following form "ETH/BTC".

func (*CurrencyPair) Unmarshal

func (m *CurrencyPair) Unmarshal(dAtA []byte) error

func (*CurrencyPair) ValidateBasic

func (cp *CurrencyPair) ValidateBasic() error

ValidateBasic checks that the Base / Quote strings in the CurrencyPair are formatted correctly, i.e. For base and quote asset: check if the asset is formatted in the legacy validation form:

  • if so, check that fields are not empty and all upper case
  • else, check that the format is in the following form: tokenName,tokenAddress,chainID

func (*CurrencyPair) XXX_DiscardUnknown

func (m *CurrencyPair) XXX_DiscardUnknown()

func (*CurrencyPair) XXX_Marshal

func (m *CurrencyPair) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*CurrencyPair) XXX_Merge

func (m *CurrencyPair) XXX_Merge(src proto.Message)

func (*CurrencyPair) XXX_Size

func (m *CurrencyPair) XXX_Size() int

func (*CurrencyPair) XXX_Unmarshal

func (m *CurrencyPair) XXX_Unmarshal(b []byte) error

Jump to

Keyboard shortcuts

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