Skip to content

Core / Assets

Asset

Asset class represents an asset, either the native asset (XLM) or an asset code / issuer account ID pair.

An asset describes an asset code and issuer pair. In the case of the native asset XLM, the issuer will be undefined.

class Asset {
constructor(code: string, issuer?: string);
static compare(assetA: Asset, assetB: Asset): -1 | 0 | 1;
static fromOperation(assetXdr: Asset): Asset;
static native(): Asset;
readonly code: string;
readonly issuer: string | undefined;
contractId(networkPassphrase: string): string;
equals(asset: Asset): boolean;
getAssetType(): AssetType;
getCode(): string;
getIssuer(): string | undefined;
getRawAssetType(): AssetType;
isNative(): boolean;
toChangeTrustXdrObject(): ChangeTrustAsset;
toChangeTrustXDRObject(): ChangeTrustAsset;
toString(): string;
toTrustLineXdrObject(): TrustLineAsset;
toTrustLineXDRObject(): TrustLineAsset;
toXdrObject(): Asset;
toXDRObject(): Asset;
}

Source: src/base/asset.ts:65

new Asset(code, issuer)

constructor(code: string, issuer?: string);

Parameters

  • codestring (required) — The asset code.
  • issuerstring (optional) — The account ID of the issuer.

Source: src/base/asset.ts:81

Asset.compare(assetA, assetB)

Compares two assets according to the criteria:

  1. First compare the type (native < alphanum4 < alphanum12).
  2. If the types are equal, compare the assets codes.
  3. If the asset codes are equal, compare the issuers.
static compare(assetA: Asset, assetB: Asset): -1 | 0 | 1;

Parameters

  • assetAAsset (required) — the first asset
  • assetBAsset (required) — the second asset

Source: src/base/asset.ts:365

Asset.fromOperation(assetXdr)

Returns an asset object from its XDR object representation.

static fromOperation(assetXdr: Asset): Asset;

Parameters

  • assetXdrAsset (required) — The asset xdr object.

Source: src/base/asset.ts:128

Asset.native()

Returns an asset object for the native asset.

static native(): Asset;

Source: src/base/asset.ts:120

asset.code

The asset code.

readonly code: string;

Source: src/base/asset.ts:67

asset.issuer

The account ID of the issuer. Undefined for the native asset.

readonly issuer: string | undefined;

Source: src/base/asset.ts:69

asset.contractId(networkPassphrase)

Returns the would-be contract ID (C... format) for this asset on a given network.

contractId(networkPassphrase: string): string;

Parameters

  • networkPassphrasestring (required) — indicates which network the contract ID should refer to, since every network will have a unique ID for the same contract (see Networks for options)

Source: src/base/asset.ts:218

asset.equals(asset)

Returns true if this asset equals the given asset.

equals(asset: Asset): boolean;

Parameters

  • assetAsset (required) — Asset to compare

Source: src/base/asset.ts:334

asset.getAssetType()

getAssetType(): AssetType;

Throws

  • if asset type is unsupported.

See also

  • Assets concept Returns the asset type. Can be one of following types:

  • native,

  • credit_alphanum4,

  • credit_alphanum12

Source: src/base/asset.ts:292

asset.getCode()

Returns the asset code

getCode(): string;

Source: src/base/asset.ts:269

asset.getIssuer()

Returns the asset issuer

getIssuer(): string | undefined;

Source: src/base/asset.ts:276

asset.getRawAssetType()

Returns the raw XDR representation of the asset type

getRawAssetType(): AssetType;

Source: src/base/asset.ts:311

asset.isNative()

Returns true if this asset object is the native asset.

isNative(): boolean;

Source: src/base/asset.ts:325

asset.toChangeTrustXdrObject()

Returns the xdr.ChangeTrustAsset object for this asset.

toChangeTrustXdrObject(): ChangeTrustAsset;

Source: src/base/asset.ts:172

asset.toChangeTrustXDRObject()

