AssetTypePoolShare
extends Asset
in package
Represents a liquidity pool share asset in the Stellar network.
Liquidity pool shares are synthetic assets that represent participation in a liquidity pool. They are automatically created when depositing assets into a constant product liquidity pool and burned when withdrawing.
The pool is defined by two reserve assets (assetA and assetB) which must be provided in a specific canonical order: Native < AlphaNum4 < AlphaNum12, then by code lexicographically, then by issuer lexicographically.
Tags
Table of Contents
Constants
- TYPE_CREDIT_ALPHANUM_12 = "credit_alphanum12"
- TYPE_CREDIT_ALPHANUM_4 = "credit_alphanum4"
- TYPE_NATIVE = "native"
- TYPE_POOL_SHARE = "liquidty_pool_shares"
Methods
- __construct() : mixed
- Constructs a new liquidity pool share asset.
- canonicalForm() : string
- Returns the canonical string representation of an asset
- create() : Asset
- Creates an asset from its type, code, and issuer
- createFromCanonicalForm() : Asset|null
- Creates an asset from its canonical string representation
- createNonNativeAsset() : AssetTypeCreditAlphanum
- Creates a non-native asset with automatic type detection based on code length
- fromJson() : Asset
- Creates an asset from JSON data (typically from Horizon responses)
- fromXdr() : Asset
- Creates an Asset from its XDR representation
- getAssetA() : Asset
- Gets the first reserve asset in the liquidity pool.
- getAssetB() : Asset
- Gets the second reserve asset in the liquidity pool.
- getType() : string
- Gets the asset type identifier.
- native() : AssetTypeNative
- Creates the native XLM asset
- toXdr() : XdrAsset
- Converts the liquidity pool share asset to XDR format.
- toXdrChangeTrustAsset() : XdrChangeTrustAsset
- Converts this asset to XDR ChangeTrustAsset format
- toXdrTrustlineAsset() : XdrTrustlineAsset
- Converts this asset to XDR TrustlineAsset format
Constants
TYPE_CREDIT_ALPHANUM_12
public
mixed
TYPE_CREDIT_ALPHANUM_12
= "credit_alphanum12"
TYPE_CREDIT_ALPHANUM_4
public
mixed
TYPE_CREDIT_ALPHANUM_4
= "credit_alphanum4"
TYPE_NATIVE
public
mixed
TYPE_NATIVE
= "native"
TYPE_POOL_SHARE
public
mixed
TYPE_POOL_SHARE
= "liquidty_pool_shares"
Methods
__construct()
Constructs a new liquidity pool share asset.
public
__construct(Asset $assetA, Asset $assetB) : mixed
Creates a pool share asset from two reserve assets. The assets must be provided in canonical order and pass validation checks:
- Neither asset can be a pool share asset
- Both assets cannot be native XLM
- Assets must be ordered: Native < AlphaNum4 < AlphaNum12, then by code, then by issuer
Parameters
- $assetA : Asset
-
The first reserve asset (in canonical order)
- $assetB : Asset
-
The second reserve asset (in canonical order)
Tags
canonicalForm()
Returns the canonical string representation of an asset
public
static canonicalForm(Asset $asset) : string
Format:
- Native: "native"
- Issued: "CODE:ISSUER" (e.g., "USD:GABC...")
Parameters
- $asset : Asset
-
The asset to convert
Tags
Return values
string —The canonical form
create()
Creates an asset from its type, code, and issuer
public
static create(string $type[, string|null $code = null ][, string|null $issuer = null ]) : Asset
Parameters
- $type : string
-
One of the TYPE_* constants
- $code : string|null = null
-
Asset code (required for non-native assets)
- $issuer : string|null = null
-
Issuer account ID (required for non-native assets)
Tags
Return values
Asset —The created asset
createFromCanonicalForm()
Creates an asset from its canonical string representation
public
static createFromCanonicalForm(string $canonicalForm) : Asset|null
Accepted formats:
- "native" or "XLM" for native XLM
- "CODE:ISSUER" for issued assets (e.g., "USD:GABC...")
Parameters
- $canonicalForm : string
-
The canonical asset string
Return values
Asset|null —The created asset, or null if the format is invalid
createNonNativeAsset()
Creates a non-native asset with automatic type detection based on code length
public
static createNonNativeAsset(string $code, string $issuer) : AssetTypeCreditAlphanum
The asset type (AlphaNum4 or AlphaNum12) is determined automatically based on the length of the asset code.
Parameters
- $code : string
-
Asset code (1-12 characters)
- $issuer : string
-
Issuer account ID (public key starting with G)
Tags
Return values
AssetTypeCreditAlphanum —The created asset (AlphaNum4 or AlphaNum12)
fromJson()
Creates an asset from JSON data (typically from Horizon responses)
public
static fromJson(array<string|int, mixed> $json) : Asset
Parameters
- $json : array<string|int, mixed>
-
JSON data with asset_type, asset_code, and asset_issuer fields
Return values
Asset —The created asset
fromXdr()
Creates an Asset from its XDR representation
public
static fromXdr(XdrAsset $xdrAsset) : Asset
Parameters
- $xdrAsset : XdrAsset
-
The XDR asset data
Tags
Return values
Asset —The reconstructed asset
getAssetA()
Gets the first reserve asset in the liquidity pool.
public
getAssetA() : Asset
Return values
Asset —The first asset (in canonical order)
getAssetB()
Gets the second reserve asset in the liquidity pool.
public
getAssetB() : Asset
Return values
Asset —The second asset (in canonical order)
getType()
Gets the asset type identifier.
public
getType() : string
Tags
Return values
string —Always returns Asset::TYPE_POOL_SHARE for liquidity pool shares
native()
Creates the native XLM asset
public
static native() : AssetTypeNative
Return values
AssetTypeNative —The native XLM asset
toXdr()
Converts the liquidity pool share asset to XDR format.
public
toXdr() : XdrAsset
Creates an XDR representation of the pool share asset by encoding both reserve assets and the constant product parameters. The resulting XDR can be used in operations that work with liquidity pools.
Return values
XdrAsset —The XDR representation of this pool share asset
toXdrChangeTrustAsset()
Converts this asset to XDR ChangeTrustAsset format
public
toXdrChangeTrustAsset() : XdrChangeTrustAsset
Return values
XdrChangeTrustAsset —XDR format for change trust operations
toXdrTrustlineAsset()
Converts this asset to XDR TrustlineAsset format
public
toXdrTrustlineAsset() : XdrTrustlineAsset
Return values
XdrTrustlineAsset —XDR format for trustline operations