types

package
v0.0.0-...-cc24d94 Latest Latest
Warning

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

Go to latest
Published: Dec 25, 2023 License: AGPL-3.0 Imports: 32 Imported by: 0

Documentation

Overview

Package types is a reverse proxy.

It translates gRPC into RESTful JSON APIs.

Index

Constants

View Source
const (
	EventTypeSettledFunding = "settled_funding"

	AttributeKeySubaccount       = "subaccount"
	AttributeKeySubaccountNumber = "subaccount_number"
	AttributeKeyPerpetualId      = "perpetual_id"
	AttributeKeyFundingPaid      = "funding_paid_quote_quantums"
)

Subaccounts module event types.

View Source
const (
	// ModuleName defines the module name
	ModuleName = "subaccounts"

	// StoreKey defines the primary module store key
	StoreKey = ModuleName
)

Module name and store keys

View Source
const (
	// SubaccountKeyPrefix is the prefix to retrieve all Subaccounts
	SubaccountKeyPrefix = "SA:"
	// NegativeTncSubaccountSeenAtBlockKey is the store key that stores the last
	// block a negative TNC subaccount was seen in state.
	NegativeTncSubaccountSeenAtBlockKey = "NegSA:"
)

State

View Source
const (
	AssetProductType     = "asset"
	PerpetualProductType = "perpetual"
	UnknownProductTYpe   = "unknown"
)
View Source
const (
	MaxSubaccountIdNumber = 127 // 0 ... 127 are valid numbers.
)

Variables

View Source
var (
	ErrInvalidLengthAssetPosition        = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflowAssetPosition          = fmt.Errorf("proto: integer overflow")
	ErrUnexpectedEndOfGroupAssetPosition = fmt.Errorf("proto: unexpected end of group")
)
View Source
var (
	// 0 - 99: generic.
	ErrIntegerOverflow = errorsmod.Register(ModuleName, 0, "integer overflow")

	// 100 - 199: update related.
	ErrNonUniqueUpdatesPosition = errorsmod.Register(
		ModuleName, 100, "multiple updates were specified for the same position id")
	ErrNonUniqueUpdatesSubaccount = errorsmod.Register(
		ModuleName, 101, "multiple updates were specified for the same subaccountId")
	ErrFailedToUpdateSubaccounts   = errorsmod.Register(ModuleName, 102, "failed to apply subaccount updates")
	ErrProductPositionNotUpdatable = errorsmod.Register(ModuleName, 103, "product position is not updatable")

	// 200 - 299: subaccount id related.
	ErrInvalidSubaccountIdNumber = errorsmod.Register(ModuleName, 200, "subaccount id number cannot exceed 127")
	ErrInvalidSubaccountIdOwner  = errorsmod.Register(ModuleName, 201, "subaccount id owner is an invalid address")
	ErrDuplicateSubaccountIds    = errorsmod.Register(ModuleName, 202, "duplicate subaccount id found in genesis")

	// 300 - 399: asset position related.
	ErrAssetPositionsOutOfOrder       = errorsmod.Register(ModuleName, 300, "asset positions are out of order")
	ErrAssetPositionZeroQuantum       = errorsmod.Register(ModuleName, 301, "asset position's quantum cannot be zero")
	ErrAssetPositionNotSupported      = errorsmod.Register(ModuleName, 302, "asset position is not supported")
	ErrMultAssetPositionsNotSupported = errorsmod.Register(
		ModuleName, 303, "having multiple asset positions is not supported")

	// 400 - 499: perpetual position related.
	ErrPerpPositionsOutOfOrder = errorsmod.Register(ModuleName, 400, "perpetual positions are out of order")
	ErrPerpPositionZeroQuantum = errorsmod.Register(ModuleName, 401, "perpetual position's quantum cannot be zero")

	// 500 - 599: transfer related.
	ErrAssetTransferQuantumsNotPositive = errorsmod.Register(
		ModuleName, 500, "asset transfer quantums is not positive")
	ErrAssetTransferThroughBankNotImplemented = errorsmod.Register(
		ModuleName, 501, "asset transfer (other than USDC) through the bank module is not implemented")
)

x/subaccounts module sentinel errors