Deprecated. Use toChangeTrustXdrObject instead. Deprecated in version v17.0.0

toChangeTrustXDRObject(): ChangeTrustAsset;

Source: src/base/asset.ts:195

asset.toString()

Returns a string representation of this asset.

Native assets return "native". Non-native assets return "code:issuer".

toString(): string;

Source: src/base/asset.ts:347

asset.toTrustLineXdrObject()

Returns the xdr.TrustLineAsset object for this asset.

toTrustLineXdrObject(): TrustLineAsset;

Source: src/base/asset.ts:179

asset.toTrustLineXDRObject()

Deprecated. Use toTrustLineXdrObject instead. Deprecated in version v17.0.0

toTrustLineXDRObject(): TrustLineAsset;

Source: src/base/asset.ts:203

asset.toXdrObject()

Returns the xdr.Asset object for this asset.

toXdrObject(): Asset;

Source: src/base/asset.ts:165

asset.toXDRObject()

Deprecated. Use toXdrObject instead. Deprecated in version v17.0.0

toXDRObject(): Asset;

Source: src/base/asset.ts:187

AssetType

const AssetType: { readonly credit12: "credit_alphanum12"; readonly credit4: "credit_alphanum4"; readonly liquidityPoolShares: "liquidity_pool_shares"; readonly native: "native" }

Source: src/base/asset.ts:22

Claimant

Claimant class represents an xdr.Claimant

The claim predicate is optional, it defaults to unconditional if none is specified.

To build a predicate from a plain object rather than the predicate* helpers below, use the SEP-0051 dialect, which RPC serves:

const predicate = xdr.ClaimPredicate.fromJson({
not: { before_absolute_time: "1788443399" },
});

Horizon serves a different dialect, and it does not map key for key. { unconditional: true } becomes the string "unconditional", abs_before_epoch and rel_before become before_absolute_time and before_relative_time, and Horizon’s ISO-8601 abs_before has no SEP-0051 counterpart. and, or and not carry over unchanged.

Two of stellar-core’s limits go unchecked here: at most 4 levels of nesting, and non-negative times. A predicate that breaks either is built without complaint and rejected at submit time — see #1727.

class Claimant {
constructor(destination: string, predicate?: ClaimPredicate);
static fromXdr(claimantXdr: ClaimantV0Arm): Claimant;
static fromXDR(claimantXdr: ClaimantV0Arm): Claimant;
static predicateAnd(left: ClaimPredicate, right: ClaimPredicate): ClaimPredicate;
static predicateBeforeAbsoluteTime(absBefore: string): ClaimPredicate;
static predicateBeforeRelativeTime(seconds: string): ClaimPredicate;
static predicateNot(predicate: ClaimPredicate): ClaimPredicate;
static predicateOr(left: ClaimPredicate, right: ClaimPredicate): ClaimPredicate;
static predicateUnconditional(): ClaimPredicate;
destination: string;
predicate: ClaimPredicate;
toXdrObject(): ClaimantV0Arm;
toXDRObject(): ClaimantV0Arm;
}

Source: src/base/claimant.ts:35

new Claimant(destination, predicate)

constructor(destination: string, predicate?: ClaimPredicate);

Parameters

  • destinationstring (required) — The destination account ID.
  • predicateClaimPredicate (optional) — The claim predicate.

Source: src/base/claimant.ts:43

Claimant.fromXdr(claimantXdr)

Returns a claimant object from its XDR object representation.

static fromXdr(claimantXdr: ClaimantV0Arm): Claimant;

Parameters

  • claimantXdrClaimantV0Arm (required) — The claimant xdr object.

Source: src/base/claimant.ts:151

Claimant.fromXDR(claimantXdr)

Deprecated. Use Claimant.fromXdr instead. Deprecated in version v17.0.0

static fromXDR(claimantXdr: ClaimantV0Arm): Claimant;

Parameters

  • claimantXdrClaimantV0Arm (required)

