types

package
v0.0.0-...-c763619 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2023 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultCodespace = ModuleName

	CodeNonExistSwapTokenPair                   uint32 = 65000
	CodeNonExistPoolToken                       uint32 = 65001
	CodeMintCoinsFailed                         uint32 = 65002
	CodeSendCoinsFromAccountToModule            uint32 = 65003
	CodeBaseAmountNameBiggerThanQuoteAmountName uint32 = 65004
	CodeValidateSwapAmountName                  uint32 = 65005
	CodeBaseNameEqualQuoteName                  uint32 = 65006
	CodeValidateDenom                           uint32 = 65007
	CodeNotAllowedOriginSymbol                  uint32 = 65008
	CodeInsufficientPoolToken                   uint32 = 65009
	CodeTokenNotExist                           uint32 = 65010
	CodeInvalidCoins                            uint32 = 65011
	CodeInvalidTokenPair                        uint32 = 65012
	CodeAddressIsRequire                        uint32 = 65013
	CodeIsZeroValue                             uint32 = 65014
	CodeBlockTimeBigThanDeadline                uint32 = 65015
	CodeLessThan                                uint32 = 65016
	CodeMintPoolTokenFailed                     uint32 = 65017
	CodeSendCoinsFromPoolToAccountFailed        uint32 = 65018
	CodeBurnPoolTokenFailed                     uint32 = 65019
	CodeSendCoinsToPoolFailed                   uint32 = 65020
	CodeSwapUnknownMsgType                      uint32 = 65021
	CodeSwapUnknownQueryTypes                   uint32 = 65022
	CodeSellAmountOrBuyTokenIsEmpty             uint32 = 65023
	CodeSellAmountEqualBuyToken                 uint32 = 65024
	CodeQueryParamsAddressIsEmpty               uint32 = 65025
	CodeQueryParamsQuoteTokenAmountIsEmpty      uint32 = 65026
	CodeQueryParamsBaseTokenIsEmpty             uint32 = 65027
	CodeMinLiquidityIsNegative                  uint32 = 65028
	CodeMaxBaseAmountOrQuoteAmountIsNegative    uint32 = 65029
	CodeMaxBaseAmount                           uint32 = 65030
	CodeQuoteAmount                             uint32 = 65031
	CodeMinBaseAmount                           uint32 = 65032
	CodeMinQuoteAmount                          uint32 = 65033
	CodeSoldTokenAmountIsNegative               uint32 = 65034
	CodeToken0NameEqualToken1Name               uint32 = 65035
	CodeSoldTokenAmount                         uint32 = 65036
	CodeMinBoughtTokenAmount                    uint32 = 65037
	CodeConvertSellTokenAmount                  uint32 = 65038
	CodeConvertQuoteTokenAmount                 uint32 = 65039
	CodeSendCoinsFailed                         uint32 = 65040
	CodeMsgDeadlineLessThanBlockTime            uint32 = 65041
	CodeBaseTokensAmountBiggerThanMax           uint32 = 65042
	CodeIsSwapTokenPairExist                    uint32 = 65043
	CodeIsPoolTokenPairExist                    uint32 = 65044
	CodeInternalError                           uint32 = 65045
)
View Source
const (
	// ModuleName is the name of the module
	ModuleName = "ammswap"

	// StoreKey to be used when creating the KVStore
	StoreKey = ModuleName

	// RouterKey to be used for routing msgs
	RouterKey = ModuleName

	// QuerierRoute to be used for querier msgs
	QuerierRoute = ModuleName

	// QuerySwapTokenPair query endpoints supported by the swap Querier
	QuerySwapTokenPair         = "swapTokenPair"
	QuerySwapTokenPairs        = "swapTokenPairs"
	QueryRedeemableAssets      = "queryRedeemableAssets"
	QueryParams                = "params"
	QueryBuyAmount             = "buy"
	QuerySwapQuoteInfo         = "swapQuoteInfo"
	QuerySwapAddLiquidityQuote = "swapAddLiquidityQuote"
)
View Source
const (
	TypeMsgAddLiquidity = "add_liquidity"
	TypeMsgTokenSwap    = "token_swap"
)