View Source
var (
	ErrInvalidLengthGenesis        = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflowGenesis          = fmt.Errorf("proto: integer overflow")
	ErrUnexpectedEndOfGroupGenesis = fmt.Errorf("proto: unexpected end of group")
)
View Source
var (
	ErrInvalidLengthPerpetualPosition        = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflowPerpetualPosition          = fmt.Errorf("proto: integer overflow")
	ErrUnexpectedEndOfGroupPerpetualPosition = fmt.Errorf("proto: unexpected end of group")
)
View Source
var (
	ErrInvalidLengthQuery        = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflowQuery          = fmt.Errorf("proto: integer overflow")
	ErrUnexpectedEndOfGroupQuery = fmt.Errorf("proto: unexpected end of group")
)
View Source
var (
	ErrInvalidLengthSubaccount        = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflowSubaccount          = fmt.Errorf("proto: integer overflow")
	ErrUnexpectedEndOfGroupSubaccount = fmt.Errorf("proto: unexpected end of group")
)

Functions

func GetErrorFromUpdateResults

func GetErrorFromUpdateResults(
	success bool,
	successPerUpdate []UpdateResult,
	updates []Update,
) error

GetErrorFromUpdateResults generates a helpful error when UpdateSubaccounts or CanUpdateSubaccounts returns one or more failed updates.

func NewCreateSettledFundingEvent

func NewCreateSettledFundingEvent(
	subaccount SubaccountId,
	perpetualId uint32,
	fundingPaid *big.Int,
) sdk.Event

NewCreateSettledFundingEvent constructs a new funding sdk.Event. Note that `fundingPaid` is positive if the subaccount paid funding, negative if the subaccount received funding.

func RegisterCodec

func RegisterCodec(cdc *codec.LegacyAmino)

func RegisterInterfaces

func RegisterInterfaces(registry cdctypes.InterfaceRegistry)

func RegisterQueryHandler

func RegisterQueryHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error

RegisterQueryHandler registers the http handlers for service Query to "mux". The handlers forward requests to the grpc endpoint over "conn".

func RegisterQueryHandlerClient

func RegisterQueryHandlerClient(ctx context.Context, mux *runtime.ServeMux, client QueryClient) error

RegisterQueryHandlerClient registers the http handlers for service Query to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "QueryClient". Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "QueryClient" doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in "QueryClient" to call the correct interceptors.

func RegisterQueryHandlerFromEndpoint

func RegisterQueryHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error)

RegisterQueryHandlerFromEndpoint is same as RegisterQueryHandler but automatically dials to "endpoint" and closes the connection when "ctx" gets done.

func RegisterQueryHandlerServer

func RegisterQueryHandlerServer(ctx context.Context, mux *runtime.ServeMux, server QueryServer) error

RegisterQueryHandlerServer registers the http handlers for service Query to "mux". UnaryRPC :call QueryServer directly. StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterQueryHandlerFromEndpoint instead.

func RegisterQueryServer

func RegisterQueryServer(s grpc1.Server, srv QueryServer)

Types

type AccountKeeper

type AccountKeeper interface {
	GetAccount(ctx sdk.Context, addr sdk.AccAddress) authtypes.AccountI
}

AccountKeeper defines the expected account keeper used for simulations (noalias)

type AssetPosition

type AssetPosition struct {
	// The `Id` of the `Asset`.
	AssetId uint32 `protobuf:"varint,1,opt,name=asset_id,json=assetId,proto3" json:"asset_id,omitempty"`
	// The absolute size of the position in base quantums.
	Quantums github_com_jinxprotocol_v4_chain_protocol_dtypes.SerializableInt `` /* 135-byte string literal not displayed */
	// The `Index` (either `LongIndex` or `ShortIndex`) of the `Asset` the last
	// time this position was settled
	// TODO(DEC-582): pending margin trading being added.
	Index uint64 `protobuf:"varint,3,opt,name=index,proto3" json:"index,omitempty"`
}

AssetPositions define an account’s positions of an `Asset`. Therefore they hold any information needed to trade on Spot and Margin.

func (*AssetPosition) Descriptor

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

func (*AssetPosition) GetAssetId

func (m *AssetPosition) GetAssetId() uint32

func (*AssetPosition) GetBigQuantums

func (m *AssetPosition) GetBigQuantums() *big.Int

Get the asset position quantum size in big.Int. Panics if the size is zero.

func (*AssetPosition) GetId

func (m *AssetPosition) GetId() uint32

func (*AssetPosition) GetIndex

func (m *AssetPosition) GetIndex() uint64

func (*AssetPosition) GetIsLong

func (m *AssetPosition) GetIsLong() bool

