@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
@@ -0,0 +1,146 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UniswapV3Adapter = void 0;
4
+ const ethers_1 = require("ethers");
5
+ const PRKTError_1 = require("../../errors/PRKTError");
6
+ const CHAINLINK_AGGREGATOR_ABI = [
7
+ "function decimals() view returns (uint8)",
8
+ "function latestRoundData() view returns (uint80,int256,uint256,uint256,uint80)"
9
+ ];
10
+ const ERC20_ABI = [
11
+ "function approve(address spender, uint256 amount) returns (bool)",
12
+ "function decimals() view returns (uint8)",
13
+ "function transfer(address to, uint256 amount) returns (bool)"
14
+ ];
15
+ const DEVNET_CHAINLINK_FEEDS = {
16
+ "sol-usd": "0xec852B2A009f49E4eE4ffEddeDcF81a1AD1bbD6d",
17
+ "usdc-usd": "0xedc0d80E85292fEf5B0946DEc957563Ceb7C8e6c"
18
+ };
19
+ const DEVNET_NEON_TOKENS = {
20
+ usdc: "0x512E48836Cd42F3eB6f50CEd9ffD81E0a7F15103",
21
+ wsol: "0xc7Fc9b46e479c5Cb42f6C458D1881e55E6B7986c"
22
+ };
23
+ class UniswapV3Adapter {
24
+ protocol = "uniswap-v3";
25
+ provider;
26
+ aggregatorInterface = new ethers_1.ethers.Interface(CHAINLINK_AGGREGATOR_ABI);
27
+ erc20Interface = new ethers_1.ethers.Interface(ERC20_ABI);
28
+ constructor(rpcEndpoint) {
29
+ this.provider = new ethers_1.ethers.JsonRpcProvider(rpcEndpoint);
30
+ }
31
+ async getQuote(tokenIn, tokenOut, amount) {
32
+ try {
33
+ const [tokenInDecimals, tokenOutDecimals] = await Promise.all([
34
+ this.readErc20Decimals(tokenIn),
35
+ this.readErc20Decimals(tokenOut)
36
+ ]);
37
+ const [priceIn, priceOut] = await Promise.all([
38
+ this.readPrice(this.resolveFeed(tokenIn)),
39
+ this.readPrice(this.resolveFeed(tokenOut))
40
+ ]);
41
+ return (amount *
42
+ priceIn.price *
43
+ 10n ** BigInt(tokenOutDecimals)) / (10n ** BigInt(tokenInDecimals) *
44
+ priceOut.price);
45
+ }
46
+ catch (error) {
47
+ throw new PRKTError_1.EvmAdapterError(`Failed to get Uniswap V3 quote: ${error}`);
48
+ }
49
+ }
50
+ async simulate(transaction) {
51
+ return this.simulateTransaction(transaction);
52
+ }
53
+ async simulateSwap(params) {
54
+ const transaction = await this.buildSwapTransaction(params);
55
+ return this.simulateTransaction(transaction);
56
+ }
57
+ async swap(params) {
58
+ try {
59
+ const minAmountOut = await this.getQuote(params.tokenIn, params.tokenOut, params.amount);
60
+ const minimum = minAmountOut * BigInt(100 - params.slippage) / 100n;
61
+ const transaction = await this.buildSwapTransaction({
62
+ ...params,
63
+ amount: minimum
64
+ });
65
+ const simulation = await this.simulateTransaction(transaction);
66
+ if (!simulation.success) {
67
+ throw new PRKTError_1.EvmAdapterError(simulation.revertReason ?? "swap simulation failed");
68
+ }
69
+ return transaction;
70
+ }
71
+ catch (error) {
72
+ throw new PRKTError_1.EvmAdapterError(`Failed to build Uniswap V3 swap tx: ${error}`);
73
+ }
74
+ }
75
+ async buildSwapTransaction(params) {
76
+ const recipient = params.recipient ?? DEVNET_NEON_TOKENS.usdc;
77
+ const mode = params.simulationMode ?? "approval";
78
+ if (mode === "transfer") {
79
+ return {
80
+ data: this.erc20Interface.encodeFunctionData("transfer", [recipient, params.amount]),
81
+ from: params.from,
82
+ to: params.tokenIn,
83
+ value: 0n
84
+ };
85
+ }
86
+ return {
87
+ data: this.erc20Interface.encodeFunctionData("approve", [recipient, params.amount]),
88
+ from: params.from,
89
+ to: params.tokenIn,
90
+ value: 0n
91
+ };
92
+ }
93
+ async simulateTransaction(transaction) {
94
+ try {
95
+ await this.provider.call(transaction);
96
+ const gasEstimate = await this.provider.estimateGas(transaction);
97
+ return {
98
+ success: true,
99
+ gasEstimate
100
+ };
101
+ }
102
+ catch (error) {
103
+ return {
104
+ success: false,
105
+ revertReason: error instanceof Error ? error.message : "eth_call reverted"
106
+ };
107
+ }
108
+ }
109
+ async readErc20Decimals(tokenAddress) {
110
+ const response = await this.provider.call({
111
+ data: this.erc20Interface.encodeFunctionData("decimals"),
112
+ to: tokenAddress
113
+ });
114
+ const [decimals] = this.erc20Interface.decodeFunctionResult("decimals", response);
115
+ return Number(decimals);
116
+ }
117
+ async readPrice(feedAddress) {
118
+ const [decimalsResponse, latestRoundDataResponse] = await Promise.all([
119
+ this.provider.call({
120
+ data: this.aggregatorInterface.encodeFunctionData("decimals"),
121
+ to: feedAddress
122
+ }),
123
+ this.provider.call({
124
+ data: this.aggregatorInterface.encodeFunctionData("latestRoundData"),
125
+ to: feedAddress
126
+ })
127
+ ]);
128
+ const [decimals] = this.aggregatorInterface.decodeFunctionResult("decimals", decimalsResponse);
129
+ const [, price] = this.aggregatorInterface.decodeFunctionResult("latestRoundData", latestRoundDataResponse);
130
+ return {
131
+ decimals: Number(decimals),
132
+ price: BigInt(price.toString())
133
+ };
134
+ }
135
+ resolveFeed(tokenAddress) {
136
+ const normalized = tokenAddress.toLowerCase();
137
+ if (normalized === DEVNET_NEON_TOKENS.wsol.toLowerCase()) {
138
+ return DEVNET_CHAINLINK_FEEDS["sol-usd"];
139
+ }
140
+ if (normalized === DEVNET_NEON_TOKENS.usdc.toLowerCase()) {
141
+ return DEVNET_CHAINLINK_FEEDS["usdc-usd"];
142
+ }
143
+ throw new PRKTError_1.EvmAdapterError(`No Neon devnet price feed configured for token ${tokenAddress}`);
144
+ }
145
+ }
146
+ exports.UniswapV3Adapter = UniswapV3Adapter;
@@ -0,0 +1,15 @@
1
+ export * from "./core";
2
+ export * from "./policy";
3
+ export * from "./agent/new-index";
4
+ export { SessionAnchor } from "./anchoring/SessionAnchor";
5
+ export type { SessionCloseResult, SessionStartResult, SessionVerifyResult } from "./anchoring/SessionAnchor";
6
+ export { PolicyAccountManager } from "./compression/PolicyAccountManager";
7
+ export { AuditLogManager } from "./compression/AuditLogManager";
8
+ export type { AuditEntry, CompressedPolicyState } from "./compression/types";
9
+ export { defaultPRKTConfig } from "./config/PRKTConfig";
10
+ export * from "./config/env";
11
+ export * from "./onchain";
12
+ export { UniversalDeFiOrchestrator } from "./defi/universal";
13
+ export { PolicyCircuit, PolicyViolation } from "./zk/PolicyCircuit";
14
+ export type { PolicyAttestation, PolicyProof } from "./zk/PolicyCircuit";
15
+ export { ProofAnchor } from "./zk/ProofAnchor";
package/dist/index.js CHANGED
@@ -1,22 +1,37 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
2
16
  Object.defineProperty(exports, "__esModule", { value: true });
