actions

package
v0.0.0-...-7640ebf Latest Latest
Warning

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

Go to latest
Published: Sep 30, 2024 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const MaxMetadataSize = 256

Variables

View Source
var (
	OutputValueZero              = []byte("value is zero")
	OutputAssetIsNative          = []byte("cannot mint native asset")
	OutputAssetAlreadyExists     = []byte("asset already exists")
	OutputAssetMissing           = []byte("asset missing")
	OutputInTickZero             = []byte("in rate is zero")
	OutputOutTickZero            = []byte("out rate is zero")
	OutputSupplyZero             = []byte("supply is zero")
	OutputSupplyMisaligned       = []byte("supply is misaligned")
	OutputOrderMissing           = []byte("order is missing")
	OutputUnauthorized           = []byte("unauthorized")
	OutputWrongIn                = []byte("wrong in asset")
	OutputWrongOut               = []byte("wrong out asset")
	OutputWrongOwner             = []byte("wrong owner")
	OutputInsufficientInput      = []byte("insufficient input")
	OutputInsufficientOutput     = []byte("insufficient output")
	OutputValueMisaligned        = []byte("value is misaligned")
	OutputMetadataTooLarge       = []byte("metadata is too large")
	OutputSameInOut              = []byte("same asset used for in and out")
	OutputConflictingAsset       = []byte("warp has same asset as another")
	OutputAnycast                = []byte("anycast output")
	OutputNotWarpAsset           = []byte("not warp asset")
	OutputWarpAsset              = []byte("warp asset")
	OutputWrongDestination       = []byte("wrong destination")
	OutputMustFill               = []byte("must fill request")
	OutputWarpVerificationFailed = []byte("warp verification failed")
)
View Source
var ErrNoSwapToFill = errors.New("no swap to fill")

Functions

func ImportedAssetID

func ImportedAssetID(assetID ids.ID, sourceChainID ids.ID) ids.ID

func ImportedAssetMetadata

func ImportedAssetMetadata(assetID ids.ID, sourceChainID ids.ID) []byte

func PairID

func PairID(in ids.ID, out ids.ID) string

func UnmarshalBurnAsset

func UnmarshalBurnAsset(p *codec.Packer, _ *warp.Message) (chain.Action, error)

func UnmarshalCloseOrder

func UnmarshalCloseOrder(p *codec.Packer, _ *warp.Message) (chain.Action, error)

func UnmarshalCreateAsset

func UnmarshalCreateAsset(p *codec.Packer, _ *warp.Message) (chain.Action, error)

func UnmarshalCreateOrder

func UnmarshalCreateOrder(p *codec.Packer, _ *warp.Message) (chain.Action, error)

func UnmarshalExportAsset

func UnmarshalExportAsset(p *codec.Packer, _ *warp.Message) (chain.Action, error)

func UnmarshalFillOrder

func UnmarshalFillOrder(p *codec.Packer, _ *warp.Message) (chain.Action, error)

func UnmarshalImportAsset

func UnmarshalImportAsset(p *codec.Packer, wm *warp.Message) (chain.Action, error)

func UnmarshalMintAsset

func UnmarshalMintAsset(p *codec.Packer, _ *warp.Message) (chain.Action, error)

func UnmarshalModifyAsset

func UnmarshalModifyAsset(p *codec.Packer, _ *warp.Message) (chain.Action, error)

func UnmarshalTransfer

func UnmarshalTransfer(p *codec.Packer, _ *warp.Message) (chain.Action, error)

func ValidSwapParams

func ValidSwapParams(
	value uint64,
	swapIn uint64,
	assetOut ids.ID,
	swapOut uint64,
	swapExpiry int64,
) bool

Types

type BurnAsset

type BurnAsset struct {
	// Asset is the [TxID] that created the asset.
	Asset ids.ID `json:"asset"`

	// Number of assets to mint to [To].
	Value uint64 `json:"value"`
}

func (*BurnAsset) Execute

func (b *BurnAsset) Execute(
	ctx context.Context,
	r chain.Rules,
	db chain.Database,
	_ int64,
	rauth chain.Auth,
	_ ids.ID,
	_ bool,
) (*chain.Result, error)

func (*BurnAsset) Marshal