func (*AssetPosition) GetProductType

func (m *AssetPosition) GetProductType() string

func (*AssetPosition) Marshal

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

func (*AssetPosition) MarshalTo

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

func (*AssetPosition) MarshalToSizedBuffer

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

func (*AssetPosition) ProtoMessage

func (*AssetPosition) ProtoMessage()

func (*AssetPosition) Reset

func (m *AssetPosition) Reset()

func (*AssetPosition) Size

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

func (*AssetPosition) String

func (m *AssetPosition) String() string

func (*AssetPosition) Unmarshal

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

func (*AssetPosition) XXX_DiscardUnknown

func (m *AssetPosition) XXX_DiscardUnknown()

func (*AssetPosition) XXX_Marshal

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

func (*AssetPosition) XXX_Merge

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

func (*AssetPosition) XXX_Size

func (m *AssetPosition) XXX_Size() int

func (*AssetPosition) XXX_Unmarshal

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

type AssetUpdate

type AssetUpdate struct {
	// The `Id` of the `Asset` for which the `AssetPosition` is for.
	AssetId uint32
	// The signed change in the Size of the `AssetPosition`.
	BigQuantumsDelta *big.Int
}

func (AssetUpdate) GetBigQuantums

func (au AssetUpdate) GetBigQuantums() *big.Int

func (AssetUpdate) GetId

func (au AssetUpdate) GetId() uint32

func (AssetUpdate) GetIsLong

func (au AssetUpdate) GetIsLong() bool

func (AssetUpdate) GetProductType

func (au AssetUpdate) GetProductType() string

type AssetsKeeper

type AssetsKeeper interface {
	ProductKeeper
	ConvertAssetToCoin(
		ctx sdk.Context,
		assetId uint32,
		quantums *big.Int,
	) (
		convertedQuantums *big.Int,
		coin sdk.Coin,
		err error,
	)
}

type BankKeeper

type BankKeeper interface {
	SpendableCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.Coins
	SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress, recipientModule string, amt sdk.Coins) error
	SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string, recipientAddr sdk.AccAddress, amt sdk.Coins) error
	SendCoinsFromModuleToModule(ctx sdk.Context, senderModule, recipientModule string, amt sdk.Coins) error
}

BankKeeper defines the expected interface needed to retrieve account balances.

type BaseQuantums

type BaseQuantums uint64

BaseQuantums is used to represent an amount in base quantums.

func (BaseQuantums) ToBigInt

func (bq BaseQuantums) ToBigInt() *big.Int

Get the BaseQuantum value in *big.Int.

func (BaseQuantums) ToUint64

func (bq BaseQuantums) ToUint64() uint64

Get the BaseQuantum value in uint64.

type GenesisState

type GenesisState struct {
	Subaccounts []Subaccount `protobuf:"bytes,1,rep,name=subaccounts,proto3" json:"subaccounts"`
}

GenesisState defines the subaccounts module's genesis state.

func DefaultGenesis

func DefaultGenesis() *GenesisState

DefaultGenesis returns the default Capability genesis state

func (*GenesisState) Descriptor

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

func (*GenesisState) GetSubaccounts

func (m *GenesisState) GetSubaccounts() []Subaccount

func (*GenesisState) Marshal

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

func (*GenesisState) MarshalTo

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

func (*GenesisState) MarshalToSizedBuffer

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

func (*GenesisState) ProtoMessage

func (*GenesisState) ProtoMessage()

func (*GenesisState) Reset

func (m *GenesisState) Reset()

func (*GenesisState) Size

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

func (*GenesisState) String

func (m *GenesisState) String() string

func (*GenesisState) Unmarshal

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

func (GenesisState) Validate

func (gs GenesisState) Validate() error

Validate performs basic genesis state validation returning an error upon any failure.

func (*GenesisState) XXX_DiscardUnknown

func (m *GenesisState) XXX_DiscardUnknown()

func (*GenesisState) XXX_Marshal

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

func (*GenesisState) XXX_Merge

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

func (*GenesisState) XXX_Size

func (m *GenesisState) XXX_Size() int

func (*GenesisState) XXX_Unmarshal

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

type PerpetualPosition