3
- const web3_js_1 = require("@solana/web3.js");
4
- const env_1 = require("./config/env");
5
- const WalletManager_1 = require("./wallet/WalletManager");
6
- async function main() {
7
- const rpcUrl = (0, env_1.getRpcUrl)();
8
- const connection = new web3_js_1.Connection(rpcUrl, "confirmed");
9
- const walletManager = WalletManager_1.WalletManager.loadOrGenerate();
10
- const { publicKey, source } = walletManager.toSafeSummary();
11
- console.log("PRKT wallet ready.");
12
- console.log(`RPC: ${rpcUrl}`);
13
- console.log(`Wallet source: ${source}`);
14
- console.log(`Devnet public key: ${publicKey}`);
15
- const balanceLamports = await connection.getBalance(walletManager.publicKey);
16
- console.log(`Devnet balance (lamports): ${balanceLamports}`);
17
- }
18
- main().catch((error) => {
19
- const message = error instanceof Error ? error.message : "Unknown error";
20
- console.error(`Startup failed: ${message}`);
21
- process.exitCode = 1;
22
- });
17
+ exports.ProofAnchor = exports.PolicyViolation = exports.PolicyCircuit = exports.UniversalDeFiOrchestrator = exports.defaultPRKTConfig = exports.AuditLogManager = exports.PolicyAccountManager = exports.SessionAnchor = void 0;
18
+ __exportStar(require("./core"), exports);
19
+ __exportStar(require("./policy"), exports);
20
+ __exportStar(require("./agent/new-index"), exports);
21
+ var SessionAnchor_1 = require("./anchoring/SessionAnchor");
22
+ Object.defineProperty(exports, "SessionAnchor", { enumerable: true, get: function () { return SessionAnchor_1.SessionAnchor; } });
23
+ var PolicyAccountManager_1 = require("./compression/PolicyAccountManager");
24
+ Object.defineProperty(exports, "PolicyAccountManager", { enumerable: true, get: function () { return PolicyAccountManager_1.PolicyAccountManager; } });
25
+ var AuditLogManager_1 = require("./compression/AuditLogManager");
26
+ Object.defineProperty(exports, "AuditLogManager", { enumerable: true, get: function () { return AuditLogManager_1.AuditLogManager; } });
27
+ var PRKTConfig_1 = require("./config/PRKTConfig");
28
+ Object.defineProperty(exports, "defaultPRKTConfig", { enumerable: true, get: function () { return PRKTConfig_1.defaultPRKTConfig; } });
29
+ __exportStar(require("./config/env"), exports);
30
+ __exportStar(require("./onchain"), exports);
31
+ var universal_1 = require("./defi/universal");
32
+ Object.defineProperty(exports, "UniversalDeFiOrchestrator", { enumerable: true, get: function () { return universal_1.UniversalDeFiOrchestrator; } });
33
+ var PolicyCircuit_1 = require("./zk/PolicyCircuit");
34
+ Object.defineProperty(exports, "PolicyCircuit", { enumerable: true, get: function () { return PolicyCircuit_1.PolicyCircuit; } });
35
+ Object.defineProperty(exports, "PolicyViolation", { enumerable: true, get: function () { return PolicyCircuit_1.PolicyViolation; } });
36
+ var ProofAnchor_1 = require("./zk/ProofAnchor");
37
+ Object.defineProperty(exports, "ProofAnchor", { enumerable: true, get: function () { return ProofAnchor_1.ProofAnchor; } });
@@ -0,0 +1,14 @@
1
+ export declare class KoraRpcError extends Error {
2
+ constructor(message: string);
3
+ }
4
+ export declare class KoraRpcClient {
5
+ private readonly endpoint;
6
+ private readonly fetchImpl;
7
+ constructor(endpoint: string, fetchImpl?: typeof fetch);
8
+ get rpcUrl(): string;
9
+ getBlockhash(): Promise<string>;
10
+ signAndSendTransaction(transaction: string): Promise<{
11
+ signature: string;
12
+ }>;
13
+ private call;
14
+ }
@@ -0,0 +1,22 @@
1
+ import { VersionedTransaction } from "@solana/web3.js";
2
+ import { WalletManager } from "../wallet/WalletManager";
3
+ import { KoraRpcClient } from "./KoraRpcClient";
4
+ export type GaslessExecutionResult = {
5
+ endpoint: string;
6
+ fallbackReason?: string;
7
+ memo: string;
8
+ mock: boolean;
9
+ signature: string;
10
+ };
11
+ export declare class KoraSigner {
12
+ private readonly client;
13
+ private readonly options;
14
+ constructor(client: KoraRpcClient, options: {
15
+ fallbackToMockOnError?: boolean;
16
+ mockMode: boolean;
17
+ });
18
+ buildMemoTransaction(walletManager: WalletManager, memo: string): Promise<VersionedTransaction>;
19
+ signAndSendGasless(transaction: VersionedTransaction, memo: string): Promise<GaslessExecutionResult>;
20
+ submitGaslessMemo(walletManager: WalletManager, memo: string): Promise<GaslessExecutionResult>;
21
+ private createMockSignature;
22
+ }
@@ -12,9 +12,17 @@ class KoraSigner {
12
12
  this.options = options;
13
13
  }
