@loyal-labs/private-transactions 0.2.7 → 0.2.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/README.md +69 -35
  2. package/dist/index.d.ts +122 -14
  3. package/dist/index.js +2918 -20273
  4. package/dist/src/LoyalPrivateTransactionsClient.d.ts +40 -13
  5. package/dist/src/actions/shieldTokens.d.ts +69 -0
  6. package/dist/src/actions/undelegateDeposit.d.ts +25 -0
  7. package/dist/src/actions/unshieldTokens.d.ts +62 -0
  8. package/dist/src/checks/enshureChecks.d.ts +5 -0
  9. package/dist/src/constants.d.ts +17 -2
  10. package/dist/src/enumerate-deposits.d.ts +23 -0
  11. package/dist/src/fee-estimate.d.ts +25 -0
  12. package/dist/src/idl/telegram_private_transfer.d.ts +182 -121
  13. package/dist/src/instructions/closeDeposit.d.ts +4 -0
  14. package/dist/src/instructions/closePermission.d.ts +2 -0
  15. package/dist/src/instructions/closeUsernameDeposit.d.ts +4 -0
  16. package/dist/src/instructions/createPermission.d.ts +4 -0
  17. package/dist/src/instructions/delegateDeposit.d.ts +4 -0
  18. package/dist/src/instructions/initializeDeposit.d.ts +4 -0
  19. package/dist/src/instructions/initializeUsernameDeposit.d.ts +4 -0
  20. package/dist/src/instructions/modifyBalance.d.ts +4 -0
  21. package/dist/src/instructions/undelegateDeposit.d.ts +4 -0
  22. package/dist/src/instructions/undelegatePermission.d.ts +2 -0
  23. package/dist/src/kamino.d.ts +44 -0
  24. package/dist/src/pda.d.ts +1 -1
  25. package/dist/src/rent-estimate.d.ts +46 -0
  26. package/dist/src/transaction-debug.d.ts +40 -0
  27. package/dist/src/types.d.ts +224 -3
  28. package/dist/src/utils.d.ts +8 -0
  29. package/dist/src/webcrypto.d.ts +2 -0
  30. package/dist/src/wsol.d.ts +14 -0
  31. package/package.json +6 -6
  32. package/dist/src/idl.d.ts +0 -1751
@@ -1,7 +1,7 @@
1
1
  import { Connection, PublicKey } from "@solana/web3.js";
2
2
  import { Program } from "@coral-xyz/anchor";
3
3
  import type { TelegramPrivateTransfer } from "./idl/telegram_private_transfer.ts";
