@prktsol/prkt 1.0.0

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.
Files changed (125) hide show
  1. package/.env.devnet.all-protocols.example +18 -0
  2. package/.env.devnet.autonomous.example +16 -0
  3. package/.env.devnet.jupiter.example +16 -0
  4. package/.env.devnet.kamino.example +17 -0
  5. package/.env.devnet.marinade.example +16 -0
  6. package/.env.devnet.orca.example +16 -0
  7. package/.env.devnet.raydium.example +17 -0
  8. package/.env.example +32 -0
  9. package/ARCHITECTURE.md +159 -0
  10. package/CLI.md +509 -0
  11. package/CLI_QUICKSTART.md +108 -0
  12. package/COMPATIBILITY.md +103 -0
  13. package/DEVNET_PROTOCOL_ADDRESSES.md +72 -0
  14. package/README.md +339 -0
  15. package/dist/agent/AgentManager.js +166 -0
  16. package/dist/agent/AgentRuntime.js +92 -0
  17. package/dist/agent/DecisionEngine.js +95 -0
  18. package/dist/agent/MockPriceFeed.js +13 -0
  19. package/dist/agent/intents/types.js +2 -0
  20. package/dist/agent/new-index.js +17 -0
  21. package/dist/agent/policyFactory.js +54 -0
  22. package/dist/agent/registry/AgentRegistry.js +16 -0
  23. package/dist/agent/runner/AgentRunner.js +266 -0
  24. package/dist/agent/strategies/MemoHeartbeatStrategy.js +15 -0
  25. package/dist/agent/strategies/SimpleScriptedTransferStrategy.js +27 -0
  26. package/dist/agent/strategies/TokenRebalancerStrategy.js +35 -0
  27. package/dist/agent/strategies/TreasuryDistributorStrategy.js +29 -0
  28. package/dist/agent/strategies/UniversalDeFiStrategy.js +19 -0
  29. package/dist/agent/types/AgentContext.js +2 -0
  30. package/dist/cli/index.js +1159 -0
  31. package/dist/cli/services/activityStore.js +42 -0
  32. package/dist/cli/services/agentRegistry.js +123 -0
  33. package/dist/cli/services/agentRuntime.js +55 -0
  34. package/dist/cli/services/storagePaths.js +64 -0
  35. package/dist/cli/services/strategyFactory.js +66 -0
  36. package/dist/cli/services/walletCrypto.js +120 -0
  37. package/dist/cli/services/walletRegistry.js +145 -0
  38. package/dist/cli/types.js +2 -0
  39. package/dist/cli/utils/completion.js +62 -0
  40. package/dist/cli/utils/output.js +44 -0
  41. package/dist/config/agentPolicies.js +37 -0
  42. package/dist/config/env.js +249 -0
  43. package/dist/config/policyPresets.js +105 -0
  44. package/dist/core/balances/BalanceService.js +34 -0
  45. package/dist/core/funding/DevnetFundingService.js +105 -0
  46. package/dist/core/idempotency/ExecutionIdempotencyGuard.js +100 -0
  47. package/dist/core/index.js +19 -0
  48. package/dist/core/rpc/RpcClient.js +45 -0
  49. package/dist/core/rpc/RpcFailoverClient.js +97 -0
  50. package/dist/core/tokens/TokenService.js +75 -0
  51. package/dist/core/transactions/PostTransactionVerifier.js +103 -0
  52. package/dist/core/transactions/TransactionService.js +104 -0
  53. package/dist/core/types/services.js +2 -0
  54. package/dist/core/wallet/WalletManager.js +120 -0
  55. package/dist/defi/DeFiCoordinator.js +93 -0
  56. package/dist/defi/DeFiExecutor.js +29 -0
  57. package/dist/defi/DeFiPolicyGuard.js +31 -0
  58. package/dist/defi/adapters/JupiterAdapter.js +25 -0
  59. package/dist/defi/adapters/KaminoAdapter.js +50 -0
  60. package/dist/defi/adapters/MarinadeAdapter.js +25 -0
  61. package/dist/defi/adapters/RaydiumAdapter.js +45 -0
  62. package/dist/defi/kamino/kaminoInstructionCompat.js +24 -0
  63. package/dist/defi/kamino/kaminoLiveConfig.js +60 -0
  64. package/dist/defi/kamino/loadKaminoMarketWithFallback.js +68 -0
  65. package/dist/defi/lp/LpInstructionBuilder.js +2 -0
  66. package/dist/defi/lp/RaydiumLpInstructionBuilder.js +100 -0
  67. package/dist/defi/lp/raydiumDevnetConfig.js +62 -0
  68. package/dist/defi/protocols.js +29 -0
  69. package/dist/defi/types.js +2 -0
  70. package/dist/defi/universal/UniversalDeFiOrchestrator.js +126 -0
  71. package/dist/defi/universal/adapters.js +73 -0
  72. package/dist/defi/universal/index.js +5 -0
  73. package/dist/defi/universal/liveExecutors.js +394 -0
  74. package/dist/defi/universal/types.js +2 -0
  75. package/dist/demo/scenarios/multiAgentDevnetScenario.js +170 -0
  76. package/dist/demo/scripts/runMultiAgentDevnetDemo.js +17 -0
  77. package/dist/dex/JupiterSwapClient.js +59 -0
  78. package/dist/dex/SwapExecutor.js +52 -0
  79. package/dist/index.js +22 -0
  80. package/dist/kora/KoraRpcClient.js +60 -0
  81. package/dist/kora/KoraSigner.js +57 -0
  82. package/dist/kora/gaslessDemo.js +18 -0
  83. package/dist/policy/PolicyGuard.js +158 -0
  84. package/dist/policy/emergencyLock.js +164 -0
  85. package/dist/policy/engine/PolicyEngine.js +237 -0
  86. package/dist/policy/errors.js +10 -0
  87. package/dist/policy/index.js +7 -0
  88. package/dist/policy/sandbox/SandboxExecutor.js +77 -0
  89. package/dist/policy/types/policy.js +2 -0
  90. package/dist/scripts/devnetFunding.js +28 -0
  91. package/dist/scripts/devnetWalletPreflight.js +16 -0
  92. package/dist/scripts/localnetCheck.js +27 -0
  93. package/dist/scripts/managedAgentWallet.js +81 -0
  94. package/dist/scripts/mode.js +6 -0
  95. package/dist/scripts/releaseReadiness.js +93 -0
  96. package/dist/scripts/runAgentUniversalDeFi.js +115 -0
  97. package/dist/scripts/runAutonomousAgentWalletDevnet.js +154 -0
  98. package/dist/scripts/runAutonomousPortfolioDevnet.js +390 -0
  99. package/dist/scripts/runBorrowStrategy.js +35 -0
  100. package/dist/scripts/runDeFiSuite.js +41 -0
  101. package/dist/scripts/runDemoRehearsal.js +111 -0
  102. package/dist/scripts/runDevnetWalletDemo.js +53 -0
  103. package/dist/scripts/runGaslessMemo.js +23 -0
  104. package/dist/scripts/runGaslessWalletDemo.js +60 -0
  105. package/dist/scripts/runKaminoDevnet.js +109 -0
  106. package/dist/scripts/runLpStrategy.js +32 -0
  107. package/dist/scripts/runMarinadeDevnet.js +97 -0
  108. package/dist/scripts/runOrcaLpDevnet.js +208 -0
  109. package/dist/scripts/runRaydiumLpDevnet.js +95 -0
  110. package/dist/scripts/runReleaseReadiness.js +22 -0
  111. package/dist/scripts/runStakeStrategy.js +33 -0
  112. package/dist/scripts/runStressTest.js +41 -0
  113. package/dist/scripts/runTradeLoop.js +53 -0
  114. package/dist/scripts/runUniversalDeFiDemo.js +84 -0
  115. package/dist/scripts/runYieldStrategy.js +33 -0
  116. package/dist/scripts/runtimeFactory.js +27 -0
  117. package/dist/scripts/shared.js +24 -0
  118. package/dist/scripts/simulateAttack.js +40 -0
  119. package/dist/scripts/simulateSwarm.js +106 -0
  120. package/dist/simulation/attack.js +30 -0
  121. package/dist/solana/programs.js +9 -0
  122. package/dist/spl/TokenWallet.js +65 -0
  123. package/dist/types/policy.js +2 -0
  124. package/dist/wallet/WalletManager.js +5 -0
  125. package/package.json +99 -0
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const AgentManager_1 = require("../agent/AgentManager");
4
+ const MockPriceFeed_1 = require("../agent/MockPriceFeed");
5
+ const runtimeFactory_1 = require("./runtimeFactory");
6
+ const shared_1 = require("./shared");
7
+ const mode_1 = require("./mode");
8
+ async function main() {
9
+ (0, mode_1.printDemoMode)("SIMULATED", "Concurrent harness with per-agent rate limits and circuit breaker");
10
+ const events = await AgentManager_1.AgentManager.runManagedTradeSimulation({
11
+ amountSol: 0.01,
12
+ koraSigner: (0, shared_1.createKoraSigner)(),
13
+ liveSwapConfig: (0, runtimeFactory_1.createLiveSwapConfig)(),
14
+ logger: (0, shared_1.createRuntimeLogger)("stress"),
15
+ rounds: 5,
16
+ safetyControls: {
17
+ cooldownMs: 15_000,
18
+ maxActionsPerWindow: 2,
19
+ maxConsecutiveFailures: 2,
20
+ windowMs: 20_000
21
+ },
22
+ priceFeed: new MockPriceFeed_1.MockPriceFeed({
23
+ buyThresholdUsd: 100,
24
+ solPriceUsd: 92,
25
+ usdcPriceUsd: 1
26
+ })
27
+ });
28
+ console.log("Managed stress run complete.");
29
+ for (const event of events) {
30
+ if (event.status === "executed") {
31
+ console.log(`${event.agentId}#${event.iteration}: ${event.result.action} ${event.result.execution?.signature ?? "NOOP"}`);
32
+ continue;
33
+ }
34
+ console.log(`${event.agentId}#${event.iteration}: ${event.status} (${event.reason})`);
35
+ }
36
+ }
37
+ main().catch((error) => {
38
+ const message = error instanceof Error ? error.message : "Unknown error";
39
+ console.error(`Stress test failed: ${message}`);
40
+ process.exitCode = 1;
41
+ });
@@ -0,0 +1,53 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const PolicyGuard_1 = require("../policy/PolicyGuard");
4
+ const MockPriceFeed_1 = require("../agent/MockPriceFeed");
5
+ const AgentRuntime_1 = require("../agent/AgentRuntime");
6
+ const policyFactory_1 = require("../agent/policyFactory");
7
+ const managedAgentWallet_1 = require("./managedAgentWallet");
8
+ const runtimeFactory_1 = require("./runtimeFactory");
9
+ const shared_1 = require("./shared");
10
+ const mode_1 = require("./mode");
11
+ const DEFAULT_AGENT_NAME = "trade-loop";
12
+ async function main() {
13
+ const managed = (0, managedAgentWallet_1.resolveManagedAgentWallet)({
14
+ agentName: (0, managedAgentWallet_1.getManagedAgentName)({ defaultAgentName: DEFAULT_AGENT_NAME, env: process.env }),
15
+ ownerId: (0, managedAgentWallet_1.getManagedOwnerId)(process.env)
16
+ });
17
+ const walletManager = managed.walletManager;
18
+ const policy = (0, policyFactory_1.createDefaultAgentPolicy)();
19
+ const policyGuard = new PolicyGuard_1.PolicyGuard(policy);
20
+ const priceFeed = new MockPriceFeed_1.MockPriceFeed({
21
+ buyThresholdUsd: 100,
22
+ solPriceUsd: 95,
23
+ usdcPriceUsd: 1
24
+ });
25
+ const result = await (0, AgentRuntime_1.simulateMarketAction)({
26
+ amountSol: 0.01,
27
+ koraSigner: (0, shared_1.createKoraSigner)(),
28
+ liveSwapConfig: (0, runtimeFactory_1.createLiveSwapConfig)(),
29
+ logger: (0, shared_1.createRuntimeLogger)("trade"),
30
+ policyGuard,
31
+ priceFeed,
32
+ walletManager
33
+ });
34
+ (0, managedAgentWallet_1.logManagedAgentWallet)(managed);
35
+ const mode = result.liveSwap && !result.execution?.mock ? "LIVE" : "SIMULATED";
36
+ const detail = mode === "LIVE"
37
+ ? "Jupiter route built and submitted"
38
+ : "Memo intent and/or mock transport";
39
+ (0, mode_1.printDemoMode)(mode, detail);
40
+ console.log(`Trade action: ${result.action}`);
41
+ if (result.execution) {
42
+ console.log(`Trade signature: ${result.execution.signature}`);
43
+ }
44
+ if (result.liveSwap) {
45
+ console.log(`Trade route: ${result.liveSwap.routeType}`);
46
+ console.log(`Quote out amount: ${result.liveSwap.quoteOutAmount}`);
47
+ }
48
+ }
49
+ main().catch((error) => {
50
+ const message = error instanceof Error ? error.message : "Unknown error";
51
+ console.error(`Trade loop failed: ${message}`);
52
+ process.exitCode = 1;
53
+ });
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const web3_js_1 = require("@solana/web3.js");
4
+ const universal_1 = require("../defi/universal");
5
+ const managedAgentWallet_1 = require("./managedAgentWallet");
6
+ const shared_1 = require("./shared");
7
+ const mode_1 = require("./mode");
8
+ const DEFAULT_AGENT_NAME = "universal-defi-demo";
9
+ async function main() {
10
+ (0, mode_1.printDemoMode)("SIMULATED", "Universal DeFi compatibility mode (trade/lp/lending/borrowing/yield/staking routed by adapter registry)");
11
+ const managed = (0, managedAgentWallet_1.resolveManagedAgentWallet)({
12
+ agentName: (0, managedAgentWallet_1.getManagedAgentName)({
13
+ defaultAgentName: DEFAULT_AGENT_NAME,
14
+ env: process.env
15
+ }),
16
+ ownerId: (0, managedAgentWallet_1.getManagedOwnerId)(process.env)
17
+ });
18
+ const orchestrator = new universal_1.UniversalDeFiOrchestrator({
19
+ koraSigner: (0, shared_1.createKoraSigner)(),
20
+ liveFirst: false,
21
+ logger: (0, shared_1.createRuntimeLogger)("universal-defi"),
22
+ walletManager: managed.walletManager
23
+ });
24
+ (0, managedAgentWallet_1.logManagedAgentWallet)(managed);
25
+ const requests = [
26
+ {
27
+ capability: "trade",
28
+ snapshot: {
29
+ buyThresholdUsd: 100,
30
+ solPriceUsd: 95
31
+ }
32
+ },
33
+ {
34
+ capability: "staking",
35
+ snapshot: {
36
+ idleSolLamports: Math.round(1.0 * web3_js_1.LAMPORTS_PER_SOL)
37
+ }
38
+ },
39
+ {
40
+ capability: "lp",
41
+ snapshot: {
42
+ liquidityInRange: true
43
+ }
44
+ },
45
+ {
46
+ capability: "lending",
47
+ snapshot: {
48
+ healthFactor: 2.0,
49
+ idleUsdcAtomic: 5_000_000
50
+ }
51
+ },
52
+ {
53
+ capability: "borrowing",
54
+ protocol: "kamino",
55
+ snapshot: {
56
+ borrowDemandUsdcAtomic: 3_000_000,
57
+ collateralSolLamports: Math.round(1.2 * web3_js_1.LAMPORTS_PER_SOL),
58
+ healthFactor: 2.3
59
+ }
60
+ },
61
+ {
62
+ capability: "yield",
63
+ protocol: "kamino",
64
+ snapshot: {
65
+ healthFactor: 2.1,
66
+ idleUsdcAtomic: 4_000_000
67
+ }
68
+ }
69
+ ];
70
+ const results = await orchestrator.executeBatch(requests);
71
+ console.log("Universal DeFi run complete.");
72
+ for (const entry of results) {
73
+ if (!entry.result) {
74
+ console.log(`${entry.capability}/${entry.protocol}: HOLD`);
75
+ continue;
76
+ }
77
+ console.log(`${entry.capability}/${entry.protocol}: ${entry.result.action} ${entry.result.signature}`);
78
+ }
79
+ }
80
+ main().catch((error) => {
81
+ const message = error instanceof Error ? error.message : "Unknown error";
82
+ console.error(`Universal DeFi demo failed: ${message}`);
83
+ process.exitCode = 1;
84
+ });
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const DeFiCoordinator_1 = require("../defi/DeFiCoordinator");
4
+ const managedAgentWallet_1 = require("./managedAgentWallet");
5
+ const shared_1 = require("./shared");
6
+ const mode_1 = require("./mode");
7
+ const DEFAULT_AGENT_NAME = "yield-strategy";
8
+ async function main() {
9
+ (0, mode_1.printDemoMode)("SIMULATED", "Protocol intent only (memo execution), not live Kamino instructions");
10
+ const managed = (0, managedAgentWallet_1.resolveManagedAgentWallet)({
11
+ agentName: (0, managedAgentWallet_1.getManagedAgentName)({ defaultAgentName: DEFAULT_AGENT_NAME, env: process.env }),
12
+ ownerId: (0, managedAgentWallet_1.getManagedOwnerId)(process.env)
13
+ });
14
+ const coordinator = new DeFiCoordinator_1.DeFiCoordinator(managed.walletManager, (0, shared_1.createKoraSigner)(), (0, shared_1.createRuntimeLogger)("yield"));
15
+ (0, managedAgentWallet_1.logManagedAgentWallet)(managed);
16
+ const result = await coordinator.runLendingStrategy({
17
+ healthFactor: 2.1,
18
+ idleUsdcAtomic: 5_000_000
19
+ });
20
+ console.log("Yield strategy complete.");
21
+ if (!result) {
22
+ console.log("No lending action executed.");
23
+ return;
24
+ }
25
+ console.log(`Protocol: ${result.protocol}`);
26
+ console.log(`Action: ${result.action}`);
27
+ console.log(`Signature: ${result.signature}`);
28
+ }
29
+ main().catch((error) => {
30
+ const message = error instanceof Error ? error.message : "Unknown error";
31
+ console.error(`Yield strategy failed: ${message}`);
32
+ process.exitCode = 1;
33
+ });
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createLiveSwapConfig = createLiveSwapConfig;
4
+ const env_1 = require("../config/env");
5
+ const JupiterSwapClient_1 = require("../dex/JupiterSwapClient");
6
+ const SwapExecutor_1 = require("../dex/SwapExecutor");
7
+ function createLiveSwapConfig() {
8
+ const enabled = (0, env_1.isLiveSwapPathEnabled)();
9
+ const outputMint = (0, env_1.getUsdcMintAddress)();
10
+ (0, env_1.assertMintMatchesRpcCluster)({
11
+ mintAddress: outputMint,
12
+ mintName: "USDC_MINT",
13
+ rpcUrl: (0, env_1.getRpcUrl)()
14
+ });
15
+ if (!enabled) {
16
+ return {
17
+ enabled,
18
+ outputMint,
19
+ swapExecutor: null
20
+ };
21
+ }
22
+ return {
23
+ enabled,
24
+ outputMint,
25
+ swapExecutor: new SwapExecutor_1.SwapExecutor(new JupiterSwapClient_1.JupiterSwapClient((0, env_1.getJupiterApiBaseUrl)()))
26
+ };
27
+ }
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createRuntimeLogger = createRuntimeLogger;
4
+ exports.createKoraSigner = createKoraSigner;
5
+ const env_1 = require("../config/env");
6
+ const KoraRpcClient_1 = require("../kora/KoraRpcClient");
7
+ const KoraSigner_1 = require("../kora/KoraSigner");
8
+ function createRuntimeLogger(prefix) {
9
+ return (message) => {
10
+ console.log(`[${prefix}] ${message}`);
11
+ };
12
+ }
13
+ function createKoraSigner() {
14
+ const koraRpcUrl = (0, env_1.getKoraRpcUrl)();
15
+ const mockMode = (0, env_1.isKoraMockMode)();
16
+ console.log(`[runtime] Solana RPC: ${(0, env_1.getRpcUrl)()}`);
17
+ console.log(`[runtime] Kora RPC: ${koraRpcUrl}`);
18
+ console.log(`[runtime] Kora mock mode: ${mockMode}`);
19
+ console.log(`[runtime] Live swap path: ${(0, env_1.isLiveSwapPathEnabled)()}`);
20
+ console.log(`[runtime] Jupiter API: ${(0, env_1.getJupiterApiBaseUrl)()}`);
21
+ return new KoraSigner_1.KoraSigner(new KoraRpcClient_1.KoraRpcClient(koraRpcUrl), {
22
+ mockMode
23
+ });
24
+ }
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const PolicyGuard_1 = require("../policy/PolicyGuard");
4
+ const errors_1 = require("../policy/errors");
5
+ const policyFactory_1 = require("../agent/policyFactory");
6
+ const attack_1 = require("../simulation/attack");
7
+ const managedAgentWallet_1 = require("./managedAgentWallet");
8
+ const DEFAULT_AGENT_NAME = "simulate-attack";
9
+ function main() {
10
+ const managed = (0, managedAgentWallet_1.resolveManagedAgentWallet)({
11
+ agentName: (0, managedAgentWallet_1.getManagedAgentName)({ defaultAgentName: DEFAULT_AGENT_NAME, env: process.env }),
12
+ ownerId: (0, managedAgentWallet_1.getManagedOwnerId)(process.env)
13
+ });
14
+ const walletManager = managed.walletManager;
15
+ const policy = (0, policyFactory_1.createDefaultAgentPolicy)({
16
+ whitelistedTransferDestinations: []
17
+ });
18
+ const policyGuard = new PolicyGuard_1.PolicyGuard(policy);
19
+ try {
20
+ (0, attack_1.simulateAttack)(policyGuard, walletManager);
21
+ console.error("Security failure: attack unexpectedly succeeded.");
22
+ process.exitCode = 1;
23
+ }
24
+ catch (error) {
25
+ if (error instanceof errors_1.SecurityViolationError) {
26
+ console.log("SecurityViolation detected. Attack blocked successfully.");
27
+ console.log(error.message);
28
+ return;
29
+ }
30
+ throw error;
31
+ }
32
+ }
33
+ try {
34
+ main();
35
+ }
36
+ catch (error) {
37
+ const message = error instanceof Error ? error.message : "Unknown error";
38
+ console.error(`Attack simulation failed: ${message}`);
39
+ process.exitCode = 1;
40
+ }
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const web3_js_1 = require("@solana/web3.js");
4
+ const policyFactory_1 = require("../agent/policyFactory");
5
+ const PolicyGuard_1 = require("../policy/PolicyGuard");
6
+ const errors_1 = require("../policy/errors");
7
+ const programs_1 = require("../solana/programs");
8
+ const WalletManager_1 = require("../wallet/WalletManager");
9
+ const shared_1 = require("./shared");
10
+ const mode_1 = require("./mode");
11
+ function log(agentId, message) {
12
+ console.log(`[swarm][${agentId}] ${message}`);
13
+ }
14
+ function createTransferProbe(walletManager, destination, lamports) {
15
+ const message = new web3_js_1.TransactionMessage({
16
+ payerKey: walletManager.publicKey,
17
+ recentBlockhash: programs_1.MOCK_BLOCKHASH,
18
+ instructions: [
19
+ web3_js_1.SystemProgram.transfer({
20
+ fromPubkey: walletManager.publicKey,
21
+ toPubkey: new web3_js_1.PublicKey(destination),
22
+ lamports
23
+ })
24
+ ]
25
+ }).compileToV0Message();
26
+ const transaction = new web3_js_1.VersionedTransaction(message);
27
+ transaction.sign([walletManager.payer]);
28
+ return transaction;
29
+ }
30
+ async function runRole(role, koraSigner) {
31
+ const walletManager = WalletManager_1.WalletManager.generate();
32
+ const policyGuard = new PolicyGuard_1.PolicyGuard(role.policy);
33
+ log(role.id, `Role: ${role.description}`);
34
+ log(role.id, `Wallet: ${walletManager.publicKey.toBase58()}`);
35
+ log(role.id, `Policy max spend: ${role.policy.maxSpend.lamports} lamports`);
36
+ log(role.id, `Policy transfer whitelist: ${role.policy.whitelistedTransferDestinations.length} destination(s)`);
37
+ log(role.id, "Policy check starting.");
38
+ if (role.runBlockedProbe) {
39
+ try {
40
+ const blockedProbe = createTransferProbe(walletManager, web3_js_1.Keypair.generate().publicKey.toBase58(), 100_000);
41
+ policyGuard.validate(blockedProbe);
42
+ log(role.id, "Strict whitelist probe unexpectedly passed.");
43
+ }
44
+ catch (error) {
45
+ if (error instanceof errors_1.SecurityViolationError) {
46
+ log(role.id, `Strict whitelist probe blocked as expected: ${error.message}`);
47
+ }
48
+ else {
49
+ throw error;
50
+ }
51
+ }
52
+ }
53
+ const transaction = await koraSigner.buildMemoTransaction(walletManager, role.memo);
54
+ policyGuard.validate(transaction);
55
+ log(role.id, "Policy check passed. Executing gasless action.");
56
+ const execution = await koraSigner.signAndSendGasless(transaction, role.memo);
57
+ log(role.id, `Execution complete (${execution.mock ? "mock" : "live"}): ${execution.signature}`);
58
+ }
59
+ async function main() {
60
+ (0, mode_1.printDemoMode)("SIMULATED", "Multi-agent memo execution and policy probes");
61
+ console.log("PRKT swarm simulation");
62
+ console.log("Spawning 3 distinct agent wallets and executing in parallel.");
63
+ const koraSigner = (0, shared_1.createKoraSigner)();
64
+ const liquidationVault = web3_js_1.Keypair.generate().publicKey.toBase58();
65
+ const roles = [
66
+ {
67
+ description: "High-frequency operator (low spend limit)",
68
+ id: "agent-1",
69
+ memo: "HFT heartbeat: rebalance window open",
70
+ policy: (0, policyFactory_1.createDefaultAgentPolicy)({
71
+ maxSpend: {
72
+ lamports: 50_000
73
+ }
74
+ })
75
+ },
76
+ {
77
+ description: "Long-term staker (high spend limit)",
78
+ id: "agent-2",
79
+ memo: "Staker review: epoch position healthy",
80
+ policy: (0, policyFactory_1.createDefaultAgentPolicy)({
81
+ maxSpend: {
82
+ lamports: 10_000_000
83
+ }
84
+ })
85
+ },
86
+ {
87
+ description: "Liquidator (strict whitelist)",
88
+ id: "agent-3",
89
+ memo: "Liquidator check: liquidation opportunity queued",
90
+ policy: (0, policyFactory_1.createDefaultAgentPolicy)({
91
+ maxSpend: {
92
+ lamports: 250_000
93
+ },
94
+ whitelistedTransferDestinations: [liquidationVault]
95
+ }),
96
+ runBlockedProbe: true
97
+ }
98
+ ];
99
+ await Promise.all(roles.map(async (role) => runRole(role, koraSigner)));
100
+ console.log("Swarm simulation complete.");
101
+ }
102
+ main().catch((error) => {
103
+ const message = error instanceof Error ? error.message : "Unknown error";
104
+ console.error(`Swarm simulation failed: ${message}`);
105
+ process.exitCode = 1;
106
+ });
@@ -0,0 +1,30 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createCompromisedDrainTransaction = createCompromisedDrainTransaction;
4
+ exports.simulateAttack = simulateAttack;
5
+ const web3_js_1 = require("@solana/web3.js");
6
+ const programs_1 = require("../solana/programs");
7
+ function createCompromisedDrainTransaction(walletManager) {
8
+ const attackerDestination = web3_js_1.Keypair.generate().publicKey;
9
+ const instruction = web3_js_1.SystemProgram.transfer({
10
+ fromPubkey: walletManager.publicKey,
11
+ toPubkey: attackerDestination,
12
+ lamports: 1_000_000
13
+ });
14
+ const message = new web3_js_1.TransactionMessage({
15
+ payerKey: walletManager.publicKey,
16
+ recentBlockhash: programs_1.MOCK_BLOCKHASH,
17
+ instructions: [instruction]
18
+ }).compileToV0Message();
19
+ const transaction = new web3_js_1.VersionedTransaction(message);
20
+ transaction.sign([walletManager.payer]);
21
+ return {
22
+ recipient: attackerDestination.toBase58(),
23
+ transaction
24
+ };
25
+ }
26
+ function simulateAttack(policyGuard, walletManager) {
27
+ const { recipient, transaction } = createCompromisedDrainTransaction(walletManager);
28
+ policyGuard.validate(transaction);
29
+ return recipient;
30
+ }
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TOKEN_PROGRAM_ID = exports.NATIVE_MINT = exports.MOCK_BLOCKHASH = exports.MEMO_PROGRAM_ID = exports.ASSOCIATED_TOKEN_PROGRAM_ID = void 0;
4
+ const web3_js_1 = require("@solana/web3.js");
5
+ exports.ASSOCIATED_TOKEN_PROGRAM_ID = new web3_js_1.PublicKey("ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL");
6
+ exports.MEMO_PROGRAM_ID = new web3_js_1.PublicKey("MemoSq4gqABAXKb96qnH8TysNcWxMyWCqXgDLGmfcHr");
7
+ exports.MOCK_BLOCKHASH = "11111111111111111111111111111111";
8
+ exports.NATIVE_MINT = new web3_js_1.PublicKey("So11111111111111111111111111111111111111112");
9
+ exports.TOKEN_PROGRAM_ID = new web3_js_1.PublicKey("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA");
@@ -0,0 +1,65 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TokenWallet = void 0;
4
+ const web3_js_1 = require("@solana/web3.js");
5
+ const programs_1 = require("../solana/programs");
6
+ class TokenWallet {
7
+ static findAssociatedTokenAddress(owner, mint) {
8
+ const [associatedTokenAddress] = web3_js_1.PublicKey.findProgramAddressSync([owner.toBuffer(), programs_1.TOKEN_PROGRAM_ID.toBuffer(), mint.toBuffer()], programs_1.ASSOCIATED_TOKEN_PROGRAM_ID);
9
+ return associatedTokenAddress;
10
+ }
11
+ static async buildWrapSolTransaction(input) {
12
+ if (!Number.isInteger(input.amountLamports) || input.amountLamports <= 0) {
13
+ throw new Error("Wrap SOL amount must be a positive integer lamport value.");
14
+ }
15
+ const associatedTokenAddress = TokenWallet.findAssociatedTokenAddress(input.walletManager.publicKey, programs_1.NATIVE_MINT);
16
+ const instructions = [];
17
+ if (input.createAssociatedTokenAccount) {
18
+ instructions.push(TokenWallet.createAssociatedTokenAccountInstruction({
19
+ mint: programs_1.NATIVE_MINT,
20
+ owner: input.walletManager.publicKey,
21
+ payer: input.walletManager.publicKey
22
+ }));
23
+ }
24
+ instructions.push(web3_js_1.SystemProgram.transfer({
25
+ fromPubkey: input.walletManager.publicKey,
26
+ toPubkey: associatedTokenAddress,
27
+ lamports: input.amountLamports
28
+ }), TokenWallet.createSyncNativeInstruction(associatedTokenAddress));
29
+ const message = new web3_js_1.TransactionMessage({
30
+ payerKey: input.walletManager.publicKey,
31
+ recentBlockhash: input.recentBlockhash,
32
+ instructions
33
+ }).compileToV0Message();
34
+ const transaction = new web3_js_1.VersionedTransaction(message);
35
+ const signedTransaction = await input.walletManager.signTransaction(transaction);
36
+ return {
37
+ associatedTokenAddress,
38
+ createdAssociatedTokenAccount: input.createAssociatedTokenAccount,
39
+ transaction: signedTransaction
40
+ };
41
+ }
42
+ static createAssociatedTokenAccountInstruction(input) {
43
+ const associatedTokenAddress = TokenWallet.findAssociatedTokenAddress(input.owner, input.mint);
44
+ return new web3_js_1.TransactionInstruction({
45
+ programId: programs_1.ASSOCIATED_TOKEN_PROGRAM_ID,
46
+ keys: [
47
+ { pubkey: input.payer, isSigner: true, isWritable: true },
48
+ { pubkey: associatedTokenAddress, isSigner: false, isWritable: true },
49
+ { pubkey: input.owner, isSigner: false, isWritable: false },
50
+ { pubkey: input.mint, isSigner: false, isWritable: false },
51
+ { pubkey: web3_js_1.SystemProgram.programId, isSigner: false, isWritable: false },
52
+ { pubkey: programs_1.TOKEN_PROGRAM_ID, isSigner: false, isWritable: false }
53
+ ],
54
+ data: Buffer.alloc(0)
55
+ });
56
+ }
57
+ static createSyncNativeInstruction(associatedTokenAddress) {
58
+ return new web3_js_1.TransactionInstruction({
59
+ programId: programs_1.TOKEN_PROGRAM_ID,
60
+ keys: [{ pubkey: associatedTokenAddress, isSigner: false, isWritable: true }],
61
+ data: Buffer.from([17])
62
+ });
63
+ }
64
+ }
65
+ exports.TokenWallet = TokenWallet;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WalletManager = void 0;
4
+ var WalletManager_1 = require("../core/wallet/WalletManager");
5
+ Object.defineProperty(exports, "WalletManager", { enumerable: true, get: function () { return WalletManager_1.WalletManager; } });
package/package.json ADDED
@@ -0,0 +1,99 @@
1
+ {
2
+ "name": "@prktsol/prkt",
3
+ "version": "1.0.0",
4
+ "description": "Policy-enforced autonomous agent wallet scaffold for Solana.",
5
+ "main": "dist/index.js",
6
+ "bin": {
7
+ "prkt": "dist/cli/index.js"
8
+ },
9
+ "files": [
10
+ "dist/**/*",
11
+ ".env.example",
12
+ ".env.devnet.all-protocols.example",
13
+ ".env.devnet.autonomous.example",
14
+ ".env.devnet.jupiter.example",
15
+ ".env.devnet.kamino.example",
16
+ ".env.devnet.marinade.example",
17
+ ".env.devnet.orca.example",
18
+ ".env.devnet.raydium.example",
19
+ "ARCHITECTURE.md",
20
+ "CLI.md",
21
+ "CLI_QUICKSTART.md",
22
+ "COMPATIBILITY.md",
23
+ "DEVNET_PROTOCOL_ADDRESSES.md",
24
+ "README.md"
25
+ ],
26
+ "type": "commonjs",
27
+ "scripts": {
28
+ "build": "node -e \"require('fs').rmSync('dist', { recursive: true, force: true })\" && tsc -p tsconfig.json",
29
+ "cli": "ts-node src/cli/index.ts",
30
+ "dashboard:demo": "node src/scripts/runDashboard.mjs",
31
+ "dev": "ts-node src/index.ts",
32
+ "demo:autonomous-agent-wallet:devnet": "ts-node src/scripts/runAutonomousAgentWalletDevnet.ts",
33
+ "demo:autonomous-portfolio:devnet": "ts-node src/scripts/runAutonomousPortfolioDevnet.ts",
34
+ "defi:all": "ts-node src/scripts/runDeFiSuite.ts",
35
+ "defi:universal": "ts-node src/scripts/runUniversalDeFiDemo.ts",
36
+ "agent:defi:universal": "ts-node src/scripts/runAgentUniversalDeFi.ts",
37
+ "defi:all:sim": "ts-node src/scripts/runDeFiSuite.ts",
38
+ "defi:lp": "ts-node src/scripts/runLpStrategy.ts",
39
+ "defi:lp:sim": "ts-node src/scripts/runLpStrategy.ts",
40
+ "defi:lp:devnet": "ts-node src/scripts/runRaydiumLpDevnet.ts",
41
+ "defi:orca:devnet": "ts-node src/scripts/runOrcaLpDevnet.ts",
42
+ "defi:kamino:devnet": "ts-node src/scripts/runKaminoDevnet.ts",
43
+ "defi:borrow": "ts-node src/scripts/runBorrowStrategy.ts",
44
+ "defi:borrow:sim": "ts-node src/scripts/runBorrowStrategy.ts",
45
+ "defi:stake": "ts-node src/scripts/runStakeStrategy.ts",
46
+ "defi:stake:sim": "ts-node src/scripts/runStakeStrategy.ts",
47
+ "defi:stake:devnet": "ts-node src/scripts/runMarinadeDevnet.ts",
48
+ "defi:yield": "ts-node src/scripts/runYieldStrategy.ts",
49
+ "defi:yield:sim": "ts-node src/scripts/runYieldStrategy.ts",
50
+ "wallet:gasless": "ts-node src/scripts/runGaslessWalletDemo.ts",
51
+ "kora:memo": "ts-node src/scripts/runGaslessMemo.ts",
52
+ "trade:simulate": "ts-node src/scripts/runTradeLoop.ts",
53
+ "simulate-attack": "ts-node src/scripts/simulateAttack.ts",
54
+ "simulate:swarm": "ts-node src/scripts/simulateSwarm.ts",
55
+ "stress:agents": "ts-node src/scripts/runStressTest.ts",
56
+ "release:check": "ts-node src/scripts/runReleaseReadiness.ts",
57
+ "demo:rehearsal": "ts-node src/scripts/runDemoRehearsal.ts",
58
+ "test": "jest --runInBand",
59
+ "test:coverage": "jest --runInBand --coverage",
60
+ "test:watch": "jest --watch",
61
+ "wallet:devnet": "ts-node src/scripts/runDevnetWalletDemo.ts",
62
+ "demo:multi-agent:devnet": "ts-node src/demo/scripts/runMultiAgentDevnetDemo.ts",
63
+ "wallet:status": "ts-node src/index.ts"
64
+ },
65
+ "keywords": [
66
+ "solana",
67
+ "agent",
68
+ "wallet",
69
+ "typescript"
70
+ ],
71
+ "engines": {
72
+ "node": ">=18"
73
+ },
74
+ "author": "",
75
+ "license": "ISC",
76
+ "dependencies": {
77
+ "@coral-xyz/anchor": "^0.32.1",
78
+ "@kamino-finance/klend-sdk": "^7.3.20",
79
+ "@marinade.finance/marinade-ts-sdk": "^5.0.18",
80
+ "@orca-so/common-sdk": "^0.7.0",
81
+ "@orca-so/whirlpools-sdk": "^0.20.0",
82
+ "@raydium-io/raydium-sdk-v2": "^0.1.95-alpha",
83
+ "@solana/spl-token": "^0.4.14",
84
+ "@solana/web3.js": "^1.98.4",
85
+ "chalk": "^4.1.2",
86
+ "commander": "^12.1.0",
87
+ "decimal.js": "^10.6.0",
88
+ "dotenv": "^16.6.1",
89
+ "solana-agent-kit": "^1.4.9"
90
+ },
91
+ "devDependencies": {
92
+ "@types/jest": "^30.0.0",
93
+ "@types/node": "^24.6.0",
94
+ "jest": "^30.2.0",
95
+ "ts-jest": "^29.4.1",
96
+ "ts-node": "^10.9.2",
97
+ "typescript": "^5.9.3"
98
+ }
99
+ }