func (b *BurnAsset) Marshal(p *codec.Packer)

func (*BurnAsset) MaxUnits

func (*BurnAsset) MaxUnits(chain.Rules) uint64

func (*BurnAsset) StateKeys

func (b *BurnAsset) StateKeys(rauth chain.Auth, _ ids.ID) [][]byte

func (*BurnAsset) ValidRange

func (*BurnAsset) ValidRange(chain.Rules) (int64, int64)

type CloseOrder

type CloseOrder struct {
	// [Order] is the OrderID you wish to close.
	Order ids.ID `json:"order"`

	// [Out] is the asset locked up in the order. We need to provide this to
	// populate [StateKeys].
	Out ids.ID `json:"out"`
}

func (*CloseOrder) Execute

func (c *CloseOrder) Execute(
	ctx context.Context,
	r chain.Rules,
	db chain.Database,
	_ int64,
	rauth chain.Auth,
	_ ids.ID,
	_ bool,
) (*chain.Result, error)

func (*CloseOrder) Marshal

func (c *CloseOrder) Marshal(p *codec.Packer)

func (*CloseOrder) MaxUnits

func (*CloseOrder) MaxUnits(chain.Rules) uint64

func (*CloseOrder) StateKeys

func (c *CloseOrder) StateKeys(rauth chain.Auth, _ ids.ID) [][]byte

func (*CloseOrder) ValidRange

func (*CloseOrder) ValidRange(chain.Rules) (int64, int64)

type CreateAsset

type CreateAsset struct {
	// Metadata is creator-specified information about the asset. This can be
	// modified using the [ModifyAsset] action.
	Metadata []byte `json:"metadata"`
}

func (*CreateAsset) Execute

func (c *CreateAsset) Execute(
	ctx context.Context,
	r chain.Rules,
	db chain.Database,
	_ int64,
	rauth chain.Auth,
	txID ids.ID,
	_ bool,
) (*chain.Result, error)

func (*CreateAsset) Marshal

func (c *CreateAsset) Marshal(p *codec.Packer)

func (*CreateAsset) MaxUnits

func (c *CreateAsset) MaxUnits(chain.Rules) uint64

func (*CreateAsset) StateKeys

func (*CreateAsset) StateKeys(_ chain.Auth, txID ids.ID) [][]byte

func (*CreateAsset) ValidRange

func (*CreateAsset) ValidRange(chain.Rules) (int64, int64)

type CreateOrder

type CreateOrder struct {
	// [In] is the asset you trade for [Out].
	In ids.ID `json:"in"`

	// [InTick] is the amount of [In] required to purchase
	// [OutTick] of [Out].
	InTick uint64 `json:"inTick"`

	// [Out] is the asset you receive when trading for [In].
	//
	// This is the asset that is actually provided by the creator.
	Out ids.ID `json:"out"`

	// [OutTick] is the amount of [Out] the counterparty gets per [InTick] of
	// [In].
	OutTick uint64 `json:"outTick"`

	// [Supply] is the initial amount of [In] that the actor is locking up.
	Supply uint64 `json:"supply"`
}

func (*CreateOrder) Execute

func (c *CreateOrder) Execute(
	ctx context.Context,
	r chain.Rules,
	db chain.Database,
	_ int64,
	rauth chain.Auth,
	txID ids.ID,
	_ bool,
) (*chain.Result, error)

func (*CreateOrder) Marshal

func (c *CreateOrder) Marshal(p *codec.Packer)

func (*CreateOrder) MaxUnits

func (*CreateOrder) MaxUnits(chain.Rules) uint64

func (*CreateOrder) StateKeys

func (c *CreateOrder) StateKeys(rauth chain.Auth, txID ids.ID) [][]byte

func (*CreateOrder) ValidRange

func (*CreateOrder) ValidRange(chain.Rules) (int64, int64)

type ExportAsset

type ExportAsset struct {
	To          crypto.PublicKey `json:"to"`
	Asset       ids.ID           `json:"asset"`
	Value       uint64           `json:"value"`
	Return      bool             `json:"return"`
	Reward      uint64           `json:"reward"`
	SwapIn      uint64           `json:"swapIn"`
	AssetOut    ids.ID           `json:"assetOut"`
	SwapOut     uint64           `json:"swapOut"`
	SwapExpiry  int64            `json:"swapExpiry"`
	Destination ids.ID           `json:"destination"`
}

