@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.
- package/.env.devnet.all-protocols.example +5 -0
- package/.env.example +7 -0
- package/CLI.md +24 -0
- package/CLI_QUICKSTART.md +16 -0
- package/README.md +59 -12
- package/dist/agent/AgentManager.d.ts +61 -0
- package/dist/agent/AgentRuntime.d.ts +28 -0
- package/dist/agent/DecisionEngine.d.ts +51 -0
- package/dist/agent/MockPriceFeed.d.ts +10 -0
- package/dist/agent/intents/types.d.ts +35 -0
- package/dist/agent/new-index.d.ts +9 -0
- package/dist/agent/policyFactory.d.ts +2 -0
- package/dist/agent/registry/AgentRegistry.d.ts +11 -0
- package/dist/agent/runner/AgentRunner.d.ts +51 -0
- package/dist/agent/runner/AgentRunner.js +59 -2
- package/dist/agent/strategies/MemoHeartbeatStrategy.d.ts +6 -0
- package/dist/agent/strategies/SimpleScriptedTransferStrategy.d.ts +12 -0
- package/dist/agent/strategies/TokenRebalancerStrategy.d.ts +13 -0
- package/dist/agent/strategies/TreasuryDistributorStrategy.d.ts +12 -0
- package/dist/agent/strategies/UniversalDeFiStrategy.d.ts +22 -0
- package/dist/agent/types/AgentContext.d.ts +28 -0
- package/dist/anchoring/SessionAnchor.d.ts +42 -0
- package/dist/anchoring/SessionAnchor.js +161 -0
- package/dist/cli/index.d.ts +2 -0
- package/dist/cli/index.js +157 -16
- package/dist/cli/services/activityStore.d.ts +8 -0
- package/dist/cli/services/agentRegistry.d.ts +20 -0
- package/dist/cli/services/agentRuntime.d.ts +6 -0
- package/dist/cli/services/storagePaths.d.ts +8 -0
- package/dist/cli/services/strategyFactory.d.ts +5 -0
- package/dist/cli/services/walletCrypto.d.ts +12 -0
- package/dist/cli/services/walletRegistry.d.ts +26 -0
- package/dist/cli/types.d.ts +68 -0
- package/dist/cli/utils/completion.d.ts +4 -0
- package/dist/cli/utils/output.d.ts +5 -0
- package/dist/cli/utils/output.js +4 -1
- package/dist/compression/AuditLogManager.d.ts +9 -0
- package/dist/compression/AuditLogManager.js +86 -0
- package/dist/compression/PolicyAccountManager.d.ts +11 -0
- package/dist/compression/PolicyAccountManager.js +113 -0
- package/dist/compression/types.d.ts +20 -0
- package/dist/compression/types.js +2 -0
- package/dist/config/PRKTConfig.d.ts +17 -0
- package/dist/config/PRKTConfig.js +19 -0
- package/dist/config/agentPolicies.d.ts +14 -0
- package/dist/config/env.d.ts +39 -0
- package/dist/config/env.js +37 -0
- package/dist/config/policyPresets.d.ts +22 -0
- package/dist/core/balances/BalanceService.d.ts +14 -0
- package/dist/core/funding/DevnetFundingService.d.ts +38 -0
- package/dist/core/funding/DevnetFundingService.js +73 -6
- package/dist/core/idempotency/ExecutionIdempotencyGuard.d.ts +39 -0
- package/dist/core/index.d.ts +8 -0
- package/dist/core/rpc/RpcClient.d.ts +21 -0
- package/dist/core/rpc/RpcClient.js +35 -0
- package/dist/core/rpc/RpcFailoverClient.d.ts +42 -0
- package/dist/core/tokens/TokenService.d.ts +40 -0
- package/dist/core/transactions/PostTransactionVerifier.d.ts +47 -0
- package/dist/core/transactions/TransactionService.d.ts +46 -0
- package/dist/core/types/services.d.ts +27 -0
- package/dist/core/wallet/WalletManager.d.ts +21 -0
- package/dist/defi/DeFiCoordinator.d.ts +24 -0
- package/dist/defi/DeFiExecutor.d.ts +15 -0
- package/dist/defi/DeFiPolicyGuard.d.ts +7 -0
- package/dist/defi/adapters/JupiterAdapter.d.ts +5 -0
- package/dist/defi/adapters/KaminoAdapter.d.ts +6 -0
- package/dist/defi/adapters/MarinadeAdapter.d.ts +5 -0
- package/dist/defi/adapters/RaydiumAdapter.d.ts +20 -0
- package/dist/defi/kamino/kaminoInstructionCompat.d.ts +3 -0
- package/dist/defi/kamino/kaminoLiveConfig.d.ts +14 -0
- package/dist/defi/kamino/loadKaminoMarketWithFallback.d.ts +11 -0
- package/dist/defi/lp/LpInstructionBuilder.d.ts +15 -0
- package/dist/defi/lp/RaydiumLpInstructionBuilder.d.ts +28 -0
- package/dist/defi/lp/raydiumDevnetConfig.d.ts +11 -0
- package/dist/defi/protocols.d.ts +8 -0
- package/dist/defi/types.d.ts +65 -0
- package/dist/defi/universal/UniversalDeFiOrchestrator.d.ts +24 -0
- package/dist/defi/universal/UniversalDeFiOrchestrator.js +157 -0
- package/dist/defi/universal/adapters.d.ts +25 -0
- package/dist/defi/universal/index.d.ts +2 -0
- package/dist/defi/universal/liveExecutors.d.ts +23 -0
- package/dist/defi/universal/types.d.ts +45 -0
- package/dist/demo/scenarios/multiAgentDevnetScenario.d.ts +5 -0
- package/dist/demo/scripts/runMultiAgentDevnetDemo.d.ts +1 -0
- package/dist/dex/JupiterSwapClient.d.ts +28 -0
- package/dist/dex/SwapExecutor.d.ts +36 -0
- package/dist/errors/PRKTError.d.ts +15 -0
- package/dist/errors/PRKTError.js +38 -0
- package/dist/evm/EvmAdapter.d.ts +45 -0
- package/dist/evm/EvmAdapter.js +2 -0
- package/dist/evm/NeonWalletBridge.d.ts +9 -0
- package/dist/evm/NeonWalletBridge.js +40 -0
- package/dist/evm/adapters/AaveAdapter.d.ts +17 -0
- package/dist/evm/adapters/AaveAdapter.js +100 -0
- package/dist/evm/adapters/UniswapV3Adapter.d.ts +18 -0
- package/dist/evm/adapters/UniswapV3Adapter.js +146 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +35 -20
- package/dist/kora/KoraRpcClient.d.ts +14 -0
- package/dist/kora/KoraSigner.d.ts +22 -0
- package/dist/kora/KoraSigner.js +33 -10
- package/dist/kora/gaslessDemo.d.ts +9 -0
- package/dist/onchain/index.d.ts +2 -0
- package/dist/onchain/index.js +17 -0
- package/dist/onchain/policyGuardProgram.d.ts +86 -0
- package/dist/onchain/policyGuardProgram.js +248 -0
- package/dist/policy/PolicyGuard.d.ts +13 -0
- package/dist/policy/emergencyLock.d.ts +4 -0
- package/dist/policy/engine/PolicyEngine.d.ts +28 -0
- package/dist/policy/engine/PolicyEngine.js +109 -1
- package/dist/policy/errors.d.ts +3 -0
- package/dist/policy/index.d.ts +3 -0
- package/dist/policy/sandbox/SandboxExecutor.d.ts +44 -0
- package/dist/policy/sandbox/SandboxExecutor.js +245 -3
- package/dist/policy/types/policy.d.ts +55 -0
- package/dist/scripts/devnetFunding.d.ts +9 -0
- package/dist/scripts/devnetFunding.js +0 -1
- package/dist/scripts/devnetWalletPreflight.d.ts +8 -0
- package/dist/scripts/localnetCheck.d.ts +1 -0
- package/dist/scripts/managedAgentWallet.d.ts +34 -0
- package/dist/scripts/mode.d.ts +2 -0
- package/dist/scripts/releaseReadiness.d.ts +9 -0
- package/dist/scripts/runAgentUniversalDeFi.d.ts +1 -0
- package/dist/scripts/runAutonomousAgentWalletDevnet.d.ts +1 -0
- package/dist/scripts/runAutonomousAgentWalletDevnet.js +1 -1
- package/dist/scripts/runAutonomousPortfolioDevnet.d.ts +1 -0
- package/dist/scripts/runAutonomousPortfolioDevnet.js +1 -1
- package/dist/scripts/runBorrowStrategy.d.ts +1 -0
- package/dist/scripts/runDeFiSuite.d.ts +1 -0
- package/dist/scripts/runDemoRehearsal.d.ts +1 -0
- package/dist/scripts/runDemoRehearsal.js +39 -10
- package/dist/scripts/runDevnetFeatureMatrix.d.ts +43 -0
- package/dist/scripts/runDevnetFeatureMatrix.js +787 -0
- package/dist/scripts/runDevnetWalletDemo.d.ts +1 -0
- package/dist/scripts/runGaslessMemo.d.ts +1 -0
- package/dist/scripts/runGaslessMemo.js +9 -1
- package/dist/scripts/runGaslessWalletDemo.d.ts +1 -0
- package/dist/scripts/runGaslessWalletDemo.js +9 -1
- package/dist/scripts/runKaminoDevnet.d.ts +1 -0
- package/dist/scripts/runKaminoDevnet.js +82 -42
- package/dist/scripts/runLpStrategy.d.ts +1 -0
- package/dist/scripts/runMarinadeDevnet.d.ts +1 -0
- package/dist/scripts/runOnchainPolicyGuardDevnet.d.ts +1 -0
- package/dist/scripts/runOnchainPolicyGuardDevnet.js +113 -0
- package/dist/scripts/runOrcaLpDevnet.d.ts +1 -0
- package/dist/scripts/runRaydiumLpDevnet.d.ts +1 -0
- package/dist/scripts/runReleaseReadiness.d.ts +1 -0
- package/dist/scripts/runStakeStrategy.d.ts +1 -0
- package/dist/scripts/runStatus.d.ts +1 -0
- package/dist/scripts/runStatus.js +22 -0
- package/dist/scripts/runStressTest.d.ts +1 -0
- package/dist/scripts/runTradeLoop.d.ts +1 -0
- package/dist/scripts/runUniversalDeFiDemo.d.ts +1 -0
- package/dist/scripts/runYieldStrategy.d.ts +1 -0
- package/dist/scripts/runtimeFactory.d.ts +8 -0
- package/dist/scripts/shared.d.ts +3 -0
- package/dist/scripts/shared.js +1 -0
- package/dist/scripts/simulateAttack.d.ts +1 -0
- package/dist/scripts/simulateSwarm.d.ts +1 -0
- package/dist/simulation/attack.d.ts +8 -0
- package/dist/solana/memoLedger.d.ts +33 -0
- package/dist/solana/memoLedger.js +205 -0
- package/dist/solana/programs.d.ts +6 -0
- package/dist/spl/TokenWallet.d.ts +18 -0
- package/dist/types/policy.d.ts +23 -0
- package/dist/wallet/WalletManager.d.ts +1 -0
- package/dist/zk/PolicyCircuit.d.ts +48 -0
- package/dist/zk/PolicyCircuit.js +171 -0
- package/dist/zk/ProofAnchor.d.ts +33 -0
- package/dist/zk/ProofAnchor.js +109 -0
- package/dist/zkCompression/CompressedCommitmentAnchor.d.ts +31 -0
- package/dist/zkCompression/CompressedCommitmentAnchor.js +90 -0
- package/dist/zkCompression/CompressedDataAccount.d.ts +45 -0
- package/dist/zkCompression/CompressedDataAccount.js +349 -0
- package/dist/zkCompression/LocalPayloadRegistry.d.ts +23 -0
- package/dist/zkCompression/LocalPayloadRegistry.js +53 -0
- package/package.json +20 -4
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -11,10 +11,18 @@ async function main() {
|
|
|
11
11
|
const walletManager = managed.walletManager;
|
|
12
12
|
const koraSigner = (0, shared_1.createKoraSigner)();
|
|
13
13
|
const result = await koraSigner.submitGaslessMemo(walletManager, "PRKT gasless memo verification");
|
|
14
|
+
const modeLabel = result.fallbackReason
|
|
15
|
+
? "mock-fallback"
|
|
16
|
+
: result.mock
|
|
17
|
+
? "mock"
|
|
18
|
+
: "live";
|
|
14
19
|
console.log("Gasless memo verification complete.");
|
|
15
20
|
(0, managedAgentWallet_1.logManagedAgentWallet)(managed);
|
|
16
21
|
console.log(`Signature: ${result.signature}`);
|
|
17
|
-
console.log(`Mode: ${
|
|
22
|
+
console.log(`Mode: ${modeLabel}`);
|
|
23
|
+
if (result.fallbackReason) {
|
|
24
|
+
console.log(`Fallback reason: ${result.fallbackReason}`);
|
|
25
|
+
}
|
|
18
26
|
}
|
|
19
27
|
main().catch((error) => {
|
|
20
28
|
const message = error instanceof Error ? error.message : "Unknown error";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -45,11 +45,19 @@ async function main() {
|
|
|
45
45
|
console.log("KORA_MOCK_MODE=true. The script will show the same fee-abstraction flow, but the signature is simulated.");
|
|
46
46
|
}
|
|
47
47
|
const result = await koraSigner.submitGaslessMemo(walletManager, "PRKT gasless agent check (USDC-backed fee abstraction)");
|
|
48
|
+
const modeLabel = result.fallbackReason
|
|
49
|
+
? "mock-fallback"
|
|
50
|
+
: result.mock
|
|
51
|
+
? "mock"
|
|
52
|
+
: "live";
|
|
48
53
|
(0, mode_1.printDemoMode)(result.mock ? "SIMULATED" : "LIVE", "Gasless memo transport");
|
|
49
54
|
const endingSolLamports = await connection.getBalance(walletManager.publicKey, "confirmed");
|
|
50
55
|
console.log("Gasless execution complete.");
|
|
51
56
|
console.log(`Signature: ${result.signature}`);
|
|
52
|
-
console.log(`Mode: ${
|
|
57
|
+
console.log(`Mode: ${modeLabel}`);
|
|
58
|
+
if (result.fallbackReason) {
|
|
59
|
+
console.log(`Fallback reason: ${result.fallbackReason}`);
|
|
60
|
+
}
|
|
53
61
|
console.log(`Ending SOL balance (lamports): ${endingSolLamports}`);
|
|
54
62
|
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
63
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function summarizeKaminoFailure(reason: string, simulationLogs?: string): string;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.summarizeKaminoFailure = summarizeKaminoFailure;
|
|
3
4
|
const web3_js_1 = require("@solana/web3.js");
|
|
5
|
+
const policyFactory_1 = require("../agent/policyFactory");
|
|
4
6
|
const agentPolicies_1 = require("../config/agentPolicies");
|
|
5
7
|
const env_1 = require("../config/env");
|
|
6
8
|
const BalanceService_1 = require("../core/balances/BalanceService");
|
|
@@ -8,12 +10,14 @@ const DevnetFundingService_1 = require("../core/funding/DevnetFundingService");
|
|
|
8
10
|
const RpcClient_1 = require("../core/rpc/RpcClient");
|
|
9
11
|
const TokenService_1 = require("../core/tokens/TokenService");
|
|
10
12
|
const TransactionService_1 = require("../core/transactions/TransactionService");
|
|
13
|
+
const DeFiExecutor_1 = require("../defi/DeFiExecutor");
|
|
11
14
|
const kaminoLiveConfig_1 = require("../defi/kamino/kaminoLiveConfig");
|
|
12
15
|
const protocols_1 = require("../defi/protocols");
|
|
13
16
|
const liveExecutors_1 = require("../defi/universal/liveExecutors");
|
|
14
17
|
const policy_1 = require("../policy");
|
|
15
18
|
const managedAgentWallet_1 = require("./managedAgentWallet");
|
|
16
19
|
const mode_1 = require("./mode");
|
|
20
|
+
const shared_1 = require("./shared");
|
|
17
21
|
const DEFAULT_AGENT_NAME = "kamino-live-devnet";
|
|
18
22
|
async function main() {
|
|
19
23
|
const action = parseAction(process.argv[2]);
|
|
@@ -40,49 +44,62 @@ async function main() {
|
|
|
40
44
|
: 0.05,
|
|
41
45
|
publicKey: walletManager.publicKey
|
|
42
46
|
});
|
|
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
47
|
console.log("PRKT Kamino live demo");
|
|
67
48
|
(0, managedAgentWallet_1.logManagedAgentWallet)(managed);
|
|
68
49
|
console.log(`Market: ${config.marketAddress}`);
|
|
69
50
|
console.log(`Program: ${config.programId}`);
|
|
70
51
|
console.log(`Action: ${action}`);
|
|
71
52
|
console.log(`Amount (raw): ${action === "deposit" ? config.actions.depositAmountRaw : config.actions.borrowAmountRaw}`);
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
53
|
+
try {
|
|
54
|
+
const prepared = await (0, liveExecutors_1.prepareLiveKamino)({
|
|
55
|
+
intent: {
|
|
56
|
+
action,
|
|
57
|
+
amountLamports: 0,
|
|
58
|
+
marketId: protocols_1.PROTOCOL_PRESETS.kamino.defaultMarketId,
|
|
59
|
+
memo: `LIVE:KAMINO:${action}`,
|
|
60
|
+
protocol: "kamino",
|
|
61
|
+
slippageBps: 40
|
|
62
|
+
},
|
|
63
|
+
logger: (message) => console.log(`[kamino-live] ${message}`),
|
|
64
|
+
walletManager
|
|
65
|
+
});
|
|
66
|
+
if (!prepared) {
|
|
67
|
+
throw new Error("Kamino live execution was not prepared. Check ENABLE_LIVE_KAMINO and config.");
|
|
68
|
+
}
|
|
69
|
+
const policyEngine = new policy_1.PolicyEngine((0, agentPolicies_1.createDefaultPolicyConfig)({
|
|
70
|
+
allowOpaqueProgramIds: prepared.policyConfigPatch?.rules?.allowOpaqueProgramIds,
|
|
71
|
+
agentId: managed.agent.name,
|
|
72
|
+
allowedCloseAccountDestinations: prepared.policyConfigPatch?.rules?.allowedCloseAccountDestinations,
|
|
73
|
+
approvalMode: "sandbox",
|
|
74
|
+
extraAllowedProgramIds: prepared.policyConfigPatch?.rules?.allowedProgramIds ?? [config.programId]
|
|
75
|
+
}));
|
|
76
|
+
const sandboxExecutor = new policy_1.SandboxExecutor(policyEngine, transactionService, "sandbox");
|
|
77
|
+
const execution = await sandboxExecutor.executePreparedTransaction({
|
|
78
|
+
confirmationStrategy: prepared.confirmationStrategy,
|
|
79
|
+
inspectionContext: prepared.inspectionContext,
|
|
80
|
+
transaction: prepared.transaction
|
|
81
|
+
});
|
|
82
|
+
if (!execution.signature) {
|
|
83
|
+
const simulationLogs = execution.simulationLogs?.join(" | ");
|
|
84
|
+
throw new Error(`Guarded Kamino execution blocked: ${summarizeKaminoFailure(execution.inspection.reasons.join("; "), simulationLogs) ||
|
|
85
|
+
"unknown reason"}${simulationLogs ? ` | simulation logs: ${simulationLogs}` : ""}`);
|
|
86
|
+
}
|
|
87
|
+
if (prepared.verifyExecution) {
|
|
88
|
+
await prepared.verifyExecution(execution.signature);
|
|
89
|
+
}
|
|
90
|
+
console.log("Mode: live");
|
|
91
|
+
console.log(`Transaction signature: ${execution.signature}`);
|
|
81
92
|
}
|
|
82
|
-
|
|
83
|
-
|
|
93
|
+
catch (error) {
|
|
94
|
+
const reason = error instanceof Error ? error.message : "unknown Kamino live error";
|
|
95
|
+
const signature = await executeSimulatedKaminoFallback({
|
|
96
|
+
action,
|
|
97
|
+
walletManager
|
|
98
|
+
});
|
|
99
|
+
console.log("Mode: simulated-fallback");
|
|
100
|
+
console.log(`Fallback reason: ${summarizeKaminoFailure(reason)}`);
|
|
101
|
+
console.log(`Transaction signature: ${signature}`);
|
|
84
102
|
}
|
|
85
|
-
console.log(`Transaction signature: ${execution.signature}`);
|
|
86
103
|
}
|
|
87
104
|
function parseAction(rawValue) {
|
|
88
105
|
if (!rawValue || rawValue === "deposit") {
|
|
@@ -94,16 +111,39 @@ function parseAction(rawValue) {
|
|
|
94
111
|
throw new Error(`Unsupported action '${rawValue}'. Use 'deposit' or 'borrow'.`);
|
|
95
112
|
}
|
|
96
113
|
function summarizeKaminoFailure(reason, simulationLogs) {
|
|
97
|
-
if (simulationLogs?.includes("ReserveStale")) {
|
|
114
|
+
if (reason.includes("ReserveStale") || simulationLogs?.includes("ReserveStale")) {
|
|
98
115
|
return "reserve refresh is currently broken on the selected devnet market";
|
|
99
116
|
}
|
|
100
|
-
if (simulationLogs?.includes("InvalidOracleConfig")) {
|
|
117
|
+
if (reason.includes("InvalidOracleConfig") || simulationLogs?.includes("InvalidOracleConfig")) {
|
|
101
118
|
return "the selected devnet market has invalid oracle configuration";
|
|
102
119
|
}
|
|
103
120
|
return reason;
|
|
104
121
|
}
|
|
105
|
-
|
|
106
|
-
const
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
}
|
|
122
|
+
async function executeSimulatedKaminoFallback(input) {
|
|
123
|
+
const executor = new DeFiExecutor_1.DeFiExecutor((0, policyFactory_1.createDefaultAgentPolicy)({
|
|
124
|
+
maxSpend: {
|
|
125
|
+
lamports: 1_000_000_000
|
|
126
|
+
}
|
|
127
|
+
}));
|
|
128
|
+
const result = await executor.executeIntent({
|
|
129
|
+
intent: {
|
|
130
|
+
action: input.action,
|
|
131
|
+
amountLamports: 0,
|
|
132
|
+
expectedHealthFactor: input.action === "borrow" ? 2.2 : 2.0,
|
|
133
|
+
marketId: protocols_1.PROTOCOL_PRESETS.kamino.defaultMarketId,
|
|
134
|
+
memo: `DEFI_INTENT:KAMINO:${input.action}:DEVNET_FALLBACK`,
|
|
135
|
+
protocol: "kamino",
|
|
136
|
+
slippageBps: 40
|
|
137
|
+
},
|
|
138
|
+
koraSigner: (0, shared_1.createKoraSigner)(),
|
|
139
|
+
walletManager: input.walletManager
|
|
140
|
+
});
|
|
141
|
+
return result.signature;
|
|
142
|
+
}
|
|
143
|
+
if (require.main === module) {
|
|
144
|
+
main().catch((error) => {
|
|
145
|
+
const message = error instanceof Error ? error.message : "Unknown error";
|
|
146
|
+
console.error(`Kamino live demo failed: ${message}`);
|
|
147
|
+
process.exitCode = 1;
|
|
148
|
+
});
|
|
149
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,113 @@
|
|
|
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 RpcClient_1 = require("../core/rpc/RpcClient");
|
|
6
|
+
const TransactionService_1 = require("../core/transactions/TransactionService");
|
|
7
|
+
const WalletManager_1 = require("../core/wallet/WalletManager");
|
|
8
|
+
const onchain_1 = require("../onchain");
|
|
9
|
+
async function main() {
|
|
10
|
+
const rpcClient = new RpcClient_1.RpcClient((0, env_1.getRpcUrl)(), "confirmed");
|
|
11
|
+
const transactionService = new TransactionService_1.TransactionService(rpcClient);
|
|
12
|
+
const treasuryWallet = WalletManager_1.WalletManager.loadOrGenerate();
|
|
13
|
+
const treasurySigner = treasuryWallet.payer;
|
|
14
|
+
const operatorSigner = web3_js_1.Keypair.generate();
|
|
15
|
+
const operatorWallet = WalletManager_1.WalletManager.fromSecretKey(operatorSigner.secretKey, "generated");
|
|
16
|
+
const programId = (0, onchain_1.resolvePolicyGuardProgramId)();
|
|
17
|
+
const amountLamports = 5000000n;
|
|
18
|
+
const operatorFundingLamports = 50000000n;
|
|
19
|
+
const sessionId = (0, onchain_1.createSessionId)(`prkt-onchain-${Date.now()}`);
|
|
20
|
+
const recipient = web3_js_1.Keypair.generate().publicKey;
|
|
21
|
+
const operatorFundingInstruction = transactionService.buildSolTransferInstruction({
|
|
22
|
+
from: treasurySigner.publicKey,
|
|
23
|
+
to: operatorSigner.publicKey,
|
|
24
|
+
lamports: Number(operatorFundingLamports)
|
|
25
|
+
});
|
|
26
|
+
const operatorFundingTx = await transactionService.buildTransaction({
|
|
27
|
+
feePayer: treasurySigner.publicKey,
|
|
28
|
+
instructions: [operatorFundingInstruction],
|
|
29
|
+
signer: treasuryWallet
|
|
30
|
+
});
|
|
31
|
+
const operatorFundingResult = await transactionService.sendAndConfirm(operatorFundingTx);
|
|
32
|
+
console.log(`operator funded: ${operatorFundingResult.signature}`);
|
|
33
|
+
const { policyPda, vaultPda, instruction: initializePolicy } = (0, onchain_1.buildInitializePolicyInstruction)({
|
|
34
|
+
owner: operatorSigner.publicKey,
|
|
35
|
+
verifier: operatorSigner.publicKey,
|
|
36
|
+
dailySpendLimitLamports: 25000000n,
|
|
37
|
+
sessionTtlMinutes: 30,
|
|
38
|
+
allowedPrograms: [programId],
|
|
39
|
+
allowedRecipients: [recipient]
|
|
40
|
+
});
|
|
41
|
+
const policyAccount = await rpcClient.getAccountInfo(policyPda);
|
|
42
|
+
if (!policyAccount) {
|
|
43
|
+
const initializeTx = await transactionService.buildTransaction({
|
|
44
|
+
feePayer: operatorSigner.publicKey,
|
|
45
|
+
instructions: [initializePolicy],
|
|
46
|
+
signer: operatorWallet
|
|
47
|
+
});
|
|
48
|
+
const initializeResult = await transactionService.sendAndConfirm(initializeTx);
|
|
49
|
+
console.log(`policy initialized: ${initializeResult.signature}`);
|
|
50
|
+
}
|
|
51
|
+
else {
|
|
52
|
+
console.log(`policy already exists: ${policyPda.toBase58()}`);
|
|
53
|
+
}
|
|
54
|
+
const fundInstruction = transactionService.buildSolTransferInstruction({
|
|
55
|
+
from: operatorSigner.publicKey,
|
|
56
|
+
to: vaultPda,
|
|
57
|
+
lamports: Number(amountLamports * 2n)
|
|
58
|
+
});
|
|
59
|
+
const fundTx = await transactionService.buildTransaction({
|
|
60
|
+
feePayer: operatorSigner.publicKey,
|
|
61
|
+
instructions: [fundInstruction],
|
|
62
|
+
signer: operatorWallet
|
|
63
|
+
});
|
|
64
|
+
const fundResult = await transactionService.sendAndConfirm(fundTx);
|
|
65
|
+
console.log(`vault funded: ${fundResult.signature}`);
|
|
66
|
+
const { sessionPda, instruction: openSession } = (0, onchain_1.buildOpenSessionInstruction)({
|
|
67
|
+
owner: operatorSigner.publicKey,
|
|
68
|
+
sessionId
|
|
69
|
+
});
|
|
70
|
+
const openTx = await transactionService.buildTransaction({
|
|
71
|
+
feePayer: operatorSigner.publicKey,
|
|
72
|
+
instructions: [openSession],
|
|
73
|
+
signer: operatorWallet
|
|
74
|
+
});
|
|
75
|
+
const openResult = await transactionService.sendAndConfirm(openTx);
|
|
76
|
+
console.log(`session opened: ${openResult.signature}`);
|
|
77
|
+
const execute = (0, onchain_1.buildManagedTransferInstructions)({
|
|
78
|
+
amountLamports,
|
|
79
|
+
nonce: 0n,
|
|
80
|
+
policyOwner: operatorSigner.publicKey,
|
|
81
|
+
recipient,
|
|
82
|
+
sessionId,
|
|
83
|
+
signer: operatorSigner,
|
|
84
|
+
expiresAtUnix: Math.floor(Date.now() / 1000) + 60
|
|
85
|
+
});
|
|
86
|
+
const executeTx = await transactionService.buildTransaction({
|
|
87
|
+
feePayer: operatorSigner.publicKey,
|
|
88
|
+
instructions: [execute.ed25519Instruction, execute.programInstruction],
|
|
89
|
+
signer: operatorWallet
|
|
90
|
+
});
|
|
91
|
+
const executeResult = await transactionService.sendAndConfirm(executeTx);
|
|
92
|
+
console.log(`managed transfer executed: ${executeResult.signature}`);
|
|
93
|
+
console.log(`recipient: ${recipient.toBase58()}`);
|
|
94
|
+
console.log(`policy: ${policyPda.toBase58()}`);
|
|
95
|
+
console.log(`vault: ${vaultPda.toBase58()}`);
|
|
96
|
+
console.log(`session: ${sessionPda.toBase58()}`);
|
|
97
|
+
const { instruction: closeSession } = (0, onchain_1.buildCloseSessionInstruction)({
|
|
98
|
+
owner: operatorSigner.publicKey,
|
|
99
|
+
sessionId
|
|
100
|
+
});
|
|
101
|
+
const closeTx = await transactionService.buildTransaction({
|
|
102
|
+
feePayer: operatorSigner.publicKey,
|
|
103
|
+
instructions: [closeSession],
|
|
104
|
+
signer: operatorWallet
|
|
105
|
+
});
|
|
106
|
+
const closeResult = await transactionService.sendAndConfirm(closeTx);
|
|
107
|
+
console.log(`session closed: ${closeResult.signature}`);
|
|
108
|
+
}
|
|
109
|
+
main().catch((error) => {
|
|
110
|
+
console.error("onchain policy-guard demo failed");
|
|
111
|
+
console.error(error instanceof Error ? error.message : error);
|
|
112
|
+
process.exitCode = 1;
|
|
113
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,22 @@
|
|
|
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 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
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { SwapExecutor } from "../dex/SwapExecutor";
|
|
2
|
+
import type { GuardedPreparedTransactionExecutor } from "../defi/universal";
|
|
3
|
+
export declare function createLiveSwapConfig(): {
|
|
4
|
+
guardedExecutor?: GuardedPreparedTransactionExecutor;
|
|
5
|
+
enabled: boolean;
|
|
6
|
+
outputMint: string;
|
|
7
|
+
swapExecutor: SwapExecutor | null;
|
|
8
|
+
};
|
package/dist/scripts/shared.js
CHANGED
|
@@ -19,6 +19,7 @@ function createKoraSigner() {
|
|
|
19
19
|
console.log(`[runtime] Live swap path: ${(0, env_1.isLiveSwapPathEnabled)()}`);
|
|
20
20
|
console.log(`[runtime] Jupiter API: ${(0, env_1.getJupiterApiBaseUrl)()}`);
|
|
21
21
|
return new KoraSigner_1.KoraSigner(new KoraRpcClient_1.KoraRpcClient(koraRpcUrl), {
|
|
22
|
+
fallbackToMockOnError: true,
|
|
22
23
|
mockMode
|
|
23
24
|
});
|
|
24
25
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { VersionedTransaction } from "@solana/web3.js";
|
|
2
|
+
import { PolicyGuard } from "../policy/PolicyGuard";
|
|
3
|
+
import { WalletManager } from "../wallet/WalletManager";
|
|
4
|
+
export declare function createCompromisedDrainTransaction(walletManager: WalletManager): {
|
|
5
|
+
recipient: string;
|
|
6
|
+
transaction: VersionedTransaction;
|
|
7
|
+
};
|
|
8
|
+
export declare function simulateAttack(policyGuard: PolicyGuard, walletManager: WalletManager): string;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type Connection, type Keypair, type ParsedTransactionWithMeta, Transaction } from "@solana/web3.js";
|
|
2
|
+
export declare const DEFAULT_MEMO_COMPUTE_UNIT_LIMIT = 1000000;
|
|
3
|
+
export type MemoSearchResult<T> = {
|
|
4
|
+
payload: T;
|
|
5
|
+
signature: string;
|
|
6
|
+
slot: number;
|
|
7
|
+
};
|
|
8
|
+
export declare function buildExplorerTxUrl(signature: string, rpcEndpoint: string): string;
|
|
9
|
+
export declare function decodeMemoPayload<T>(transaction: ParsedTransactionWithMeta, isExpectedPayload?: (value: unknown) => value is T): T | null;
|
|
10
|
+
export declare function findMemoEntry<T>(input: {
|
|
11
|
+
connection: Connection;
|
|
12
|
+
isExpectedPayload?: (value: unknown) => value is T;
|
|
13
|
+
limit?: number;
|
|
14
|
+
matches: (payload: T) => boolean;
|
|
15
|
+
}): Promise<MemoSearchResult<T> | null>;
|
|
16
|
+
export declare function findMemoEntries<T>(input: {
|
|
17
|
+
connection: Connection;
|
|
18
|
+
isExpectedPayload?: (value: unknown) => value is T;
|
|
19
|
+
limit?: number;
|
|
20
|
+
matches: (payload: T) => boolean;
|
|
21
|
+
}): Promise<MemoSearchResult<T>[]>;
|
|
22
|
+
export declare function sendMemoPayload<T>(input: {
|
|
23
|
+
connection: Connection;
|
|
24
|
+
payload: T;
|
|
25
|
+
payer: Keypair;
|
|
26
|
+
}): Promise<{
|
|
27
|
+
signature: string;
|
|
28
|
+
slot: number;
|
|
29
|
+
}>;
|
|
30
|
+
export declare function buildMemoTransaction<T>(input: {
|
|
31
|
+
payload: T;
|
|
32
|
+
payer: Keypair;
|
|
33
|
+
}): Transaction;
|