@loyal-labs/private-transactions 0.2.8 → 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.
- package/README.md +69 -35
- package/dist/index.d.ts +66 -2
- package/dist/index.js +2349 -350
- package/dist/src/LoyalPrivateTransactionsClient.d.ts +15 -3
- package/dist/src/actions/shieldTokens.d.ts +69 -0
- package/dist/src/actions/undelegateDeposit.d.ts +25 -0
- package/dist/src/actions/unshieldTokens.d.ts +62 -0
- package/dist/src/checks/enshureChecks.d.ts +5 -0
- package/dist/src/constants.d.ts +1 -1
- package/dist/src/enumerate-deposits.d.ts +23 -0
- package/dist/src/fee-estimate.d.ts +25 -0
- package/dist/src/idl/telegram_private_transfer.d.ts +119 -3
- package/dist/src/instructions/closeDeposit.d.ts +4 -0
- package/dist/src/instructions/closePermission.d.ts +2 -0
- package/dist/src/instructions/closeUsernameDeposit.d.ts +4 -0
- package/dist/src/instructions/createPermission.d.ts +4 -0
- package/dist/src/instructions/delegateDeposit.d.ts +4 -0
- package/dist/src/instructions/initializeDeposit.d.ts +4 -0
- package/dist/src/instructions/initializeUsernameDeposit.d.ts +4 -0
- package/dist/src/instructions/modifyBalance.d.ts +4 -0
- package/dist/src/instructions/undelegateDeposit.d.ts +4 -0
- package/dist/src/instructions/undelegatePermission.d.ts +2 -0
- package/dist/src/kamino.d.ts +1 -1
- package/dist/src/rent-estimate.d.ts +46 -0
- package/dist/src/transaction-debug.d.ts +40 -0
- package/dist/src/types.d.ts +182 -2
- package/dist/src/utils.d.ts +7 -0
- package/dist/src/wsol.d.ts +14 -0
- package/package.json +6 -3
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.
|
|
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:
|
|
83
|
-
await client.
|
|
61
|
+
// Unshield: withdraw from private deposit in one base transaction
|
|
62
|
+
await client.unshieldTokens({
|
|
84
63
|
tokenMint,
|
|
85
64
|
user: signer.publicKey,
|
|
86
|
-
|
|
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
|
|
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;
|
|
@@ -94,6 +98,66 @@ export declare const IDL: {
|
|
|
94
98
|
name: string;
|
|
95
99
|
type: string;
|
|
96
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[];
|
|
97
161
|
} | {
|
|
98
162
|
name: string;
|
|
99
163
|
docs: string[];
|