@elisym/cli 0.9.0 → 0.9.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/dist/index.js +31 -27
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env -S node --no-deprecation
|
|
2
2
|
import { readFileSync, readdirSync, statSync, renameSync, mkdirSync, writeFileSync } from 'node:fs';
|
|
3
3
|
import { dirname, join, resolve, basename, relative, sep } from 'node:path';
|
|
4
|
-
import { SolanaPaymentStrategy, validateAgentName, RELAYS, ElisymIdentity, formatSol, formatAssetAmount, ElisymClient, MediaService, jobRequestKind, DEFAULT_KIND_OFFSET, toDTag, DEFAULTS,
|
|
4
|
+
import { SolanaPaymentStrategy, validateAgentName, RELAYS, ElisymIdentity, formatSol, formatAssetAmount, USDC_SOLANA_DEVNET, ElisymClient, MediaService, jobRequestKind, DEFAULT_KIND_OFFSET, toDTag, DEFAULTS, makeCensor, DEFAULT_REDACT_PATHS, createSlidingWindowLimiter, getProtocolProgramId, getProtocolConfig, LIMITS, calculateProtocolFee, BoundedSet, KIND_JOB_FEEDBACK, NATIVE_SOL } from '@elisym/sdk';
|
|
5
5
|
import { ElisymYamlSchema, resolveInHome, resolveInProject, createAgentDir, writeYaml, writeSecrets, listAgents, loadAgent, agentPaths, readMediaCache, lookupCachedUrl, newCacheEntry, writeMediaCache } from '@elisym/sdk/agent-store';
|
|
6
6
|
import { isAddress, createSolanaRpc, address } from '@solana/kit';
|
|
7
7
|
import { generateSecretKey, getPublicKey, nip19, verifyEvent } from 'nostr-tools';
|
|
@@ -712,6 +712,30 @@ function getRpcUrl(_network) {
|
|
|
712
712
|
}
|
|
713
713
|
return "https://api.devnet.solana.com";
|
|
714
714
|
}
|
|
715
|
+
async function fetchUsdcBalance(rpc, owner) {
|
|
716
|
+
const mint = USDC_SOLANA_DEVNET.mint;
|
|
717
|
+
if (!mint) {
|
|
718
|
+
return 0n;
|
|
719
|
+
}
|
|
720
|
+
try {
|
|
721
|
+
const response = await rpc.getTokenAccountsByOwner(
|
|
722
|
+
owner,
|
|
723
|
+
{ mint: address(mint) },
|
|
724
|
+
{ encoding: "jsonParsed", commitment: "confirmed" }
|
|
725
|
+
).send();
|
|
726
|
+
let total = 0n;
|
|
727
|
+
for (const entry of response.value) {
|
|
728
|
+
const parsed = entry.account.data;
|
|
729
|
+
const raw = parsed?.parsed?.info?.tokenAmount?.amount;
|
|
730
|
+
if (typeof raw === "string") {
|
|
731
|
+
total += BigInt(raw);
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
return total;
|
|
735
|
+
} catch {
|
|
736
|
+
return 0n;
|
|
737
|
+
}
|
|
738
|
+
}
|
|
715
739
|
var VALID_TRANSITIONS = {
|
|
716
740
|
paid: ["executed", "failed"],
|
|
717
741
|
executed: ["delivered", "failed"],
|
|
@@ -2505,7 +2529,10 @@ async function cmdStart(nameArg, options = {}) {
|
|
|
2505
2529
|
const rpcUrl = getRpcUrl(walletNetwork);
|
|
2506
2530
|
const rpc = createSolanaRpc(rpcUrl);
|
|
2507
2531
|
const walletAddress = address(solanaAddress);
|
|
2508
|
-
const { value: balanceLamports } = await
|
|
2532
|
+
const [{ value: balanceLamports }, usdcBalance] = await Promise.all([
|
|
2533
|
+
rpc.getBalance(walletAddress).send(),
|
|
2534
|
+
fetchUsdcBalance(rpc, walletAddress)
|
|
2535
|
+
]);
|
|
2509
2536
|
const balance = Number(balanceLamports);
|
|
2510
2537
|
console.log(" Wallet");
|
|
2511
2538
|
console.log(` Network ${walletNetwork}`);
|
|
@@ -2513,7 +2540,8 @@ async function cmdStart(nameArg, options = {}) {
|
|
|
2513
2540
|
if (process.env.SOLANA_RPC_URL) {
|
|
2514
2541
|
console.log(` RPC ${process.env.SOLANA_RPC_URL} (custom)`);
|
|
2515
2542
|
}
|
|
2516
|
-
console.log(`
|
|
2543
|
+
console.log(` SOL ${formatSol(balance)} (${balance} lamports)`);
|
|
2544
|
+
console.log(` USDC ${formatAssetAmount(USDC_SOLANA_DEVNET, usdcBalance)}`);
|
|
2517
2545
|
if (balance === 0) {
|
|
2518
2546
|
console.log(" ! Wallet is empty. Get devnet SOL: https://faucet.solana.com");
|
|
2519
2547
|
}
|
|
@@ -3000,30 +3028,6 @@ async function loadAgentWithPrompt(name, cwd) {
|
|
|
3000
3028
|
}
|
|
3001
3029
|
throw new Error("Unreachable");
|
|
3002
3030
|
}
|
|
3003
|
-
async function fetchUsdcBalance(rpc, owner) {
|
|
3004
|
-
const mint = USDC_SOLANA_DEVNET.mint;
|
|
3005
|
-
if (!mint) {
|
|
3006
|
-
return 0n;
|
|
3007
|
-
}
|
|
3008
|
-
try {
|
|
3009
|
-
const response = await rpc.getTokenAccountsByOwner(
|
|
3010
|
-
owner,
|
|
3011
|
-
{ mint: address(mint) },
|
|
3012
|
-
{ encoding: "jsonParsed", commitment: "confirmed" }
|
|
3013
|
-
).send();
|
|
3014
|
-
let total = 0n;
|
|
3015
|
-
for (const entry of response.value) {
|
|
3016
|
-
const parsed = entry.account.data;
|
|
3017
|
-
const raw = parsed?.parsed?.info?.tokenAmount?.amount;
|
|
3018
|
-
if (typeof raw === "string") {
|
|
3019
|
-
total += BigInt(raw);
|
|
3020
|
-
}
|
|
3021
|
-
}
|
|
3022
|
-
return total;
|
|
3023
|
-
} catch {
|
|
3024
|
-
return 0n;
|
|
3025
|
-
}
|
|
3026
|
-
}
|
|
3027
3031
|
async function cmdWallet(name) {
|
|
3028
3032
|
const cwd = process.cwd();
|
|
3029
3033
|
if (!name) {
|