@arkade-os/skill 0.1.1 → 0.1.3
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 +2 -3
- package/SKILL.md +9 -23
- package/cli/arkade.mjs +201 -174
- package/dist/cjs/index.js +1 -1
- package/dist/cjs/skills/index.js +1 -4
- package/dist/cjs/skills/index.js.map +1 -1
- package/dist/cjs/skills/lendaswap.js +248 -316
- package/dist/cjs/skills/lendaswap.js.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/skills/index.js +1 -4
- package/dist/esm/skills/index.js.map +1 -1
- package/dist/esm/skills/lendaswap.js +248 -316
- package/dist/esm/skills/lendaswap.js.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/skills/index.d.ts +2 -5
- package/dist/types/skills/index.d.ts.map +1 -1
- package/dist/types/skills/lendaswap.d.ts +44 -82
- package/dist/types/skills/lendaswap.d.ts.map +1 -1
- package/dist/types/skills/types.d.ts +80 -12
- package/dist/types/skills/types.d.ts.map +1 -1
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @arkade-os/skill
|
|
2
2
|
|
|
3
|
-
Arkade
|
|
3
|
+
Arkade skills for agent integration - send and receive Bitcoin over Arkade, onchain via onboard/offboard, Lightning Network via Boltz, and swap USDC/USDT via LendaSwap.
|
|
4
4
|
|
|
5
5
|
## Features
|
|
6
6
|
|
|
@@ -89,7 +89,7 @@ const lightning = new ArkaLightningSkill({ wallet, network: "bitcoin" });
|
|
|
89
89
|
const invoice = await lightning.createInvoice({ amount: 25000 });
|
|
90
90
|
|
|
91
91
|
// Stablecoin swaps
|
|
92
|
-
const lendaswap = new LendaSwapSkill({ wallet
|
|
92
|
+
const lendaswap = new LendaSwapSkill({ wallet });
|
|
93
93
|
const quote = await lendaswap.getQuoteBtcToStablecoin(100000, "usdc_pol");
|
|
94
94
|
```
|
|
95
95
|
|
|
@@ -127,7 +127,6 @@ const quote = await lendaswap.getQuoteBtcToStablecoin(100000, "usdc_pol");
|
|
|
127
127
|
## Configuration
|
|
128
128
|
|
|
129
129
|
- **Data:** `~/.arkade-wallet/config.json`
|
|
130
|
-
- **Env:** `LENDASWAP_API_KEY` for stablecoin swaps
|
|
131
130
|
|
|
132
131
|
## Documentation
|
|
133
132
|
|
package/SKILL.md
CHANGED
|
@@ -10,11 +10,9 @@ read_when:
|
|
|
10
10
|
- user wants to get paid onchain or pay someone onchain
|
|
11
11
|
- user mentions boarding address or VTXOs
|
|
12
12
|
- user wants instant Bitcoin payments
|
|
13
|
+
requires: []
|
|
13
14
|
metadata:
|
|
14
15
|
emoji: "₿"
|
|
15
|
-
requires:
|
|
16
|
-
- private key (64 hex characters)
|
|
17
|
-
- LENDASWAP_API_KEY (for stablecoin swaps)
|
|
18
16
|
---
|
|
19
17
|
|
|
20
18
|
# Arkade Skill
|
|
@@ -35,13 +33,11 @@ Swap between BTC and stablecoins (USDC/USDT) via LendaSwap.
|
|
|
35
33
|
|
|
36
34
|
```bash
|
|
37
35
|
# Using pnpm (recommended)
|
|
38
|
-
pnpm dlx @arkade-os/skill
|
|
39
|
-
pnpm dlx @arkade-os/skill init <private-key-hex>
|
|
36
|
+
pnpm dlx @arkade-os/skill init
|
|
40
37
|
pnpm dlx @arkade-os/skill address
|
|
41
38
|
|
|
42
39
|
# Using npx
|
|
43
|
-
npx -y -p @arkade-os/skill arkade
|
|
44
|
-
npx -y -p @arkade-os/skill arkade init <private-key-hex>
|
|
40
|
+
npx -y -p @arkade-os/skill arkade init
|
|
45
41
|
npx -y -p @arkade-os/skill arkade address
|
|
46
42
|
```
|
|
47
43
|
|
|
@@ -54,8 +50,7 @@ npm install -g @arkade-os/skill
|
|
|
54
50
|
pnpm add -g @arkade-os/skill
|
|
55
51
|
|
|
56
52
|
# Then use directly
|
|
57
|
-
arkade
|
|
58
|
-
arkade init <private-key-hex>
|
|
53
|
+
arkade init
|
|
59
54
|
arkade address
|
|
60
55
|
```
|
|
61
56
|
|
|
@@ -76,14 +71,11 @@ pnpm add @arkade-os/skill
|
|
|
76
71
|
### Wallet Management
|
|
77
72
|
|
|
78
73
|
```bash
|
|
79
|
-
#
|
|
80
|
-
arkade
|
|
81
|
-
|
|
82
|
-
# Initialize wallet with private key (default server: arkade.computer)
|
|
83
|
-
arkade init <private-key-hex>
|
|
74
|
+
# Initialize wallet (auto-generates private key, default server: arkade.computer)
|
|
75
|
+
arkade init
|
|
84
76
|
|
|
85
77
|
# Initialize with custom server
|
|
86
|
-
arkade init
|
|
78
|
+
arkade init https://custom-server.com
|
|
87
79
|
|
|
88
80
|
# Show Ark address (for receiving offchain Bitcoin)
|
|
89
81
|
arkade address
|
|
@@ -151,8 +143,6 @@ arkade ln-pending
|
|
|
151
143
|
|
|
152
144
|
### Stablecoin Swaps (LendaSwap)
|
|
153
145
|
|
|
154
|
-
Requires `LENDASWAP_API_KEY` environment variable.
|
|
155
|
-
|
|
156
146
|
```bash
|
|
157
147
|
# Get quote for BTC to stablecoin swap
|
|
158
148
|
arkade swap-quote <amount-sats> <from> <to>
|
|
@@ -229,10 +219,7 @@ const payment = await lightning.payInvoice({
|
|
|
229
219
|
console.log("Paid! Preimage:", payment.preimage);
|
|
230
220
|
|
|
231
221
|
// === Stablecoin Swaps ===
|
|
232
|
-
const lendaswap = new LendaSwapSkill({
|
|
233
|
-
wallet,
|
|
234
|
-
apiKey: process.env.LENDASWAP_API_KEY,
|
|
235
|
-
});
|
|
222
|
+
const lendaswap = new LendaSwapSkill({ wallet });
|
|
236
223
|
|
|
237
224
|
// Get quote
|
|
238
225
|
const quote = await lendaswap.getQuoteBtcToStablecoin(100000, "usdc_pol");
|
|
@@ -252,8 +239,7 @@ console.log("Swap ID:", swap.swapId);
|
|
|
252
239
|
|
|
253
240
|
**Data Storage:** `~/.arkade-wallet/config.json`
|
|
254
241
|
|
|
255
|
-
|
|
256
|
-
- `LENDASWAP_API_KEY` - Required for stablecoin swaps
|
|
242
|
+
Private keys are auto-generated on first use and stored locally. They are never exposed via CLI arguments or stdout. No environment variables required. The LendaSwap API is publicly accessible.
|
|
257
243
|
|
|
258
244
|
## Skill Interfaces
|
|
259
245
|
|
package/cli/arkade.mjs
CHANGED
|
@@ -5,12 +5,12 @@
|
|
|
5
5
|
*
|
|
6
6
|
* This CLI is designed for agent integration (CLI-friendly for agents like MoltBot).
|
|
7
7
|
* Data is stored in ~/.arkade-wallet/config.json
|
|
8
|
+
* Private keys are auto-generated and stored locally — never exposed via CLI args.
|
|
8
9
|
*
|
|
9
10
|
* Default server: https://arkade.computer
|
|
10
11
|
*
|
|
11
12
|
* Usage:
|
|
12
|
-
* arkade
|
|
13
|
-
* arkade init <key> [url] # Initialize wallet
|
|
13
|
+
* arkade init [url] # Initialize wallet (auto-generates key)
|
|
14
14
|
* arkade address # Show Ark address
|
|
15
15
|
* arkade boarding-address # Show boarding address
|
|
16
16
|
* arkade balance # Show balance breakdown
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
* arkade help # Show help
|
|
29
29
|
*/
|
|
30
30
|
|
|
31
|
-
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
31
|
+
import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
|
|
32
32
|
import { homedir } from "node:os";
|
|
33
33
|
import { join } from "node:path";
|
|
34
34
|
|
|
@@ -55,9 +55,10 @@ function loadConfig() {
|
|
|
55
55
|
*/
|
|
56
56
|
function saveConfig(config) {
|
|
57
57
|
if (!existsSync(CONFIG_DIR)) {
|
|
58
|
-
mkdirSync(CONFIG_DIR, { recursive: true });
|
|
58
|
+
mkdirSync(CONFIG_DIR, { recursive: true, mode: 0o700 });
|
|
59
59
|
}
|
|
60
60
|
writeFileSync(CONFIG_FILE, JSON.stringify(config, null, 2));
|
|
61
|
+
chmodSync(CONFIG_FILE, 0o600);
|
|
61
62
|
}
|
|
62
63
|
|
|
63
64
|
/**
|
|
@@ -86,15 +87,35 @@ async function getSDK() {
|
|
|
86
87
|
}
|
|
87
88
|
|
|
88
89
|
/**
|
|
89
|
-
*
|
|
90
|
+
* Auto-initialize wallet config by generating a new private key.
|
|
91
|
+
*/
|
|
92
|
+
async function autoInit(serverUrl) {
|
|
93
|
+
const { sdk } = await getSDK();
|
|
94
|
+
const { SingleKey } = sdk;
|
|
95
|
+
|
|
96
|
+
const identity = SingleKey.fromRandomBytes();
|
|
97
|
+
const privateKey = Buffer.from(identity.key).toString("hex");
|
|
98
|
+
const url = serverUrl || DEFAULT_SERVER;
|
|
99
|
+
|
|
100
|
+
const config = {
|
|
101
|
+
privateKey,
|
|
102
|
+
serverUrl: url,
|
|
103
|
+
createdAt: new Date().toISOString(),
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
saveConfig(config);
|
|
107
|
+
return config;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Create wallet from config, auto-initializing if needed.
|
|
90
112
|
*/
|
|
91
113
|
async function createWallet() {
|
|
92
|
-
|
|
114
|
+
let config = loadConfig();
|
|
93
115
|
if (!config) {
|
|
94
|
-
console.error(
|
|
95
|
-
|
|
96
|
-
);
|
|
97
|
-
process.exit(1);
|
|
116
|
+
console.error("No wallet found. Auto-generating a new private key...");
|
|
117
|
+
config = await autoInit();
|
|
118
|
+
console.error("Wallet initialized. Config saved to ~/.arkade-wallet/config.json");
|
|
98
119
|
}
|
|
99
120
|
|
|
100
121
|
const { sdk } = await getSDK();
|
|
@@ -126,41 +147,41 @@ USAGE:
|
|
|
126
147
|
arkade <command> [options]
|
|
127
148
|
|
|
128
149
|
COMMANDS:
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
Default server: arkade.computer
|
|
150
|
+
init [url] Initialize wallet (auto-generates key)
|
|
151
|
+
Default server: arkade.computer
|
|
132
152
|
|
|
133
|
-
address
|
|
134
|
-
boarding-address
|
|
135
|
-
balance
|
|
153
|
+
address Show Ark address (for receiving offchain)
|
|
154
|
+
boarding-address Show boarding address (for onchain deposits)
|
|
155
|
+
balance Show balance breakdown
|
|
136
156
|
|
|
137
|
-
send <address> <amount>
|
|
138
|
-
history
|
|
157
|
+
send <address> <amount> Send satoshis to an Ark address
|
|
158
|
+
history Show transaction history
|
|
139
159
|
|
|
140
|
-
onboard
|
|
141
|
-
offboard <btc-address>
|
|
160
|
+
onboard Move funds from onchain to offchain (Arkade)
|
|
161
|
+
offboard <btc-address> Move funds from offchain to onchain
|
|
142
162
|
|
|
143
|
-
ln-invoice <amount> [desc]
|
|
144
|
-
ln-pay <bolt11>
|
|
145
|
-
ln-fees
|
|
146
|
-
ln-limits
|
|
147
|
-
ln-pending
|
|
163
|
+
ln-invoice <amount> [desc] Create a Lightning invoice
|
|
164
|
+
ln-pay <bolt11> Pay a Lightning invoice
|
|
165
|
+
ln-fees Show Lightning swap fees
|
|
166
|
+
ln-limits Show Lightning swap limits
|
|
167
|
+
ln-pending Show pending Lightning swaps
|
|
148
168
|
|
|
149
169
|
swap-quote <amt> <from> <to> Get stablecoin swap quote
|
|
150
170
|
swap-to-stable <amt> <token> <chain> <evm-addr>
|
|
151
|
-
|
|
171
|
+
Swap BTC to stablecoin
|
|
152
172
|
swap-to-btc <amt> <token> <chain> <evm-addr>
|
|
153
|
-
|
|
154
|
-
swap-
|
|
155
|
-
swap-
|
|
156
|
-
swap-
|
|
173
|
+
Swap stablecoin to BTC
|
|
174
|
+
swap-claim <swap-id> Claim a completed swap
|
|
175
|
+
swap-refund <swap-id> [addr] Refund an expired/failed swap
|
|
176
|
+
swap-status <swap-id> Check swap status
|
|
177
|
+
swap-pending Show pending stablecoin swaps
|
|
178
|
+
swap-pairs Show available stablecoin pairs
|
|
157
179
|
|
|
158
|
-
help
|
|
180
|
+
help Show this help message
|
|
159
181
|
|
|
160
182
|
EXAMPLES:
|
|
161
|
-
arkade
|
|
162
|
-
arkade init
|
|
163
|
-
arkade init abc123... https://custom-server.com
|
|
183
|
+
arkade init
|
|
184
|
+
arkade init https://custom-server.com
|
|
164
185
|
arkade balance
|
|
165
186
|
arkade send ark1... 50000
|
|
166
187
|
arkade ln-invoice 25000 "Coffee payment"
|
|
@@ -168,70 +189,49 @@ EXAMPLES:
|
|
|
168
189
|
arkade swap-to-stable 100000 usdc_pol polygon 0x...
|
|
169
190
|
arkade swap-to-btc 100 usdc_pol polygon 0x...
|
|
170
191
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
CONFIG:
|
|
175
|
-
Data stored in: ~/.arkade-wallet/config.json
|
|
192
|
+
NOTE:
|
|
193
|
+
Private keys are auto-generated and stored securely in ~/.arkade-wallet/config.json.
|
|
194
|
+
They are never exposed via CLI arguments or stdout.
|
|
176
195
|
`);
|
|
177
196
|
}
|
|
178
197
|
|
|
179
198
|
/**
|
|
180
|
-
*
|
|
199
|
+
* Initialize wallet command. Auto-generates a new private key.
|
|
200
|
+
* If a wallet already exists, shows its address without overwriting.
|
|
181
201
|
*/
|
|
182
|
-
async function
|
|
183
|
-
const
|
|
202
|
+
async function cmdInit(serverUrl) {
|
|
203
|
+
const existing = loadConfig();
|
|
204
|
+
if (existing) {
|
|
205
|
+
const { sdk } = await getSDK();
|
|
206
|
+
const { Wallet, SingleKey } = sdk;
|
|
184
207
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
console.log(privateKey);
|
|
190
|
-
console.log("");
|
|
191
|
-
console.log("IMPORTANT: Save this key securely! It cannot be recovered.");
|
|
192
|
-
console.log("");
|
|
193
|
-
console.log("To initialize your wallet, run:");
|
|
194
|
-
console.log(` arkade init ${privateKey}`);
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
* Initialize wallet command.
|
|
199
|
-
*/
|
|
200
|
-
async function cmdInit(privateKey, serverUrl) {
|
|
201
|
-
if (!privateKey) {
|
|
202
|
-
console.error("Error: Private key required.");
|
|
203
|
-
console.error("Usage: arkade init <private-key-hex> [server-url]");
|
|
204
|
-
process.exit(1);
|
|
205
|
-
}
|
|
208
|
+
const wallet = await Wallet.create({
|
|
209
|
+
identity: SingleKey.fromHex(existing.privateKey),
|
|
210
|
+
arkServerUrl: existing.serverUrl || DEFAULT_SERVER,
|
|
211
|
+
});
|
|
206
212
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
console.
|
|
210
|
-
|
|
213
|
+
const address = await wallet.getAddress();
|
|
214
|
+
console.log("Wallet already initialized.");
|
|
215
|
+
console.log(`Server: ${existing.serverUrl || DEFAULT_SERVER}`);
|
|
216
|
+
console.log(`Address: ${address}`);
|
|
217
|
+
return;
|
|
211
218
|
}
|
|
212
219
|
|
|
213
|
-
|
|
220
|
+
try {
|
|
221
|
+
const config = await autoInit(serverUrl);
|
|
214
222
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
const { Wallet, SingleKey } = sdk;
|
|
223
|
+
const { sdk } = await getSDK();
|
|
224
|
+
const { Wallet, SingleKey } = sdk;
|
|
218
225
|
|
|
219
|
-
try {
|
|
220
226
|
const wallet = await Wallet.create({
|
|
221
|
-
identity: SingleKey.fromHex(privateKey),
|
|
222
|
-
arkServerUrl:
|
|
227
|
+
identity: SingleKey.fromHex(config.privateKey),
|
|
228
|
+
arkServerUrl: config.serverUrl,
|
|
223
229
|
});
|
|
224
230
|
|
|
225
231
|
const address = await wallet.getAddress();
|
|
226
232
|
|
|
227
|
-
saveConfig({
|
|
228
|
-
privateKey,
|
|
229
|
-
serverUrl: url,
|
|
230
|
-
createdAt: new Date().toISOString(),
|
|
231
|
-
});
|
|
232
|
-
|
|
233
233
|
console.log("Wallet initialized successfully!");
|
|
234
|
-
console.log(`Server: ${
|
|
234
|
+
console.log(`Server: ${config.serverUrl}`);
|
|
235
235
|
console.log(`Address: ${address}`);
|
|
236
236
|
} catch (e) {
|
|
237
237
|
console.error(`Error: Failed to initialize wallet: ${e.message}`);
|
|
@@ -615,6 +615,44 @@ async function cmdLnPending() {
|
|
|
615
615
|
}
|
|
616
616
|
}
|
|
617
617
|
|
|
618
|
+
/**
|
|
619
|
+
* Create a LendaSwapSkill with mnemonic persistence.
|
|
620
|
+
* Loads mnemonic from config, and saves it back after first initialization.
|
|
621
|
+
*/
|
|
622
|
+
async function createLendaSwap() {
|
|
623
|
+
const wallet = await createWallet();
|
|
624
|
+
const { skill } = await getSDK();
|
|
625
|
+
const { LendaSwapSkill } = skill;
|
|
626
|
+
|
|
627
|
+
const config = loadConfig();
|
|
628
|
+
const options = {};
|
|
629
|
+
|
|
630
|
+
if (config.lendaswapMnemonic) {
|
|
631
|
+
options.mnemonic = config.lendaswapMnemonic;
|
|
632
|
+
}
|
|
633
|
+
if (process.env.LENDASWAP_API_KEY) {
|
|
634
|
+
options.apiKey = process.env.LENDASWAP_API_KEY;
|
|
635
|
+
}
|
|
636
|
+
if (process.env.LENDASWAP_API_URL) {
|
|
637
|
+
options.apiUrl = process.env.LENDASWAP_API_URL;
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
const lendaswap = new LendaSwapSkill({ wallet, ...options });
|
|
641
|
+
|
|
642
|
+
// Persist mnemonic after first SDK client initialization
|
|
643
|
+
if (!config.lendaswapMnemonic) {
|
|
644
|
+
try {
|
|
645
|
+
const mnemonic = await lendaswap.getMnemonic();
|
|
646
|
+
config.lendaswapMnemonic = mnemonic;
|
|
647
|
+
saveConfig(config);
|
|
648
|
+
} catch {
|
|
649
|
+
// Non-fatal: mnemonic save failed, will generate a new one next time
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
|
|
653
|
+
return lendaswap;
|
|
654
|
+
}
|
|
655
|
+
|
|
618
656
|
/**
|
|
619
657
|
* Get stablecoin quote command.
|
|
620
658
|
*/
|
|
@@ -626,20 +664,7 @@ async function cmdSwapQuote(amount, from, to) {
|
|
|
626
664
|
process.exit(1);
|
|
627
665
|
}
|
|
628
666
|
|
|
629
|
-
const
|
|
630
|
-
if (!apiKey) {
|
|
631
|
-
console.error("Error: LENDASWAP_API_KEY environment variable required.");
|
|
632
|
-
process.exit(1);
|
|
633
|
-
}
|
|
634
|
-
|
|
635
|
-
const wallet = await createWallet();
|
|
636
|
-
const { skill } = await getSDK();
|
|
637
|
-
const { LendaSwapSkill } = skill;
|
|
638
|
-
|
|
639
|
-
const lendaswap = new LendaSwapSkill({
|
|
640
|
-
wallet,
|
|
641
|
-
apiKey,
|
|
642
|
-
});
|
|
667
|
+
const lendaswap = await createLendaSwap();
|
|
643
668
|
|
|
644
669
|
try {
|
|
645
670
|
let quote;
|
|
@@ -691,26 +716,13 @@ async function cmdSwapToStable(
|
|
|
691
716
|
process.exit(1);
|
|
692
717
|
}
|
|
693
718
|
|
|
694
|
-
const apiKey = process.env.LENDASWAP_API_KEY;
|
|
695
|
-
if (!apiKey) {
|
|
696
|
-
console.error("Error: LENDASWAP_API_KEY environment variable required.");
|
|
697
|
-
process.exit(1);
|
|
698
|
-
}
|
|
699
|
-
|
|
700
719
|
const sats = parseInt(amount, 10);
|
|
701
720
|
if (isNaN(sats) || sats <= 0) {
|
|
702
721
|
console.error("Error: Invalid amount.");
|
|
703
722
|
process.exit(1);
|
|
704
723
|
}
|
|
705
724
|
|
|
706
|
-
const
|
|
707
|
-
const { skill } = await getSDK();
|
|
708
|
-
const { LendaSwapSkill } = skill;
|
|
709
|
-
|
|
710
|
-
const lendaswap = new LendaSwapSkill({
|
|
711
|
-
wallet,
|
|
712
|
-
apiKey,
|
|
713
|
-
});
|
|
725
|
+
const lendaswap = await createLendaSwap();
|
|
714
726
|
|
|
715
727
|
console.log(`Swapping ${formatSats(sats)} sats to ${targetToken}...`);
|
|
716
728
|
|
|
@@ -726,10 +738,10 @@ async function cmdSwapToStable(
|
|
|
726
738
|
console.log(`Swap ID: ${result.swapId}`);
|
|
727
739
|
console.log(`Status: ${result.status}`);
|
|
728
740
|
console.log(`Expected: ${result.targetAmount} ${targetToken}`);
|
|
729
|
-
console.log(`Rate: ${result.exchangeRate}`);
|
|
730
741
|
if (result.paymentDetails?.address) {
|
|
731
742
|
console.log(`Payment Address: ${result.paymentDetails.address}`);
|
|
732
743
|
}
|
|
744
|
+
console.log(`Fee: ${result.fee.amount} sats`);
|
|
733
745
|
console.log(`Expires: ${result.expiresAt.toLocaleString()}`);
|
|
734
746
|
} catch (e) {
|
|
735
747
|
console.error(`Error: ${e.message}`);
|
|
@@ -750,27 +762,14 @@ async function cmdSwapToBtc(amount, sourceToken, sourceChain, evmAddress) {
|
|
|
750
762
|
process.exit(1);
|
|
751
763
|
}
|
|
752
764
|
|
|
753
|
-
const apiKey = process.env.LENDASWAP_API_KEY;
|
|
754
|
-
if (!apiKey) {
|
|
755
|
-
console.error("Error: LENDASWAP_API_KEY environment variable required.");
|
|
756
|
-
process.exit(1);
|
|
757
|
-
}
|
|
758
|
-
|
|
759
765
|
const tokenAmount = parseFloat(amount);
|
|
760
766
|
if (isNaN(tokenAmount) || tokenAmount <= 0) {
|
|
761
767
|
console.error("Error: Invalid amount.");
|
|
762
768
|
process.exit(1);
|
|
763
769
|
}
|
|
764
770
|
|
|
765
|
-
const
|
|
766
|
-
const
|
|
767
|
-
const { LendaSwapSkill } = skill;
|
|
768
|
-
|
|
769
|
-
const lendaswap = new LendaSwapSkill({
|
|
770
|
-
wallet,
|
|
771
|
-
apiKey,
|
|
772
|
-
});
|
|
773
|
-
|
|
771
|
+
const lendaswap = await createLendaSwap();
|
|
772
|
+
const wallet = lendaswap.getWallet();
|
|
774
773
|
const arkAddress = await wallet.getAddress();
|
|
775
774
|
|
|
776
775
|
console.log(`Swapping ${tokenAmount} ${sourceToken} to BTC...`);
|
|
@@ -788,13 +787,13 @@ async function cmdSwapToBtc(amount, sourceToken, sourceChain, evmAddress) {
|
|
|
788
787
|
console.log(`Swap ID: ${result.swapId}`);
|
|
789
788
|
console.log(`Status: ${result.status}`);
|
|
790
789
|
console.log(`Expected: ${result.targetAmount} sats`);
|
|
791
|
-
console.log(`Rate: ${result.exchangeRate}`);
|
|
792
790
|
if (result.paymentDetails?.address) {
|
|
793
791
|
console.log(`HTLC Address: ${result.paymentDetails.address}`);
|
|
794
792
|
}
|
|
795
793
|
if (result.paymentDetails?.callData) {
|
|
796
|
-
console.log(`
|
|
794
|
+
console.log(`Token Address: ${result.paymentDetails.callData}`);
|
|
797
795
|
}
|
|
796
|
+
console.log(`Fee: ${result.fee.amount} sats`);
|
|
798
797
|
console.log(`Expires: ${result.expiresAt.toLocaleString()}`);
|
|
799
798
|
} catch (e) {
|
|
800
799
|
console.error(`Error: ${e.message}`);
|
|
@@ -812,20 +811,7 @@ async function cmdSwapStatus(swapId) {
|
|
|
812
811
|
process.exit(1);
|
|
813
812
|
}
|
|
814
813
|
|
|
815
|
-
const
|
|
816
|
-
if (!apiKey) {
|
|
817
|
-
console.error("Error: LENDASWAP_API_KEY environment variable required.");
|
|
818
|
-
process.exit(1);
|
|
819
|
-
}
|
|
820
|
-
|
|
821
|
-
const wallet = await createWallet();
|
|
822
|
-
const { skill } = await getSDK();
|
|
823
|
-
const { LendaSwapSkill } = skill;
|
|
824
|
-
|
|
825
|
-
const lendaswap = new LendaSwapSkill({
|
|
826
|
-
wallet,
|
|
827
|
-
apiKey,
|
|
828
|
-
});
|
|
814
|
+
const lendaswap = await createLendaSwap();
|
|
829
815
|
|
|
830
816
|
try {
|
|
831
817
|
const status = await lendaswap.getSwapStatus(swapId);
|
|
@@ -837,7 +823,6 @@ async function cmdSwapStatus(swapId) {
|
|
|
837
823
|
console.log(`Status: ${status.status}`);
|
|
838
824
|
console.log(`From: ${status.sourceAmount} ${status.sourceToken}`);
|
|
839
825
|
console.log(`To: ${status.targetAmount} ${status.targetToken}`);
|
|
840
|
-
console.log(`Rate: ${status.exchangeRate}`);
|
|
841
826
|
console.log(`Created: ${status.createdAt.toLocaleString()}`);
|
|
842
827
|
if (status.completedAt) {
|
|
843
828
|
console.log(`Completed: ${status.completedAt.toLocaleString()}`);
|
|
@@ -855,20 +840,7 @@ async function cmdSwapStatus(swapId) {
|
|
|
855
840
|
* Show pending stablecoin swaps command.
|
|
856
841
|
*/
|
|
857
842
|
async function cmdSwapPending() {
|
|
858
|
-
const
|
|
859
|
-
if (!apiKey) {
|
|
860
|
-
console.error("Error: LENDASWAP_API_KEY environment variable required.");
|
|
861
|
-
process.exit(1);
|
|
862
|
-
}
|
|
863
|
-
|
|
864
|
-
const wallet = await createWallet();
|
|
865
|
-
const { skill } = await getSDK();
|
|
866
|
-
const { LendaSwapSkill } = skill;
|
|
867
|
-
|
|
868
|
-
const lendaswap = new LendaSwapSkill({
|
|
869
|
-
wallet,
|
|
870
|
-
apiKey,
|
|
871
|
-
});
|
|
843
|
+
const lendaswap = await createLendaSwap();
|
|
872
844
|
|
|
873
845
|
try {
|
|
874
846
|
const pending = await lendaswap.getPendingSwaps();
|
|
@@ -898,20 +870,7 @@ async function cmdSwapPending() {
|
|
|
898
870
|
* Show available stablecoin pairs command.
|
|
899
871
|
*/
|
|
900
872
|
async function cmdSwapPairs() {
|
|
901
|
-
const
|
|
902
|
-
if (!apiKey) {
|
|
903
|
-
console.error("Error: LENDASWAP_API_KEY environment variable required.");
|
|
904
|
-
process.exit(1);
|
|
905
|
-
}
|
|
906
|
-
|
|
907
|
-
const wallet = await createWallet();
|
|
908
|
-
const { skill } = await getSDK();
|
|
909
|
-
const { LendaSwapSkill } = skill;
|
|
910
|
-
|
|
911
|
-
const lendaswap = new LendaSwapSkill({
|
|
912
|
-
wallet,
|
|
913
|
-
apiKey,
|
|
914
|
-
});
|
|
873
|
+
const lendaswap = await createLendaSwap();
|
|
915
874
|
|
|
916
875
|
try {
|
|
917
876
|
const pairs = await lendaswap.getAvailablePairs();
|
|
@@ -931,6 +890,71 @@ async function cmdSwapPairs() {
|
|
|
931
890
|
}
|
|
932
891
|
}
|
|
933
892
|
|
|
893
|
+
/**
|
|
894
|
+
* Claim a swap command.
|
|
895
|
+
*/
|
|
896
|
+
async function cmdSwapClaim(swapId) {
|
|
897
|
+
if (!swapId) {
|
|
898
|
+
console.error("Error: Swap ID required.");
|
|
899
|
+
console.error("Usage: arkade swap-claim <swap-id>");
|
|
900
|
+
process.exit(1);
|
|
901
|
+
}
|
|
902
|
+
|
|
903
|
+
const lendaswap = await createLendaSwap();
|
|
904
|
+
|
|
905
|
+
try {
|
|
906
|
+
const result = await lendaswap.claimSwap(swapId);
|
|
907
|
+
|
|
908
|
+
if (result.success) {
|
|
909
|
+
console.log("Swap claimed successfully!");
|
|
910
|
+
if (result.chain) {
|
|
911
|
+
console.log(`Chain: ${result.chain}`);
|
|
912
|
+
}
|
|
913
|
+
if (result.txHash) {
|
|
914
|
+
console.log(`TX Hash: ${result.txHash}`);
|
|
915
|
+
}
|
|
916
|
+
} else {
|
|
917
|
+
console.log(`Claim status: ${result.message}`);
|
|
918
|
+
}
|
|
919
|
+
} catch (e) {
|
|
920
|
+
console.error(`Error: ${e.message}`);
|
|
921
|
+
process.exit(1);
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
|
|
925
|
+
/**
|
|
926
|
+
* Refund a swap command.
|
|
927
|
+
*/
|
|
928
|
+
async function cmdSwapRefund(swapId, destinationAddress) {
|
|
929
|
+
if (!swapId) {
|
|
930
|
+
console.error("Error: Swap ID required.");
|
|
931
|
+
console.error("Usage: arkade swap-refund <swap-id> [destination-address]");
|
|
932
|
+
process.exit(1);
|
|
933
|
+
}
|
|
934
|
+
|
|
935
|
+
const lendaswap = await createLendaSwap();
|
|
936
|
+
|
|
937
|
+
try {
|
|
938
|
+
const options = destinationAddress ? { destinationAddress } : undefined;
|
|
939
|
+
const result = await lendaswap.refundSwap(swapId, options);
|
|
940
|
+
|
|
941
|
+
if (result.success) {
|
|
942
|
+
console.log("Swap refunded successfully!");
|
|
943
|
+
if (result.txId) {
|
|
944
|
+
console.log(`TX ID: ${result.txId}`);
|
|
945
|
+
}
|
|
946
|
+
if (result.refundAmount != null) {
|
|
947
|
+
console.log(`Refund Amount: ${formatSats(result.refundAmount)} sats`);
|
|
948
|
+
}
|
|
949
|
+
} else {
|
|
950
|
+
console.log(`Refund status: ${result.message}`);
|
|
951
|
+
}
|
|
952
|
+
} catch (e) {
|
|
953
|
+
console.error(`Error: ${e.message}`);
|
|
954
|
+
process.exit(1);
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
|
|
934
958
|
/**
|
|
935
959
|
* Main entry point.
|
|
936
960
|
*/
|
|
@@ -939,11 +963,8 @@ async function main() {
|
|
|
939
963
|
const command = args[0];
|
|
940
964
|
|
|
941
965
|
switch (command) {
|
|
942
|
-
case "generate":
|
|
943
|
-
await cmdGenerate();
|
|
944
|
-
break;
|
|
945
966
|
case "init":
|
|
946
|
-
await cmdInit(args[1]
|
|
967
|
+
await cmdInit(args[1]);
|
|
947
968
|
break;
|
|
948
969
|
case "address":
|
|
949
970
|
await cmdAddress();
|
|
@@ -990,6 +1011,12 @@ async function main() {
|
|
|
990
1011
|
case "swap-to-btc":
|
|
991
1012
|
await cmdSwapToBtc(args[1], args[2], args[3], args[4]);
|
|
992
1013
|
break;
|
|
1014
|
+
case "swap-claim":
|
|
1015
|
+
await cmdSwapClaim(args[1]);
|
|
1016
|
+
break;
|
|
1017
|
+
case "swap-refund":
|
|
1018
|
+
await cmdSwapRefund(args[1], args[2]);
|
|
1019
|
+
break;
|
|
993
1020
|
case "swap-status":
|
|
994
1021
|
await cmdSwapStatus(args[1]);
|
|
995
1022
|
break;
|
package/dist/cjs/index.js
CHANGED
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
* const invoice = await lightning.createInvoice({ amount: 50000 });
|
|
38
38
|
*
|
|
39
39
|
* // Stablecoin swaps
|
|
40
|
-
* const lendaswap = new LendaSwapSkill({ wallet
|
|
40
|
+
* const lendaswap = new LendaSwapSkill({ wallet });
|
|
41
41
|
* const quote = await lendaswap.getQuoteBtcToStablecoin(100000, "usdc_pol");
|
|
42
42
|
* ```
|
|
43
43
|
*
|
package/dist/cjs/skills/index.js
CHANGED
|
@@ -49,10 +49,7 @@
|
|
|
49
49
|
* console.log("Invoice:", invoice.bolt11);
|
|
50
50
|
*
|
|
51
51
|
* // === LendaSwap Skill ===
|
|
52
|
-
* const lendaswap = new LendaSwapSkill({
|
|
53
|
-
* wallet,
|
|
54
|
-
* apiKey: process.env.LENDASWAP_API_KEY,
|
|
55
|
-
* });
|
|
52
|
+
* const lendaswap = new LendaSwapSkill({ wallet });
|
|
56
53
|
*
|
|
57
54
|
* // Get quote for BTC to USDC
|
|
58
55
|
* const quote = await lendaswap.getQuoteBtcToStablecoin(100000, "usdc_pol");
|