PoolSwap message types and routes

View Source
const (
	DefaultParamspace = ModuleName

	GenerateTokenType = 2
)

Default parameter namespace

View Source
const (
	AttributeValueCategory = ModuleName
)

ammswap module event types

View Source
const PoolTokenPrefix = "ammswap_"

PoolTokenPrefix defines pool token prefix name

View Source
const TestBasePooledToken = "aab"

nolint

View Source
const TestBasePooledToken2 = "ccb"
View Source
const TestBasePooledToken3 = "ddb"
View Source
const TestQuotePooledToken = common.NativeToken
View Source
const TestSwapTokenPairName = TestBasePooledToken + "_" + TestQuotePooledToken

Variables

View Source
var (
	KeyFeeRate = []byte("FeeRate")
)

Parameter store keys

View Source
var ModuleCdc *codec.Codec

ModuleCdc defines the module codec

View Source
var (
	// TokenPairPrefixKey to be used for KVStore
	TokenPairPrefixKey = []byte{0x01}
)

Functions

func CreateTestMsgs

func CreateTestMsgs(addr sdk.AccAddress) []sdk.Msg

func ErrAddressIsRequire

func ErrAddressIsRequire(msg string) sdk.EnvelopedErr

func ErrBaseAmountNameBiggerThanQuoteAmountName

func ErrBaseAmountNameBiggerThanQuoteAmountName() sdk.EnvelopedErr

func ErrBaseNameEqualQuoteName

func ErrBaseNameEqualQuoteName() sdk.EnvelopedErr

func ErrBaseTokensAmountBiggerThanMax

func ErrBaseTokensAmountBiggerThanMax() sdk.EnvelopedErr

func ErrBlockTimeBigThanDeadline

func ErrBlockTimeBigThanDeadline() sdk.EnvelopedErr

func ErrBurnPoolTokenFailed

func ErrBurnPoolTokenFailed(err error) sdk.EnvelopedErr

func ErrCodeMinCoinsFailed

func ErrCodeMinCoinsFailed(err error) sdk.EnvelopedErr

func ErrConvertQuoteTokenAmount

func ErrConvertQuoteTokenAmount(quoteTokenAmount string, err error) sdk.EnvelopedErr

func ErrConvertSellTokenAmount

func ErrConvertSellTokenAmount(sellTokenAmount string, err error) sdk.EnvelopedErr

func ErrInsufficientPoolToken

func ErrInsufficientPoolToken() sdk.EnvelopedErr

func ErrInvalidCoins

func ErrInvalidCoins() sdk.EnvelopedErr

func ErrInvalidTokenPair

func ErrInvalidTokenPair(swapTokenPair string) sdk.EnvelopedErr

func ErrIsZeroValue

func ErrIsZeroValue(msg string) sdk.EnvelopedErr

func ErrLessThan

func ErrLessThan(param1 string, param2 string) sdk.EnvelopedErr

func ErrMaxBaseAmount

func ErrMaxBaseAmount() sdk.EnvelopedErr

func ErrMaxBaseAmountOrQuoteAmountIsNegative

func ErrMaxBaseAmountOrQuoteAmountIsNegative() sdk.EnvelopedErr

func ErrMinBaseAmount

func ErrMinBaseAmount() sdk.EnvelopedErr

func ErrMinBoughtTokenAmount

func ErrMinBoughtTokenAmount() sdk.EnvelopedErr

func ErrMinLiquidityIsNegative

func ErrMinLiquidityIsNegative() sdk.EnvelopedErr

func ErrMinQuoteAmount

func ErrMinQuoteAmount() sdk.EnvelopedErr

func ErrMintPoolTokenFailed

func ErrMintPoolTokenFailed(err error) sdk.EnvelopedErr

func ErrMsgDeadlineLessThanBlockTime

func ErrMsgDeadlineLessThanBlockTime() sdk.EnvelopedErr

func ErrNonExistPoolToken

func ErrNonExistPoolToken(token string) sdk.EnvelopedErr

func ErrNonExistSwapTokenPair

func ErrNonExistSwapTokenPair(tokenPairName string) sdk.EnvelopedErr

