@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
|
@@ -3,42 +3,77 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.RpcClient = void 0;
|
|
4
4
|
const web3_js_1 = require("@solana/web3.js");
|
|
5
5
|
const env_1 = require("../../config/env");
|
|
6
|
+
const RpcFailoverClient_1 = require("./RpcFailoverClient");
|
|
6
7
|
class RpcClient {
|
|
7
8
|
connection;
|
|
9
|
+
failoverClient;
|
|
8
10
|
constructor(rpcUrl = (0, env_1.getRpcUrl)(), commitment = "confirmed") {
|
|
9
11
|
this.connection = new web3_js_1.Connection(rpcUrl, commitment);
|
|
12
|
+
const fallbackUrl = (0, env_1.getRpcFallbackUrl)();
|
|
13
|
+
this.failoverClient =
|
|
14
|
+
fallbackUrl && fallbackUrl !== rpcUrl
|
|
15
|
+
? new RpcFailoverClient_1.RpcFailoverClient({
|
|
16
|
+
commitment,
|
|
17
|
+
fallbackUrl,
|
|
18
|
+
primaryUrl: rpcUrl
|
|
19
|
+
})
|
|
20
|
+
: null;
|
|
10
21
|
}
|
|
11
22
|
get rpcUrl() {
|
|
12
23
|
return this.connection.rpcEndpoint;
|
|
13
24
|
}
|
|
14
25
|
async getLatestBlockhash(commitment = "confirmed") {
|
|
26
|
+
if (this.failoverClient) {
|
|
27
|
+
return this.failoverClient.getLatestBlockhash(commitment);
|
|
28
|
+
}
|
|
15
29
|
return this.connection.getLatestBlockhash(commitment);
|
|
16
30
|
}
|
|
17
31
|
async getBalance(publicKey, commitment = "confirmed") {
|
|
32
|
+
if (this.failoverClient) {
|
|
33
|
+
return this.failoverClient.getBalance(publicKey, commitment);
|
|
34
|
+
}
|
|
18
35
|
return this.connection.getBalance(publicKey, commitment);
|
|
19
36
|
}
|
|
20
37
|
async getTokenAccountBalance(publicKey, commitment = "confirmed") {
|
|
38
|
+
if (this.failoverClient) {
|
|
39
|
+
return this.failoverClient.getTokenAccountBalance(publicKey, commitment);
|
|
40
|
+
}
|
|
21
41
|
return this.connection.getTokenAccountBalance(publicKey, commitment);
|
|
22
42
|
}
|
|
23
43
|
async getAccountInfo(publicKey, commitment = "confirmed") {
|
|
44
|
+
if (this.failoverClient) {
|
|
45
|
+
return this.failoverClient.getAccountInfo(publicKey, commitment);
|
|
46
|
+
}
|
|
24
47
|
return this.connection.getAccountInfo(publicKey, commitment);
|
|
25
48
|
}
|
|
26
49
|
async sendTransaction(transaction, options) {
|
|
50
|
+
if (this.failoverClient) {
|
|
51
|
+
return this.failoverClient.sendTransaction(transaction, options);
|
|
52
|
+
}
|
|
27
53
|
return this.connection.sendTransaction(transaction, options);
|
|
28
54
|
}
|
|
29
55
|
async confirmTransaction(strategy, commitment = "confirmed") {
|
|
56
|
+
if (this.failoverClient) {
|
|
57
|
+
return this.failoverClient.confirmTransaction(strategy, commitment);
|
|
58
|
+
}
|
|
30
59
|
if (typeof strategy === "string") {
|
|
31
60
|
return this.connection.confirmTransaction(strategy, commitment);
|
|
32
61
|
}
|
|
33
62
|
return this.connection.confirmTransaction(strategy, commitment);
|
|
34
63
|
}
|
|
35
64
|
async simulateTransaction(transaction, options) {
|
|
65
|
+
if (this.failoverClient) {
|
|
66
|
+
return this.failoverClient.simulateTransaction(transaction, options);
|
|
67
|
+
}
|
|
36
68
|
return this.connection.simulateTransaction(transaction, {
|
|
37
69
|
commitment: options?.commitment ?? "confirmed",
|
|
38
70
|
sigVerify: options?.sigVerify ?? true
|
|
39
71
|
});
|
|
40
72
|
}
|
|
41
73
|
async requestAirdrop(publicKey, lamports) {
|
|
74
|
+
if (this.failoverClient) {
|
|
75
|
+
return this.failoverClient.requestAirdrop(publicKey, lamports);
|
|
76
|
+
}
|
|
42
77
|
return this.connection.requestAirdrop(publicKey, lamports);
|
|
43
78
|
}
|
|
44
79
|
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { Connection, type Commitment, type ConfirmOptions, type PublicKey, type RpcResponseAndContext, type SignatureResult, type SimulatedTransactionResponse, type TransactionConfirmationStrategy, type VersionedTransaction } from "@solana/web3.js";
|
|
2
|
+
export type RpcFailoverConfig = {
|
|
3
|
+
primaryUrl: string;
|
|
4
|
+
fallbackUrl?: string | null;
|
|
5
|
+
commitment?: Commitment;
|
|
6
|
+
maxRetries?: number;
|
|
7
|
+
baseDelayMs?: number;
|
|
8
|
+
maxDelayMs?: number;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* RPC client with automatic failover from primary to fallback URL,
|
|
12
|
+
* exponential backoff, and random jitter on retries.
|
|
13
|
+
*/
|
|
14
|
+
export declare class RpcFailoverClient {
|
|
15
|
+
private primaryConnection;
|
|
16
|
+
private fallbackConnection;
|
|
17
|
+
private readonly maxRetries;
|
|
18
|
+
private readonly baseDelayMs;
|
|
19
|
+
private readonly maxDelayMs;
|
|
20
|
+
private readonly commitment;
|
|
21
|
+
readonly primaryUrl: string;
|
|
22
|
+
readonly fallbackUrl: string | null;
|
|
23
|
+
constructor(config: RpcFailoverConfig);
|
|
24
|
+
get connection(): Connection;
|
|
25
|
+
get rpcUrl(): string;
|
|
26
|
+
getLatestBlockhash(commitment?: Commitment): Promise<{
|
|
27
|
+
blockhash: string;
|
|
28
|
+
lastValidBlockHeight: number;
|
|
29
|
+
}>;
|
|
30
|
+
getBalance(publicKey: PublicKey, commitment?: Commitment): Promise<number>;
|
|
31
|
+
getTokenAccountBalance(publicKey: PublicKey, commitment?: Commitment): Promise<RpcResponseAndContext<import("@solana/web3.js").TokenAmount>>;
|
|
32
|
+
getAccountInfo(publicKey: PublicKey, commitment?: Commitment): Promise<import("@solana/web3.js").AccountInfo<Buffer<ArrayBufferLike>> | null>;
|
|
33
|
+
sendTransaction(transaction: VersionedTransaction, options?: ConfirmOptions): Promise<string>;
|
|
34
|
+
confirmTransaction(strategy: TransactionConfirmationStrategy | string, commitment?: Commitment): Promise<RpcResponseAndContext<SignatureResult>>;
|
|
35
|
+
simulateTransaction(transaction: VersionedTransaction, options?: {
|
|
36
|
+
commitment?: Commitment;
|
|
37
|
+
sigVerify?: boolean;
|
|
38
|
+
}): Promise<RpcResponseAndContext<SimulatedTransactionResponse>>;
|
|
39
|
+
requestAirdrop(publicKey: PublicKey, lamports: number): Promise<string>;
|
|
40
|
+
private executeWithFailover;
|
|
41
|
+
private backoff;
|
|
42
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Keypair, PublicKey, TransactionInstruction } from "@solana/web3.js";
|
|
2
|
+
import { RpcClient } from "../rpc/RpcClient";
|
|
3
|
+
import { WalletManager } from "../wallet/WalletManager";
|
|
4
|
+
export declare class TokenService {
|
|
5
|
+
private readonly rpcClient;
|
|
6
|
+
constructor(rpcClient: RpcClient);
|
|
7
|
+
getMintDecimals(mint: PublicKey): Promise<number>;
|
|
8
|
+
findAssociatedTokenAddress(owner: PublicKey, mint: PublicKey): PublicKey;
|
|
9
|
+
ensureAtaInstruction(input: {
|
|
10
|
+
mint: PublicKey;
|
|
11
|
+
owner: PublicKey;
|
|
12
|
+
payer: PublicKey;
|
|
13
|
+
}): Promise<{
|
|
14
|
+
address: PublicKey;
|
|
15
|
+
createInstruction: TransactionInstruction | null;
|
|
16
|
+
}>;
|
|
17
|
+
buildWrapSolInstructions(input: {
|
|
18
|
+
wallet: WalletManager;
|
|
19
|
+
amountLamports: number;
|
|
20
|
+
createAtaIfMissing: boolean;
|
|
21
|
+
}): {
|
|
22
|
+
associatedTokenAddress: PublicKey;
|
|
23
|
+
createdAssociatedTokenAccount: boolean;
|
|
24
|
+
instructions: TransactionInstruction[];
|
|
25
|
+
};
|
|
26
|
+
buildCreateMintInstructions(input: {
|
|
27
|
+
payer: PublicKey;
|
|
28
|
+
mintAuthority: PublicKey;
|
|
29
|
+
decimals: number;
|
|
30
|
+
}): Promise<{
|
|
31
|
+
mintKeypair: Keypair;
|
|
32
|
+
instructions: TransactionInstruction[];
|
|
33
|
+
}>;
|
|
34
|
+
buildMintToInstruction(input: {
|
|
35
|
+
mint: PublicKey;
|
|
36
|
+
destinationAta: PublicKey;
|
|
37
|
+
authority: PublicKey;
|
|
38
|
+
amount: bigint;
|
|
39
|
+
}): TransactionInstruction;
|
|
40
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { PublicKey } from "@solana/web3.js";
|
|
2
|
+
import { RpcClient } from "../rpc/RpcClient";
|
|
3
|
+
import { TokenService } from "../tokens/TokenService";
|
|
4
|
+
export type BalanceSnapshot = {
|
|
5
|
+
address: PublicKey;
|
|
6
|
+
beforeRaw: bigint;
|
|
7
|
+
decimals: number;
|
|
8
|
+
kind: "sol" | "spl";
|
|
9
|
+
label: string;
|
|
10
|
+
};
|
|
11
|
+
export type BalanceVerificationExpectation = {
|
|
12
|
+
label?: string;
|
|
13
|
+
maxDecreaseRaw?: bigint;
|
|
14
|
+
minIncreaseRaw?: bigint;
|
|
15
|
+
snapshot: BalanceSnapshot;
|
|
16
|
+
};
|
|
17
|
+
export type BalanceVerificationResult = {
|
|
18
|
+
address: string;
|
|
19
|
+
afterRaw: bigint;
|
|
20
|
+
afterUi: string;
|
|
21
|
+
beforeRaw: bigint;
|
|
22
|
+
beforeUi: string;
|
|
23
|
+
deltaRaw: bigint;
|
|
24
|
+
deltaUi: string;
|
|
25
|
+
kind: "sol" | "spl";
|
|
26
|
+
label: string;
|
|
27
|
+
};
|
|
28
|
+
export declare class PostTransactionVerifier {
|
|
29
|
+
private readonly rpcClient;
|
|
30
|
+
private readonly tokenService;
|
|
31
|
+
constructor(rpcClient: RpcClient, tokenService: TokenService);
|
|
32
|
+
snapshotSolBalance(owner: PublicKey, label?: string): Promise<BalanceSnapshot>;
|
|
33
|
+
snapshotSplBalanceForOwner(input: {
|
|
34
|
+
label?: string;
|
|
35
|
+
mint: PublicKey;
|
|
36
|
+
owner: PublicKey;
|
|
37
|
+
}): Promise<BalanceSnapshot>;
|
|
38
|
+
snapshotSplTokenAccount(input: {
|
|
39
|
+
label?: string;
|
|
40
|
+
mint: PublicKey;
|
|
41
|
+
tokenAccount: PublicKey;
|
|
42
|
+
}): Promise<BalanceSnapshot>;
|
|
43
|
+
assertBalanceChanges(expectations: BalanceVerificationExpectation[]): Promise<BalanceVerificationResult[]>;
|
|
44
|
+
private buildReport;
|
|
45
|
+
private readCurrentRaw;
|
|
46
|
+
private getSplTokenBalanceRaw;
|
|
47
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { PublicKey, TransactionInstruction, VersionedTransaction } from "@solana/web3.js";
|
|
2
|
+
import type { BuiltTransaction, SendResult, SendableTransaction, SimulationResult } from "../types/services";
|
|
3
|
+
import { RpcClient } from "../rpc/RpcClient";
|
|
4
|
+
import { WalletManager } from "../wallet/WalletManager";
|
|
5
|
+
export declare class TransactionService {
|
|
6
|
+
private readonly rpcClient;
|
|
7
|
+
constructor(rpcClient: RpcClient);
|
|
8
|
+
buildTransaction(input: {
|
|
9
|
+
feePayer: PublicKey;
|
|
10
|
+
instructions: TransactionInstruction[];
|
|
11
|
+
signer: WalletManager;
|
|
12
|
+
}): Promise<BuiltTransaction>;
|
|
13
|
+
buildSolTransferInstruction(input: {
|
|
14
|
+
from: PublicKey;
|
|
15
|
+
to: PublicKey;
|
|
16
|
+
lamports: number;
|
|
17
|
+
}): TransactionInstruction;
|
|
18
|
+
buildSolTransferInstructionInSol(input: {
|
|
19
|
+
from: PublicKey;
|
|
20
|
+
to: PublicKey;
|
|
21
|
+
amountSol: number;
|
|
22
|
+
}): TransactionInstruction;
|
|
23
|
+
buildSplTransferInstruction(input: {
|
|
24
|
+
sourceAta: PublicKey;
|
|
25
|
+
destinationAta: PublicKey;
|
|
26
|
+
owner: PublicKey;
|
|
27
|
+
amount: bigint;
|
|
28
|
+
multiSigners?: PublicKey[];
|
|
29
|
+
programId?: PublicKey;
|
|
30
|
+
}): TransactionInstruction;
|
|
31
|
+
buildSplTransferCheckedInstruction(input: {
|
|
32
|
+
sourceAta: PublicKey;
|
|
33
|
+
mint: PublicKey;
|
|
34
|
+
destinationAta: PublicKey;
|
|
35
|
+
owner: PublicKey;
|
|
36
|
+
amount: bigint;
|
|
37
|
+
decimals: number;
|
|
38
|
+
multiSigners?: PublicKey[];
|
|
39
|
+
programId?: PublicKey;
|
|
40
|
+
}): TransactionInstruction;
|
|
41
|
+
buildMemoInstruction(memo: string): TransactionInstruction;
|
|
42
|
+
simulate(transaction: VersionedTransaction): Promise<SimulationResult>;
|
|
43
|
+
sendAndConfirm(input: SendableTransaction): Promise<SendResult>;
|
|
44
|
+
private normalizeSendable;
|
|
45
|
+
private resolveConfirmationTarget;
|
|
46
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { PublicKey, TransactionConfirmationStrategy, VersionedTransaction } from "@solana/web3.js";
|
|
2
|
+
import type { WalletManager } from "../wallet/WalletManager";
|
|
3
|
+
export type BuiltTransaction = {
|
|
4
|
+
confirmationStrategy: TransactionConfirmationStrategy;
|
|
5
|
+
instructionsCount: number;
|
|
6
|
+
transaction: VersionedTransaction;
|
|
7
|
+
};
|
|
8
|
+
export type SendableTransaction = VersionedTransaction | {
|
|
9
|
+
confirmationStrategy?: TransactionConfirmationStrategy | string;
|
|
10
|
+
transaction: VersionedTransaction;
|
|
11
|
+
};
|
|
12
|
+
export type SimulationResult = {
|
|
13
|
+
err: unknown;
|
|
14
|
+
logs: string[] | null;
|
|
15
|
+
unitsConsumed: number | null;
|
|
16
|
+
};
|
|
17
|
+
export type SendResult = {
|
|
18
|
+
signature: string;
|
|
19
|
+
slot?: number;
|
|
20
|
+
};
|
|
21
|
+
export type TokenAccountDetails = {
|
|
22
|
+
address: PublicKey;
|
|
23
|
+
existed: boolean;
|
|
24
|
+
};
|
|
25
|
+
export type WalletServiceDependencies = {
|
|
26
|
+
walletManager: WalletManager;
|
|
27
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Keypair, type PublicKey, VersionedTransaction } from "@solana/web3.js";
|
|
2
|
+
type WalletSource = "env" | "generated" | "remote";
|
|
3
|
+
export declare class WalletManager {
|
|
4
|
+
private readonly signer;
|
|
5
|
+
private constructor();
|
|
6
|
+
static generate(): WalletManager;
|
|
7
|
+
static loadFromEnv(): WalletManager;
|
|
8
|
+
static loadRemoteSigner(): WalletManager;
|
|
9
|
+
static loadConfigured(): WalletManager;
|
|
10
|
+
static loadOrGenerate(): WalletManager;
|
|
11
|
+
static fromSecretKey(secretKey: Uint8Array, source?: "generated" | "env"): WalletManager;
|
|
12
|
+
get payer(): Keypair;
|
|
13
|
+
get publicKey(): PublicKey;
|
|
14
|
+
get source(): WalletSource;
|
|
15
|
+
signTransaction(transaction: VersionedTransaction): Promise<VersionedTransaction>;
|
|
16
|
+
toSafeSummary(): {
|
|
17
|
+
publicKey: string;
|
|
18
|
+
source: WalletSource;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
export {};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { PolicyConstraints } from "../types/policy";
|
|
2
|
+
import { KoraSigner } from "../kora/KoraSigner";
|
|
3
|
+
import { WalletManager } from "../wallet/WalletManager";
|
|
4
|
+
import type { DeFiExecutionResult, MarketSnapshot } from "./types";
|
|
5
|
+
type StrategyLogger = (message: string) => void;
|
|
6
|
+
export declare class DeFiCoordinator {
|
|
7
|
+
private readonly walletManager;
|
|
8
|
+
private readonly koraSigner;
|
|
9
|
+
private readonly logger;
|
|
10
|
+
private readonly policy;
|
|
11
|
+
private readonly kaminoAdapter;
|
|
12
|
+
private readonly jupiterAdapter;
|
|
13
|
+
private readonly marinadeAdapter;
|
|
14
|
+
private readonly raydiumAdapter;
|
|
15
|
+
constructor(walletManager: WalletManager, koraSigner: KoraSigner, logger?: StrategyLogger, policy?: PolicyConstraints);
|
|
16
|
+
runStakingStrategy(snapshot: MarketSnapshot): Promise<DeFiExecutionResult | null>;
|
|
17
|
+
runLiquidityStrategy(snapshot: MarketSnapshot): Promise<DeFiExecutionResult | null>;
|
|
18
|
+
runLendingStrategy(snapshot: MarketSnapshot): Promise<DeFiExecutionResult | null>;
|
|
19
|
+
runBorrowingStrategy(snapshot: MarketSnapshot): Promise<DeFiExecutionResult | null>;
|
|
20
|
+
runTradeStrategy(snapshot: MarketSnapshot): Promise<DeFiExecutionResult | null>;
|
|
21
|
+
runFullSuite(snapshot: MarketSnapshot): Promise<DeFiExecutionResult[]>;
|
|
22
|
+
private execute;
|
|
23
|
+
}
|
|
24
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { PolicyConstraints } from "../types/policy";
|
|
2
|
+
import { KoraSigner } from "../kora/KoraSigner";
|
|
3
|
+
import { WalletManager } from "../wallet/WalletManager";
|
|
4
|
+
import type { DeFiExecutionResult, DeFiIntent } from "./types";
|
|
5
|
+
export declare class DeFiExecutor {
|
|
6
|
+
private readonly policy;
|
|
7
|
+
private readonly defiPolicyGuard;
|
|
8
|
+
private readonly policyGuard;
|
|
9
|
+
constructor(policy: PolicyConstraints);
|
|
10
|
+
executeIntent(input: {
|
|
11
|
+
intent: DeFiIntent;
|
|
12
|
+
koraSigner: KoraSigner;
|
|
13
|
+
walletManager: WalletManager;
|
|
14
|
+
}): Promise<DeFiExecutionResult>;
|
|
15
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { DeFiIntent, LpInstructionPlan, LpPositionSettings, MarketSnapshot, RaydiumLiquidityPoolConfig, RaydiumUserTokenAccounts } from "../types";
|
|
2
|
+
import { WalletManager } from "../../wallet/WalletManager";
|
|
3
|
+
import { VersionedTransaction } from "@solana/web3.js";
|
|
4
|
+
export declare class RaydiumAdapter {
|
|
5
|
+
readonly protocol: "raydium";
|
|
6
|
+
private readonly lpInstructionBuilder;
|
|
7
|
+
createDefaultPositionSettings(): LpPositionSettings;
|
|
8
|
+
buildAddLiquidityPlan(settings?: LpPositionSettings): LpInstructionPlan;
|
|
9
|
+
buildAddLiquidityTransactionDraft(input: {
|
|
10
|
+
baseAmountIn: number;
|
|
11
|
+
fixedSide?: "base" | "quote";
|
|
12
|
+
otherAmountMin: number;
|
|
13
|
+
owner: WalletManager;
|
|
14
|
+
poolConfig: RaydiumLiquidityPoolConfig;
|
|
15
|
+
quoteAmountIn: number;
|
|
16
|
+
recentBlockhash?: string;
|
|
17
|
+
userTokenAccounts: RaydiumUserTokenAccounts;
|
|
18
|
+
}): Promise<VersionedTransaction>;
|
|
19
|
+
buildAddLiquidityIntent(snapshot: MarketSnapshot, settings?: LpPositionSettings): DeFiIntent | null;
|
|
20
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
type SupportedKaminoCluster = "devnet" | "localnet" | "mainnet-beta";
|
|
2
|
+
export type KaminoLiveConfig = {
|
|
3
|
+
actions: {
|
|
4
|
+
borrowAmountRaw: bigint;
|
|
5
|
+
depositAmountRaw: bigint;
|
|
6
|
+
};
|
|
7
|
+
borrowMint: string;
|
|
8
|
+
cluster?: SupportedKaminoCluster;
|
|
9
|
+
depositMint: string;
|
|
10
|
+
marketAddress: string;
|
|
11
|
+
programId: string;
|
|
12
|
+
};
|
|
13
|
+
export declare function loadKaminoLiveConfig(): KaminoLiveConfig;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type Address } from "@solana/kit";
|
|
2
|
+
import { KaminoMarket } from "@kamino-finance/klend-sdk";
|
|
3
|
+
type Cluster = "devnet" | "localnet" | "mainnet-beta" | "testnet" | "unknown";
|
|
4
|
+
export declare function loadKaminoMarketWithFallback(input: {
|
|
5
|
+
cluster: Cluster;
|
|
6
|
+
logger?: (message: string) => void;
|
|
7
|
+
marketAddress: Address;
|
|
8
|
+
programAddress: Address;
|
|
9
|
+
rpcUrl: string;
|
|
10
|
+
}): Promise<KaminoMarket>;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { LpInstructionPlan, LpPositionSettings, MarketSnapshot } from "../types";
|
|
2
|
+
export interface LpInstructionBuilder {
|
|
3
|
+
buildAddLiquidityPlan(input: {
|
|
4
|
+
depositLamports: number;
|
|
5
|
+
settings: LpPositionSettings;
|
|
6
|
+
}): LpInstructionPlan;
|
|
7
|
+
buildHarvestFeesPlan(input: {
|
|
8
|
+
settings: LpPositionSettings;
|
|
9
|
+
snapshot: MarketSnapshot;
|
|
10
|
+
}): LpInstructionPlan | null;
|
|
11
|
+
buildRemoveLiquidityPlan(input: {
|
|
12
|
+
withdrawLamports: number;
|
|
13
|
+
settings: LpPositionSettings;
|
|
14
|
+
}): LpInstructionPlan;
|
|
15
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { VersionedTransaction } from "@solana/web3.js";
|
|
2
|
+
import { WalletManager } from "../../wallet/WalletManager";
|
|
3
|
+
import type { LpInstructionBuilder } from "./LpInstructionBuilder";
|
|
4
|
+
import type { LpInstructionPlan, LpPositionSettings, MarketSnapshot, RaydiumLiquidityPoolConfig, RaydiumUserTokenAccounts } from "../types";
|
|
5
|
+
export declare class RaydiumLpInstructionBuilder implements LpInstructionBuilder {
|
|
6
|
+
buildAddLiquidityPlan(input: {
|
|
7
|
+
depositLamports: number;
|
|
8
|
+
settings: LpPositionSettings;
|
|
9
|
+
}): LpInstructionPlan;
|
|
10
|
+
buildAddLiquidityTransactionDraft(input: {
|
|
11
|
+
baseAmountIn: number;
|
|
12
|
+
fixedSide?: "base" | "quote";
|
|
13
|
+
otherAmountMin: number;
|
|
14
|
+
owner: WalletManager;
|
|
15
|
+
poolConfig: RaydiumLiquidityPoolConfig;
|
|
16
|
+
quoteAmountIn: number;
|
|
17
|
+
recentBlockhash?: string;
|
|
18
|
+
userTokenAccounts: RaydiumUserTokenAccounts;
|
|
19
|
+
}): Promise<VersionedTransaction>;
|
|
20
|
+
buildHarvestFeesPlan(input: {
|
|
21
|
+
settings: LpPositionSettings;
|
|
22
|
+
snapshot: MarketSnapshot;
|
|
23
|
+
}): LpInstructionPlan | null;
|
|
24
|
+
buildRemoveLiquidityPlan(input: {
|
|
25
|
+
withdrawLamports: number;
|
|
26
|
+
settings: LpPositionSettings;
|
|
27
|
+
}): LpInstructionPlan;
|
|
28
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { RaydiumLiquidityPoolConfig, RaydiumUserTokenAccounts } from "../types";
|
|
2
|
+
export type RaydiumLpDevnetConfig = {
|
|
3
|
+
amounts: {
|
|
4
|
+
baseAmountIn: number;
|
|
5
|
+
otherAmountMin: number;
|
|
6
|
+
quoteAmountIn: number;
|
|
7
|
+
};
|
|
8
|
+
poolConfig: RaydiumLiquidityPoolConfig;
|
|
9
|
+
userTokenAccounts: RaydiumUserTokenAccounts;
|
|
10
|
+
};
|
|
11
|
+
export declare function loadRaydiumLpDevnetConfig(): RaydiumLpDevnetConfig;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { SupportedProtocol } from "../types/policy";
|
|
2
|
+
export type ProtocolPreset = {
|
|
3
|
+
defaultMarketId: string;
|
|
4
|
+
description: string;
|
|
5
|
+
label: string;
|
|
6
|
+
protocol: SupportedProtocol;
|
|
7
|
+
};
|
|
8
|
+
export declare const PROTOCOL_PRESETS: Record<SupportedProtocol, ProtocolPreset>;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import type { SupportedProtocol } from "../types/policy";
|
|
2
|
+
export type DeFiAction = "trade" | "stake" | "unstake" | "add_liquidity" | "remove_liquidity" | "harvest" | "deposit" | "withdraw" | "borrow" | "repay";
|
|
3
|
+
export type DeFiIntent = {
|
|
4
|
+
action: DeFiAction;
|
|
5
|
+
amountLamports: number;
|
|
6
|
+
expectedHealthFactor?: number;
|
|
7
|
+
marketId: string;
|
|
8
|
+
memo: string;
|
|
9
|
+
protocol: SupportedProtocol;
|
|
10
|
+
slippageBps: number;
|
|
11
|
+
};
|
|
12
|
+
export type MarketSnapshot = {
|
|
13
|
+
borrowDemandUsdcAtomic?: number;
|
|
14
|
+
buyThresholdUsd?: number;
|
|
15
|
+
collateralSolLamports?: number;
|
|
16
|
+
healthFactor?: number;
|
|
17
|
+
idleSolLamports?: number;
|
|
18
|
+
idleUsdcAtomic?: number;
|
|
19
|
+
liquidityInRange?: boolean;
|
|
20
|
+
rewardsClaimableAtomic?: number;
|
|
21
|
+
solPriceUsd?: number;
|
|
22
|
+
};
|
|
23
|
+
export type DeFiExecutionResult = {
|
|
24
|
+
action: DeFiAction;
|
|
25
|
+
memo: string;
|
|
26
|
+
mock: boolean;
|
|
27
|
+
protocol: SupportedProtocol;
|
|
28
|
+
signature: string;
|
|
29
|
+
};
|
|
30
|
+
export type LpPositionSettings = {
|
|
31
|
+
harvestThresholdAtomic: number;
|
|
32
|
+
maxCapitalLamports: number;
|
|
33
|
+
maxSlippageBps: number;
|
|
34
|
+
poolId: string;
|
|
35
|
+
rebalanceOnOutOfRange: boolean;
|
|
36
|
+
tokenPair: string;
|
|
37
|
+
};
|
|
38
|
+
export type LpInstructionPlan = {
|
|
39
|
+
action: "add_liquidity" | "remove_liquidity" | "harvest";
|
|
40
|
+
amountLamports: number;
|
|
41
|
+
operatorSummary: string;
|
|
42
|
+
poolId: string;
|
|
43
|
+
protocol: "raydium";
|
|
44
|
+
requiredAccounts: string[];
|
|
45
|
+
slippageBps: number;
|
|
46
|
+
tokenPair: string;
|
|
47
|
+
};
|
|
48
|
+
export type RaydiumLiquidityPoolConfig = {
|
|
49
|
+
authority: string;
|
|
50
|
+
baseVault: string;
|
|
51
|
+
lpMint: string;
|
|
52
|
+
marketEventQueue: string;
|
|
53
|
+
marketId: string;
|
|
54
|
+
openOrders: string;
|
|
55
|
+
poolId: string;
|
|
56
|
+
poolType: "Standard" | "StablePool";
|
|
57
|
+
programId: string;
|
|
58
|
+
quoteVault: string;
|
|
59
|
+
targetOrders: string;
|
|
60
|
+
};
|
|
61
|
+
export type RaydiumUserTokenAccounts = {
|
|
62
|
+
baseTokenAccount: string;
|
|
63
|
+
lpTokenAccount: string;
|
|
64
|
+
quoteTokenAccount: string;
|
|
65
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { KoraSigner } from "../../kora/KoraSigner";
|
|
2
|
+
import type { WalletManager } from "../../wallet/WalletManager";
|
|
3
|
+
import type { PolicyConstraints } from "../../types/policy";
|
|
4
|
+
import type { UniversalDeFiAdapter, UniversalExecutionOptions, UniversalDeFiRequest, UniversalExecutionResult } from "./types";
|
|
5
|
+
type OrchestratorLogger = (message: string) => void;
|
|
6
|
+
export declare class UniversalDeFiOrchestrator {
|
|
7
|
+
private readonly deps;
|
|
8
|
+
private readonly adapters;
|
|
9
|
+
private readonly executor;
|
|
10
|
+
constructor(deps: {
|
|
11
|
+
koraSigner: KoraSigner;
|
|
12
|
+
liveFirst?: boolean;
|
|
13
|
+
logger?: OrchestratorLogger;
|
|
14
|
+
policy?: PolicyConstraints;
|
|
15
|
+
walletManager: WalletManager;
|
|
16
|
+
}, adapters?: UniversalDeFiAdapter[]);
|
|
17
|
+
execute(request: UniversalDeFiRequest, options?: UniversalExecutionOptions): Promise<UniversalExecutionResult>;
|
|
18
|
+
executeBatch(requests: UniversalDeFiRequest[], options?: UniversalExecutionOptions): Promise<UniversalExecutionResult[]>;
|
|
19
|
+
private resolveAdapter;
|
|
20
|
+
private log;
|
|
21
|
+
private tryExecutePreparedLive;
|
|
22
|
+
private routeToEvm;
|
|
23
|
+
}
|
|
24
|
+
export {};
|