type PerpetualPosition struct {
	// The `Id` of the `Perpetual`.
	PerpetualId uint32 `protobuf:"varint,1,opt,name=perpetual_id,json=perpetualId,proto3" json:"perpetual_id,omitempty"`
	// The size of the position in base quantums.
	Quantums github_com_jinxprotocol_v4_chain_protocol_dtypes.SerializableInt `` /* 135-byte string literal not displayed */
	// The funding_index of the `Perpetual` the last time this position was
	// settled.
	FundingIndex github_com_jinxprotocol_v4_chain_protocol_dtypes.SerializableInt `` /* 163-byte string literal not displayed */
}

PerpetualPositions are an account’s positions of a `Perpetual`. Therefore they hold any information needed to trade perpetuals.

func (*PerpetualPosition) Descriptor

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

func (*PerpetualPosition) GetBigQuantums

func (m *PerpetualPosition) GetBigQuantums() *big.Int

Get the perpetual position quantum size in big.Int. Panics if the size is zero.

func (*PerpetualPosition) GetId

func (m *PerpetualPosition) GetId() uint32

func (*PerpetualPosition) GetIsLong

func (m *PerpetualPosition) GetIsLong() bool

func (*PerpetualPosition) GetPerpetualId

func (m *PerpetualPosition) GetPerpetualId() uint32

func (*PerpetualPosition) GetProductType

func (m *PerpetualPosition) GetProductType() string

func (*PerpetualPosition) Marshal

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

func (*PerpetualPosition) MarshalTo

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

func (*PerpetualPosition) MarshalToSizedBuffer

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

func (*PerpetualPosition) ProtoMessage

func (*PerpetualPosition) ProtoMessage()

func (*PerpetualPosition) Reset

func (m *PerpetualPosition) Reset()

func (*PerpetualPosition) SetQuantums

func (m *PerpetualPosition) SetQuantums(sizeQuantums int64)

func (*PerpetualPosition) Size

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

func (*PerpetualPosition) String

func (m *PerpetualPosition) String() string

func (*PerpetualPosition) Unmarshal

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

func (*PerpetualPosition) XXX_DiscardUnknown

func (m *PerpetualPosition) XXX_DiscardUnknown()

func (*PerpetualPosition) XXX_Marshal

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

func (*PerpetualPosition) XXX_Merge

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

func (*PerpetualPosition) XXX_Size

func (m *PerpetualPosition) XXX_Size() int

func (*PerpetualPosition) XXX_Unmarshal

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

type PerpetualUpdate

type PerpetualUpdate struct {
	// The `Id` of the `Perpetual` for which the `PerpetualPosition` is for.
	PerpetualId uint32
	// The signed change in the `Quantums` of the `PerpetualPosition`
	// represented in base quantums.
	BigQuantumsDelta *big.Int
}

func (PerpetualUpdate) GetBigQuantums

func (pu PerpetualUpdate) GetBigQuantums() *big.Int

func (PerpetualUpdate) GetId

func (pu PerpetualUpdate) GetId() uint32

func (PerpetualUpdate) GetIsLong

func (pu PerpetualUpdate) GetIsLong() bool

func (PerpetualUpdate) GetProductType

func (pu PerpetualUpdate) GetProductType() string

type PerpetualsKeeper

type PerpetualsKeeper interface {
	ProductKeeper
	GetSettlementPpm(
		ctx sdk.Context,
		perpetualId uint32,
		quantums *big.Int,
		index *big.Int,
	) (
		bigNetSettlement *big.Int,
		newFundingIndex *big.Int,
		err error,
	)
	GetPerpetual(
		ctx sdk.Context,
		perpetualId uint32,
	) (
		perpetual perptypes.Perpetual,
		err error,
	)
	GetAllPerpetuals(ctx sdk.Context) []perptypes.Perpetual
}

type PositionSize

type PositionSize interface {
	// Returns true if and only if the position size is positive.
	GetIsLong() bool
	// Returns the signed position size in big.Int.
	GetBigQuantums() *big.Int
	GetId() uint32
	GetProductType() string
}

PositionSize is an interface for expressing the size of a position

type PositionUpdate

type PositionUpdate struct {
	Id          uint32
	BigQuantums *big.Int
}

func NewPositionUpdate

func NewPositionUpdate(id uint32) PositionUpdate

func (PositionUpdate) GetBigQuantums

func (pu PositionUpdate) GetBigQuantums() *big.Int

func (PositionUpdate) GetId

func (pu PositionUpdate) GetId() uint32

func (PositionUpdate) GetIsLong

func (pu PositionUpdate) GetIsLong() bool

