stableswap

package
v11.0.1 Latest Latest
Warning

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

Go to latest
Published: Aug 15, 2022 License: Apache-2.0 Imports: 25 Imported by: 0

README

Stableswap

This package implements the Solidly stableswap curve, namely a CFMM with invariant: xy(x^2 + y^2) = k

Documentation

Index

Constants

View Source
const (
	TypeMsgCreateStableswapPool           = "create_stableswap_pool"
	TypeMsgStableSwapAdjustScalingFactors = "stable_swap_adjust_scaling_factors"
)

Variables

View Source
var (
	ErrInvalidLengthStableswapPool        = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflowStableswapPool          = fmt.Errorf("proto: integer overflow")
	ErrUnexpectedEndOfGroupStableswapPool = fmt.Errorf("proto: unexpected end of group")
)
View Source
var (
	ErrInvalidLengthTx        = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflowTx          = fmt.Errorf("proto: integer overflow")
	ErrUnexpectedEndOfGroupTx = fmt.Errorf("proto: unexpected end of group")
)
View Source
var (

	// ModuleCdc references the global x/bank module codec. Note, the codec should
	// ONLY be used in certain instances of tests and for JSON encoding as Amino is
	// still used for that purpose.
	//
	// The actual codec used for serialization should be provided to x/staking and
	// defined at the application level.
	ModuleCdc = codec.NewAminoCodec(amino)
)

Functions

func RegisterInterfaces

func RegisterInterfaces(registry codectypes.InterfaceRegistry)

func RegisterLegacyAminoCodec

func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino)

RegisterLegacyAminoCodec registers the necessary x/gamm interfaces and concrete types on the provided LegacyAmino codec. These types are used for Amino JSON serialization.

func RegisterMsgServer

func RegisterMsgServer(s grpc1.Server, srv MsgServer)

Types

type MsgClient

type MsgClient interface {
	CreateStableswapPool(ctx context.Context, in *MsgCreateStableswapPool, opts ...grpc.CallOption) (*MsgCreateStableswapPoolResponse, error)
	StableSwapAdjustScalingFactors(ctx context.Context, in *MsgStableSwapAdjustScalingFactors, opts ...grpc.CallOption) (*MsgStableSwapAdjustScalingFactorsResponse, error)
}

MsgClient is the client API for Msg service.

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

func NewMsgClient

func NewMsgClient(cc grpc1.ClientConn) MsgClient

type MsgCreateStableswapPool

type MsgCreateStableswapPool struct {
	Sender               string                                   `protobuf:"bytes,1,opt,name=sender,proto3" json:"sender,omitempty" yaml:"sender"`
	PoolParams           *PoolParams                              `protobuf:"bytes,2,opt,name=poolParams,proto3" json:"poolParams,omitempty" yaml:"pool_params"`
	InitialPoolLiquidity github_com_cosmos_cosmos_sdk_types.Coins `` /* 167-byte string literal not displayed */
	FuturePoolGovernor   string                                   `` /* 145-byte string literal not displayed */
}

func NewMsgCreateStableswapPool

func NewMsgCreateStableswapPool(
	sender sdk.AccAddress,
	poolParams PoolParams,
	initialLiquidity sdk.Coins,
	futurePoolGovernor string,
) MsgCreateStableswapPool

func (MsgCreateStableswapPool) CreatePool

func (msg MsgCreateStableswapPool) CreatePool(ctx sdk.Context, poolId uint64) (types.PoolI, error)

func (*MsgCreateStableswapPool) Descriptor

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

func (*MsgCreateStableswapPool) GetFuturePoolGovernor

func (m *MsgCreateStableswapPool) GetFuturePoolGovernor() string

func (*MsgCreateStableswapPool) GetInitialPoolLiquidity

func (*MsgCreateStableswapPool) GetPoolParams

func (m *MsgCreateStableswapPool) GetPoolParams() *PoolParams

func (*MsgCreateStableswapPool) GetSender

func (m *MsgCreateStableswapPool) GetSender() string

func (MsgCreateStableswapPool) GetSignBytes

