txs

package
v1.22.21 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2025 License: BSD-3-Clause Imports: 4 Imported by: 0

Documentation

Overview

Package txs defines transaction types for the DEX VM.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidSignature  = errors.New("invalid signature")
	ErrInvalidTxType     = errors.New("invalid transaction type")
	ErrInvalidAmount     = errors.New("invalid amount")
	ErrInvalidPrice      = errors.New("invalid price")
	ErrInsufficientFunds = errors.New("insufficient funds")
)

Functions

This section is empty.

Types

type AddLiquidityTx

type AddLiquidityTx struct {
	BaseTx
	PoolID       ids.ID `json:"poolId"`
	Token0Amount uint64 `json:"token0Amount"`
	Token1Amount uint64 `json:"token1Amount"`
	MinLPTokens  uint64 `json:"minLPTokens"`
	Deadline     int64  `json:"deadline"`
}

AddLiquidityTx represents adding liquidity to a pool.

func NewAddLiquidityTx

func NewAddLiquidityTx(
	from ids.ShortID,
	nonce uint64,
	poolID ids.ID,
	token0Amount, token1Amount, minLPTokens uint64,
) *AddLiquidityTx

NewAddLiquidityTx creates a new add liquidity transaction.

func (*AddLiquidityTx) Verify

func (tx *AddLiquidityTx) Verify() error

type BaseTx

type BaseTx struct {
	TxID      ids.ID      `json:"id"`
	TxType    TxType      `json:"type"`
	From      ids.ShortID `json:"from"`
	Nonce     uint64      `json:"nonce"`
	GasPrice  uint64      `json:"gasPrice"`
	GasLimit  uint64      `json:"gasLimit"`
	CreatedAt int64       `json:"createdAt"`
	Signature []byte      `json:"signature"`
	// contains filtered or unexported fields
}

BaseTx contains common fields for all transactions.

func (*BaseTx) Bytes

func (tx *BaseTx) Bytes() []byte

func (*BaseTx) ID

func (tx *BaseTx) ID() ids.ID

func (*BaseTx) Sender

func (tx *BaseTx) Sender() ids.ShortID

func (*BaseTx) Timestamp

func (tx *BaseTx) Timestamp() int64

func (*BaseTx) Type

func (tx *BaseTx) Type() TxType

type CancelOrderTx

type CancelOrderTx struct {
	BaseTx
	OrderID ids.ID `json:"orderId"`
	Symbol  string `json:"symbol"`
}

CancelOrderTx represents a cancel order transaction.

func NewCancelOrderTx

func NewCancelOrderTx(from ids.ShortID, nonce uint64, orderID ids.ID, symbol string) *CancelOrderTx

NewCancelOrderTx creates a new cancel order transaction.

func (*CancelOrderTx) Verify

func (tx *CancelOrderTx) Verify() error

type CreatePoolTx

type CreatePoolTx struct {
	BaseTx
	Token0        ids.ID `json:"token0"`
	Token1        ids.ID `json:"token1"`
	PoolType      uint8  `json:"poolType"` // 0 = ConstantProduct, 1 = StableSwap, 2 = Concentrated
	SwapFeeBps    uint16 `json:"swapFeeBps"`
	InitialToken0 uint64 `json:"initialToken0"`
	InitialToken1 uint64 `json:"initialToken1"`
	// For concentrated liquidity
	TickLower int32 `json:"tickLower"`
	TickUpper int32 `json:"tickUpper"`
}

CreatePoolTx represents creating a new liquidity pool.

func NewCreatePoolTx

func NewCreatePoolTx(
	from ids.ShortID,
	nonce uint64,
	token0, token1 ids.ID,
	poolType uint8,
	swapFeeBps uint16,
	initialToken0, initialToken1 uint64,
) *CreatePoolTx

NewCreatePoolTx creates a new create pool transaction.

func (*CreatePoolTx) Verify

func (tx *CreatePoolTx) Verify() error

type CrossChainSwapTx

type CrossChainSwapTx struct {
	BaseTx
	SourceChain   ids.ID      `json:"sourceChain"`
	DestChain     ids.ID      `json:"destChain"`
	TokenIn       ids.ID      `json:"tokenIn"`
	TokenOut      ids.ID      `json:"tokenOut"`
	AmountIn      uint64      `json:"amountIn"`
	MinAmountOut  uint64      `json:"minAmountOut"`
	Recipient     ids.ShortID `json:"recipient"`
	WarpMessageID ids.ID      `json:"warpMessageId"`
	Deadline      int64       `json:"deadline"`
}

CrossChainSwapTx represents a cross-chain atomic swap via Warp.

func (*CrossChainSwapTx) Verify