func (*ExportAsset) Execute

func (e *ExportAsset) Execute(
	ctx context.Context,
	r chain.Rules,
	db chain.Database,
	_ int64,
	rauth chain.Auth,
	txID ids.ID,
	_ bool,
) (*chain.Result, error)

func (*ExportAsset) Marshal

func (e *ExportAsset) Marshal(p *codec.Packer)

func (*ExportAsset) MaxUnits

func (*ExportAsset) MaxUnits(chain.Rules) uint64

func (*ExportAsset) StateKeys

func (e *ExportAsset) StateKeys(rauth chain.Auth, _ ids.ID) [][]byte

func (*ExportAsset) ValidRange

func (*ExportAsset) ValidRange(chain.Rules) (int64, int64)

type FillOrder

type FillOrder struct {
	// [Order] is the OrderID you wish to close.
	Order ids.ID `json:"order"`

	// [Owner] is the owner of the order and the recipient of the trade
	// proceeds.
	Owner crypto.PublicKey `json:"owner"`

	// [In] is the asset that will be sent to the owner from the fill. We need to provide this to
	// populate [StateKeys].
	In ids.ID `json:"in"`

	// [Out] is the asset that will be received from the fill. We need to provide this to
	// populate [StateKeys].
	Out ids.ID `json:"out"`

	// [Value] is the max amount of [In] that will be swapped for [Out].
	Value uint64 `json:"value"`
}

func (*FillOrder) Execute

func (f *FillOrder) Execute(
	ctx context.Context,
	_ chain.Rules,
	db chain.Database,
	_ int64,
	rauth chain.Auth,
	_ ids.ID,
	_ bool,
) (*chain.Result, error)

func (*FillOrder) Marshal

func (f *FillOrder) Marshal(p *codec.Packer)

func (*FillOrder) MaxUnits

func (*FillOrder) MaxUnits(chain.Rules) uint64

func (*FillOrder) StateKeys

func (f *FillOrder) StateKeys(rauth chain.Auth, _ ids.ID) [][]byte

func (*FillOrder) ValidRange

func (*FillOrder) ValidRange(chain.Rules) (int64, int64)

type ImportAsset

type ImportAsset struct {
	// Fill indicates if the actor wishes to fill the order request in the warp
	// message. This must be true if the warp message is in a block with
	// a timestamp < [SwapExpiry].
	Fill bool `json:"fill"`
	// contains filtered or unexported fields
}

func (*ImportAsset) Execute

func (i *ImportAsset) Execute(
	ctx context.Context,
	r chain.Rules,
	db chain.Database,
	t int64,
	rauth chain.Auth,
	_ ids.ID,
	warpVerified bool,
) (*chain.Result, error)

func (*ImportAsset) Marshal

func (i *ImportAsset) Marshal(p *codec.Packer)

All we encode that is action specific for now is the type byte from the registry.

func (*ImportAsset) MaxUnits

func (i *ImportAsset) MaxUnits(chain.Rules) uint64

func (*ImportAsset) StateKeys

func (i *ImportAsset) StateKeys(rauth chain.Auth, _ ids.ID) [][]byte

func (*ImportAsset) ValidRange

func (*ImportAsset) ValidRange(chain.Rules) (int64, int64)

type MintAsset

type MintAsset struct {
	// To is the recipient of the [Value].
	To crypto.PublicKey `json:"to"`

	// Asset is the [TxID] that created the asset.
	Asset ids.ID `json:"asset"`

	// Number of assets to mint to [To].
	Value uint64 `json:"value"`
}

func (*MintAsset) Execute

func (m *MintAsset) Execute(
	ctx context.Context,
	r chain.Rules,
	db chain.Database,
	_ int64,
	rauth chain.Auth,
	_ ids.ID,
	_ bool,
) (*chain.Result, error)

func (*MintAsset) Marshal

func (m *MintAsset) Marshal(p *codec.Packer)

func (*MintAsset) MaxUnits

func (*MintAsset) MaxUnits(chain.Rules) uint64

func (*MintAsset) StateKeys

func (m *MintAsset) StateKeys(chain.Auth, ids.ID) [][]byte