func (msg MsgCreateStableswapPool) GetSignBytes() []byte

func (MsgCreateStableswapPool) GetSigners

func (msg MsgCreateStableswapPool) GetSigners() []sdk.AccAddress

func (MsgCreateStableswapPool) InitialLiquidity

func (msg MsgCreateStableswapPool) InitialLiquidity() sdk.Coins

func (*MsgCreateStableswapPool) Marshal

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

func (*MsgCreateStableswapPool) MarshalTo

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

func (*MsgCreateStableswapPool) MarshalToSizedBuffer

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

func (MsgCreateStableswapPool) PoolCreator

func (msg MsgCreateStableswapPool) PoolCreator() sdk.AccAddress

func (*MsgCreateStableswapPool) ProtoMessage

func (*MsgCreateStableswapPool) ProtoMessage()

func (*MsgCreateStableswapPool) Reset

func (m *MsgCreateStableswapPool) Reset()

func (MsgCreateStableswapPool) Route

func (msg MsgCreateStableswapPool) Route() string

func (*MsgCreateStableswapPool) Size

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

func (*MsgCreateStableswapPool) String

func (m *MsgCreateStableswapPool) String() string

func (MsgCreateStableswapPool) Type

func (msg MsgCreateStableswapPool) Type() string

func (*MsgCreateStableswapPool) Unmarshal

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

func (MsgCreateStableswapPool) Validate

func (msg MsgCreateStableswapPool) Validate(ctx sdk.Context) error

func (MsgCreateStableswapPool) ValidateBasic

func (msg MsgCreateStableswapPool) ValidateBasic() error

func (*MsgCreateStableswapPool) XXX_DiscardUnknown

func (m *MsgCreateStableswapPool) XXX_DiscardUnknown()

func (*MsgCreateStableswapPool) XXX_Marshal

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

func (*MsgCreateStableswapPool) XXX_Merge

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

func (*MsgCreateStableswapPool) XXX_Size

func (m *MsgCreateStableswapPool) XXX_Size() int

func (*MsgCreateStableswapPool) XXX_Unmarshal

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

type MsgCreateStableswapPoolResponse

type MsgCreateStableswapPoolResponse struct {
	PoolID uint64 `protobuf:"varint,1,opt,name=pool_id,json=poolId,proto3" json:"pool_id,omitempty"`
}

func (*MsgCreateStableswapPoolResponse) Descriptor

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

func (*MsgCreateStableswapPoolResponse) GetPoolID

func (m *MsgCreateStableswapPoolResponse) GetPoolID() uint64

func (*MsgCreateStableswapPoolResponse) Marshal

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

func (*MsgCreateStableswapPoolResponse) MarshalTo

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

func (*MsgCreateStableswapPoolResponse) MarshalToSizedBuffer

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

func (*MsgCreateStableswapPoolResponse) ProtoMessage

func (*MsgCreateStableswapPoolResponse) ProtoMessage()

func (*MsgCreateStableswapPoolResponse) Reset

func (*MsgCreateStableswapPoolResponse) Size

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

func (*MsgCreateStableswapPoolResponse) String

func (*MsgCreateStableswapPoolResponse) Unmarshal

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

func (*MsgCreateStableswapPoolResponse) XXX_DiscardUnknown

func (m *MsgCreateStableswapPoolResponse) XXX_DiscardUnknown()

func (*MsgCreateStableswapPoolResponse) XXX_Marshal

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

func (*MsgCreateStableswapPoolResponse) XXX_Merge

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

func (*MsgCreateStableswapPoolResponse) XXX_Size

func (m *MsgCreateStableswapPoolResponse) XXX_Size() int

func (*MsgCreateStableswapPoolResponse) XXX_Unmarshal

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

type MsgServer

MsgServer is the server API for Msg service.

type MsgStableSwapAdjustScalingFactors

