Options
All
  • Public
  • Public/Protected
  • All
Menu
class

Swapable.Swap

package

Swapable

subpackage

Commands

since

v1.0.0

description

Class that describes a command for swapping assets in automated liquidity pools (i.e. "swap").

summary

This automated pool command accepts the following arguments:

Argument Description Example
trader Trader new PublicAccount(...)
input_x Amount and asset identifier of x (first in pair) new AssetAmount(...)
output Asset identifier of y (second in pair). new AssetIdentifier(...)

The execution of this command results in the creation of the following list of transactions with their respective signer and a description:

Sequence Type Signer Description
01 TransferTransaction Trader Account Transfers the input currency to the target account.
02 TransferTransaction Target Account Transfers the output currency to the trader account. Note that the amount that is sent to the trader is automatically calculated.
03 TransferTransaction Target Account Adds an execution proof message sent to the target account.

Hierarchy

Implements

Index

Constructors

constructor

Properties

arguments

arguments: string[] = ['trader','input_x','output',]
access

public

description

The list of required arguments to execute this automated pool command.

context

context: Context

The execution context.

Protected identifier

identifier: AssetIdentifier

The automated pool shares asset identifier.

mosaicInfo

mosaicInfo: MosaicInfo | undefined
access

public

description

Mosaic information for the network-wide created automated pool shares of an automated liquidity pool.

reserveInfo

reserveInfo: AccountInfo | undefined
access

public

description

Account information for the network-wide target public account. This variable holds balances of reserves under the mosaics field.

target

target: PublicAccount
access

public

description

The deterministic public account which owns an automated liquidity pool. This account is used to issue the automated pool shares mosaic.

Accessors

descriptor

  • get descriptor(): string
  • This method MUST return a unique automated pool command descriptor which includes:

    • the open standard descriptor (e.g.: "Swapable") ;
    • the open standard revision (e.g.: 1) ;
    • the kebab-case command name (e.g.: "create-pool") ;
    • and the automated pool shares asset identifier.

    Items are joined with the : operator and attached to a so-called execution proof transaction.

    access

    public

    Returns string

name

  • get name(): string

Protected transactions

  • get transactions(): Transaction[]
  • This method returns a list of unsigned transactions in a sequencial order of execution. The resulting transaction array is later wrapped inside a digital contract that is executed atomically such that either all transactions do succeed or all transactions are cancelled.

    see

    {execute()}

    access

    public

    Returns Transaction[]

    Given the execution of a command, returns a list of unsigned transactions.

Methods

Protected assertExecutionAllowance

  • assertExecutionAllowance(actor: PublicAccount, argv: CommandOption[] | undefined): boolean

Protected assertHasMandatoryArguments

  • assertHasMandatoryArguments(argv: CommandOption[] | undefined, fields: string[]): boolean

canExecute

  • Verifies allowance of \a actor to execute a command with arguments \a argv. This method returns true if all required arguments are present.

    This method asserts the presence of mandatory arguments.

    Additionally, this method asserts that amounts of assets do not overflow in relation with available pool reserves.

    access

    public

    throws

    {FailureMissingArgument} On missing mandatory argument(s).

    Parameters

    • actor: PublicAccount

      The actor is whom executes the command.

    • Optional argv: CommandOption[]

      The command options (arguments).

    Returns AllowanceResult

    Returns whether an actor is authorized to execute this command.

execute

  • execute(actor: PublicAccount, argv?: CommandOption[]): TransactionURI<Transaction>
  • Executes an automated pool command with \a actor given \a argv command options.

    access

    public

    throws

    {FailureMissingArgument} On missing mandatory argument(s).

    throws

    {FailureOperationForbidden} On denial of authorization.

    Parameters

    • actor: PublicAccount

      The actor is whom executes the command.

    • Optional argv: CommandOption[]

      The command options (arguments).

    Returns TransactionURI<Transaction>

    Returns one transaction URI with all transactions.

Protected prepare

  • prepare(): AggregateTransaction | Transaction

Protected reserveOf

  • Returns the available reserve of asset \a r. This method is used internally to determine the available balance in the automated pool and calculate the liquidity shares ratio.

    access

    protected

    Parameters

    • r: AssetIdentifier

      The asset identifier (i.e. for which to check reserves).

    Returns number

    number The total balance (reserve) available.

Generated using TypeDoc