14
14
  async buildMemoTransaction(walletManager, memo) {
15
- const recentBlockhash = this.options.mockMode
16
- ? programs_1.MOCK_BLOCKHASH
17
- : await this.client.getBlockhash();
15
+ let recentBlockhash = programs_1.MOCK_BLOCKHASH;
16
+ if (!this.options.mockMode) {
17
+ try {
18
+ recentBlockhash = await this.client.getBlockhash();
19
+ }
20
+ catch (error) {
21
+ if (!this.options.fallbackToMockOnError) {
22
+ throw error;
23
+ }
24
+ }
25
+ }
18
26
  const memoInstruction = new web3_js_1.TransactionInstruction({
19
27
  programId: programs_1.MEMO_PROGRAM_ID,
20
28
  keys: [],
@@ -38,13 +46,28 @@ class KoraSigner {
38
46
  signature: this.createMockSignature(serializedTransaction)
39
47
  };
40
48
  }
41
- const { signature } = await this.client.signAndSendTransaction(serializedTransaction);
42
- return {
43
- endpoint: this.client.rpcUrl,
44
- memo,
45
- mock: false,
46
- signature
47
- };
49
+ try {
50
+ const { signature } = await this.client.signAndSendTransaction(serializedTransaction);
51
+ return {
52
+ endpoint: this.client.rpcUrl,
53
+ memo,
54
+ mock: false,
55
+ signature
56
+ };
57
+ }
58
+ catch (error) {
59
+ if (!this.options.fallbackToMockOnError) {
60
+ throw error;
61
+ }
62
+ const fallbackReason = error instanceof Error ? error.message : "unknown Kora RPC error";
63
+ return {
64
+ endpoint: this.client.rpcUrl,
65
+ fallbackReason,
66
+ memo,
67
+ mock: true,
68
+ signature: this.createMockSignature(serializedTransaction)
69
+ };
70
+ }
48
71
  }
49
72
  async submitGaslessMemo(walletManager, memo) {
50
73
  const transaction = await this.buildMemoTransaction(walletManager, memo);
@@ -0,0 +1,9 @@
1
+ export declare function assertGaslessDemoReadiness(input: {
2
+ solLamports: number;
3
+ usdcBalance: number;
4
+ }): void;
5
+ export declare function parseUiAmount(input: {
6
+ amount: string;
7
+ decimals: number;
8
+ uiAmount: number | null;
9
+ }): number;
@@ -0,0 +1,2 @@
1
+ export { buildCloseSessionInstruction, buildInitializePolicyInstruction, buildManagedTransferInstructions, buildOpenSessionInstruction, buildSetKillSwitchInstruction, createSessionId, deriveTransferIntentHash, encodeManagedTransferPayload, findPolicyPda, findSessionPda, findVaultPda, getPolicyStateSpace, resolvePolicyGuardProgramId } from "./policyGuardProgram";
2
+ export type { InitializePolicyInput, ManagedTransferInput, ManagedTransferPayload, SessionInstructionInput } from "./policyGuardProgram";
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.resolvePolicyGuardProgramId = exports.getPolicyStateSpace = exports.findVaultPda = exports.findSessionPda = exports.findPolicyPda = exports.encodeManagedTransferPayload = exports.deriveTransferIntentHash = exports.createSessionId = exports.buildSetKillSwitchInstruction = exports.buildOpenSessionInstruction = exports.buildManagedTransferInstructions = exports.buildInitializePolicyInstruction = exports.buildCloseSessionInstruction = void 0;
4
+ var policyGuardProgram_1 = require("./policyGuardProgram");
5
+ Object.defineProperty(exports, "buildCloseSessionInstruction", { enumerable: true, get: function () { return policyGuardProgram_1.buildCloseSessionInstruction; } });
6
+ Object.defineProperty(exports, "buildInitializePolicyInstruction", { enumerable: true, get: function () { return policyGuardProgram_1.buildInitializePolicyInstruction; } });
7
+ Object.defineProperty(exports, "buildManagedTransferInstructions", { enumerable: true, get: function () { return policyGuardProgram_1.buildManagedTransferInstructions; } });
8
+ Object.defineProperty(exports, "buildOpenSessionInstruction", { enumerable: true, get: function () { return policyGuardProgram_1.buildOpenSessionInstruction; } });
9
+ Object.defineProperty(exports, "buildSetKillSwitchInstruction", { enumerable: true, get: function () { return policyGuardProgram_1.buildSetKillSwitchInstruction; } });
10
+ Object.defineProperty(exports, "createSessionId", { enumerable: true, get: function () { return policyGuardProgram_1.createSessionId; } });
11
+ Object.defineProperty(exports, "deriveTransferIntentHash", { enumerable: true, get: function () { return policyGuardProgram_1.deriveTransferIntentHash; } });
12
+ Object.defineProperty(exports, "encodeManagedTransferPayload", { enumerable: true, get: function () { return policyGuardProgram_1.encodeManagedTransferPayload; } });
13
+ Object.defineProperty(exports, "findPolicyPda", { enumerable: true, get: function () { return policyGuardProgram_1.findPolicyPda; } });
14
+ Object.defineProperty(exports, "findSessionPda", { enumerable: true, get: function () { return policyGuardProgram_1.findSessionPda; } });
15
+ Object.defineProperty(exports, "findVaultPda", { enumerable: true, get: function () { return policyGuardProgram_1.findVaultPda; } });
16
+ Object.defineProperty(exports, "getPolicyStateSpace", { enumerable: true, get: function () { return policyGuardProgram_1.getPolicyStateSpace; } });
17
+ Object.defineProperty(exports, "resolvePolicyGuardProgramId", { enumerable: true, get: function () { return policyGuardProgram_1.resolvePolicyGuardProgramId; } });
@@ -0,0 +1,86 @@
1
+ import { Keypair, PublicKey, TransactionInstruction } from "@solana/web3.js";
2
+ export type InitializePolicyInput = {
3
+ owner: PublicKey;
4
+ verifier: PublicKey;
5
+ dailySpendLimitLamports: bigint;
6
+ sessionTtlMinutes: number;
7
+ allowedPrograms?: PublicKey[];
8
+ allowedRecipients?: PublicKey[];
9
+ programId?: PublicKey;
10
+ };
11
+ export type SessionInstructionInput = {
12
+ owner: PublicKey;
13
+ sessionId: Uint8Array;
14
+ programId?: PublicKey;
15
+ };
16
+ export type ManagedTransferInput = {
17
+ amountLamports: bigint;
18
+ nonce: bigint;
19
+ policyOwner: PublicKey;
20
+ recipient: PublicKey;
21
+ sessionId: Uint8Array;
22
+ signer: Keypair | Uint8Array;
23
+ expiresAtUnix: number;
24
+ timestampUnix?: number;
25
+ targetProgram?: PublicKey;
26
+ intentHash?: Uint8Array;
27
+ programId?: PublicKey;
28
+ };
29
+ export type ManagedTransferPayload = {
30
+ amountLamports: bigint;
31
+ expiresAtUnix: number;
32
+ intentHash: Buffer;
33
+ nonce: bigint;
34
+ recipient: PublicKey;
35
+ sessionId: Buffer;
36
+ targetProgram: PublicKey;
37
+ timestampUnix: number;
38
+ };
39
+ export declare function resolvePolicyGuardProgramId(programId?: PublicKey): PublicKey;
40
+ export declare function createSessionId(seed?: string | Uint8Array): Buffer;
41
+ export declare function getPolicyStateSpace(input: {
42
+ allowedPrograms?: PublicKey[];
43
+ allowedRecipients?: PublicKey[];
44
+ }): number;
45
+ export declare function findPolicyPda(owner: PublicKey, programId?: PublicKey): [PublicKey, number];
46
+ export declare function findVaultPda(policyPda: PublicKey, programId?: PublicKey): [PublicKey, number];
47
+ export declare function findSessionPda(policyPda: PublicKey, sessionId: Uint8Array, programId?: PublicKey): [PublicKey, number];
48
+ export declare function buildInitializePolicyInstruction(input: InitializePolicyInput): {
49
+ instruction: TransactionInstruction;
50
+ policyPda: PublicKey;
51
+ vaultPda: PublicKey;
52
+ };
53
+ export declare function buildSetKillSwitchInstruction(input: {
54
+ active: boolean;
55
+ owner: PublicKey;
56
+ programId?: PublicKey;
57
+ }): {
58
+ instruction: TransactionInstruction;
59
+ policyPda: PublicKey;
60
+ };
61
+ export declare function buildOpenSessionInstruction(input: SessionInstructionInput): {
62
+ instruction: TransactionInstruction;
63
+ policyPda: PublicKey;
64
+ sessionPda: PublicKey;
65
+ };
66
+ export declare function buildCloseSessionInstruction(input: SessionInstructionInput): {
67
+ instruction: TransactionInstruction;
68
+ policyPda: PublicKey;
69
+ sessionPda: PublicKey;
70
+ };
71
+ export declare function buildManagedTransferInstructions(input: ManagedTransferInput): {
72
+ ed25519Instruction: TransactionInstruction;
73
+ payload: Buffer;
74
+ policyPda: PublicKey;
75
+ programInstruction: TransactionInstruction;
76
+ sessionPda: PublicKey;
77
+ vaultPda: PublicKey;
78
+ };
79
+ export declare function encodeManagedTransferPayload(input: ManagedTransferPayload): Buffer;
80
+ export declare function deriveTransferIntentHash(input: {
81
+ amountLamports: bigint;
82
+ nonce: bigint;
83
+ recipient: PublicKey;
84
+ sessionId: Uint8Array;
85
+ targetProgram?: PublicKey;
86
+ }): Buffer;