@arkade-os/boltz-swap 0.1.8 → 0.2.0-alpha.1
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 +121 -34
- package/dist/index.cjs +449 -354
- package/dist/index.d.cts +94 -76
- package/dist/index.d.ts +94 -76
- package/dist/index.js +449 -353
- package/package.json +18 -17
package/README.md
CHANGED
|
@@ -24,8 +24,11 @@ npm install @arkade-os/sdk @arkade-os/boltz-swap
|
|
|
24
24
|
### Initializing the Lightning Swap Provider
|
|
25
25
|
|
|
26
26
|
```typescript
|
|
27
|
-
import { Wallet } from '@arkade-os/sdk';
|
|
28
|
-
import { ArkadeLightning, BoltzSwapProvider
|
|
27
|
+
import { Wallet, SingleKey } from '@arkade-os/sdk';
|
|
28
|
+
import { ArkadeLightning, BoltzSwapProvider } from '@arkade-os/boltz-swap';
|
|
29
|
+
|
|
30
|
+
// Create an identity
|
|
31
|
+
const identity = SingleKey.fromHex('your_private_key_in_hex');
|
|
29
32
|
|
|
30
33
|
// Initialize your Arkade wallet
|
|
31
34
|
const wallet = await Wallet.create({
|
|
@@ -39,22 +42,14 @@ const swapProvider = new BoltzSwapProvider({
|
|
|
39
42
|
network: 'mutinynet',
|
|
40
43
|
});
|
|
41
44
|
|
|
42
|
-
// Optionally: initialize a storage provider
|
|
43
|
-
const storageProvider = await StorageProvider.create();
|
|
44
|
-
|
|
45
45
|
// Create the ArkadeLightning instance
|
|
46
46
|
const arkadeLightning = new ArkadeLightning({
|
|
47
47
|
wallet,
|
|
48
48
|
swapProvider,
|
|
49
|
-
storageProvider, // optional
|
|
50
49
|
});
|
|
51
50
|
```
|
|
52
51
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
This library supports both wallet interface patterns:
|
|
56
|
-
|
|
57
|
-
### Wallet (with optional nested identity and providers)
|
|
52
|
+
### Create your Wallet
|
|
58
53
|
|
|
59
54
|
```typescript
|
|
60
55
|
import { Wallet } from '@arkade-os/sdk';
|
|
@@ -62,57 +57,149 @@ import { Wallet } from '@arkade-os/sdk';
|
|
|
62
57
|
const wallet = await Wallet.create({
|
|
63
58
|
identity,
|
|
64
59
|
arkServerUrl: 'https://mutinynet.arkade.sh',
|
|
60
|
+
// storage defaults to in-memory
|
|
65
61
|
});
|
|
66
62
|
|
|
67
63
|
// Wallet may have built-in providers
|
|
68
64
|
const arkadeLightning = new ArkadeLightning({
|
|
69
65
|
wallet,
|
|
70
|
-
swapProvider
|
|
71
|
-
// arkProvider and indexerProvider can be provided here if wallet doesn't have them
|
|
66
|
+
swapProvider
|
|
72
67
|
});
|
|
73
68
|
```
|
|
74
69
|
|
|
75
|
-
### ServiceWorkerWallet
|
|
70
|
+
### ServiceWorkerWallet with IndexDB
|
|
76
71
|
|
|
77
72
|
```typescript
|
|
78
|
-
import { RestArkProvider, RestIndexerProvider } from '@arkade-os/sdk';
|
|
73
|
+
import { ServiceWorkerWallet, SingleKey, RestArkProvider, RestIndexerProvider } from '@arkade-os/sdk';
|
|
74
|
+
import { IndexedDBStorageAdapter } from '@arkade-os/sdk/storage';
|
|
79
75
|
|
|
80
|
-
//
|
|
81
|
-
const
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
76
|
+
// Create your identity
|
|
77
|
+
const identity = SingleKey.fromHex('your_private_key_hex');
|
|
78
|
+
// Or generate a new one:
|
|
79
|
+
// const identity = SingleKey.fromRandomBytes();
|
|
80
|
+
|
|
81
|
+
// Configure IndexedDB storage adapter for ServiceWorker
|
|
82
|
+
const storage = new IndexedDBStorageAdapter('arkade-service-worker-wallet', 1);
|
|
83
|
+
|
|
84
|
+
const wallet = await ServiceWorkerWallet.setup({
|
|
85
|
+
serviceWorkerPath: '/service-worker.js',
|
|
86
|
+
arkServerUrl: 'https://mutinynet.arkade.sh',
|
|
87
|
+
identity,
|
|
88
|
+
storage, // Pass the IndexedDB storage adapter
|
|
85
89
|
});
|
|
86
90
|
|
|
87
91
|
// Must provide external providers for ServiceWorkerWallet (it doesn't have them)
|
|
88
92
|
const arkadeLightning = new ArkadeLightning({
|
|
89
93
|
wallet: serviceWorkerWallet,
|
|
90
|
-
arkProvider: new RestArkProvider('https://
|
|
91
|
-
indexerProvider: new RestIndexerProvider('https://
|
|
94
|
+
arkProvider: new RestArkProvider('https://mutinynet.arkade.sh'),
|
|
95
|
+
indexerProvider: new RestIndexerProvider('https://mutinynet.arkade.sh'),
|
|
92
96
|
swapProvider,
|
|
93
97
|
});
|
|
94
98
|
```
|
|
95
99
|
|
|
96
|
-
|
|
100
|
+
**Storage Adapters**: The Arkade SDK provides various storage adapters for different environments. For ServiceWorker environments, use `IndexedDBStorageAdapter`. For more storage options and adapters, see the [Arkade SDK storage adapters documentation](https://github.com/arkade-os/ts-sdk).
|
|
97
101
|
|
|
98
|
-
|
|
102
|
+
## Checking Swap Limits
|
|
99
103
|
|
|
100
|
-
|
|
104
|
+
Before creating Lightning invoices or sending payments, you can check the minimum and maximum swap amounts supported by the Boltz service. This is useful to validate that your invoice amount is within the acceptable range.
|
|
101
105
|
|
|
102
106
|
```typescript
|
|
103
|
-
|
|
107
|
+
// Get current swap limits (in satoshis)
|
|
108
|
+
const limits = await arkadeLightning.getLimits();
|
|
104
109
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
+
if (limits) {
|
|
111
|
+
console.log('Minimum swap amount:', limits.min, 'sats');
|
|
112
|
+
console.log('Maximum swap amount:', limits.max, 'sats');
|
|
113
|
+
|
|
114
|
+
// Example: Validate invoice amount before creating
|
|
115
|
+
const invoiceAmount = 50000; // 50,000 sats
|
|
116
|
+
|
|
117
|
+
if (invoiceAmount < limits.min) {
|
|
118
|
+
console.error(`Amount ${invoiceAmount} is below minimum ${limits.min} sats`);
|
|
119
|
+
} else if (invoiceAmount > limits.max) {
|
|
120
|
+
console.error(`Amount ${invoiceAmount} is above maximum ${limits.max} sats`);
|
|
121
|
+
} else {
|
|
122
|
+
console.log('Amount is within valid range');
|
|
123
|
+
// Safe to proceed with creating invoice or payment
|
|
124
|
+
}
|
|
125
|
+
} else {
|
|
126
|
+
console.log('Unable to fetch limits - no swap provider configured');
|
|
127
|
+
}
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### Validating Lightning Invoice Amounts
|
|
131
|
+
|
|
132
|
+
```typescript
|
|
133
|
+
import { decodeInvoice } from '@arkade-os/boltz-swap';
|
|
134
|
+
|
|
135
|
+
// Decode an incoming Lightning invoice to check its amount
|
|
136
|
+
const invoice = 'lnbc500u1pj...'; // Lightning invoice string
|
|
137
|
+
const decodedInvoice = decodeInvoice(invoice);
|
|
138
|
+
|
|
139
|
+
console.log('Invoice amount:', decodedInvoice.amountSats, 'sats');
|
|
140
|
+
|
|
141
|
+
// Check if the invoice amount is within swap limits
|
|
142
|
+
const limits = await arkadeLightning.getLimits();
|
|
143
|
+
|
|
144
|
+
if (limits && decodedInvoice.amountSats >= limits.min && decodedInvoice.amountSats <= limits.max) {
|
|
145
|
+
// Amount is valid for swaps
|
|
146
|
+
const paymentResult = await arkadeLightning.sendLightningPayment({
|
|
147
|
+
invoice: invoice,
|
|
148
|
+
maxFeeSats: 1000,
|
|
149
|
+
});
|
|
150
|
+
console.log('Payment successful!');
|
|
151
|
+
} else {
|
|
152
|
+
console.error('Invoice amount is outside supported swap limits');
|
|
153
|
+
}
|
|
154
|
+
```
|
|
155
|
+
|
|
156
|
+
## Checking Swap Fees
|
|
157
|
+
|
|
158
|
+
You can check the fee to pay for different swap amounts supported by the Boltz service.
|
|
159
|
+
This is useful to validate the user is willing to pay the fees.
|
|
160
|
+
|
|
161
|
+
```typescript
|
|
162
|
+
// Get current swap fees
|
|
163
|
+
const fees: FeesResponse | null = await arkadeLightning.getFees();
|
|
164
|
+
if (!fees) throw new Error('something went wrong');
|
|
165
|
+
|
|
166
|
+
const calcSubmarineSwapFee = (satoshis: number): number => {
|
|
167
|
+
if (!satoshis) return 0;
|
|
168
|
+
const { percentage, minerFees } = fees.submarine;
|
|
169
|
+
return Math.ceil((satoshis * percentage) / 100 + minerFees);
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
const calcReverseSwapFee = (satoshis: number): number => {
|
|
173
|
+
if (!satoshis) return 0;
|
|
174
|
+
const { percentage, minerFees } = fees.reverse;
|
|
175
|
+
return Math.ceil((satoshis * percentage) / 100 + minerFees.claim + minerFees.lockup);
|
|
176
|
+
};
|
|
177
|
+
```
|
|
178
|
+
|
|
179
|
+
## Checking swap status
|
|
180
|
+
|
|
181
|
+
```typescript
|
|
182
|
+
const response = await arkadeLightning.getSwapStatus('swap_id');
|
|
183
|
+
console.log('swap status = ', response.status);
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
## Storage
|
|
187
|
+
|
|
188
|
+
This library automatically stores pending swaps using the wallet's built-in contract repository. All swap data is persisted automatically and can be retrieved using the following methods:
|
|
189
|
+
|
|
190
|
+
```typescript
|
|
191
|
+
// Get all pending submarine swaps (those waiting for Lightning payment)
|
|
192
|
+
const pendingPaymentsToLightning = await arkadeLightning.getPendingSubmarineSwaps();
|
|
193
|
+
|
|
194
|
+
// Get all pending reverse swaps (those waiting for claim)
|
|
195
|
+
const pendingPaymentsFromLightning = await arkadeLightning.getPendingReverseSwaps();
|
|
110
196
|
|
|
111
|
-
//
|
|
112
|
-
const
|
|
113
|
-
const pendingPaymentsFromLightning = arkadeLightning.getPendingReverseSwaps();
|
|
197
|
+
// Get complete swap history (both completed and pending)
|
|
198
|
+
const swapHistory = await arkadeLightning.getSwapHistory();
|
|
114
199
|
```
|
|
115
200
|
|
|
201
|
+
**Note**: All swap data is automatically persisted and retrieved through the wallet's contract repository. No additional storage configuration is required.
|
|
202
|
+
|
|
116
203
|
## Receiving Lightning Payments
|
|
117
204
|
|
|
118
205
|
To receive a Lightning payment into your Arkade wallet:
|