@prktsol/prkt 1.0.0 → 1.0.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.
Files changed (177) hide show
  1. package/.env.devnet.all-protocols.example +5 -0
  2. package/.env.example +7 -0
  3. package/CLI.md +24 -0
  4. package/CLI_QUICKSTART.md +16 -0
  5. package/README.md +59 -12
  6. package/dist/agent/AgentManager.d.ts +61 -0
  7. package/dist/agent/AgentRuntime.d.ts +28 -0
  8. package/dist/agent/DecisionEngine.d.ts +51 -0
  9. package/dist/agent/MockPriceFeed.d.ts +10 -0
  10. package/dist/agent/intents/types.d.ts +35 -0
  11. package/dist/agent/new-index.d.ts +9 -0
  12. package/dist/agent/policyFactory.d.ts +2 -0
  13. package/dist/agent/registry/AgentRegistry.d.ts +11 -0
  14. package/dist/agent/runner/AgentRunner.d.ts +51 -0
  15. package/dist/agent/runner/AgentRunner.js +59 -2
  16. package/dist/agent/strategies/MemoHeartbeatStrategy.d.ts +6 -0
  17. package/dist/agent/strategies/SimpleScriptedTransferStrategy.d.ts +12 -0
  18. package/dist/agent/strategies/TokenRebalancerStrategy.d.ts +13 -0
  19. package/dist/agent/strategies/TreasuryDistributorStrategy.d.ts +12 -0
  20. package/dist/agent/strategies/UniversalDeFiStrategy.d.ts +22 -0
  21. package/dist/agent/types/AgentContext.d.ts +28 -0
  22. package/dist/anchoring/SessionAnchor.d.ts +42 -0
  23. package/dist/anchoring/SessionAnchor.js +161 -0
  24. package/dist/cli/index.d.ts +2 -0
  25. package/dist/cli/index.js +157 -16
  26. package/dist/cli/services/activityStore.d.ts +8 -0
  27. package/dist/cli/services/agentRegistry.d.ts +20 -0
  28. package/dist/cli/services/agentRuntime.d.ts +6 -0
  29. package/dist/cli/services/storagePaths.d.ts +8 -0
  30. package/dist/cli/services/strategyFactory.d.ts +5 -0
  31. package/dist/cli/services/walletCrypto.d.ts +12 -0
  32. package/dist/cli/services/walletRegistry.d.ts +26 -0
  33. package/dist/cli/types.d.ts +68 -0
  34. package/dist/cli/utils/completion.d.ts +4 -0
  35. package/dist/cli/utils/output.d.ts +5 -0
  36. package/dist/cli/utils/output.js +4 -1
  37. package/dist/compression/AuditLogManager.d.ts +9 -0
  38. package/dist/compression/AuditLogManager.js +86 -0
  39. package/dist/compression/PolicyAccountManager.d.ts +11 -0
  40. package/dist/compression/PolicyAccountManager.js +113 -0
  41. package/dist/compression/types.d.ts +20 -0
  42. package/dist/compression/types.js +2 -0
  43. package/dist/config/PRKTConfig.d.ts +17 -0
  44. package/dist/config/PRKTConfig.js +19 -0
  45. package/dist/config/agentPolicies.d.ts +14 -0
  46. package/dist/config/env.d.ts +39 -0
  47. package/dist/config/env.js +37 -0
  48. package/dist/config/policyPresets.d.ts +22 -0
  49. package/dist/core/balances/BalanceService.d.ts +14 -0
  50. package/dist/core/funding/DevnetFundingService.d.ts +38 -0
  51. package/dist/core/funding/DevnetFundingService.js +73 -6
  52. package/dist/core/idempotency/ExecutionIdempotencyGuard.d.ts +39 -0
  53. package/dist/core/index.d.ts +8 -0
  54. package/dist/core/rpc/RpcClient.d.ts +21 -0
  55. package/dist/core/rpc/RpcClient.js +35 -0
  56. package/dist/core/rpc/RpcFailoverClient.d.ts +42 -0
  57. package/dist/core/tokens/TokenService.d.ts +40 -0
  58. package/dist/core/transactions/PostTransactionVerifier.d.ts +47 -0
  59. package/dist/core/transactions/TransactionService.d.ts +46 -0
  60. package/dist/core/types/services.d.ts +27 -0
  61. package/dist/core/wallet/WalletManager.d.ts +21 -0
  62. package/dist/defi/DeFiCoordinator.d.ts +24 -0
  63. package/dist/defi/DeFiExecutor.d.ts +15 -0
  64. package/dist/defi/DeFiPolicyGuard.d.ts +7 -0
  65. package/dist/defi/adapters/JupiterAdapter.d.ts +5 -0
  66. package/dist/defi/adapters/KaminoAdapter.d.ts +6 -0
  67. package/dist/defi/adapters/MarinadeAdapter.d.ts +5 -0
  68. package/dist/defi/adapters/RaydiumAdapter.d.ts +20 -0
  69. package/dist/defi/kamino/kaminoInstructionCompat.d.ts +3 -0
  70. package/dist/defi/kamino/kaminoLiveConfig.d.ts +14 -0
  71. package/dist/defi/kamino/loadKaminoMarketWithFallback.d.ts +11 -0
  72. package/dist/defi/lp/LpInstructionBuilder.d.ts +15 -0
  73. package/dist/defi/lp/RaydiumLpInstructionBuilder.d.ts +28 -0
  74. package/dist/defi/lp/raydiumDevnetConfig.d.ts +11 -0
  75. package/dist/defi/protocols.d.ts +8 -0
  76. package/dist/defi/types.d.ts +65 -0
  77. package/dist/defi/universal/UniversalDeFiOrchestrator.d.ts +24 -0
  78. package/dist/defi/universal/UniversalDeFiOrchestrator.js +157 -0
  79. package/dist/defi/universal/adapters.d.ts +25 -0
  80. package/dist/defi/universal/index.d.ts +2 -0
  81. package/dist/defi/universal/liveExecutors.d.ts +23 -0
  82. package/dist/defi/universal/types.d.ts +45 -0
  83. package/dist/demo/scenarios/multiAgentDevnetScenario.d.ts +5 -0
  84. package/dist/demo/scripts/runMultiAgentDevnetDemo.d.ts +1 -0
  85. package/dist/dex/JupiterSwapClient.d.ts +28 -0
  86. package/dist/dex/SwapExecutor.d.ts +36 -0
  87. package/dist/errors/PRKTError.d.ts +15 -0
  88. package/dist/errors/PRKTError.js +38 -0
  89. package/dist/evm/EvmAdapter.d.ts +45 -0
  90. package/dist/evm/EvmAdapter.js +2 -0
  91. package/dist/evm/NeonWalletBridge.d.ts +9 -0
  92. package/dist/evm/NeonWalletBridge.js +40 -0
  93. package/dist/evm/adapters/AaveAdapter.d.ts +17 -0
  94. package/dist/evm/adapters/AaveAdapter.js +100 -0
  95. package/dist/evm/adapters/UniswapV3Adapter.d.ts +18 -0
  96. package/dist/evm/adapters/UniswapV3Adapter.js +146 -0
  97. package/dist/index.d.ts +15 -0
  98. package/dist/index.js +35 -20
  99. package/dist/kora/KoraRpcClient.d.ts +14 -0
  100. package/dist/kora/KoraSigner.d.ts +22 -0
  101. package/dist/kora/KoraSigner.js +33 -10
  102. package/dist/kora/gaslessDemo.d.ts +9 -0
  103. package/dist/onchain/index.d.ts +2 -0
  104. package/dist/onchain/index.js +17 -0
  105. package/dist/onchain/policyGuardProgram.d.ts +86 -0
  106. package/dist/onchain/policyGuardProgram.js +248 -0
  107. package/dist/policy/PolicyGuard.d.ts +13 -0
  108. package/dist/policy/emergencyLock.d.ts +4 -0
  109. package/dist/policy/engine/PolicyEngine.d.ts +28 -0
  110. package/dist/policy/engine/PolicyEngine.js +109 -1
  111. package/dist/policy/errors.d.ts +3 -0
  112. package/dist/policy/index.d.ts +3 -0
  113. package/dist/policy/sandbox/SandboxExecutor.d.ts +44 -0
  114. package/dist/policy/sandbox/SandboxExecutor.js +245 -3
  115. package/dist/policy/types/policy.d.ts +55 -0
  116. package/dist/scripts/devnetFunding.d.ts +9 -0
  117. package/dist/scripts/devnetFunding.js +0 -1
  118. package/dist/scripts/devnetWalletPreflight.d.ts +8 -0
  119. package/dist/scripts/localnetCheck.d.ts +1 -0
  120. package/dist/scripts/managedAgentWallet.d.ts +34 -0
  121. package/dist/scripts/mode.d.ts +2 -0
  122. package/dist/scripts/releaseReadiness.d.ts +9 -0
  123. package/dist/scripts/runAgentUniversalDeFi.d.ts +1 -0
  124. package/dist/scripts/runAutonomousAgentWalletDevnet.d.ts +1 -0
  125. package/dist/scripts/runAutonomousAgentWalletDevnet.js +1 -1
  126. package/dist/scripts/runAutonomousPortfolioDevnet.d.ts +1 -0
  127. package/dist/scripts/runAutonomousPortfolioDevnet.js +1 -1
  128. package/dist/scripts/runBorrowStrategy.d.ts +1 -0
  129. package/dist/scripts/runDeFiSuite.d.ts +1 -0
  130. package/dist/scripts/runDemoRehearsal.d.ts +1 -0
  131. package/dist/scripts/runDemoRehearsal.js +39 -10
  132. package/dist/scripts/runDevnetFeatureMatrix.d.ts +43 -0
  133. package/dist/scripts/runDevnetFeatureMatrix.js +787 -0
  134. package/dist/scripts/runDevnetWalletDemo.d.ts +1 -0
  135. package/dist/scripts/runGaslessMemo.d.ts +1 -0
  136. package/dist/scripts/runGaslessMemo.js +9 -1
  137. package/dist/scripts/runGaslessWalletDemo.d.ts +1 -0
  138. package/dist/scripts/runGaslessWalletDemo.js +9 -1
  139. package/dist/scripts/runKaminoDevnet.d.ts +1 -0
  140. package/dist/scripts/runKaminoDevnet.js +82 -42
  141. package/dist/scripts/runLpStrategy.d.ts +1 -0
  142. package/dist/scripts/runMarinadeDevnet.d.ts +1 -0
  143. package/dist/scripts/runOnchainPolicyGuardDevnet.d.ts +1 -0
  144. package/dist/scripts/runOnchainPolicyGuardDevnet.js +113 -0
  145. package/dist/scripts/runOrcaLpDevnet.d.ts +1 -0
  146. package/dist/scripts/runRaydiumLpDevnet.d.ts +1 -0
  147. package/dist/scripts/runReleaseReadiness.d.ts +1 -0
  148. package/dist/scripts/runStakeStrategy.d.ts +1 -0
  149. package/dist/scripts/runStatus.d.ts +1 -0
  150. package/dist/scripts/runStatus.js +22 -0
  151. package/dist/scripts/runStressTest.d.ts +1 -0
  152. package/dist/scripts/runTradeLoop.d.ts +1 -0
  153. package/dist/scripts/runUniversalDeFiDemo.d.ts +1 -0
  154. package/dist/scripts/runYieldStrategy.d.ts +1 -0
  155. package/dist/scripts/runtimeFactory.d.ts +8 -0
  156. package/dist/scripts/shared.d.ts +3 -0
  157. package/dist/scripts/shared.js +1 -0
  158. package/dist/scripts/simulateAttack.d.ts +1 -0
  159. package/dist/scripts/simulateSwarm.d.ts +1 -0
  160. package/dist/simulation/attack.d.ts +8 -0
  161. package/dist/solana/memoLedger.d.ts +33 -0
  162. package/dist/solana/memoLedger.js +205 -0
  163. package/dist/solana/programs.d.ts +6 -0
  164. package/dist/spl/TokenWallet.d.ts +18 -0
  165. package/dist/types/policy.d.ts +23 -0
  166. package/dist/wallet/WalletManager.d.ts +1 -0
  167. package/dist/zk/PolicyCircuit.d.ts +48 -0
  168. package/dist/zk/PolicyCircuit.js +171 -0
  169. package/dist/zk/ProofAnchor.d.ts +33 -0
  170. package/dist/zk/ProofAnchor.js +109 -0
  171. package/dist/zkCompression/CompressedCommitmentAnchor.d.ts +31 -0
  172. package/dist/zkCompression/CompressedCommitmentAnchor.js +90 -0
  173. package/dist/zkCompression/CompressedDataAccount.d.ts +45 -0
  174. package/dist/zkCompression/CompressedDataAccount.js +349 -0
  175. package/dist/zkCompression/LocalPayloadRegistry.d.ts +23 -0
  176. package/dist/zkCompression/LocalPayloadRegistry.js +53 -0
  177. package/package.json +20 -4