type MsgStableSwapAdjustScalingFactors struct {
	// Sender must be the pool's scaling_factor_governor in order for the tx to
	// succeed
	Sender         string   `protobuf:"bytes,1,opt,name=sender,proto3" json:"sender,omitempty" yaml:"sender"`
	PoolID         uint64   `protobuf:"varint,2,opt,name=pool_id,json=poolId,proto3" json:"pool_id,omitempty"`
	ScalingFactors []uint64 `` /* 144-byte string literal not displayed */
}

func NewMsgStableSwapAdjustScalingFactors

func NewMsgStableSwapAdjustScalingFactors(
	sender string,
	poolID uint64,
) MsgStableSwapAdjustScalingFactors

Implement sdk.Msg

func (*MsgStableSwapAdjustScalingFactors) Descriptor

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

func (*MsgStableSwapAdjustScalingFactors) GetPoolID

func (*MsgStableSwapAdjustScalingFactors) GetScalingFactors

func (m *MsgStableSwapAdjustScalingFactors) GetScalingFactors() []uint64

func (*MsgStableSwapAdjustScalingFactors) GetSender

func (MsgStableSwapAdjustScalingFactors) GetSignBytes

func (msg MsgStableSwapAdjustScalingFactors) GetSignBytes() []byte

func (MsgStableSwapAdjustScalingFactors) GetSigners

func (*MsgStableSwapAdjustScalingFactors) Marshal

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

func (*MsgStableSwapAdjustScalingFactors) MarshalTo

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

func (*MsgStableSwapAdjustScalingFactors) MarshalToSizedBuffer

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

func (*MsgStableSwapAdjustScalingFactors) ProtoMessage

func (*MsgStableSwapAdjustScalingFactors) ProtoMessage()

func (*MsgStableSwapAdjustScalingFactors) Reset

func (MsgStableSwapAdjustScalingFactors) Route

func (*MsgStableSwapAdjustScalingFactors) Size

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

func (*MsgStableSwapAdjustScalingFactors) String

func (MsgStableSwapAdjustScalingFactors) Type

func (*MsgStableSwapAdjustScalingFactors) Unmarshal

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

func (MsgStableSwapAdjustScalingFactors) ValidateBasic

func (msg MsgStableSwapAdjustScalingFactors) ValidateBasic() error

func (*MsgStableSwapAdjustScalingFactors) XXX_DiscardUnknown

func (m *MsgStableSwapAdjustScalingFactors) XXX_DiscardUnknown()

func (*MsgStableSwapAdjustScalingFactors) XXX_Marshal

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

func (*MsgStableSwapAdjustScalingFactors) XXX_Merge

func (*MsgStableSwapAdjustScalingFactors) XXX_Size

func (m *MsgStableSwapAdjustScalingFactors) XXX_Size() int

func (*MsgStableSwapAdjustScalingFactors) XXX_Unmarshal

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

type MsgStableSwapAdjustScalingFactorsResponse

type MsgStableSwapAdjustScalingFactorsResponse struct {
}

func (*MsgStableSwapAdjustScalingFactorsResponse) Descriptor

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

func (*MsgStableSwapAdjustScalingFactorsResponse) Marshal

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

func (*MsgStableSwapAdjustScalingFactorsResponse) MarshalTo

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

func (*MsgStableSwapAdjustScalingFactorsResponse) MarshalToSizedBuffer

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

func (*MsgStableSwapAdjustScalingFactorsResponse) ProtoMessage

func (*MsgStableSwapAdjustScalingFactorsResponse) Reset

func (*MsgStableSwapAdjustScalingFactorsResponse) Size

func (*MsgStableSwapAdjustScalingFactorsResponse) String

func (*MsgStableSwapAdjustScalingFactorsResponse) Unmarshal

func (*MsgStableSwapAdjustScalingFactorsResponse) XXX_DiscardUnknown

func (m *MsgStableSwapAdjustScalingFactorsResponse) XXX_DiscardUnknown()

func (*MsgStableSwapAdjustScalingFactorsResponse) XXX_Marshal

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

func (*MsgStableSwapAdjustScalingFactorsResponse) XXX_Merge

func (*MsgStableSwapAdjustScalingFactorsResponse) XXX_Size

