@glamsystems/glam-sdk 0.1.16 → 0.1.17

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/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "@glamsystems/glam-sdk",
3
- "version": "0.1.16",
3
+ "version": "0.1.17",
4
4
  "description": "TypeScript SDK for the GLAM Protocol",
5
5
  "main": "./index.cjs.js",
6
6
  "module": "./index.esm.js",
7
7
  "homepage": "https://www.glam.systems",
8
8
  "repository": {
9
9
  "type": "git",
10
- "url": "git@github.com:glamsystems/glam-sdk.git"
10
+ "url": "git@github.com:glamsystems/glam.git"
11
11
  },
12
12
  "keywords": [
13
13
  "glam",
@@ -20,16 +20,15 @@
20
20
  "dependencies": {
21
21
  "@coral-xyz/anchor": "^0.31.0",
22
22
  "@coral-xyz/borsh": "^0.31.0",
23
- "@drift-labs/sdk": "2.118.0-beta.7",
23
+ "@drift-labs/sdk": "2.114.0-beta.3",
24
24
  "@marinade.finance/marinade-ts-sdk": "^5.0.15",
25
+ "@pythnetwork/client": "^2.21.1",
25
26
  "@solana/spl-stake-pool": "^1.1.5",
26
27
  "@solana/spl-token": "^0.4.9",
27
28
  "@solana/spl-token-metadata": "^0.1.4",
28
29
  "@solana/web3.js": "^1.98.0",
29
- "@meteora-ag/dlmm": "^1.4.11",
30
30
  "bs58": "^5.0.0",
31
- "buffer": "^6.0.3",
32
- "@switchboard-xyz/common": "^3.0.0"
31
+ "buffer": "^6.0.3"
33
32
  },
34
33
  "engines": {
35
34
  "node": ">=20.18.0"
@@ -38,20 +37,13 @@
38
37
  "@rollup/plugin-terser": "^0.4.4",
39
38
  "rollup-plugin-javascript-obfuscator": "^1.0.4"
40
39
  },
41
- "peerDependencies": {
42
- "solana-bankrun": "^0.4.0",
43
- "@coral-xyz/anchor": "^0.31.0",
44
- "@solana/web3.js": "^1.98.0"
45
- },
46
40
  "pnpm": {
47
41
  "overrides": {
48
- "anchor-bankrun": "^0.4.0",
49
- "solana-bankrun": "^0.4.0",
50
- "@coral-xyz/anchor": "^0.31.0",
51
- "@solana/web3.js": "^1.98.0",
52
- "@solana/spl-token": "^0.4.6",
53
- "@solana/spl-stake-pool": "^1.1.5",
54
- "typescript": "^5.5.3"
42
+ "@solana/web3.js@>=0.0.1": "^1.98.0",
43
+ "@solana/spl-token@>=0.0.1": "^0.4.6",
44
+ "@solana/spl-stake-pool@>=0.0.1": "^1.1.5",
45
+ "typescript@>=0.0.1": "^5.5.3",
46
+ "solana-bankrun@>=0.0.1": "^0.3.0"
55
47
  }
56
48
  },
57
49
  "types": "./index.esm.d.ts"
@@ -2,17 +2,11 @@ import { PublicKey } from "@solana/web3.js";
2
2
  /**
3
3
  * Metadata for an asset for pricing
4
4
  */
5
- export declare class AssetMeta {
6
- pricingAccount?: PublicKey;
7
- stateAccount?: PublicKey;
8
- priceFeed?: string;
5
+ export interface AssetMeta {
6
+ decimals: number;
7
+ oracle: PublicKey;
9
8
  programId?: PublicKey;
10
9
  }
11
- /**
12
- * We use sponsored feed listed on https://docs.pyth.network/price-feeds/sponsored-feeds/solana for popular tokens.
13
- *
14
- * For PYUSD, we use the price feed from Drift.
15
- * For LSTs, we use the state account to calculate the price based on the number of SOLs locked.
16
- */
17
10
  export declare const ASSETS_MAINNET: Map<string, AssetMeta>;
18
11
  export declare const ASSETS_TESTS: Map<string, AssetMeta>;
12
+ export declare const SOL_ORACLE: PublicKey;
@@ -52,7 +52,7 @@ export declare class BaseClient {
52
52
  intoVersionedTransaction(tx: Transaction, { lookupTables, signer, computeUnitLimit, getPriorityFeeMicroLamports, maxFeeLamports, useMaxFee, jitoTipLamports, simulate, }: TxOptions): Promise<VersionedTransaction>;
53
53
  sendAndConfirm(tx: VersionedTransaction | Transaction, additionalSigners?: Keypair[]): Promise<TransactionSignature>;
54
54
  parseProgramLogs(logs?: null | string[]): string;
55
- getAdressLookupTableAccounts(keys?: string[]): Promise<AddressLookupTableAccount[]>;
55
+ getAdressLookupTableAccounts(keys?: string[] | PublicKey[]): Promise<AddressLookupTableAccount[]>;
56
56
  getWallet(): Wallet;
57
57
  getSigner(): PublicKey;
58
58
  getAta(mint: PublicKey, owner: PublicKey, tokenProgram?: anchor.web3.PublicKey): PublicKey;
@@ -3,7 +3,7 @@ import { PublicKey, VersionedTransaction, TransactionSignature, TransactionInstr
3
3
  import { MarketType, OrderParams, PositionDirection, SpotPosition, PerpPosition, ModifyOrderParams } from "@drift-labs/sdk";
4
4
  import { BaseClient, TxOptions } from "./base";
5
5
  import { AccountMeta } from "@solana/web3.js";
6
- import { StateModel } from "../models";
6
+ import { PriceDenom, StateModel } from "../models";
7
7
  interface OrderConstants {
8
8
  perpBaseScale: number;
9
9
  quoteScale: number;
@@ -57,7 +57,7 @@ export interface GlamDriftUser {
57
57
  export declare class DriftClient {
58
58
  readonly base: BaseClient;
59
59
  constructor(base: BaseClient);
60
- initialize(statePda: PublicKey, subAccountId?: number, txOptions?: TxOptions): Promise<TransactionSignature>;
60
+ initialize(statePda: PublicKey | string, subAccountId?: number, txOptions?: TxOptions): Promise<TransactionSignature>;
61
61
  updateUserCustomMarginRatio(statePda: PublicKey, maxLeverage: number, // 1=1x, 2=2x ... 50=50x leverage
62
62
  subAccountId?: number): Promise<TransactionSignature>;
63
63
  updateUserMarginTradingEnabled(statePda: PublicKey, marginTradingEnabled: boolean, subAccountId?: number, txOptions?: TxOptions): Promise<TransactionSignature>;
@@ -69,7 +69,8 @@ export declare class DriftClient {
69
69
  modifyOrder(statePda: PublicKey | string, modifyOrderParams: ModifyOrderParams, subAccountId: number, marketConfigs: DriftMarketConfigs, txOptions?: TxOptions): Promise<TransactionSignature>;
70
70
  cancelOrders(statePda: PublicKey | string, marketType: MarketType, marketIndex: number, direction: PositionDirection, subAccountId: number, marketConfigs: DriftMarketConfigs, txOptions?: TxOptions): Promise<TransactionSignature>;
71
71
  cancelOrdersByIds(statePda: PublicKey | string, orderIds: number[], subAccountId: number, marketConfigs: DriftMarketConfigs, txOptions?: TxOptions): Promise<TransactionSignature>;
72
- priceDrift(statePda: PublicKey | string, marketConfigs: DriftMarketConfigs, txOptions?: TxOptions): Promise<TransactionSignature>;
72
+ settlePnl(statePda: PublicKey | string, marketIndex: number, subAccountId: number, marketConfigs: DriftMarketConfigs, txOptions?: TxOptions): Promise<TransactionSignature>;
73
+ priceDrift(statePda: PublicKey | string, marketConfigs: DriftMarketConfigs, priceDenom: PriceDenom, txOptions?: TxOptions): Promise<TransactionSignature>;
73
74
  getUser(statePda: PublicKey | string, subAccountId?: number): PublicKey[];
74
75
  fetchMarketConfigs(): Promise<DriftMarketConfigs>;
75
76
  fetchGlamDriftUser(glamState: PublicKey | string, subAccountId?: number): Promise<GlamDriftUser>;
@@ -108,6 +109,7 @@ export declare class DriftClient {
108
109
  modifyOrderTx(statePda: PublicKey, modifyOrderParams: ModifyOrderParams, subAccountId: number, marketConfigs: DriftMarketConfigs, txOptions?: TxOptions): Promise<VersionedTransaction>;
109
110
  cancelOrdersTx(glamState: PublicKey, marketType: MarketType, marketIndex: number, direction: PositionDirection, subAccountId: number, marketConfigs: DriftMarketConfigs, txOptions?: TxOptions): Promise<VersionedTransaction>;
110
111
  cancelOrdersByIdsTx(glamState: PublicKey, orderIds: number[], subAccountId: number, marketConfigs: DriftMarketConfigs, txOptions?: TxOptions): Promise<VersionedTransaction>;
111
- priceDriftTx(glamState: PublicKey, marketConfigs: DriftMarketConfigs, txOptions?: TxOptions): Promise<VersionedTransaction>;
112
+ settlePnlTx(glamState: PublicKey, marketIndex: number, subAccountId: number, marketConfigs: DriftMarketConfigs, txOptions?: TxOptions): Promise<VersionedTransaction>;
113
+ priceDriftTx(glamState: PublicKey, marketConfigs: DriftMarketConfigs, priceDenom: PriceDenom, txOptions?: TxOptions): Promise<VersionedTransaction>;
112
114
  }
113
115
  export {};
@@ -1,17 +1,123 @@
1
1
  import { BN } from "@coral-xyz/anchor";
2
- import { PublicKey, VersionedTransaction, TransactionSignature } from "@solana/web3.js";
2
+ import { PublicKey, VersionedTransaction, TransactionSignature, TransactionInstruction } from "@solana/web3.js";
3
3
  import { BaseClient, TxOptions } from "./base";
4
+ interface ParsedReserve {
5
+ address: PublicKey;
6
+ farmCollateral?: PublicKey;
7
+ farmDebt?: PublicKey;
8
+ liquidityMint: PublicKey;
9
+ liquiditySupplyVault: PublicKey;
10
+ collateralMint: PublicKey;
11
+ collateralSupplyVault: PublicKey;
12
+ feeVault: PublicKey;
13
+ }
14
+ interface ParsedObligation {
15
+ deposits: {
16
+ reserve: PublicKey;
17
+ }[];
18
+ borrows: {
19
+ reserve: PublicKey;
20
+ }[];
21
+ }
4
22
  export declare class KaminoLendingClient {
5
23
  readonly base: BaseClient;
24
+ private reserves;
25
+ private obligations;
6
26
  constructor(base: BaseClient);
7
- initialize(statePda: PublicKey, txOptions?: TxOptions): Promise<TransactionSignature>;
8
- deposit(statePda: PublicKey, amount: BN | number, txOptions?: TxOptions): Promise<TransactionSignature>;
27
+ /**
28
+ * Initializes Kamino user metadata
29
+ *
30
+ * @param statePda
31
+ * @param market Lending market
32
+ * @param referrer Referrer user metadata
33
+ * @param txOptions
34
+ * @returns
35
+ */
36
+ initUserMetadata(statePda: PublicKey | string, referrer?: PublicKey | string, txOptions?: TxOptions): Promise<TransactionSignature>;
37
+ /**
38
+ * Deposits asset to the lending market.
39
+ *
40
+ * @param statePda
41
+ * @param market Lending market
42
+ * @param asset Asset mint
43
+ * @param amount Amount to deposit
44
+ * @param txOptions
45
+ * @returns
46
+ */
47
+ deposit(statePda: PublicKey | string, market: PublicKey | string, asset: PublicKey | string, amount: BN | number, txOptions?: TxOptions): Promise<TransactionSignature>;
48
+ /**
49
+ * Withdraws asset from the lending market.
50
+ *
51
+ * @param statePda
52
+ * @param market Lending market
53
+ * @param asset Asset mint
54
+ * @param amount Amount to deposit
55
+ * @param txOptions
56
+ * @returns
57
+ */
58
+ withdraw(statePda: PublicKey | string, market: PublicKey | string, asset: PublicKey | string, amount: BN | number, txOptions?: TxOptions): Promise<TransactionSignature>;
59
+ /**
60
+ * Borrows asset from the lending market.
61
+ *
62
+ * @param statePda GLAM state
63
+ * @param market Lending market
64
+ * @param asset Asset mint
65
+ * @param amount Amount to borrow
66
+ * @param txOptions
67
+ * @returns
68
+ */
69
+ borrow(statePda: PublicKey | string, market: PublicKey | string, asset: PublicKey | string, amount: BN | number, txOptions?: TxOptions): Promise<TransactionSignature>;
70
+ /**
71
+ * Repays asset to the lending market.
72
+ *
73
+ * @param statePda
74
+ * @param market
75
+ * @param asset
76
+ * @param amount
77
+ * @param txOptions
78
+ * @returns
79
+ */
80
+ repay(statePda: PublicKey | string, market: PublicKey | string, asset: PublicKey | string, amount: BN | number, txOptions?: TxOptions): Promise<TransactionSignature>;
9
81
  getUserMetadataPda(owner: PublicKey): PublicKey;
10
- getObligationPda(owner: PublicKey, args: {
82
+ getObligationPda(owner: PublicKey, market: PublicKey, args?: {
11
83
  tag: number;
12
84
  id: number;
13
85
  }): PublicKey;
14
- getObligationFarm(obligation: PublicKey): PublicKey;
15
- initializeTx(statePda: PublicKey, txOptions: TxOptions): Promise<VersionedTransaction>;
16
- depositTx(statePda: PublicKey, asset: PublicKey, amount: number | BN, txOptions: TxOptions): Promise<VersionedTransaction>;
86
+ getObligationFarmState(obligation: PublicKey, farm: PublicKey): PublicKey;
87
+ initUserMetadataTx(glamState: PublicKey, referrer: PublicKey, txOptions: TxOptions): Promise<VersionedTransaction>;
88
+ refreshReserveIxs(lendingMarket: PublicKey, reserves: PublicKey[]): TransactionInstruction[];
89
+ refreshObligationFarmsForReserveIxs(obligation: PublicKey, lendingMarket: PublicKey, parsedReserves: ParsedReserve[]): TransactionInstruction[];
90
+ /**
91
+ * Returns an array of instructions for refreshing an existing obligation and reserves it depends on.
92
+ */
93
+ getRefreshIxs(obligation: PublicKey, lendingMarket: PublicKey): Promise<TransactionInstruction[]>;
94
+ getMarketAuthority(market: PublicKey): PublicKey;
95
+ reservePdas(market: PublicKey, mint: PublicKey): {
96
+ liquiditySupplyVault: PublicKey;
97
+ collateralMint: PublicKey;
98
+ collateralSupplyVault: PublicKey;
99
+ feeVault: PublicKey;
100
+ };
101
+ /**
102
+ * Fetches and parses obligation account
103
+ *
104
+ * @param obligation User obligation pubkey
105
+ * @returns Pubkeys of reserves for deposits and borrows
106
+ */
107
+ fetchAndParseObligation(obligation: PublicKey): Promise<ParsedObligation>;
108
+ pubkeyArraysEqual: (a: PublicKey[], b: PublicKey[]) => boolean;
109
+ /**
110
+ * We only need pubkeys that don't change over time. No need to fetch them every time.
111
+ *
112
+ * @param market
113
+ * @param asset
114
+ * @returns
115
+ */
116
+ fetchAndParseReserves(reserves: PublicKey[]): Promise<ParsedReserve[]>;
117
+ findAndParseReserve(market: PublicKey, asset: PublicKey): Promise<ParsedReserve>;
118
+ depositTx(glamState: PublicKey, market: PublicKey, asset: PublicKey, amount: BN, txOptions: TxOptions): Promise<VersionedTransaction>;
119
+ withdrawTx(glamState: PublicKey, market: PublicKey, asset: PublicKey, amount: BN, txOptions: TxOptions): Promise<VersionedTransaction>;
120
+ borrowTx(glamState: PublicKey, market: PublicKey, asset: PublicKey, amount: BN, txOptions: TxOptions): Promise<VersionedTransaction>;
121
+ repayTx(glamState: PublicKey, market: PublicKey, asset: PublicKey, amount: BN, txOptions?: TxOptions): Promise<VersionedTransaction>;
17
122
  }
123
+ export {};
@@ -15,17 +15,9 @@ export declare class MeteoraDlmmClient {
15
15
  closePosition(statePda: PublicKey | string, position: PublicKey | string, txOptions?: TxOptions): Promise<TransactionSignature>;
16
16
  getPositionPda(lbPair: PublicKey, base: PublicKey, lowerBinId: number, // i32
17
17
  width: number): PublicKey;
18
- fetchPositions(owner: PublicKey): Promise<PublicKey[]>;
19
- parsePosition(position: PublicKey): Promise<{
20
- lowerBinId: number;
21
- upperBinId: number;
22
- binArrayLower: PublicKey;
23
- binArrayUpper: PublicKey;
24
- lbPair: PublicKey;
25
- }>;
26
18
  autoFillY(dlmmPool: DLMM, amountX: BN): Promise<{
27
19
  amountX: BN;
28
- amountY: any;
20
+ amountY: BN;
29
21
  activeBinId: number;
30
22
  }>;
31
23
  }
@@ -1,15 +1,28 @@
1
1
  import { PublicKey, TransactionInstruction } from "@solana/web3.js";
2
+ import { BN } from "@coral-xyz/anchor";
2
3
  import { BaseClient } from "./base";
4
+ import { PriceDenom } from "../models";
3
5
  export declare class PriceClient {
4
6
  readonly base: BaseClient;
5
7
  constructor(base: BaseClient);
6
8
  /**
7
9
  * !! This is a convenience method that calculates the AUM of the vault based on priced assets.
8
- * !! It doesn't reflect the actual AUM of the vault. If the vault has not been priced or pricing data is outdated, the number is NOT meaningful.
10
+ * !! It doesn't reflect the actual AUM of the vault.
11
+ * !! If the vault has not been priced or pricing data is outdated, the number is NOT meaningful.
9
12
  */
10
13
  getAum(glamState: PublicKey): Promise<BN>;
11
- priceVaultIxs(glamState: PublicKey): Promise<TransactionInstruction[]>;
12
- remainingAccountsForPricing: (glamState: PublicKey) => Promise<{
14
+ priceVaultIxs(glamState: PublicKey, priceDenom: PriceDenom): Promise<TransactionInstruction[]>;
15
+ remainingAccountsForPricingKamino: (glamState: PublicKey) => Promise<{
16
+ pubkey: PublicKey;
17
+ isSigner: boolean;
18
+ isWritable: boolean;
19
+ }[]>;
20
+ remainingAccountsForPricingMeteora: (glamState: PublicKey) => Promise<{
21
+ pubkey: PublicKey;
22
+ isSigner: boolean;
23
+ isWritable: boolean;
24
+ }[]>;
25
+ remainingAccountsForPricingVaultAssets: (glamState: PublicKey) => Promise<{
13
26
  pubkey: PublicKey;
14
27
  isSigner: boolean;
15
28
  isWritable: boolean;
@@ -6,6 +6,8 @@ export declare const SEED_VAULT: string;
6
6
  export declare const SEED_ESCROW: string;
7
7
  export declare const MARINADE_TICKET_SIZE = 88;
8
8
  export declare const STAKE_ACCOUNT_SIZE = 200;
9
+ export declare const METEORA_POSITION_SIZE = 8120;
10
+ export declare const KAMINO_OBTRIGATION_SIZE = 3344;
9
11
  export declare const JITO_TIP_DEFAULT: PublicKey;
10
12
  /**
11
13
  * Token mints. If no devnet version is defined, assume mainnet and devnet addresses are the same.
@@ -30,6 +32,10 @@ export declare const GOVERNANCE_PROGRAM_ID: PublicKey;
30
32
  export declare const JUP_VOTE_PROGRAM: PublicKey;
31
33
  export declare const MERKLE_DISTRIBUTOR_PROGRAM: PublicKey;
32
34
  export declare const TRANSFER_HOOK_PROGRAM: PublicKey;
35
+ export declare const METEORA_DLMM_PROGRAM: PublicKey;
36
+ export declare const KAMINO_LENDING_PROGRAM: PublicKey;
37
+ export declare const KAMINO_FARM_PROGRAM: PublicKey;
38
+ export declare const MEMO_PROGRAM: PublicKey;
33
39
  /**
34
40
  * Stake pools
35
41
  */
package/src/index.d.ts CHANGED
@@ -9,3 +9,4 @@ export * from "./utils/helpers";
9
9
  export * from "./utils/priorityfee";
10
10
  export * from "./constants";
11
11
  export * from "./error";
12
+ export * from "./client/assets";
package/src/models.d.ts CHANGED
@@ -178,3 +178,11 @@ export type FeeStructure = IdlTypes<GlamProtocol>["feeStructure"];
178
178
  export type FeeParams = IdlTypes<GlamProtocol>["feeParams"];
179
179
  export type AccruedFees = IdlTypes<GlamProtocol>["accruedFees"];
180
180
  export type Valuation = IdlTypes<GlamProtocol>["valuation"];
181
+ export declare class PriceDenom {
182
+ static readonly SOL: {
183
+ sol: {};
184
+ };
185
+ static readonly USD: {
186
+ usd: {};
187
+ };
188
+ }
@@ -4,4 +4,13 @@ export declare const fetchMarinadeTicketAccounts: (connection: Connection, benef
4
4
  pubkey: PublicKey;
5
5
  account: import("@solana/web3.js").AccountInfo<Buffer | import("@solana/web3.js").ParsedAccountData>;
6
6
  }[]>;
7
+ export declare const fetchKaminoObligations: (connection: Connection, owner: PublicKey, market?: PublicKey) => Promise<PublicKey[]>;
8
+ export declare const fetchMeteoraPositions: (connection: Connection, owner: PublicKey) => Promise<PublicKey[]>;
9
+ export declare const parseMeteoraPosition: (connection: Connection, position: PublicKey) => Promise<{
10
+ lbPair: PublicKey;
11
+ lowerBinId: number;
12
+ upperBinId: number;
13
+ binArrayLower: PublicKey;
14
+ binArrayUpper: PublicKey;
15
+ }>;
7
16
  export declare const getSimulationComputeUnits: (connection: Connection, instructions: Array<TransactionInstruction>, payer: PublicKey, lookupTables?: Array<AddressLookupTableAccount>) => Promise<number | undefined>;