func (PositionUpdate) GetProductType

func (pu PositionUpdate) GetProductType() string

func (PositionUpdate) SetBigQuantums

func (pu PositionUpdate) SetBigQuantums(bigQuantums *big.Int)

type ProductKeeper

type ProductKeeper interface {
	GetNetCollateral(
		ctx sdk.Context,
		id uint32,
		bigQuantums *big.Int,
	) (
		bigNetCollateralQuoteQuantums *big.Int,
		err error,
	)
	GetMarginRequirements(
		ctx sdk.Context,
		id uint32,
		bigQuantums *big.Int,
	) (
		bigInitialMarginQuoteQuantums *big.Int,
		bigMaintenanceMarginQuoteQuantums *big.Int,
		err error,
	)
	IsPositionUpdatable(
		ctx sdk.Context,
		id uint32,
	) (
		updatable bool,
		err error,
	)
}

ProductKeeper represents a generic interface for a keeper of a product.

type QueryAllSubaccountRequest

type QueryAllSubaccountRequest struct {
	Pagination *query.PageRequest `protobuf:"bytes,1,opt,name=pagination,proto3" json:"pagination,omitempty"`
}

QueryAllSubaccountRequest is request type for the Query RPC method.

func (*QueryAllSubaccountRequest) Descriptor

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

func (*QueryAllSubaccountRequest) GetPagination

func (m *QueryAllSubaccountRequest) GetPagination() *query.PageRequest

func (*QueryAllSubaccountRequest) Marshal

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

func (*QueryAllSubaccountRequest) MarshalTo

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

func (*QueryAllSubaccountRequest) MarshalToSizedBuffer

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

func (*QueryAllSubaccountRequest) ProtoMessage

func (*QueryAllSubaccountRequest) ProtoMessage()

func (*QueryAllSubaccountRequest) Reset

func (m *QueryAllSubaccountRequest) Reset()

func (*QueryAllSubaccountRequest) Size

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

func (*QueryAllSubaccountRequest) String

func (m *QueryAllSubaccountRequest) String() string

func (*QueryAllSubaccountRequest) Unmarshal

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

func (*QueryAllSubaccountRequest) XXX_DiscardUnknown

func (m *QueryAllSubaccountRequest) XXX_DiscardUnknown()

func (*QueryAllSubaccountRequest) XXX_Marshal

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

func (*QueryAllSubaccountRequest) XXX_Merge

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

func (*QueryAllSubaccountRequest) XXX_Size

func (m *QueryAllSubaccountRequest) XXX_Size() int

func (*QueryAllSubaccountRequest) XXX_Unmarshal

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

type QueryClient

type QueryClient interface {
	// Queries a Subaccount by id
	Subaccount(ctx context.Context, in *QueryGetSubaccountRequest, opts ...grpc.CallOption) (*QuerySubaccountResponse, error)
	// Queries a list of Subaccount items.
	SubaccountAll(ctx context.Context, in *QueryAllSubaccountRequest, opts ...grpc.CallOption) (*QuerySubaccountAllResponse, error)
}

QueryClient is the client API for Query service.

For semantics around ctx use and closing/ending streaming RPCs, please refer to https://godoc.org/google.golang.org/grpc#ClientConn.NewStream.

func NewQueryClient

func NewQueryClient(cc grpc1.ClientConn) QueryClient

type QueryGetSubaccountRequest

type QueryGetSubaccountRequest struct {
	Owner  string `protobuf:"bytes,1,opt,name=owner,proto3" json:"owner,omitempty"`
	Number uint32 `protobuf:"varint,2,opt,name=number,proto3" json:"number,omitempty"`
}

QueryGetSubaccountRequest is request type for the Query RPC method.

func (*QueryGetSubaccountRequest) Descriptor

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

func (*QueryGetSubaccountRequest) GetNumber

func (m *QueryGetSubaccountRequest) GetNumber() uint32

func (*QueryGetSubaccountRequest) GetOwner

func (m *QueryGetSubaccountRequest) GetOwner() string

func (*QueryGetSubaccountRequest) Marshal

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

func (*QueryGetSubaccountRequest) MarshalTo

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

func (*QueryGetSubaccountRequest) MarshalToSizedBuffer

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

func (*QueryGetSubaccountRequest) ProtoMessage

func (*QueryGetSubaccountRequest) ProtoMessage()

func (*QueryGetSubaccountRequest) Reset