func ErrNotAllowedOriginSymbol

func ErrNotAllowedOriginSymbol() sdk.EnvelopedErr

func ErrPoolTokenPairExist

func ErrPoolTokenPairExist() sdk.EnvelopedErr

func ErrQueryParamsAddressIsEmpty

func ErrQueryParamsAddressIsEmpty() sdk.EnvelopedErr

func ErrQueryParamsBaseTokenIsEmpty

func ErrQueryParamsBaseTokenIsEmpty() sdk.EnvelopedErr

func ErrQueryParamsQuoteTokenAmountIsEmpty

func ErrQueryParamsQuoteTokenAmountIsEmpty() sdk.EnvelopedErr

func ErrQuoteAmount

func ErrQuoteAmount() sdk.EnvelopedErr

func ErrSellAmountEqualBuyToken

func ErrSellAmountEqualBuyToken() sdk.EnvelopedErr

func ErrSellAmountOrBuyTokenIsEmpty

func ErrSellAmountOrBuyTokenIsEmpty() sdk.EnvelopedErr

func ErrSendCoinsFailed

func ErrSendCoinsFailed(err error) sdk.EnvelopedErr

func ErrSendCoinsFromAccountToModule

func ErrSendCoinsFromAccountToModule(err error) sdk.EnvelopedErr

func ErrSendCoinsFromPoolToAccountFailed

func ErrSendCoinsFromPoolToAccountFailed(msg string) sdk.EnvelopedErr

func ErrSendCoinsToPoolFailed

func ErrSendCoinsToPoolFailed(msg string) sdk.EnvelopedErr

func ErrSoldTokenAmount

func ErrSoldTokenAmount() sdk.EnvelopedErr

func ErrSoldTokenAmountIsNegative

func ErrSoldTokenAmountIsNegative() sdk.EnvelopedErr

func ErrSwapTokenPairExist

func ErrSwapTokenPairExist() sdk.EnvelopedErr

func ErrSwapUnknownMsgType

func ErrSwapUnknownMsgType() sdk.EnvelopedErr

func ErrSwapUnknownQueryType

func ErrSwapUnknownQueryType() sdk.EnvelopedErr

func ErrToken0NameEqualToken1Name

func ErrToken0NameEqualToken1Name() sdk.EnvelopedErr

func ErrTokenNotExist

func ErrTokenNotExist() sdk.EnvelopedErr

func ErrValidateDenom

func ErrValidateDenom(tokenName string) sdk.EnvelopedErr

func ErrValidateSwapAmountName

func ErrValidateSwapAmountName() sdk.EnvelopedErr

func GetBaseQuoteTokenName

func GetBaseQuoteTokenName(token0, token1 string) (string, string)

func GetPoolTokenName

func GetPoolTokenName(token1, token2 string) string

func GetSwapTokenPairName

func GetSwapTokenPairName(token0, token1 string) string

func GetTokenPairKey

func GetTokenPairKey(key string) []byte

nolint

func InitPoolToken

func InitPoolToken(poolTokenName string) token.Token

InitPoolToken default pool token

func IsPoolToken

func IsPoolToken(symbol string) bool

func ParamKeyTable

func ParamKeyTable() params.KeyTable

ParamKeyTable for swap module

func RegisterCodec

func RegisterCodec(cdc *codec.Codec)

RegisterCodec registers concrete types on codec

func SetTestTokens

func SetTestTokens(ctx sdk.Context, tokenKeeper token.Keeper, supplyKeeper supply.Keeper, addr sdk.AccAddress, coins sdk.DecCoins) error

func SplitPoolToken

func SplitPoolToken(symbol string) (token0, token1 string)

func ValidateBaseAndQuoteAmount

func ValidateBaseAndQuoteAmount(baseAmountName, quoteAmountName string) error

func ValidateSwapAmountName

func ValidateSwapAmountName(amountName string) error

Types

type BackendKeeper

type BackendKeeper interface {
	OnSwapToken(ctx sdk.Context, address sdk.AccAddress, swapTokenPair SwapTokenPair, sellAmount sdk.SysCoin, buyAmount sdk.SysCoin)
	OnSwapCreateExchange(ctx sdk.Context, swapTokenPair SwapTokenPair)
}

