@prktsol/prkt 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env.devnet.all-protocols.example +18 -0
- package/.env.devnet.autonomous.example +16 -0
- package/.env.devnet.jupiter.example +16 -0
- package/.env.devnet.kamino.example +17 -0
- package/.env.devnet.marinade.example +16 -0
- package/.env.devnet.orca.example +16 -0
- package/.env.devnet.raydium.example +17 -0
- package/.env.example +32 -0
- package/ARCHITECTURE.md +159 -0
- package/CLI.md +509 -0
- package/CLI_QUICKSTART.md +108 -0
- package/COMPATIBILITY.md +103 -0
- package/DEVNET_PROTOCOL_ADDRESSES.md +72 -0
- package/README.md +339 -0
- package/dist/agent/AgentManager.js +166 -0
- package/dist/agent/AgentRuntime.js +92 -0
- package/dist/agent/DecisionEngine.js +95 -0
- package/dist/agent/MockPriceFeed.js +13 -0
- package/dist/agent/intents/types.js +2 -0
- package/dist/agent/new-index.js +17 -0
- package/dist/agent/policyFactory.js +54 -0
- package/dist/agent/registry/AgentRegistry.js +16 -0
- package/dist/agent/runner/AgentRunner.js +266 -0
- package/dist/agent/strategies/MemoHeartbeatStrategy.js +15 -0
- package/dist/agent/strategies/SimpleScriptedTransferStrategy.js +27 -0
- package/dist/agent/strategies/TokenRebalancerStrategy.js +35 -0
- package/dist/agent/strategies/TreasuryDistributorStrategy.js +29 -0
- package/dist/agent/strategies/UniversalDeFiStrategy.js +19 -0
- package/dist/agent/types/AgentContext.js +2 -0
- package/dist/cli/index.js +1159 -0
- package/dist/cli/services/activityStore.js +42 -0
- package/dist/cli/services/agentRegistry.js +123 -0
- package/dist/cli/services/agentRuntime.js +55 -0
- package/dist/cli/services/storagePaths.js +64 -0
- package/dist/cli/services/strategyFactory.js +66 -0
- package/dist/cli/services/walletCrypto.js +120 -0
- package/dist/cli/services/walletRegistry.js +145 -0
- package/dist/cli/types.js +2 -0
- package/dist/cli/utils/completion.js +62 -0
- package/dist/cli/utils/output.js +44 -0
- package/dist/config/agentPolicies.js +37 -0
- package/dist/config/env.js +249 -0
- package/dist/config/policyPresets.js +105 -0
- package/dist/core/balances/BalanceService.js +34 -0
- package/dist/core/funding/DevnetFundingService.js +105 -0
- package/dist/core/idempotency/ExecutionIdempotencyGuard.js +100 -0
- package/dist/core/index.js +19 -0
- package/dist/core/rpc/RpcClient.js +45 -0
- package/dist/core/rpc/RpcFailoverClient.js +97 -0
- package/dist/core/tokens/TokenService.js +75 -0
- package/dist/core/transactions/PostTransactionVerifier.js +103 -0
- package/dist/core/transactions/TransactionService.js +104 -0
- package/dist/core/types/services.js +2 -0
- package/dist/core/wallet/WalletManager.js +120 -0
- package/dist/defi/DeFiCoordinator.js +93 -0
- package/dist/defi/DeFiExecutor.js +29 -0
- package/dist/defi/DeFiPolicyGuard.js +31 -0
- package/dist/defi/adapters/JupiterAdapter.js +25 -0
- package/dist/defi/adapters/KaminoAdapter.js +50 -0
- package/dist/defi/adapters/MarinadeAdapter.js +25 -0
- package/dist/defi/adapters/RaydiumAdapter.js +45 -0
- package/dist/defi/kamino/kaminoInstructionCompat.js +24 -0
- package/dist/defi/kamino/kaminoLiveConfig.js +60 -0
- package/dist/defi/kamino/loadKaminoMarketWithFallback.js +68 -0
- package/dist/defi/lp/LpInstructionBuilder.js +2 -0
- package/dist/defi/lp/RaydiumLpInstructionBuilder.js +100 -0
- package/dist/defi/lp/raydiumDevnetConfig.js +62 -0
- package/dist/defi/protocols.js +29 -0
- package/dist/defi/types.js +2 -0
- package/dist/defi/universal/UniversalDeFiOrchestrator.js +126 -0
- package/dist/defi/universal/adapters.js +73 -0
- package/dist/defi/universal/index.js +5 -0
- package/dist/defi/universal/liveExecutors.js +394 -0
- package/dist/defi/universal/types.js +2 -0
- package/dist/demo/scenarios/multiAgentDevnetScenario.js +170 -0
- package/dist/demo/scripts/runMultiAgentDevnetDemo.js +17 -0
- package/dist/dex/JupiterSwapClient.js +59 -0
- package/dist/dex/SwapExecutor.js +52 -0
- package/dist/index.js +22 -0
- package/dist/kora/KoraRpcClient.js +60 -0
- package/dist/kora/KoraSigner.js +57 -0
- package/dist/kora/gaslessDemo.js +18 -0
- package/dist/policy/PolicyGuard.js +158 -0
- package/dist/policy/emergencyLock.js +164 -0
- package/dist/policy/engine/PolicyEngine.js +237 -0
- package/dist/policy/errors.js +10 -0
- package/dist/policy/index.js +7 -0
- package/dist/policy/sandbox/SandboxExecutor.js +77 -0
- package/dist/policy/types/policy.js +2 -0
- package/dist/scripts/devnetFunding.js +28 -0
- package/dist/scripts/devnetWalletPreflight.js +16 -0
- package/dist/scripts/localnetCheck.js +27 -0
- package/dist/scripts/managedAgentWallet.js +81 -0
- package/dist/scripts/mode.js +6 -0
- package/dist/scripts/releaseReadiness.js +93 -0
- package/dist/scripts/runAgentUniversalDeFi.js +115 -0
- package/dist/scripts/runAutonomousAgentWalletDevnet.js +154 -0
- package/dist/scripts/runAutonomousPortfolioDevnet.js +390 -0
- package/dist/scripts/runBorrowStrategy.js +35 -0
- package/dist/scripts/runDeFiSuite.js +41 -0
- package/dist/scripts/runDemoRehearsal.js +111 -0
- package/dist/scripts/runDevnetWalletDemo.js +53 -0
- package/dist/scripts/runGaslessMemo.js +23 -0
- package/dist/scripts/runGaslessWalletDemo.js +60 -0
- package/dist/scripts/runKaminoDevnet.js +109 -0
- package/dist/scripts/runLpStrategy.js +32 -0
- package/dist/scripts/runMarinadeDevnet.js +97 -0
- package/dist/scripts/runOrcaLpDevnet.js +208 -0
- package/dist/scripts/runRaydiumLpDevnet.js +95 -0
- package/dist/scripts/runReleaseReadiness.js +22 -0
- package/dist/scripts/runStakeStrategy.js +33 -0
- package/dist/scripts/runStressTest.js +41 -0
- package/dist/scripts/runTradeLoop.js +53 -0
- package/dist/scripts/runUniversalDeFiDemo.js +84 -0
- package/dist/scripts/runYieldStrategy.js +33 -0
- package/dist/scripts/runtimeFactory.js +27 -0
- package/dist/scripts/shared.js +24 -0
- package/dist/scripts/simulateAttack.js +40 -0
- package/dist/scripts/simulateSwarm.js +106 -0
- package/dist/simulation/attack.js +30 -0
- package/dist/solana/programs.js +9 -0
- package/dist/spl/TokenWallet.js +65 -0
- package/dist/types/policy.js +2 -0
- package/dist/wallet/WalletManager.js +5 -0
- package/package.json +99 -0
|
@@ -0,0 +1,390 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const common_sdk_1 = require("@orca-so/common-sdk");
|
|
7
|
+
const whirlpools_sdk_1 = require("@orca-so/whirlpools-sdk");
|
|
8
|
+
const spl_token_1 = require("@solana/spl-token");
|
|
9
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
10
|
+
const decimal_js_1 = __importDefault(require("decimal.js"));
|
|
11
|
+
const MockPriceFeed_1 = require("../agent/MockPriceFeed");
|
|
12
|
+
const AgentRuntime_1 = require("../agent/AgentRuntime");
|
|
13
|
+
const policyFactory_1 = require("../agent/policyFactory");
|
|
14
|
+
const agentPolicies_1 = require("../config/agentPolicies");
|
|
15
|
+
const env_1 = require("../config/env");
|
|
16
|
+
const BalanceService_1 = require("../core/balances/BalanceService");
|
|
17
|
+
const DevnetFundingService_1 = require("../core/funding/DevnetFundingService");
|
|
18
|
+
const RpcClient_1 = require("../core/rpc/RpcClient");
|
|
19
|
+
const TokenService_1 = require("../core/tokens/TokenService");
|
|
20
|
+
const TransactionService_1 = require("../core/transactions/TransactionService");
|
|
21
|
+
const DeFiExecutor_1 = require("../defi/DeFiExecutor");
|
|
22
|
+
const kaminoLiveConfig_1 = require("../defi/kamino/kaminoLiveConfig");
|
|
23
|
+
const protocols_1 = require("../defi/protocols");
|
|
24
|
+
const liveExecutors_1 = require("../defi/universal/liveExecutors");
|
|
25
|
+
const PolicyGuard_1 = require("../policy/PolicyGuard");
|
|
26
|
+
const policy_1 = require("../policy");
|
|
27
|
+
const shared_1 = require("./shared");
|
|
28
|
+
const managedAgentWallet_1 = require("./managedAgentWallet");
|
|
29
|
+
const mode_1 = require("./mode");
|
|
30
|
+
const DEFAULT_AGENT_NAME = "autonomous-portfolio-devnet";
|
|
31
|
+
const REQUIRED_FUNDING_SOL = 1.0;
|
|
32
|
+
const DEFAULT_SWAP_SOL = 0.01;
|
|
33
|
+
const DEFAULT_ORCA_LP_SOL = 0.05;
|
|
34
|
+
const ORCA_DEVNET_PROGRAM_ID = new web3_js_1.PublicKey("whirLbMiicVdio4qvUfM5KAg6Ct8VwpYzGff3uctyCc");
|
|
35
|
+
const ORCA_DEVNET_CONFIG = new web3_js_1.PublicKey("FcrweFY1G9HJAHG5inkGB6pKg1HZ6x9UC2WioAfWrGkR");
|
|
36
|
+
const ORCA_DEVNET_USDC_MINT = new web3_js_1.PublicKey("BRjpCHtyQLNCo8gqRUr8jtdAj5AjPYQaoqbvcZiHok1k");
|
|
37
|
+
const ORCA_DEVNET_TICK_SPACING = 64;
|
|
38
|
+
async function main() {
|
|
39
|
+
(0, mode_1.printDemoMode)("LIVE", "Autonomous portfolio wallet: provision or load the assigned agent wallet, fund on devnet, swap via Jupiter, open Orca LP, then attempt Kamino deposit/borrow live with simulated fallback on devnet");
|
|
40
|
+
const rpcUrl = (0, env_1.getRpcUrl)();
|
|
41
|
+
const cluster = (0, env_1.detectClusterFromRpcUrl)(rpcUrl);
|
|
42
|
+
if (cluster !== "devnet") {
|
|
43
|
+
throw new Error(`Autonomous portfolio demo requires devnet. Current RPC cluster is ${cluster} (${rpcUrl}).`);
|
|
44
|
+
}
|
|
45
|
+
const rpcClient = new RpcClient_1.RpcClient(rpcUrl, "confirmed");
|
|
46
|
+
const tokenService = new TokenService_1.TokenService(rpcClient);
|
|
47
|
+
const balanceService = new BalanceService_1.BalanceService(rpcClient, tokenService);
|
|
48
|
+
const transactionService = new TransactionService_1.TransactionService(rpcClient);
|
|
49
|
+
const fundingService = new DevnetFundingService_1.DevnetFundingService(rpcClient, transactionService);
|
|
50
|
+
const managed = (0, managedAgentWallet_1.resolveManagedAgentWallet)({
|
|
51
|
+
agentName: (0, managedAgentWallet_1.getManagedAgentName)({
|
|
52
|
+
defaultAgentName: DEFAULT_AGENT_NAME,
|
|
53
|
+
env: process.env
|
|
54
|
+
}),
|
|
55
|
+
ownerId: (0, managedAgentWallet_1.getManagedOwnerId)(process.env)
|
|
56
|
+
});
|
|
57
|
+
const walletManager = managed.walletManager;
|
|
58
|
+
console.log("PRKT autonomous portfolio demo");
|
|
59
|
+
console.log(`RPC: ${rpcUrl}`);
|
|
60
|
+
(0, managedAgentWallet_1.logManagedAgentWallet)(managed);
|
|
61
|
+
await (0, managedAgentWallet_1.ensureManagedAgentWalletFunding)({
|
|
62
|
+
balanceService,
|
|
63
|
+
fundingService,
|
|
64
|
+
minimumSol: REQUIRED_FUNDING_SOL,
|
|
65
|
+
publicKey: walletManager.publicKey
|
|
66
|
+
});
|
|
67
|
+
const signatures = [];
|
|
68
|
+
const swapResult = await executeAutonomousSwapIntent({
|
|
69
|
+
amountSol: DEFAULT_SWAP_SOL,
|
|
70
|
+
walletManager
|
|
71
|
+
});
|
|
72
|
+
signatures.push({
|
|
73
|
+
label: swapResult.mode === "LIVE"
|
|
74
|
+
? "Jupiter swap"
|
|
75
|
+
: "Jupiter swap intent (simulated on devnet)",
|
|
76
|
+
signature: swapResult.signature
|
|
77
|
+
});
|
|
78
|
+
const orcaResult = await executeAutonomousOrcaLp({
|
|
79
|
+
balanceService,
|
|
80
|
+
depositAmountSol: DEFAULT_ORCA_LP_SOL,
|
|
81
|
+
rpcClient,
|
|
82
|
+
tokenService,
|
|
83
|
+
transactionService,
|
|
84
|
+
walletManager
|
|
85
|
+
});
|
|
86
|
+
if (orcaResult.tickArrayInitSignature) {
|
|
87
|
+
signatures.push({
|
|
88
|
+
label: "Orca tick arrays",
|
|
89
|
+
signature: orcaResult.tickArrayInitSignature
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
signatures.push({
|
|
93
|
+
label: "Orca LP position",
|
|
94
|
+
signature: orcaResult.signature
|
|
95
|
+
});
|
|
96
|
+
const kaminoDepositResult = await executeKaminoActionWithFallback({
|
|
97
|
+
action: "deposit",
|
|
98
|
+
transactionService,
|
|
99
|
+
walletManager
|
|
100
|
+
});
|
|
101
|
+
signatures.push({
|
|
102
|
+
label: kaminoDepositResult.label,
|
|
103
|
+
signature: kaminoDepositResult.signature
|
|
104
|
+
});
|
|
105
|
+
const kaminoBorrowResult = await executeKaminoActionWithFallback({
|
|
106
|
+
action: "borrow",
|
|
107
|
+
transactionService,
|
|
108
|
+
walletManager
|
|
109
|
+
});
|
|
110
|
+
signatures.push({
|
|
111
|
+
label: kaminoBorrowResult.label,
|
|
112
|
+
signature: kaminoBorrowResult.signature
|
|
113
|
+
});
|
|
114
|
+
const usdcMint = new web3_js_1.PublicKey((0, env_1.getUsdcMintAddress)());
|
|
115
|
+
const solAfter = await balanceService.getSolBalance(walletManager.publicKey);
|
|
116
|
+
const usdcAfter = await balanceService.getSplTokenBalance({
|
|
117
|
+
mint: usdcMint,
|
|
118
|
+
owner: walletManager.publicKey
|
|
119
|
+
});
|
|
120
|
+
console.log("");
|
|
121
|
+
console.log("Autonomous portfolio run");
|
|
122
|
+
for (const entry of signatures) {
|
|
123
|
+
console.log(`${entry.label}: ${entry.signature}`);
|
|
124
|
+
}
|
|
125
|
+
console.log(`Orca position mint: ${orcaResult.positionMint}`);
|
|
126
|
+
console.log(`SOL after: ${solAfter.toFixed(4)}`);
|
|
127
|
+
console.log(`USDC after: ${usdcAfter.toFixed(6)}`);
|
|
128
|
+
}
|
|
129
|
+
async function executeAutonomousSwapIntent(input) {
|
|
130
|
+
const result = await (0, AgentRuntime_1.simulateMarketAction)({
|
|
131
|
+
amountSol: input.amountSol,
|
|
132
|
+
koraSigner: (0, shared_1.createKoraSigner)(),
|
|
133
|
+
liveSwapConfig: {
|
|
134
|
+
enabled: false,
|
|
135
|
+
outputMint: (0, env_1.getUsdcMintAddress)(),
|
|
136
|
+
swapExecutor: null
|
|
137
|
+
},
|
|
138
|
+
logger: (message) => console.log(`[autonomous-jupiter] ${message}`),
|
|
139
|
+
policyGuard: new PolicyGuard_1.PolicyGuard((0, policyFactory_1.createDefaultAgentPolicy)()),
|
|
140
|
+
priceFeed: new MockPriceFeed_1.MockPriceFeed({
|
|
141
|
+
buyThresholdUsd: 100,
|
|
142
|
+
solPriceUsd: 95,
|
|
143
|
+
usdcPriceUsd: 1
|
|
144
|
+
}),
|
|
145
|
+
walletManager: input.walletManager
|
|
146
|
+
});
|
|
147
|
+
if (!result.execution) {
|
|
148
|
+
throw new Error("Autonomous Jupiter swap intent did not produce an execution result.");
|
|
149
|
+
}
|
|
150
|
+
return {
|
|
151
|
+
mode: result.liveSwap && !result.execution.mock ? "LIVE" : "SIMULATED",
|
|
152
|
+
signature: result.execution.signature
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
async function executeLiveKaminoAction(input) {
|
|
156
|
+
const config = (0, kaminoLiveConfig_1.loadKaminoLiveConfig)();
|
|
157
|
+
const prepared = await (0, liveExecutors_1.prepareLiveKamino)({
|
|
158
|
+
intent: {
|
|
159
|
+
action: input.action,
|
|
160
|
+
amountLamports: 0,
|
|
161
|
+
marketId: protocols_1.PROTOCOL_PRESETS.kamino.defaultMarketId,
|
|
162
|
+
memo: `LIVE:KAMINO:${input.action}`,
|
|
163
|
+
protocol: "kamino",
|
|
164
|
+
slippageBps: 40
|
|
165
|
+
},
|
|
166
|
+
logger: (message) => console.log(`[autonomous-kamino] ${message}`),
|
|
167
|
+
walletManager: input.walletManager
|
|
168
|
+
});
|
|
169
|
+
if (!prepared) {
|
|
170
|
+
throw new Error(`Kamino ${input.action} was not prepared. Check ENABLE_LIVE_KAMINO and ${config.marketAddress}.`);
|
|
171
|
+
}
|
|
172
|
+
return executePreparedLive({
|
|
173
|
+
agentId: `autonomous-portfolio-kamino-${input.action}`,
|
|
174
|
+
prepared,
|
|
175
|
+
transactionService: input.transactionService
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
async function executeKaminoActionWithFallback(input) {
|
|
179
|
+
try {
|
|
180
|
+
const signature = await executeLiveKaminoAction(input);
|
|
181
|
+
return {
|
|
182
|
+
label: `Kamino ${input.action}`,
|
|
183
|
+
signature
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
catch (error) {
|
|
187
|
+
const message = error instanceof Error ? error.message : "unknown Kamino live error";
|
|
188
|
+
console.log(`[autonomous-kamino] live ${input.action} failed on devnet (${summarizeKaminoLiveFailure(message)}); falling back to simulated intent`);
|
|
189
|
+
const signature = await executeSimulatedKaminoAction(input);
|
|
190
|
+
return {
|
|
191
|
+
label: `Kamino ${input.action} intent (simulated fallback)`,
|
|
192
|
+
signature
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
async function executeSimulatedKaminoAction(input) {
|
|
197
|
+
const executor = new DeFiExecutor_1.DeFiExecutor((0, policyFactory_1.createDefaultAgentPolicy)({
|
|
198
|
+
maxSpend: {
|
|
199
|
+
lamports: 1_000_000_000
|
|
200
|
+
}
|
|
201
|
+
}));
|
|
202
|
+
const result = await executor.executeIntent({
|
|
203
|
+
intent: {
|
|
204
|
+
action: input.action,
|
|
205
|
+
amountLamports: 0,
|
|
206
|
+
expectedHealthFactor: input.action === "borrow" ? 2.2 : 2.0,
|
|
207
|
+
marketId: protocols_1.PROTOCOL_PRESETS.kamino.defaultMarketId,
|
|
208
|
+
memo: `DEFI_INTENT:KAMINO:${input.action}:DEVNET_FALLBACK`,
|
|
209
|
+
protocol: "kamino",
|
|
210
|
+
slippageBps: 40
|
|
211
|
+
},
|
|
212
|
+
koraSigner: (0, shared_1.createKoraSigner)(),
|
|
213
|
+
walletManager: input.walletManager
|
|
214
|
+
});
|
|
215
|
+
return result.signature;
|
|
216
|
+
}
|
|
217
|
+
function summarizeKaminoLiveFailure(message) {
|
|
218
|
+
if (message.includes("ReserveStale")) {
|
|
219
|
+
return "reserve refresh is currently broken on the selected devnet market";
|
|
220
|
+
}
|
|
221
|
+
if (message.includes("InvalidOracleConfig")) {
|
|
222
|
+
return "the selected devnet market has invalid oracle configuration";
|
|
223
|
+
}
|
|
224
|
+
if (message.includes("simulation failed")) {
|
|
225
|
+
return "transaction simulation failed";
|
|
226
|
+
}
|
|
227
|
+
return message.length > 140 ? `${message.slice(0, 137)}...` : message;
|
|
228
|
+
}
|
|
229
|
+
async function executePreparedLive(input) {
|
|
230
|
+
const policyEngine = new policy_1.PolicyEngine((0, agentPolicies_1.createDefaultPolicyConfig)({
|
|
231
|
+
agentId: input.agentId,
|
|
232
|
+
allowOpaqueProgramIds: input.prepared.policyConfigPatch?.rules?.allowOpaqueProgramIds,
|
|
233
|
+
allowedCloseAccountDestinations: input.prepared.policyConfigPatch?.rules?.allowedCloseAccountDestinations,
|
|
234
|
+
approvalMode: "sandbox",
|
|
235
|
+
extraAllowedProgramIds: input.prepared.policyConfigPatch?.rules?.allowedProgramIds
|
|
236
|
+
}));
|
|
237
|
+
const sandboxExecutor = new policy_1.SandboxExecutor(policyEngine, input.transactionService, "sandbox");
|
|
238
|
+
const execution = await sandboxExecutor.executePreparedTransaction({
|
|
239
|
+
confirmationStrategy: input.prepared.confirmationStrategy,
|
|
240
|
+
inspectionContext: input.prepared.inspectionContext,
|
|
241
|
+
transaction: input.prepared.transaction
|
|
242
|
+
});
|
|
243
|
+
if (!execution.signature) {
|
|
244
|
+
const simulationLogs = execution.simulationLogs?.join(" | ");
|
|
245
|
+
throw new Error(`Guarded ${input.prepared.protocol} execution blocked: ${execution.inspection.reasons.join("; ") || "unknown reason"}${simulationLogs ? ` | simulation logs: ${simulationLogs}` : ""}`);
|
|
246
|
+
}
|
|
247
|
+
if (input.prepared.verifyExecution) {
|
|
248
|
+
await input.prepared.verifyExecution(execution.signature);
|
|
249
|
+
}
|
|
250
|
+
return execution.signature;
|
|
251
|
+
}
|
|
252
|
+
async function executeAutonomousOrcaLp(input) {
|
|
253
|
+
const orcaWallet = new common_sdk_1.ReadOnlyWallet(input.walletManager.publicKey);
|
|
254
|
+
const whirlpoolContext = whirlpools_sdk_1.WhirlpoolContext.from(input.rpcClient.connection, orcaWallet);
|
|
255
|
+
const whirlpoolClient = (0, whirlpools_sdk_1.buildWhirlpoolClient)(whirlpoolContext);
|
|
256
|
+
const whirlpool = await loadSupportedDevnetPool(whirlpoolClient);
|
|
257
|
+
const poolData = whirlpool.getData();
|
|
258
|
+
const poolAddress = whirlpool.getAddress();
|
|
259
|
+
const tokenA = whirlpool.getTokenAInfo();
|
|
260
|
+
const tokenB = whirlpool.getTokenBInfo();
|
|
261
|
+
if (whirlpools_sdk_1.TickUtil.isFullRangeOnly(poolData.tickSpacing)) {
|
|
262
|
+
throw new Error(`Configured Orca pool ${poolAddress.toBase58()} is full-range only (tick spacing ${poolData.tickSpacing}).`);
|
|
263
|
+
}
|
|
264
|
+
const { sideDescription, tickLowerIndex, tickUpperIndex } = deriveOneSidedPositionRange({
|
|
265
|
+
currentTickIndex: poolData.tickCurrentIndex,
|
|
266
|
+
nativeIsTokenA: tokenA.mint.equals(spl_token_1.NATIVE_MINT),
|
|
267
|
+
tickSpacing: poolData.tickSpacing
|
|
268
|
+
});
|
|
269
|
+
const tokenExtensionContext = await whirlpools_sdk_1.TokenExtensionUtil.buildTokenExtensionContextForPool(whirlpoolClient.getFetcher(), tokenA.mint, tokenB.mint);
|
|
270
|
+
const quote = (0, whirlpools_sdk_1.increaseLiquidityQuoteByInputTokenUsingPriceDeviation)(spl_token_1.NATIVE_MINT, new decimal_js_1.default(input.depositAmountSol.toString()), tickLowerIndex, tickUpperIndex, common_sdk_1.Percentage.fromFraction(1, 100), whirlpool, tokenExtensionContext);
|
|
271
|
+
if (quote.liquidityAmount.isZero()) {
|
|
272
|
+
throw new Error(`Orca quote returned zero liquidity for pool ${poolAddress.toBase58()}. Try a different amount or RPC.`);
|
|
273
|
+
}
|
|
274
|
+
const policyEngine = new policy_1.PolicyEngine((0, agentPolicies_1.createDefaultPolicyConfig)({
|
|
275
|
+
agentId: "autonomous-portfolio-orca",
|
|
276
|
+
allowOpaqueProgramIds: [ORCA_DEVNET_PROGRAM_ID.toBase58()],
|
|
277
|
+
allowedCloseAccountDestinations: [input.walletManager.publicKey.toBase58()],
|
|
278
|
+
approvalMode: "sandbox",
|
|
279
|
+
extraAllowedProgramIds: [ORCA_DEVNET_PROGRAM_ID.toBase58()]
|
|
280
|
+
}));
|
|
281
|
+
const sandboxExecutor = new policy_1.SandboxExecutor(policyEngine, input.transactionService, "sandbox");
|
|
282
|
+
const solBefore = await input.balanceService.getSolBalance(input.walletManager.publicKey);
|
|
283
|
+
console.log(`Orca pool: ${poolAddress.toBase58()}`);
|
|
284
|
+
console.log(`Orca range: [${tickLowerIndex}, ${tickUpperIndex}] (${sideDescription})`);
|
|
285
|
+
console.log(`Orca estimated token max A: ${quote.tokenMaxA.toString()}`);
|
|
286
|
+
console.log(`Orca estimated token max B: ${quote.tokenMaxB.toString()}`);
|
|
287
|
+
let tickArrayInitSignature;
|
|
288
|
+
const initTickArrays = await whirlpool.initTickArrayForTicks([tickLowerIndex, tickUpperIndex], input.walletManager.publicKey);
|
|
289
|
+
if (initTickArrays && !initTickArrays.isEmpty()) {
|
|
290
|
+
tickArrayInitSignature = await executeBuilder({
|
|
291
|
+
builder: initTickArrays,
|
|
292
|
+
label: "initialize Orca tick arrays",
|
|
293
|
+
sandboxExecutor,
|
|
294
|
+
walletManager: input.walletManager
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
const { positionMint, tx } = await whirlpool.openPosition(tickLowerIndex, tickUpperIndex, quote, input.walletManager.publicKey, input.walletManager.publicKey);
|
|
298
|
+
const positionTokenAccount = (0, spl_token_1.getAssociatedTokenAddressSync)(positionMint, input.walletManager.publicKey);
|
|
299
|
+
const signature = await executeBuilder({
|
|
300
|
+
builder: tx,
|
|
301
|
+
label: "open Orca position",
|
|
302
|
+
sandboxExecutor,
|
|
303
|
+
walletManager: input.walletManager
|
|
304
|
+
});
|
|
305
|
+
const positionTokenBalance = await readPositionTokenBalance(positionTokenAccount, input.rpcClient);
|
|
306
|
+
if (positionTokenBalance !== 1n) {
|
|
307
|
+
throw new Error(`Orca position verification failed: expected 1 position token, got ${positionTokenBalance.toString()}.`);
|
|
308
|
+
}
|
|
309
|
+
const solAfter = await input.balanceService.getSolBalance(input.walletManager.publicKey);
|
|
310
|
+
console.log(`Orca verified ${signature}: position token balance ${positionTokenBalance.toString()}`);
|
|
311
|
+
console.log(`Orca SOL before: ${solBefore.toFixed(4)}`);
|
|
312
|
+
console.log(`Orca SOL after: ${solAfter.toFixed(4)}`);
|
|
313
|
+
return {
|
|
314
|
+
positionMint: positionMint.toBase58(),
|
|
315
|
+
signature,
|
|
316
|
+
tickArrayInitSignature
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
async function loadSupportedDevnetPool(whirlpoolClient) {
|
|
320
|
+
const candidates = [
|
|
321
|
+
whirlpools_sdk_1.PDAUtil.getWhirlpool(ORCA_DEVNET_PROGRAM_ID, ORCA_DEVNET_CONFIG, spl_token_1.NATIVE_MINT, ORCA_DEVNET_USDC_MINT, ORCA_DEVNET_TICK_SPACING).publicKey,
|
|
322
|
+
whirlpools_sdk_1.PDAUtil.getWhirlpool(ORCA_DEVNET_PROGRAM_ID, ORCA_DEVNET_CONFIG, ORCA_DEVNET_USDC_MINT, spl_token_1.NATIVE_MINT, ORCA_DEVNET_TICK_SPACING).publicKey
|
|
323
|
+
];
|
|
324
|
+
for (const address of candidates) {
|
|
325
|
+
try {
|
|
326
|
+
return await whirlpoolClient.getPool(address);
|
|
327
|
+
}
|
|
328
|
+
catch {
|
|
329
|
+
continue;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
throw new Error(`Could not load the public Orca devnet SOL/devUSDC concentrated pool (tick spacing ${ORCA_DEVNET_TICK_SPACING}).`);
|
|
333
|
+
}
|
|
334
|
+
function deriveOneSidedPositionRange(input) {
|
|
335
|
+
const [minTick, maxTick] = whirlpools_sdk_1.TickUtil.getFullRangeTickIndex(input.tickSpacing);
|
|
336
|
+
const currentTickIndex = whirlpools_sdk_1.TickUtil.getInitializableTickIndex(input.currentTickIndex, input.tickSpacing);
|
|
337
|
+
const width = input.tickSpacing * 128;
|
|
338
|
+
const gap = input.tickSpacing * 64;
|
|
339
|
+
if (input.nativeIsTokenA) {
|
|
340
|
+
const tickLowerIndex = Math.min(Math.max(currentTickIndex + gap, minTick), maxTick - width);
|
|
341
|
+
return {
|
|
342
|
+
sideDescription: "one-sided SOL above current price",
|
|
343
|
+
tickLowerIndex,
|
|
344
|
+
tickUpperIndex: tickLowerIndex + width
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
const tickUpperIndex = Math.max(Math.min(currentTickIndex - gap, maxTick), minTick + width);
|
|
348
|
+
return {
|
|
349
|
+
sideDescription: "one-sided SOL below current price",
|
|
350
|
+
tickLowerIndex: tickUpperIndex - width,
|
|
351
|
+
tickUpperIndex
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
async function executeBuilder(input) {
|
|
355
|
+
const payload = await input.builder.build({
|
|
356
|
+
maxSupportedTransactionVersion: 0
|
|
357
|
+
});
|
|
358
|
+
if (!(payload.transaction instanceof web3_js_1.VersionedTransaction)) {
|
|
359
|
+
throw new Error(`${input.label} did not build a versioned transaction.`);
|
|
360
|
+
}
|
|
361
|
+
if (payload.signers.length > 0) {
|
|
362
|
+
payload.transaction.sign(payload.signers);
|
|
363
|
+
}
|
|
364
|
+
const signedTransaction = await input.walletManager.signTransaction(payload.transaction);
|
|
365
|
+
const execution = await input.sandboxExecutor.executePreparedTransaction({
|
|
366
|
+
confirmationStrategy: {
|
|
367
|
+
blockhash: payload.recentBlockhash.blockhash,
|
|
368
|
+
lastValidBlockHeight: payload.recentBlockhash.lastValidBlockHeight,
|
|
369
|
+
signature: ""
|
|
370
|
+
},
|
|
371
|
+
transaction: signedTransaction
|
|
372
|
+
});
|
|
373
|
+
if (!execution.signature) {
|
|
374
|
+
throw new Error(`${input.label} was blocked: ${execution.inspection.reasons.join("; ") || "unknown reason"}`);
|
|
375
|
+
}
|
|
376
|
+
return execution.signature;
|
|
377
|
+
}
|
|
378
|
+
async function readPositionTokenBalance(tokenAccount, rpcClient) {
|
|
379
|
+
const accountInfo = await rpcClient.getAccountInfo(tokenAccount, "confirmed");
|
|
380
|
+
if (!accountInfo) {
|
|
381
|
+
return 0n;
|
|
382
|
+
}
|
|
383
|
+
const balance = await rpcClient.getTokenAccountBalance(tokenAccount, "confirmed");
|
|
384
|
+
return BigInt(balance.value.amount);
|
|
385
|
+
}
|
|
386
|
+
main().catch((error) => {
|
|
387
|
+
const message = error instanceof Error ? error.message : "Unknown error";
|
|
388
|
+
console.error(`Autonomous portfolio demo failed: ${message}`);
|
|
389
|
+
process.exitCode = 1;
|
|
390
|
+
});
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
4
|
+
const DeFiCoordinator_1 = require("../defi/DeFiCoordinator");
|
|
5
|
+
const managedAgentWallet_1 = require("./managedAgentWallet");
|
|
6
|
+
const shared_1 = require("./shared");
|
|
7
|
+
const mode_1 = require("./mode");
|
|
8
|
+
const DEFAULT_AGENT_NAME = "borrow-strategy";
|
|
9
|
+
async function main() {
|
|
10
|
+
(0, mode_1.printDemoMode)("SIMULATED", "Protocol intent only (memo execution), not live Kamino borrow instructions");
|
|
11
|
+
const managed = (0, managedAgentWallet_1.resolveManagedAgentWallet)({
|
|
12
|
+
agentName: (0, managedAgentWallet_1.getManagedAgentName)({ defaultAgentName: DEFAULT_AGENT_NAME, env: process.env }),
|
|
13
|
+
ownerId: (0, managedAgentWallet_1.getManagedOwnerId)(process.env)
|
|
14
|
+
});
|
|
15
|
+
const coordinator = new DeFiCoordinator_1.DeFiCoordinator(managed.walletManager, (0, shared_1.createKoraSigner)(), (0, shared_1.createRuntimeLogger)("borrow"));
|
|
16
|
+
(0, managedAgentWallet_1.logManagedAgentWallet)(managed);
|
|
17
|
+
const result = await coordinator.runBorrowingStrategy({
|
|
18
|
+
borrowDemandUsdcAtomic: 3_000_000,
|
|
19
|
+
collateralSolLamports: Math.round(1.2 * web3_js_1.LAMPORTS_PER_SOL),
|
|
20
|
+
healthFactor: 2.3
|
|
21
|
+
});
|
|
22
|
+
console.log("Borrow strategy complete.");
|
|
23
|
+
if (!result) {
|
|
24
|
+
console.log("No borrowing action executed.");
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
console.log(`Protocol: ${result.protocol}`);
|
|
28
|
+
console.log(`Action: ${result.action}`);
|
|
29
|
+
console.log(`Signature: ${result.signature}`);
|
|
30
|
+
}
|
|
31
|
+
main().catch((error) => {
|
|
32
|
+
const message = error instanceof Error ? error.message : "Unknown error";
|
|
33
|
+
console.error(`Borrow strategy failed: ${message}`);
|
|
34
|
+
process.exitCode = 1;
|
|
35
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
4
|
+
const DeFiCoordinator_1 = require("../defi/DeFiCoordinator");
|
|
5
|
+
const managedAgentWallet_1 = require("./managedAgentWallet");
|
|
6
|
+
const shared_1 = require("./shared");
|
|
7
|
+
const mode_1 = require("./mode");
|
|
8
|
+
const DEFAULT_AGENT_NAME = "defi-suite";
|
|
9
|
+
async function main() {
|
|
10
|
+
(0, mode_1.printDemoMode)("SIMULATED", "Protocol intents only (memo execution), not live Marinade/Raydium/Kamino instructions");
|
|
11
|
+
const managed = (0, managedAgentWallet_1.resolveManagedAgentWallet)({
|
|
12
|
+
agentName: (0, managedAgentWallet_1.getManagedAgentName)({
|
|
13
|
+
defaultAgentName: DEFAULT_AGENT_NAME,
|
|
14
|
+
env: process.env
|
|
15
|
+
}),
|
|
16
|
+
ownerId: (0, managedAgentWallet_1.getManagedOwnerId)(process.env)
|
|
17
|
+
});
|
|
18
|
+
const coordinator = new DeFiCoordinator_1.DeFiCoordinator(managed.walletManager, (0, shared_1.createKoraSigner)(), (0, shared_1.createRuntimeLogger)("defi"));
|
|
19
|
+
(0, managedAgentWallet_1.logManagedAgentWallet)(managed);
|
|
20
|
+
const results = await coordinator.runFullSuite({
|
|
21
|
+
buyThresholdUsd: 100,
|
|
22
|
+
healthFactor: 2.2,
|
|
23
|
+
idleSolLamports: Math.round(1.0 * web3_js_1.LAMPORTS_PER_SOL),
|
|
24
|
+
idleUsdcAtomic: 5_000_000,
|
|
25
|
+
liquidityInRange: true,
|
|
26
|
+
solPriceUsd: 95
|
|
27
|
+
});
|
|
28
|
+
console.log("DeFi suite complete.");
|
|
29
|
+
if (results.length === 0) {
|
|
30
|
+
console.log("No DeFi actions executed.");
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
for (const result of results) {
|
|
34
|
+
console.log(`${result.protocol}: ${result.action} ${result.signature}`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
main().catch((error) => {
|
|
38
|
+
const message = error instanceof Error ? error.message : "Unknown error";
|
|
39
|
+
console.error(`DeFi suite failed: ${message}`);
|
|
40
|
+
process.exitCode = 1;
|
|
41
|
+
});
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const fs_1 = require("fs");
|
|
7
|
+
const path_1 = __importDefault(require("path"));
|
|
8
|
+
const child_process_1 = require("child_process");
|
|
9
|
+
const env_1 = require("../config/env");
|
|
10
|
+
const env_2 = require("../config/env");
|
|
11
|
+
function runCommand(command, args) {
|
|
12
|
+
const result = (0, child_process_1.spawnSync)([command, ...args].join(" "), {
|
|
13
|
+
shell: true,
|
|
14
|
+
stdio: "inherit"
|
|
15
|
+
});
|
|
16
|
+
return {
|
|
17
|
+
detail: `${command} ${args.join(" ")}`,
|
|
18
|
+
ok: result.status === 0,
|
|
19
|
+
title: `Command ${command}`
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
function runPreflightChecks() {
|
|
23
|
+
const checks = [];
|
|
24
|
+
const rpcUrl = (0, env_1.getRpcUrl)();
|
|
25
|
+
const cluster = (0, env_1.detectClusterFromRpcUrl)(rpcUrl);
|
|
26
|
+
const usdcMint = (0, env_1.getUsdcMintAddress)();
|
|
27
|
+
const secretKey = (0, env_2.getOptionalSecretKey)();
|
|
28
|
+
const remoteSigner = (0, env_1.getRemoteSignerConfig)();
|
|
29
|
+
checks.push({
|
|
30
|
+
detail: rpcUrl,
|
|
31
|
+
ok: cluster === "devnet",
|
|
32
|
+
title: "RPC cluster is devnet"
|
|
33
|
+
});
|
|
34
|
+
try {
|
|
35
|
+
(0, env_1.assertMintMatchesRpcCluster)({
|
|
36
|
+
mintAddress: usdcMint,
|
|
37
|
+
mintName: "USDC_MINT",
|
|
38
|
+
rpcUrl
|
|
39
|
+
});
|
|
40
|
+
checks.push({
|
|
41
|
+
detail: usdcMint,
|
|
42
|
+
ok: true,
|
|
43
|
+
title: "USDC mint matches RPC cluster"
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
checks.push({
|
|
48
|
+
detail: error instanceof Error ? error.message : "mint and cluster mismatch",
|
|
49
|
+
ok: false,
|
|
50
|
+
title: "USDC mint matches RPC cluster"
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
checks.push({
|
|
54
|
+
detail: remoteSigner
|
|
55
|
+
? `remote signer ${remoteSigner.publicKey.toBase58()}`
|
|
56
|
+
: secretKey
|
|
57
|
+
? "local demo key present"
|
|
58
|
+
: "missing signer config",
|
|
59
|
+
ok: Boolean(remoteSigner) || Boolean(secretKey),
|
|
60
|
+
title: "signer configuration is present"
|
|
61
|
+
});
|
|
62
|
+
checks.push({
|
|
63
|
+
detail: "raydium_lp.devnet.json",
|
|
64
|
+
ok: (0, fs_1.existsSync)("raydium_lp.devnet.json"),
|
|
65
|
+
title: "Raydium devnet LP config exists"
|
|
66
|
+
});
|
|
67
|
+
checks.push(runCommand("npm", ["run", "release:check"]));
|
|
68
|
+
return checks;
|
|
69
|
+
}
|
|
70
|
+
function writeSessionArtifact(checks) {
|
|
71
|
+
const artifactDir = path_1.default.join(process.cwd(), "artifacts");
|
|
72
|
+
if (!(0, fs_1.existsSync)(artifactDir)) {
|
|
73
|
+
(0, fs_1.mkdirSync)(artifactDir, { recursive: true });
|
|
74
|
+
}
|
|
75
|
+
const artifactPath = path_1.default.join(artifactDir, "demo-session.json");
|
|
76
|
+
const payload = {
|
|
77
|
+
cluster: (0, env_1.detectClusterFromRpcUrl)((0, env_1.getRpcUrl)()),
|
|
78
|
+
generatedAtIso8601: new Date().toISOString(),
|
|
79
|
+
recommendedLiveRunOrder: [
|
|
80
|
+
"npm run wallet:devnet",
|
|
81
|
+
"npm run defi:lp:devnet",
|
|
82
|
+
"npm run simulate-attack",
|
|
83
|
+
"npm run stress:agents"
|
|
84
|
+
],
|
|
85
|
+
checks
|
|
86
|
+
};
|
|
87
|
+
(0, fs_1.writeFileSync)(artifactPath, JSON.stringify(payload, null, 2), "utf8");
|
|
88
|
+
return artifactPath;
|
|
89
|
+
}
|
|
90
|
+
function main() {
|
|
91
|
+
console.log("PRKT demo rehearsal");
|
|
92
|
+
const checks = runPreflightChecks();
|
|
93
|
+
let failures = 0;
|
|
94
|
+
for (const check of checks) {
|
|
95
|
+
const marker = check.ok ? "PASS" : "FAIL";
|
|
96
|
+
console.log(`[${marker}] ${check.title} -> ${check.detail}`);
|
|
97
|
+
if (!check.ok) {
|
|
98
|
+
failures += 1;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
const artifactPath = writeSessionArtifact(checks);
|
|
102
|
+
console.log(`Session artifact: ${artifactPath}`);
|
|
103
|
+
if (failures > 0) {
|
|
104
|
+
console.error(`Demo rehearsal preflight failed with ${failures} failing check(s).`);
|
|
105
|
+
process.exitCode = 1;
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
console.log("Demo rehearsal preflight passed.");
|
|
109
|
+
console.log("Next: run the recommended live order and record signatures in artifacts/bounty-evidence.md.");
|
|
110
|
+
}
|
|
111
|
+
main();
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
4
|
+
const DecisionEngine_1 = require("../agent/DecisionEngine");
|
|
5
|
+
const env_1 = require("../config/env");
|
|
6
|
+
const programs_1 = require("../solana/programs");
|
|
7
|
+
const TokenWallet_1 = require("../spl/TokenWallet");
|
|
8
|
+
const WalletManager_1 = require("../wallet/WalletManager");
|
|
9
|
+
const mode_1 = require("./mode");
|
|
10
|
+
const devnetWalletPreflight_1 = require("./devnetWalletPreflight");
|
|
11
|
+
async function main() {
|
|
12
|
+
(0, mode_1.printDemoMode)("LIVE", "Direct Solana transaction path (wrap SOL into wSOL)");
|
|
13
|
+
const rpcUrl = (0, env_1.getRpcUrl)();
|
|
14
|
+
const connection = new web3_js_1.Connection(rpcUrl, "confirmed");
|
|
15
|
+
const walletManager = WalletManager_1.WalletManager.loadConfigured();
|
|
16
|
+
const associatedTokenAddress = TokenWallet_1.TokenWallet.findAssociatedTokenAddress(walletManager.publicKey, programs_1.NATIVE_MINT);
|
|
17
|
+
console.log("PRKT devnet wallet demo");
|
|
18
|
+
console.log(`RPC: ${rpcUrl}`);
|
|
19
|
+
console.log(`Wallet: ${walletManager.publicKey.toBase58()}`);
|
|
20
|
+
const startingSolBalance = (await connection.getBalance(walletManager.publicKey, "confirmed")) / 1_000_000_000;
|
|
21
|
+
let startingWsolBalance = 0;
|
|
22
|
+
const existingWsolAccount = await connection.getAccountInfo(associatedTokenAddress, "confirmed");
|
|
23
|
+
if (existingWsolAccount) {
|
|
24
|
+
const tokenBalance = await connection.getTokenAccountBalance(associatedTokenAddress, "confirmed");
|
|
25
|
+
startingWsolBalance = tokenBalance.value.uiAmount ?? 0;
|
|
26
|
+
}
|
|
27
|
+
(0, devnetWalletPreflight_1.assertDeterministicWrapPreflight)({
|
|
28
|
+
startingSolBalance,
|
|
29
|
+
startingWsolBalance
|
|
30
|
+
});
|
|
31
|
+
const agent = new DecisionEngine_1.DecisionEngine(connection, walletManager);
|
|
32
|
+
const result = await agent.think();
|
|
33
|
+
console.log(`Associated token account: ${associatedTokenAddress.toBase58()}`);
|
|
34
|
+
console.log(`Decision: ${result.action}`);
|
|
35
|
+
if (result.action !== "wrap") {
|
|
36
|
+
throw new Error("Execution failed: DecisionEngine returned HOLD during a deterministic wrap run. Check preflight balances and retry.");
|
|
37
|
+
}
|
|
38
|
+
const endingWsolBalance = result.wsolBalance;
|
|
39
|
+
if (endingWsolBalance <= startingWsolBalance) {
|
|
40
|
+
throw new Error(`Post-check failed: wSOL did not increase (${startingWsolBalance.toFixed(4)} -> ${endingWsolBalance.toFixed(4)}).`);
|
|
41
|
+
}
|
|
42
|
+
console.log(`Created ATA this run: ${result.createdAssociatedTokenAccount ? "yes" : "no"}`);
|
|
43
|
+
console.log(`Wrapped amount: ${result.wrapAmount.toFixed(2)} SOL`);
|
|
44
|
+
console.log(`Transaction signature: ${result.signature}`);
|
|
45
|
+
console.log(`wSOL before: ${startingWsolBalance.toFixed(4)}`);
|
|
46
|
+
console.log(`wSOL after: ${endingWsolBalance.toFixed(4)}`);
|
|
47
|
+
console.log("Post-check passed: wSOL balance increased.");
|
|
48
|
+
}
|
|
49
|
+
main().catch((error) => {
|
|
50
|
+
const message = error instanceof Error ? error.message : "Unknown error";
|
|
51
|
+
console.error(`Devnet wallet demo failed: ${message}`);
|
|
52
|
+
process.exitCode = 1;
|
|
53
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const managedAgentWallet_1 = require("./managedAgentWallet");
|
|
4
|
+
const shared_1 = require("./shared");
|
|
5
|
+
const DEFAULT_AGENT_NAME = "gasless-memo";
|
|
6
|
+
async function main() {
|
|
7
|
+
const managed = (0, managedAgentWallet_1.resolveManagedAgentWallet)({
|
|
8
|
+
agentName: (0, managedAgentWallet_1.getManagedAgentName)({ defaultAgentName: DEFAULT_AGENT_NAME, env: process.env }),
|
|
9
|
+
ownerId: (0, managedAgentWallet_1.getManagedOwnerId)(process.env)
|
|
10
|
+
});
|
|
11
|
+
const walletManager = managed.walletManager;
|
|
12
|
+
const koraSigner = (0, shared_1.createKoraSigner)();
|
|
13
|
+
const result = await koraSigner.submitGaslessMemo(walletManager, "PRKT gasless memo verification");
|
|
14
|
+
console.log("Gasless memo verification complete.");
|
|
15
|
+
(0, managedAgentWallet_1.logManagedAgentWallet)(managed);
|
|
16
|
+
console.log(`Signature: ${result.signature}`);
|
|
17
|
+
console.log(`Mode: ${result.mock ? "mock" : "live"}`);
|
|
18
|
+
}
|
|
19
|
+
main().catch((error) => {
|
|
20
|
+
const message = error instanceof Error ? error.message : "Unknown error";
|
|
21
|
+
console.error(`Gasless memo failed: ${message}`);
|
|
22
|
+
process.exitCode = 1;
|
|
23
|
+
});
|