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; toString(): string; toTrustLineXDRObject(): TrustLineAsset; toXDRObject(): Asset;}Source: src/base/asset.ts:46
new Asset(code, issuer)
constructor(code: string, issuer?: string);Parameters
code—string(required) — The asset code.issuer—string(optional) — The account ID of the issuer.
Source: src/base/asset.ts:56
Asset.compare(assetA, assetB)
Compares two assets according to the criteria:
- First compare the type (
native < alphanum4 < alphanum12). - If the types are equal, compare the assets codes.
- If the asset codes are equal, compare the issuers.
static compare(assetA: Asset, assetB: Asset): -1 | 0 | 1;Parameters
assetA—Asset(required) — the first assetassetB—Asset(required) — the second asset
Source: src/base/asset.ts:288
Asset.fromOperation(assetXdr)
Returns an asset object from its XDR object representation.
static fromOperation(assetXdr: Asset): Asset;Parameters
assetXdr—Asset(required) — The asset xdr object.
Source: src/base/asset.ts:90
Asset.native()
Returns an asset object for the native asset.
static native(): Asset;Source: src/base/asset.ts:82
asset.code
The asset code.
readonly code: string;Source: src/base/asset.ts:48
asset.issuer
The account ID of the issuer. Undefined for the native asset.
readonly issuer: string | undefined;Source: src/base/asset.ts:50
asset.contractId(networkPassphrase)
Returns the would-be contract ID (C... format) for this asset on a given
network.
contractId(networkPassphrase: string): string;Parameters
-
networkPassphrase—string(required) — indicates which network the contract ID should refer to, since every network will have a unique ID for the same contract (seeNetworksfor options)Warning: This makes no guarantee that this contract actually exists.
Source: src/base/asset.ts:143
asset.equals(asset)
Returns true if this asset equals the given asset.
equals(asset: Asset): boolean;Parameters
asset—Asset(required) — Asset to compare
Source: src/base/asset.ts:261
asset.getAssetType()
getAssetType(): AssetType;Throws
- Throws
Errorif 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:219
asset.getCode()
Returns the asset code
getCode(): string;Source: src/base/asset.ts:196
asset.getIssuer()
Returns the asset issuer
getIssuer(): string | undefined;Source: src/base/asset.ts:203
asset.getRawAssetType()
Returns the raw XDR representation of the asset type
getRawAssetType(): AssetType;Source: src/base/asset.ts:237
asset.isNative()
Returns true if this asset object is the native asset.
isNative(): boolean;Source: src/base/asset.ts:252
asset.toChangeTrustXDRObject()
Returns the xdr.ChangeTrustAsset object for this asset.
toChangeTrustXDRObject(): ChangeTrustAsset;Source: src/base/asset.ts:122
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:270
asset.toTrustLineXDRObject()
Returns the xdr.TrustLineAsset object for this asset.
toTrustLineXDRObject(): TrustLineAsset;Source: src/base/asset.ts:129
asset.toXDRObject()
Returns the xdr.Asset object for this asset.
toXDRObject(): Asset;Source: src/base/asset.ts:115
AssetType
const AssetType: { readonly credit12: "credit_alphanum12"; readonly credit4: "credit_alphanum4"; readonly liquidityPoolShares: "liquidity_pool_shares"; readonly native: "native" }Source: src/base/asset.ts:7
Claimant
Claimant class represents an xdr.Claimant
The claim predicate is optional, it defaults to unconditional if none is specified.
class Claimant { constructor(destination: string, predicate?: ClaimPredicate); static fromXDR(claimantXdr: Claimant): 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(): Claimant;}Source: src/base/claimant.ts:10
new Claimant(destination, predicate)
constructor(destination: string, predicate?: ClaimPredicate);Parameters
destination—string(required) — The destination account ID.predicate—ClaimPredicate(optional) — The claim predicate.
Source: src/base/claimant.ts:18
Claimant.fromXDR(claimantXdr)
Returns a claimant object from its XDR object representation.
static fromXDR(claimantXdr: Claimant): Claimant;Parameters
claimantXdr—Claimant(required) — The claimant xdr object.
Source: src/base/claimant.ts:124
Claimant.predicateAnd(left, right)
Returns an and claim predicate
static predicateAnd(left: ClaimPredicate, right: ClaimPredicate): ClaimPredicate;Parameters
left—ClaimPredicate(required) — an xdr.ClaimPredicateright—ClaimPredicate(required) — an xdr.ClaimPredicate
Source: src/base/claimant.ts:45
Claimant.predicateBeforeAbsoluteTime(absBefore)
Returns a BeforeAbsoluteTime claim predicate
This predicate will be fulfilled if the closing time of the ledger that includes the CreateClaimableBalance operation is less than this (absolute) Unix timestamp (expressed in seconds).
static predicateBeforeAbsoluteTime(absBefore: string): ClaimPredicate;Parameters
absBefore—string(required) — Unix epoch (in seconds) as a string
Source: src/base/claimant.ts:99
Claimant.predicateBeforeRelativeTime(seconds)
Returns a BeforeRelativeTime claim predicate
This predicate will be fulfilled if the closing time of the ledger that includes the CreateClaimableBalance operation plus this relative time delta (in seconds) is less than the current time.
static predicateBeforeRelativeTime(seconds: string): ClaimPredicate;Parameters
seconds—string(required) — seconds since closeTime of the ledger in which the ClaimableBalanceEntry was created (as string)
Source: src/base/claimant.ts:114
Claimant.predicateNot(predicate)
Returns a not claim predicate
static predicateNot(predicate: ClaimPredicate): ClaimPredicate;Parameters
predicate—ClaimPredicate(required) — an xdr.ClaimPredicate
Source: src/base/claimant.ts:82
Claimant.predicateOr(left, right)
Returns an or claim predicate
static predicateOr(left: ClaimPredicate, right: ClaimPredicate): ClaimPredicate;Parameters
left—ClaimPredicate(required) — an xdr.ClaimPredicateright—ClaimPredicate(required) — an xdr.ClaimPredicate
Source: src/base/claimant.ts:64
Claimant.predicateUnconditional()
Returns an unconditional claim predicate
static predicateUnconditional(): ClaimPredicate;Source: src/base/claimant.ts:36
claimant.destination
The destination account ID.
destination: string;Source: src/base/claimant.ts:153
claimant.predicate
The claim predicate.
predicate: ClaimPredicate;Source: src/base/claimant.ts:164
claimant.toXDRObject()
Returns the xdr object for this claimant.
toXDRObject(): Claimant;Source: src/base/claimant.ts:141
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;}Source: src/base/liquidity_pool_asset.ts:12
new LiquidityPoolAsset(assetA, assetB, fee)
constructor(assetA: Asset, assetB: Asset, fee: number);Parameters
assetA—Asset(required) — The first asset in the Pool, it must respect the ruleassetA < assetB. SeeAsset.comparefor more details on how assets are sorted.assetB—Asset(required) — The second asset in the Pool, it must respect the ruleassetA < assetB. SeeAsset.comparefor more details on how assets are sorted.fee—number(required) — The liquidity pool fee. For now the only fee supported is30.
Source: src/base/liquidity_pool_asset.ts:22
LiquidityPoolAsset.fromOperation(ctAssetXdr)
Returns a liquidity pool asset object from its XDR ChangeTrustAsset object representation.
static fromOperation(ctAssetXdr: ChangeTrustAsset): LiquidityPoolAsset;Parameters
ctAssetXdr—ChangeTrustAsset(required) — The asset XDR object.
Source: src/base/liquidity_pool_asset.ts:50
liquidityPoolAsset.assetA
assetA: Asset;Source: src/base/liquidity_pool_asset.ts:13
liquidityPoolAsset.assetB
assetB: Asset;Source: src/base/liquidity_pool_asset.ts:14
liquidityPoolAsset.fee
fee: number;Source: src/base/liquidity_pool_asset.ts:15
liquidityPoolAsset.equals(other)
Returns true if this liquidity pool asset equals the given one.
equals(other: LiquidityPoolAsset): boolean;Parameters
other—LiquidityPoolAsset(required) — the LiquidityPoolAsset to compare
Source: src/base/liquidity_pool_asset.ts:116
liquidityPoolAsset.getAssetType()
Returns the asset type, always "liquidity_pool_shares".
getAssetType(): "liquidity_pool_shares";See also
Source: src/base/liquidity_pool_asset.ts:107
liquidityPoolAsset.getLiquidityPoolParameters()
Returns liquidity pool parameters.
getLiquidityPoolParameters(): ConstantProduct;Source: src/base/liquidity_pool_asset.ts:93
liquidityPoolAsset.toString()
Returns a string representation in liquidity_pool:<hex pool id> format.
toString(): string;Source: src/base/liquidity_pool_asset.ts:125
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:75
LiquidityPoolFeeV18
const LiquidityPoolFeeV18: 30Source: src/base/get_liquidity_pool_id.ts:22
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;}Source: src/base/liquidity_pool_id.ts:7
new LiquidityPoolId(liquidityPoolId)
constructor(liquidityPoolId: string);Parameters
liquidityPoolId—string(required) — The ID of the liquidity pool in string ‘hex’.
Source: src/base/liquidity_pool_id.ts:13
LiquidityPoolId.fromOperation(tlAssetXdr)
Returns a liquidity pool ID object from its xdr.TrustLineAsset representation.
static fromOperation(tlAssetXdr: TrustLineAsset): LiquidityPoolId;Parameters
tlAssetXdr—TrustLineAsset(required) — The asset XDR object.
Source: src/base/liquidity_pool_id.ts:28
liquidityPoolId.liquidityPoolId
liquidityPoolId: string;Source: src/base/liquidity_pool_id.ts:8
liquidityPoolId.equals(asset)
Returns true if this liquidity pool ID equals the given one.
equals(asset: LiquidityPoolId): boolean;Parameters
asset—LiquidityPoolId(required) — LiquidityPoolId to compare.
Source: src/base/liquidity_pool_id.ts:77
liquidityPoolId.getAssetType()
Returns the asset type, always "liquidity_pool_shares".
getAssetType(): "liquidity_pool_shares";See also
Source: src/base/liquidity_pool_id.ts:68
liquidityPoolId.getLiquidityPoolId()
Returns the liquidity pool ID as a hex string.
getLiquidityPoolId(): string;Source: src/base/liquidity_pool_id.ts:59
liquidityPoolId.toString()
Returns a string representation of this liquidity pool ID.
toString(): string;Source: src/base/liquidity_pool_id.ts:84
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:48
getLiquidityPoolId
Computes the Pool ID for the given assets, fee and pool type.
Returns the raw Pool ID buffer, which can be stringified with
toString('hex').
getLiquidityPoolId(liquidityPoolType: "constant_product", liquidityPoolParameters: ConstantProduct): Buffer<ArrayBufferLike>Parameters
liquidityPoolType—"constant_product"(required) — A string representing the liquidity pool type.liquidityPoolParameters—ConstantProduct(required) — The liquidity pool parameters.assetA: The first asset in the Pool, it must respect the ruleassetA < assetB.assetB: The second asset in the Pool, it must respect the ruleassetA < assetB.fee: The liquidity pool fee. For now the only fee supported is30.
See also
Source: src/base/get_liquidity_pool_id.ts:38
Types
AssetType
type AssetType = typeof AssetType[keyof typeof AssetType]Source: src/base/asset.ts:7
AssetType.credit12
type credit12 = "credit_alphanum12"Source: src/base/asset.ts:20
AssetType.credit4
type credit4 = "credit_alphanum4"Source: src/base/asset.ts:19
AssetType.liquidityPoolShares
type liquidityPoolShares = "liquidity_pool_shares"Source: src/base/asset.ts:21
AssetType.native
type native = "native"Source: src/base/asset.ts:18
LiquidityPoolParameters
type LiquidityPoolParameters = LiquidityPoolParameters.ConstantProductSource: src/base/get_liquidity_pool_id.ts:12
LiquidityPoolParameters.ConstantProduct
interface ConstantProduct { assetA: Asset; assetB: Asset; fee: number;}Source: src/base/get_liquidity_pool_id.ts:13
constantProduct.assetA
assetA: Asset;Source: src/base/get_liquidity_pool_id.ts:14
constantProduct.assetB
assetB: Asset;Source: src/base/get_liquidity_pool_id.ts:15
constantProduct.fee
fee: number;Source: src/base/get_liquidity_pool_id.ts:16
LiquidityPoolType
type LiquidityPoolType = LiquidityPoolType.constantProductSource: src/base/get_liquidity_pool_id.ts:7
LiquidityPoolType.constantProduct
type constantProduct = "constant_product"