Source: src/base/claimant.ts:169

Claimant.predicateAnd(left, right)

Returns an and claim predicate

static predicateAnd(left: ClaimPredicate, right: ClaimPredicate): ClaimPredicate;

Parameters

  • leftClaimPredicate (required) — an xdr.ClaimPredicate
  • rightClaimPredicate (required) — an xdr.ClaimPredicate

Source: src/base/claimant.ts:70

Claimant.predicateBeforeAbsoluteTime(absBefore)

Returns a BeforeAbsoluteTime claim predicate

This predicate will be fulfilled if the closing time of the ledger in which the balance is claimed is less than this (absolute) Unix timestamp (expressed in seconds).

static predicateBeforeAbsoluteTime(absBefore: string): ClaimPredicate;

Parameters

  • absBeforestring (required) — Unix epoch (in seconds) as a string

Source: src/base/claimant.ts:124

Claimant.predicateBeforeRelativeTime(seconds)

Returns a BeforeRelativeTime claim predicate

When the balance is created, this is converted to a BeforeAbsoluteTime predicate by adding this relative time delta (in seconds) to the closing time of the ledger that includes the CreateClaimableBalance operation. The predicate is then fulfilled while the closing time of the ledger in which the balance is claimed is less than that sum.

static predicateBeforeRelativeTime(seconds: string): ClaimPredicate;

Parameters

  • secondsstring (required) — seconds since closeTime of the ledger in which the ClaimableBalanceEntry was created (as string)

Source: src/base/claimant.ts:141

Claimant.predicateNot(predicate)

Returns a not claim predicate

static predicateNot(predicate: ClaimPredicate): ClaimPredicate;

Parameters

  • predicateClaimPredicate (required) — an xdr.ClaimPredicate

Source: src/base/claimant.ts:107

Claimant.predicateOr(left, right)

Returns an or claim predicate

static predicateOr(left: ClaimPredicate, right: ClaimPredicate): ClaimPredicate;

Parameters

  • leftClaimPredicate (required) — an xdr.ClaimPredicate
  • rightClaimPredicate (required) — an xdr.ClaimPredicate

Source: src/base/claimant.ts:89

Claimant.predicateUnconditional()

Returns an unconditional claim predicate

static predicateUnconditional(): ClaimPredicate;

Source: src/base/claimant.ts:61

claimant.destination

The destination account ID.

destination: string;

Source: src/base/claimant.ts:196

claimant.predicate

The claim predicate.

predicate: ClaimPredicate;

Source: src/base/claimant.ts:207

claimant.toXdrObject()

Returns the xdr object for this claimant.

toXdrObject(): ClaimantV0Arm;

Source: src/base/claimant.ts:176

claimant.toXDRObject()

Deprecated. Use toXdrObject instead. Deprecated in version v17.0.0

toXDRObject(): ClaimantV0Arm;

Source: src/base/claimant.ts:189

LiquidityPoolAsset

LiquidityPoolAsset class represents a liquidity pool trustline change.

class LiquidityPoolAsset {
constructor(assetA: Asset, assetB: Asset, fee: number);
static fromOperation(ctAssetXdr: ChangeTrustAsset): LiquidityPoolAsset;
assetA: Asset;
assetB: Asset;
fee: number;
equals(other: LiquidityPoolAsset): boolean;
getAssetType(): "liquidity_pool_shares";
getLiquidityPoolParameters(): ConstantProduct;
toString(): string;
toXdrObject(): ChangeTrustAsset;
toXDRObject(): ChangeTrustAsset;
}

Source: src/base/liquidity_pool_asset.ts:17

new LiquidityPoolAsset(assetA, assetB, fee)

constructor(assetA: Asset, assetB: Asset, fee: number);