func (*MsgStableSwapAdjustScalingFactorsResponse) XXX_Unmarshal

type Pool

type Pool struct {
	Address    string     `protobuf:"bytes,1,opt,name=address,proto3" json:"address,omitempty" yaml:"address"`
	Id         uint64     `protobuf:"varint,2,opt,name=id,proto3" json:"id,omitempty"`
	PoolParams PoolParams `protobuf:"bytes,3,opt,name=poolParams,proto3" json:"poolParams" yaml:"stableswap_pool_params"`
	// This string specifies who will govern the pool in the future.
	// Valid forms of this are:
	// {token name},{duration}
	// {duration}
	// where {token name} if specified is the token which determines the
	// governor, and if not specified is the LP token for this pool.duration is
	// a time specified as 0w,1w,2w, etc. which specifies how long the token
	// would need to be locked up to count in governance. 0w means no lockup.
	FuturePoolGovernor string `` /* 145-byte string literal not displayed */
	// sum of all LP shares
	TotalShares types.Coin `protobuf:"bytes,5,opt,name=totalShares,proto3" json:"totalShares" yaml:"total_shares"`
	// assets in the pool
	PoolLiquidity github_com_cosmos_cosmos_sdk_types.Coins `protobuf:"bytes,6,rep,name=poolLiquidity,proto3,castrepeated=github.com/cosmos/cosmos-sdk/types.Coins" json:"poolLiquidity"`
	// for calculation amognst assets with different precisions
	ScalingFactor []uint64 `` /* 141-byte string literal not displayed */
	// scaling_factor_governor is the address can adjust pool scaling factors
	ScalingFactorGovernor string `` /* 157-byte string literal not displayed */
}

Pool is the stableswap Pool struct

func NewStableswapPool

func NewStableswapPool(poolId uint64, stableswapPoolParams PoolParams, initialLiquidity sdk.Coins, futureGovernor string, blockTime time.Time) (Pool, error)

NewStableswapPool returns a stableswap pool Invariants that are assumed to be satisfied and not checked: * len(initialLiquidity) = 2 * FutureGovernor is valid * poolID doesn't already exist

func (Pool) CalcExitPoolShares

func (pa Pool) CalcExitPoolShares(ctx sdk.Context, exitingShares sdk.Int, exitFee sdk.Dec) (exitingCoins sdk.Coins, err error)

func (Pool) CalcInAmtGivenOut

func (pa Pool) CalcInAmtGivenOut(ctx sdk.Context, tokenOut sdk.Coins, tokenInDenom string, swapFee sdk.Dec) (tokenIn sdk.Coin, err error)

func (*Pool) CalcJoinPoolShares

func (pa *Pool) CalcJoinPoolShares(ctx sdk.Context, tokensIn sdk.Coins, swapFee sdk.Dec) (numShares sdk.Int, newLiquidity sdk.Coins, err error)

func (Pool) CalcOutAmtGivenIn

func (pa Pool) CalcOutAmtGivenIn(ctx sdk.Context, tokenIn sdk.Coins, tokenOutDenom string, swapFee sdk.Dec) (tokenOut sdk.Coin, err error)

TODO: These should all get moved to amm.go

func (Pool) Copy

func (pa Pool) Copy() Pool

func (*Pool) Descriptor

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

func (*Pool) ExitPool

func (pa *Pool) ExitPool(ctx sdk.Context, exitingShares sdk.Int, exitFee sdk.Dec) (exitingCoins sdk.Coins, err error)

func (Pool) GetAddress

func (pa Pool) GetAddress() sdk.AccAddress

func (Pool) GetExitFee

func (pa Pool) GetExitFee(ctx sdk.Context) sdk.Dec

func (Pool) GetId

func (pa Pool) GetId() uint64

func (Pool) GetScalingFactorByLiquidityIndex

func (pa Pool) GetScalingFactorByLiquidityIndex(liquidityIndex int) uint64

CONTRACT: scaling factors follow the same index with pool liquidity denoms

func (Pool) GetScalingFactors

func (pa Pool) GetScalingFactors() []uint64