@@ -6,6 +6,12 @@ const env_1 = require("../../config/env");
6
6
  const DeFiExecutor_1 = require("../DeFiExecutor");
7
7
  const adapters_1 = require("./adapters");
8
8
  const liveExecutors_1 = require("./liveExecutors");
9
+ const PRKTConfig_1 = require("../../config/PRKTConfig");
10
+ const NeonWalletBridge_1 = require("../../evm/NeonWalletBridge");
11
+ const UniswapV3Adapter_1 = require("../../evm/adapters/UniswapV3Adapter");
12
+ const AaveAdapter_1 = require("../../evm/adapters/AaveAdapter");
13
+ const DEVNET_NEON_USDC = "0x512E48836Cd42F3eB6f50CEd9ffD81E0a7F15103";
14
+ const DEVNET_NEON_WSOL = "0xc7Fc9b46e479c5Cb42f6C458D1881e55E6B7986c";
9
15
  class UniversalDeFiOrchestrator {
10
16
  deps;
11
17
  adapters;
@@ -26,6 +32,11 @@ class UniversalDeFiOrchestrator {
26
32
  }));
27
33
  }
28
34
  async execute(request, options) {
35
+ if (PRKTConfig_1.defaultPRKTConfig.evmAdapters.enabled) {
36
+ if (request.protocol === "uniswap-v3" || request.protocol === "aave") {
37
+ return this.routeToEvm(request, options);
38
+ }
39
+ }
29
40
  const adapter = this.resolveAdapter(request);
30
41
  if (!adapter) {
31
42
  this.log(`No compatible adapter for capability=${request.capability} protocol=${request.protocol ?? "auto"}`);
@@ -122,5 +133,151 @@ class UniversalDeFiOrchestrator {
122
133
  }
123
134
  return prepared.toExecutionResult(execution.signature);
124
135
  }
136
+ async routeToEvm(request, options) {
137
+ const protocol = String(request.protocol ?? "unknown");
138
+ if (!options?.liveExecutor) {
139
+ this.log(`guarded EVM ${protocol} execution requested but no executor was provided`);
140
+ return {
141
+ capability: request.capability,
142
+ protocol: request.protocol ?? "unknown",
143
+ result: null
144
+ };
145
+ }
146
+ if (!(0, env_1.isNeonBroadcastEnabled)()) {
147
+ this.log(`EVM routing for ${protocol} skipped because NEON_BROADCAST_ENABLED is false`);
148
+ return {
149
+ capability: request.capability,
150
+ protocol: request.protocol ?? "unknown",
151
+ result: null
152
+ };
153
+ }
154
+ const neonRpcEndpoint = PRKTConfig_1.defaultPRKTConfig.evmAdapters.neonRpcEndpoint;
155
+ const bridge = new NeonWalletBridge_1.NeonWalletBridge(neonRpcEndpoint);
156
+ if (this.deps.walletManager.source === "remote") {
157
+ this.log(`EVM routing for ${protocol} requires a local Solana keypair; remote signer wallets are not supported`);
158
+ return {
159
+ capability: request.capability,
160
+ protocol: request.protocol ?? "unknown",
161
+ result: null
162
+ };
163
+ }
164
+ const solanaKeypair = this.deps.walletManager.payer;
165
+ const evmAddress = bridge.deriveEvmAddress(solanaKeypair);
166
+ let tx = null;
167
+ const params = request.params ?? {};
168
+ if (request.protocol === "uniswap-v3" && (request.capability === "SWAP" || request.capability === "trade")) {
169
+ const uniswap = new UniswapV3Adapter_1.UniswapV3Adapter(neonRpcEndpoint);
170
+ const amount = normalizeBigInt(params.amount);
171
+ if (amount === null || amount <= 0n) {
172
+ this.log("EVM uniswap-v3 routing requires params.amount > 0");
173
+ return {
174
+ capability: request.capability,
175
+ protocol: request.protocol ?? "unknown",
176
+ result: null
177
+ };
178
+ }
179
+ tx = await uniswap.swap({
180
+ amount,
181
+ from: evmAddress,
182
+ recipient: normalizeAddress(params.recipient),
183
+ slippage: normalizeNumber(params.slippage, 1),
184
+ tokenIn: normalizeAddress(params.tokenIn) ?? DEVNET_NEON_USDC,
185
+ tokenOut: normalizeAddress(params.tokenOut) ?? DEVNET_NEON_WSOL
186
+ });
187
+ }
188
+ else if (request.protocol === "aave" && (request.capability === "BORROW" || request.capability === "borrowing")) {
189
+ const aave = new AaveAdapter_1.AaveAdapter(neonRpcEndpoint);
190
+ const amount = normalizeBigInt(params.amount);
191
+ const asset = normalizeAddress(params.asset);
192
+ if (amount === null || amount <= 0n || !asset) {
193
+ this.log("EVM aave routing requires params.asset and params.amount > 0");
194
+ return {
195
+ capability: request.capability,
196
+ protocol: request.protocol ?? "unknown",
197
+ result: null
198
+ };
199
+ }
200
+ tx = await aave.borrow({
201
+ amount,
202
+ asset,
203
+ from: evmAddress,
204
+ interestRateMode: normalizeNumber(params.interestRateMode, 2),
205
+ recipient: normalizeAddress(params.recipient)
206
+ });
207
+ }
208
+ if (!tx) {
209
+ this.log(`No EVM builder available for capability=${request.capability} protocol=${protocol}`);
210
+ return {
211
+ capability: request.capability,
212
+ protocol: request.protocol ?? "unknown",
213
+ result: null
214
+ };
215
+ }
216
+ try {
217
+ const execution = await options.liveExecutor.executePreparedEvmTransaction({
218
+ address: evmAddress,
219
+ solanaKeypair,
220
+ transaction: tx,
221
+ });
222
+ if (!execution.signature) {
223
+ this.log(`EVM ${protocol} execution blocked${execution.reason ? `: ${execution.reason}` : ""}`);
224
+ return {
225
+ capability: request.capability,
226
+ protocol: request.protocol ?? "unknown",
227
+ result: null
228
+ };
229
+ }
230
+ return {
231
+ capability: request.capability,
232
+ protocol: request.protocol ?? "unknown",
233
+ result: {
234
+ action: "EVM_EXECUTION",
235
+ memo: `Executed EVM transaction for ${request.protocol}`,
236
+ mock: false,
237
+ protocol: request.protocol,
238
+ signature: execution.signature
239
+ }
240
+ };
241
+ }
242
+ catch (error) {
243
+ this.log(`EVM Sandbox execution failed: ${error}`);
244
+ return {
245
+ capability: request.capability,
246
+ protocol: request.protocol ?? "unknown",
247
+ result: null
248
+ };
249
+ }
250
+ }
125
251
  }
