@glamsystems/glam-sdk 1.0.7 → 1.0.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 (56) hide show
  1. package/index.cjs.js +2989 -951
  2. package/index.esm.js +2986 -951
  3. package/package.json +3 -2
  4. package/src/assets.d.ts +1 -1
  5. package/src/client/base.d.ts +2 -0
  6. package/src/client/cctp.d.ts +2 -1
  7. package/src/client/price.d.ts +54 -9
  8. package/src/client/state.d.ts +2 -0
  9. package/src/clientConfig.d.ts +2 -0
  10. package/src/glamExports.d.ts +613 -0
  11. package/src/models/state.d.ts +2 -0
  12. package/src/utils/computeBudget.d.ts +1 -2
  13. package/src/utils/index.d.ts +1 -1
  14. package/src/utils/jupiterApi.d.ts +5 -1
  15. package/src/utils/positionCategorizer.d.ts +54 -0
  16. package/src/utils/rpc.d.ts +33 -3
  17. package/target/idl/ext_cctp.json +6 -0
  18. package/target/idl/ext_drift-staging.json +6 -0
  19. package/target/idl/ext_drift.json +6 -0
  20. package/target/idl/ext_kamino-staging.json +6 -0
  21. package/target/idl/ext_kamino.json +6 -0
  22. package/target/idl/ext_marinade.json +6 -0
  23. package/target/idl/ext_spl-staging.json +6 -0
  24. package/target/idl/ext_spl.json +6 -0
  25. package/target/idl/ext_stake_pool-staging.json +6 -0
  26. package/target/idl/ext_stake_pool.json +6 -0
  27. package/target/idl/glam_config.json +25 -36
  28. package/target/idl/glam_mint-staging.json +6 -0
  29. package/target/idl/glam_mint.json +6 -0
  30. package/target/idl/glam_protocol-staging.json +117 -9
  31. package/target/idl/glam_protocol.json +36 -8
  32. package/target/types/ext_cctp.d.ts +6 -0
  33. package/target/types/ext_cctp.ts +6 -0
  34. package/target/types/ext_drift-staging.ts +6 -0
  35. package/target/types/ext_drift.d.ts +6 -0
  36. package/target/types/ext_drift.ts +6 -0
  37. package/target/types/ext_kamino-staging.ts +6 -0
  38. package/target/types/ext_kamino.d.ts +6 -0
  39. package/target/types/ext_kamino.ts +6 -0
  40. package/target/types/ext_marinade.d.ts +6 -0
  41. package/target/types/ext_marinade.ts +6 -0
  42. package/target/types/ext_spl-staging.ts +6 -0
  43. package/target/types/ext_spl.d.ts +6 -0
  44. package/target/types/ext_spl.ts +6 -0
  45. package/target/types/ext_stake_pool-staging.ts +6 -0
  46. package/target/types/ext_stake_pool.d.ts +6 -0
  47. package/target/types/ext_stake_pool.ts +6 -0
  48. package/target/types/glam_config.d.ts +20 -31
  49. package/target/types/glam_config.ts +25 -36
  50. package/target/types/glam_mint-staging.ts +6 -0
  51. package/target/types/glam_mint.d.ts +6 -0
  52. package/target/types/glam_mint.ts +6 -0
  53. package/target/types/glam_protocol-staging.ts +117 -9
  54. package/target/types/glam_protocol.d.ts +36 -8
  55. package/target/types/glam_protocol.ts +36 -8
  56. package/src/utils/priorityfee.d.ts +0 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@glamsystems/glam-sdk",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "description": "TypeScript SDK for the GLAM Protocol",
5
5
  "main": "./index.cjs.js",
6
6
  "module": "./index.esm.js",
@@ -29,10 +29,11 @@
29
29
  "bs58": "^6.0.0",
30
30
  "buffer": "^6.0.3",
31
31
  "decimal.js": "^10.6.0",
32
+ "fzstd": "^0.1.1",
32
33
  "zod": "^3.24.3"
33
34
  },
34
35
  "engines": {
35
- "node": ">=20.18.0"
36
+ "node": ">=20.20.0"
36
37
  },
