UNPKG

@ledgerhq/coin-stellar

Version:
46 lines 2.15 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.buildPaymentOperation = exports.buildCreateAccountOperation = exports.buildChangeTrustOperation = exports.buildTransactionBuilder = void 0; const currencies_1 = require("@ledgerhq/cryptoassets/currencies"); const stellar_sdk_1 = require("@stellar/stellar-sdk"); const currency = (0, currencies_1.getCryptoCurrencyById)("stellar"); function buildTransactionBuilder(source, fee) { const formattedFee = fee.toString(); return new stellar_sdk_1.TransactionBuilder(source, { fee: formattedFee, networkPassphrase: stellar_sdk_1.Networks.PUBLIC, }); } exports.buildTransactionBuilder = buildTransactionBuilder; function buildChangeTrustOperation(assetCode, assetIssuer) { return stellar_sdk_1.Operation.changeTrust({ asset: new stellar_sdk_1.Asset(assetCode, assetIssuer), }); } exports.buildChangeTrustOperation = buildChangeTrustOperation; function buildCreateAccountOperation(destination, amount) { const formattedAmount = getFormattedAmount(amount); return stellar_sdk_1.Operation.createAccount({ destination: destination, startingBalance: formattedAmount, }); } exports.buildCreateAccountOperation = buildCreateAccountOperation; function buildPaymentOperation({ destination, amount, assetCode, assetIssuer, }) { const formattedAmount = getFormattedAmount(amount); // Non-native assets should always have asset code and asset issuer. If an // asset doesn't have both, we assume it is native asset. const asset = assetCode && assetIssuer ? new stellar_sdk_1.Asset(assetCode, assetIssuer) : stellar_sdk_1.Asset.native(); return stellar_sdk_1.Operation.payment({ destination: destination, amount: formattedAmount, asset, }); } exports.buildPaymentOperation = buildPaymentOperation; function getFormattedAmount(amount) { const div = 10 ** currency.units[0].magnitude; // BigInt division is always an integer, never a float. We need to convert first to a Number. return (Number(amount) / div).toString(); } //# sourceMappingURL=sdkWrapper.js.map