func (m *QueryGetSubaccountRequest) Reset()

func (*QueryGetSubaccountRequest) Size

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

func (*QueryGetSubaccountRequest) String

func (m *QueryGetSubaccountRequest) String() string

func (*QueryGetSubaccountRequest) Unmarshal

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

func (*QueryGetSubaccountRequest) XXX_DiscardUnknown

func (m *QueryGetSubaccountRequest) XXX_DiscardUnknown()

func (*QueryGetSubaccountRequest) XXX_Marshal

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

func (*QueryGetSubaccountRequest) XXX_Merge

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

func (*QueryGetSubaccountRequest) XXX_Size

func (m *QueryGetSubaccountRequest) XXX_Size() int

func (*QueryGetSubaccountRequest) XXX_Unmarshal

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

type QueryServer

type QueryServer interface {
	// Queries a Subaccount by id
	Subaccount(context.Context, *QueryGetSubaccountRequest) (*QuerySubaccountResponse, error)
	// Queries a list of Subaccount items.
	SubaccountAll(context.Context, *QueryAllSubaccountRequest) (*QuerySubaccountAllResponse, error)
}

QueryServer is the server API for Query service.

type QuerySubaccountAllResponse

type QuerySubaccountAllResponse struct {
	Subaccount []Subaccount        `protobuf:"bytes,1,rep,name=subaccount,proto3" json:"subaccount"`
	Pagination *query.PageResponse `protobuf:"bytes,2,opt,name=pagination,proto3" json:"pagination,omitempty"`
}

QuerySubaccountAllResponse is response type for the Query RPC method.

func (*QuerySubaccountAllResponse) Descriptor

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

func (*QuerySubaccountAllResponse) GetPagination

func (m *QuerySubaccountAllResponse) GetPagination() *query.PageResponse

func (*QuerySubaccountAllResponse) GetSubaccount

func (m *QuerySubaccountAllResponse) GetSubaccount() []Subaccount

func (*QuerySubaccountAllResponse) Marshal

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

func (*QuerySubaccountAllResponse) MarshalTo

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

func (*QuerySubaccountAllResponse) MarshalToSizedBuffer

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

func (*QuerySubaccountAllResponse) ProtoMessage

func (*QuerySubaccountAllResponse) ProtoMessage()

func (*QuerySubaccountAllResponse) Reset

func (m *QuerySubaccountAllResponse) Reset()

func (*QuerySubaccountAllResponse) Size

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

func (*QuerySubaccountAllResponse) String

func (m *QuerySubaccountAllResponse) String() string

func (*QuerySubaccountAllResponse) Unmarshal

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

func (*QuerySubaccountAllResponse) XXX_DiscardUnknown

func (m *QuerySubaccountAllResponse) XXX_DiscardUnknown()

func (*QuerySubaccountAllResponse) XXX_Marshal

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

func (*QuerySubaccountAllResponse) XXX_Merge

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

func (*QuerySubaccountAllResponse) XXX_Size

func (m *QuerySubaccountAllResponse) XXX_Size() int

func (*QuerySubaccountAllResponse) XXX_Unmarshal

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

type QuerySubaccountResponse

type QuerySubaccountResponse struct {
	Subaccount Subaccount `protobuf:"bytes,1,opt,name=subaccount,proto3" json:"subaccount"`
}

QuerySubaccountResponse is response type for the Query RPC method.

func (*QuerySubaccountResponse) Descriptor

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

func (*QuerySubaccountResponse) GetSubaccount

func (m *QuerySubaccountResponse) GetSubaccount() Subaccount

func (*QuerySubaccountResponse) Marshal

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

func (*QuerySubaccountResponse) MarshalTo

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

func (*QuerySubaccountResponse) MarshalToSizedBuffer

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

func (*QuerySubaccountResponse) ProtoMessage

func (*QuerySubaccountResponse) ProtoMessage()

func (*QuerySubaccountResponse) Reset

func (m *QuerySubaccountResponse) Reset()

func (*QuerySubaccountResponse) Size

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

func (*QuerySubaccountResponse) String

func (m *QuerySubaccountResponse) String() string

func (*QuerySubaccountResponse) Unmarshal

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

func (*QuerySubaccountResponse) XXX_DiscardUnknown

func (m *QuerySubaccountResponse) XXX_DiscardUnknown()

func (*QuerySubaccountResponse) XXX_Marshal

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

