@glamsystems/glam-sdk 0.1.20 → 0.1.21
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/index.cjs.js +1366 -155
- package/index.esm.js +1314 -153
- package/package.json +1 -3
- package/src/client/drift.d.ts +75 -60
- package/src/client/kamino.d.ts +1 -1
- package/src/client/meteora.d.ts +1 -1
- package/src/client/price.d.ts +0 -1
- package/src/index.d.ts +3 -0
- package/src/react/glam.d.ts +2 -2
- package/src/utils/driftOrderParams.d.ts +28 -0
- package/src/utils/driftTypes.d.ts +1422 -0
- package/src/utils/driftUser.d.ts +2 -0
- package/src/utils/helpers.d.ts +1 -0
- package/target/idl/glam_protocol.json +7 -2
- package/target/types/glam_protocol.d.ts +7 -2
- package/target/types/glam_protocol.ts +7 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@glamsystems/glam-sdk",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.21",
|
|
4
4
|
"description": "TypeScript SDK for the GLAM Protocol",
|
|
5
5
|
"main": "./index.cjs.js",
|
|
6
6
|
"module": "./index.esm.js",
|
|
@@ -20,9 +20,7 @@
|
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@coral-xyz/anchor": "^0.31.0",
|
|
22
22
|
"@coral-xyz/borsh": "^0.31.0",
|
|
23
|
-
"@drift-labs/sdk": "2.114.0-beta.3",
|
|
24
23
|
"@marinade.finance/marinade-ts-sdk": "^5.0.15",
|
|
25
|
-
"@pythnetwork/client": "^2.21.1",
|
|
26
24
|
"@meteora-ag/dlmm": "^1.4.11",
|
|
27
25
|
"@solana/spl-stake-pool": "^1.1.5",
|
|
28
26
|
"@solana/spl-token": "^0.4.9",
|
package/src/client/drift.d.ts
CHANGED
|
@@ -1,61 +1,61 @@
|
|
|
1
1
|
import * as anchor from "@coral-xyz/anchor";
|
|
2
2
|
import { PublicKey, VersionedTransaction, TransactionSignature, TransactionInstruction } from "@solana/web3.js";
|
|
3
|
-
import { MarketType, OrderParams, PositionDirection, SpotPosition, PerpPosition, ModifyOrderParams } from "
|
|
3
|
+
import { MarketType, OrderParams, PositionDirection, SpotPosition, PerpPosition, ModifyOrderParams, OracleSource, SpotBalanceType, MarginMode, Order } from "../utils/driftTypes";
|
|
4
4
|
import { BaseClient, TxOptions } from "./base";
|
|
5
5
|
import { AccountMeta } from "@solana/web3.js";
|
|
6
6
|
import { PriceDenom, StateModel } from "../models";
|
|
7
|
+
import { BN } from "@coral-xyz/anchor";
|
|
7
8
|
interface OrderConstants {
|
|
8
9
|
perpBaseScale: number;
|
|
9
10
|
quoteScale: number;
|
|
10
11
|
}
|
|
11
|
-
export interface
|
|
12
|
-
|
|
13
|
-
categories: string[];
|
|
14
|
-
symbol: string;
|
|
15
|
-
baseAsset: string;
|
|
12
|
+
export interface SpotMarket {
|
|
13
|
+
name: string;
|
|
16
14
|
marketIndex: number;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
marketPDA: string;
|
|
23
|
-
}
|
|
24
|
-
export interface SpotMarketConfig {
|
|
25
|
-
symbol: string;
|
|
15
|
+
marketPda: PublicKey;
|
|
16
|
+
vault: PublicKey;
|
|
17
|
+
oracle: PublicKey;
|
|
18
|
+
oracleSource: OracleSource;
|
|
19
|
+
mint: PublicKey;
|
|
26
20
|
decimals: number;
|
|
21
|
+
tokenProgram: PublicKey;
|
|
22
|
+
cumulativeDepositInterest: BN;
|
|
23
|
+
cumulativeBorrowInterest: BN;
|
|
24
|
+
}
|
|
25
|
+
export interface PerpMarket {
|
|
26
|
+
name: string;
|
|
27
27
|
marketIndex: number;
|
|
28
|
-
|
|
29
|
-
oracle:
|
|
30
|
-
oracleSource:
|
|
31
|
-
pythPullOraclePDA: string;
|
|
32
|
-
pythFeedId: string;
|
|
33
|
-
marketPDA: string;
|
|
34
|
-
mint: string;
|
|
35
|
-
serumMarket?: string;
|
|
36
|
-
phoenixMarket?: string;
|
|
37
|
-
openBookMarket?: string;
|
|
38
|
-
vaultPDA: string;
|
|
28
|
+
marketPda: PublicKey;
|
|
29
|
+
oracle: PublicKey;
|
|
30
|
+
oracleSource: OracleSource;
|
|
39
31
|
}
|
|
40
32
|
export interface DriftMarketConfigs {
|
|
41
33
|
orderConstants: OrderConstants;
|
|
42
|
-
|
|
43
|
-
|
|
34
|
+
perpMarkets: PerpMarket[];
|
|
35
|
+
spotMarkets: SpotMarket[];
|
|
44
36
|
}
|
|
45
|
-
export interface
|
|
46
|
-
delegate:
|
|
37
|
+
export interface DriftUser {
|
|
38
|
+
delegate: PublicKey;
|
|
47
39
|
name: string;
|
|
48
40
|
spotPositions: (SpotPosition & {
|
|
49
|
-
|
|
41
|
+
amount: number;
|
|
42
|
+
uiAmount: number;
|
|
43
|
+
mint: PublicKey;
|
|
44
|
+
decimals: number;
|
|
45
|
+
marketName: string;
|
|
50
46
|
})[];
|
|
51
47
|
perpPositions: PerpPosition[];
|
|
52
|
-
marginMode:
|
|
48
|
+
marginMode: MarginMode;
|
|
53
49
|
subAccountId: number;
|
|
54
50
|
isMarginTradingEnabled: boolean;
|
|
55
51
|
maxMarginRatio: number;
|
|
52
|
+
orders: Order[];
|
|
56
53
|
}
|
|
57
54
|
export declare class DriftClient {
|
|
58
55
|
readonly base: BaseClient;
|
|
56
|
+
private spotMarkets;
|
|
57
|
+
private perpMarkets;
|
|
58
|
+
private marketConfigs;
|
|
59
59
|
constructor(base: BaseClient);
|
|
60
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
|
|
@@ -63,35 +63,50 @@ export declare class DriftClient {
|
|
|
63
63
|
updateUserMarginTradingEnabled(statePda: PublicKey, marginTradingEnabled: boolean, subAccountId?: number, txOptions?: TxOptions): Promise<TransactionSignature>;
|
|
64
64
|
updateUserDelegate(statePda: PublicKey | string, delegate: PublicKey | string, subAccountId?: number): Promise<TransactionSignature>;
|
|
65
65
|
deleteUser(statePda: PublicKey | string, subAccountId?: number, txOptions?: TxOptions): Promise<TransactionSignature>;
|
|
66
|
-
deposit(statePda: PublicKey | string, amount: anchor.BN, marketIndex
|
|
67
|
-
withdraw(statePda: PublicKey | string, amount: anchor.BN, marketIndex
|
|
68
|
-
placeOrder(statePda: PublicKey | string, orderParams: OrderParams, subAccountId
|
|
69
|
-
modifyOrder(statePda: PublicKey | string, modifyOrderParams: ModifyOrderParams, subAccountId
|
|
70
|
-
cancelOrders(statePda: PublicKey | string, marketType: MarketType, marketIndex: number, direction: PositionDirection, subAccountId
|
|
71
|
-
cancelOrdersByIds(statePda: PublicKey | string, orderIds: number[], subAccountId
|
|
72
|
-
settlePnl(statePda: PublicKey | string, marketIndex: number, subAccountId
|
|
73
|
-
priceDrift(statePda: PublicKey | string,
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
66
|
+
deposit(statePda: PublicKey | string, amount: anchor.BN, marketIndex?: number, subAccountId?: number, txOptions?: TxOptions): Promise<TransactionSignature>;
|
|
67
|
+
withdraw(statePda: PublicKey | string, amount: anchor.BN, marketIndex?: number, subAccountId?: number, txOptions?: TxOptions): Promise<TransactionSignature>;
|
|
68
|
+
placeOrder(statePda: PublicKey | string, orderParams: OrderParams, subAccountId?: number, txOptions?: TxOptions): Promise<TransactionSignature>;
|
|
69
|
+
modifyOrder(statePda: PublicKey | string, modifyOrderParams: ModifyOrderParams, subAccountId?: number, txOptions?: TxOptions): Promise<TransactionSignature>;
|
|
70
|
+
cancelOrders(statePda: PublicKey | string, marketType: MarketType, marketIndex: number, direction: PositionDirection, subAccountId?: number, txOptions?: TxOptions): Promise<TransactionSignature>;
|
|
71
|
+
cancelOrdersByIds(statePda: PublicKey | string, orderIds: number[], subAccountId?: number, txOptions?: TxOptions): Promise<TransactionSignature>;
|
|
72
|
+
settlePnl(statePda: PublicKey | string, marketIndex: number, subAccountId?: number, txOptions?: TxOptions): Promise<TransactionSignature>;
|
|
73
|
+
priceDrift(statePda: PublicKey | string, priceDenom: PriceDenom, txOptions?: TxOptions): Promise<TransactionSignature>;
|
|
74
|
+
getMarketPda: (marketType: MarketType, marketIndex: number) => anchor.web3.PublicKey;
|
|
75
|
+
getUserPda: (authority: PublicKey, subAccountId?: number) => anchor.web3.PublicKey;
|
|
76
|
+
getUserStatsPda: (authority: PublicKey) => PublicKey;
|
|
77
|
+
getGlamReferrerPdas(): {
|
|
78
|
+
user: PublicKey;
|
|
79
|
+
userStats: PublicKey;
|
|
80
|
+
};
|
|
81
|
+
parsePerpMarket(data: Buffer): PerpMarket;
|
|
82
|
+
parseSpotMarket(data: Buffer): SpotMarket;
|
|
83
|
+
calcSpotBalance(marketIndex: number, scaledBalance: BN, scaledBalanceType: SpotBalanceType): Promise<{
|
|
84
|
+
amount: number;
|
|
85
|
+
uiAmount: number;
|
|
83
86
|
}>;
|
|
87
|
+
getDriftUserPdas(statePda: PublicKey | string, subAccountId?: number): {
|
|
88
|
+
user: PublicKey;
|
|
89
|
+
userStats: PublicKey;
|
|
90
|
+
};
|
|
91
|
+
get driftStatePda(): PublicKey;
|
|
92
|
+
fetchAndParseSpotMarket(marketIndex: number): Promise<SpotMarket>;
|
|
93
|
+
fetchAndParseSpotMarkets(marketIndexes: number[]): Promise<SpotMarket[]>;
|
|
94
|
+
fetchAndParsePerpMarket(marketIndex: number): Promise<PerpMarket>;
|
|
95
|
+
fetchAndParsePerpMarkets(marketIndexes: number[]): Promise<PerpMarket[]>;
|
|
96
|
+
fetchMarketConfigs(): Promise<DriftMarketConfigs>;
|
|
97
|
+
charsToName(chars: number[] | Buffer): string;
|
|
98
|
+
fetchDriftUser(statePda: PublicKey | string, subAccountId?: number): Promise<DriftUser | null>;
|
|
84
99
|
fetchPolicyConfig(glamState: StateModel): Promise<{
|
|
85
100
|
driftAccessControl: number;
|
|
86
|
-
driftDelegatedAccount:
|
|
101
|
+
driftDelegatedAccount: anchor.web3.PublicKey;
|
|
87
102
|
driftMarketIndexesPerp: number[];
|
|
88
103
|
driftOrderTypes: number[];
|
|
89
104
|
driftMaxLeverage: number;
|
|
90
|
-
driftEnableSpot:
|
|
105
|
+
driftEnableSpot: boolean;
|
|
91
106
|
driftMarketIndexesSpot: number[];
|
|
92
107
|
}>;
|
|
93
108
|
marketTypeEquals: (a: MarketType | undefined, b: MarketType) => boolean;
|
|
94
|
-
composeRemainingAccounts(glamState: PublicKey, subAccountId: number,
|
|
109
|
+
composeRemainingAccounts(glamState: PublicKey, subAccountId: number, marketType?: MarketType, marketIndex?: number): Promise<AccountMeta[]>;
|
|
95
110
|
initializeUserStatsIx(glamState: PublicKey, glamSigner: PublicKey): Promise<TransactionInstruction>;
|
|
96
111
|
initializeUserIx(glamState: PublicKey, glamSigner: PublicKey, subAccountId: number): Promise<TransactionInstruction>;
|
|
97
112
|
initializeTx(glamState: PublicKey, subAccountId?: number, txOptions?: TxOptions): Promise<VersionedTransaction>;
|
|
@@ -104,13 +119,13 @@ export declare class DriftClient {
|
|
|
104
119
|
updateUserDelegateIx(glamState: PublicKey, delegate: PublicKey | string, subAccountId?: number, txOptions?: TxOptions): Promise<TransactionInstruction>;
|
|
105
120
|
updateUserDelegateTx(glamState: PublicKey, delegate: PublicKey, subAccountId?: number, txOptions?: TxOptions): Promise<VersionedTransaction>;
|
|
106
121
|
deleteUserTx(glamState: PublicKey, subAccountId?: number, txOptions?: TxOptions): Promise<VersionedTransaction>;
|
|
107
|
-
depositTx(glamState: PublicKey, amount: anchor.BN, marketIndex
|
|
108
|
-
withdrawTx(statePda: PublicKey, amount: anchor.BN, marketIndex
|
|
109
|
-
placeOrderTx(glamState: PublicKey, orderParams: OrderParams, subAccountId
|
|
110
|
-
modifyOrderTx(statePda: PublicKey, modifyOrderParams: ModifyOrderParams, subAccountId
|
|
111
|
-
cancelOrdersTx(glamState: PublicKey, marketType: MarketType, marketIndex: number, direction: PositionDirection, subAccountId
|
|
112
|
-
cancelOrdersByIdsTx(glamState: PublicKey, orderIds: number[], subAccountId
|
|
113
|
-
settlePnlTx(glamState: PublicKey, marketIndex: number, subAccountId
|
|
114
|
-
priceDriftTx(glamState: PublicKey,
|
|
122
|
+
depositTx(glamState: PublicKey, amount: anchor.BN, marketIndex?: number, subAccountId?: number, txOptions?: TxOptions): Promise<VersionedTransaction>;
|
|
123
|
+
withdrawTx(statePda: PublicKey, amount: anchor.BN, marketIndex?: number, subAccountId?: number, txOptions?: TxOptions): Promise<VersionedTransaction>;
|
|
124
|
+
placeOrderTx(glamState: PublicKey, orderParams: OrderParams, subAccountId?: number, txOptions?: TxOptions): Promise<VersionedTransaction>;
|
|
125
|
+
modifyOrderTx(statePda: PublicKey, modifyOrderParams: ModifyOrderParams, subAccountId?: number, txOptions?: TxOptions): Promise<VersionedTransaction>;
|
|
126
|
+
cancelOrdersTx(glamState: PublicKey, marketType: MarketType, marketIndex: number, direction: PositionDirection, subAccountId?: number, txOptions?: TxOptions): Promise<VersionedTransaction>;
|
|
127
|
+
cancelOrdersByIdsTx(glamState: PublicKey, orderIds: number[], subAccountId?: number, txOptions?: TxOptions): Promise<VersionedTransaction>;
|
|
128
|
+
settlePnlTx(glamState: PublicKey, marketIndex: number, subAccountId?: number, txOptions?: TxOptions): Promise<VersionedTransaction>;
|
|
129
|
+
priceDriftTx(glamState: PublicKey, priceDenom: PriceDenom, txOptions?: TxOptions): Promise<VersionedTransaction>;
|
|
115
130
|
}
|
|
116
131
|
export {};
|
package/src/client/kamino.d.ts
CHANGED
package/src/client/meteora.d.ts
CHANGED
package/src/client/price.d.ts
CHANGED
package/src/index.d.ts
CHANGED
|
@@ -7,6 +7,9 @@ export * from "./client/drift";
|
|
|
7
7
|
export * from "./client/base";
|
|
8
8
|
export * from "./utils/helpers";
|
|
9
9
|
export * from "./utils/priorityfee";
|
|
10
|
+
export * from "./utils/driftOrderParams";
|
|
11
|
+
export * from "./utils/driftTypes";
|
|
12
|
+
export * from "./utils/driftUser";
|
|
10
13
|
export * from "./constants";
|
|
11
14
|
export * from "./error";
|
|
12
15
|
export * from "./client/assets";
|
package/src/react/glam.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { DelegateAcl, StateModel } from "../models";
|
|
2
2
|
import { GlamClient } from "../client";
|
|
3
3
|
import { PublicKey } from "@solana/web3.js";
|
|
4
|
-
import { DriftMarketConfigs,
|
|
4
|
+
import { DriftMarketConfigs, DriftUser } from "../client/drift";
|
|
5
5
|
import { TokenAccount } from "../client/base";
|
|
6
6
|
declare global {
|
|
7
7
|
interface Window {
|
|
@@ -33,7 +33,7 @@ interface GlamProviderContext {
|
|
|
33
33
|
prices: TokenPrice[];
|
|
34
34
|
jupTokenList?: JupTokenListItem[];
|
|
35
35
|
driftMarketConfigs: DriftMarketConfigs;
|
|
36
|
-
driftUser:
|
|
36
|
+
driftUser: DriftUser;
|
|
37
37
|
setActiveGlamState: (f: GlamStateCache) => void;
|
|
38
38
|
refresh: () => Promise<void>;
|
|
39
39
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { OptionalOrderParams, OrderParams, OrderTriggerCondition } from "./driftTypes";
|
|
2
|
+
import { BN } from "@coral-xyz/anchor";
|
|
3
|
+
export declare function getLimitOrderParams(params: Omit<OptionalOrderParams, "orderType"> & {
|
|
4
|
+
price: BN;
|
|
5
|
+
}): OptionalOrderParams;
|
|
6
|
+
export declare function getTriggerMarketOrderParams(params: Omit<OptionalOrderParams, "orderType"> & {
|
|
7
|
+
triggerCondition: OrderTriggerCondition;
|
|
8
|
+
triggerPrice: BN;
|
|
9
|
+
}): OptionalOrderParams;
|
|
10
|
+
export declare function getTriggerLimitOrderParams(params: Omit<OptionalOrderParams, "orderType"> & {
|
|
11
|
+
triggerCondition: OrderTriggerCondition;
|
|
12
|
+
triggerPrice: BN;
|
|
13
|
+
price: BN;
|
|
14
|
+
}): OptionalOrderParams;
|
|
15
|
+
export declare function getMarketOrderParams(params: Omit<OptionalOrderParams, "orderType">): OptionalOrderParams;
|
|
16
|
+
/**
|
|
17
|
+
* Creates an OrderParams object with the given OptionalOrderParams and any params to override.
|
|
18
|
+
*
|
|
19
|
+
* example:
|
|
20
|
+
* ```
|
|
21
|
+
* const orderParams = getOrderParams(optionalOrderParams, { marketType: MarketType.PERP });
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* @param optionalOrderParams
|
|
25
|
+
* @param overridingParams
|
|
26
|
+
* @returns
|
|
27
|
+
*/
|
|
28
|
+
export declare function getOrderParams(optionalOrderParams: OptionalOrderParams, overridingParams?: Record<string, any>): OrderParams;
|