@arkade-os/boltz-swap 0.2.9 → 0.2.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -40,6 +40,7 @@ const wallet = await Wallet.create({
40
40
  const swapProvider = new BoltzSwapProvider({
41
41
  apiUrl: 'https://api.boltz.mutinynet.arkade.sh',
42
42
  network: 'mutinynet',
43
+ referralId: 'arkade', // optional
43
44
  });
44
45
 
45
46
  // Create the ArkadeLightning instance
package/dist/index.cjs CHANGED
@@ -205,6 +205,7 @@ var BoltzSwapProvider = class {
205
205
  wsUrl;
206
206
  apiUrl;
207
207
  network;
208
+ referralId;
208
209
  constructor(config) {
209
210
  this.network = config.network;
210
211
  const apiUrl = config.apiUrl || BASE_URLS[config.network];
@@ -301,15 +302,17 @@ var BoltzSwapProvider = class {
301
302
  message: "refundPublicKey must be a compressed public key"
302
303
  });
303
304
  }
305
+ const requestBody = {
306
+ from: "ARK",
307
+ to: "BTC",
308
+ invoice,
309
+ refundPublicKey,
310
+ ...this.referralId ? { referralId: this.referralId } : {}
311
+ };
304
312
  const response = await this.request(
305
313
  "/v2/swap/submarine",
306
314
  "POST",
307
- {
308
- from: "ARK",
309
- to: "BTC",
310
- invoice,
311
- refundPublicKey
312
- }
315
+ requestBody
313
316
  );
314
317
  if (!isCreateSubmarineSwapResponse(response))
315
318
  throw new SchemaError({ message: "Error creating submarine swap" });
@@ -332,7 +335,8 @@ var BoltzSwapProvider = class {
332
335
  invoiceAmount,
333
336
  claimPublicKey,
334
337
  preimageHash,
335
- ...description?.trim() ? { description: description.trim() } : {}
338
+ ...description?.trim() ? { description: description.trim() } : {},
339
+ ...this.referralId ? { referralId: this.referralId } : {}
336
340
  };
337
341
  const response = await this.request(
338
342
  "/v2/swap/reverse",
@@ -793,6 +797,18 @@ var ArkadeLightning = class {
793
797
  * @param pendingSwap - The pending submarine swap to refund the VHTLC.
794
798
  */
795
799
  async refundVHTLC(pendingSwap) {
800
+ const vhtlcPkScript = import_sdk3.ArkAddress.decode(
801
+ pendingSwap.response.address
802
+ ).pkScript;
803
+ const spendableVtxos = await this.indexerProvider.getVtxos({
804
+ scripts: [import_base2.hex.encode(vhtlcPkScript)],
805
+ spendableOnly: true
806
+ });
807
+ if (spendableVtxos.vtxos.length === 0) {
808
+ throw new Error(
809
+ `VHTLC not found for address ${pendingSwap.response.address}`
810
+ );
811
+ }
796
812
  const aspInfo = await this.arkProvider.getInfo();
797
813
  const address = await this.wallet.getAddress();
798
814
  if (!address) throw new Error("Failed to get ark address from wallet");
@@ -811,7 +827,7 @@ var ArkadeLightning = class {
811
827
  "boltz",
812
828
  pendingSwap.id
813
829
  );
814
- const { vhtlcScript, vhtlcAddress } = this.createVHTLCScript({
830
+ const { vhtlcScript } = this.createVHTLCScript({
815
831
  network: aspInfo.network,
816
832
  preimageHash: import_base2.hex.decode(
817
833
  getInvoicePaymentHash(pendingSwap.request.invoice)
@@ -823,15 +839,6 @@ var ArkadeLightning = class {
823
839
  });
824
840
  if (!vhtlcScript)
825
841
  throw new Error("Failed to create VHTLC script for reverse swap");
826
- if (vhtlcAddress !== pendingSwap.response.address)
827
- throw new Error("Boltz is trying to scam us");
828
- const spendableVtxos = await this.indexerProvider.getVtxos({
829
- scripts: [import_base2.hex.encode(vhtlcScript.pkScript)],
830
- spendableOnly: true
831
- });
832
- if (spendableVtxos.vtxos.length === 0) {
833
- throw new Error("No spendable virtual coins found");
834
- }
835
842
  const vhtlcIdentity = {
836
843
  sign: async (tx2, inputIndexes) => {
837
844
  const cpy = tx2.clone();
package/dist/index.d.cts CHANGED
@@ -1,9 +1,10 @@
1
- import { Transaction, Wallet, ServiceWorkerWallet, ArkProvider, IndexerProvider, VHTLC } from '@arkade-os/sdk';
1
+ import { Transaction, Wallet, ServiceWorkerWallet, ArkProvider, NetworkName, IndexerProvider, VHTLC } from '@arkade-os/sdk';
2
2
  import { Transaction as Transaction$1 } from '@scure/btc-signer';
3
3
 
4
4
  interface SwapProviderConfig {
5
5
  apiUrl?: string;
6
6
  network: Network;
7
+ referralId?: string;
7
8
  }
8
9
  type BoltzSwapStatus = "invoice.expired" | "invoice.failedToPay" | "invoice.paid" | "invoice.pending" | "invoice.set" | "invoice.settled" | "swap.created" | "swap.expired" | "transaction.claim.pending" | "transaction.claimed" | "transaction.confirmed" | "transaction.failed" | "transaction.lockupFailed" | "transaction.mempool" | "transaction.refunded";
9
10
  declare const isSubmarineFinalStatus: (status: BoltzSwapStatus) => boolean;
@@ -71,6 +72,7 @@ declare class BoltzSwapProvider {
71
72
  private readonly wsUrl;
72
73
  private readonly apiUrl;
73
74
  private readonly network;
75
+ private readonly referralId?;
74
76
  constructor(config: SwapProviderConfig);
75
77
  getApiUrl(): string;
76
78
  getWsUrl(): string;
@@ -101,7 +103,7 @@ interface Vtxo {
101
103
  locktime: number;
102
104
  };
103
105
  }
104
- type Network = "bitcoin" | "mutinynet" | "regtest" | "signet";
106
+ type Network = NetworkName;
105
107
  interface CreateLightningInvoiceRequest {
106
108
  amount: number;
107
109
  description?: string;
package/dist/index.d.ts CHANGED
@@ -1,9 +1,10 @@
1
- import { Transaction, Wallet, ServiceWorkerWallet, ArkProvider, IndexerProvider, VHTLC } from '@arkade-os/sdk';
1
+ import { Transaction, Wallet, ServiceWorkerWallet, ArkProvider, NetworkName, IndexerProvider, VHTLC } from '@arkade-os/sdk';
2
2
  import { Transaction as Transaction$1 } from '@scure/btc-signer';
3
3
 
4
4
  interface SwapProviderConfig {
5
5
  apiUrl?: string;
6
6
  network: Network;
7
+ referralId?: string;
7
8
  }
8
9
  type BoltzSwapStatus = "invoice.expired" | "invoice.failedToPay" | "invoice.paid" | "invoice.pending" | "invoice.set" | "invoice.settled" | "swap.created" | "swap.expired" | "transaction.claim.pending" | "transaction.claimed" | "transaction.confirmed" | "transaction.failed" | "transaction.lockupFailed" | "transaction.mempool" | "transaction.refunded";
9
10
  declare const isSubmarineFinalStatus: (status: BoltzSwapStatus) => boolean;
@@ -71,6 +72,7 @@ declare class BoltzSwapProvider {
71
72
  private readonly wsUrl;
72
73
  private readonly apiUrl;
73
74
  private readonly network;
75
+ private readonly referralId?;
74
76
  constructor(config: SwapProviderConfig);
75
77
  getApiUrl(): string;
76
78
  getWsUrl(): string;
@@ -101,7 +103,7 @@ interface Vtxo {
101
103
  locktime: number;
102
104
  };
103
105
  }
104
- type Network = "bitcoin" | "mutinynet" | "regtest" | "signet";
106
+ type Network = NetworkName;
105
107
  interface CreateLightningInvoiceRequest {
106
108
  amount: number;
107
109
  description?: string;
package/dist/index.js CHANGED
@@ -157,6 +157,7 @@ var BoltzSwapProvider = class {
157
157
  wsUrl;
158
158
  apiUrl;
159
159
  network;
160
+ referralId;
160
161
  constructor(config) {
161
162
  this.network = config.network;
162
163
  const apiUrl = config.apiUrl || BASE_URLS[config.network];
@@ -253,15 +254,17 @@ var BoltzSwapProvider = class {
253
254
  message: "refundPublicKey must be a compressed public key"
254
255
  });
255
256
  }
257
+ const requestBody = {
258
+ from: "ARK",
259
+ to: "BTC",
260
+ invoice,
261
+ refundPublicKey,
262
+ ...this.referralId ? { referralId: this.referralId } : {}
263
+ };
256
264
  const response = await this.request(
257
265
  "/v2/swap/submarine",
258
266
  "POST",
259
- {
260
- from: "ARK",
261
- to: "BTC",
262
- invoice,
263
- refundPublicKey
264
- }
267
+ requestBody
265
268
  );
266
269
  if (!isCreateSubmarineSwapResponse(response))
267
270
  throw new SchemaError({ message: "Error creating submarine swap" });
@@ -284,7 +287,8 @@ var BoltzSwapProvider = class {
284
287
  invoiceAmount,
285
288
  claimPublicKey,
286
289
  preimageHash,
287
- ...description?.trim() ? { description: description.trim() } : {}
290
+ ...description?.trim() ? { description: description.trim() } : {},
291
+ ...this.referralId ? { referralId: this.referralId } : {}
288
292
  };
289
293
  const response = await this.request(
290
294
  "/v2/swap/reverse",
@@ -745,6 +749,18 @@ var ArkadeLightning = class {
745
749
  * @param pendingSwap - The pending submarine swap to refund the VHTLC.
746
750
  */
747
751
  async refundVHTLC(pendingSwap) {
752
+ const vhtlcPkScript = ArkAddress.decode(
753
+ pendingSwap.response.address
754
+ ).pkScript;
755
+ const spendableVtxos = await this.indexerProvider.getVtxos({
756
+ scripts: [hex.encode(vhtlcPkScript)],
757
+ spendableOnly: true
758
+ });
759
+ if (spendableVtxos.vtxos.length === 0) {
760
+ throw new Error(
761
+ `VHTLC not found for address ${pendingSwap.response.address}`
762
+ );
763
+ }
748
764
  const aspInfo = await this.arkProvider.getInfo();
749
765
  const address = await this.wallet.getAddress();
750
766
  if (!address) throw new Error("Failed to get ark address from wallet");
@@ -763,7 +779,7 @@ var ArkadeLightning = class {
763
779
  "boltz",
764
780
  pendingSwap.id
765
781
  );
766
- const { vhtlcScript, vhtlcAddress } = this.createVHTLCScript({
782
+ const { vhtlcScript } = this.createVHTLCScript({
767
783
  network: aspInfo.network,
768
784
  preimageHash: hex.decode(
769
785
  getInvoicePaymentHash(pendingSwap.request.invoice)
@@ -775,15 +791,6 @@ var ArkadeLightning = class {
775
791
  });
776
792
  if (!vhtlcScript)
777
793
  throw new Error("Failed to create VHTLC script for reverse swap");
778
- if (vhtlcAddress !== pendingSwap.response.address)
779
- throw new Error("Boltz is trying to scam us");
780
- const spendableVtxos = await this.indexerProvider.getVtxos({
781
- scripts: [hex.encode(vhtlcScript.pkScript)],
782
- spendableOnly: true
783
- });
784
- if (spendableVtxos.vtxos.length === 0) {
785
- throw new Error("No spendable virtual coins found");
786
- }
787
794
  const vhtlcIdentity = {
788
795
  sign: async (tx2, inputIndexes) => {
789
796
  const cpy = tx2.clone();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arkade-os/boltz-swap",
3
- "version": "0.2.9",
3
+ "version": "0.2.11",
4
4
  "type": "module",
5
5
  "description": "A production-ready TypeScript package that brings Boltz submarine-swaps to Arkade.",
6
6
  "main": "./dist/index.js",
@@ -30,7 +30,7 @@
30
30
  "author": "Arkade-OS",
31
31
  "license": "MIT",
32
32
  "dependencies": {
33
- "@arkade-os/sdk": "0.3.7",
33
+ "@arkade-os/sdk": "0.3.8",
34
34
  "@noble/hashes": "2.0.1",
35
35
  "@scure/base": "2.0.0",
36
36
  "@scure/btc-signer": "2.0.1",