func (tx *CrossChainSwapTx) Verify() error

type CrossChainTransferTx

type CrossChainTransferTx struct {
	BaseTx
	SourceChain   ids.ID      `json:"sourceChain"`
	DestChain     ids.ID      `json:"destChain"`
	Token         ids.ID      `json:"token"`
	Amount        uint64      `json:"amount"`
	Recipient     ids.ShortID `json:"recipient"`
	WarpMessageID ids.ID      `json:"warpMessageId"`
}

CrossChainTransferTx represents a cross-chain token transfer via Warp.

func (*CrossChainTransferTx) Verify

func (tx *CrossChainTransferTx) Verify() error

type PlaceOrderTx

type PlaceOrderTx struct {
	BaseTx
	Symbol      string `json:"symbol"`
	Side        uint8  `json:"side"`      // 0 = Buy, 1 = Sell
	OrderType   uint8  `json:"orderType"` // 0 = Limit, 1 = Market, etc.
	Price       uint64 `json:"price"`
	Quantity    uint64 `json:"quantity"`
	StopPrice   uint64 `json:"stopPrice"`
	PostOnly    bool   `json:"postOnly"`
	ReduceOnly  bool   `json:"reduceOnly"`
	TimeInForce string `json:"timeInForce"` // GTC, IOC, FOK
	ExpiresAt   int64  `json:"expiresAt"`
}

PlaceOrderTx represents a place order transaction.

func NewPlaceOrderTx

func NewPlaceOrderTx(
	from ids.ShortID,
	nonce uint64,
	symbol string,
	side uint8,
	orderType uint8,
	price, quantity uint64,
	timeInForce string,
) *PlaceOrderTx

NewPlaceOrderTx creates a new place order transaction.

func (*PlaceOrderTx) Verify

func (tx *PlaceOrderTx) Verify() error

type RemoveLiquidityTx

type RemoveLiquidityTx struct {
	BaseTx
	PoolID        ids.ID `json:"poolId"`
	LPTokenAmount uint64 `json:"lpTokenAmount"`
	MinToken0     uint64 `json:"minToken0"`
	MinToken1     uint64 `json:"minToken1"`
	Deadline      int64  `json:"deadline"`
}

RemoveLiquidityTx represents removing liquidity from a pool.

func NewRemoveLiquidityTx

func NewRemoveLiquidityTx(
	from ids.ShortID,
	nonce uint64,
	poolID ids.ID,
	lpTokenAmount, minToken0, minToken1 uint64,
) *RemoveLiquidityTx

NewRemoveLiquidityTx creates a new remove liquidity transaction.

func (*RemoveLiquidityTx) Verify

func (tx *RemoveLiquidityTx) Verify() error

type SwapTx

type SwapTx struct {
	BaseTx
	PoolID       ids.ID `json:"poolId"`
	TokenIn      ids.ID `json:"tokenIn"`
	TokenOut     ids.ID `json:"tokenOut"`
	AmountIn     uint64 `json:"amountIn"`
	MinAmountOut uint64 `json:"minAmountOut"`
	MaxSlippage  uint16 `json:"maxSlippage"` // In basis points
	Deadline     int64  `json:"deadline"`
}

SwapTx represents an AMM swap transaction.

func NewSwapTx

func NewSwapTx(
	from ids.ShortID,
	nonce uint64,
	poolID ids.ID,
	tokenIn, tokenOut ids.ID,
	amountIn, minAmountOut uint64,
	maxSlippage uint16,
) *SwapTx

NewSwapTx creates a new swap transaction.

func (*SwapTx) Verify

func (tx *SwapTx) Verify() error

type Tx

type Tx interface {
	// ID returns the unique identifier for this transaction.
	ID() ids.ID
	// Type returns the transaction type.
	Type() TxType
	// Sender returns the sender's address.
	Sender() ids.ShortID
	// Timestamp returns when the transaction was created.
	Timestamp() int64
	// Bytes returns the serialized transaction.
	Bytes() []byte
	// Verify validates the transaction.
	Verify() error
}

Tx is the interface for all DEX transactions.

type TxParser

type TxParser struct{}

TxParser parses raw transaction bytes.

func (*TxParser) Parse

func (p *TxParser) Parse(data []byte) (Tx, error)

Parse parses a transaction from bytes.

type TxType

type TxType uint8

TxType represents the type of transaction.

const (
	TxPlaceOrder TxType = iota
	TxCancelOrder
	TxSwap
	TxAddLiquidity
	TxRemoveLiquidity
	TxCreatePool
	TxCrossChainSwap
	TxCrossChainTransfer
)

func (TxType) String

func (t TxType) String() string

Jump to

Keyboard shortcuts

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