@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,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const web3_js_1 = require("@solana/web3.js");
4
+ const env_1 = require("../config/env");
5
+ const gaslessDemo_1 = require("../kora/gaslessDemo");
6
+ const TokenWallet_1 = require("../spl/TokenWallet");
7
+ const managedAgentWallet_1 = require("./managedAgentWallet");
8
+ const shared_1 = require("./shared");
9
+ const mode_1 = require("./mode");
10
+ const DEFAULT_AGENT_NAME = "gasless-wallet-demo";
11
+ async function main() {
12
+ const rpcUrl = (0, env_1.getRpcUrl)();
13
+ const usdcMintAddress = (0, env_1.getUsdcMintAddress)();
14
+ (0, env_1.assertMintMatchesRpcCluster)({
15
+ mintAddress: usdcMintAddress,
16
+ mintName: "USDC_MINT",
17
+ rpcUrl
18
+ });
19
+ const connection = new web3_js_1.Connection(rpcUrl, "confirmed");
20
+ const managed = (0, managedAgentWallet_1.resolveManagedAgentWallet)({
21
+ agentName: (0, managedAgentWallet_1.getManagedAgentName)({ defaultAgentName: DEFAULT_AGENT_NAME, env: process.env }),
22
+ ownerId: (0, managedAgentWallet_1.getManagedOwnerId)(process.env)
23
+ });
24
+ const walletManager = managed.walletManager;
25
+ const koraSigner = (0, shared_1.createKoraSigner)();
26
+ const usdcMint = new web3_js_1.PublicKey(usdcMintAddress);
27
+ const usdcAccount = TokenWallet_1.TokenWallet.findAssociatedTokenAddress(walletManager.publicKey, usdcMint);
28
+ const solLamports = await connection.getBalance(walletManager.publicKey, "confirmed");
29
+ const usdcAccountInfo = await connection.getAccountInfo(usdcAccount, "confirmed");
30
+ let usdcBalance = 0;
31
+ if (usdcAccountInfo) {
32
+ const tokenBalance = await connection.getTokenAccountBalance(usdcAccount, "confirmed");
33
+ usdcBalance = (0, gaslessDemo_1.parseUiAmount)(tokenBalance.value);
34
+ }
35
+ console.log("PRKT gasless wallet demo");
36
+ (0, managedAgentWallet_1.logManagedAgentWallet)(managed);
37
+ console.log(`USDC ATA: ${usdcAccount.toBase58()}`);
38
+ console.log(`Starting SOL balance (lamports): ${solLamports}`);
39
+ console.log(`Starting USDC balance: ${usdcBalance.toFixed(6)}`);
40
+ (0, gaslessDemo_1.assertGaslessDemoReadiness)({
41
+ solLamports,
42
+ usdcBalance
43
+ });
44
+ if ((0, env_1.isKoraMockMode)()) {
45
+ console.log("KORA_MOCK_MODE=true. The script will show the same fee-abstraction flow, but the signature is simulated.");
46
+ }
47
+ const result = await koraSigner.submitGaslessMemo(walletManager, "PRKT gasless agent check (USDC-backed fee abstraction)");
48
+ (0, mode_1.printDemoMode)(result.mock ? "SIMULATED" : "LIVE", "Gasless memo transport");
49
+ const endingSolLamports = await connection.getBalance(walletManager.publicKey, "confirmed");
50
+ console.log("Gasless execution complete.");
51
+ console.log(`Signature: ${result.signature}`);
52
+ console.log(`Mode: ${result.mock ? "mock" : "live"}`);
53
+ console.log(`Ending SOL balance (lamports): ${endingSolLamports}`);
54
+ console.log("Kora relayed the transaction while the wallet started at 0 SOL. For this demo, the relayer is expected to be configured to settle fees against the wallet's USDC liquidity.");
55
+ }
56
+ main().catch((error) => {
57
+ const message = error instanceof Error ? error.message : "Unknown error";
58
+ console.error(`Gasless wallet demo failed: ${message}`);
59
+ process.exitCode = 1;
60
+ });
@@ -0,0 +1,109 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const web3_js_1 = require("@solana/web3.js");
4
+ const agentPolicies_1 = require("../config/agentPolicies");
5
+ const env_1 = require("../config/env");
6
+ const BalanceService_1 = require("../core/balances/BalanceService");
7
+ const DevnetFundingService_1 = require("../core/funding/DevnetFundingService");
8
+ const RpcClient_1 = require("../core/rpc/RpcClient");
9
+ const TokenService_1 = require("../core/tokens/TokenService");
10
+ const TransactionService_1 = require("../core/transactions/TransactionService");
11
+ const kaminoLiveConfig_1 = require("../defi/kamino/kaminoLiveConfig");
12
+ const protocols_1 = require("../defi/protocols");
13
+ const liveExecutors_1 = require("../defi/universal/liveExecutors");
14
+ const policy_1 = require("../policy");
15
+ const managedAgentWallet_1 = require("./managedAgentWallet");
16
+ const mode_1 = require("./mode");
17
+ const DEFAULT_AGENT_NAME = "kamino-live-devnet";
18
+ async function main() {
19
+ const action = parseAction(process.argv[2]);
20
+ (0, mode_1.printDemoMode)("LIVE", `Kamino ${action} transaction on configured cluster`);
21
+ const rpcClient = new RpcClient_1.RpcClient((0, env_1.getRpcUrl)(), "confirmed");
22
+ const transactionService = new TransactionService_1.TransactionService(rpcClient);
23
+ const tokenService = new TokenService_1.TokenService(rpcClient);
24
+ const balanceService = new BalanceService_1.BalanceService(rpcClient, tokenService);
25
+ const fundingService = new DevnetFundingService_1.DevnetFundingService(rpcClient, transactionService);
26
+ const config = (0, kaminoLiveConfig_1.loadKaminoLiveConfig)();
27
+ const managed = (0, managedAgentWallet_1.resolveManagedAgentWallet)({
28
+ agentName: (0, managedAgentWallet_1.getManagedAgentName)({
29
+ defaultAgentName: DEFAULT_AGENT_NAME,
30
+ env: process.env
31
+ }),
32
+ ownerId: (0, managedAgentWallet_1.getManagedOwnerId)(process.env)
33
+ });
34
+ const walletManager = managed.walletManager;
35
+ await (0, managedAgentWallet_1.ensureManagedAgentWalletFunding)({
36
+ balanceService,
37
+ fundingService,
38
+ minimumSol: action === "deposit"
39
+ ? Number(config.actions.depositAmountRaw) / web3_js_1.LAMPORTS_PER_SOL + 0.05
40
+ : 0.05,
41
+ publicKey: walletManager.publicKey
42
+ });
43
+ const prepared = await (0, liveExecutors_1.prepareLiveKamino)({
44
+ intent: {
45
+ action,
46
+ amountLamports: 0,
47
+ marketId: protocols_1.PROTOCOL_PRESETS.kamino.defaultMarketId,
48
+ memo: `LIVE:KAMINO:${action}`,
49
+ protocol: "kamino",
50
+ slippageBps: 40
51
+ },
52
+ logger: (message) => console.log(`[kamino-live] ${message}`),
53
+ walletManager
54
+ });
55
+ if (!prepared) {
56
+ throw new Error("Kamino live execution was not prepared. Check ENABLE_LIVE_KAMINO and config.");
57
+ }
58
+ const policyEngine = new policy_1.PolicyEngine((0, agentPolicies_1.createDefaultPolicyConfig)({
59
+ allowOpaqueProgramIds: prepared.policyConfigPatch?.rules?.allowOpaqueProgramIds,
60
+ agentId: managed.agent.name,
61
+ allowedCloseAccountDestinations: prepared.policyConfigPatch?.rules?.allowedCloseAccountDestinations,
62
+ approvalMode: "sandbox",
63
+ extraAllowedProgramIds: prepared.policyConfigPatch?.rules?.allowedProgramIds ?? [config.programId]
64
+ }));
65
+ const sandboxExecutor = new policy_1.SandboxExecutor(policyEngine, transactionService, "sandbox");
66
+ console.log("PRKT Kamino live demo");
67
+ (0, managedAgentWallet_1.logManagedAgentWallet)(managed);
68
+ console.log(`Market: ${config.marketAddress}`);
69
+ console.log(`Program: ${config.programId}`);
70
+ console.log(`Action: ${action}`);
71
+ console.log(`Amount (raw): ${action === "deposit" ? config.actions.depositAmountRaw : config.actions.borrowAmountRaw}`);
72
+ const execution = await sandboxExecutor.executePreparedTransaction({
73
+ confirmationStrategy: prepared.confirmationStrategy,
74
+ inspectionContext: prepared.inspectionContext,
75
+ transaction: prepared.transaction
76
+ });
77
+ if (!execution.signature) {
78
+ const simulationLogs = execution.simulationLogs?.join(" | ");
79
+ throw new Error(`Guarded Kamino execution blocked: ${summarizeKaminoFailure(execution.inspection.reasons.join("; "), simulationLogs) ||
80
+ "unknown reason"}${simulationLogs ? ` | simulation logs: ${simulationLogs}` : ""}`);
81
+ }
82
+ if (prepared.verifyExecution) {
83
+ await prepared.verifyExecution(execution.signature);
84
+ }
85
+ console.log(`Transaction signature: ${execution.signature}`);
86
+ }
87
+ function parseAction(rawValue) {
88
+ if (!rawValue || rawValue === "deposit") {
89
+ return "deposit";
90
+ }
91
+ if (rawValue === "borrow") {
92
+ return "borrow";
93
+ }
94
+ throw new Error(`Unsupported action '${rawValue}'. Use 'deposit' or 'borrow'.`);
95
+ }
96
+ function summarizeKaminoFailure(reason, simulationLogs) {
97
+ if (simulationLogs?.includes("ReserveStale")) {
98
+ return "reserve refresh is currently broken on the selected devnet market";
99
+ }
100
+ if (simulationLogs?.includes("InvalidOracleConfig")) {
101
+ return "the selected devnet market has invalid oracle configuration";
102
+ }
103
+ return reason;
104
+ }
105
+ main().catch((error) => {
106
+ const message = error instanceof Error ? error.message : "Unknown error";
107
+ console.error(`Kamino live demo failed: ${message}`);
108
+ process.exitCode = 1;
109
+ });
@@ -0,0 +1,32 @@
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 = "lp-strategy";
8
+ async function main() {
9
+ (0, mode_1.printDemoMode)("SIMULATED", "Protocol intent only (memo execution), not live Raydium LP 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)("lp"));
15
+ (0, managedAgentWallet_1.logManagedAgentWallet)(managed);
16
+ const result = await coordinator.runLiquidityStrategy({
17
+ liquidityInRange: true
18
+ });
19
+ console.log("LP strategy complete.");
20
+ if (!result) {
21
+ console.log("No liquidity action executed.");
22
+ return;
23
+ }
24
+ console.log(`Protocol: ${result.protocol}`);
25
+ console.log(`Action: ${result.action}`);
26
+ console.log(`Signature: ${result.signature}`);
27
+ }
28
+ main().catch((error) => {
29
+ const message = error instanceof Error ? error.message : "Unknown error";
30
+ console.error(`LP strategy failed: ${message}`);
31
+ process.exitCode = 1;
32
+ });
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const web3_js_1 = require("@solana/web3.js");
4
+ const agentPolicies_1 = require("../config/agentPolicies");
5
+ const env_1 = require("../config/env");
6
+ const BalanceService_1 = require("../core/balances/BalanceService");
7
+ const DevnetFundingService_1 = require("../core/funding/DevnetFundingService");
8
+ const RpcClient_1 = require("../core/rpc/RpcClient");
9
+ const TokenService_1 = require("../core/tokens/TokenService");
10
+ const TransactionService_1 = require("../core/transactions/TransactionService");
11
+ const protocols_1 = require("../defi/protocols");
12
+ const liveExecutors_1 = require("../defi/universal/liveExecutors");
13
+ const policy_1 = require("../policy");
14
+ const managedAgentWallet_1 = require("./managedAgentWallet");
15
+ const mode_1 = require("./mode");
16
+ const DEFAULT_AGENT_NAME = "marinade-live-devnet";
17
+ async function main() {
18
+ const amountLamports = parseAmountLamports(process.argv[2]);
19
+ (0, mode_1.printDemoMode)("LIVE", `Marinade staking transaction on configured cluster (${amountLamports} lamports)`);
20
+ const rpcUrl = (0, env_1.getRpcUrl)();
21
+ const cluster = (0, env_1.detectClusterFromRpcUrl)(rpcUrl);
22
+ if (cluster !== "devnet") {
23
+ throw new Error(`Marinade live demo requires devnet. Current RPC cluster is ${cluster} (${rpcUrl}).`);
24
+ }
25
+ const rpcClient = new RpcClient_1.RpcClient(rpcUrl, "confirmed");
26
+ const tokenService = new TokenService_1.TokenService(rpcClient);
27
+ const balanceService = new BalanceService_1.BalanceService(rpcClient, tokenService);
28
+ const transactionService = new TransactionService_1.TransactionService(rpcClient);
29
+ const fundingService = new DevnetFundingService_1.DevnetFundingService(rpcClient, transactionService);
30
+ const managed = (0, managedAgentWallet_1.resolveManagedAgentWallet)({
31
+ agentName: (0, managedAgentWallet_1.getManagedAgentName)({
32
+ defaultAgentName: DEFAULT_AGENT_NAME,
33
+ env: process.env
34
+ }),
35
+ ownerId: (0, managedAgentWallet_1.getManagedOwnerId)(process.env)
36
+ });
37
+ const walletManager = managed.walletManager;
38
+ await (0, managedAgentWallet_1.ensureManagedAgentWalletFunding)({
39
+ balanceService,
40
+ fundingService,
41
+ minimumSol: amountLamports / web3_js_1.LAMPORTS_PER_SOL + 0.05,
42
+ publicKey: walletManager.publicKey
43
+ });
44
+ const prepared = await (0, liveExecutors_1.prepareLiveMarinade)({
45
+ intent: {
46
+ action: "stake",
47
+ amountLamports,
48
+ marketId: protocols_1.PROTOCOL_PRESETS.marinade.defaultMarketId,
49
+ memo: `LIVE:MARINADE:stake:${amountLamports}`,
50
+ protocol: "marinade",
51
+ slippageBps: 25
52
+ },
53
+ logger: (message) => console.log(`[marinade-live] ${message}`),
54
+ walletManager
55
+ });
56
+ if (!prepared) {
57
+ throw new Error("Marinade live execution was not prepared. Check ENABLE_LIVE_MARINADE and your RPC cluster.");
58
+ }
59
+ const policyEngine = new policy_1.PolicyEngine((0, agentPolicies_1.createDefaultPolicyConfig)({
60
+ agentId: managed.agent.name,
61
+ allowOpaqueProgramIds: prepared.policyConfigPatch?.rules?.allowOpaqueProgramIds,
62
+ approvalMode: "sandbox",
63
+ extraAllowedProgramIds: prepared.policyConfigPatch?.rules?.allowedProgramIds
64
+ }));
65
+ const sandboxExecutor = new policy_1.SandboxExecutor(policyEngine, transactionService, "sandbox");
66
+ console.log("PRKT Marinade live demo");
67
+ console.log(`RPC: ${rpcUrl}`);
68
+ (0, managedAgentWallet_1.logManagedAgentWallet)(managed);
69
+ console.log(`Amount (lamports): ${amountLamports}`);
70
+ const execution = await sandboxExecutor.executePreparedTransaction({
71
+ confirmationStrategy: prepared.confirmationStrategy,
72
+ inspectionContext: prepared.inspectionContext,
73
+ transaction: prepared.transaction
74
+ });
75
+ if (!execution.signature) {
76
+ throw new Error(`Guarded Marinade execution blocked: ${execution.inspection.reasons.join("; ") || "unknown reason"}`);
77
+ }
78
+ if (prepared.verifyExecution) {
79
+ await prepared.verifyExecution(execution.signature);
80
+ }
81
+ console.log(`Transaction signature: ${execution.signature}`);
82
+ }
83
+ function parseAmountLamports(rawValue) {
84
+ if (!rawValue) {
85
+ return Math.round(0.15 * web3_js_1.LAMPORTS_PER_SOL);
86
+ }
87
+ const sol = Number(rawValue);
88
+ if (!Number.isFinite(sol) || sol <= 0) {
89
+ throw new Error(`Invalid SOL amount '${rawValue}'. Provide a positive decimal SOL amount.`);
90
+ }
91
+ return Math.round(sol * web3_js_1.LAMPORTS_PER_SOL);
92
+ }
93
+ main().catch((error) => {
94
+ const message = error instanceof Error ? error.message : "Unknown error";
95
+ console.error(`Marinade live demo failed: ${message}`);
96
+ process.exitCode = 1;
97
+ });
@@ -0,0 +1,208 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const common_sdk_1 = require("@orca-so/common-sdk");
7
+ const whirlpools_sdk_1 = require("@orca-so/whirlpools-sdk");
8
+ const spl_token_1 = require("@solana/spl-token");
9
+ const web3_js_1 = require("@solana/web3.js");
10
+ const decimal_js_1 = __importDefault(require("decimal.js"));
11
+ const agentPolicies_1 = require("../config/agentPolicies");
12
+ const env_1 = require("../config/env");
13
+ const BalanceService_1 = require("../core/balances/BalanceService");
14
+ const DevnetFundingService_1 = require("../core/funding/DevnetFundingService");
15
+ const RpcClient_1 = require("../core/rpc/RpcClient");
16
+ const TokenService_1 = require("../core/tokens/TokenService");
17
+ const TransactionService_1 = require("../core/transactions/TransactionService");
18
+ const policy_1 = require("../policy");
19
+ const managedAgentWallet_1 = require("./managedAgentWallet");
20
+ const mode_1 = require("./mode");
21
+ const DEFAULT_AGENT_NAME = "orca-live-devnet";
22
+ const DEFAULT_LP_SOL = 0.05;
23
+ const MINIMUM_SOL_BALANCE = 0.25;
24
+ const ORCA_DEVNET_PROGRAM_ID = new web3_js_1.PublicKey("whirLbMiicVdio4qvUfM5KAg6Ct8VwpYzGff3uctyCc");
25
+ const ORCA_DEVNET_CONFIG = new web3_js_1.PublicKey("FcrweFY1G9HJAHG5inkGB6pKg1HZ6x9UC2WioAfWrGkR");
26
+ const ORCA_DEVNET_CONFIG_EXTENSION = new web3_js_1.PublicKey("475EJ7JqnRpVLoFVzp2ruEYvWWMCf6Z8KMWRujtXXNSU");
27
+ const ORCA_DEVNET_USDC_MINT = new web3_js_1.PublicKey("BRjpCHtyQLNCo8gqRUr8jtdAj5AjPYQaoqbvcZiHok1k");
28
+ const ORCA_DEVNET_TICK_SPACING = 64;
29
+ async function main() {
30
+ const depositAmountSol = parseAmountSol(process.argv[2]);
31
+ (0, mode_1.printDemoMode)("LIVE", `Orca Whirlpool LP demo on devnet (${depositAmountSol.toFixed(4)} SOL one-sided deposit)`);
32
+ const rpcUrl = (0, env_1.getRpcUrl)();
33
+ const cluster = (0, env_1.detectClusterFromRpcUrl)(rpcUrl);
34
+ if (cluster !== "devnet") {
35
+ throw new Error(`Orca LP demo requires devnet. Current RPC cluster is ${cluster} (${rpcUrl}).`);
36
+ }
37
+ const rpcClient = new RpcClient_1.RpcClient(rpcUrl, "confirmed");
38
+ const tokenService = new TokenService_1.TokenService(rpcClient);
39
+ const balanceService = new BalanceService_1.BalanceService(rpcClient, tokenService);
40
+ const transactionService = new TransactionService_1.TransactionService(rpcClient);
41
+ const fundingService = new DevnetFundingService_1.DevnetFundingService(rpcClient, transactionService);
42
+ const managed = (0, managedAgentWallet_1.resolveManagedAgentWallet)({
43
+ agentName: (0, managedAgentWallet_1.getManagedAgentName)({
44
+ defaultAgentName: DEFAULT_AGENT_NAME,
45
+ env: process.env
46
+ }),
47
+ ownerId: (0, managedAgentWallet_1.getManagedOwnerId)(process.env)
48
+ });
49
+ const walletManager = managed.walletManager;
50
+ console.log("PRKT Orca devnet LP demo");
51
+ console.log(`RPC: ${rpcUrl}`);
52
+ (0, managedAgentWallet_1.logManagedAgentWallet)(managed);
53
+ console.log(`Orca program: ${ORCA_DEVNET_PROGRAM_ID.toBase58()}`);
54
+ console.log(`Orca config: ${ORCA_DEVNET_CONFIG.toBase58()}`);
55
+ console.log(`Orca config extension: ${ORCA_DEVNET_CONFIG_EXTENSION.toBase58()}`);
56
+ await (0, managedAgentWallet_1.ensureManagedAgentWalletFunding)({
57
+ balanceService,
58
+ fundingService,
59
+ minimumSol: MINIMUM_SOL_BALANCE,
60
+ publicKey: walletManager.publicKey
61
+ });
62
+ const orcaWallet = new common_sdk_1.ReadOnlyWallet(walletManager.publicKey);
63
+ const whirlpoolContext = whirlpools_sdk_1.WhirlpoolContext.from(rpcClient.connection, orcaWallet);
64
+ const whirlpoolClient = (0, whirlpools_sdk_1.buildWhirlpoolClient)(whirlpoolContext);
65
+ const whirlpool = await loadSupportedDevnetPool(whirlpoolClient);
66
+ const poolData = whirlpool.getData();
67
+ const poolAddress = whirlpool.getAddress();
68
+ const tokenA = whirlpool.getTokenAInfo();
69
+ const tokenB = whirlpool.getTokenBInfo();
70
+ if (whirlpools_sdk_1.TickUtil.isFullRangeOnly(poolData.tickSpacing)) {
71
+ throw new Error(`Configured Orca pool ${poolAddress.toBase58()} is full-range only (tick spacing ${poolData.tickSpacing}).`);
72
+ }
73
+ const { sideDescription, tickLowerIndex, tickUpperIndex } = deriveOneSidedPositionRange({
74
+ currentTickIndex: poolData.tickCurrentIndex,
75
+ nativeIsTokenA: tokenA.mint.equals(spl_token_1.NATIVE_MINT),
76
+ tickSpacing: poolData.tickSpacing
77
+ });
78
+ const tokenExtensionContext = await whirlpools_sdk_1.TokenExtensionUtil.buildTokenExtensionContextForPool(whirlpoolClient.getFetcher(), tokenA.mint, tokenB.mint);
79
+ const quote = (0, whirlpools_sdk_1.increaseLiquidityQuoteByInputTokenUsingPriceDeviation)(spl_token_1.NATIVE_MINT, new decimal_js_1.default(depositAmountSol.toString()), tickLowerIndex, tickUpperIndex, common_sdk_1.Percentage.fromFraction(1, 100), whirlpool, tokenExtensionContext);
80
+ if (quote.liquidityAmount.isZero()) {
81
+ throw new Error(`Orca quote returned zero liquidity for pool ${poolAddress.toBase58()}. Try a different amount or RPC.`);
82
+ }
83
+ const policyEngine = new policy_1.PolicyEngine((0, agentPolicies_1.createDefaultPolicyConfig)({
84
+ agentId: managed.agent.name,
85
+ allowOpaqueProgramIds: [ORCA_DEVNET_PROGRAM_ID.toBase58()],
86
+ allowedCloseAccountDestinations: [walletManager.publicKey.toBase58()],
87
+ approvalMode: "sandbox",
88
+ extraAllowedProgramIds: [ORCA_DEVNET_PROGRAM_ID.toBase58()]
89
+ }));
90
+ const sandboxExecutor = new policy_1.SandboxExecutor(policyEngine, transactionService, "sandbox");
91
+ console.log(`Pool: ${poolAddress.toBase58()}`);
92
+ console.log(`Pool tick spacing: ${poolData.tickSpacing}`);
93
+ console.log(`Pool token A: ${tokenA.mint.toBase58()}`);
94
+ console.log(`Pool token B: ${tokenB.mint.toBase58()}`);
95
+ console.log(`Current tick: ${poolData.tickCurrentIndex}`);
96
+ console.log(`Range: [${tickLowerIndex}, ${tickUpperIndex}] (${sideDescription})`);
97
+ console.log(`Estimated token max A: ${quote.tokenMaxA.toString()}`);
98
+ console.log(`Estimated token max B: ${quote.tokenMaxB.toString()}`);
99
+ const initTickArrays = await whirlpool.initTickArrayForTicks([tickLowerIndex, tickUpperIndex], walletManager.publicKey);
100
+ if (initTickArrays && !initTickArrays.isEmpty()) {
101
+ const tickArraySignature = await executeBuilder({
102
+ builder: initTickArrays,
103
+ label: "initialize Orca tick arrays",
104
+ sandboxExecutor,
105
+ walletManager
106
+ });
107
+ console.log(`Tick array init signature: ${tickArraySignature}`);
108
+ }
109
+ const { positionMint, tx } = await whirlpool.openPosition(tickLowerIndex, tickUpperIndex, quote, walletManager.publicKey, walletManager.publicKey);
110
+ const lpSignature = await executeBuilder({
111
+ builder: tx,
112
+ label: "open Orca position",
113
+ sandboxExecutor,
114
+ walletManager
115
+ });
116
+ const positionTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(positionMint, walletManager.publicKey);
117
+ const positionTokenBalance = await readPositionTokenBalance(positionTokenAccount, rpcClient);
118
+ if (positionTokenBalance !== 1n) {
119
+ throw new Error(`Orca position verification failed: expected 1 position token, got ${positionTokenBalance.toString()}.`);
120
+ }
121
+ const solAfter = await balanceService.getSolBalance(walletManager.publicKey);
122
+ console.log(`Position mint: ${positionMint.toBase58()}`);
123
+ console.log(`Position token account: ${positionTokenAccount.toBase58()}`);
124
+ console.log(`Transaction signature: ${lpSignature}`);
125
+ console.log(`SOL after execution: ${solAfter.toFixed(4)}`);
126
+ }
127
+ async function loadSupportedDevnetPool(whirlpoolClient) {
128
+ const candidates = [
129
+ whirlpools_sdk_1.PDAUtil.getWhirlpool(ORCA_DEVNET_PROGRAM_ID, ORCA_DEVNET_CONFIG, spl_token_1.NATIVE_MINT, ORCA_DEVNET_USDC_MINT, ORCA_DEVNET_TICK_SPACING).publicKey,
130
+ whirlpools_sdk_1.PDAUtil.getWhirlpool(ORCA_DEVNET_PROGRAM_ID, ORCA_DEVNET_CONFIG, ORCA_DEVNET_USDC_MINT, spl_token_1.NATIVE_MINT, ORCA_DEVNET_TICK_SPACING).publicKey
131
+ ];
132
+ for (const address of candidates) {
133
+ try {
134
+ return await whirlpoolClient.getPool(address);
135
+ }
136
+ catch {
137
+ continue;
138
+ }
139
+ }
140
+ throw new Error(`Could not load the public Orca devnet SOL/devUSDC concentrated pool (tick spacing ${ORCA_DEVNET_TICK_SPACING}).`);
141
+ }
142
+ function deriveOneSidedPositionRange(input) {
143
+ const [minTick, maxTick] = whirlpools_sdk_1.TickUtil.getFullRangeTickIndex(input.tickSpacing);
144
+ const currentTickIndex = whirlpools_sdk_1.TickUtil.getInitializableTickIndex(input.currentTickIndex, input.tickSpacing);
145
+ const width = input.tickSpacing * 128;
146
+ const gap = input.tickSpacing * 64;
147
+ if (input.nativeIsTokenA) {
148
+ const tickLowerIndex = Math.min(Math.max(currentTickIndex + gap, minTick), maxTick - width);
149
+ return {
150
+ sideDescription: "one-sided SOL above current price",
151
+ tickLowerIndex,
152
+ tickUpperIndex: tickLowerIndex + width
153
+ };
154
+ }
155
+ const tickUpperIndex = Math.max(Math.min(currentTickIndex - gap, maxTick), minTick + width);
156
+ return {
157
+ sideDescription: "one-sided SOL below current price",
158
+ tickLowerIndex: tickUpperIndex - width,
159
+ tickUpperIndex
160
+ };
161
+ }
162
+ async function executeBuilder(input) {
163
+ const payload = await input.builder.build({
164
+ maxSupportedTransactionVersion: 0
165
+ });
166
+ if (!(payload.transaction instanceof web3_js_1.VersionedTransaction)) {
167
+ throw new Error(`${input.label} did not build a versioned transaction.`);
168
+ }
169
+ if (payload.signers.length > 0) {
170
+ payload.transaction.sign(payload.signers);
171
+ }
172
+ const signedTransaction = await input.walletManager.signTransaction(payload.transaction);
173
+ const execution = await input.sandboxExecutor.executePreparedTransaction({
174
+ confirmationStrategy: {
175
+ blockhash: payload.recentBlockhash.blockhash,
176
+ lastValidBlockHeight: payload.recentBlockhash.lastValidBlockHeight,
177
+ signature: ""
178
+ },
179
+ transaction: signedTransaction
180
+ });
181
+ if (!execution.signature) {
182
+ throw new Error(`${input.label} was blocked: ${execution.inspection.reasons.join("; ") || "unknown reason"}`);
183
+ }
184
+ return execution.signature;
185
+ }
186
+ async function readPositionTokenBalance(tokenAccount, rpcClient) {
187
+ const accountInfo = await rpcClient.getAccountInfo(tokenAccount, "confirmed");
188
+ if (!accountInfo) {
189
+ return 0n;
190
+ }
191
+ const balance = await rpcClient.getTokenAccountBalance(tokenAccount, "confirmed");
192
+ return BigInt(balance.value.amount);
193
+ }
194
+ function parseAmountSol(rawValue) {
195
+ if (!rawValue) {
196
+ return DEFAULT_LP_SOL;
197
+ }
198
+ const parsed = Number(rawValue);
199
+ if (!Number.isFinite(parsed) || parsed <= 0) {
200
+ throw new Error(`Invalid SOL amount '${rawValue}'. Provide a positive decimal SOL amount.`);
201
+ }
202
+ return parsed;
203
+ }
204
+ main().catch((error) => {
205
+ const message = error instanceof Error ? error.message : "Unknown error";
206
+ console.error(`Orca LP devnet demo failed: ${message}`);
207
+ process.exitCode = 1;
208
+ });
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const web3_js_1 = require("@solana/web3.js");
4
+ const agentPolicies_1 = require("../config/agentPolicies");
5
+ const env_1 = require("../config/env");
6
+ const RpcClient_1 = require("../core/rpc/RpcClient");
7
+ const PostTransactionVerifier_1 = require("../core/transactions/PostTransactionVerifier");
8
+ const TransactionService_1 = require("../core/transactions/TransactionService");
9
+ const TokenService_1 = require("../core/tokens/TokenService");
10
+ const RaydiumAdapter_1 = require("../defi/adapters/RaydiumAdapter");
11
+ const raydiumDevnetConfig_1 = require("../defi/lp/raydiumDevnetConfig");
12
+ const policy_1 = require("../policy");
13
+ const WalletManager_1 = require("../wallet/WalletManager");
14
+ const mode_1 = require("./mode");
15
+ async function main() {
16
+ (0, mode_1.printDemoMode)("LIVE", "Real Raydium add-liquidity transaction on configured cluster");
17
+ const walletManager = WalletManager_1.WalletManager.loadOrGenerate();
18
+ const connection = new web3_js_1.Connection((0, env_1.getRpcUrl)(), "confirmed");
19
+ const rpcClient = new RpcClient_1.RpcClient((0, env_1.getRpcUrl)(), "confirmed");
20
+ const tokenService = new TokenService_1.TokenService(rpcClient);
21
+ const verifier = new PostTransactionVerifier_1.PostTransactionVerifier(rpcClient, tokenService);
22
+ const transactionService = new TransactionService_1.TransactionService(rpcClient);
23
+ const config = (0, raydiumDevnetConfig_1.loadRaydiumLpDevnetConfig)();
24
+ const adapter = new RaydiumAdapter_1.RaydiumAdapter();
25
+ const requiredAccounts = [
26
+ config.poolConfig.poolId,
27
+ config.poolConfig.authority,
28
+ config.poolConfig.baseVault,
29
+ config.poolConfig.quoteVault,
30
+ config.poolConfig.openOrders,
31
+ config.poolConfig.targetOrders,
32
+ config.poolConfig.marketId,
33
+ config.poolConfig.marketEventQueue,
34
+ config.poolConfig.lpMint,
35
+ config.userTokenAccounts.baseTokenAccount,
36
+ config.userTokenAccounts.quoteTokenAccount,
37
+ config.userTokenAccounts.lpTokenAccount
38
+ ];
39
+ const accountInfos = await connection.getMultipleAccountsInfo(requiredAccounts.map((key) => new web3_js_1.PublicKey(key)), "confirmed");
40
+ const missingAccounts = requiredAccounts.filter((_, index) => accountInfos[index] === null);
41
+ if (missingAccounts.length > 0) {
42
+ throw new Error(`The following configured accounts do not exist on the selected cluster: ${missingAccounts.join(", ")}`);
43
+ }
44
+ const latestBlockhash = await connection.getLatestBlockhash("confirmed");
45
+ const lpBalanceSnapshot = await verifier.snapshotSplTokenAccount({
46
+ label: "Raydium LP token balance",
47
+ mint: new web3_js_1.PublicKey(config.poolConfig.lpMint),
48
+ tokenAccount: new web3_js_1.PublicKey(config.userTokenAccounts.lpTokenAccount)
49
+ });
50
+ const transaction = await adapter.buildAddLiquidityTransactionDraft({
51
+ baseAmountIn: config.amounts.baseAmountIn,
52
+ otherAmountMin: config.amounts.otherAmountMin,
53
+ owner: walletManager,
54
+ poolConfig: config.poolConfig,
55
+ quoteAmountIn: config.amounts.quoteAmountIn,
56
+ recentBlockhash: latestBlockhash.blockhash,
57
+ userTokenAccounts: config.userTokenAccounts
58
+ });
59
+ const policyEngine = new policy_1.PolicyEngine((0, agentPolicies_1.createDefaultPolicyConfig)({
60
+ allowOpaqueProgramIds: [config.poolConfig.programId],
61
+ agentId: "raydium-live-devnet-script",
62
+ approvalMode: "sandbox",
63
+ extraAllowedProgramIds: [config.poolConfig.programId]
64
+ }));
65
+ const sandboxExecutor = new policy_1.SandboxExecutor(policyEngine, transactionService, "sandbox");
66
+ console.log("PRKT Raydium devnet LP demo");
67
+ console.log(`Wallet: ${walletManager.publicKey.toBase58()}`);
68
+ console.log(`Pool: ${config.poolConfig.poolId}`);
69
+ console.log(`Base amount in: ${config.amounts.baseAmountIn}`);
70
+ console.log(`Quote amount in: ${config.amounts.quoteAmountIn}`);
71
+ const execution = await sandboxExecutor.executePreparedTransaction({
72
+ confirmationStrategy: {
73
+ blockhash: latestBlockhash.blockhash,
74
+ lastValidBlockHeight: latestBlockhash.lastValidBlockHeight,
75
+ signature: ""
76
+ },
77
+ transaction
78
+ });
79
+ if (!execution.signature) {
80
+ throw new Error(`Guarded Raydium execution blocked: ${execution.inspection.reasons.join("; ") || "unknown reason"}`);
81
+ }
82
+ const [verification] = await verifier.assertBalanceChanges([
83
+ {
84
+ minIncreaseRaw: 1n,
85
+ snapshot: lpBalanceSnapshot
86
+ }
87
+ ]);
88
+ console.log(`Transaction signature: ${execution.signature}`);
89
+ console.log(`Verification: ${verification.label} ${verification.beforeUi} -> ${verification.afterUi} (${verification.deltaUi})`);
90
+ }
91
+ main().catch((error) => {
92
+ const message = error instanceof Error ? error.message : "Unknown error";
93
+ console.error(`Raydium LP devnet demo failed: ${message}`);
94
+ process.exitCode = 1;
95
+ });
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const releaseReadiness_1 = require("./releaseReadiness");
4
+ function main() {
5
+ console.log("PRKT release readiness check");
6
+ const checks = (0, releaseReadiness_1.runReadinessChecks)();
7
+ let failures = 0;
8
+ for (const check of checks) {
9
+ const marker = check.ok ? "PASS" : "FAIL";
10
+ console.log(`[${marker}] ${check.title} -> ${check.detail}`);
11
+ if (!check.ok) {
12
+ failures += 1;
13
+ }
14
+ }
15
+ if (failures > 0) {
16
+ console.error(`Release readiness failed with ${failures} failing check(s).`);
17
+ process.exitCode = 1;
18
+ return;
19
+ }
20
+ console.log("Release readiness passed.");
21
+ }
22
+ main();
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const web3_js_1 = require("@solana/web3.js");
4
+ const DeFiCoordinator_1 = require("../defi/DeFiCoordinator");
5
+ const managedAgentWallet_1 = require("./managedAgentWallet");
6
+ const shared_1 = require("./shared");
7
+ const mode_1 = require("./mode");
8
+ const DEFAULT_AGENT_NAME = "stake-strategy";
9
+ async function main() {
10
+ (0, mode_1.printDemoMode)("SIMULATED", "Protocol intent only (memo execution), not live Marinade instructions");
11
+ const managed = (0, managedAgentWallet_1.resolveManagedAgentWallet)({
12
+ agentName: (0, managedAgentWallet_1.getManagedAgentName)({ defaultAgentName: DEFAULT_AGENT_NAME, env: process.env }),
13
+ ownerId: (0, managedAgentWallet_1.getManagedOwnerId)(process.env)
14
+ });
15
+ const coordinator = new DeFiCoordinator_1.DeFiCoordinator(managed.walletManager, (0, shared_1.createKoraSigner)(), (0, shared_1.createRuntimeLogger)("stake"));
16
+ (0, managedAgentWallet_1.logManagedAgentWallet)(managed);
17
+ const result = await coordinator.runStakingStrategy({
18
+ idleSolLamports: Math.round(0.8 * web3_js_1.LAMPORTS_PER_SOL)
19
+ });
20
+ console.log("Staking strategy complete.");
21
+ if (!result) {
22
+ console.log("No staking 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(`Staking strategy failed: ${message}`);
32
+ process.exitCode = 1;
33
+ });