Parameters

  • assetAAsset (required) — The first asset in the Pool, it must respect the rule assetA < assetB. See Asset.compare for more details on how assets are sorted.
  • assetBAsset (required) — The second asset in the Pool, it must respect the rule assetA < assetB. See Asset.compare for more details on how assets are sorted.
  • feenumber (required) — The liquidity pool fee. For now the only fee supported is 30.

Source: src/base/liquidity_pool_asset.ts:27

LiquidityPoolAsset.fromOperation(ctAssetXdr)

Returns a liquidity pool asset object from its XDR ChangeTrustAsset object representation.

static fromOperation(ctAssetXdr: ChangeTrustAsset): LiquidityPoolAsset;

Parameters

  • ctAssetXdrChangeTrustAsset (required) — The asset XDR object.

Source: src/base/liquidity_pool_asset.ts:55

liquidityPoolAsset.assetA

assetA: Asset;

Source: src/base/liquidity_pool_asset.ts:18

liquidityPoolAsset.assetB

assetB: Asset;

Source: src/base/liquidity_pool_asset.ts:19

liquidityPoolAsset.fee

fee: number;

Source: src/base/liquidity_pool_asset.ts:20

liquidityPoolAsset.equals(other)

Returns true if this liquidity pool asset equals the given one.

equals(other: LiquidityPoolAsset): boolean;

Parameters

  • otherLiquidityPoolAsset (required) — the LiquidityPoolAsset to compare

Source: src/base/liquidity_pool_asset.ts:126

liquidityPoolAsset.getAssetType()

Returns the asset type, always "liquidity_pool_shares".

getAssetType(): "liquidity_pool_shares";

See also

Source: src/base/liquidity_pool_asset.ts:117

liquidityPoolAsset.getLiquidityPoolParameters()

Returns liquidity pool parameters.

getLiquidityPoolParameters(): ConstantProduct;

Source: src/base/liquidity_pool_asset.ts:103

liquidityPoolAsset.toString()

Returns a string representation in liquidity_pool:<hex pool id> format.

toString(): string;

Source: src/base/liquidity_pool_asset.ts:135

liquidityPoolAsset.toXdrObject()

Returns the xdr.ChangeTrustAsset object for this liquidity pool asset.

Note: To convert from an Asset to xdr.ChangeTrustAsset please refer to the Asset.toChangeTrustXdrObject method.

toXdrObject(): ChangeTrustAsset;

Source: src/base/liquidity_pool_asset.ts:78

liquidityPoolAsset.toXDRObject()

Deprecated. Use toXdrObject instead. Deprecated in version v17.0.0

toXDRObject(): ChangeTrustAsset;

Source: src/base/liquidity_pool_asset.ts:96

LiquidityPoolFeeV18

const LiquidityPoolFeeV18: 30

Source: src/base/get_liquidity_pool_id.ts:25

LiquidityPoolId

LiquidityPoolId class represents the asset referenced by a trustline to a liquidity pool.

class LiquidityPoolId {
constructor(liquidityPoolId: string);
static fromOperation(tlAssetXdr: TrustLineAsset): LiquidityPoolId;
liquidityPoolId: string;
equals(asset: LiquidityPoolId): boolean;
getAssetType(): "liquidity_pool_shares";
getLiquidityPoolId(): string;
toString(): string;
toXdrObject(): TrustLineAsset;
toXDRObject(): TrustLineAsset;
}

Source: src/base/liquidity_pool_id.ts:8

new LiquidityPoolId(liquidityPoolId)

constructor(liquidityPoolId: string);

Parameters

  • liquidityPoolIdstring (required) — The ID of the liquidity pool in string ‘hex’.

Source: src/base/liquidity_pool_id.ts:14

LiquidityPoolId.fromOperation(tlAssetXdr)

Returns a liquidity pool ID object from its xdr.TrustLineAsset representation.

static fromOperation(tlAssetXdr: TrustLineAsset): LiquidityPoolId;

Parameters

  • tlAssetXdrTrustLineAsset (required) — The asset XDR object.

Source: src/base/liquidity_pool_id.ts:29

