Documentation ¶
Overview ¶
Package balancer implements weighted constant product AMMs, satisfying the AMM pool interface from x/gamm/types. Please refer to the specification under /spec for further information, and the Balancer projects documentation for more details on the mathematical equations.
Index ¶
- Constants
- Variables
- func RegisterInterfaces(registry codectypes.InterfaceRegistry)
- func RegisterLegacyAminoCodec(cdc *codec.LegacyAmino)
- func RegisterMsgServer(s grpc1.Server, srv MsgServer)
- func ValidateUserSpecifiedWeight(weight sdk.Int) error
- type MsgClient
- type MsgCreateBalancerPool
- func (msg MsgCreateBalancerPool) CreatePool(ctx sdk.Context, poolID uint64) (types.PoolI, error)
- func (*MsgCreateBalancerPool) Descriptor() ([]byte, []int)
- func (m *MsgCreateBalancerPool) GetFuturePoolGovernor() string
- func (m *MsgCreateBalancerPool) GetPoolAssets() []PoolAsset
- func (m *MsgCreateBalancerPool) GetPoolParams() *PoolParams
- func (m *MsgCreateBalancerPool) GetSender() string
- func (msg MsgCreateBalancerPool) GetSignBytes() []byte
- func (msg MsgCreateBalancerPool) GetSigners() []sdk.AccAddress
- func (msg MsgCreateBalancerPool) InitialLiquidity() sdk.Coins
- func (m *MsgCreateBalancerPool) Marshal() (dAtA []byte, err error)
- func (m *MsgCreateBalancerPool) MarshalTo(dAtA []byte) (int, error)
- func (m *MsgCreateBalancerPool) MarshalToSizedBuffer(dAtA []byte) (int, error)
- func (msg MsgCreateBalancerPool) PoolCreator() sdk.AccAddress
- func (*MsgCreateBalancerPool) ProtoMessage()
- func (m *MsgCreateBalancerPool) Reset()
- func (msg MsgCreateBalancerPool) Route() string
- func (m *MsgCreateBalancerPool) Size() (n int)
- func (m *MsgCreateBalancerPool) String() string
- func (msg MsgCreateBalancerPool) Type() string
- func (m *MsgCreateBalancerPool) Unmarshal(dAtA []byte) error
- func (msg MsgCreateBalancerPool) Validate(ctx sdk.Context) error
- func (msg MsgCreateBalancerPool) ValidateBasic() error
- func (m *MsgCreateBalancerPool) XXX_DiscardUnknown()
- func (m *MsgCreateBalancerPool) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *MsgCreateBalancerPool) XXX_Merge(src proto.Message)
- func (m *MsgCreateBalancerPool) XXX_Size() int
- func (m *MsgCreateBalancerPool) XXX_Unmarshal(b []byte) error
- type MsgCreateBalancerPoolResponse
- func (*MsgCreateBalancerPoolResponse) Descriptor() ([]byte, []int)
- func (m *MsgCreateBalancerPoolResponse) GetPoolID() uint64
- func (m *MsgCreateBalancerPoolResponse) Marshal() (dAtA []byte, err error)
- func (m *MsgCreateBalancerPoolResponse) MarshalTo(dAtA []byte) (int, error)
- func (m *MsgCreateBalancerPoolResponse) MarshalToSizedBuffer(dAtA []byte) (int, error)
- func (*MsgCreateBalancerPoolResponse) ProtoMessage()
- func (m *MsgCreateBalancerPoolResponse) Reset()
- func (m *MsgCreateBalancerPoolResponse) Size() (n int)
- func (m *MsgCreateBalancerPoolResponse) String() string
- func (m *MsgCreateBalancerPoolResponse) Unmarshal(dAtA []byte) error
- func (m *MsgCreateBalancerPoolResponse) XXX_DiscardUnknown()
- func (m *MsgCreateBalancerPoolResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *MsgCreateBalancerPoolResponse) XXX_Merge(src proto.Message)
- func (m *MsgCreateBalancerPoolResponse) XXX_Size() int
- func (m *MsgCreateBalancerPoolResponse) XXX_Unmarshal(b []byte) error
- type MsgServer
- type Pool
- func (p *Pool) AddTotalShares(amt sdk.Int)
- func (p *Pool) CalcExitPoolCoinsFromShares(ctx sdk.Context, exitingShares sdk.Int, exitFee sdk.Dec) (exitedCoins sdk.Coins, err error)
- func (p Pool) CalcInAmtGivenOut(ctx sdk.Context, tokensOut sdk.Coins, tokenInDenom string, swapFee sdk.Dec) (tokenIn sdk.Coin, err error)
- func (p *Pool) CalcJoinPoolNoSwapShares(ctx sdk.Context, tokensIn sdk.Coins, swapFee sdk.Dec) (numShares sdk.Int, tokensJoined sdk.Coins, err error)
- func (p *Pool) CalcJoinPoolShares(ctx sdk.Context, tokensIn sdk.Coins, swapFee sdk.Dec) (numShares sdk.Int, tokensJoined sdk.Coins, err error)
- func (p Pool) CalcOutAmtGivenIn(ctx sdk.Context, tokensIn sdk.Coins, tokenOutDenom string, swapFee sdk.Dec) (sdk.Coin, error)
- func (p *Pool) CalcTokenInShareAmountOut(ctx sdk.Context, tokenInDenom string, shareOutAmount sdk.Int, swapFee sdk.Dec) (tokenInAmount sdk.Int, err error)
- func (*Pool) Descriptor() ([]byte, []int)
- func (p *Pool) ExitPool(ctx sdk.Context, exitingShares sdk.Int, exitFee sdk.Dec) (exitingCoins sdk.Coins, err error)
- func (p *Pool) ExitSwapExactAmountOut(ctx sdk.Context, tokenOut sdk.Coin, shareInMaxAmount sdk.Int) (shareInAmount sdk.Int, err error)
- func (p Pool) GetAddress() sdk.AccAddress
- func (p Pool) GetAllPoolAssets() []PoolAsset
- func (p Pool) GetExitFee(_ sdk.Context) sdk.Dec
- func (p Pool) GetId() uint64
- func (p Pool) GetPoolAsset(denom string) (PoolAsset, error)
- func (p Pool) GetPoolAssets(denoms ...string) ([]PoolAsset, error)
- func (p Pool) GetPoolParams() PoolParams
- func (p Pool) GetSwapFee(_ sdk.Context) sdk.Dec
- func (p Pool) GetTokenBalance(denom string) (sdk.Int, error)
- func (p Pool) GetTokenWeight(denom string) (sdk.Int, error)
- func (p Pool) GetTotalPoolLiquidity(_ sdk.Context) sdk.Coins
- func (p Pool) GetTotalShares() sdk.Int
- func (p Pool) GetTotalWeight() sdk.Int
- func (p *Pool) IncreaseLiquidity(sharesOut sdk.Int, coinsIn sdk.Coins)
- func (p Pool) IsActive(ctx sdk.Context) bool
- func (p *Pool) JoinPool(ctx sdk.Context, tokensIn sdk.Coins, swapFee sdk.Dec) (numShares sdk.Int, err error)
- func (p *Pool) JoinPoolNoSwap(ctx sdk.Context, tokensIn sdk.Coins, swapFee sdk.Dec) (numShares sdk.Int, err error)
- func (p *Pool) JoinPoolTokenInMaxShareAmountOut(ctx sdk.Context, tokenInDenom string, shareOutAmount sdk.Int) (tokenInAmount sdk.Int, err error)
- func (m *Pool) Marshal() (dAtA []byte, err error)
- func (p Pool) MarshalJSON() ([]byte, error)
- func (m *Pool) MarshalTo(dAtA []byte) (int, error)
- func (m *Pool) MarshalToSizedBuffer(dAtA []byte) (int, error)
- func (p Pool) NumAssets() int
- func (p *Pool) PokePool(blockTime time.Time)
- func (*Pool) ProtoMessage()
- func (m *Pool) Reset()
- func (p *Pool) SetInitialPoolAssets(PoolAssets []PoolAsset) error
- func (m *Pool) Size() (n int)
- func (p Pool) SpotPrice(ctx sdk.Context, baseAsset, quoteAsset string) (spotPrice sdk.Dec, err error)
- func (p Pool) String() string
- func (p *Pool) SubTotalShares(amt sdk.Int)
- func (p *Pool) SwapInAmtGivenOut(ctx sdk.Context, tokensOut sdk.Coins, tokenInDenom string, swapFee sdk.Dec) (tokenIn sdk.Coin, err error)
- func (p *Pool) SwapOutAmtGivenIn(ctx sdk.Context, tokensIn sdk.Coins, tokenOutDenom string, swapFee sdk.Dec) (tokenOut sdk.Coin, err error)
- func (m *Pool) Unmarshal(dAtA []byte) error
- func (p *Pool) UnmarshalJSON(bz []byte) error
- func (p *Pool) UpdatePoolAssetBalance(coin sdk.Coin) error
- func (p *Pool) UpdatePoolAssetBalances(coins sdk.Coins) error
- func (m *Pool) XXX_DiscardUnknown()
- func (m *Pool) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *Pool) XXX_Merge(src proto.Message)
- func (m *Pool) XXX_Size() int
- func (m *Pool) XXX_Unmarshal(b []byte) error
- type PoolAsset
- func (*PoolAsset) Descriptor() ([]byte, []int)
- func (m *PoolAsset) GetToken() types1.Coin
- func (m *PoolAsset) Marshal() (dAtA []byte, err error)
- func (m *PoolAsset) MarshalTo(dAtA []byte) (int, error)
- func (m *PoolAsset) MarshalToSizedBuffer(dAtA []byte) (int, error)
- func (pa PoolAsset) MarshalYAML() (interface{}, error)
- func (*PoolAsset) ProtoMessage()
- func (m *PoolAsset) Reset()
- func (m *PoolAsset) Size() (n int)
- func (m *PoolAsset) String() string
- func (m *PoolAsset) Unmarshal(dAtA []byte) error
- func (m *PoolAsset) XXX_DiscardUnknown()
- func (m *PoolAsset) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *PoolAsset) XXX_Merge(src proto.Message)
- func (m *PoolAsset) XXX_Size() int
- func (m *PoolAsset) XXX_Unmarshal(b []byte) error
- type PoolParams
- func (*PoolParams) Descriptor() ([]byte, []int)
- func (params PoolParams) GetPoolExitFee() sdk.Dec
- func (params PoolParams) GetPoolSwapFee() sdk.Dec
- func (m *PoolParams) GetSmoothWeightChangeParams() *SmoothWeightChangeParams
- func (m *PoolParams) Marshal() (dAtA []byte, err error)
- func (m *PoolParams) MarshalTo(dAtA []byte) (int, error)
- func (m *PoolParams) MarshalToSizedBuffer(dAtA []byte) (int, error)
- func (*PoolParams) ProtoMessage()
- func (m *PoolParams) Reset()
- func (m *PoolParams) Size() (n int)
- func (m *PoolParams) String() string
- func (m *PoolParams) Unmarshal(dAtA []byte) error
- func (params PoolParams) Validate(poolWeights []PoolAsset) error
- func (m *PoolParams) XXX_DiscardUnknown()
- func (m *PoolParams) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *PoolParams) XXX_Merge(src proto.Message)
- func (m *PoolParams) XXX_Size() int
- func (m *PoolParams) XXX_Unmarshal(b []byte) error
- type SmoothWeightChangeParams
- func (*SmoothWeightChangeParams) Descriptor() ([]byte, []int)
- func (m *SmoothWeightChangeParams) GetDuration() time.Duration
- func (m *SmoothWeightChangeParams) GetInitialPoolWeights() []PoolAsset
- func (m *SmoothWeightChangeParams) GetStartTime() time.Time
- func (m *SmoothWeightChangeParams) GetTargetPoolWeights() []PoolAsset
- func (m *SmoothWeightChangeParams) Marshal() (dAtA []byte, err error)
- func (m *SmoothWeightChangeParams) MarshalTo(dAtA []byte) (int, error)
- func (m *SmoothWeightChangeParams) MarshalToSizedBuffer(dAtA []byte) (int, error)
- func (*SmoothWeightChangeParams) ProtoMessage()
- func (m *SmoothWeightChangeParams) Reset()
- func (m *SmoothWeightChangeParams) Size() (n int)
- func (m *SmoothWeightChangeParams) String() string
- func (m *SmoothWeightChangeParams) Unmarshal(dAtA []byte) error
- func (m *SmoothWeightChangeParams) XXX_DiscardUnknown()
- func (m *SmoothWeightChangeParams) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *SmoothWeightChangeParams) XXX_Merge(src proto.Message)
- func (m *SmoothWeightChangeParams) XXX_Size() int
- func (m *SmoothWeightChangeParams) XXX_Unmarshal(b []byte) error
- type UnimplementedMsgServer
Constants ¶
const (
TypeMsgCreateBalancerPool = "create_balancer_pool"
)
Variables ¶
var ( ErrInvalidLengthBalancerPool = fmt.Errorf("proto: negative length found during unmarshaling") ErrIntOverflowBalancerPool = fmt.Errorf("proto: integer overflow") ErrUnexpectedEndOfGroupBalancerPool = fmt.Errorf("proto: unexpected end of group") )
var ( // Pool creators can specify a weight in [1, MaxUserSpecifiedWeight) // for every token in the balancer pool. // // The weight used in the balancer equation is then creator-specified-weight * GuaranteedWeightPrecision. // This is done so that LBP's / smooth weight changes can actually happen smoothly, // without complex precision loss / edge effects. MaxUserSpecifiedWeight sdk.Int = sdk.NewIntFromUint64(1 << 20) // Scaling factor for every weight. The pool weight is: // weight_in_MsgCreateBalancerPool * GuaranteedWeightPrecision // // This is done so that smooth weight changes have enough precision to actually be smooth. GuaranteedWeightPrecision int64 = 1 << 30 )
var ( ErrInvalidLengthTx = fmt.Errorf("proto: negative length found during unmarshaling") ErrIntOverflowTx = fmt.Errorf("proto: integer overflow") ErrUnexpectedEndOfGroupTx = fmt.Errorf("proto: unexpected end of group") )
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 ValidateUserSpecifiedWeight ¶
ValidateUserSpecifiedWeight ensures that a weight that is provided from user-input anywhere for creating a pool obeys the expected guarantees. Namely, that the weight is in the range [1, MaxUserSpecifiedWeight)
Types ¶
type MsgClient ¶
type MsgClient interface {
CreateBalancerPool(ctx context.Context, in *MsgCreateBalancerPool, opts ...grpc.CallOption) (*MsgCreateBalancerPoolResponse, 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 MsgCreateBalancerPool ¶
type MsgCreateBalancerPool struct { Sender string `protobuf:"bytes,1,opt,name=sender,proto3" json:"sender,omitempty" yaml:"sender"` PoolParams *PoolParams `protobuf:"bytes,2,opt,name=pool_params,json=poolParams,proto3" json:"pool_params,omitempty" yaml:"pool_params"` PoolAssets []PoolAsset `protobuf:"bytes,3,rep,name=pool_assets,json=poolAssets,proto3" json:"pool_assets"` FuturePoolGovernor string `` /* 145-byte string literal not displayed */ }
===================== MsgCreatePool
func NewMsgCreateBalancerPool ¶
func NewMsgCreateBalancerPool( sender sdk.AccAddress, poolParams PoolParams, poolAssets []PoolAsset, futurePoolGovernor string, ) MsgCreateBalancerPool
func (MsgCreateBalancerPool) CreatePool ¶
func (*MsgCreateBalancerPool) Descriptor ¶
func (*MsgCreateBalancerPool) Descriptor() ([]byte, []int)
func (*MsgCreateBalancerPool) GetFuturePoolGovernor ¶
func (m *MsgCreateBalancerPool) GetFuturePoolGovernor() string
func (*MsgCreateBalancerPool) GetPoolAssets ¶
func (m *MsgCreateBalancerPool) GetPoolAssets() []PoolAsset
func (*MsgCreateBalancerPool) GetPoolParams ¶
func (m *MsgCreateBalancerPool) GetPoolParams() *PoolParams
func (*MsgCreateBalancerPool) GetSender ¶
func (m *MsgCreateBalancerPool) GetSender() string
func (MsgCreateBalancerPool) GetSignBytes ¶
func (msg MsgCreateBalancerPool) GetSignBytes() []byte
func (MsgCreateBalancerPool) GetSigners ¶
func (msg MsgCreateBalancerPool) GetSigners() []sdk.AccAddress
func (MsgCreateBalancerPool) InitialLiquidity ¶
func (msg MsgCreateBalancerPool) InitialLiquidity() sdk.Coins
func (*MsgCreateBalancerPool) Marshal ¶
func (m *MsgCreateBalancerPool) Marshal() (dAtA []byte, err error)
func (*MsgCreateBalancerPool) MarshalTo ¶
func (m *MsgCreateBalancerPool) MarshalTo(dAtA []byte) (int, error)
func (*MsgCreateBalancerPool) MarshalToSizedBuffer ¶
func (m *MsgCreateBalancerPool) MarshalToSizedBuffer(dAtA []byte) (int, error)
func (MsgCreateBalancerPool) PoolCreator ¶
func (msg MsgCreateBalancerPool) PoolCreator() sdk.AccAddress
func (*MsgCreateBalancerPool) ProtoMessage ¶
func (*MsgCreateBalancerPool) ProtoMessage()
func (*MsgCreateBalancerPool) Reset ¶
func (m *MsgCreateBalancerPool) Reset()
func (MsgCreateBalancerPool) Route ¶
func (msg MsgCreateBalancerPool) Route() string
func (*MsgCreateBalancerPool) Size ¶
func (m *MsgCreateBalancerPool) Size() (n int)
func (*MsgCreateBalancerPool) String ¶
func (m *MsgCreateBalancerPool) String() string
func (MsgCreateBalancerPool) Type ¶
func (msg MsgCreateBalancerPool) Type() string
func (*MsgCreateBalancerPool) Unmarshal ¶
func (m *MsgCreateBalancerPool) Unmarshal(dAtA []byte) error
func (MsgCreateBalancerPool) Validate ¶
func (msg MsgCreateBalancerPool) Validate(ctx sdk.Context) error
func (MsgCreateBalancerPool) ValidateBasic ¶
func (msg MsgCreateBalancerPool) ValidateBasic() error
func (*MsgCreateBalancerPool) XXX_DiscardUnknown ¶
func (m *MsgCreateBalancerPool) XXX_DiscardUnknown()
func (*MsgCreateBalancerPool) XXX_Marshal ¶
func (m *MsgCreateBalancerPool) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
func (*MsgCreateBalancerPool) XXX_Merge ¶
func (m *MsgCreateBalancerPool) XXX_Merge(src proto.Message)
func (*MsgCreateBalancerPool) XXX_Size ¶
func (m *MsgCreateBalancerPool) XXX_Size() int
func (*MsgCreateBalancerPool) XXX_Unmarshal ¶
func (m *MsgCreateBalancerPool) XXX_Unmarshal(b []byte) error
type MsgCreateBalancerPoolResponse ¶
type MsgCreateBalancerPoolResponse struct {
PoolID uint64 `protobuf:"varint,1,opt,name=pool_id,json=poolId,proto3" json:"pool_id,omitempty"`
}
Returns the poolID
func (*MsgCreateBalancerPoolResponse) Descriptor ¶
func (*MsgCreateBalancerPoolResponse) Descriptor() ([]byte, []int)
func (*MsgCreateBalancerPoolResponse) GetPoolID ¶
func (m *MsgCreateBalancerPoolResponse) GetPoolID() uint64
func (*MsgCreateBalancerPoolResponse) Marshal ¶
func (m *MsgCreateBalancerPoolResponse) Marshal() (dAtA []byte, err error)
func (*MsgCreateBalancerPoolResponse) MarshalTo ¶
func (m *MsgCreateBalancerPoolResponse) MarshalTo(dAtA []byte) (int, error)
func (*MsgCreateBalancerPoolResponse) MarshalToSizedBuffer ¶
func (m *MsgCreateBalancerPoolResponse) MarshalToSizedBuffer(dAtA []byte) (int, error)
func (*MsgCreateBalancerPoolResponse) ProtoMessage ¶
func (*MsgCreateBalancerPoolResponse) ProtoMessage()
func (*MsgCreateBalancerPoolResponse) Reset ¶
func (m *MsgCreateBalancerPoolResponse) Reset()
func (*MsgCreateBalancerPoolResponse) Size ¶
func (m *MsgCreateBalancerPoolResponse) Size() (n int)
func (*MsgCreateBalancerPoolResponse) String ¶
func (m *MsgCreateBalancerPoolResponse) String() string
func (*MsgCreateBalancerPoolResponse) Unmarshal ¶
func (m *MsgCreateBalancerPoolResponse) Unmarshal(dAtA []byte) error
func (*MsgCreateBalancerPoolResponse) XXX_DiscardUnknown ¶
func (m *MsgCreateBalancerPoolResponse) XXX_DiscardUnknown()
func (*MsgCreateBalancerPoolResponse) XXX_Marshal ¶
func (m *MsgCreateBalancerPoolResponse) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
func (*MsgCreateBalancerPoolResponse) XXX_Merge ¶
func (m *MsgCreateBalancerPoolResponse) XXX_Merge(src proto.Message)
func (*MsgCreateBalancerPoolResponse) XXX_Size ¶
func (m *MsgCreateBalancerPoolResponse) XXX_Size() int
func (*MsgCreateBalancerPoolResponse) XXX_Unmarshal ¶
func (m *MsgCreateBalancerPoolResponse) XXX_Unmarshal(b []byte) error
type MsgServer ¶
type MsgServer interface {
CreateBalancerPool(context.Context, *MsgCreateBalancerPool) (*MsgCreateBalancerPoolResponse, error)
}
MsgServer is the server API for Msg service.
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=pool_params,json=poolParams,proto3" json:"pool_params" yaml:"balancer_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. // TODO: Further improve these docs FuturePoolGovernor string `` /* 145-byte string literal not displayed */ TotalShares types1.Coin `protobuf:"bytes,5,opt,name=total_shares,json=totalShares,proto3" json:"total_shares" yaml:"total_shares"` // These are assumed to be sorted by denomiation. // They contain the pool asset and the information about the weight PoolAssets []PoolAsset `protobuf:"bytes,6,rep,name=pool_assets,json=poolAssets,proto3" json:"pool_assets" yaml:"pool_assets"` // sum of all non-normalized pool weights TotalWeight github_com_cosmos_cosmos_sdk_types.Int `` /* 154-byte string literal not displayed */ }
func NewBalancerPool ¶
func NewBalancerPool(poolId uint64, balancerPoolParams PoolParams, assets []PoolAsset, futureGovernor string, blockTime time.Time) (Pool, error)
NewPool returns a weighted CPMM pool with the provided parameters, and initial assets. Invariants that are assumed to be satisfied and not checked: (This is handled in ValidateBasic) * 2 <= len(assets) <= 8 * FutureGovernor is valid * poolID doesn't already exist
func (*Pool) AddTotalShares ¶
func (*Pool) CalcExitPoolCoinsFromShares ¶
func (Pool) CalcInAmtGivenOut ¶
func (p Pool) CalcInAmtGivenOut( ctx sdk.Context, tokensOut sdk.Coins, tokenInDenom string, swapFee sdk.Dec) ( tokenIn sdk.Coin, err error, )
CalcInAmtGivenOut calculates token to be provided, fee added, given the swapped out amount, using solveConstantFunctionInvariant.
func (*Pool) CalcJoinPoolNoSwapShares ¶
func (p *Pool) CalcJoinPoolNoSwapShares(ctx sdk.Context, tokensIn sdk.Coins, swapFee sdk.Dec) (numShares sdk.Int, tokensJoined sdk.Coins, err error)
CalcJoinPoolNoSwapShares calculates the number of shares created to execute an all-asset pool join with the provided amount of `tokensIn`. The input tokens must contain the same tokens as in the pool.
Returns the number of shares created, the amount of coins actually joined into the pool, (in case of not being able to fully join), and the remaining tokens in `tokensIn` after joining. If an all-asset join is not possible, returns an error.
Since CalcJoinPoolNoSwapShares is non-mutative, the steps for updating pool shares / liquidity are more complex / don't just alter the state. We should simplify this logic further in the future using multi-join equations.
func (*Pool) CalcJoinPoolShares ¶
func (p *Pool) CalcJoinPoolShares(ctx sdk.Context, tokensIn sdk.Coins, swapFee sdk.Dec) (numShares sdk.Int, tokensJoined sdk.Coins, err error)
CalcJoinPoolShares calculates the number of shares created to join pool with the provided amount of `tokenIn`. The input tokens must either be: - a single token - contain exactly the same tokens as the pool contains
It returns the number of shares created, the amount of coins actually joined into the pool (in case of not being able to fully join), or an error.
func (Pool) CalcOutAmtGivenIn ¶
func (p Pool) CalcOutAmtGivenIn( ctx sdk.Context, tokensIn sdk.Coins, tokenOutDenom string, swapFee sdk.Dec, ) (sdk.Coin, error)
CalcOutAmtGivenIn calculates tokens to be swapped out given the provided amount and fee deducted, using solveConstantFunctionInvariant.
func (*Pool) CalcTokenInShareAmountOut ¶
func (*Pool) Descriptor ¶
func (*Pool) ExitSwapExactAmountOut ¶
func (Pool) GetAddress ¶
func (p Pool) GetAddress() sdk.AccAddress
GetAddress returns the address of a pool. If the pool address is not bech32 valid, it returns an empty address.
func (Pool) GetAllPoolAssets ¶
func (Pool) GetPoolAsset ¶
GetPoolAssets returns the denom's PoolAsset, If the PoolAsset doesn't exist, will return error. As above, it will search the denom's PoolAsset by using binary search. So, it is important to make sure that the PoolAssets are sorted.
func (Pool) GetPoolParams ¶
func (p Pool) GetPoolParams() PoolParams
func (Pool) GetTotalShares ¶
func (Pool) GetTotalWeight ¶
func (*Pool) IncreaseLiquidity ¶
func (*Pool) JoinPool ¶
func (p *Pool) JoinPool(ctx sdk.Context, tokensIn sdk.Coins, swapFee sdk.Dec) (numShares sdk.Int, err error)
JoinPool calculates the number of shares needed given tokensIn with swapFee applied. It updates the liquidity if the pool is joined successfully. If not, returns error. and updates pool accordingly.
func (*Pool) JoinPoolNoSwap ¶
func (p *Pool) JoinPoolNoSwap(ctx sdk.Context, tokensIn sdk.Coins, swapFee sdk.Dec) (numShares sdk.Int, err error)
JoinPoolNoSwap calculates the number of shares needed for an all-asset join given tokensIn with swapFee applied. It updates the liquidity if the pool is joined successfully. If not, returns error.
func (*Pool) JoinPoolTokenInMaxShareAmountOut ¶
func (Pool) MarshalJSON ¶
MarshalJSON returns the JSON representation of a Pool.
func (*Pool) PokePool ¶
PokePool checks to see if the pool's token weights need to be updated, and if so, does so. Currently doesn't do anything outside out LBPs.
func (*Pool) ProtoMessage ¶
func (*Pool) ProtoMessage()
func (*Pool) SetInitialPoolAssets ¶
SetInitialPoolAssets sets the PoolAssets in the pool. It is only designed to be called at the pool's creation. If the same denom's PoolAsset exists, will return error.
The list of PoolAssets must be sorted. This is done to enable fast searching for a PoolAsset by denomination. TODO: Unify story for validation of []PoolAsset, some is here, some is in CreatePool.ValidateBasic()
func (Pool) SpotPrice ¶
func (p Pool) SpotPrice(ctx sdk.Context, baseAsset, quoteAsset string) (spotPrice sdk.Dec, err error)
SpotPrice returns the spot price of the pool This is the weight-adjusted balance of the tokens in the pool. In order reduce the propagated effect of incorrect trailing digits, we take the ratio of weights and divide this by ratio of supplies this is equivalent to spot_price = (Base_supply / Weight_base) / (Quote_supply / Weight_quote) but cancels out the common term in weight.
panics if the pool in state is incorrect, and has any weight that is 0. TODO: Come back and improve docs for this.
func (*Pool) SubTotalShares ¶
func (*Pool) SwapInAmtGivenOut ¶
func (p *Pool) SwapInAmtGivenOut( ctx sdk.Context, tokensOut sdk.Coins, tokenInDenom string, swapFee sdk.Dec) ( tokenIn sdk.Coin, err error, )
SwapInAmtGivenOut is a mutative method for CalcOutAmtGivenIn, which includes the actual swap.
func (*Pool) SwapOutAmtGivenIn ¶
func (p *Pool) SwapOutAmtGivenIn( ctx sdk.Context, tokensIn sdk.Coins, tokenOutDenom string, swapFee sdk.Dec, ) ( tokenOut sdk.Coin, err error, )
SwapOutAmtGivenIn is a mutative method for CalcOutAmtGivenIn, which includes the actual swap.
func (*Pool) UnmarshalJSON ¶
UnmarshalJSON unmarshals raw JSON bytes into a Pool.
func (*Pool) UpdatePoolAssetBalances ¶
func (*Pool) XXX_DiscardUnknown ¶
func (m *Pool) XXX_DiscardUnknown()
func (*Pool) XXX_Unmarshal ¶
type PoolAsset ¶
type PoolAsset struct { // Coins we are talking about, // the denomination must be unique amongst all PoolAssets for this pool. Token types1.Coin `protobuf:"bytes,1,opt,name=token,proto3" json:"token" yaml:"token"` // Weight that is not normalized. This weight must be less than 2^50 Weight github_com_cosmos_cosmos_sdk_types.Int `protobuf:"bytes,2,opt,name=weight,proto3,customtype=github.com/cosmos/cosmos-sdk/types.Int" json:"weight" yaml:"weight"` }
Pool asset is an internal struct that combines the amount of the token in the pool, and its balancer weight. This is an awkward packaging of data, and should be revisited in a future state migration.
func (*PoolAsset) Descriptor ¶
func (*PoolAsset) MarshalToSizedBuffer ¶
func (PoolAsset) MarshalYAML ¶
MarshalYAML returns the YAML representation of a PoolAsset. This is assumed to not be called on a stand-alone instance, so it removes the first marshalled line.
func (*PoolAsset) ProtoMessage ¶
func (*PoolAsset) ProtoMessage()
func (*PoolAsset) XXX_DiscardUnknown ¶
func (m *PoolAsset) XXX_DiscardUnknown()
func (*PoolAsset) XXX_Marshal ¶
func (*PoolAsset) XXX_Unmarshal ¶
type PoolParams ¶
type PoolParams struct { SwapFee github_com_cosmos_cosmos_sdk_types.Dec `` /* 138-byte string literal not displayed */ ExitFee github_com_cosmos_cosmos_sdk_types.Dec `` /* 138-byte string literal not displayed */ SmoothWeightChangeParams *SmoothWeightChangeParams `` /* 172-byte string literal not displayed */ }
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 NewPoolParams ¶
func NewPoolParams(swapFee, exitFee sdk.Dec, params *SmoothWeightChangeParams) PoolParams
func (*PoolParams) Descriptor ¶
func (*PoolParams) Descriptor() ([]byte, []int)
func (PoolParams) GetPoolExitFee ¶
func (params PoolParams) GetPoolExitFee() sdk.Dec
func (PoolParams) GetPoolSwapFee ¶
func (params PoolParams) GetPoolSwapFee() sdk.Dec
func (*PoolParams) GetSmoothWeightChangeParams ¶
func (m *PoolParams) GetSmoothWeightChangeParams() *SmoothWeightChangeParams
func (*PoolParams) Marshal ¶
func (m *PoolParams) Marshal() (dAtA []byte, err 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(poolWeights []PoolAsset) 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 SmoothWeightChangeParams ¶
type SmoothWeightChangeParams struct { // The start time for beginning the weight change. // If a parameter change / pool instantiation leaves this blank, // it should be generated by the state_machine as the current time. StartTime time.Time `protobuf:"bytes,1,opt,name=start_time,json=startTime,proto3,stdtime" json:"start_time" yaml:"start_time"` // Duration for the weights to change over Duration time.Duration `protobuf:"bytes,2,opt,name=duration,proto3,stdduration" json:"duration,omitempty" yaml:"duration"` // The initial pool weights. These are copied from the pool's settings // at the time of weight change instantiation. // The amount PoolAsset.token.amount field is ignored if present, // future type refactorings should just have a type with the denom & weight // here. InitialPoolWeights []PoolAsset `` /* 135-byte string literal not displayed */ // The target pool weights. The pool weights will change linearly with respect // to time between start_time, and start_time + duration. The amount // PoolAsset.token.amount field is ignored if present, future type // refactorings should just have a type with the denom & weight here. TargetPoolWeights []PoolAsset `` /* 131-byte string literal not displayed */ }
Parameters for changing the weights in a balancer pool smoothly from a start weight and end weight over a period of time. Currently, the only smooth change supported is linear changing between the two weights, but more types may be added in the future. When these parameters are set, the weight w(t) for pool time `t` is the following:
t <= start_time: w(t) = initial_pool_weights start_time < t <= start_time + duration: w(t) = initial_pool_weights + (t - start_time) * (target_pool_weights - initial_pool_weights) / (duration) t > start_time + duration: w(t) = target_pool_weights
func (*SmoothWeightChangeParams) Descriptor ¶
func (*SmoothWeightChangeParams) Descriptor() ([]byte, []int)
func (*SmoothWeightChangeParams) GetDuration ¶
func (m *SmoothWeightChangeParams) GetDuration() time.Duration
func (*SmoothWeightChangeParams) GetInitialPoolWeights ¶
func (m *SmoothWeightChangeParams) GetInitialPoolWeights() []PoolAsset
func (*SmoothWeightChangeParams) GetStartTime ¶
func (m *SmoothWeightChangeParams) GetStartTime() time.Time
func (*SmoothWeightChangeParams) GetTargetPoolWeights ¶
func (m *SmoothWeightChangeParams) GetTargetPoolWeights() []PoolAsset
func (*SmoothWeightChangeParams) Marshal ¶
func (m *SmoothWeightChangeParams) Marshal() (dAtA []byte, err error)
func (*SmoothWeightChangeParams) MarshalTo ¶
func (m *SmoothWeightChangeParams) MarshalTo(dAtA []byte) (int, error)
func (*SmoothWeightChangeParams) MarshalToSizedBuffer ¶
func (m *SmoothWeightChangeParams) MarshalToSizedBuffer(dAtA []byte) (int, error)
func (*SmoothWeightChangeParams) ProtoMessage ¶
func (*SmoothWeightChangeParams) ProtoMessage()
func (*SmoothWeightChangeParams) Reset ¶
func (m *SmoothWeightChangeParams) Reset()
func (*SmoothWeightChangeParams) Size ¶
func (m *SmoothWeightChangeParams) Size() (n int)
func (*SmoothWeightChangeParams) String ¶
func (m *SmoothWeightChangeParams) String() string
func (*SmoothWeightChangeParams) Unmarshal ¶
func (m *SmoothWeightChangeParams) Unmarshal(dAtA []byte) error
func (*SmoothWeightChangeParams) XXX_DiscardUnknown ¶
func (m *SmoothWeightChangeParams) XXX_DiscardUnknown()
func (*SmoothWeightChangeParams) XXX_Marshal ¶
func (m *SmoothWeightChangeParams) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
func (*SmoothWeightChangeParams) XXX_Merge ¶
func (m *SmoothWeightChangeParams) XXX_Merge(src proto.Message)
func (*SmoothWeightChangeParams) XXX_Size ¶
func (m *SmoothWeightChangeParams) XXX_Size() int
func (*SmoothWeightChangeParams) XXX_Unmarshal ¶
func (m *SmoothWeightChangeParams) XXX_Unmarshal(b []byte) error
type UnimplementedMsgServer ¶
type UnimplementedMsgServer struct { }
UnimplementedMsgServer can be embedded to have forward compatible implementations.
func (*UnimplementedMsgServer) CreateBalancerPool ¶
func (*UnimplementedMsgServer) CreateBalancerPool(ctx context.Context, req *MsgCreateBalancerPool) (*MsgCreateBalancerPoolResponse, error)