func (*MintAsset) ValidRange

func (*MintAsset) ValidRange(chain.Rules) (int64, int64)

type ModifyAsset

type ModifyAsset struct {
	// Asset is the [TxID] that created the asset.
	Asset ids.ID

	// Owner will be the new owner of the [Asset].
	//
	// If you want to retain ownership, set this to the signer. If you want to
	// revoke ownership, set this to another key or the empty public key.
	Owner crypto.PublicKey `json:"owner"`

	// Metadata is the new metadata of the [Asset].
	//
	// If you want this to stay the same, you must set it to be the same value.
	Metadata []byte `json:"metadata"`
}

func (*ModifyAsset) Execute

func (m *ModifyAsset) Execute(
	ctx context.Context,
	r chain.Rules,
	db chain.Database,
	_ int64,
	rauth chain.Auth,
	_ ids.ID,
	_ bool,
) (*chain.Result, error)

func (*ModifyAsset) Marshal

func (m *ModifyAsset) Marshal(p *codec.Packer)

func (*ModifyAsset) MaxUnits

func (m *ModifyAsset) MaxUnits(chain.Rules) uint64

func (*ModifyAsset) StateKeys

func (m *ModifyAsset) StateKeys(chain.Auth, ids.ID) [][]byte

func (*ModifyAsset) ValidRange

func (*ModifyAsset) ValidRange(chain.Rules) (int64, int64)

type OrderResult

type OrderResult struct {
	In        uint64 `json:"in"`
	Out       uint64 `json:"out"`
	Remaining uint64 `json:"remaining"`
}

OrderResult is a custom successful response output that provides information about a successful trade.

func UnmarshalOrderResult

func UnmarshalOrderResult(b []byte) (*OrderResult, error)

func (*OrderResult) Marshal

func (o *OrderResult) Marshal() ([]byte, error)

type Transfer

type Transfer struct {
	// To is the recipient of the [Value].
	To crypto.PublicKey `json:"to"`

	// Asset to transfer to [To].
	Asset ids.ID

	// Amount are transferred to [To].
	Value uint64 `json:"value"`
}

func (*Transfer) Execute

func (t *Transfer) Execute(
	ctx context.Context,
	r chain.Rules,
	db chain.Database,
	_ int64,
	rauth chain.Auth,
	_ ids.ID,
	_ bool,
) (*chain.Result, error)

func (*Transfer) Marshal

func (t *Transfer) Marshal(p *codec.Packer)

func (*Transfer) MaxUnits

func (*Transfer) MaxUnits(chain.Rules) uint64

func (*Transfer) StateKeys

func (t *Transfer) StateKeys(rauth chain.Auth, _ ids.ID) [][]byte

func (*Transfer) ValidRange

func (*Transfer) ValidRange(chain.Rules) (int64, int64)

type WarpTransfer

type WarpTransfer struct {
	To    crypto.PublicKey `json:"to"`
	Asset ids.ID           `json:"asset"`
	Value uint64           `json:"value"`

	// Return is set to true when a warp message is sending funds back to the
	// chain where they were created.
	Return bool `json:"return"`

	// Reward is the amount of [Asset] to send the [Actor] that submits this
	// transaction.
	Reward uint64 `json:"reward"`

	// SwapIn is the amount of [Asset] we are willing to swap for [AssetOut].
	SwapIn uint64 `json:"swapIn"`
	// AssetOut is the asset we are seeking to get for [SwapIn].
	AssetOut ids.ID `json:"assetOut"`
	// SwapOut is the amount of [AssetOut] we are seeking.
	SwapOut uint64 `json:"swapOut"`
	// SwapExpiry is the unix timestamp at which the swap becomes invalid (and
	// the message can be processed without a swap.
	SwapExpiry int64 `json:"swapExpiry"`

	// TxID is the transaction that created this message. This is used to ensure
	// there is WarpID uniqueness.
	TxID ids.ID `json:"txID"`
}

func UnmarshalWarpTransfer

func UnmarshalWarpTransfer(b []byte) (*WarpTransfer, error)

func (*WarpTransfer) Marshal

func (w *WarpTransfer) Marshal() ([]byte, error)

Jump to

Keyboard shortcuts

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