37
38
  "devDependencies": {
38
39
  "@rollup/plugin-terser": "^0.4.4"
package/src/assets.d.ts CHANGED
@@ -43,4 +43,4 @@ export declare const USDC_ORACLE: PublicKey;
43
43
  * @param cluster The cluster network (defaults to mainnet)
44
44
  * @returns Metadata of the asset
45
45
  */
46
- export declare function getAssetMeta(assetMint: string, cluster?: ClusterNetwork): AssetMeta;
46
+ export declare function getAssetMeta(assetMint: string | PublicKey, cluster?: ClusterNetwork): AssetMeta;
@@ -6,6 +6,7 @@ import { ExtCctpProgram, ExtDriftProgram, ExtKaminoProgram, ExtMarinadeProgram,
6
6
  import { ClusterNetwork, GlamClientConfig } from "../clientConfig";
7
7
  import { RequestQueue, StateAccount, StateModel } from "../models";
8
8
  import { BlockhashWithCache } from "../utils/blockhash";
9
+ import { JupiterApiClient } from "../utils";
9
10
  export type TxOptions = {
10
11
  signer?: PublicKey;
11
12
  computeUnitLimit?: number;
@@ -32,6 +33,7 @@ export declare class BaseClient {
32
33
  provider: anchor.Provider;
33
34
  blockhashWithCache: BlockhashWithCache;
34
35
  jupiterApiKey?: string;
36
+ jupiterApiClient?: JupiterApiClient;
35
37
  private _protocolProgram?;
36
38
  private _mintProgram?;
37
39
  private _extSplProgram?;
@@ -1,5 +1,5 @@
1
1
  import { BN } from "@coral-xyz/anchor";
2
- import { PublicKey, VersionedTransaction, TransactionSignature, Keypair, Commitment, Finality, TransactionInstruction } from "@solana/web3.js";
2
+ import { PublicKey, VersionedTransaction, TransactionSignature, Keypair, Commitment, Finality, TransactionInstruction, VersionedTransactionResponse } from "@solana/web3.js";
3
3
  import { BaseClient, BaseTxBuilder, TxOptions } from "./base";
4
4
  export declare class CctpBridgeEvent {
5
5
  readonly amount: BN;
@@ -122,6 +122,7 @@ export declare class CctpClient {
122
122
  txHash?: string;
123
123
  nonce?: string;
124
124
  }): Promise<CctpBridgeEvent[]>;
125
+ getTransactions(signatures: string[], batchSize: number, commitment?: Finality): Promise<VersionedTransactionResponse[]>;
125
126
  /**
126
127
  * Get incoming bridge events (EVM -> Solana)
127
128
  *
@@ -7,6 +7,17 @@ import { DriftProtocolClient, DriftVaultsClient } from "./drift";
7
7
  import { PkMap, PkSet } from "../utils";
8
8
  import { DriftSpotMarket, DriftPerpMarket, DriftVault, KVaultState, Reserve, DriftVaultDepositor } from "../deser";
9
9
  import { JupiterApiClient, TokenListItem } from "../utils/jupiterApi";
10
+ /**
11
+ * Represents a single asset holding within a vault.
12
+ *
13
+ * @param mintAddress - The SPL token mint address of the held asset
14
+ * @param decimals - Number of decimal places for the token (e.g., 6 for USDC, 9 for SOL)
15
+ * @param amount - Unsigned token amount in native units; direction (deposit/borrow) is in protocolMeta
16
+ * @param price - Current price of the asset denominated in the base asset (e.g., USD, SOL)
17
+ * @param priceMeta - Additional pricing context (e.g., source, slot, base asset). Default base asset, if not specified, is USD.
18
+ * @param protocol - Protocol identifier where the asset is allocated
19
+ * @param protocolMeta - Protocol-specific metadata (e.g., market index, position direction, reserve address)
20
+ */
10
21
  export declare class Holding {
11
22
  readonly mintAddress: PublicKey;
12
23
  readonly decimals: number;
@@ -18,6 +29,17 @@ export declare class Holding {
18
29
  readonly uiAmount: number;
19
30
  constructor(mintAddress: PublicKey, decimals: number, amount: BN, price: number, priceMeta: Record<string, any> | undefined, protocol: string, protocolMeta?: Record<string, any>);
20
31
  }
32
+ /**
33
+ * Aggregates all holdings for a GLAM vault.
34
+ * Includes token balances, DeFi positions (Drift, Kamino).
35
+ *
36
+ * @param vaultState - The vault's state account address (stores vault configuration)
37
+ * @param vaultPda - The vault's PDA that holds tokens and positions
38
+ * @param priceBaseAssetMint - The base asset mint used for pricing (e.g., PublicKey.default for USD, So11111111111111111111111111111111111111112 for SOL)
39
+ * @param slot - The Solana slot at which holdings were fetched
40
+ * @param timestamp - Unix timestamp (seconds) when holdings were fetched
41
+ * @param commitment - The Solana commitment level used for fetching account data
42
+ */
21
43
  export declare class VaultHoldings {
22
44
  readonly vaultState: PublicKey;
23
45
  readonly vaultPda: PublicKey;
@@ -48,22 +70,45 @@ export declare class PriceClient {
48
70
  /**
49
71
  * Fetches all holdings in the vault.
50
72
  *
73
+ * The source of truth for external positions is the `externalPositions` array
74
+ * from the state account, which tracks:
75
+ * - Drift user PDAs (direct trading positions)
76
+ * - Drift vault depositor accounts (shares in drift vaults)
77
+ * - Kamino obligation accounts (lending positions)
78
+ * - Kamino vault share ATAs (shares in kamino vaults)
79
+ *
51
80
  * @param commitment Commitment level for fetching accounts
52
- * @param priceBaseAssetMint Price reference/numeraire asset mint (default: USD)
81
+ * @param priceBaseAssetMint Price reference/numeraire asset mint (default: PublicKey.default for USD).
82
+ * Pass a token mint (e.g., WSOL) to get prices denominated in that asset.
53
83
  * @returns VaultHoldings object containing all holdings
54
84
  */
55
85
  getVaultHoldings(commitment: Commitment, priceBaseAssetMint?: PublicKey): Promise<VaultHoldings>;
56
86
  getPubkeysForTokenHoldings(externalPositionsSet: PkSet, commitment?: Commitment): Promise<PublicKey[]>;
57
87
  getPubkeysForSpotHoldings(driftUserPdas: PublicKey[], commitment?: Commitment): Promise<PkMap<PkSet>>;
58
88
  getPubkeysForPerpHoldings(driftUserPdas: PublicKey[], commitment?: Commitment): Promise<PkMap<PkSet>>;
59
- getDepositorsAndDriftVaults(commitment?: Commitment): Promise<PkMap<DriftVault>>;
60
- getKaminoVaultStates(externalPositionsSet: PkSet, commitment?: Commitment): Promise<PkMap<KVaultState>>;
61
- getPubkeysForKaminoHoldings(commitment?: Commitment): Promise<PkMap<PkSet>>;
62
- getTokenHoldings(tokenAccountPubkeys: PublicKey[], accountsDataMap: PkMap<Buffer>, tokenPricesMap: PkMap<TokenListItem>, priceSource: string): Holding[];
63
- getDriftHoldings(userPubkeys: Iterable<PublicKey>, spotMarketsMap: PkMap<DriftSpotMarket>, perpMarketsMap: PkMap<DriftPerpMarket>, accountsDataMap: PkMap<Buffer>, tokenPricesMap: PkMap<TokenListItem>, priceSource: string): Holding[];
64
- getDriftVaultsHoldings(dvaultDepositorsAndVaults: PkMap<DriftVault>, dvaultDepositorsMap: PkMap<DriftVaultDepositor>, spotMarketsMap: PkMap<DriftSpotMarket>, perpMarketsMap: PkMap<DriftPerpMarket>, accountsDataMap: PkMap<Buffer>, tokenPricesMap: PkMap<TokenListItem>, priceSource: string): Holding[];
65
- getKaminoLendHoldings(obligationPubkeys: Iterable<PublicKey>, reservesMap: PkMap<Reserve>, accountsDataMap: PkMap<Buffer>, tokenPricesMap: PkMap<TokenListItem>, priceSource: string): Holding[];
66
- getKaminoVaultsHoldings(kvaultAtasAndStates: PkMap<KVaultState>, reservesMap: PkMap<Reserve>, accountsDataMap: PkMap<Buffer>, tokenPricesMap: PkMap<TokenListItem>, priceSource: string): Holding[];
89
+ /**
90
+ * Parses drift vault depositors from known pubkeys.
91
+ */
92
+ getDepositorsAndDriftVaults(depositorPubkeys: PublicKey[], commitment?: Commitment): Promise<PkMap<DriftVault>>;
93
+ /**
94
+ * Gets kamino obligation reserves from known obligation pubkeys.
95
+ */
96
+ getPubkeysForKaminoHoldings(obligationPubkeys: PublicKey[], commitment?: Commitment): Promise<PkMap<PkSet>>;
97
+ /**
98
+ * Gets kamino vault states from known share ATA pubkeys.
99
+ * Used by getVaultHoldingsV2 to process vault shares from externalPositions.
100
+ */
101
+ getKaminoVaultStatesFromAtas(shareAtaPubkeys: PublicKey[], commitment?: Commitment): Promise<PkMap<KVaultState>>;
102
+ /**
103
+ * Fetches token price from the prefetched map, falling back to Jupiter API if not found.
104
+ * @throws Error if price cannot be fetched from either source
105
+ */
106
+ private getTokenPrice;
107
+ getTokenHoldings(tokenAccountPubkeys: PublicKey[], accountsDataMap: PkMap<Buffer>, tokenPricesMap: PkMap<TokenListItem>, priceSource: string): Promise<Holding[]>;
108
+ getDriftHoldings(userPubkeys: Iterable<PublicKey>, spotMarketsMap: PkMap<DriftSpotMarket>, perpMarketsMap: PkMap<DriftPerpMarket>, accountsDataMap: PkMap<Buffer>, tokenPricesMap: PkMap<TokenListItem>, priceSource: string): Promise<Holding[]>;
109
+ getDriftVaultsHoldings(dvaultDepositorsAndVaults: PkMap<DriftVault>, dvaultDepositorsMap: PkMap<DriftVaultDepositor>, spotMarketsMap: PkMap<DriftSpotMarket>, perpMarketsMap: PkMap<DriftPerpMarket>, accountsDataMap: PkMap<Buffer>, tokenPricesMap: PkMap<TokenListItem>, priceSource: string): Promise<Holding[]>;
110
+ getKaminoLendHoldings(obligationPubkeys: Iterable<PublicKey>, reservesMap: PkMap<Reserve>, accountsDataMap: PkMap<Buffer>, tokenPricesMap: PkMap<TokenListItem>, priceSource: string): Promise<Holding[]>;
111
+ getKaminoVaultsHoldings(kvaultAtasAndStates: PkMap<KVaultState>, reservesMap: PkMap<Reserve>, accountsDataMap: PkMap<Buffer>, tokenPricesMap: PkMap<TokenListItem>, priceSource: string): Promise<Holding[]>;
67
112
  /**
68
113
  * Returns an instruction that prices Kamino obligations.
69
114
  * If there are no Kamino obligations, returns null.
@@ -16,6 +16,8 @@ export type UpdateStateParams = {
16
16
  timelockDuration?: number;
17
17
  assets?: PublicKey[];
18
18
  borrowable?: PublicKey[];
19
+ reduceOnly?: boolean;
20
+ anyLst?: boolean;
19
21
  };
20
22
  declare class TxBuilder extends BaseTxBuilder<StateClient> {
21
23
  initializeIx(params: InitStateParams, glamSigner: PublicKey): Promise<[TransactionInstruction, PublicKey]>;
@@ -1,5 +1,6 @@
1
1
  import { Provider, Wallet } from "@coral-xyz/anchor";
2
2
  import { PublicKey } from "@solana/web3.js";
3
+ import { JupiterApiClient } from "./utils";
3
4
  export declare enum ClusterNetwork {
4
5
  Mainnet = "mainnet-beta",
5
6
  Testnet = "testnet",
@@ -23,4 +24,5 @@ export type GlamClientConfig = {
23
24
  cluster?: ClusterNetwork;
24
25
  statePda?: PublicKey;
25
26
  jupiterApiKey?: string;
27
+ jupiterApiClient?: JupiterApiClient;
26
28
  };