type BankKeeper

type BankKeeper interface {
	SubtractCoins(ctx sdk.Context, addr sdk.AccAddress, amt sdk.Coins) (sdk.Coins, error)
	SendCoins(ctx sdk.Context, fromAddr sdk.AccAddress, toAddr sdk.AccAddress, amt sdk.Coins) error
}

BankKeeper defines the expected bank interface

type MsgAddLiquidity

type MsgAddLiquidity struct {
	MinLiquidity  sdk.Dec        `json:"min_liquidity"`   // Minimum number of sender will mint if total pool token supply is greater than 0.
	MaxBaseAmount sdk.SysCoin    `json:"max_base_amount"` // Maximum number of tokens deposited. Deposits max amount if total pool token supply is 0.
	QuoteAmount   sdk.SysCoin    `json:"quote_amount"`    // Quote token amount
	Deadline      int64          `json:"deadline"`        // Time after which this transaction can no longer be executed.
	Sender        sdk.AccAddress `json:"sender"`          // Sender
}

MsgAddLiquidity Deposit quote_amount and base_amount at current ratio to mint pool tokens.

func NewMsgAddLiquidity

func NewMsgAddLiquidity(minLiquidity sdk.Dec, maxBaseAmount, quoteAmount sdk.SysCoin, deadline int64, sender sdk.AccAddress) MsgAddLiquidity

NewMsgAddLiquidity is a constructor function for MsgAddLiquidity

func (MsgAddLiquidity) GetSignBytes

func (msg MsgAddLiquidity) GetSignBytes() []byte

GetSignBytes encodes the message for signing

func (MsgAddLiquidity) GetSigners

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

GetSigners defines whose signature is required

func (MsgAddLiquidity) GetSwapTokenPairName

func (msg MsgAddLiquidity) GetSwapTokenPairName() string

GetSwapTokenPair defines token pair

func (MsgAddLiquidity) Route

func (msg MsgAddLiquidity) Route() string

Route should return the name of the module

func (MsgAddLiquidity) Type

func (msg MsgAddLiquidity) Type() string

Type should return the action

func (MsgAddLiquidity) ValidateBasic

func (msg MsgAddLiquidity) ValidateBasic() sdk.Error

ValidateBasic runs stateless checks on the message

type MsgCreateExchange

type MsgCreateExchange struct {
	Token0Name string         `json:"token0_name"`
	Token1Name string         `json:"token1_name"`
	Sender     sdk.AccAddress `json:"sender"` // Sender
}

MsgCreateExchange creates a new exchange with token

func NewMsgCreateExchange

func NewMsgCreateExchange(token0Name string, token1Name string, sender sdk.AccAddress) MsgCreateExchange

NewMsgCreateExchange create a new exchange with token

func (MsgCreateExchange) GetSignBytes

func (msg MsgCreateExchange) GetSignBytes() []byte

GetSignBytes encodes the message for signing

func (MsgCreateExchange) GetSigners

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

GetSigners defines whose signature is required

func (MsgCreateExchange) GetSwapTokenPairName

func (msg MsgCreateExchange) GetSwapTokenPairName() string

GetSwapTokenPair defines token pair

func (MsgCreateExchange) Route

func (msg MsgCreateExchange) Route() string

Route should return the name of the module

func (MsgCreateExchange) Type

func (msg MsgCreateExchange) Type() string

Type should return the action

func (MsgCreateExchange) ValidateBasic

func (msg MsgCreateExchange) ValidateBasic() sdk.Error

ValidateBasic runs stateless checks on the message

type MsgRemoveLiquidity

type MsgRemoveLiquidity struct {
	Liquidity      sdk.Dec        `json:"liquidity"`        // Amount of pool token burned.
	MinBaseAmount  sdk.SysCoin    `json:"min_base_amount"`  // Minimum base amount.
	MinQuoteAmount sdk.SysCoin    `json:"min_quote_amount"` // Minimum quote amount.
	Deadline       int64          `json:"deadline"`         // Time after which this transaction can no longer be executed.
	Sender         sdk.AccAddress `json:"sender"`           // Sender
}