func (*QuerySubaccountResponse) XXX_Merge

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

func (*QuerySubaccountResponse) XXX_Size

func (m *QuerySubaccountResponse) XXX_Size() int

func (*QuerySubaccountResponse) XXX_Unmarshal

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

type SortedSubaccountIds

type SortedSubaccountIds []SubaccountId

SortedSubaccountIds is type alias for `[]SubaccountId` which supports deterministic sorting. SubaccountIds are first ordered by string comparison of their `Owner`, followed by integer comparison of their `Number`. If two `SubaccountId` have equal Owners, and Numbers, they are assumed to be equal, and their sorted order is not deterministic.

func (SortedSubaccountIds) Len

func (s SortedSubaccountIds) Len() int

func (SortedSubaccountIds) Less

func (s SortedSubaccountIds) Less(i, j int) bool

func (SortedSubaccountIds) Swap

func (s SortedSubaccountIds) Swap(i, j int)

type Subaccount

type Subaccount struct {
	// The Id of the Subaccount
	Id *SubaccountId `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
	// All `AssetPosition`s associated with this subaccount.
	// Always sorted ascending by `asset_id`.
	AssetPositions []*AssetPosition `protobuf:"bytes,2,rep,name=asset_positions,json=assetPositions,proto3" json:"asset_positions,omitempty"`
	// All `PerpetualPosition`s associated with this subaccount.
	// Always sorted ascending by `perpetual_id.
	PerpetualPositions []*PerpetualPosition `protobuf:"bytes,3,rep,name=perpetual_positions,json=perpetualPositions,proto3" json:"perpetual_positions,omitempty"`
	// Set by the owner. If true, then margin trades can be made in this
	// subaccount.
	MarginEnabled bool `protobuf:"varint,4,opt,name=margin_enabled,json=marginEnabled,proto3" json:"margin_enabled,omitempty"`
}

Subaccount defines a single sub-account for a given address. Subaccounts are uniquely indexed by a subaccountNumber/owner pair.

func (*Subaccount) Descriptor

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

func (*Subaccount) GetAssetPositions

func (m *Subaccount) GetAssetPositions() []*AssetPosition

func (*Subaccount) GetId

func (m *Subaccount) GetId() *SubaccountId

func (*Subaccount) GetMarginEnabled

func (m *Subaccount) GetMarginEnabled() bool

func (*Subaccount) GetPerpetualPositionForId

func (m *Subaccount) GetPerpetualPositionForId(
	perpetualId uint32,
) (
	perpetualPosition *PerpetualPosition,
	exists bool,
)

GetPerpetualPositionForId returns the perpetual position with the given perpetual id. Returns nil if subaccount does not have an open position for the perpetual.

func (*Subaccount) GetPerpetualPositions

func (m *Subaccount) GetPerpetualPositions() []*PerpetualPosition

func (*Subaccount) GetUsdcPosition

func (m *Subaccount) GetUsdcPosition() *big.Int

GetUsdcPosition returns the balance of the USDC asset position.

func (*Subaccount) Marshal

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

func (*Subaccount) MarshalTo

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

func (*Subaccount) MarshalToSizedBuffer

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

func (*Subaccount) ProtoMessage

func (*Subaccount) ProtoMessage()

func (*Subaccount) Reset

func (m *Subaccount) Reset()

func (*Subaccount) SetUsdcAssetPosition

func (m *Subaccount) SetUsdcAssetPosition(newUsdcPosition *big.Int)

SetUsdcAssetPosition sets the balance of the USDC asset position to `newUsdcPosition`.

func (*Subaccount) Size

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

func (*Subaccount) String

func (m *Subaccount) String() string

func (*Subaccount) Unmarshal

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

func (*Subaccount) XXX_DiscardUnknown

func (m *Subaccount) XXX_DiscardUnknown()

func (*Subaccount) XXX_Marshal

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

func (*Subaccount) XXX_Merge

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

func (*Subaccount) XXX_Size

func (m *Subaccount) XXX_Size() int

func (*Subaccount) XXX_Unmarshal

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

type SubaccountId

type SubaccountId struct {
	// The address of the wallet that owns this subaccount.
	Owner string `protobuf:"bytes,1,opt,name=owner,proto3" json:"owner,omitempty"`
	// < 128 Since 128 should be enough to start and it fits within
	// 1 Byte (1 Bit needed to indicate that the first byte is the last).
	Number uint32 `protobuf:"varint,2,opt,name=number,proto3" json:"number,omitempty"`
}