liquidityPoolId.liquidityPoolId

liquidityPoolId: string;

Source: src/base/liquidity_pool_id.ts:9

liquidityPoolId.equals(asset)

Returns true if this liquidity pool ID equals the given one.

equals(asset: LiquidityPoolId): boolean;

Parameters

  • assetLiquidityPoolId (required) — LiquidityPoolId to compare.

Source: src/base/liquidity_pool_id.ts:83

liquidityPoolId.getAssetType()

Returns the asset type, always "liquidity_pool_shares".

getAssetType(): "liquidity_pool_shares";

See also

Source: src/base/liquidity_pool_id.ts:74

liquidityPoolId.getLiquidityPoolId()

Returns the liquidity pool ID as a hex string.

getLiquidityPoolId(): string;

Source: src/base/liquidity_pool_id.ts:65

liquidityPoolId.toString()

Returns a string representation of this liquidity pool ID.

toString(): string;

Source: src/base/liquidity_pool_id.ts:90

liquidityPoolId.toXdrObject()

Returns the xdr.TrustLineAsset object for this liquidity pool ID.

Note: To convert from Asset to xdr.TrustLineAsset please refer to the Asset.toTrustLineXdrObject method.

toXdrObject(): TrustLineAsset;

Source: src/base/liquidity_pool_id.ts:49

liquidityPoolId.toXDRObject()

Deprecated. Use toXdrObject instead. Deprecated in version v17.0.0

toXDRObject(): TrustLineAsset;

Source: src/base/liquidity_pool_id.ts:58

getLiquidityPoolId

Computes the Pool ID for the given assets, fee and pool type.

Returns the raw Pool ID bytes, which can be stringified with uint8ArrayToHex from uint8array-extras.

getLiquidityPoolId(liquidityPoolType: "constant_product", liquidityPoolParameters: ConstantProduct): Uint8Array<ArrayBufferLike>

Parameters

  • liquidityPoolType"constant_product" (required) — A string representing the liquidity pool type.
  • liquidityPoolParametersConstantProduct (required) — The liquidity pool parameters.
    • assetA: The first asset in the Pool, it must respect the rule assetA < assetB.
    • assetB: The second asset in the Pool, it must respect the rule assetA < assetB.
    • fee: The liquidity pool fee. For now the only fee supported is 30.

See also

Source: src/base/get_liquidity_pool_id.ts:41

Types

AssetType

type AssetType = typeof AssetType[keyof typeof AssetType]

Source: src/base/asset.ts:22

AssetType.credit12

type credit12 = "credit_alphanum12"

Source: src/base/asset.ts:35

AssetType.credit4

type credit4 = "credit_alphanum4"

Source: src/base/asset.ts:34

AssetType.liquidityPoolShares

type liquidityPoolShares = "liquidity_pool_shares"

Source: src/base/asset.ts:36

AssetType.native

type native = "native"

Source: src/base/asset.ts:33

LiquidityPoolParameters

type LiquidityPoolParameters = LiquidityPoolParameters.ConstantProduct

Source: src/base/get_liquidity_pool_id.ts:15

LiquidityPoolParameters.ConstantProduct

interface ConstantProduct {
assetA: Asset;
assetB: Asset;
fee: number;
}

Source: src/base/get_liquidity_pool_id.ts:16

constantProduct.assetA

assetA: Asset;

Source: src/base/get_liquidity_pool_id.ts:17

constantProduct.assetB

assetB: Asset;

Source: src/base/get_liquidity_pool_id.ts:18

constantProduct.fee

fee: number;

Source: src/base/get_liquidity_pool_id.ts:19

LiquidityPoolType

type LiquidityPoolType = LiquidityPoolType.constantProduct

Source: src/base/get_liquidity_pool_id.ts:10

LiquidityPoolType.constantProduct

type constantProduct = "constant_product"

Source: src/base/get_liquidity_pool_id.ts:11