From f8dba6e6f3c4a04045ad9fe6d5cbbda8a52b1075 Mon Sep 17 00:00:00 2001 From: keljoshX Date: Mon, 1 Jun 2026 20:36:51 +0100 Subject: [PATCH] feat(stellar): support payments for issued assets and XLM --- packages/payments-engine/dist/index.js | 5 +++-- packages/payments-engine/dist/index.mjs | 5 +++-- packages/payments-engine/src/index.ts | 2 ++ packages/payments-engine/src/stellar.service.ts | 13 +++++++++++-- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/packages/payments-engine/dist/index.js b/packages/payments-engine/dist/index.js index cd3f255..3ffa0a3 100644 --- a/packages/payments-engine/dist/index.js +++ b/packages/payments-engine/dist/index.js @@ -52,16 +52,17 @@ var StellarService = class { /** * Sends funds from the operational storage to a destination address */ - async sendFunds(destinationAddress, amount) { + async sendFunds(destinationAddress, amount, assetCode, assetIssuer) { try { const sourceAccount = await this.server.loadAccount(this.sourceKeypair.publicKey()); + const asset = assetCode && assetIssuer ? new StellarSdk.Asset(assetCode, assetIssuer) : StellarSdk.Asset.native(); const transaction = new StellarSdk.TransactionBuilder(sourceAccount, { fee: StellarSdk.BASE_FEE, networkPassphrase: process.env.STELLAR_NETWORK_URL?.includes("public") ? StellarSdk.Networks.PUBLIC : StellarSdk.Networks.TESTNET }).addOperation( StellarSdk.Operation.payment({ destination: destinationAddress, - asset: StellarSdk.Asset.native(), + asset, amount }) ).setTimeout(30).build(); diff --git a/packages/payments-engine/dist/index.mjs b/packages/payments-engine/dist/index.mjs index 900b24d..07c00a1 100644 --- a/packages/payments-engine/dist/index.mjs +++ b/packages/payments-engine/dist/index.mjs @@ -16,16 +16,17 @@ var StellarService = class { /** * Sends funds from the operational storage to a destination address */ - async sendFunds(destinationAddress, amount) { + async sendFunds(destinationAddress, amount, assetCode, assetIssuer) { try { const sourceAccount = await this.server.loadAccount(this.sourceKeypair.publicKey()); + const asset = assetCode && assetIssuer ? new StellarSdk.Asset(assetCode, assetIssuer) : StellarSdk.Asset.native(); const transaction = new StellarSdk.TransactionBuilder(sourceAccount, { fee: StellarSdk.BASE_FEE, networkPassphrase: process.env.STELLAR_NETWORK_URL?.includes("public") ? StellarSdk.Networks.PUBLIC : StellarSdk.Networks.TESTNET }).addOperation( StellarSdk.Operation.payment({ destination: destinationAddress, - asset: StellarSdk.Asset.native(), + asset, amount }) ).setTimeout(30).build(); diff --git a/packages/payments-engine/src/index.ts b/packages/payments-engine/src/index.ts index 8e2735a..1cc2ab0 100644 --- a/packages/payments-engine/src/index.ts +++ b/packages/payments-engine/src/index.ts @@ -2,6 +2,8 @@ export interface PaymentIntentType { id: string; amount: number; currency: string; + assetCode?: string; + assetIssuer?: string; status: 'pending' | 'completed' | 'failed'; createdAt: Date; updatedAt: Date; diff --git a/packages/payments-engine/src/stellar.service.ts b/packages/payments-engine/src/stellar.service.ts index 026fccb..6e07d13 100644 --- a/packages/payments-engine/src/stellar.service.ts +++ b/packages/payments-engine/src/stellar.service.ts @@ -24,9 +24,18 @@ export class StellarService { /** * Sends funds from the operational storage to a destination address */ - async sendFunds(destinationAddress: string, amount: string): Promise { + async sendFunds( + destinationAddress: string, + amount: string, + assetCode?: string, + assetIssuer?: string, + ): Promise { try { const sourceAccount = await this.server.loadAccount(this.sourceKeypair.publicKey()); + const asset = + assetCode && assetIssuer + ? new StellarSdk.Asset(assetCode, assetIssuer) + : StellarSdk.Asset.native(); const transaction = new StellarSdk.TransactionBuilder(sourceAccount, { fee: StellarSdk.BASE_FEE, @@ -37,7 +46,7 @@ export class StellarService { .addOperation( StellarSdk.Operation.payment({ destination: destinationAddress, - asset: StellarSdk.Asset.native(), + asset, amount: amount, }), )