MsgRemoveLiquidity burns pool tokens to withdraw fibo and Tokens at current ratio.

func NewMsgRemoveLiquidity

func NewMsgRemoveLiquidity(liquidity sdk.Dec, minBaseAmount, minQuoteAmount sdk.SysCoin, deadline int64, sender sdk.AccAddress) MsgRemoveLiquidity

NewMsgRemoveLiquidity is a constructor function for MsgAddLiquidity

func (MsgRemoveLiquidity) GetSignBytes

func (msg MsgRemoveLiquidity) GetSignBytes() []byte

GetSignBytes encodes the message for signing

func (MsgRemoveLiquidity) GetSigners

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

GetSigners defines whose signature is required

func (MsgRemoveLiquidity) GetSwapTokenPairName

func (msg MsgRemoveLiquidity) GetSwapTokenPairName() string

GetSwapTokenPair defines token pair

func (MsgRemoveLiquidity) Route

func (msg MsgRemoveLiquidity) Route() string

Route should return the name of the module

func (MsgRemoveLiquidity) Type

func (msg MsgRemoveLiquidity) Type() string

Type should return the action

func (MsgRemoveLiquidity) ValidateBasic

func (msg MsgRemoveLiquidity) ValidateBasic() sdk.Error

ValidateBasic runs stateless checks on the message

type MsgTokenToToken

type MsgTokenToToken struct {
	SoldTokenAmount      sdk.SysCoin    `json:"sold_token_amount"`       // Amount of Tokens sold.
	MinBoughtTokenAmount sdk.SysCoin    `json:"min_bought_token_amount"` // Minimum token purchased.
	Deadline             int64          `json:"deadline"`                // Time after which this transaction can no longer be executed.
	Recipient            sdk.AccAddress `json:"recipient"`               // Recipient address,transfer Tokens to recipient.default recipient is sender.
	Sender               sdk.AccAddress `json:"sender"`                  // Sender
}

MsgTokenToToken define the message for swap between token and DefaultBondDenom

func NewMsgTokenToToken

func NewMsgTokenToToken(
	soldTokenAmount, minBoughtTokenAmount sdk.SysCoin, deadline int64, recipient, sender sdk.AccAddress,
) MsgTokenToToken

NewMsgTokenToToken is a constructor function for MsgTokenfiboSwap

func (MsgTokenToToken) GetSignBytes

func (msg MsgTokenToToken) GetSignBytes() []byte

GetSignBytes encodes the message for signing

func (MsgTokenToToken) GetSigners

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

GetSigners defines whose signature is required

func (MsgTokenToToken) GetSwapTokenPairName

func (msg MsgTokenToToken) GetSwapTokenPairName() string

GetSwapTokenPair defines token pair

func (MsgTokenToToken) Route

func (msg MsgTokenToToken) Route() string

Route should return the name of the module

func (MsgTokenToToken) Type

func (msg MsgTokenToToken) Type() string

Type should return the action

func (MsgTokenToToken) ValidateBasic

func (msg MsgTokenToToken) ValidateBasic() sdk.Error

ValidateBasic runs stateless checks on the message

type ParamSubspace

type ParamSubspace interface {
	WithKeyTable(table params.KeyTable) params.Subspace
	Get(ctx sdk.Context, key []byte, ptr interface{})
	GetParamSet(ctx sdk.Context, ps params.ParamSet)
	SetParamSet(ctx sdk.Context, ps params.ParamSet)
}

ParamSubspace defines the expected Subspace interface

type Params

type Params struct {
	FeeRate sdk.Dec `json:"fee_rate"`
}

Params - used for initializing default parameter for swap at genesis

func DefaultParams

func DefaultParams() Params

DefaultParams defines the parameters for this module

func NewParams

func NewParams(feeRate sdk.Dec) Params

NewParams creates a new Params object

func (*Params) ParamSetPairs

func (p *Params) ParamSetPairs() params.ParamSetPairs

ParamSetPairs implements params.ParamSet

func (Params) String

func (p Params) String() string

