@loyal-labs/private-transactions 0.2.6 → 0.2.8

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.
@@ -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, ModifyBalanceParams, ModifyBalanceResult, GetKaminoShieldedBalanceQuoteParams, GetKaminoCollateralSharesForLiquidityAmountParams, KaminoReserveSnapshot, KaminoShieldedBalanceQuote, 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>;
@@ -93,23 +93,38 @@ export declare class LoyalPrivateTransactionsClient {
93
93
  */
94
94
  getBaseDeposit(user: PublicKey, tokenMint: PublicKey): Promise<DepositData | null>;
95
95
  getEphemeralDeposit(user: PublicKey, tokenMint: PublicKey): Promise<DepositData | null>;
96
+ /**
97
+ * Enumerate every Deposit account owned by a user across both the base
98
+ * program and the ephemeral program. Used by the wallet UI to discover
99
+ * shielded holdings even when the user no longer has a matching base-chain
100
+ * token balance.
101
+ *
102
+ * Delegated deposits only exist on the ephemeral chain (on base the PDA is
103
+ * owned by the delegation program and Anchor cannot deserialize it as a
104
+ * `Deposit`). Undelegated deposits only exist on base. We query both and
105
+ * merge by PDA address, preferring the ephemeral amount when both return
106
+ * an entry because ephemeral reflects the live balance.
107
+ */
108
+ getAllDepositsByUser(user: PublicKey): Promise<DepositData[]>;
96
109
  /**
97
110
  * Get username deposit data
98
111
  */
99
112
  getBaseUsernameDeposit(username: string, tokenMint: PublicKey): Promise<UsernameDepositData | null>;
100
113
  getEphemeralUsernameDeposit(username: string, tokenMint: PublicKey): Promise<UsernameDepositData | null>;
101
114
  /**
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
111
- */
112
- findVaultPda(tokenMint: PublicKey): [PublicKey, number];
115
+ * Get the live base lending APY for the configured Kamino reserve in basis points.
116
+ * This is reserve supply APY only and does not include farm reward APY.
117
+ * Returns null when the token mint has no hardcoded Kamino reserve config.
118
+ * Devnet reserves intentionally return 0 because the UI APY source is mainnet-only.
119
+ */
120
+ getKaminoLendingApyBps(tokenMint: PublicKey): Promise<number | null>;
121
+ getKaminoReserveSnapshot(tokenMint: PublicKey): Promise<KaminoReserveSnapshot | null>;
122
+ getKaminoShieldedBalanceQuote(params: GetKaminoShieldedBalanceQuoteParams): Promise<KaminoShieldedBalanceQuote | null>;
123
+ getKaminoCollateralSharesForLiquidityAmount(params: GetKaminoCollateralSharesForLiquidityAmountParams): Promise<bigint | null>;
124
+ calculateKaminoCollateralExchangeRateSfFromAmounts(args: {
125
+ collateralAmountRaw: number | bigint;
126
+ liquidityAmountRaw: number | bigint;
127
+ }): bigint | null;
113
128
  /**
114
129
  * Get the connected wallet's public key
115
130
  */
@@ -10,10 +10,25 @@ export declare const ER_VALIDATOR_MAINNET: PublicKey;
10
10
  export declare const ER_VALIDATOR: PublicKey;
11
11
  export declare function getErValidatorForSolanaEnv(env: string): PublicKey;
12
12
  export declare function getErValidatorForRpcEndpoint(rpcEndpoint: 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
@@ -38,41 +38,6 @@ export type TelegramPrivateTransfer = {
38
38
  {
39
39
  "name": "sourceUsernameDeposit";
40
40
  "writable": true;
41
- "pda": {
42
- "seeds": [
43
- {
44
- "kind": "const";
45
- "value": [
46
- 117,
47
- 115,
48
- 101,
49
- 114,
50
- 110,
51
- 97,
52
- 109,
53
- 101,
54
- 95,
55
- 100,
56
- 101,
57
- 112,
58
- 111,
59
- 115,
60
- 105,
61
- 116
62
- ];
63
- },
64
- {
65
- "kind": "account";
66
- "path": "source_username_deposit.username";
67
- "account": "usernameDeposit";
68
- },
69
- {
70
- "kind": "account";
71
- "path": "source_username_deposit.token_mint";
72
- "account": "usernameDeposit";
73
- }
74
- ];
75
- };
76
41
  },
77
42
  {
78
43
  "name": "destinationDeposit";
@@ -228,41 +193,6 @@ export type TelegramPrivateTransfer = {
228
193
  },
229
194
  {
230
195
  "name": "deposit";
231
- "pda": {
232
- "seeds": [
233
- {
234
- "kind": "const";
235
- "value": [
236
- 117,
237
- 115,
238
- 101,
239
- 114,
240
- 110,
241
- 97,
242
- 109,
243
- 101,
244
- 95,
245
- 100,
246
- 101,
247
- 112,
248
- 111,
249
- 115,
250
- 105,
251
- 116
252
- ];
253
- },
254
- {
255
- "kind": "account";
256
- "path": "deposit.username";
257
- "account": "usernameDeposit";
258
- },
259
- {
260
- "kind": "account";
261
- "path": "deposit.token_mint";
262
- "account": "usernameDeposit";
263
- }
264
- ];
265
- };
266
196
  },
267
197
  {
268
198
  "name": "session";
@@ -673,12 +603,15 @@ export type TelegramPrivateTransfer = {
673
603
  111,
674
604
  115,
675
605
  105,
676
- 116
606
+ 116,
607
+ 95,
608
+ 118,
609
+ 50
677
610
  ];
678
611
  },
679
612
  {
680
613
  "kind": "arg";
681
- "path": "username";
614
+ "path": "usernameHash";
682
615
  },
683
616
  {
684
617
  "kind": "arg";
@@ -702,8 +635,13 @@ export type TelegramPrivateTransfer = {
702
635
  ];
703
636
  "args": [
704
637
  {
705
- "name": "username";
706
- "type": "string";
638
+ "name": "usernameHash";
639
+ "type": {
640
+ "array": [
641
+ "u8",
642
+ 32
643
+ ];
644
+ };
707
645
  },
708
646
  {
709
647
  "name": "tokenMint";
@@ -824,12 +762,15 @@ export type TelegramPrivateTransfer = {
824
762
  111,
825
763
  115,
826
764
  105,
827
- 116
765
+ 116,
766
+ 95,
767
+ 118,
768
+ 50
828
769
  ];
829
770
  },
830
771
  {
831
772
  "kind": "arg";
832
- "path": "username";
773
+ "path": "usernameHash";
833
774
  },
834
775
  {
835
776
  "kind": "account";
@@ -852,8 +793,13 @@ export type TelegramPrivateTransfer = {
852
793
  ];
853
794
  "args": [
854
795
  {
855
- "name": "username";
856
- "type": "string";
796
+ "name": "usernameHash";
797
+ "type": {
798
+ "array": [
799
+ "u8",
800
+ 32
801
+ ];
802
+ };
857
803
  }
858
804
  ];
859
805
  },
@@ -1378,41 +1324,6 @@ export type TelegramPrivateTransfer = {
1378
1324
  {
1379
1325
  "name": "destinationDeposit";
1380
1326
  "writable": true;
1381
- "pda": {
1382
- "seeds": [
1383
- {
1384
- "kind": "const";
1385
- "value": [
1386
- 117,
1387
- 115,
1388
- 101,
1389
- 114,
1390
- 110,
1391
- 97,
1392
- 109,
1393
- 101,
1394
- 95,
1395
- 100,
1396
- 101,
1397
- 112,
1398
- 111,
1399
- 115,
1400
- 105,
1401
- 116
1402
- ];
1403
- },
1404
- {
1405
- "kind": "account";
1406
- "path": "destination_deposit.username";
1407
- "account": "usernameDeposit";
1408
- },
1409
- {
1410
- "kind": "account";
1411
- "path": "destination_deposit.token_mint";
1412
- "account": "usernameDeposit";
1413
- }
1414
- ];
1415
- };
1416
1327
  },
1417
1328
  {
1418
1329
  "name": "tokenMint";
@@ -1554,12 +1465,15 @@ export type TelegramPrivateTransfer = {
1554
1465
  111,
1555
1466
  115,
1556
1467
  105,
1557
- 116
1468
+ 116,
1469
+ 95,
1470
+ 118,
1471
+ 50
1558
1472
  ];
1559
1473
  },
1560
1474
  {
1561
1475
  "kind": "arg";
1562
- "path": "username";
1476
+ "path": "usernameHash";
1563
1477
  },
1564
1478
  {
1565
1479
  "kind": "arg";
@@ -1580,8 +1494,13 @@ export type TelegramPrivateTransfer = {
1580
1494
  ];
1581
1495
  "args": [
1582
1496
  {
1583
- "name": "username";
1584
- "type": "string";
1497
+ "name": "usernameHash";
1498
+ "type": {
1499
+ "array": [
1500
+ "u8",
1501
+ 32
1502
+ ];
1503
+ };
1585
1504
  },
1586
1505
  {
1587
1506
  "name": "tokenMint";
@@ -1717,6 +1636,16 @@ export type TelegramPrivateTransfer = {
1717
1636
  "code": 6011;
1718
1637
  "name": "invalidDepositor";
1719
1638
  "msg": "Invalid Depositor";
1639
+ },
1640
+ {
1641
+ "code": 6012;
1642
+ "name": "invalidKaminoAccounts";
1643
+ "msg": "Invalid Kamino accounts";
1644
+ },
1645
+ {
1646
+ "code": 6013;
1647
+ "name": "invalidAmount";
1648
+ "msg": "Invalid amount";
1720
1649
  }
1721
1650
  ];
1722
1651
  "types": [
@@ -1738,6 +1667,10 @@ export type TelegramPrivateTransfer = {
1738
1667
  },
1739
1668
  {
1740
1669
  "name": "amount";
1670
+ "docs": [
1671
+ "For USDC deposits, this stores the Kamino share token amount.",
1672
+ "For all other mints, this stores the deposited liquidity token amount."
1673
+ ];
1741
1674
  "type": "u64";
1742
1675
  }
1743
1676
  ];
@@ -1793,8 +1726,13 @@ export type TelegramPrivateTransfer = {
1793
1726
  "type": "pubkey";
1794
1727
  },
1795
1728
  {
1796
- "name": "username";
1797
- "type": "string";
1729
+ "name": "usernameHash";
1730
+ "type": {
1731
+ "array": [
1732
+ "u8",
1733
+ 32
1734
+ ];
1735
+ };
1798
1736
  },
1799
1737
  {
1800
1738
  "name": "validationBytes";
@@ -1820,16 +1758,19 @@ export type TelegramPrivateTransfer = {
1820
1758
  {
1821
1759
  "name": "usernameDeposit";
1822
1760
  "docs": [
1823
- "A deposit account for a telegram username and token mint.",
1824
- "",
1825
- "Telegram username is always lowercase (a-z, 0-9 and underscores)"
1761
+ "A deposit account for a telegram username sha256 hash and token mint."
1826
1762
  ];
1827
1763
  "type": {
1828
1764
  "kind": "struct";
1829
1765
  "fields": [
1830
1766
  {
1831
- "name": "username";
1832
- "type": "string";
1767
+ "name": "usernameHash";
1768
+ "type": {
1769
+ "array": [
1770
+ "u8",
1771
+ 32
1772
+ ];
1773
+ };
1833
1774
  },
1834
1775
  {
1835
1776
  "name": "tokenMint";
@@ -1837,6 +1778,10 @@ export type TelegramPrivateTransfer = {
1837
1778
  },
1838
1779
  {
1839
1780
  "name": "amount";
1781
+ "docs": [
1782
+ "For USDC deposits, this stores the Kamino share token amount.",
1783
+ "For all other mints, this stores the deposited liquidity token amount."
1784
+ ];
1840
1785
  "type": "u64";
1841
1786
  }
1842
1787
  ];
@@ -0,0 +1,44 @@
1
+ import { Connection, PublicKey } from "@solana/web3.js";
2
+ import { type KaminoModifyBalanceAccounts } from "./constants";
3
+ import type { KaminoPositionYieldInfo, KaminoReserveSnapshot } from "./types";
4
+ export declare function parseKaminoReserveSnapshotFromAccountData(args: {
5
+ data: Buffer;
6
+ reserve: PublicKey;
7
+ tokenMint: PublicKey;
8
+ }): KaminoReserveSnapshot;
9
+ export declare function calculateKaminoRedeemableLiquidityAmountRaw(snapshot: KaminoReserveSnapshot, shareAmountRaw: bigint | number): bigint;
10
+ export declare function calculateKaminoShareAmountForLiquidityAmountRaw(args: {
11
+ snapshot: KaminoReserveSnapshot;
12
+ liquidityAmountRaw: bigint | number;
13
+ rounding?: "floor" | "ceil";
14
+ }): bigint;
15
+ export declare function calculateKaminoTrackedLiquidityCostBasisRaw(args: {
16
+ currentShareAmountRaw: bigint | number;
17
+ trackedShareAmountRaw?: bigint | number | null;
18
+ trackedLiquidityAmountRaw?: bigint | number | null;
19
+ }): bigint | null;
20
+ export declare function calculateKaminoCollateralExchangeRateSfFromAmounts(args: {
21
+ collateralAmount: bigint | number;
22
+ liquidityAmount: bigint | number;
23
+ }): bigint | null;
24
+ export declare function calculateKaminoCollateralValuation(args: {
25
+ snapshot: KaminoReserveSnapshot;
26
+ collateralAmount: bigint | number;
27
+ principalLiquidityAmount?: bigint | number | null;
28
+ shieldCollateralExchangeRateSf?: bigint | number | null;
29
+ }): {
30
+ currentLiquidityAmount: bigint;
31
+ principalLiquidityAmount: bigint | null;
32
+ earnedLiquidityAmount: bigint | null;
33
+ };
34
+ export declare function calculateKaminoPositionYieldInfoFromSnapshot(args: {
35
+ snapshot: KaminoReserveSnapshot;
36
+ shareAmountRaw: bigint | number;
37
+ trackedShareAmountRaw?: bigint | number | null;
38
+ trackedLiquidityAmountRaw?: bigint | number | null;
39
+ }): KaminoPositionYieldInfo;
40
+ export declare function fetchKaminoReserveSnapshot(args: {
41
+ connection: Connection;
42
+ tokenMint: PublicKey;
43
+ kaminoAccounts?: KaminoModifyBalanceAccounts;
44
+ }): Promise<KaminoReserveSnapshot | null>;
package/dist/src/pda.d.ts CHANGED
@@ -16,7 +16,7 @@ export declare function findDepositPda(user: PublicKey, tokenMint: PublicKey, pr
16
16
  * @param programId - Optional program ID (defaults to PROGRAM_ID)
17
17
  * @returns [PDA address, bump seed]
18
18
  */
19
- export declare function findUsernameDepositPda(username: string, tokenMint: PublicKey, programId?: PublicKey): [PublicKey, number];
19
+ export declare function findUsernameDepositPda(username: string, tokenMint: PublicKey, programId?: PublicKey): Promise<[PublicKey, number]>;
20
20
  /**
21
21
  * Derive the vault PDA
22
22
  *
@@ -48,11 +48,34 @@ export interface DepositData {
48
48
  amount: bigint;
49
49
  address: PublicKey;
50
50
  }
51
+ export interface KaminoReserveSnapshot {
52
+ reserve: PublicKey;
53
+ tokenMint: PublicKey;
54
+ liquidityDecimals: number;
55
+ collateralSupplyRaw: bigint;
56
+ totalLiquiditySupplyScaled: bigint;
57
+ collateralExchangeRateSf: bigint;
58
+ }
59
+ export interface KaminoTrackedBalanceCostBasis {
60
+ trackedShareAmountRaw: bigint;
61
+ trackedLiquidityAmountRaw: bigint;
62
+ }
63
+ export interface KaminoPositionYieldInfo {
64
+ reserve: PublicKey;
65
+ tokenMint: PublicKey;
66
+ liquidityDecimals: number;
67
+ shareAmountRaw: bigint;
68
+ currentLiquidityAmountRaw: bigint;
69
+ trackedShareAmountRaw: bigint | null;
70
+ trackedLiquidityAmountRaw: bigint | null;
71
+ currentTrackedLiquidityCostBasisRaw: bigint | null;
72
+ earnedLiquidityAmountRaw: bigint | null;
73
+ }
51
74
  /**
52
75
  * Data structure for a username-based deposit account
53
76
  */
54
77
  export interface UsernameDepositData {
55
- username: string;
78
+ usernameHash: number[];
56
79
  tokenMint: PublicKey;
57
80
  amount: bigint;
58
81
  address: PublicKey;
@@ -91,6 +114,24 @@ export interface ModifyBalanceResult {
91
114
  signature: string;
92
115
  deposit: DepositData;
93
116
  }
117
+ export interface GetKaminoShieldedBalanceQuoteParams {
118
+ tokenMint: PublicKey;
119
+ collateralSharesAmountRaw: number | bigint;
120
+ principalLiquidityAmountRaw?: number | bigint | null;
121
+ shieldCollateralExchangeRateSf?: number | bigint | null;
122
+ }
123
+ export interface GetKaminoCollateralSharesForLiquidityAmountParams {
124
+ tokenMint: PublicKey;
125
+ liquidityAmountRaw: number | bigint;
126
+ }
127
+ export interface KaminoShieldedBalanceQuote {
128
+ snapshot: KaminoReserveSnapshot;
129
+ collateralSharesAmountRaw: bigint;
130
+ redeemableLiquidityAmountRaw: bigint;
131
+ principalLiquidityAmountRaw: bigint | null;
132
+ earnedLiquidityAmountRaw: bigint | null;
133
+ shieldCollateralExchangeRateSf: bigint | null;
134
+ }
94
135
  export interface ClaimUsernameDepositToDepositParams {
95
136
  username: string;
96
137
  tokenMint: PublicKey;
@@ -0,0 +1 @@
1
+ export declare function sha256hash(data: string): Promise<number[]>;
@@ -0,0 +1,2 @@
1
+ import type { Keypair } from "@solana/web3.js";
2
+ export declare function createKeypairMessageSigner(keypair: Keypair): (message: Uint8Array) => Promise<Uint8Array>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@loyal-labs/private-transactions",
3
- "version": "0.2.6",
3
+ "version": "0.2.8",
4
4
  "description": "SDK for Telegram-based private Solana deposits",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -51,9 +51,6 @@
51
51
  "@solana/spl-token": "^0.4.14",
52
52
  "@solana/web3.js": "^1.95.0"
53
53
  },
54
- "dependencies": {
55
- "tweetnacl": "^1.0.3"
56
- },
57
54
  "devDependencies": {
58
55
  "@coral-xyz/anchor": "^0.32.1",
59
56
  "@solana/web3.js": "^1.95.0",