func (Pool) GetSwapFee

func (pa Pool) GetSwapFee(ctx sdk.Context) sdk.Dec

func (Pool) GetTotalPoolLiquidity

func (pa Pool) GetTotalPoolLiquidity(ctx sdk.Context) sdk.Coins

Returns the coins in the pool owned by all LP shareholders

func (Pool) GetTotalShares

func (pa Pool) GetTotalShares() sdk.Int

func (Pool) IsActive

func (pa Pool) IsActive(ctx sdk.Context) bool

func (*Pool) JoinPool

func (pa *Pool) JoinPool(ctx sdk.Context, tokensIn sdk.Coins, swapFee sdk.Dec) (numShares sdk.Int, err error)

func (*Pool) Marshal

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

func (*Pool) MarshalTo

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

func (*Pool) MarshalToSizedBuffer

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

func (Pool) NumAssets

func (pa Pool) NumAssets() int

func (*Pool) PokePool

func (pa *Pool) PokePool(blockTime time.Time)

no-op for stableswap

func (*Pool) ProtoMessage

func (*Pool) ProtoMessage()

func (*Pool) Reset

func (m *Pool) Reset()

func (*Pool) Size

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

func (Pool) SpotPrice

func (pa Pool) SpotPrice(ctx sdk.Context, baseAssetDenom string, quoteAssetDenom string) (sdk.Dec, error)

func (Pool) String

func (pa Pool) String() string

func (*Pool) SwapInAmtGivenOut

func (pa *Pool) SwapInAmtGivenOut(ctx sdk.Context, tokenOut sdk.Coins, tokenInDenom string, swapFee sdk.Dec) (tokenIn sdk.Coin, err error)

func (*Pool) SwapOutAmtGivenIn

func (pa *Pool) SwapOutAmtGivenIn(ctx sdk.Context, tokenIn sdk.Coins, tokenOutDenom string, swapFee sdk.Dec) (tokenOut sdk.Coin, err error)

func (*Pool) Unmarshal

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

func (*Pool) XXX_DiscardUnknown

func (m *Pool) XXX_DiscardUnknown()

func (*Pool) XXX_Marshal

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

func (*Pool) XXX_Merge

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

func (*Pool) XXX_Size

func (m *Pool) XXX_Size() int

func (*Pool) XXX_Unmarshal

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

type PoolParams

type PoolParams struct {
	SwapFee github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,1,opt,name=swapFee,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"swapFee" yaml:"swap_fee"`
	ExitFee github_com_cosmos_cosmos_sdk_types.Dec `protobuf:"bytes,2,opt,name=exitFee,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Dec" json:"exitFee" yaml:"exit_fee"`
}

PoolParams defined the parameters that will be managed by the pool governance in the future. This params are not managed by the chain governance. Instead they will be managed by the token holders of the pool. The pool's token holders are specified in future_pool_governor.

func (*PoolParams) Descriptor

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

func (*PoolParams) Marshal

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

func (*PoolParams) MarshalTo

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

func (*PoolParams) MarshalToSizedBuffer

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

func (*PoolParams) ProtoMessage

func (*PoolParams) ProtoMessage()

func (*PoolParams) Reset

func (m *PoolParams) Reset()

func (*PoolParams) Size

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

func (*PoolParams) String

func (m *PoolParams) String() string

func (*PoolParams) Unmarshal

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

func (PoolParams) Validate

func (params PoolParams) Validate() error

func (*PoolParams) XXX_DiscardUnknown

func (m *PoolParams) XXX_DiscardUnknown()

func (*PoolParams) XXX_Marshal

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

func (*PoolParams) XXX_Merge

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

func (*PoolParams) XXX_Size

func (m *PoolParams) XXX_Size() int

func (*PoolParams) XXX_Unmarshal

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

type UnimplementedMsgServer

type UnimplementedMsgServer struct {
}

UnimplementedMsgServer can be embedded to have forward compatible implementations.

func (*UnimplementedMsgServer) CreateStableswapPool

Jump to

Keyboard shortcuts

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