@okxweb3/coin-stellar
Version:
@ok/coin-stellar is a Stellar SDK for building Web3 wallets and applications. It supports Stellar and PI blockchains, enabling private key management, address generation, transaction signing, trustline creation, and asset transfers
44 lines • 1.63 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.LiquidityPoolId = void 0;
const xdr_1 = __importDefault(require("./xdr"));
class LiquidityPoolId {
constructor(liquidityPoolId) {
if (!liquidityPoolId) {
throw new Error('liquidityPoolId cannot be empty');
}
if (!/^[a-f0-9]{64}$/.test(liquidityPoolId)) {
throw new Error('Liquidity pool ID is not a valid hash');
}
this.liquidityPoolId = liquidityPoolId;
}
static fromOperation(tlAssetXdr) {
const assetType = tlAssetXdr.switch();
if (assetType === xdr_1.default.AssetType.assetTypePoolShare()) {
const liquidityPoolId = tlAssetXdr.liquidityPoolId().toString('hex');
return new this(liquidityPoolId);
}
throw new Error(`Invalid asset type: ${assetType.name}`);
}
toXDRObject() {
const xdrPoolId = xdr_1.default.PoolId.fromXDR(this.liquidityPoolId, 'hex');
return new xdr_1.default.TrustLineAsset('assetTypePoolShare', xdrPoolId);
}
getLiquidityPoolId() {
return String(this.liquidityPoolId);
}
getAssetType() {
return 'liquidity_pool_shares';
}
equals(asset) {
return this.liquidityPoolId === asset.getLiquidityPoolId();
}
toString() {
return `liquidity_pool:${this.liquidityPoolId}`;
}
}
exports.LiquidityPoolId = LiquidityPoolId;
//# sourceMappingURL=liquidity_pool_id.js.map