4
- import type { WalletLike, ClientConfig, DepositData, UsernameDepositData, InitializeDepositParams, ModifyBalanceParams, ModifyBalanceResult, CreatePermissionParams, CreateUsernamePermissionParams, DelegateDepositParams, DelegateUsernameDepositParams, UndelegateDepositParams, UndelegateUsernameDepositParams, TransferDepositParams, TransferToUsernameDepositParams, InitializeUsernameDepositParams, ClaimUsernameDepositToDepositParams, DelegationStatusResponse } from "./types";
4
+ import type { WalletLike, ClientConfig, DepositData, UsernameDepositData, InitializeDepositParams, CloseDepositParams, CloseUsernameDepositParams, ModifyBalanceParams, ModifyBalanceResult, GetKaminoShieldedBalanceQuoteParams, GetKaminoCollateralSharesForLiquidityAmountParams, KaminoReserveSnapshot, KaminoShieldedBalanceQuote, BuildShieldFlowTransactionPlanParams, BuildShieldTokensTransactionPlanParams, BuildUnshieldTokensTransactionPlanParams, ExecuteShieldFlowTransactionPlanParams, ExecuteShieldTokensTransactionPlanParams, ExecuteUnshieldTokensTransactionPlanParams, EstimateShieldFlowFeeParams, EstimateShieldTokensFeeParams, EstimateUnshieldTokensFeeParams, ShieldFlowExecutionResult, ShieldFlowFeeEstimate, ShieldFlowPlan, ShieldTokensClientParams, UnshieldTokensClientParams, CreatePermissionParams, CreateUsernamePermissionParams, DelegateDepositParams, DelegateUsernameDepositParams, UndelegateDepositParams, UndelegateUsernameDepositParams, TransferDepositParams, TransferToUsernameDepositParams, InitializeUsernameDepositParams, ClaimUsernameDepositToDepositParams, DelegationStatusResponse } from "./types";
5
5
  export declare function waitForAccountOwnerChange(connection: Connection, account: PublicKey, expectedOwner: PublicKey, timeoutMs?: number, intervalMs?: number): {
6
6
  wait: () => Promise<void>;
7
7
  cancel: () => Promise<void>;
@@ -44,11 +44,24 @@ export declare class LoyalPrivateTransactionsClient {
44
44
  * Verifies TEE RPC integrity and obtains an auth token automatically.
45
45
  */
46
46
  static fromConfig(config: ClientConfig): Promise<LoyalPrivateTransactionsClient>;
47
+ shieldTokens(params: ShieldTokensClientParams): Promise<string>;
48
+ unshieldTokens(params: UnshieldTokensClientParams): Promise<string>;
49
+ buildShieldFlowTransactionPlan(params: BuildShieldFlowTransactionPlanParams): Promise<ShieldFlowPlan>;
50
+ buildShieldTokensTransactionPlan(params: BuildShieldTokensTransactionPlanParams): Promise<ShieldFlowPlan>;
51
+ buildUnshieldTokensTransactionPlan(params: BuildUnshieldTokensTransactionPlanParams): Promise<ShieldFlowPlan>;
52
+ estimateShieldFlowFee(params: EstimateShieldFlowFeeParams): Promise<ShieldFlowFeeEstimate>;
53
+ estimateShieldTokensFee(params: EstimateShieldTokensFeeParams): Promise<ShieldFlowFeeEstimate>;
54
+ estimateUnshieldTokensFee(params: EstimateUnshieldTokensFeeParams): Promise<ShieldFlowFeeEstimate>;
55
+ executeShieldFlowTransactionPlan(params: ExecuteShieldFlowTransactionPlanParams): Promise<ShieldFlowExecutionResult>;
56
+ executeShieldTokensTransactionPlan(params: ExecuteShieldTokensTransactionPlanParams): Promise<ShieldFlowExecutionResult>;
57
+ executeUnshieldTokensTransactionPlan(params: ExecuteUnshieldTokensTransactionPlanParams): Promise<ShieldFlowExecutionResult>;
47
58
  /**
48
59
  * Initialize a deposit account for a user and token mint
49
60
  */
50
61
  initializeDeposit(params: InitializeDepositParams): Promise<string>;
51
62
  initializeUsernameDeposit(params: InitializeUsernameDepositParams): Promise<string>;
63
+ closeDeposit(params: CloseDepositParams): Promise<string>;
64
+ closeUsernameDeposit(params: CloseUsernameDepositParams): Promise<string>;
52
65
  /**
53
66
  * Modify the balance of a user's deposit account
54
67
  */
@@ -57,7 +70,7 @@ export declare class LoyalPrivateTransactionsClient {
57
70
  /**
58
71
  * Create a permission for a deposit account (required for PER)
59
72
  */
60
- createPermission(params: CreatePermissionParams): Promise<string | null>;
73
+ createPermission(params: CreatePermissionParams): Promise<string>;
61
74
  /**
62
75
  * Create a permission for a username-based deposit account
63
76
  */
@@ -93,23 +106,38 @@ export declare class LoyalPrivateTransactionsClient {
93
106
  */
94
107
  getBaseDeposit(user: PublicKey, tokenMint: PublicKey): Promise<DepositData | null>;
95
108
  getEphemeralDeposit(user: PublicKey, tokenMint: PublicKey): Promise<DepositData | null>;
109
+ /**
110
+ * Enumerate every Deposit account owned by a user across both the base
111
+ * program and the ephemeral program. Used by the wallet UI to discover
112
+ * shielded holdings even when the user no longer has a matching base-chain
113
+ * token balance.
114
+ *
115
+ * Delegated deposits only exist on the ephemeral chain (on base the PDA is
116
+ * owned by the delegation program and Anchor cannot deserialize it as a
117
+ * `Deposit`). Undelegated deposits only exist on base. We query both and
118
+ * merge by PDA address, preferring the ephemeral amount when both return
119
+ * an entry because ephemeral reflects the live balance.
120
+ */
121
+ getAllDepositsByUser(user: PublicKey): Promise<DepositData[]>;
96
122
  /**
97
123
  * Get username deposit data
98
124
  */
99
125
  getBaseUsernameDeposit(username: string, tokenMint: PublicKey): Promise<UsernameDepositData | null>;
100
126
  getEphemeralUsernameDeposit(username: string, tokenMint: PublicKey): Promise<UsernameDepositData | null>;
101
127
  /**
102
- * Find the deposit PDA for a user and token mint
103
- */
104
- findDepositPda(user: PublicKey, tokenMint: PublicKey): [PublicKey, number];
105
- /**
106
- * Find the username deposit PDA
107
- */
108
- findUsernameDepositPda(username: string, tokenMint: PublicKey): [PublicKey, number];
109
- /**
110
- * Find the vault PDA
128
+ * Get the live base lending APY for the configured Kamino reserve in basis points.
129
+ * This is reserve supply APY only and does not include farm reward APY.
130
+ * Returns null when the token mint has no hardcoded Kamino reserve config.
131
+ * Devnet reserves intentionally return 0 because the UI APY source is mainnet-only.
111
132
  */
112
- findVaultPda(tokenMint: PublicKey): [PublicKey, number];
133
+ getKaminoLendingApyBps(tokenMint: PublicKey): Promise<number | null>;
134
+ getKaminoReserveSnapshot(tokenMint: PublicKey): Promise<KaminoReserveSnapshot | null>;
135
+ getKaminoShieldedBalanceQuote(params: GetKaminoShieldedBalanceQuoteParams): Promise<KaminoShieldedBalanceQuote | null>;
136
+ getKaminoCollateralSharesForLiquidityAmount(params: GetKaminoCollateralSharesForLiquidityAmountParams): Promise<bigint | null>;
137
+ calculateKaminoCollateralExchangeRateSfFromAmounts(args: {
138
+ collateralAmountRaw: number | bigint;
139
+ liquidityAmountRaw: number | bigint;
140
+ }): bigint | null;
113
141
  /**
114
142
  * Get the connected wallet's public key
115
143
  */
@@ -123,7 +151,6 @@ export declare class LoyalPrivateTransactionsClient {
123
151
  * Get the program ID
124
152
  */
125
153
  getProgramId(): PublicKey;
126
- private validateUsername;
127
154
  private permissionAccountExists;
128
155
  private isAccountAlreadyInUse;
129
156
  private ensureNotDelegated;
@@ -0,0 +1,69 @@
1
+ import { type AccountInfo, type PublicKey, type TransactionInstruction } from "@solana/web3.js";
2
+ import type { FeeEstimateCluster, InstructionCheck, RpcOptions } from "../types";
3
+ import type { TelegramPrivateTransfer } from "../idl/telegram_private_transfer";
4
+ import type { Program } from "@coral-xyz/anchor";
5
+ export type LabeledTransactionInstruction = {
6
+ label: string;
7
+ ix: TransactionInstruction;
8
+ rentLamports?: number;
9
+ nativeLamports?: number;
10
+ };
11
+ export type LabeledTransactionPlan = {
12
+ label: string;
13
+ cluster: FeeEstimateCluster;
14
+ instructions: LabeledTransactionInstruction[];
15
+ checks: InstructionCheck[];
16
+ };
17
+ export type ShieldTokensInstructionPlan = {
18
+ instructions: LabeledTransactionInstruction[];
19
+ checks: InstructionCheck[];
20
+ needsUndelegate: boolean;
21
+ context: {
22
+ isNativeSol: boolean;
23
+ validator: PublicKey;
24
+ depositPda: PublicKey;
25
+ permissionPda: PublicKey;
26
+ depositAccountInfo: AccountInfo<Buffer> | null;
27
+ permissionAccountInfo: AccountInfo<Buffer> | null;
28
+ };
29
+ };
30
+ export type ShieldTokensTransactionPlan = {
31
+ preUndelegateTransaction: LabeledTransactionPlan | null;
32
+ baseTransaction: LabeledTransactionPlan;
33
+ context: ShieldTokensInstructionPlan["context"];
34
+ };
35
+ export declare function labelTransactionInstructions(prefix: string, instructions: TransactionInstruction[]): LabeledTransactionInstruction[];
36
+ export declare function buildShieldTokensInstructionPlan(params: {
37
+ user: PublicKey;
38
+ payer: PublicKey;
39
+ tokenMint: PublicKey;
40
+ amount: bigint;
41
+ baseProgram: Program<TelegramPrivateTransfer>;
42
+ perProgram: Program<TelegramPrivateTransfer>;
43
+ validator?: PublicKey;
44
+ }): Promise<ShieldTokensInstructionPlan>;
45
+ export declare function buildShieldTokensTransactionPlan(params: {
46
+ user: PublicKey;
47
+ payer: PublicKey;
48
+ tokenMint: PublicKey;
49
+ amount: bigint;
50
+ baseProgram: Program<TelegramPrivateTransfer>;
51
+ perProgram: Program<TelegramPrivateTransfer>;
52
+ validator?: PublicKey;
53
+ sessionToken?: PublicKey | null;
54
+ magicProgram?: PublicKey;
55
+ magicContext?: PublicKey;
56
+ }): Promise<ShieldTokensTransactionPlan>;
57
+ export declare function shieldTokens(params: {
58
+ user: PublicKey;
59
+ payer: PublicKey;
60
+ tokenMint: PublicKey;
61
+ amount: bigint;
62
+ baseProgram: Program<TelegramPrivateTransfer>;
63
+ perProgram: Program<TelegramPrivateTransfer>;
64
+ validator?: PublicKey;
65
+ sessionToken?: PublicKey | null;
66
+ magicProgram?: PublicKey;
67
+ magicContext?: PublicKey;
68
+ rpcOptions?: RpcOptions;
69
+ }): Promise<string>;
@@ -0,0 +1,25 @@
1
+ import type { Program } from "@coral-xyz/anchor";
2
+ import { type PublicKey, type TransactionInstruction } from "@solana/web3.js";
3
+ import type { InstructionCheck, RpcOptions, UndelegateDepositParams } from "../types";
4
+ import type { TelegramPrivateTransfer } from "../idl/telegram_private_transfer";
5
+ export type PlannedUndelegateDepositTransaction = {
6
+ label: string;
7
+ instructions: {
8
+ ix: TransactionInstruction;
9
+ }[];
10
+ checks: InstructionCheck[];
11
+ };
12
+ export declare function sendPlannedUndelegateDepositTransaction(params: {
13
+ baseProgram: Program<TelegramPrivateTransfer>;
14
+ perProgram: Program<TelegramPrivateTransfer>;
15
+ transaction: PlannedUndelegateDepositTransaction;
16
+ user: PublicKey;
17
+ tokenMint: PublicKey;
18
+ rpcOptions?: RpcOptions;
19
+ }): Promise<string>;
20
+ /**
21
+ * Undelegate a deposit account from the ephemeral rollup.
22
+ * Waits for both base and ephemeral connections to confirm the deposit
23
+ * is owned by PROGRAM_ID before returning.
24
+ */
25
+ export declare function undelegateDeposit(baseProgram: Program<TelegramPrivateTransfer>, perProgram: Program<TelegramPrivateTransfer>, params: UndelegateDepositParams): Promise<string>;
@@ -0,0 +1,62 @@
1
+ import { type PublicKey } from "@solana/web3.js";
2
+ import type { Program } from "@coral-xyz/anchor";
3
+ import type { TelegramPrivateTransfer } from "../idl/telegram_private_transfer";
4
+ import type { InstructionCheck, RpcOptions } from "../types";
5
+ import { type LabeledTransactionInstruction, type LabeledTransactionPlan } from "./shieldTokens";
6
+ export type UnshieldTokensInstructionPlan = {
7
+ instructions: LabeledTransactionInstruction[];
8
+ checks: InstructionCheck[];
9
+ needsUndelegate: boolean;
10
+ shouldRedelegate: boolean;
11
+ context: {
12
+ isNativeSol: boolean;
13
+ validator: PublicKey;
14
+ depositPda: PublicKey;
15
+ currentDepositAmount: bigint | null;
16
+ };
17
+ };
18
+ export type UnshieldTokensTransactionPlan = {
19
+ preUndelegateTransaction: LabeledTransactionPlan | null;
20
+ baseTransaction: LabeledTransactionPlan;
21
+ shouldRedelegate: boolean;
22
+ context: UnshieldTokensInstructionPlan["context"];
23
+ };
24
+ export declare function buildUnshieldTokensInstructionPlan(params: {
25
+ user: PublicKey;
26
+ payer: PublicKey;
27
+ tokenMint: PublicKey;
28
+ amount: bigint;
29
+ baseProgram: Program<TelegramPrivateTransfer>;
30
+ perProgram: Program<TelegramPrivateTransfer>;
31
+ validator?: PublicKey;
32
+ }): Promise<UnshieldTokensInstructionPlan>;
33
+ export declare function buildUnshieldTokensTransactionPlan(params: {
34
+ user: PublicKey;
35
+ payer: PublicKey;
36
+ tokenMint: PublicKey;
37
+ amount: bigint;
38
+ baseProgram: Program<TelegramPrivateTransfer>;
39
+ perProgram: Program<TelegramPrivateTransfer>;
40
+ validator?: PublicKey;
41
+ sessionToken?: PublicKey | null;
42
+ magicProgram?: PublicKey;
43
+ magicContext?: PublicKey;
44
+ }): Promise<UnshieldTokensTransactionPlan>;
45
+ /**
46
+ * Unshield tokens: move from a Loyal private deposit back to a regular wallet.
47
+ * If the deposit is delegated, this first commits it back to base, then sends
48
+ * one base transaction for withdraw/native-SOL close/redelegate.
49
+ */
50
+ export declare function unshieldTokens(params: {
51
+ user: PublicKey;
52
+ payer: PublicKey;
53
+ tokenMint: PublicKey;
54
+ amount: bigint;
55
+ baseProgram: Program<TelegramPrivateTransfer>;
56
+ perProgram: Program<TelegramPrivateTransfer>;
57
+ validator?: PublicKey;
58
+ sessionToken?: PublicKey | null;
59
+ magicProgram?: PublicKey;
60
+ magicContext?: PublicKey;
61
+ rpcOptions?: RpcOptions;
62
+ }): Promise<string>;
@@ -0,0 +1,5 @@
1
+ import type { AccountInfo, Connection, PublicKey } from "@solana/web3.js";
2
+ import type { InstructionCheck } from "../types";
3
+ export declare function processEnsureChecks(baseConnection: Connection, perConnection: Connection, ensure: InstructionCheck[]): Promise<void>;
4
+ export declare function getMultipleAccountsInfoWithRetry(connection: Connection, accounts: PublicKey[], label: string): Promise<(AccountInfo<Buffer> | null)[]>;
5
+ export declare function runEnsureFetchWithRetry<T>(label: string, task: () => Promise<T>): Promise<T>;
@@ -9,11 +9,26 @@ export declare const ER_VALIDATOR_MAINNET: PublicKey;
9
9
  */
10
10
  export declare const ER_VALIDATOR: PublicKey;
11
11
  export declare function getErValidatorForSolanaEnv(env: string): PublicKey;
12
- export declare function getErValidatorForRpcEndpoint(rpcEndpoint: string): PublicKey;
12
+ export declare function getErValidatorForRpcEndpoint(perRpcEndpoint: string): PublicKey;
13
+ export declare function getKaminoModifyBalanceAccountsForTokenMint(tokenMint: PublicKey): KaminoModifyBalanceAccounts | null;
13
14
  /**
14
15
  * Telegram Private Transfer program ID
15
16
  */
16
17
  export declare const PROGRAM_ID: PublicKey;
18
+ export declare const USDC_MINT_DEVNET: PublicKey;
19
+ export declare const USDC_MINT_MAINNET: PublicKey;
20
+ export declare const KLEND_PROGRAM_ID: PublicKey;
21
+ export interface KaminoModifyBalanceAccounts {
22
+ lendingMarket: PublicKey;
23
+ lendingMarketAuthority: PublicKey;
24
+ reserve: PublicKey;
25
+ reserveLiquiditySupply: PublicKey;
26
+ reserveCollateralMint: PublicKey;
27
+ liquidityDecimals: number;
28
+ instructionSysvarAccount: PublicKey;
29
+ klendProgram: PublicKey;
30
+ }
31
+ export declare function isKaminoMainnetModifyBalanceAccounts(accounts: KaminoModifyBalanceAccounts): boolean;
17
32
  /**
18
33
  * MagicBlock Delegation Program ID
19
34
  */
@@ -38,7 +53,7 @@ export declare const DEPOSIT_SEED_BYTES: Buffer<ArrayBuffer>;
38
53
  /**
39
54
  * PDA seed for username deposit accounts
40
55
  */
41
- export declare const USERNAME_DEPOSIT_SEED = "username_deposit";
56
+ export declare const USERNAME_DEPOSIT_SEED = "username_deposit_v2";
42
57
  export declare const USERNAME_DEPOSIT_SEED_BYTES: Buffer<ArrayBuffer>;
43
58
  /**
44
59
  * PDA seed for vault account
@@ -0,0 +1,23 @@
1
+ import { type Connection, PublicKey } from "@solana/web3.js";
2
+ import type { DepositData } from "./types";
3
+ /**
4
+ * Enumerate every Deposit account belonging to `user` across the base program
5
+ * and (optionally) the ephemeral program. Read-only — no signer required.
6
+ *
7
+ * Three sources are merged:
8
+ * 1. Base, owned by the deposit program — undelegated deposits (Anchor).
9
+ * 2. Base, owned by the delegation program — delegated deposits whose data
10
+ * bytes are still readable on base. Required when no authenticated
11
+ * ephemeral connection is available (e.g. browser wallet UI).
12
+ * 3. Ephemeral, owned by the deposit program — delegated deposits with the
13
+ * live balance (Anchor). Wins over (2) for the same PDA when present.
14
+ *
15
+ * Used by wallet UIs to discover shielded holdings even when the user has no
16
+ * matching base-chain token balance — e.g. after fully shielding an SPL mint,
17
+ * where Helius `getAssetsByOwner` no longer surfaces it.
18
+ */
19
+ export declare function enumerateDepositsByUser(args: {
20
+ user: PublicKey;
21
+ baseConnection: Connection;
22
+ ephemeralConnection?: Connection;
23
+ }): Promise<DepositData[]>;
@@ -0,0 +1,25 @@
1
+ import { type Commitment, type Connection, type PublicKey, type TransactionInstruction } from "@solana/web3.js";
2
+ import type { FeeEstimateCluster, InstructionCostEstimate, ShieldFlowTransactionFeeEstimate } from "./types";
3
+ export type FeeEstimateInstructionPlan = {
4
+ label: string;
5
+ ix: TransactionInstruction;
6
+ rentLamports?: number;
7
+ nativeLamports?: number;
8
+ };
9
+ export type FeeEstimateTransactionPlan = {
10
+ label: string;
11
+ cluster: FeeEstimateCluster;
12
+ connection: Connection;
13
+ feePayer: PublicKey;
14
+ instructions: FeeEstimateInstructionPlan[];
15
+ };
16
+ export declare function estimatePlannedTransactionFees(params: {
17
+ transactions: FeeEstimateTransactionPlan[];
18
+ commitment?: Commitment;
19
+ }): Promise<{
20
+ transactions: ShieldFlowTransactionFeeEstimate[];
21
+ instructions: InstructionCostEstimate[];
22
+ totalFeeLamports: number;
23
+ totalRentLamports: number;
24
+ totalNativeLamports: number;
25
+ }>;