@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
package/README.md CHANGED
@@ -40,32 +40,11 @@ const client = await LoyalPrivateTransactionsClient.fromConfig({
40
40
  commitment: "confirmed",
41
41
  });
42
42
 
43
- // Shield: move tokens into private deposit
44
- await client.initializeDeposit({
43
+ // Shield: move tokens into private deposit in one base transaction
44
+ await client.shieldTokens({
45
45
  tokenMint,
46
46
  user: signer.publicKey,
47
- payer: signer.publicKey,
48
- });
49
-
50
- await client.modifyBalance({
51
- tokenMint,
52
- user: signer.publicKey,
53
- payer: signer.publicKey,
54
- userTokenAccount: new PublicKey("<sender-ata>"),
55
47
  amount: 1_000_000,
56
- increase: true,
57
- });
58
-
59
- await client.createPermission({
60
- tokenMint,
61
- user: signer.publicKey,
62
- payer: signer.publicKey,
63
- });
64
-
65
- await client.delegateDeposit({
66
- tokenMint,
67
- user: signer.publicKey,
68
- payer: signer.publicKey,
69
48
  validator: ER_VALIDATOR,
70
49
  });
71
50
 
@@ -79,24 +58,15 @@ await client.transferToUsernameDeposit({
79
58
  sessionToken: null,
80
59
  });
81
60
 
82
- // Unshield: commit PER state and withdraw tokens
83
- await client.undelegateDeposit({
61
+ // Unshield: withdraw from private deposit in one base transaction
62
+ await client.unshieldTokens({
84
63
  tokenMint,
85
64
  user: signer.publicKey,
86
- payer: signer.publicKey,
65
+ amount: 1_000_000,
87
66
  sessionToken: null,
88
67
  magicProgram: MAGIC_PROGRAM_ID,
89
68
  magicContext: MAGIC_CONTEXT_ID,
90
69
  });
91
-
92
- await client.modifyBalance({
93
- tokenMint,
94
- user: signer.publicKey,
95
- payer: signer.publicKey,
96
- userTokenAccount: new PublicKey("<sender-ata>"),
97
- amount: 1_000_000,
98
- increase: false,
99
- });
100
70
  ```
101
71
 
102
72
  ## PER Authentication
@@ -131,11 +101,75 @@ const client = await LoyalPrivateTransactionsClient.fromConfig({
131
101
 
132
102
  ### Shield / Unshield
133
103
 
104
+ - `shieldTokens` — one-transaction base shield flow, with optional pre-undelegate when the deposit is already delegated
105
+ - `unshieldTokens` — one-transaction base unshield flow, with optional pre-undelegate and automatic re-delegate when balance remains
106
+ - `buildShieldFlowTransactionPlan` — create the planned `shield` or `unshield` transactions and instruction metadata once
107
+ - `buildShieldTokensTransactionPlan` / `buildUnshieldTokensTransactionPlan` — explicit shield/unshield plan builders
108
+ - `estimateShieldFlowFee` — estimate transaction-level network fees plus instruction-attributed rent from an existing plan
109
+ - `estimateShieldTokensFee` / `estimateUnshieldTokensFee` — explicit shield/unshield estimators for an existing plan
110
+ - `executeShieldFlowTransactionPlan` — send the exact transactions from an existing plan in order
111
+ - `executeShieldTokensTransactionPlan` / `executeUnshieldTokensTransactionPlan` — explicit shield/unshield executors for an existing plan
134
112
  - `initializeDeposit` — create deposit account (no-op if exists)
135
113
  - `modifyBalance` — deposit (`increase: true`) or withdraw (`increase: false`) real tokens
136
114
  - `createPermission` — set up PER access control (idempotent)
137
115
  - `delegateDeposit` — delegate to TEE validator
138
116
 
117
+ Fee estimates use Solana's `getFeeForMessage` on the planned transaction
118
+ messages. Instruction rows report net `rentLamports`: positive values are rent
119
+ locked for newly created accounts, negative values are rent reclaimed by close
120
+ or undelegate cleanup. Delegation rent credits are net of MagicBlock's
121
+ undelegate session fee, so undelegation is not a full refund of every lamport
122
+ held by delegation accounts. For native-SOL flows, instruction rows also report
123
+ `nativeLamports` for the shielded/unshielded SOL principal; this is separate
124
+ from protocol fees and rent, but it does affect the payer's SOL balance.
125
+ `feeAndRentLamports` excludes native token principal, while `totalLamports`
126
+ is a cost-style net SOL impact for the common payer=user flow: positive values
127
+ are debits/costs and negative values are credits/gains. If payer differs from
128
+ user, `nativeLamports` belongs to the token owner while fees/rent may belong to
129
+ the payer. Network fees are not attributed per
130
+ instruction because Solana charges them at the transaction/message level. Build
131
+ the plan once and pass the same plan into the estimator so the estimate is tied
132
+ to the exact instructions your app is about to inspect or send. To execute that
133
+ exact plan, pass it to the matching `execute*TransactionPlan` method; it will
134
+ send any pre-undelegate transaction first, wait for the required owner transition
135
+ when the plan includes one, then send the base transaction.
136
+
137
+ ```ts
138
+ const shieldPlan = await client.buildShieldTokensTransactionPlan({
139
+ user: signer.publicKey,
140
+ tokenMint,
141
+ amount: 1_000_000,
142
+ });
143
+ const shieldEstimate = await client.estimateShieldTokensFee({
144
+ plan: shieldPlan,
145
+ });
146
+
147
+ const unshieldPlan = await client.buildUnshieldTokensTransactionPlan({
148
+ user: signer.publicKey,
149
+ tokenMint,
150
+ amount: 1_000_000,
151
+ });
152
+ const unshieldEstimate = await client.estimateUnshieldTokensFee({
153
+ plan: unshieldPlan,
154
+ });
155
+
156
+ console.log(shieldEstimate.feeAndRentLamports);
157
+ console.log(shieldEstimate.totalLamports);
158
+ console.log(unshieldEstimate.feeAndRentLamports);
159
+ console.log(unshieldEstimate.totalLamports);
160
+
161
+ const shieldResult = await client.executeShieldTokensTransactionPlan({
162
+ plan: shieldPlan,
163
+ });
164
+
165
+ const unshieldResult = await client.executeUnshieldTokensTransactionPlan({
166
+ plan: unshieldPlan,
167
+ });
168
+
169
+ console.log(shieldResult.signatures);
170
+ console.log(unshieldResult.signatures);
171
+ ```
172
+
139
173
  ### Private Transfers (on PER)
140
174
 
141
175
  - `transferDeposit` — transfer between user deposits
package/dist/index.d.ts CHANGED
@@ -31,9 +31,13 @@
31
31
  * await client.undelegateDeposit({ user: signer.publicKey, tokenMint, payer: signer.publicKey, sessionToken: null, magicProgram: MAGIC_PROGRAM_ID, magicContext: MAGIC_CONTEXT_ID });
32
32
  */
33
33
  export { LoyalPrivateTransactionsClient, waitForAccountOwnerChange, } from "./src/LoyalPrivateTransactionsClient";
34
- export type { WalletSigner, WalletLike, RpcOptions, ClientConfig, DepositData, UsernameDepositData, InitializeDepositParams, ModifyBalanceParams, ModifyBalanceResult, CreatePermissionParams, CreateUsernamePermissionParams, DelegateDepositParams, DelegateUsernameDepositParams, UndelegateDepositParams, UndelegateUsernameDepositParams, TransferDepositParams, TransferToUsernameDepositParams, DelegationRecord, DelegationStatusResult, DelegationStatusResponse, } from "./src/types";
34
+ export { shieldTokens } from "./src/actions/shieldTokens";
35
+ export { unshieldTokens } from "./src/actions/unshieldTokens";
36
+ export { enumerateDepositsByUser } from "./src/enumerate-deposits";
37
+ export type { WalletSigner, WalletLike, RpcOptions, ClientConfig, DepositData, UsernameDepositData, InitializeDepositParams, CloseDepositParams, CloseUsernameDepositParams, ClosePermissionParams, ModifyBalanceParams, ModifyBalanceResult, BuildShieldFlowTransactionPlanParams, BuildShieldTokensTransactionPlanParams, BuildUnshieldTokensTransactionPlanParams, ExecuteShieldFlowTransactionPlanParams, ExecuteShieldTokensTransactionPlanParams, ExecuteUnshieldTokensTransactionPlanParams, ShieldFlowKind, FeeEstimateCluster, EstimateShieldFlowFeeParams, EstimateShieldTokensFeeParams, EstimateUnshieldTokensFeeParams, ShieldFlowInstructionPlan, ShieldFlowOwnerChangeWait, ShieldFlowTransactionPlan, ShieldFlowPlan, InstructionCostEstimate, ShieldFlowTransactionFeeEstimate, ShieldFlowFeeEstimate, ShieldFlowTransactionExecutionResult, ShieldFlowExecutionResult, ShieldTokensClientParams, UnshieldTokensClientParams, GetKaminoShieldedBalanceQuoteParams, GetKaminoCollateralSharesForLiquidityAmountParams, KaminoReserveSnapshot, KaminoTrackedBalanceCostBasis, KaminoPositionYieldInfo, KaminoShieldedBalanceQuote, CreatePermissionParams, CreateUsernamePermissionParams, DelegateDepositParams, DelegateUsernameDepositParams, UndelegateDepositParams, UndelegateUsernameDepositParams, TransferDepositParams, TransferToUsernameDepositParams, DelegationRecord, DelegationStatusResult, DelegationStatusResponse, } from "./src/types";
35
38
  export { isKeypair, isAnchorProvider, isWalletLike } from "./src/types";
36
- export { ER_VALIDATOR, ER_VALIDATOR_DEVNET, ER_VALIDATOR_MAINNET, getErValidatorForSolanaEnv, getErValidatorForRpcEndpoint, PROGRAM_ID, DELEGATION_PROGRAM_ID, PERMISSION_PROGRAM_ID, MAGIC_PROGRAM_ID, MAGIC_CONTEXT_ID, DEPOSIT_SEED, DEPOSIT_SEED_BYTES, USERNAME_DEPOSIT_SEED, USERNAME_DEPOSIT_SEED_BYTES, VAULT_SEED, VAULT_SEED_BYTES, PERMISSION_SEED, PERMISSION_SEED_BYTES, LAMPORTS_PER_SOL, solToLamports, lamportsToSol, } from "./src/constants";
39
+ export { ER_VALIDATOR, ER_VALIDATOR_DEVNET, ER_VALIDATOR_MAINNET, getErValidatorForSolanaEnv, getErValidatorForRpcEndpoint, getKaminoModifyBalanceAccountsForTokenMint, isKaminoMainnetModifyBalanceAccounts, KLEND_PROGRAM_ID, PROGRAM_ID, USDC_MINT_DEVNET, USDC_MINT_MAINNET, DELEGATION_PROGRAM_ID, PERMISSION_PROGRAM_ID, MAGIC_PROGRAM_ID, MAGIC_CONTEXT_ID, DEPOSIT_SEED, DEPOSIT_SEED_BYTES, USERNAME_DEPOSIT_SEED, USERNAME_DEPOSIT_SEED_BYTES, VAULT_SEED, VAULT_SEED_BYTES, PERMISSION_SEED, PERMISSION_SEED_BYTES, LAMPORTS_PER_SOL, solToLamports, lamportsToSol, } from "./src/constants";
40
+ export { calculateKaminoCollateralExchangeRateSfFromAmounts, calculateKaminoCollateralValuation, calculateKaminoRedeemableLiquidityAmountRaw, calculateKaminoShareAmountForLiquidityAmountRaw, fetchKaminoReserveSnapshot, parseKaminoReserveSnapshotFromAccountData, } from "./src/kamino";
37
41
  export { findDepositPda, findUsernameDepositPda, findVaultPda, findPermissionPda, findDelegationRecordPda, findDelegationMetadataPda, findBufferPda, } from "./src/pda";
38
42
  export declare const IDL: {
39
43
  address: string;
@@ -53,6 +57,12 @@ export declare const IDL: {
53
57
  writable?: undefined;
54
58
  pda?: undefined;
55
59
  address?: undefined;
60
+ } | {
61
+ name: string;
62
+ writable: boolean;
63
+ relations?: undefined;
64
+ pda?: undefined;
65
+ address?: undefined;
56
66
  } | {
57
67
  name: string;
58
68
  writable: boolean;
@@ -88,6 +98,66 @@ export declare const IDL: {
88
98
  name: string;
89
99
  type: string;
90
100
  }[];
101
+ } | {
102
+ name: string;
103
+ docs: string[];
104
+ discriminator: number[];
105
+ accounts: ({
106
+ name: string;
107
+ writable: boolean;
108
+ signer: boolean;
109
+ relations: string[];
110
+ pda?: undefined;
111
+ } | {
112
+ name: string;
113
+ writable: boolean;
114
+ pda: {
115
+ seeds: ({
116
+ kind: string;
117
+ value: number[];
118
+ path?: undefined;
119
+ } | {
120
+ kind: string;
121
+ path: string;
122
+ value?: undefined;
123
+ })[];
124
+ };
125
+ signer?: undefined;
126
+ relations?: undefined;
127
+ } | {
128
+ name: string;
129
+ relations: string[];
130
+ writable?: undefined;
131
+ signer?: undefined;
132
+ pda?: undefined;
133
+ })[];
134
+ args: never[];
135
+ } | {
136
+ name: string;
137
+ docs: string[];
138
+ discriminator: number[];
139
+ accounts: ({
140
+ name: string;
141
+ writable: boolean;
142
+ signer: boolean;
143
+ relations?: undefined;
144
+ } | {
145
+ name: string;
146
+ writable: boolean;
147
+ signer?: undefined;
148
+ relations?: undefined;
149
+ } | {
150
+ name: string;
151
+ relations: string[];
152
+ writable?: undefined;
153
+ signer?: undefined;
154
+ } | {
155
+ name: string;
156
+ writable?: undefined;
157
+ signer?: undefined;
158
+ relations?: undefined;
159
+ })[];
160
+ args: never[];
91
161
  } | {
92
162
  name: string;
93
163
  docs: string[];
@@ -235,10 +305,15 @@ export declare const IDL: {
235
305
  optional?: undefined;
236
306
  pda?: undefined;
237
307
  })[];
238
- args: {
308
+ args: ({
309
+ name: string;
310
+ type: {
311
+ array: (string | number)[];
312
+ };
313
+ } | {
239
314
  name: string;
240
315
  type: string;
241
- }[];
316
+ })[];
242
317
  } | {
243
318
  name: string;
244
319
  discriminator: number[];
@@ -279,7 +354,9 @@ export declare const IDL: {
279
354
  })[];
280
355
  args: {
281
356
  name: string;
282
- type: string;
357
+ type: {
358
+ array: (string | number)[];
359
+ };
283
360
  }[];
284
361
  docs?: undefined;
285
362
  } | {
@@ -429,6 +506,14 @@ export declare const IDL: {
429
506
  signer?: undefined;
430
507
  optional?: undefined;
431
508
  address?: undefined;
509
+ } | {
510
+ name: string;
511
+ writable: boolean;
512
+ relations?: undefined;
513
+ signer?: undefined;
514
+ optional?: undefined;
515
+ pda?: undefined;
516
+ address?: undefined;
432
517
  } | {
433
518
  name: string;
434
519
  address: string;
@@ -552,10 +637,15 @@ export declare const IDL: {
552
637
  signer?: undefined;
553
638
  pda?: undefined;
554
639
  })[];
555
- args: {
640
+ args: ({
641
+ name: string;
642
+ type: {
643
+ array: (string | number)[];
644
+ };
645
+ } | {
556
646
  name: string;
557
647
  type: string;
558
- }[];
648
+ })[];
559
649
  })[];
560
650
  accounts: {
561
651
  name: string;
@@ -568,29 +658,47 @@ export declare const IDL: {
568
658
  }[];
569
659
  types: ({
570
660
  name: string;
571
- docs: string[];
572
661
  type: {
573
662
  kind: string;
574
- fields: {
663
+ fields: ({
575
664
  name: string;
576
665
  type: string;
577
- }[];
666
+ } | {
667
+ name: string;
668
+ type: {
669
+ array: (string | number)[];
670
+ option?: undefined;
671
+ };
672
+ } | {
673
+ name: string;
674
+ type: {
675
+ option: string;
676
+ array?: undefined;
677
+ };
678
+ })[];
578
679
  };
680
+ docs?: undefined;
579
681
  } | {
580
682
  name: string;
683
+ docs: string[];
581
684
  type: {
582
685
  kind: string;
583
686
  fields: ({
687
+ name: string;
688
+ type: {
689
+ array: (string | number)[];
690
+ };
691
+ docs?: undefined;
692
+ } | {
584
693
  name: string;
585
694
  type: string;
695
+ docs?: undefined;
586
696
  } | {
587
697
  name: string;
588
- type: {
589
- option: string;
590
- };
698
+ docs: string[];
699
+ type: string;
591
700
  })[];
592
701
  };
593
- docs?: undefined;
594
702
  })[];
595
703
  };
596
704
  export type { TelegramPrivateTransfer } from "./src/idl/telegram_private_transfer.ts";