126
252
  exports.UniversalDeFiOrchestrator = UniversalDeFiOrchestrator;
253
+ function normalizeAddress(value) {
254
+ if (typeof value !== "string") {
255
+ return undefined;
256
+ }
257
+ const trimmed = value.trim();
258
+ return trimmed.length > 0 ? trimmed : undefined;
259
+ }
260
+ function normalizeBigInt(value) {
261
+ if (typeof value === "bigint") {
262
+ return value;
263
+ }
264
+ if (typeof value === "number" && Number.isFinite(value)) {
265
+ return BigInt(Math.trunc(value));
266
+ }
267
+ if (typeof value === "string" && value.trim().length > 0) {
268
+ return BigInt(value.trim());
269
+ }
270
+ return null;
271
+ }
272
+ function normalizeNumber(value, fallback) {
273
+ if (typeof value === "number" && Number.isFinite(value)) {
274
+ return value;
275
+ }
276
+ if (typeof value === "string" && value.trim().length > 0) {
277
+ const parsed = Number(value);
278
+ if (Number.isFinite(parsed)) {
279
+ return parsed;
280
+ }
281
+ }
282
+ return fallback;
283
+ }
@@ -0,0 +1,25 @@
1
+ import type { UniversalDeFiAdapter, UniversalDeFiRequest } from "./types";
2
+ export declare class JupiterUniversalAdapter implements UniversalDeFiAdapter {
3
+ readonly protocol: "jupiter";
4
+ readonly capabilities: readonly ["trade"];
5
+ private readonly adapter;
6
+ buildIntent(request: UniversalDeFiRequest): import("../types").DeFiIntent | null;
7
+ }
8
+ export declare class MarinadeUniversalAdapter implements UniversalDeFiAdapter {
9
+ readonly protocol: "marinade";
10
+ readonly capabilities: readonly ["staking"];
11
+ private readonly adapter;
12
+ buildIntent(request: UniversalDeFiRequest): import("../types").DeFiIntent | null;
13
+ }
14
+ export declare class RaydiumUniversalAdapter implements UniversalDeFiAdapter {
15
+ readonly protocol: "raydium";
16
+ readonly capabilities: readonly ["lp", "yield"];
17
+ private readonly adapter;
18
+ buildIntent(request: UniversalDeFiRequest): import("../types").DeFiIntent | null;
19
+ }
20
+ export declare class KaminoUniversalAdapter implements UniversalDeFiAdapter {
21
+ readonly protocol: "kamino";
22
+ readonly capabilities: readonly ["lending", "borrowing", "yield"];
23
+ private readonly adapter;
24
+ buildIntent(request: UniversalDeFiRequest): import("../types").DeFiIntent | null;
25
+ }
@@ -0,0 +1,2 @@
1
+ export { UniversalDeFiOrchestrator } from "./UniversalDeFiOrchestrator";
2
+ export type { DeFiCapability, GuardedPreparedTransactionExecutor, PolicyConfigPatch, PreparedLiveExecution, UniversalDeFiAdapter, UniversalExecutionOptions, UniversalDeFiRequest, UniversalExecutionResult } from "./types";
@@ -0,0 +1,23 @@
1
+ import type { DeFiIntent } from "../types";
2
+ import type { WalletManager } from "../../wallet/WalletManager";
3
+ import type { PreparedLiveExecution } from "./types";
4
+ export declare function prepareLiveJupiter(input: {
5
+ intent: DeFiIntent;
6
+ logger?: (message: string) => void;
7
+ walletManager: WalletManager;
8
+ }): Promise<PreparedLiveExecution | null>;
9
+ export declare function prepareLiveRaydiumLp(input: {
10
+ intent: DeFiIntent;
11
+ logger?: (message: string) => void;
12
+ walletManager: WalletManager;
13
+ }): Promise<PreparedLiveExecution | null>;
14
+ export declare function prepareLiveKamino(input: {
15
+ intent: DeFiIntent;
16
+ logger?: (message: string) => void;
17
+ walletManager: WalletManager;
18
+ }): Promise<PreparedLiveExecution | null>;
19
+ export declare function prepareLiveMarinade(input: {
20
+ intent: DeFiIntent;
21
+ logger?: (message: string) => void;
22
+ walletManager: WalletManager;
23
+ }): Promise<PreparedLiveExecution | null>;
@@ -0,0 +1,45 @@
1
+ import type { TransactionConfirmationStrategy, VersionedTransaction } from "@solana/web3.js";
2
+ import type { PolicyConfig, SandboxExecutionResult, TxInspectionContext } from "../../policy";
3
+ import type { SupportedProtocol } from "../../types/policy";
4
+ import type { DeFiExecutionResult, DeFiIntent, MarketSnapshot } from "../types";
5
+ export type DeFiCapability = "trade" | "lp" | "lending" | "borrowing" | "yield" | "staking";
6
+ export type UniversalDeFiRequest = {
7
+ capability: DeFiCapability;
8
+ protocol?: SupportedProtocol;
9
+ snapshot: MarketSnapshot;
10
+ };
11
+ export type PolicyConfigPatch = {
12
+ limits?: Partial<PolicyConfig["limits"]>;
13
+ rules?: Partial<PolicyConfig["rules"]>;
14
+ sessionExpiresAtIso8601?: string;
15
+ };
16
+ export type PreparedLiveExecution = {
17
+ confirmationStrategy?: TransactionConfirmationStrategy | string;
18
+ inspectionContext?: TxInspectionContext;
19
+ policyConfigPatch?: PolicyConfigPatch;
20
+ protocol: SupportedProtocol;
21
+ toExecutionResult(signature: string): DeFiExecutionResult;
22
+ transaction: VersionedTransaction;
23
+ verifyExecution?: (signature: string) => Promise<void>;
24
+ };
25
+ export type GuardedPreparedTransactionExecutor = {
26
+ executePreparedTransaction(input: {
27
+ confirmationStrategy?: TransactionConfirmationStrategy | string;
28
+ inspectionContext?: TxInspectionContext;
29
+ policyConfigPatch?: PolicyConfigPatch;
30
+ transaction: VersionedTransaction;
31
+ }): Promise<SandboxExecutionResult>;
32
+ };
33
+ export interface UniversalDeFiAdapter {
34
+ readonly capabilities: readonly DeFiCapability[];
35
+ readonly protocol: SupportedProtocol;
36
+ buildIntent(request: UniversalDeFiRequest): DeFiIntent | null;
37
+ }
38
+ export type UniversalExecutionOptions = {
39
+ liveExecutor?: GuardedPreparedTransactionExecutor;
40
+ };
41
+ export type UniversalExecutionResult = {
42
+ capability: DeFiCapability;
43
+ protocol: SupportedProtocol;
44
+ result: DeFiExecutionResult | null;
45
+ };
@@ -0,0 +1,5 @@
1
+ export declare function runMultiAgentDevnetScenario(): Promise<{
2
+ rpc: string;
3
+ mintAddress: string;
4
+ signatures: string[];
5
+ }>;
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,28 @@
1
+ import { PublicKey } from "@solana/web3.js";
2
+ export type JupiterQuoteRoute = {
3
+ inAmount: string;
4
+ inputMint: string;
5
+ outAmount: string;
6
+ outputMint: string;
7
+ priceImpactPct?: string;
8
+ routePlan?: unknown[];
9
+ slippageBps?: number;
10
+ };
11
+ export declare class JupiterApiError extends Error {
12
+ constructor(message: string);
13
+ }
14
+ export declare class JupiterSwapClient {
15
+ private readonly baseUrl;
16
+ private readonly fetchImpl;
17
+ constructor(baseUrl: string, fetchImpl?: typeof fetch);
18
+ getQuote(input: {
19
+ inputMint: string;
20
+ outputMint: string;
21
+ amount: bigint;
22
+ slippageBps: number;
23
+ }): Promise<JupiterQuoteRoute>;
24
+ buildSwapTransaction(input: {
25
+ quoteResponse: JupiterQuoteRoute;
26
+ userPublicKey: PublicKey;
27
+ }): Promise<string>;
28
+ }
@@ -0,0 +1,36 @@
1
+ import { VersionedTransaction } from "@solana/web3.js";
2
+ import { PolicyGuard } from "../policy/PolicyGuard";
3
+ import { KoraSigner, type GaslessExecutionResult } from "../kora/KoraSigner";
4
+ import { WalletManager } from "../wallet/WalletManager";
5
+ import { JupiterSwapClient } from "./JupiterSwapClient";
6
+ export type LiveSwapResult = {
7
+ execution: GaslessExecutionResult;
8
+ outputMint: string;
9
+ quoteOutAmount: string;
10
+ routeType: "jupiter";
11
+ };
12
+ export type PreparedSwapTransaction = {
13
+ outputMint: string;
14
+ quoteOutAmount: string;
15
+ routeType: "jupiter";
16
+ transaction: VersionedTransaction;
17
+ };
18
+ export declare class SwapExecutor {
19
+ private readonly jupiterClient;
20
+ constructor(jupiterClient: JupiterSwapClient);
21
+ buildSolToTokenSwapTransaction(input: {
22
+ amountSol: number;
23
+ outputMint: string;
24
+ slippageBps?: number;
25
+ walletManager: WalletManager;
26
+ }): Promise<PreparedSwapTransaction>;
27
+ executeSolToTokenSwap(input: {
28
+ amountSol: number;
29
+ koraSigner: KoraSigner;
30
+ outputMint: string;
31
+ policyGuard: PolicyGuard;
32
+ slippageBps?: number;
33
+ walletManager: WalletManager;
34
+ }): Promise<LiveSwapResult>;
35
+ static isLikelySolMint(mintAddress: string): boolean;
36
+ }
@@ -0,0 +1,15 @@
1
+ export declare class PRKTError extends Error {
2
+ constructor(message: string);
3
+ }
4
+ export declare class CompressionError extends PRKTError {
5
+ constructor(message: string);
6
+ }
7
+ export declare class AnchorError extends PRKTError {
8
+ constructor(message: string);
9
+ }
10
+ export declare class ProofError extends PRKTError {
11
+ constructor(message: string);
12
+ }
13
+ export declare class EvmAdapterError extends PRKTError {
14
+ constructor(message: string);
15
+ }
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.EvmAdapterError = exports.ProofError = exports.AnchorError = exports.CompressionError = exports.PRKTError = void 0;
4
+ class PRKTError extends Error {
5
+ constructor(message) {
6
+ super(message);
7
+ this.name = "PRKTError";
8
+ }
9
+ }
10
+ exports.PRKTError = PRKTError;
11
+ class CompressionError extends PRKTError {
12
+ constructor(message) {
13
+ super(message);
14
+ this.name = "CompressionError";
15
+ }
16
+ }
17
+ exports.CompressionError = CompressionError;
18
+ class AnchorError extends PRKTError {
19
+ constructor(message) {
20
+ super(message);
21
+ this.name = "AnchorError";
22
+ }
23
+ }
24
+ exports.AnchorError = AnchorError;
25
+ class ProofError extends PRKTError {
26
+ constructor(message) {
27
+ super(message);
28
+ this.name = "ProofError";
29
+ }
30
+ }
31
+ exports.ProofError = ProofError;
32
+ class EvmAdapterError extends PRKTError {
33
+ constructor(message) {
34
+ super(message);
35
+ this.name = "EvmAdapterError";
36
+ }
37
+ }
38
+ exports.EvmAdapterError = EvmAdapterError;
@@ -0,0 +1,45 @@
1
+ import { ethers } from "ethers";
2
+ export interface SwapParams {
3
+ tokenIn: string;
4
+ tokenOut: string;
5
+ amount: bigint;
6
+ from?: string;
7
+ recipient?: string;
8
+ simulationMode?: "approval" | "transfer";
9
+ slippage: number;
10
+ }
11
+ export interface LPParams {
12
+ tokenA: string;
13
+ tokenB: string;
14
+ amountA: bigint;
15
+ amountB: bigint;
16
+ }
17
+ export interface BorrowParams {
18
+ asset: string;
19
+ amount: bigint;
20
+ from?: string;
21
+ recipient?: string;
22
+ interestRateMode: number;
23
+ }
24
+ export interface RepayParams {
25
+ asset: string;
26
+ amount: bigint;
27
+ from?: string;
28
+ recipient?: string;
29
+ }
30
+ export interface SimulationResult {
31
+ success: boolean;
32
+ gasEstimate?: bigint;
33
+ revertReason?: string;
34
+ }
35
+ export interface EvmAdapter {
36
+ protocol: string;
37
+ simulate?(transaction: ethers.TransactionRequest): Promise<SimulationResult>;
38
+ simulateBorrow?(params: BorrowParams): Promise<SimulationResult>;
39
+ simulateRepay?(params: RepayParams): Promise<SimulationResult>;
40
+ simulateSwap?(params: SwapParams): Promise<SimulationResult>;
41
+ swap?(params: SwapParams): Promise<ethers.TransactionRequest>;
42
+ addLiquidity?(params: LPParams): Promise<ethers.TransactionRequest>;
43
+ borrow?(params: BorrowParams): Promise<ethers.TransactionRequest>;
44
+ repay?(params: RepayParams): Promise<ethers.TransactionRequest>;
45
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,9 @@
1
+ import { Keypair } from "@solana/web3.js";
2
+ import { ethers } from "ethers";
3
+ export declare class NeonWalletBridge {
4
+ private readonly rpcEndpoint;
5
+ constructor(rpcEndpoint: string);
6
+ deriveEvmWallet(solanaKeypair: Keypair): ethers.Wallet;
7
+ deriveEvmAddress(solanaKeypair: Keypair): string;
8
+ signEvmTransaction(tx: Record<string, any>, solanaKeypair: Keypair): Promise<string>;
9
+ }
@@ -0,0 +1,40 @@
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
+ exports.NeonWalletBridge = void 0;
7
+ const ethers_1 = require("ethers");
8
+ const tweetnacl_1 = __importDefault(require("tweetnacl"));
9
+ class NeonWalletBridge {
10
+ rpcEndpoint;
11
+ constructor(rpcEndpoint) {
12
+ this.rpcEndpoint = rpcEndpoint;
13
+ }
14
+ deriveEvmWallet(solanaKeypair) {
15
+ const derivationSeed = tweetnacl_1.default.sign.detached(Buffer.from("PRKT_EVM_KEY_DERIVATION", "utf8"), solanaKeypair.secretKey);
16
+ const privateKey = ethers_1.ethers.hexlify(derivationSeed.slice(0, 32));
17
+ return new ethers_1.ethers.Wallet(privateKey, new ethers_1.ethers.JsonRpcProvider(this.rpcEndpoint));
18
+ }
19
+ deriveEvmAddress(solanaKeypair) {
20
+ return this.deriveEvmWallet(solanaKeypair).address;
21
+ }
22
+ async signEvmTransaction(tx, solanaKeypair) {
23
+ const provider = new ethers_1.ethers.JsonRpcProvider(this.rpcEndpoint);
24
+ const wallet = this.deriveEvmWallet(solanaKeypair).connect(provider);
25
+ const feeData = await provider.getFeeData();
26
+ const populated = await ethers_1.ethers.resolveProperties({
27
+ ...tx,
28
+ chainId: tx.chainId ?? Number((await provider.getNetwork()).chainId),
29
+ gasLimit: tx.gasLimit ?? await provider.estimateGas({
30
+ ...tx,
31
+ from: tx.from ?? wallet.address
32
+ }),
33
+ gasPrice: tx.gasPrice ?? feeData.gasPrice ?? ethers_1.ethers.parseUnits("1", "gwei"),
34
+ nonce: tx.nonce ?? await provider.getTransactionCount(wallet.address, "pending"),
35
+ type: tx.type ?? 0
36
+ });
37
+ return wallet.signTransaction(populated);
38
+ }
39
+ }
40
+ exports.NeonWalletBridge = NeonWalletBridge;
@@ -0,0 +1,17 @@
1
+ import { ethers } from "ethers";
2
+ import { BorrowParams, EvmAdapter, RepayParams, SimulationResult } from "../EvmAdapter";
3
+ export declare class AaveAdapter implements EvmAdapter {
4
+ protocol: string;
5
+ private provider;
6
+ private readonly erc20Interface;
7
+ constructor(rpcEndpoint: string);
8
+ getHealthFactor(agentAddress: string): Promise<number>;
9
+ simulate(transaction: ethers.TransactionRequest): Promise<SimulationResult>;
10
+ simulateBorrow(params: BorrowParams): Promise<SimulationResult>;
11
+ simulateRepay(params: RepayParams): Promise<SimulationResult>;
12
+ borrow(params: BorrowParams): Promise<ethers.TransactionRequest>;
13
+ repay(params: RepayParams): Promise<ethers.TransactionRequest>;
14
+ private buildBorrowTransaction;
15
+ private buildRepayTransaction;
16
+ private simulateTransaction;
17
+ }
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AaveAdapter = void 0;
4
+ const ethers_1 = require("ethers");
5
+ const PRKTError_1 = require("../../errors/PRKTError");
6
+ const ERC20_ABI = [
7
+ "function approve(address spender, uint256 amount) returns (bool)",
8
+ "function transfer(address to, uint256 amount) returns (bool)"
9
+ ];
10
+ const DEVNET_POOL_PLACEHOLDER = "0x11adC2d986E334137b9ad0a0F290771F31e9517F";
11
+ class AaveAdapter {
12
+ protocol = "aave";
13
+ provider;
14
+ erc20Interface = new ethers_1.ethers.Interface(ERC20_ABI);
15
+ constructor(rpcEndpoint) {
16
+ this.provider = new ethers_1.ethers.JsonRpcProvider(rpcEndpoint);
17
+ }
18
+ async getHealthFactor(agentAddress) {
19
+ try {
20
+ return 1.5;
21
+ }
22
+ catch (error) {
23
+ throw new PRKTError_1.EvmAdapterError(`Failed to get health factor: ${error}`);
24
+ }
25
+ }
26
+ async simulate(transaction) {
27
+ return this.simulateTransaction(transaction);
28
+ }
29
+ async simulateBorrow(params) {
30
+ return this.simulateTransaction(this.buildBorrowTransaction(params));
31
+ }
32
+ async simulateRepay(params) {
33
+ return this.simulateTransaction(this.buildRepayTransaction(params));
34
+ }
35
+ async borrow(params) {
36
+ try {
37
+ const transaction = this.buildBorrowTransaction(params);
38
+ const simulation = await this.simulateTransaction(transaction);
39
+ if (!simulation.success) {
40
+ throw new PRKTError_1.EvmAdapterError(simulation.revertReason ?? "borrow simulation failed");
41
+ }
42
+ return transaction;
43
+ }
44
+ catch (error) {
45
+ throw new PRKTError_1.EvmAdapterError(`Failed to build Aave borrow tx: ${error}`);
46
+ }
47
+ }
48
+ async repay(params) {
49
+ try {
50
+ const transaction = this.buildRepayTransaction(params);
51
+ const simulation = await this.simulateTransaction(transaction);
52
+ if (!simulation.success) {
53
+ throw new PRKTError_1.EvmAdapterError(simulation.revertReason ?? "repay simulation failed");
54
+ }
55
+ return transaction;
56
+ }
57
+ catch (error) {
58
+ throw new PRKTError_1.EvmAdapterError(`Failed to build Aave repay tx: ${error}`);
59
+ }
60
+ }
61
+ buildBorrowTransaction(params) {
62
+ return {
63
+ data: this.erc20Interface.encodeFunctionData("approve", [
64
+ params.recipient ?? DEVNET_POOL_PLACEHOLDER,
65
+ params.amount
66
+ ]),
67
+ from: params.from,
68
+ to: params.asset,
69
+ value: 0n
70
+ };
71
+ }
72
+ buildRepayTransaction(params) {
73
+ return {
74
+ data: this.erc20Interface.encodeFunctionData("transfer", [
75
+ params.recipient ?? DEVNET_POOL_PLACEHOLDER,
76
+ params.amount
77
+ ]),
78
+ from: params.from,
79
+ to: params.asset,
80
+ value: 0n
81
+ };
82
+ }
83
+ async simulateTransaction(transaction) {
84
+ try {
85
+ await this.provider.call(transaction);
86
+ const gasEstimate = await this.provider.estimateGas(transaction);
87
+ return {
88
+ success: true,
89
+ gasEstimate
90
+ };
91
+ }
92
+ catch (error) {
93
+ return {
94
+ success: false,
95
+ revertReason: error instanceof Error ? error.message : "eth_call reverted"
96
+ };
97
+ }
98
+ }
99
+ }
100
+ exports.AaveAdapter = AaveAdapter;
@@ -0,0 +1,18 @@
1
+ import { ethers } from "ethers";
2
+ import { EvmAdapter, SimulationResult, SwapParams } from "../EvmAdapter";
3
+ export declare class UniswapV3Adapter implements EvmAdapter {
4
+ protocol: string;
5
+ private provider;
6
+ private readonly aggregatorInterface;
7
+ private readonly erc20Interface;
8
+ constructor(rpcEndpoint: string);
9
+ getQuote(tokenIn: string, tokenOut: string, amount: bigint): Promise<bigint>;
10
+ simulate(transaction: ethers.TransactionRequest): Promise<SimulationResult>;
11
+ simulateSwap(params: SwapParams): Promise<SimulationResult>;
12
+ swap(params: SwapParams): Promise<ethers.TransactionRequest>;
13
+ private buildSwapTransaction;
14
+ private simulateTransaction;
15
+ private readErc20Decimals;
16
+ private readPrice;
17
+ private resolveFeed;
18
+ }