Options
All
  • Public
  • Public/Protected
  • All
Menu

Class AutomatedPool

class

Swapable.AutomatedPool

package

standards

since

v1.0.0

description

Generic class to describe Swapable digital assets.

Swapable assets consist in combining two cryptocurrencies in a liquidity pool to define an invariant k using a constant product formula of: x * y = k where x and y represent the cryptocurrencies that are paired in said liquidity pool.

A swapable asset may be paired with any other cryptocurrency provided that they reside on the same blockchain network.

Liquidity providers add liquidity into pools and Traders can swap currencies. A fee is added to each trade at the rate of 0.30% which are then added to token reserves. Providers can withdraw their shares of the total reserve at any time.

When liquidity is added by a provider, they will be assigned some Pool Shares. Those shares can then be burned at any time by providers in order to take back their part of pooled assets.

example

Create a liquidity pool

import { DigitalMarket, dHealth } from '@ubcdigital/swapable';

const market = new DigitalMarket(
  'DHP:wXYM',
  new dHealth.Reader(
    'http://dual-01.dhealth.cloud:3000',
     NetworkType.MAIN_NET,
     'ED5761EA890A096C50D3F50B7C2F0CCB4B84AFC9EA870F381E84DDE36D04EF16',
     1616978397,
     new MosaicId('39E0C49FA322A459'),
     '5172C98BD61DF32F447C501DE8090A9D7096F9E71975D788D67F7A82B8C04EFA',
  ),
  'NDS6LVW7ZWXZE2TVCA5DANKE7RSD3IMNWOF7FZQ'
);

Hierarchy

Implements

Index

Constructors

constructor

  • new AutomatedPool(name: string, reader: ReaderImpl, target: PublicAccount): AutomatedPool
  • Constructs an automated liquidity pool instance around a name of \a name, a network reader \a reader and a target account \a target.

    access

    public

    Parameters

    • name: string

      The name of the automated liquidity pool (e.g.: "XYM:BTC").

    • reader: ReaderImpl

      The blockchain network reader configuration.

    • target: PublicAccount

      The liquidity pool target account (holding funds).

    Returns AutomatedPool

Properties

mosaicInfo

mosaicInfo: MosaicInfo | undefined
description

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

name

name: string

The name of the automated liquidity pool (e.g.: "XYM:BTC").

reader

reader: ReaderImpl

The blockchain network reader configuration.

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.

Optional result

result: TransactionURI<Transaction>
description

Last automated pool command execution result.

source

source: AssetSource
description

The source blockchain network of assets paired in an automated liquidity pool.

target

target: PublicAccount

The liquidity pool target account (holding funds).

Accessors

identifier

  • Getter for the deterministic asset identifier related to the automated pool shares mosaic that will be created on the network. At any time, there is always one automated pool shares mosaic identifier per automated pool.

    access

    public

    Returns AssetIdentifier

Methods

canExecute

  • Verifies the autorization for \a actor to execute a pool command \a command given \a sharesAssetId automated pool shares asset identifier.

    access

    public

    Parameters

    • actor: PublicAccount

      The actor is whom executes the command.

    • sharesAssetId: AssetIdentifier

      The automated pool shares asset identifier.

    • command: string

      The automated pool command.

    • argv: CommandOption[]

      The command options (arguments).

    Returns AllowanceResult

    Returns whether an actor is authorized to execute said command.

create

  • Creates a new Automated Liquidity Pool given \a provider a funded public account, \a x left-side input amount and \a y right-side input amount. The transaction parameters argument is optional and should be used to override data about network configuration.

    This method returns the asset identifier that represents the automated pool shares, all automated liquidity pools will be assigned one such asset identifier.

    access

    public

    Parameters

    • provider: PublicAccount

      The public account of the liquidity provider.

    • x: AssetAmount

      The cryptocurrency amount for x in the constant product formula.

    • y: AssetAmount

      The cryptocurrency amount for y in the constant product formula.

    • Default value parameters: TransactionParameters = new TransactionParameters()

      (Optional) The additional transaction parameters (network specific).

    Returns AssetIdentifier

    The automated pool shares asset identifier.

execute

  • Executes \a command given \a sharesAssetId automated pool shares asset identifier, \a actor public account, \a argv command execution options and \a parameters to broadcast.

    access

    public

    Parameters

    • actor: PublicAccount

      The actor is whom executes the command.

    • sharesAssetId: AssetIdentifier

      The automated pool shares asset identifier.

    • command: string

      The automated pool command descriptor (e.g. "CreatePool").

    • parameters: TransactionParameters

      The transaction parameters (network specific).

    • argv: CommandOption[]

      The command execution options (arguments).

    Returns Promise<TransactionURI<Transaction>>

    A digital contract that must be signed by the actor and possibly by the target account.

executeOffline

  • Executes \a command given \a sharesAssetId automated pool shares asset identifier, \a actor public account, \a argv command execution options and \a parameters to broadcast.

    This method does not call the synchronize() method.

    access

    public

    Parameters

    • actor: PublicAccount

      The actor is whom executes the command.

    • sharesAssetId: AssetIdentifier

      The automated pool shares asset identifier.

    • command: string

      The automated pool command descriptor (e.g. "CreatePool").

    • parameters: TransactionParameters

      The transaction parameters (network specific).

    • argv: CommandOption[]

      The command execution options (arguments).

    Returns TransactionURI<Transaction>

    A digital contract that must be signed by the actor and possibly by the target account.

Protected getCommand

  • Returns a command instance for \a command given \a context and \a sharesAssetId.

    see

    {Swapable.AssetCommands}

    access

    protected

    throws

    {FailureInvalidCommand} On invalid automated pool command.

    Parameters

    • sharesAssetId: AssetIdentifier

      The automated pool shares asset identifier.

    • command: string

      The automated pool command name (which command).

    • context: Context

      The command execution context (arguments).

    Returns Command

    The command instance pre-configured with the execution context.

Protected getContext

  • Returns an execution context around an \a actor, \a argv command options and \a parameters transaction parameters.

    access

    protected

    Parameters

    • actor: PublicAccount

      The actor in said execution context.

    • parameters: TransactionParameters

      The transaction parameters.

    • Optional argv: CommandOption[]

      The execution options.

    Returns Context

    The pre-configured execution context.

publish

  • publish(registry: PublicAccount): Promise<TransactionURI<Transaction>>
  • Publishes an Automated Liquidity Pool to \a registry and uses the target public account. Registries serve as list of liquidity pools.

    Parameters

    • registry: PublicAccount

    Returns Promise<TransactionURI<Transaction>>

synchronize

  • synchronize(): Promise<boolean>
  • Synchronize the command execution with the network. This method shall be used to fetch data required for / before the execution of an automated pool command.

    async
    override

    {Market.synchronize()}

    access

    public

    Returns Promise<boolean>

Generated using TypeDoc