String implements the stringer interface for Params

type QueryBuyAmountParams

type QueryBuyAmountParams struct {
	SoldToken  sdk.SysCoin
	TokenToBuy string
}

type QuerySwapAddInfoParams

type QuerySwapAddInfoParams struct {
	QuoteTokenAmount string `json:"quote_token_amount"`
	BaseToken        string `json:"base_token"`
}

nolint

func NewQuerySwapAddInfoParams

func NewQuerySwapAddInfoParams(quoteTokenAmount string, baseToken string) QuerySwapAddInfoParams

NewQuerySwapAddInfoParams creates a new instance of QuerySwapAddInfoParams

type QuerySwapBuyInfoParams

type QuerySwapBuyInfoParams struct {
	SellTokenAmount string `json:"sell_token_amount"`
	BuyToken        string `json:"buy_token"`
}

nolint

func NewQuerySwapBuyInfoParams

func NewQuerySwapBuyInfoParams(sellTokenAmount string, buyToken string) QuerySwapBuyInfoParams

NewQuerySwapBuyInfoParams creates a new instance of QuerySwapBuyInfoParams

type SupplyKeeper

type SupplyKeeper interface {
	GetSupplyByDenom(ctx sdk.Context, denom string) sdk.Dec
	SendCoinsFromModuleToAccount(ctx sdk.Context, senderModule string,
		recipientAddr sdk.AccAddress, amt sdk.Coins) sdk.Error
	SendCoinsFromAccountToModule(ctx sdk.Context, senderAddr sdk.AccAddress,
		recipientModule string, amt sdk.Coins) sdk.Error
	MintCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) sdk.Error
	BurnCoins(ctx sdk.Context, moduleName string, amt sdk.Coins) sdk.Error
}

SupplyKeeper defines the expected supply interface

type SwapAddInfo

type SwapAddInfo struct {
	BaseTokenAmount sdk.Dec `json:"base_token_amount"`
	PoolShare       sdk.Dec `json:"pool_share"`
	Liquidity       sdk.Dec `json:"liquidity"`
}

type SwapBuyInfo

type SwapBuyInfo struct {
	BuyAmount   sdk.Dec `json:"buy_amount"`
	Price       sdk.Dec `json:"price"`
	PriceImpact sdk.Dec `json:"price_impact"`
	Fee         string  `json:"fee"`
	Route       string  `json:"route"`
}

type SwapTokenPair

type SwapTokenPair struct {
	QuotePooledCoin sdk.SysCoin `json:"quote_pooled_coin"` // The volume of quote token in the token pair exchange pool
	BasePooledCoin  sdk.SysCoin `json:"base_pooled_coin"`  // The volume of base token in the token pair exchange pool
	PoolTokenName   string      `json:"pool_token_name"`   // The name of pool token
}

SwapTokenPair defines token pair exchange

func GetTestSwapTokenPair

func GetTestSwapTokenPair() SwapTokenPair

GetTestSwapTokenPair just for test

func NewSwapPair

func NewSwapPair(token0, token1 string) SwapTokenPair

func NewSwapTokenPair

func NewSwapTokenPair(quotePooledCoin sdk.SysCoin, basePooledCoin sdk.SysCoin, poolTokenName string) *SwapTokenPair

NewSwapTokenPair is a constructor function for SwapTokenPair

func (SwapTokenPair) String

func (s SwapTokenPair) String() string

String implement fmt.Stringer

func (SwapTokenPair) TokenPairName

func (s SwapTokenPair) TokenPairName() string

TokenPairName defines token pair

type TokenKeeper

type TokenKeeper interface {
	GetTokenInfo(ctx sdk.Context, symbol string) token.Token
	NewToken(ctx sdk.Context, token token.Token)
	UpdateToken(ctx sdk.Context, token token.Token)
	GetCoins(ctx sdk.Context, addr sdk.AccAddress) sdk.SysCoins
	TokenExist(ctx sdk.Context, symbol string) bool
	GetTokensInfo(ctx sdk.Context) (tokens []token.Token)
}

TokenKeeper defines the expected token interface

Jump to

Keyboard shortcuts

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