SubaccountId defines a unique identifier for a Subaccount.

func (*SubaccountId) Descriptor

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

func (*SubaccountId) GetNumber

func (m *SubaccountId) GetNumber() uint32

func (*SubaccountId) GetOwner

func (m *SubaccountId) GetOwner() string

func (*SubaccountId) Marshal

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

func (*SubaccountId) MarshalTo

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

func (*SubaccountId) MarshalToSizedBuffer

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

func (*SubaccountId) MustGetAccAddress

func (m *SubaccountId) MustGetAccAddress() sdk.AccAddress

func (*SubaccountId) ProtoMessage

func (*SubaccountId) ProtoMessage()

func (*SubaccountId) Reset

func (m *SubaccountId) Reset()

func (*SubaccountId) Size

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

func (*SubaccountId) String

func (m *SubaccountId) String() string

func (*SubaccountId) ToStateKey

func (id *SubaccountId) ToStateKey() []byte

ToStateKey returns a bytes representation of a SubaccountId for use as a state key. The key uses the proto marshaling of the object such that it can be unmarshalled in the same way if it needs to be.

func (*SubaccountId) Unmarshal

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

func (*SubaccountId) Validate

func (m *SubaccountId) Validate() error

func (*SubaccountId) XXX_DiscardUnknown

func (m *SubaccountId) XXX_DiscardUnknown()

func (*SubaccountId) XXX_Marshal

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

func (*SubaccountId) XXX_Merge

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

func (*SubaccountId) XXX_Size

func (m *SubaccountId) XXX_Size() int

func (*SubaccountId) XXX_Unmarshal

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

type SubaccountsKeeper

type SubaccountsKeeper interface {
	GetAllSubaccount(ctx sdk.Context) (list []Subaccount)
	GetRandomSubaccount(ctx sdk.Context, rand *rand.Rand) (Subaccount, error)
	GetNetCollateralAndMarginRequirements(
		ctx sdk.Context,
		update Update,
	) (
		bigNetCollateral *big.Int,
		bigInitialMargin *big.Int,
		bigMaintenanceMargin *big.Int,
		err error,
	)
	CanUpdateSubaccounts(
		ctx sdk.Context,
		updates []Update,
	) (
		success bool,
		successPerUpdate []UpdateResult,
		err error,
	)
	UpdateSubaccounts(
		ctx sdk.Context,
		updates []Update,
	) (
		success bool,
		successPerUpdate []UpdateResult,
		err error,
	)
	DepositFundsFromAccountToSubaccount(
		ctx sdk.Context,
		fromAccount sdk.AccAddress,
		toSubaccountId SubaccountId,
		assetId uint32,
		amount *big.Int,
	) (err error)
	WithdrawFundsFromSubaccountToAccount(
		ctx sdk.Context,
		fromSubaccountId SubaccountId,
		toAccount sdk.AccAddress,
		assetId uint32,
		amount *big.Int,
	) (err error)
	SetSubaccount(ctx sdk.Context, subaccount Subaccount)
	GetSubaccount(
		ctx sdk.Context,
		id SubaccountId,
	) (val Subaccount)
}

type UnimplementedQueryServer

type UnimplementedQueryServer struct {
}

UnimplementedQueryServer can be embedded to have forward compatible implementations.

func (*UnimplementedQueryServer) Subaccount

func (*UnimplementedQueryServer) SubaccountAll

type Update

type Update struct {
	// The `Id` of the `Subaccount` for which this update applies.
	SubaccountId SubaccountId
	// A list of changes to make to any `AssetPositions` in the `Subaccount`.
	AssetUpdates []AssetUpdate
	// A list of changes to make to any `PerpetualPositions` in the `Subaccount`.
	PerpetualUpdates []PerpetualUpdate
}

Update is used by the subaccounts keeper to allow other modules to specify changes to one or more `Subaccounts` (for example the result of a trade, transfer, etc)

type UpdateResult

type UpdateResult uint
const (
	Success UpdateResult = iota
	NewlyUndercollateralized
	StillUndercollateralized
	UpdateCausedError
)

func (UpdateResult) IsSuccess

func (u UpdateResult) IsSuccess() bool

IsSuccess returns true if the `UpdateResult` value is `Success`.

func (UpdateResult) String

func (u UpdateResult) String() string

Jump to

Keyboard shortcuts

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