@blockrun/clawrouter 0.11.14 → 0.12.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 +6 -6
- package/dist/cli.js +622 -47
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +55 -3
- package/dist/index.js +974 -41
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -95,7 +95,10 @@ var init_solana_balance = __esm({
|
|
|
95
95
|
}
|
|
96
96
|
return total;
|
|
97
97
|
} catch (err) {
|
|
98
|
-
throw new Error(
|
|
98
|
+
throw new Error(
|
|
99
|
+
`Failed to fetch Solana USDC balance: ${err instanceof Error ? err.message : String(err)}`,
|
|
100
|
+
{ cause: err }
|
|
101
|
+
);
|
|
99
102
|
} finally {
|
|
100
103
|
clearTimeout(timer);
|
|
101
104
|
}
|
|
@@ -114,12 +117,546 @@ var init_solana_balance = __esm({
|
|
|
114
117
|
}
|
|
115
118
|
});
|
|
116
119
|
|
|
120
|
+
// node_modules/@noble/hashes/esm/utils.js
|
|
121
|
+
function isBytes(a) {
|
|
122
|
+
return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array";
|
|
123
|
+
}
|
|
124
|
+
function anumber(n) {
|
|
125
|
+
if (!Number.isSafeInteger(n) || n < 0)
|
|
126
|
+
throw new Error("positive integer expected, got " + n);
|
|
127
|
+
}
|
|
128
|
+
function abytes(b, ...lengths) {
|
|
129
|
+
if (!isBytes(b))
|
|
130
|
+
throw new Error("Uint8Array expected");
|
|
131
|
+
if (lengths.length > 0 && !lengths.includes(b.length))
|
|
132
|
+
throw new Error("Uint8Array expected of length " + lengths + ", got length=" + b.length);
|
|
133
|
+
}
|
|
134
|
+
function ahash(h) {
|
|
135
|
+
if (typeof h !== "function" || typeof h.create !== "function")
|
|
136
|
+
throw new Error("Hash should be wrapped by utils.createHasher");
|
|
137
|
+
anumber(h.outputLen);
|
|
138
|
+
anumber(h.blockLen);
|
|
139
|
+
}
|
|
140
|
+
function aexists(instance, checkFinished = true) {
|
|
141
|
+
if (instance.destroyed)
|
|
142
|
+
throw new Error("Hash instance has been destroyed");
|
|
143
|
+
if (checkFinished && instance.finished)
|
|
144
|
+
throw new Error("Hash#digest() has already been called");
|
|
145
|
+
}
|
|
146
|
+
function aoutput(out, instance) {
|
|
147
|
+
abytes(out);
|
|
148
|
+
const min = instance.outputLen;
|
|
149
|
+
if (out.length < min) {
|
|
150
|
+
throw new Error("digestInto() expects output buffer of length at least " + min);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
function clean(...arrays) {
|
|
154
|
+
for (let i = 0; i < arrays.length; i++) {
|
|
155
|
+
arrays[i].fill(0);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
function createView(arr) {
|
|
159
|
+
return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
160
|
+
}
|
|
161
|
+
function utf8ToBytes(str) {
|
|
162
|
+
if (typeof str !== "string")
|
|
163
|
+
throw new Error("string expected");
|
|
164
|
+
return new Uint8Array(new TextEncoder().encode(str));
|
|
165
|
+
}
|
|
166
|
+
function toBytes(data) {
|
|
167
|
+
if (typeof data === "string")
|
|
168
|
+
data = utf8ToBytes(data);
|
|
169
|
+
abytes(data);
|
|
170
|
+
return data;
|
|
171
|
+
}
|
|
172
|
+
function createHasher(hashCons) {
|
|
173
|
+
const hashC = (msg) => hashCons().update(toBytes(msg)).digest();
|
|
174
|
+
const tmp = hashCons();
|
|
175
|
+
hashC.outputLen = tmp.outputLen;
|
|
176
|
+
hashC.blockLen = tmp.blockLen;
|
|
177
|
+
hashC.create = () => hashCons();
|
|
178
|
+
return hashC;
|
|
179
|
+
}
|
|
180
|
+
var Hash;
|
|
181
|
+
var init_utils = __esm({
|
|
182
|
+
"node_modules/@noble/hashes/esm/utils.js"() {
|
|
183
|
+
"use strict";
|
|
184
|
+
Hash = class {
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
// node_modules/@noble/hashes/esm/hmac.js
|
|
190
|
+
var HMAC, hmac;
|
|
191
|
+
var init_hmac = __esm({
|
|
192
|
+
"node_modules/@noble/hashes/esm/hmac.js"() {
|
|
193
|
+
"use strict";
|
|
194
|
+
init_utils();
|
|
195
|
+
HMAC = class extends Hash {
|
|
196
|
+
constructor(hash, _key) {
|
|
197
|
+
super();
|
|
198
|
+
this.finished = false;
|
|
199
|
+
this.destroyed = false;
|
|
200
|
+
ahash(hash);
|
|
201
|
+
const key = toBytes(_key);
|
|
202
|
+
this.iHash = hash.create();
|
|
203
|
+
if (typeof this.iHash.update !== "function")
|
|
204
|
+
throw new Error("Expected instance of class which extends utils.Hash");
|
|
205
|
+
this.blockLen = this.iHash.blockLen;
|
|
206
|
+
this.outputLen = this.iHash.outputLen;
|
|
207
|
+
const blockLen = this.blockLen;
|
|
208
|
+
const pad = new Uint8Array(blockLen);
|
|
209
|
+
pad.set(key.length > blockLen ? hash.create().update(key).digest() : key);
|
|
210
|
+
for (let i = 0; i < pad.length; i++)
|
|
211
|
+
pad[i] ^= 54;
|
|
212
|
+
this.iHash.update(pad);
|
|
213
|
+
this.oHash = hash.create();
|
|
214
|
+
for (let i = 0; i < pad.length; i++)
|
|
215
|
+
pad[i] ^= 54 ^ 92;
|
|
216
|
+
this.oHash.update(pad);
|
|
217
|
+
clean(pad);
|
|
218
|
+
}
|
|
219
|
+
update(buf) {
|
|
220
|
+
aexists(this);
|
|
221
|
+
this.iHash.update(buf);
|
|
222
|
+
return this;
|
|
223
|
+
}
|
|
224
|
+
digestInto(out) {
|
|
225
|
+
aexists(this);
|
|
226
|
+
abytes(out, this.outputLen);
|
|
227
|
+
this.finished = true;
|
|
228
|
+
this.iHash.digestInto(out);
|
|
229
|
+
this.oHash.update(out);
|
|
230
|
+
this.oHash.digestInto(out);
|
|
231
|
+
this.destroy();
|
|
232
|
+
}
|
|
233
|
+
digest() {
|
|
234
|
+
const out = new Uint8Array(this.oHash.outputLen);
|
|
235
|
+
this.digestInto(out);
|
|
236
|
+
return out;
|
|
237
|
+
}
|
|
238
|
+
_cloneInto(to) {
|
|
239
|
+
to || (to = Object.create(Object.getPrototypeOf(this), {}));
|
|
240
|
+
const { oHash, iHash, finished: finished2, destroyed, blockLen, outputLen } = this;
|
|
241
|
+
to = to;
|
|
242
|
+
to.finished = finished2;
|
|
243
|
+
to.destroyed = destroyed;
|
|
244
|
+
to.blockLen = blockLen;
|
|
245
|
+
to.outputLen = outputLen;
|
|
246
|
+
to.oHash = oHash._cloneInto(to.oHash);
|
|
247
|
+
to.iHash = iHash._cloneInto(to.iHash);
|
|
248
|
+
return to;
|
|
249
|
+
}
|
|
250
|
+
clone() {
|
|
251
|
+
return this._cloneInto();
|
|
252
|
+
}
|
|
253
|
+
destroy() {
|
|
254
|
+
this.destroyed = true;
|
|
255
|
+
this.oHash.destroy();
|
|
256
|
+
this.iHash.destroy();
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
hmac = (hash, key, message) => new HMAC(hash, key).update(message).digest();
|
|
260
|
+
hmac.create = (hash, key) => new HMAC(hash, key);
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
// node_modules/@noble/hashes/esm/_md.js
|
|
265
|
+
function setBigUint64(view, byteOffset, value, isLE) {
|
|
266
|
+
if (typeof view.setBigUint64 === "function")
|
|
267
|
+
return view.setBigUint64(byteOffset, value, isLE);
|
|
268
|
+
const _32n2 = BigInt(32);
|
|
269
|
+
const _u32_max = BigInt(4294967295);
|
|
270
|
+
const wh = Number(value >> _32n2 & _u32_max);
|
|
271
|
+
const wl = Number(value & _u32_max);
|
|
272
|
+
const h = isLE ? 4 : 0;
|
|
273
|
+
const l = isLE ? 0 : 4;
|
|
274
|
+
view.setUint32(byteOffset + h, wh, isLE);
|
|
275
|
+
view.setUint32(byteOffset + l, wl, isLE);
|
|
276
|
+
}
|
|
277
|
+
var HashMD, SHA512_IV;
|
|
278
|
+
var init_md = __esm({
|
|
279
|
+
"node_modules/@noble/hashes/esm/_md.js"() {
|
|
280
|
+
"use strict";
|
|
281
|
+
init_utils();
|
|
282
|
+
HashMD = class extends Hash {
|
|
283
|
+
constructor(blockLen, outputLen, padOffset, isLE) {
|
|
284
|
+
super();
|
|
285
|
+
this.finished = false;
|
|
286
|
+
this.length = 0;
|
|
287
|
+
this.pos = 0;
|
|
288
|
+
this.destroyed = false;
|
|
289
|
+
this.blockLen = blockLen;
|
|
290
|
+
this.outputLen = outputLen;
|
|
291
|
+
this.padOffset = padOffset;
|
|
292
|
+
this.isLE = isLE;
|
|
293
|
+
this.buffer = new Uint8Array(blockLen);
|
|
294
|
+
this.view = createView(this.buffer);
|
|
295
|
+
}
|
|
296
|
+
update(data) {
|
|
297
|
+
aexists(this);
|
|
298
|
+
data = toBytes(data);
|
|
299
|
+
abytes(data);
|
|
300
|
+
const { view, buffer, blockLen } = this;
|
|
301
|
+
const len = data.length;
|
|
302
|
+
for (let pos = 0; pos < len; ) {
|
|
303
|
+
const take = Math.min(blockLen - this.pos, len - pos);
|
|
304
|
+
if (take === blockLen) {
|
|
305
|
+
const dataView = createView(data);
|
|
306
|
+
for (; blockLen <= len - pos; pos += blockLen)
|
|
307
|
+
this.process(dataView, pos);
|
|
308
|
+
continue;
|
|
309
|
+
}
|
|
310
|
+
buffer.set(data.subarray(pos, pos + take), this.pos);
|
|
311
|
+
this.pos += take;
|
|
312
|
+
pos += take;
|
|
313
|
+
if (this.pos === blockLen) {
|
|
314
|
+
this.process(view, 0);
|
|
315
|
+
this.pos = 0;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
this.length += data.length;
|
|
319
|
+
this.roundClean();
|
|
320
|
+
return this;
|
|
321
|
+
}
|
|
322
|
+
digestInto(out) {
|
|
323
|
+
aexists(this);
|
|
324
|
+
aoutput(out, this);
|
|
325
|
+
this.finished = true;
|
|
326
|
+
const { buffer, view, blockLen, isLE } = this;
|
|
327
|
+
let { pos } = this;
|
|
328
|
+
buffer[pos++] = 128;
|
|
329
|
+
clean(this.buffer.subarray(pos));
|
|
330
|
+
if (this.padOffset > blockLen - pos) {
|
|
331
|
+
this.process(view, 0);
|
|
332
|
+
pos = 0;
|
|
333
|
+
}
|
|
334
|
+
for (let i = pos; i < blockLen; i++)
|
|
335
|
+
buffer[i] = 0;
|
|
336
|
+
setBigUint64(view, blockLen - 8, BigInt(this.length * 8), isLE);
|
|
337
|
+
this.process(view, 0);
|
|
338
|
+
const oview = createView(out);
|
|
339
|
+
const len = this.outputLen;
|
|
340
|
+
if (len % 4)
|
|
341
|
+
throw new Error("_sha2: outputLen should be aligned to 32bit");
|
|
342
|
+
const outLen = len / 4;
|
|
343
|
+
const state = this.get();
|
|
344
|
+
if (outLen > state.length)
|
|
345
|
+
throw new Error("_sha2: outputLen bigger than state");
|
|
346
|
+
for (let i = 0; i < outLen; i++)
|
|
347
|
+
oview.setUint32(4 * i, state[i], isLE);
|
|
348
|
+
}
|
|
349
|
+
digest() {
|
|
350
|
+
const { buffer, outputLen } = this;
|
|
351
|
+
this.digestInto(buffer);
|
|
352
|
+
const res = buffer.slice(0, outputLen);
|
|
353
|
+
this.destroy();
|
|
354
|
+
return res;
|
|
355
|
+
}
|
|
356
|
+
_cloneInto(to) {
|
|
357
|
+
to || (to = new this.constructor());
|
|
358
|
+
to.set(...this.get());
|
|
359
|
+
const { blockLen, buffer, length, finished: finished2, destroyed, pos } = this;
|
|
360
|
+
to.destroyed = destroyed;
|
|
361
|
+
to.finished = finished2;
|
|
362
|
+
to.length = length;
|
|
363
|
+
to.pos = pos;
|
|
364
|
+
if (length % blockLen)
|
|
365
|
+
to.buffer.set(buffer);
|
|
366
|
+
return to;
|
|
367
|
+
}
|
|
368
|
+
clone() {
|
|
369
|
+
return this._cloneInto();
|
|
370
|
+
}
|
|
371
|
+
};
|
|
372
|
+
SHA512_IV = /* @__PURE__ */ Uint32Array.from([
|
|
373
|
+
1779033703,
|
|
374
|
+
4089235720,
|
|
375
|
+
3144134277,
|
|
376
|
+
2227873595,
|
|
377
|
+
1013904242,
|
|
378
|
+
4271175723,
|
|
379
|
+
2773480762,
|
|
380
|
+
1595750129,
|
|
381
|
+
1359893119,
|
|
382
|
+
2917565137,
|
|
383
|
+
2600822924,
|
|
384
|
+
725511199,
|
|
385
|
+
528734635,
|
|
386
|
+
4215389547,
|
|
387
|
+
1541459225,
|
|
388
|
+
327033209
|
|
389
|
+
]);
|
|
390
|
+
}
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
// node_modules/@noble/hashes/esm/_u64.js
|
|
394
|
+
function fromBig(n, le = false) {
|
|
395
|
+
if (le)
|
|
396
|
+
return { h: Number(n & U32_MASK64), l: Number(n >> _32n & U32_MASK64) };
|
|
397
|
+
return { h: Number(n >> _32n & U32_MASK64) | 0, l: Number(n & U32_MASK64) | 0 };
|
|
398
|
+
}
|
|
399
|
+
function split(lst, le = false) {
|
|
400
|
+
const len = lst.length;
|
|
401
|
+
let Ah = new Uint32Array(len);
|
|
402
|
+
let Al = new Uint32Array(len);
|
|
403
|
+
for (let i = 0; i < len; i++) {
|
|
404
|
+
const { h, l } = fromBig(lst[i], le);
|
|
405
|
+
[Ah[i], Al[i]] = [h, l];
|
|
406
|
+
}
|
|
407
|
+
return [Ah, Al];
|
|
408
|
+
}
|
|
409
|
+
function add(Ah, Al, Bh, Bl) {
|
|
410
|
+
const l = (Al >>> 0) + (Bl >>> 0);
|
|
411
|
+
return { h: Ah + Bh + (l / 2 ** 32 | 0) | 0, l: l | 0 };
|
|
412
|
+
}
|
|
413
|
+
var U32_MASK64, _32n, shrSH, shrSL, rotrSH, rotrSL, rotrBH, rotrBL, add3L, add3H, add4L, add4H, add5L, add5H;
|
|
414
|
+
var init_u64 = __esm({
|
|
415
|
+
"node_modules/@noble/hashes/esm/_u64.js"() {
|
|
416
|
+
"use strict";
|
|
417
|
+
U32_MASK64 = /* @__PURE__ */ BigInt(2 ** 32 - 1);
|
|
418
|
+
_32n = /* @__PURE__ */ BigInt(32);
|
|
419
|
+
shrSH = (h, _l, s) => h >>> s;
|
|
420
|
+
shrSL = (h, l, s) => h << 32 - s | l >>> s;
|
|
421
|
+
rotrSH = (h, l, s) => h >>> s | l << 32 - s;
|
|
422
|
+
rotrSL = (h, l, s) => h << 32 - s | l >>> s;
|
|
423
|
+
rotrBH = (h, l, s) => h << 64 - s | l >>> s - 32;
|
|
424
|
+
rotrBL = (h, l, s) => h >>> s - 32 | l << 64 - s;
|
|
425
|
+
add3L = (Al, Bl, Cl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0);
|
|
426
|
+
add3H = (low, Ah, Bh, Ch) => Ah + Bh + Ch + (low / 2 ** 32 | 0) | 0;
|
|
427
|
+
add4L = (Al, Bl, Cl, Dl) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0);
|
|
428
|
+
add4H = (low, Ah, Bh, Ch, Dh) => Ah + Bh + Ch + Dh + (low / 2 ** 32 | 0) | 0;
|
|
429
|
+
add5L = (Al, Bl, Cl, Dl, El) => (Al >>> 0) + (Bl >>> 0) + (Cl >>> 0) + (Dl >>> 0) + (El >>> 0);
|
|
430
|
+
add5H = (low, Ah, Bh, Ch, Dh, Eh) => Ah + Bh + Ch + Dh + Eh + (low / 2 ** 32 | 0) | 0;
|
|
431
|
+
}
|
|
432
|
+
});
|
|
433
|
+
|
|
434
|
+
// node_modules/@noble/hashes/esm/sha2.js
|
|
435
|
+
var K512, SHA512_Kh, SHA512_Kl, SHA512_W_H, SHA512_W_L, SHA512, sha512;
|
|
436
|
+
var init_sha2 = __esm({
|
|
437
|
+
"node_modules/@noble/hashes/esm/sha2.js"() {
|
|
438
|
+
"use strict";
|
|
439
|
+
init_md();
|
|
440
|
+
init_u64();
|
|
441
|
+
init_utils();
|
|
442
|
+
K512 = /* @__PURE__ */ (() => split([
|
|
443
|
+
"0x428a2f98d728ae22",
|
|
444
|
+
"0x7137449123ef65cd",
|
|
445
|
+
"0xb5c0fbcfec4d3b2f",
|
|
446
|
+
"0xe9b5dba58189dbbc",
|
|
447
|
+
"0x3956c25bf348b538",
|
|
448
|
+
"0x59f111f1b605d019",
|
|
449
|
+
"0x923f82a4af194f9b",
|
|
450
|
+
"0xab1c5ed5da6d8118",
|
|
451
|
+
"0xd807aa98a3030242",
|
|
452
|
+
"0x12835b0145706fbe",
|
|
453
|
+
"0x243185be4ee4b28c",
|
|
454
|
+
"0x550c7dc3d5ffb4e2",
|
|
455
|
+
"0x72be5d74f27b896f",
|
|
456
|
+
"0x80deb1fe3b1696b1",
|
|
457
|
+
"0x9bdc06a725c71235",
|
|
458
|
+
"0xc19bf174cf692694",
|
|
459
|
+
"0xe49b69c19ef14ad2",
|
|
460
|
+
"0xefbe4786384f25e3",
|
|
461
|
+
"0x0fc19dc68b8cd5b5",
|
|
462
|
+
"0x240ca1cc77ac9c65",
|
|
463
|
+
"0x2de92c6f592b0275",
|
|
464
|
+
"0x4a7484aa6ea6e483",
|
|
465
|
+
"0x5cb0a9dcbd41fbd4",
|
|
466
|
+
"0x76f988da831153b5",
|
|
467
|
+
"0x983e5152ee66dfab",
|
|
468
|
+
"0xa831c66d2db43210",
|
|
469
|
+
"0xb00327c898fb213f",
|
|
470
|
+
"0xbf597fc7beef0ee4",
|
|
471
|
+
"0xc6e00bf33da88fc2",
|
|
472
|
+
"0xd5a79147930aa725",
|
|
473
|
+
"0x06ca6351e003826f",
|
|
474
|
+
"0x142929670a0e6e70",
|
|
475
|
+
"0x27b70a8546d22ffc",
|
|
476
|
+
"0x2e1b21385c26c926",
|
|
477
|
+
"0x4d2c6dfc5ac42aed",
|
|
478
|
+
"0x53380d139d95b3df",
|
|
479
|
+
"0x650a73548baf63de",
|
|
480
|
+
"0x766a0abb3c77b2a8",
|
|
481
|
+
"0x81c2c92e47edaee6",
|
|
482
|
+
"0x92722c851482353b",
|
|
483
|
+
"0xa2bfe8a14cf10364",
|
|
484
|
+
"0xa81a664bbc423001",
|
|
485
|
+
"0xc24b8b70d0f89791",
|
|
486
|
+
"0xc76c51a30654be30",
|
|
487
|
+
"0xd192e819d6ef5218",
|
|
488
|
+
"0xd69906245565a910",
|
|
489
|
+
"0xf40e35855771202a",
|
|
490
|
+
"0x106aa07032bbd1b8",
|
|
491
|
+
"0x19a4c116b8d2d0c8",
|
|
492
|
+
"0x1e376c085141ab53",
|
|
493
|
+
"0x2748774cdf8eeb99",
|
|
494
|
+
"0x34b0bcb5e19b48a8",
|
|
495
|
+
"0x391c0cb3c5c95a63",
|
|
496
|
+
"0x4ed8aa4ae3418acb",
|
|
497
|
+
"0x5b9cca4f7763e373",
|
|
498
|
+
"0x682e6ff3d6b2b8a3",
|
|
499
|
+
"0x748f82ee5defb2fc",
|
|
500
|
+
"0x78a5636f43172f60",
|
|
501
|
+
"0x84c87814a1f0ab72",
|
|
502
|
+
"0x8cc702081a6439ec",
|
|
503
|
+
"0x90befffa23631e28",
|
|
504
|
+
"0xa4506cebde82bde9",
|
|
505
|
+
"0xbef9a3f7b2c67915",
|
|
506
|
+
"0xc67178f2e372532b",
|
|
507
|
+
"0xca273eceea26619c",
|
|
508
|
+
"0xd186b8c721c0c207",
|
|
509
|
+
"0xeada7dd6cde0eb1e",
|
|
510
|
+
"0xf57d4f7fee6ed178",
|
|
511
|
+
"0x06f067aa72176fba",
|
|
512
|
+
"0x0a637dc5a2c898a6",
|
|
513
|
+
"0x113f9804bef90dae",
|
|
514
|
+
"0x1b710b35131c471b",
|
|
515
|
+
"0x28db77f523047d84",
|
|
516
|
+
"0x32caab7b40c72493",
|
|
517
|
+
"0x3c9ebe0a15c9bebc",
|
|
518
|
+
"0x431d67c49c100d4c",
|
|
519
|
+
"0x4cc5d4becb3e42b6",
|
|
520
|
+
"0x597f299cfc657e2a",
|
|
521
|
+
"0x5fcb6fab3ad6faec",
|
|
522
|
+
"0x6c44198c4a475817"
|
|
523
|
+
].map((n) => BigInt(n))))();
|
|
524
|
+
SHA512_Kh = /* @__PURE__ */ (() => K512[0])();
|
|
525
|
+
SHA512_Kl = /* @__PURE__ */ (() => K512[1])();
|
|
526
|
+
SHA512_W_H = /* @__PURE__ */ new Uint32Array(80);
|
|
527
|
+
SHA512_W_L = /* @__PURE__ */ new Uint32Array(80);
|
|
528
|
+
SHA512 = class extends HashMD {
|
|
529
|
+
constructor(outputLen = 64) {
|
|
530
|
+
super(128, outputLen, 16, false);
|
|
531
|
+
this.Ah = SHA512_IV[0] | 0;
|
|
532
|
+
this.Al = SHA512_IV[1] | 0;
|
|
533
|
+
this.Bh = SHA512_IV[2] | 0;
|
|
534
|
+
this.Bl = SHA512_IV[3] | 0;
|
|
535
|
+
this.Ch = SHA512_IV[4] | 0;
|
|
536
|
+
this.Cl = SHA512_IV[5] | 0;
|
|
537
|
+
this.Dh = SHA512_IV[6] | 0;
|
|
538
|
+
this.Dl = SHA512_IV[7] | 0;
|
|
539
|
+
this.Eh = SHA512_IV[8] | 0;
|
|
540
|
+
this.El = SHA512_IV[9] | 0;
|
|
541
|
+
this.Fh = SHA512_IV[10] | 0;
|
|
542
|
+
this.Fl = SHA512_IV[11] | 0;
|
|
543
|
+
this.Gh = SHA512_IV[12] | 0;
|
|
544
|
+
this.Gl = SHA512_IV[13] | 0;
|
|
545
|
+
this.Hh = SHA512_IV[14] | 0;
|
|
546
|
+
this.Hl = SHA512_IV[15] | 0;
|
|
547
|
+
}
|
|
548
|
+
// prettier-ignore
|
|
549
|
+
get() {
|
|
550
|
+
const { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
|
|
551
|
+
return [Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl];
|
|
552
|
+
}
|
|
553
|
+
// prettier-ignore
|
|
554
|
+
set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl) {
|
|
555
|
+
this.Ah = Ah | 0;
|
|
556
|
+
this.Al = Al | 0;
|
|
557
|
+
this.Bh = Bh | 0;
|
|
558
|
+
this.Bl = Bl | 0;
|
|
559
|
+
this.Ch = Ch | 0;
|
|
560
|
+
this.Cl = Cl | 0;
|
|
561
|
+
this.Dh = Dh | 0;
|
|
562
|
+
this.Dl = Dl | 0;
|
|
563
|
+
this.Eh = Eh | 0;
|
|
564
|
+
this.El = El | 0;
|
|
565
|
+
this.Fh = Fh | 0;
|
|
566
|
+
this.Fl = Fl | 0;
|
|
567
|
+
this.Gh = Gh | 0;
|
|
568
|
+
this.Gl = Gl | 0;
|
|
569
|
+
this.Hh = Hh | 0;
|
|
570
|
+
this.Hl = Hl | 0;
|
|
571
|
+
}
|
|
572
|
+
process(view, offset) {
|
|
573
|
+
for (let i = 0; i < 16; i++, offset += 4) {
|
|
574
|
+
SHA512_W_H[i] = view.getUint32(offset);
|
|
575
|
+
SHA512_W_L[i] = view.getUint32(offset += 4);
|
|
576
|
+
}
|
|
577
|
+
for (let i = 16; i < 80; i++) {
|
|
578
|
+
const W15h = SHA512_W_H[i - 15] | 0;
|
|
579
|
+
const W15l = SHA512_W_L[i - 15] | 0;
|
|
580
|
+
const s0h = rotrSH(W15h, W15l, 1) ^ rotrSH(W15h, W15l, 8) ^ shrSH(W15h, W15l, 7);
|
|
581
|
+
const s0l = rotrSL(W15h, W15l, 1) ^ rotrSL(W15h, W15l, 8) ^ shrSL(W15h, W15l, 7);
|
|
582
|
+
const W2h = SHA512_W_H[i - 2] | 0;
|
|
583
|
+
const W2l = SHA512_W_L[i - 2] | 0;
|
|
584
|
+
const s1h = rotrSH(W2h, W2l, 19) ^ rotrBH(W2h, W2l, 61) ^ shrSH(W2h, W2l, 6);
|
|
585
|
+
const s1l = rotrSL(W2h, W2l, 19) ^ rotrBL(W2h, W2l, 61) ^ shrSL(W2h, W2l, 6);
|
|
586
|
+
const SUMl = add4L(s0l, s1l, SHA512_W_L[i - 7], SHA512_W_L[i - 16]);
|
|
587
|
+
const SUMh = add4H(SUMl, s0h, s1h, SHA512_W_H[i - 7], SHA512_W_H[i - 16]);
|
|
588
|
+
SHA512_W_H[i] = SUMh | 0;
|
|
589
|
+
SHA512_W_L[i] = SUMl | 0;
|
|
590
|
+
}
|
|
591
|
+
let { Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl } = this;
|
|
592
|
+
for (let i = 0; i < 80; i++) {
|
|
593
|
+
const sigma1h = rotrSH(Eh, El, 14) ^ rotrSH(Eh, El, 18) ^ rotrBH(Eh, El, 41);
|
|
594
|
+
const sigma1l = rotrSL(Eh, El, 14) ^ rotrSL(Eh, El, 18) ^ rotrBL(Eh, El, 41);
|
|
595
|
+
const CHIh = Eh & Fh ^ ~Eh & Gh;
|
|
596
|
+
const CHIl = El & Fl ^ ~El & Gl;
|
|
597
|
+
const T1ll = add5L(Hl, sigma1l, CHIl, SHA512_Kl[i], SHA512_W_L[i]);
|
|
598
|
+
const T1h = add5H(T1ll, Hh, sigma1h, CHIh, SHA512_Kh[i], SHA512_W_H[i]);
|
|
599
|
+
const T1l = T1ll | 0;
|
|
600
|
+
const sigma0h = rotrSH(Ah, Al, 28) ^ rotrBH(Ah, Al, 34) ^ rotrBH(Ah, Al, 39);
|
|
601
|
+
const sigma0l = rotrSL(Ah, Al, 28) ^ rotrBL(Ah, Al, 34) ^ rotrBL(Ah, Al, 39);
|
|
602
|
+
const MAJh = Ah & Bh ^ Ah & Ch ^ Bh & Ch;
|
|
603
|
+
const MAJl = Al & Bl ^ Al & Cl ^ Bl & Cl;
|
|
604
|
+
Hh = Gh | 0;
|
|
605
|
+
Hl = Gl | 0;
|
|
606
|
+
Gh = Fh | 0;
|
|
607
|
+
Gl = Fl | 0;
|
|
608
|
+
Fh = Eh | 0;
|
|
609
|
+
Fl = El | 0;
|
|
610
|
+
({ h: Eh, l: El } = add(Dh | 0, Dl | 0, T1h | 0, T1l | 0));
|
|
611
|
+
Dh = Ch | 0;
|
|
612
|
+
Dl = Cl | 0;
|
|
613
|
+
Ch = Bh | 0;
|
|
614
|
+
Cl = Bl | 0;
|
|
615
|
+
Bh = Ah | 0;
|
|
616
|
+
Bl = Al | 0;
|
|
617
|
+
const All = add3L(T1l, sigma0l, MAJl);
|
|
618
|
+
Ah = add3H(All, T1h, sigma0h, MAJh);
|
|
619
|
+
Al = All | 0;
|
|
620
|
+
}
|
|
621
|
+
({ h: Ah, l: Al } = add(this.Ah | 0, this.Al | 0, Ah | 0, Al | 0));
|
|
622
|
+
({ h: Bh, l: Bl } = add(this.Bh | 0, this.Bl | 0, Bh | 0, Bl | 0));
|
|
623
|
+
({ h: Ch, l: Cl } = add(this.Ch | 0, this.Cl | 0, Ch | 0, Cl | 0));
|
|
624
|
+
({ h: Dh, l: Dl } = add(this.Dh | 0, this.Dl | 0, Dh | 0, Dl | 0));
|
|
625
|
+
({ h: Eh, l: El } = add(this.Eh | 0, this.El | 0, Eh | 0, El | 0));
|
|
626
|
+
({ h: Fh, l: Fl } = add(this.Fh | 0, this.Fl | 0, Fh | 0, Fl | 0));
|
|
627
|
+
({ h: Gh, l: Gl } = add(this.Gh | 0, this.Gl | 0, Gh | 0, Gl | 0));
|
|
628
|
+
({ h: Hh, l: Hl } = add(this.Hh | 0, this.Hl | 0, Hh | 0, Hl | 0));
|
|
629
|
+
this.set(Ah, Al, Bh, Bl, Ch, Cl, Dh, Dl, Eh, El, Fh, Fl, Gh, Gl, Hh, Hl);
|
|
630
|
+
}
|
|
631
|
+
roundClean() {
|
|
632
|
+
clean(SHA512_W_H, SHA512_W_L);
|
|
633
|
+
}
|
|
634
|
+
destroy() {
|
|
635
|
+
clean(this.buffer);
|
|
636
|
+
this.set(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
|
|
637
|
+
}
|
|
638
|
+
};
|
|
639
|
+
sha512 = /* @__PURE__ */ createHasher(() => new SHA512());
|
|
640
|
+
}
|
|
641
|
+
});
|
|
642
|
+
|
|
643
|
+
// node_modules/@noble/hashes/esm/sha512.js
|
|
644
|
+
var sha5122;
|
|
645
|
+
var init_sha512 = __esm({
|
|
646
|
+
"node_modules/@noble/hashes/esm/sha512.js"() {
|
|
647
|
+
"use strict";
|
|
648
|
+
init_sha2();
|
|
649
|
+
sha5122 = sha512;
|
|
650
|
+
}
|
|
651
|
+
});
|
|
652
|
+
|
|
117
653
|
// src/wallet.ts
|
|
118
654
|
var wallet_exports = {};
|
|
119
655
|
__export(wallet_exports, {
|
|
120
656
|
deriveAllKeys: () => deriveAllKeys,
|
|
121
657
|
deriveEvmKey: () => deriveEvmKey,
|
|
122
658
|
deriveSolanaKeyBytes: () => deriveSolanaKeyBytes,
|
|
659
|
+
deriveSolanaKeyBytesLegacy: () => deriveSolanaKeyBytesLegacy,
|
|
123
660
|
generateWalletMnemonic: () => generateWalletMnemonic,
|
|
124
661
|
isValidMnemonic: () => isValidMnemonic
|
|
125
662
|
});
|
|
@@ -143,10 +680,29 @@ function deriveEvmKey(mnemonic) {
|
|
|
143
680
|
return { privateKey: hex, address: account.address };
|
|
144
681
|
}
|
|
145
682
|
function deriveSolanaKeyBytes(mnemonic) {
|
|
683
|
+
const seed = mnemonicToSeedSync(mnemonic);
|
|
684
|
+
let I = hmac(sha5122, "ed25519 seed", seed);
|
|
685
|
+
let key = I.slice(0, 32);
|
|
686
|
+
let chainCode = I.slice(32);
|
|
687
|
+
for (const index of SOLANA_HARDENED_INDICES) {
|
|
688
|
+
const data = new Uint8Array(37);
|
|
689
|
+
data[0] = 0;
|
|
690
|
+
data.set(key, 1);
|
|
691
|
+
data[33] = index >>> 24 & 255;
|
|
692
|
+
data[34] = index >>> 16 & 255;
|
|
693
|
+
data[35] = index >>> 8 & 255;
|
|
694
|
+
data[36] = index & 255;
|
|
695
|
+
I = hmac(sha5122, chainCode, data);
|
|
696
|
+
key = I.slice(0, 32);
|
|
697
|
+
chainCode = I.slice(32);
|
|
698
|
+
}
|
|
699
|
+
return new Uint8Array(key);
|
|
700
|
+
}
|
|
701
|
+
function deriveSolanaKeyBytesLegacy(mnemonic) {
|
|
146
702
|
const seed = mnemonicToSeedSync(mnemonic);
|
|
147
703
|
const hdKey = HDKey.fromMasterSeed(seed);
|
|
148
|
-
const derived = hdKey.derive(
|
|
149
|
-
if (!derived.privateKey) throw new Error("Failed to derive Solana private key");
|
|
704
|
+
const derived = hdKey.derive("m/44'/501'/0'/0'");
|
|
705
|
+
if (!derived.privateKey) throw new Error("Failed to derive legacy Solana private key");
|
|
150
706
|
return new Uint8Array(derived.privateKey);
|
|
151
707
|
}
|
|
152
708
|
function deriveAllKeys(mnemonic) {
|
|
@@ -154,12 +710,247 @@ function deriveAllKeys(mnemonic) {
|
|
|
154
710
|
const solanaPrivateKeyBytes = deriveSolanaKeyBytes(mnemonic);
|
|
155
711
|
return { mnemonic, evmPrivateKey, evmAddress, solanaPrivateKeyBytes };
|
|
156
712
|
}
|
|
157
|
-
var ETH_DERIVATION_PATH,
|
|
713
|
+
var ETH_DERIVATION_PATH, SOLANA_HARDENED_INDICES;
|
|
158
714
|
var init_wallet = __esm({
|
|
159
715
|
"src/wallet.ts"() {
|
|
160
716
|
"use strict";
|
|
717
|
+
init_hmac();
|
|
718
|
+
init_sha512();
|
|
161
719
|
ETH_DERIVATION_PATH = "m/44'/60'/0'/0/0";
|
|
162
|
-
|
|
720
|
+
SOLANA_HARDENED_INDICES = [
|
|
721
|
+
44 + 2147483648,
|
|
722
|
+
501 + 2147483648,
|
|
723
|
+
0 + 2147483648,
|
|
724
|
+
0 + 2147483648
|
|
725
|
+
];
|
|
726
|
+
}
|
|
727
|
+
});
|
|
728
|
+
|
|
729
|
+
// src/solana-sweep.ts
|
|
730
|
+
var solana_sweep_exports = {};
|
|
731
|
+
__export(solana_sweep_exports, {
|
|
732
|
+
sweepSolanaWallet: () => sweepSolanaWallet
|
|
733
|
+
});
|
|
734
|
+
import {
|
|
735
|
+
address as solAddress2,
|
|
736
|
+
createSolanaRpc as createSolanaRpc2,
|
|
737
|
+
createSolanaRpcSubscriptions,
|
|
738
|
+
createKeyPairSignerFromPrivateKeyBytes,
|
|
739
|
+
pipe,
|
|
740
|
+
createTransactionMessage,
|
|
741
|
+
setTransactionMessageFeePayer,
|
|
742
|
+
setTransactionMessageLifetimeUsingBlockhash,
|
|
743
|
+
appendTransactionMessageInstructions,
|
|
744
|
+
signTransactionMessageWithSigners,
|
|
745
|
+
getSignatureFromTransaction,
|
|
746
|
+
sendAndConfirmTransactionFactory,
|
|
747
|
+
getProgramDerivedAddress,
|
|
748
|
+
getAddressEncoder
|
|
749
|
+
} from "@solana/kit";
|
|
750
|
+
async function getAssociatedTokenAddress(owner, mint) {
|
|
751
|
+
const encoder = getAddressEncoder();
|
|
752
|
+
const [ata] = await getProgramDerivedAddress({
|
|
753
|
+
programAddress: ASSOCIATED_TOKEN_PROGRAM,
|
|
754
|
+
seeds: [encoder.encode(owner), encoder.encode(TOKEN_PROGRAM), encoder.encode(mint)]
|
|
755
|
+
});
|
|
756
|
+
return ata;
|
|
757
|
+
}
|
|
758
|
+
function buildCreateAtaIdempotentInstruction(payer, ata, owner, mint) {
|
|
759
|
+
return {
|
|
760
|
+
programAddress: ASSOCIATED_TOKEN_PROGRAM,
|
|
761
|
+
accounts: [
|
|
762
|
+
{
|
|
763
|
+
address: payer,
|
|
764
|
+
role: 3
|
|
765
|
+
/* writable signer */
|
|
766
|
+
},
|
|
767
|
+
{
|
|
768
|
+
address: ata,
|
|
769
|
+
role: 1
|
|
770
|
+
/* writable */
|
|
771
|
+
},
|
|
772
|
+
{
|
|
773
|
+
address: owner,
|
|
774
|
+
role: 0
|
|
775
|
+
/* readonly */
|
|
776
|
+
},
|
|
777
|
+
{
|
|
778
|
+
address: mint,
|
|
779
|
+
role: 0
|
|
780
|
+
/* readonly */
|
|
781
|
+
},
|
|
782
|
+
{
|
|
783
|
+
address: SYSTEM_PROGRAM,
|
|
784
|
+
role: 0
|
|
785
|
+
/* readonly */
|
|
786
|
+
},
|
|
787
|
+
{
|
|
788
|
+
address: TOKEN_PROGRAM,
|
|
789
|
+
role: 0
|
|
790
|
+
/* readonly */
|
|
791
|
+
}
|
|
792
|
+
],
|
|
793
|
+
data: new Uint8Array([1])
|
|
794
|
+
// instruction index 1 = CreateIdempotent
|
|
795
|
+
};
|
|
796
|
+
}
|
|
797
|
+
function buildTokenTransferInstruction(source, destination, authority, amount) {
|
|
798
|
+
const data = new Uint8Array(9);
|
|
799
|
+
data[0] = 3;
|
|
800
|
+
const view = new DataView(data.buffer, data.byteOffset);
|
|
801
|
+
view.setBigUint64(1, amount, true);
|
|
802
|
+
return {
|
|
803
|
+
programAddress: TOKEN_PROGRAM,
|
|
804
|
+
accounts: [
|
|
805
|
+
{
|
|
806
|
+
address: source,
|
|
807
|
+
role: 1
|
|
808
|
+
/* writable */
|
|
809
|
+
},
|
|
810
|
+
{
|
|
811
|
+
address: destination,
|
|
812
|
+
role: 1
|
|
813
|
+
/* writable */
|
|
814
|
+
},
|
|
815
|
+
{
|
|
816
|
+
address: authority,
|
|
817
|
+
role: 2
|
|
818
|
+
/* signer */
|
|
819
|
+
}
|
|
820
|
+
],
|
|
821
|
+
data
|
|
822
|
+
};
|
|
823
|
+
}
|
|
824
|
+
async function sweepSolanaWallet(oldKeyBytes, newKeyBytes, rpcUrl) {
|
|
825
|
+
const url = rpcUrl || process["env"].CLAWROUTER_SOLANA_RPC_URL || SOLANA_DEFAULT_RPC2;
|
|
826
|
+
const rpc = createSolanaRpc2(url);
|
|
827
|
+
const [oldSigner, newSigner] = await Promise.all([
|
|
828
|
+
createKeyPairSignerFromPrivateKeyBytes(oldKeyBytes),
|
|
829
|
+
createKeyPairSignerFromPrivateKeyBytes(newKeyBytes)
|
|
830
|
+
]);
|
|
831
|
+
const oldAddress = oldSigner.address;
|
|
832
|
+
const newAddress = newSigner.address;
|
|
833
|
+
const mint = solAddress2(SOLANA_USDC_MINT2);
|
|
834
|
+
let newSolBalance;
|
|
835
|
+
try {
|
|
836
|
+
const solResp = await rpc.getBalance(solAddress2(newAddress)).send();
|
|
837
|
+
newSolBalance = solResp.value;
|
|
838
|
+
} catch (err) {
|
|
839
|
+
return {
|
|
840
|
+
error: `Failed to check SOL balance: ${err instanceof Error ? err.message : String(err)}`,
|
|
841
|
+
oldAddress,
|
|
842
|
+
newAddress
|
|
843
|
+
};
|
|
844
|
+
}
|
|
845
|
+
let usdcBalance = 0n;
|
|
846
|
+
let oldTokenAccount;
|
|
847
|
+
try {
|
|
848
|
+
const response = await rpc.getTokenAccountsByOwner(
|
|
849
|
+
solAddress2(oldAddress),
|
|
850
|
+
{ mint },
|
|
851
|
+
{ encoding: "jsonParsed" }
|
|
852
|
+
).send();
|
|
853
|
+
if (response.value.length > 0) {
|
|
854
|
+
for (const account of response.value) {
|
|
855
|
+
const parsed = account.account.data;
|
|
856
|
+
const amount = BigInt(parsed.parsed.info.tokenAmount.amount);
|
|
857
|
+
if (amount > 0n) {
|
|
858
|
+
usdcBalance += amount;
|
|
859
|
+
oldTokenAccount = account.pubkey;
|
|
860
|
+
}
|
|
861
|
+
}
|
|
862
|
+
}
|
|
863
|
+
} catch (err) {
|
|
864
|
+
return {
|
|
865
|
+
error: `Failed to check USDC balance: ${err instanceof Error ? err.message : String(err)}`,
|
|
866
|
+
oldAddress,
|
|
867
|
+
newAddress
|
|
868
|
+
};
|
|
869
|
+
}
|
|
870
|
+
if (usdcBalance === 0n) {
|
|
871
|
+
return {
|
|
872
|
+
error: "No USDC found in old wallet. Nothing to sweep.",
|
|
873
|
+
oldAddress,
|
|
874
|
+
newAddress,
|
|
875
|
+
solBalance: newSolBalance,
|
|
876
|
+
usdcBalance: 0n
|
|
877
|
+
};
|
|
878
|
+
}
|
|
879
|
+
const MIN_SOL_FOR_GAS = 5000000n;
|
|
880
|
+
if (newSolBalance < MIN_SOL_FOR_GAS) {
|
|
881
|
+
const needed = Number(MIN_SOL_FOR_GAS - newSolBalance) / 1e9;
|
|
882
|
+
return {
|
|
883
|
+
error: `Insufficient SOL for transaction fees in your new wallet. Send ~${needed.toFixed(4)} SOL to ${newAddress} (your new Phantom-compatible address) to cover gas. Current SOL balance: ${(Number(newSolBalance) / 1e9).toFixed(6)} SOL`,
|
|
884
|
+
oldAddress,
|
|
885
|
+
newAddress,
|
|
886
|
+
solBalance: newSolBalance,
|
|
887
|
+
usdcBalance
|
|
888
|
+
};
|
|
889
|
+
}
|
|
890
|
+
if (!oldTokenAccount) {
|
|
891
|
+
return {
|
|
892
|
+
error: "Could not find USDC token account in old wallet.",
|
|
893
|
+
oldAddress,
|
|
894
|
+
newAddress
|
|
895
|
+
};
|
|
896
|
+
}
|
|
897
|
+
try {
|
|
898
|
+
const newAta = await getAssociatedTokenAddress(solAddress2(newAddress), mint);
|
|
899
|
+
const { value: latestBlockhash } = await rpc.getLatestBlockhash().send();
|
|
900
|
+
const createAtaIx = buildCreateAtaIdempotentInstruction(
|
|
901
|
+
newSigner.address,
|
|
902
|
+
// new wallet pays for ATA creation
|
|
903
|
+
newAta,
|
|
904
|
+
solAddress2(newAddress),
|
|
905
|
+
mint
|
|
906
|
+
);
|
|
907
|
+
const transferIx = buildTokenTransferInstruction(
|
|
908
|
+
solAddress2(oldTokenAccount),
|
|
909
|
+
newAta,
|
|
910
|
+
oldSigner.address,
|
|
911
|
+
// old wallet authorizes the token transfer
|
|
912
|
+
usdcBalance
|
|
913
|
+
);
|
|
914
|
+
const txMessage = pipe(
|
|
915
|
+
createTransactionMessage({ version: 0 }),
|
|
916
|
+
(msg) => setTransactionMessageFeePayer(newSigner.address, msg),
|
|
917
|
+
// new wallet pays gas
|
|
918
|
+
(msg) => setTransactionMessageLifetimeUsingBlockhash(latestBlockhash, msg),
|
|
919
|
+
(msg) => appendTransactionMessageInstructions([createAtaIx, transferIx], msg)
|
|
920
|
+
);
|
|
921
|
+
const signedTx = await signTransactionMessageWithSigners(txMessage);
|
|
922
|
+
const txSignature = getSignatureFromTransaction(signedTx);
|
|
923
|
+
const wsUrl = url.replace("https://", "wss://").replace("http://", "ws://");
|
|
924
|
+
const rpcSubscriptions = createSolanaRpcSubscriptions(wsUrl);
|
|
925
|
+
const sendAndConfirm = sendAndConfirmTransactionFactory({ rpc, rpcSubscriptions });
|
|
926
|
+
await sendAndConfirm(signedTx, { commitment: "confirmed" });
|
|
927
|
+
const dollars = Number(usdcBalance) / 1e6;
|
|
928
|
+
return {
|
|
929
|
+
transferred: `$${dollars.toFixed(2)}`,
|
|
930
|
+
transferredMicros: usdcBalance,
|
|
931
|
+
txSignature,
|
|
932
|
+
oldAddress,
|
|
933
|
+
newAddress
|
|
934
|
+
};
|
|
935
|
+
} catch (err) {
|
|
936
|
+
return {
|
|
937
|
+
error: `Transaction failed: ${err instanceof Error ? err.message : String(err)}`,
|
|
938
|
+
oldAddress,
|
|
939
|
+
newAddress,
|
|
940
|
+
solBalance: newSolBalance,
|
|
941
|
+
usdcBalance
|
|
942
|
+
};
|
|
943
|
+
}
|
|
944
|
+
}
|
|
945
|
+
var SOLANA_USDC_MINT2, SOLANA_DEFAULT_RPC2, TOKEN_PROGRAM, ASSOCIATED_TOKEN_PROGRAM, SYSTEM_PROGRAM;
|
|
946
|
+
var init_solana_sweep = __esm({
|
|
947
|
+
"src/solana-sweep.ts"() {
|
|
948
|
+
"use strict";
|
|
949
|
+
SOLANA_USDC_MINT2 = "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v";
|
|
950
|
+
SOLANA_DEFAULT_RPC2 = "https://api.mainnet-beta.solana.com";
|
|
951
|
+
TOKEN_PROGRAM = "TokenkegQfeN4jV6bme4LphiJbfPe2VopRsimuVSoZ5K";
|
|
952
|
+
ASSOCIATED_TOKEN_PROGRAM = "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL";
|
|
953
|
+
SYSTEM_PROGRAM = "11111111111111111111111111111111";
|
|
163
954
|
}
|
|
164
955
|
});
|
|
165
956
|
|
|
@@ -859,7 +1650,8 @@ function createPayFetchWithPreAuth(baseFetch, client, ttlMs = DEFAULT_TTL_MS, op
|
|
|
859
1650
|
cache.set(urlPath, { paymentRequired, cachedAt: Date.now() });
|
|
860
1651
|
} catch (error) {
|
|
861
1652
|
throw new Error(
|
|
862
|
-
`Failed to parse payment requirements: ${error instanceof Error ? error.message : "Unknown error"}
|
|
1653
|
+
`Failed to parse payment requirements: ${error instanceof Error ? error.message : "Unknown error"}`,
|
|
1654
|
+
{ cause: error }
|
|
863
1655
|
);
|
|
864
1656
|
}
|
|
865
1657
|
const payload = await client.createPaymentPayload(paymentRequired);
|
|
@@ -3329,6 +4121,32 @@ async function generateAndSaveWallet() {
|
|
|
3329
4121
|
solanaPrivateKeyBytes: derived.solanaPrivateKeyBytes
|
|
3330
4122
|
};
|
|
3331
4123
|
}
|
|
4124
|
+
async function logMigrationWarning(legacyKeyBytes, newKeyBytes) {
|
|
4125
|
+
try {
|
|
4126
|
+
const { createKeyPairSignerFromPrivateKeyBytes: createKeyPairSignerFromPrivateKeyBytes2 } = await import("@solana/kit");
|
|
4127
|
+
const [oldSigner, newSigner] = await Promise.all([
|
|
4128
|
+
createKeyPairSignerFromPrivateKeyBytes2(legacyKeyBytes),
|
|
4129
|
+
createKeyPairSignerFromPrivateKeyBytes2(newKeyBytes)
|
|
4130
|
+
]);
|
|
4131
|
+
console.log(`[ClawRouter]`);
|
|
4132
|
+
console.log(`[ClawRouter] \u26A0 SOLANA WALLET MIGRATION DETECTED`);
|
|
4133
|
+
console.log(`[ClawRouter] \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550`);
|
|
4134
|
+
console.log(`[ClawRouter] Old address (secp256k1): ${oldSigner.address}`);
|
|
4135
|
+
console.log(`[ClawRouter] New address (SLIP-10): ${newSigner.address}`);
|
|
4136
|
+
console.log(`[ClawRouter]`);
|
|
4137
|
+
console.log(`[ClawRouter] Your Solana wallet derivation has been fixed to use`);
|
|
4138
|
+
console.log(`[ClawRouter] SLIP-10 Ed25519 (Phantom/Solflare compatible).`);
|
|
4139
|
+
console.log(`[ClawRouter]`);
|
|
4140
|
+
console.log(`[ClawRouter] If you had funds in the old wallet, run:`);
|
|
4141
|
+
console.log(`[ClawRouter] /wallet migrate-solana`);
|
|
4142
|
+
console.log(`[ClawRouter]`);
|
|
4143
|
+
console.log(`[ClawRouter] The new wallet pays gas. Send ~0.005 SOL to:`);
|
|
4144
|
+
console.log(`[ClawRouter] ${newSigner.address}`);
|
|
4145
|
+
console.log(`[ClawRouter] \u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550\u2550`);
|
|
4146
|
+
console.log(`[ClawRouter]`);
|
|
4147
|
+
} catch {
|
|
4148
|
+
}
|
|
4149
|
+
}
|
|
3332
4150
|
async function resolveOrGenerateWalletKey() {
|
|
3333
4151
|
const saved = await loadSavedWallet();
|
|
3334
4152
|
if (saved) {
|
|
@@ -3336,13 +4154,19 @@ async function resolveOrGenerateWalletKey() {
|
|
|
3336
4154
|
const mnemonic = await loadMnemonic();
|
|
3337
4155
|
if (mnemonic) {
|
|
3338
4156
|
const solanaKeyBytes = deriveSolanaKeyBytes(mnemonic);
|
|
3339
|
-
|
|
4157
|
+
const result2 = {
|
|
3340
4158
|
key: saved,
|
|
3341
4159
|
address: account.address,
|
|
3342
4160
|
source: "saved",
|
|
3343
4161
|
mnemonic,
|
|
3344
4162
|
solanaPrivateKeyBytes: solanaKeyBytes
|
|
3345
4163
|
};
|
|
4164
|
+
const legacyKeyBytes = deriveSolanaKeyBytesLegacy(mnemonic);
|
|
4165
|
+
if (Buffer.from(legacyKeyBytes).toString("hex") !== Buffer.from(solanaKeyBytes).toString("hex")) {
|
|
4166
|
+
result2.legacySolanaKeyBytes = legacyKeyBytes;
|
|
4167
|
+
await logMigrationWarning(legacyKeyBytes, solanaKeyBytes);
|
|
4168
|
+
}
|
|
4169
|
+
return result2;
|
|
3346
4170
|
}
|
|
3347
4171
|
return { key: saved, address: account.address, source: "saved" };
|
|
3348
4172
|
}
|
|
@@ -3352,13 +4176,19 @@ async function resolveOrGenerateWalletKey() {
|
|
|
3352
4176
|
const mnemonic = await loadMnemonic();
|
|
3353
4177
|
if (mnemonic) {
|
|
3354
4178
|
const solanaKeyBytes = deriveSolanaKeyBytes(mnemonic);
|
|
3355
|
-
|
|
4179
|
+
const result2 = {
|
|
3356
4180
|
key: envKey,
|
|
3357
4181
|
address: account.address,
|
|
3358
4182
|
source: "env",
|
|
3359
4183
|
mnemonic,
|
|
3360
4184
|
solanaPrivateKeyBytes: solanaKeyBytes
|
|
3361
4185
|
};
|
|
4186
|
+
const legacyKeyBytes = deriveSolanaKeyBytesLegacy(mnemonic);
|
|
4187
|
+
if (Buffer.from(legacyKeyBytes).toString("hex") !== Buffer.from(solanaKeyBytes).toString("hex")) {
|
|
4188
|
+
result2.legacySolanaKeyBytes = legacyKeyBytes;
|
|
4189
|
+
await logMigrationWarning(legacyKeyBytes, solanaKeyBytes);
|
|
4190
|
+
}
|
|
4191
|
+
return result2;
|
|
3362
4192
|
}
|
|
3363
4193
|
return { key: envKey, address: account.address, source: "env" };
|
|
3364
4194
|
}
|
|
@@ -3374,9 +4204,7 @@ async function resolveOrGenerateWalletKey() {
|
|
|
3374
4204
|
async function setupSolana() {
|
|
3375
4205
|
const existing = await loadMnemonic();
|
|
3376
4206
|
if (existing) {
|
|
3377
|
-
throw new Error(
|
|
3378
|
-
"Solana wallet already set up. Mnemonic file exists at " + MNEMONIC_FILE
|
|
3379
|
-
);
|
|
4207
|
+
throw new Error("Solana wallet already set up. Mnemonic file exists at " + MNEMONIC_FILE);
|
|
3380
4208
|
}
|
|
3381
4209
|
const savedKey = await loadSavedWallet();
|
|
3382
4210
|
if (!savedKey) {
|
|
@@ -5121,7 +5949,9 @@ async function startProxy(options) {
|
|
|
5121
5949
|
const paymentChain = options.paymentChain ?? await resolvePaymentChain();
|
|
5122
5950
|
const apiBase = options.apiBase ?? (paymentChain === "solana" && solanaPrivateKeyBytes ? BLOCKRUN_SOLANA_API : BLOCKRUN_API);
|
|
5123
5951
|
if (paymentChain === "solana" && !solanaPrivateKeyBytes) {
|
|
5124
|
-
console.warn(
|
|
5952
|
+
console.warn(
|
|
5953
|
+
`[ClawRouter] Payment chain is Solana but no Solana keys provided. Using Base (EVM).`
|
|
5954
|
+
);
|
|
5125
5955
|
} else if (paymentChain === "solana") {
|
|
5126
5956
|
console.log(`[ClawRouter] Payment chain: Solana (${BLOCKRUN_SOLANA_API})`);
|
|
5127
5957
|
}
|
|
@@ -5142,15 +5972,17 @@ async function startProxy(options) {
|
|
|
5142
5972
|
);
|
|
5143
5973
|
}
|
|
5144
5974
|
} else if (paymentChain !== "base") {
|
|
5145
|
-
console.warn(
|
|
5975
|
+
console.warn(
|
|
5976
|
+
`[ClawRouter] Existing proxy on port ${listenPort} does not report paymentChain (pre-v0.11 instance). Assuming Base.`
|
|
5977
|
+
);
|
|
5146
5978
|
throw new Error(
|
|
5147
5979
|
`Existing proxy on port ${listenPort} is a pre-v0.11 instance (assumed Base) but ${paymentChain} was requested. Stop the existing proxy first or use a different port.`
|
|
5148
5980
|
);
|
|
5149
5981
|
}
|
|
5150
5982
|
let reuseSolanaAddress;
|
|
5151
5983
|
if (solanaPrivateKeyBytes) {
|
|
5152
|
-
const { createKeyPairSignerFromPrivateKeyBytes } = await import("@solana/kit");
|
|
5153
|
-
const solanaSigner = await
|
|
5984
|
+
const { createKeyPairSignerFromPrivateKeyBytes: createKeyPairSignerFromPrivateKeyBytes2 } = await import("@solana/kit");
|
|
5985
|
+
const solanaSigner = await createKeyPairSignerFromPrivateKeyBytes2(solanaPrivateKeyBytes);
|
|
5154
5986
|
reuseSolanaAddress = solanaSigner.address;
|
|
5155
5987
|
}
|
|
5156
5988
|
const balanceMonitor2 = paymentChain === "solana" && reuseSolanaAddress ? new SolanaBalanceMonitor(reuseSolanaAddress) : new BalanceMonitor(account2.address);
|
|
@@ -5173,8 +6005,8 @@ async function startProxy(options) {
|
|
|
5173
6005
|
let solanaAddress;
|
|
5174
6006
|
if (solanaPrivateKeyBytes) {
|
|
5175
6007
|
const { registerExactSvmScheme } = await import("@x402/svm/exact/client");
|
|
5176
|
-
const { createKeyPairSignerFromPrivateKeyBytes } = await import("@solana/kit");
|
|
5177
|
-
const solanaSigner = await
|
|
6008
|
+
const { createKeyPairSignerFromPrivateKeyBytes: createKeyPairSignerFromPrivateKeyBytes2 } = await import("@solana/kit");
|
|
6009
|
+
const solanaSigner = await createKeyPairSignerFromPrivateKeyBytes2(solanaPrivateKeyBytes);
|
|
5178
6010
|
solanaAddress = solanaSigner.address;
|
|
5179
6011
|
registerExactSvmScheme(x402, { signer: solanaSigner });
|
|
5180
6012
|
console.log(`[ClawRouter] Solana x402 scheme registered: ${solanaAddress}`);
|
|
@@ -5341,7 +6173,11 @@ async function startProxy(options) {
|
|
|
5341
6173
|
const existingProxy2 = await checkExistingProxy(listenPort);
|
|
5342
6174
|
if (existingProxy2) {
|
|
5343
6175
|
console.log(`[ClawRouter] Existing proxy detected on port ${listenPort}, reusing`);
|
|
5344
|
-
rejectAttempt({
|
|
6176
|
+
rejectAttempt({
|
|
6177
|
+
code: "REUSE_EXISTING",
|
|
6178
|
+
wallet: existingProxy2.wallet,
|
|
6179
|
+
existingChain: existingProxy2.paymentChain
|
|
6180
|
+
});
|
|
5345
6181
|
return;
|
|
5346
6182
|
}
|
|
5347
6183
|
if (attempt < PORT_RETRY_ATTEMPTS) {
|
|
@@ -5376,7 +6212,8 @@ async function startProxy(options) {
|
|
|
5376
6212
|
if (error.code === "REUSE_EXISTING" && error.wallet) {
|
|
5377
6213
|
if (error.existingChain && error.existingChain !== paymentChain) {
|
|
5378
6214
|
throw new Error(
|
|
5379
|
-
`Existing proxy on port ${listenPort} is using ${error.existingChain} but ${paymentChain} was requested. Stop the existing proxy first or use a different port
|
|
6215
|
+
`Existing proxy on port ${listenPort} is using ${error.existingChain} but ${paymentChain} was requested. Stop the existing proxy first or use a different port.`,
|
|
6216
|
+
{ cause: err }
|
|
5380
6217
|
);
|
|
5381
6218
|
}
|
|
5382
6219
|
const baseUrl2 = `http://127.0.0.1:${listenPort}`;
|
|
@@ -5484,15 +6321,12 @@ async function tryModelRequest(upstreamUrl, method, headers, body, modelId, maxT
|
|
|
5484
6321
|
} catch {
|
|
5485
6322
|
}
|
|
5486
6323
|
try {
|
|
5487
|
-
const response = await payFetch(
|
|
5488
|
-
|
|
5489
|
-
|
|
5490
|
-
|
|
5491
|
-
|
|
5492
|
-
|
|
5493
|
-
signal
|
|
5494
|
-
}
|
|
5495
|
-
);
|
|
6324
|
+
const response = await payFetch(upstreamUrl, {
|
|
6325
|
+
method,
|
|
6326
|
+
headers,
|
|
6327
|
+
body: requestBody.length > 0 ? new Uint8Array(requestBody) : void 0,
|
|
6328
|
+
signal
|
|
6329
|
+
});
|
|
5496
6330
|
if (response.status !== 200) {
|
|
5497
6331
|
const errorBody = await response.text();
|
|
5498
6332
|
const isProviderErr = isProviderError(response.status, errorBody);
|
|
@@ -6443,7 +7277,14 @@ async function proxyRequest(req, res, apiBase, payFetch, options, routerOpts, de
|
|
|
6443
7277
|
if (balanceFallbackNotice) {
|
|
6444
7278
|
const noticeChunk = {
|
|
6445
7279
|
...baseChunk,
|
|
6446
|
-
choices: [
|
|
7280
|
+
choices: [
|
|
7281
|
+
{
|
|
7282
|
+
index,
|
|
7283
|
+
delta: { content: balanceFallbackNotice },
|
|
7284
|
+
logprobs: null,
|
|
7285
|
+
finish_reason: null
|
|
7286
|
+
}
|
|
7287
|
+
]
|
|
6447
7288
|
};
|
|
6448
7289
|
const noticeData = `data: ${JSON.stringify(noticeChunk)}
|
|
6449
7290
|
|
|
@@ -7009,6 +7850,7 @@ function formatDuration(seconds) {
|
|
|
7009
7850
|
|
|
7010
7851
|
// src/index.ts
|
|
7011
7852
|
init_wallet();
|
|
7853
|
+
init_solana_sweep();
|
|
7012
7854
|
|
|
7013
7855
|
// src/retry.ts
|
|
7014
7856
|
var DEFAULT_RETRY_CONFIG = {
|
|
@@ -7363,7 +8205,8 @@ async function startProxyInBackground(api) {
|
|
|
7363
8205
|
activeProxyHandle = proxy;
|
|
7364
8206
|
api.logger.info(`ClawRouter ready \u2014 smart routing enabled`);
|
|
7365
8207
|
api.logger.info(`Pricing: Simple ~$0.001 | Code ~$0.01 | Complex ~$0.05 | Free: $0`);
|
|
7366
|
-
const
|
|
8208
|
+
const currentChain = await resolvePaymentChain();
|
|
8209
|
+
const displayAddress = currentChain === "solana" && proxy.solanaAddress ? proxy.solanaAddress : wallet.address;
|
|
7367
8210
|
proxy.balanceMonitor.checkBalance().then((balance) => {
|
|
7368
8211
|
if (balance.isEmpty) {
|
|
7369
8212
|
api.logger.info(`Wallet: ${displayAddress} | Balance: $0.00`);
|
|
@@ -7448,8 +8291,8 @@ Run \`openclaw plugins install @blockrun/clawrouter\` to generate a wallet.`,
|
|
|
7448
8291
|
hasMnemonic = true;
|
|
7449
8292
|
const { deriveSolanaKeyBytes: deriveSolanaKeyBytes2 } = await Promise.resolve().then(() => (init_wallet(), wallet_exports));
|
|
7450
8293
|
const solKeyBytes = deriveSolanaKeyBytes2(mnemonic);
|
|
7451
|
-
const { createKeyPairSignerFromPrivateKeyBytes } = await import("@solana/kit");
|
|
7452
|
-
const signer = await
|
|
8294
|
+
const { createKeyPairSignerFromPrivateKeyBytes: createKeyPairSignerFromPrivateKeyBytes2 } = await import("@solana/kit");
|
|
8295
|
+
const signer = await createKeyPairSignerFromPrivateKeyBytes2(solKeyBytes);
|
|
7453
8296
|
lines.push(
|
|
7454
8297
|
"",
|
|
7455
8298
|
"**Solana:**",
|
|
@@ -7490,8 +8333,8 @@ Run \`openclaw plugins install @blockrun/clawrouter\` to generate a wallet.`,
|
|
|
7490
8333
|
await savePaymentChain("solana");
|
|
7491
8334
|
const { deriveSolanaKeyBytes: deriveSolanaKeyBytes2 } = await Promise.resolve().then(() => (init_wallet(), wallet_exports));
|
|
7492
8335
|
const solKeyBytes = deriveSolanaKeyBytes2(existingMnemonic);
|
|
7493
|
-
const { createKeyPairSignerFromPrivateKeyBytes:
|
|
7494
|
-
const signer2 = await
|
|
8336
|
+
const { createKeyPairSignerFromPrivateKeyBytes: createKeyPairSignerFromPrivateKeyBytes3 } = await import("@solana/kit");
|
|
8337
|
+
const signer2 = await createKeyPairSignerFromPrivateKeyBytes3(solKeyBytes);
|
|
7495
8338
|
solanaAddr = signer2.address;
|
|
7496
8339
|
return {
|
|
7497
8340
|
text: [
|
|
@@ -7505,8 +8348,8 @@ Run \`openclaw plugins install @blockrun/clawrouter\` to generate a wallet.`,
|
|
|
7505
8348
|
}
|
|
7506
8349
|
const { solanaPrivateKeyBytes } = await setupSolana();
|
|
7507
8350
|
await savePaymentChain("solana");
|
|
7508
|
-
const { createKeyPairSignerFromPrivateKeyBytes } = await import("@solana/kit");
|
|
7509
|
-
const signer = await
|
|
8351
|
+
const { createKeyPairSignerFromPrivateKeyBytes: createKeyPairSignerFromPrivateKeyBytes2 } = await import("@solana/kit");
|
|
8352
|
+
const signer = await createKeyPairSignerFromPrivateKeyBytes2(solanaPrivateKeyBytes);
|
|
7510
8353
|
return {
|
|
7511
8354
|
text: [
|
|
7512
8355
|
"**Solana Wallet Set Up**",
|
|
@@ -7527,6 +8370,88 @@ Run \`openclaw plugins install @blockrun/clawrouter\` to generate a wallet.`,
|
|
|
7527
8370
|
};
|
|
7528
8371
|
}
|
|
7529
8372
|
}
|
|
8373
|
+
if (subcommand === "migrate-solana") {
|
|
8374
|
+
try {
|
|
8375
|
+
if (!existsSync2(MNEMONIC_FILE)) {
|
|
8376
|
+
return {
|
|
8377
|
+
text: "No mnemonic file found. Solana wallet not set up \u2014 nothing to migrate.",
|
|
8378
|
+
isError: true
|
|
8379
|
+
};
|
|
8380
|
+
}
|
|
8381
|
+
const mnemonic = readTextFileSync(MNEMONIC_FILE).trim();
|
|
8382
|
+
if (!mnemonic) {
|
|
8383
|
+
return { text: "Mnemonic file is empty.", isError: true };
|
|
8384
|
+
}
|
|
8385
|
+
const { deriveSolanaKeyBytes: deriveSolanaKeyBytes2, deriveSolanaKeyBytesLegacy: deriveSolanaKeyBytesLegacy2 } = await Promise.resolve().then(() => (init_wallet(), wallet_exports));
|
|
8386
|
+
const { createKeyPairSignerFromPrivateKeyBytes: createKeyPairSignerFromPrivateKeyBytes2 } = await import("@solana/kit");
|
|
8387
|
+
const legacyKeyBytes = deriveSolanaKeyBytesLegacy2(mnemonic);
|
|
8388
|
+
const newKeyBytes = deriveSolanaKeyBytes2(mnemonic);
|
|
8389
|
+
const [oldSigner, newSigner] = await Promise.all([
|
|
8390
|
+
createKeyPairSignerFromPrivateKeyBytes2(legacyKeyBytes),
|
|
8391
|
+
createKeyPairSignerFromPrivateKeyBytes2(newKeyBytes)
|
|
8392
|
+
]);
|
|
8393
|
+
if (oldSigner.address === newSigner.address) {
|
|
8394
|
+
return { text: "Legacy and new Solana addresses are the same. No migration needed." };
|
|
8395
|
+
}
|
|
8396
|
+
let oldUsdcText = "unknown";
|
|
8397
|
+
try {
|
|
8398
|
+
const { SolanaBalanceMonitor: SolanaBalanceMonitor2 } = await Promise.resolve().then(() => (init_solana_balance(), solana_balance_exports));
|
|
8399
|
+
const monitor = new SolanaBalanceMonitor2(oldSigner.address);
|
|
8400
|
+
const balance = await monitor.checkBalance();
|
|
8401
|
+
oldUsdcText = balance.balanceUSD;
|
|
8402
|
+
if (balance.isEmpty) {
|
|
8403
|
+
return {
|
|
8404
|
+
text: [
|
|
8405
|
+
"**Solana Migration Status**",
|
|
8406
|
+
"",
|
|
8407
|
+
`Old wallet (secp256k1): \`${oldSigner.address}\``,
|
|
8408
|
+
` USDC: $0.00`,
|
|
8409
|
+
"",
|
|
8410
|
+
`New wallet (SLIP-10): \`${newSigner.address}\``,
|
|
8411
|
+
"",
|
|
8412
|
+
"No USDC in old wallet. Nothing to sweep.",
|
|
8413
|
+
"Your new SLIP-10 address is Phantom/Solflare compatible."
|
|
8414
|
+
].join("\n")
|
|
8415
|
+
};
|
|
8416
|
+
}
|
|
8417
|
+
} catch {
|
|
8418
|
+
}
|
|
8419
|
+
const { sweepSolanaWallet: sweepSolanaWallet2 } = await Promise.resolve().then(() => (init_solana_sweep(), solana_sweep_exports));
|
|
8420
|
+
const result = await sweepSolanaWallet2(legacyKeyBytes, newKeyBytes);
|
|
8421
|
+
if ("error" in result) {
|
|
8422
|
+
return {
|
|
8423
|
+
text: [
|
|
8424
|
+
"**Solana Migration Failed**",
|
|
8425
|
+
"",
|
|
8426
|
+
`Old wallet: \`${result.oldAddress}\` (USDC: ${oldUsdcText})`,
|
|
8427
|
+
`New wallet: \`${result.newAddress || newSigner.address}\``,
|
|
8428
|
+
"",
|
|
8429
|
+
`Error: ${result.error}`
|
|
8430
|
+
].join("\n"),
|
|
8431
|
+
isError: true
|
|
8432
|
+
};
|
|
8433
|
+
}
|
|
8434
|
+
return {
|
|
8435
|
+
text: [
|
|
8436
|
+
"**Solana Migration Complete**",
|
|
8437
|
+
"",
|
|
8438
|
+
`Swept **${result.transferred}** USDC from old to new wallet.`,
|
|
8439
|
+
"",
|
|
8440
|
+
`Old wallet: \`${result.oldAddress}\``,
|
|
8441
|
+
`New wallet: \`${result.newAddress}\``,
|
|
8442
|
+
`TX: https://solscan.io/tx/${result.txSignature}`,
|
|
8443
|
+
"",
|
|
8444
|
+
"Your new SLIP-10 address is Phantom/Solflare compatible.",
|
|
8445
|
+
"You can recover it from your 24-word mnemonic in any standard wallet."
|
|
8446
|
+
].join("\n")
|
|
8447
|
+
};
|
|
8448
|
+
} catch (err) {
|
|
8449
|
+
return {
|
|
8450
|
+
text: `Migration failed: ${err instanceof Error ? err.message : String(err)}`,
|
|
8451
|
+
isError: true
|
|
8452
|
+
};
|
|
8453
|
+
}
|
|
8454
|
+
}
|
|
7530
8455
|
if (subcommand === "base") {
|
|
7531
8456
|
try {
|
|
7532
8457
|
await savePaymentChain("base");
|
|
@@ -7540,7 +8465,7 @@ Run \`openclaw plugins install @blockrun/clawrouter\` to generate a wallet.`,
|
|
|
7540
8465
|
};
|
|
7541
8466
|
}
|
|
7542
8467
|
}
|
|
7543
|
-
let evmBalanceText
|
|
8468
|
+
let evmBalanceText;
|
|
7544
8469
|
try {
|
|
7545
8470
|
const monitor = new BalanceMonitor(address);
|
|
7546
8471
|
const balance = await monitor.checkBalance();
|
|
@@ -7555,8 +8480,8 @@ Run \`openclaw plugins install @blockrun/clawrouter\` to generate a wallet.`,
|
|
|
7555
8480
|
const mnemonic = readTextFileSync(MNEMONIC_FILE).trim();
|
|
7556
8481
|
if (mnemonic) {
|
|
7557
8482
|
const solKeyBytes = deriveSolanaKeyBytes2(mnemonic);
|
|
7558
|
-
const { createKeyPairSignerFromPrivateKeyBytes } = await import("@solana/kit");
|
|
7559
|
-
const signer = await
|
|
8483
|
+
const { createKeyPairSignerFromPrivateKeyBytes: createKeyPairSignerFromPrivateKeyBytes2 } = await import("@solana/kit");
|
|
8484
|
+
const signer = await createKeyPairSignerFromPrivateKeyBytes2(solKeyBytes);
|
|
7560
8485
|
const solAddr = signer.address;
|
|
7561
8486
|
let solBalanceText = "Balance: (checking...)";
|
|
7562
8487
|
try {
|
|
@@ -7598,7 +8523,8 @@ Run \`openclaw plugins install @blockrun/clawrouter\` to generate a wallet.`,
|
|
|
7598
8523
|
"\u2022 `/wallet export` - Export private key for backup",
|
|
7599
8524
|
!solanaSection ? "\u2022 `/wallet solana` - Enable Solana payments" : "",
|
|
7600
8525
|
solanaSection ? "\u2022 `/wallet base` - Switch to Base (EVM)" : "",
|
|
7601
|
-
solanaSection ? "\u2022 `/wallet solana` - Switch to Solana" : ""
|
|
8526
|
+
solanaSection ? "\u2022 `/wallet solana` - Switch to Solana" : "",
|
|
8527
|
+
solanaSection ? "\u2022 `/wallet migrate-solana` - Sweep funds from old Solana wallet" : ""
|
|
7602
8528
|
].filter(Boolean).join("\n")
|
|
7603
8529
|
};
|
|
7604
8530
|
}
|
|
@@ -7774,6 +8700,7 @@ export {
|
|
|
7774
8700
|
deriveAllKeys,
|
|
7775
8701
|
deriveEvmKey,
|
|
7776
8702
|
deriveSolanaKeyBytes,
|
|
8703
|
+
deriveSolanaKeyBytesLegacy,
|
|
7777
8704
|
fetchWithRetry,
|
|
7778
8705
|
formatDuration,
|
|
7779
8706
|
formatStatsAscii,
|
|
@@ -7801,6 +8728,12 @@ export {
|
|
|
7801
8728
|
route,
|
|
7802
8729
|
savePaymentChain,
|
|
7803
8730
|
setupSolana,
|
|
7804
|
-
startProxy
|
|
8731
|
+
startProxy,
|
|
8732
|
+
sweepSolanaWallet
|
|
7805
8733
|
};
|
|
8734
|
+
/*! Bundled license information:
|
|
8735
|
+
|
|
8736
|
+
@noble/hashes/esm/utils.js:
|
|
8737
|
+
(*! noble-hashes - MIT License (c) 2022 Paul Miller (paulmillr.com) *)
|
|
8738
|
+
*/
|
|
7806
8739
|
//# sourceMappingURL=index.js.map
|