@drift-labs/sdk 0.2.0-master.31 → 0.2.0-master.33
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/lib/accounts/bulkAccountLoader.js +2 -1
- package/lib/accounts/pollingClearingHouseAccountSubscriber.d.ts +2 -2
- package/lib/accounts/pollingClearingHouseAccountSubscriber.js +8 -8
- package/lib/accounts/types.d.ts +1 -0
- package/lib/accounts/webSocketClearingHouseAccountSubscriber.d.ts +2 -2
- package/lib/accounts/webSocketClearingHouseAccountSubscriber.js +7 -7
- package/lib/addresses/marketAddresses.js +1 -1
- package/lib/addresses/pda.d.ts +4 -4
- package/lib/addresses/pda.js +23 -22
- package/lib/admin.d.ts +30 -32
- package/lib/admin.js +111 -119
- package/lib/clearingHouse.d.ts +43 -34
- package/lib/clearingHouse.js +353 -193
- package/lib/clearingHouseConfig.d.ts +2 -2
- package/lib/clearingHouseUser.d.ts +26 -5
- package/lib/clearingHouseUser.js +151 -51
- package/lib/config.d.ts +2 -0
- package/lib/config.js +5 -1
- package/lib/constants/numericConstants.d.ts +1 -0
- package/lib/constants/numericConstants.js +3 -2
- package/lib/dlob/DLOB.d.ts +19 -11
- package/lib/dlob/DLOB.js +208 -107
- package/lib/dlob/DLOBNode.js +2 -10
- package/lib/dlob/NodeList.d.ts +1 -0
- package/lib/dlob/NodeList.js +6 -1
- package/lib/events/eventSubscriber.d.ts +1 -0
- package/lib/events/eventSubscriber.js +11 -4
- package/lib/events/fetchLogs.d.ts +3 -1
- package/lib/events/fetchLogs.js +13 -5
- package/lib/events/pollingLogProvider.js +1 -1
- package/lib/events/types.d.ts +1 -1
- package/lib/events/webSocketLogProvider.js +1 -1
- package/lib/factory/bigNum.d.ts +5 -4
- package/lib/factory/bigNum.js +36 -6
- package/lib/idl/clearing_house.json +1527 -1242
- package/lib/index.d.ts +3 -0
- package/lib/index.js +3 -0
- package/lib/math/amm.js +9 -9
- package/lib/math/exchangeStatus.d.ts +4 -0
- package/lib/math/exchangeStatus.js +18 -0
- package/lib/math/funding.js +10 -10
- package/lib/math/margin.js +6 -1
- package/lib/math/market.js +9 -9
- package/lib/math/orders.d.ts +7 -3
- package/lib/math/orders.js +39 -31
- package/lib/math/repeg.js +3 -3
- package/lib/math/spotBalance.js +3 -3
- package/lib/math/spotPosition.js +2 -2
- package/lib/serum/serumFulfillmentConfigMap.d.ts +10 -0
- package/lib/serum/serumFulfillmentConfigMap.js +17 -0
- package/lib/serum/serumSubscriber.d.ts +4 -0
- package/lib/serum/serumSubscriber.js +16 -1
- package/lib/types.d.ts +70 -85
- package/lib/types.js +12 -11
- package/lib/userMap/userMap.d.ts +17 -1
- package/lib/userMap/userMap.js +12 -0
- package/lib/userName.d.ts +1 -0
- package/lib/userName.js +3 -2
- package/package.json +1 -1
- package/src/accounts/bulkAccountLoader.ts +5 -1
- package/src/accounts/pollingClearingHouseAccountSubscriber.ts +9 -9
- package/src/accounts/webSocketClearingHouseAccountSubscriber.ts +8 -8
- package/src/addresses/marketAddresses.ts +2 -2
- package/src/addresses/pda.ts +20 -20
- package/src/admin.ts +246 -221
- package/src/clearingHouse.ts +556 -236
- package/src/clearingHouseConfig.ts +2 -2
- package/src/clearingHouseUser.ts +237 -87
- package/src/config.ts +8 -1
- package/src/constants/numericConstants.ts +5 -1
- package/src/dlob/DLOB.ts +290 -120
- package/src/dlob/DLOBNode.ts +2 -14
- package/src/dlob/NodeList.ts +7 -1
- package/src/events/eventSubscriber.ts +18 -4
- package/src/events/fetchLogs.ts +20 -5
- package/src/events/pollingLogProvider.ts +1 -1
- package/src/events/types.ts +2 -1
- package/src/events/webSocketLogProvider.ts +1 -1
- package/src/factory/bigNum.ts +59 -6
- package/src/idl/clearing_house.json +1527 -1242
- package/src/idl/pyth.json +98 -2
- package/src/index.ts +3 -0
- package/src/math/amm.ts +9 -9
- package/src/math/exchangeStatus.ts +31 -0
- package/src/math/funding.ts +20 -10
- package/src/math/margin.ts +7 -1
- package/src/math/market.ts +9 -9
- package/src/math/orders.ts +44 -29
- package/src/math/repeg.ts +3 -3
- package/src/math/spotBalance.ts +4 -4
- package/src/math/spotPosition.ts +2 -2
- package/src/serum/serumFulfillmentConfigMap.ts +26 -0
- package/src/serum/serumSubscriber.ts +20 -1
- package/src/types.ts +75 -61
- package/src/userMap/userMap.ts +25 -1
- package/src/userName.ts +2 -1
- package/tests/bn/test.ts +22 -1
- package/tests/dlob/helpers.ts +252 -81
- package/tests/dlob/test.ts +1115 -215
package/lib/clearingHouse.d.ts
CHANGED
|
@@ -34,7 +34,7 @@ export declare class ClearingHouse {
|
|
|
34
34
|
opts?: ConfirmOptions;
|
|
35
35
|
users: Map<number, ClearingHouseUser>;
|
|
36
36
|
userStats?: ClearingHouseUserStats;
|
|
37
|
-
|
|
37
|
+
activeSubAccountId: number;
|
|
38
38
|
userAccountSubscriptionConfig: ClearingHouseUserAccountSubscriptionConfig;
|
|
39
39
|
accountSubscriber: ClearingHouseAccountSubscriber;
|
|
40
40
|
eventEmitter: StrictEventEmitter<EventEmitter, ClearingHouseAccountEvents>;
|
|
@@ -45,8 +45,8 @@ export declare class ClearingHouse {
|
|
|
45
45
|
get isSubscribed(): boolean;
|
|
46
46
|
set isSubscribed(val: boolean);
|
|
47
47
|
constructor(config: ClearingHouseConfig);
|
|
48
|
-
createUsers(
|
|
49
|
-
createUser(
|
|
48
|
+
createUsers(subAccountIds: number[], accountSubscriptionConfig: ClearingHouseUserAccountSubscriptionConfig): void;
|
|
49
|
+
createUser(subAccountId: number, accountSubscriptionConfig: ClearingHouseUserAccountSubscriptionConfig): ClearingHouseUser;
|
|
50
50
|
subscribe(): Promise<boolean>;
|
|
51
51
|
subscribeUsers(): Promise<boolean>[];
|
|
52
52
|
/**
|
|
@@ -70,30 +70,31 @@ export declare class ClearingHouse {
|
|
|
70
70
|
/**
|
|
71
71
|
* Update the wallet to use for clearing house transactions and linked user account
|
|
72
72
|
* @param newWallet
|
|
73
|
-
* @param
|
|
74
|
-
* @param
|
|
73
|
+
* @param subAccountIds
|
|
74
|
+
* @param activeSubAccountId
|
|
75
75
|
*/
|
|
76
|
-
updateWallet(newWallet: IWallet,
|
|
77
|
-
switchActiveUser(
|
|
78
|
-
addUser(
|
|
79
|
-
initializeUserAccount(
|
|
80
|
-
getInitializeUserInstructions(
|
|
76
|
+
updateWallet(newWallet: IWallet, subAccountIds?: number[], activeSubAccountId?: number): Promise<void>;
|
|
77
|
+
switchActiveUser(subAccountId: number): Promise<void>;
|
|
78
|
+
addUser(subAccountId: number): Promise<void>;
|
|
79
|
+
initializeUserAccount(subAccountId?: number, name?: string, referrerInfo?: ReferrerInfo): Promise<[TransactionSignature, PublicKey]>;
|
|
80
|
+
getInitializeUserInstructions(subAccountId?: number, name?: string, referrerInfo?: ReferrerInfo): Promise<[PublicKey, TransactionInstruction]>;
|
|
81
81
|
getInitializeUserStatsIx(): Promise<TransactionInstruction>;
|
|
82
|
-
updateUserName(name: string,
|
|
83
|
-
updateUserCustomMarginRatio(marginRatio: number,
|
|
84
|
-
updateUserDelegate(delegate: PublicKey,
|
|
82
|
+
updateUserName(name: string, subAccountId?: number): Promise<TransactionSignature>;
|
|
83
|
+
updateUserCustomMarginRatio(marginRatio: number, subAccountId?: number): Promise<TransactionSignature>;
|
|
84
|
+
updateUserDelegate(delegate: PublicKey, subAccountId?: number): Promise<TransactionSignature>;
|
|
85
85
|
getUserAccountsForDelegate(delegate: PublicKey): Promise<UserAccount[]>;
|
|
86
|
-
deleteUser(
|
|
87
|
-
getUser(
|
|
86
|
+
deleteUser(subAccountId?: number): Promise<TransactionSignature>;
|
|
87
|
+
getUser(subAccountId?: number): ClearingHouseUser;
|
|
88
88
|
getUsers(): ClearingHouseUser[];
|
|
89
89
|
getUserStats(): ClearingHouseUserStats;
|
|
90
90
|
userStatsAccountPublicKey: PublicKey;
|
|
91
91
|
getUserStatsAccountPublicKey(): PublicKey;
|
|
92
92
|
getUserAccountPublicKey(): Promise<PublicKey>;
|
|
93
|
-
getUserAccount(
|
|
94
|
-
getUserAccountAndSlot(
|
|
93
|
+
getUserAccount(subAccountId?: number): UserAccount | undefined;
|
|
94
|
+
getUserAccountAndSlot(subAccountId?: number): DataAndSlot<UserAccount> | undefined;
|
|
95
95
|
getSpotPosition(marketIndex: number): SpotPosition | undefined;
|
|
96
96
|
getQuoteAssetTokenAmount(): BN;
|
|
97
|
+
getTokenAmount(marketIndex: number): BN;
|
|
97
98
|
getRemainingAccounts(params: RemainingAccountParams): AccountMeta[];
|
|
98
99
|
getRemainingAccountMapsForUsers(userAccounts: UserAccount[]): {
|
|
99
100
|
oracleAccountMap: Map<string, AccountMeta>;
|
|
@@ -102,8 +103,8 @@ export declare class ClearingHouse {
|
|
|
102
103
|
};
|
|
103
104
|
getOrder(orderId: number): Order | undefined;
|
|
104
105
|
getOrderByUserId(userOrderId: number): Order | undefined;
|
|
105
|
-
deposit(amount: BN, marketIndex: number, collateralAccountPublicKey: PublicKey,
|
|
106
|
-
getDepositInstruction(amount: BN, marketIndex: number, userTokenAccount: PublicKey,
|
|
106
|
+
deposit(amount: BN, marketIndex: number, collateralAccountPublicKey: PublicKey, subAccountId?: number, reduceOnly?: boolean): Promise<TransactionSignature>;
|
|
107
|
+
getDepositInstruction(amount: BN, marketIndex: number, userTokenAccount: PublicKey, subAccountId?: number, reduceOnly?: boolean, userInitialized?: boolean): Promise<TransactionInstruction>;
|
|
107
108
|
private checkIfAccountExists;
|
|
108
109
|
private getWrappedSolAccountCreationIxs;
|
|
109
110
|
getAssociatedTokenAccountCreationIx(tokenMintAddress: PublicKey, associatedTokenAddress: PublicKey): anchor.web3.TransactionInstruction;
|
|
@@ -112,25 +113,27 @@ export declare class ClearingHouse {
|
|
|
112
113
|
* @param amount
|
|
113
114
|
* @param userTokenAccount
|
|
114
115
|
* @param marketIndex
|
|
115
|
-
* @param
|
|
116
|
+
* @param subAccountId
|
|
116
117
|
* @param name
|
|
117
|
-
* @param
|
|
118
|
+
* @param fromSubAccountId
|
|
118
119
|
* @returns
|
|
119
120
|
*/
|
|
120
|
-
initializeUserAccountAndDepositCollateral(amount: BN, userTokenAccount: PublicKey, marketIndex?: number,
|
|
121
|
-
initializeUserAccountForDevnet(
|
|
121
|
+
initializeUserAccountAndDepositCollateral(amount: BN, userTokenAccount: PublicKey, marketIndex?: number, subAccountId?: number, name?: string, fromSubAccountId?: number, referrerInfo?: ReferrerInfo): Promise<[TransactionSignature, PublicKey]>;
|
|
122
|
+
initializeUserAccountForDevnet(subAccountId: number, name: string, marketIndex: number, tokenFaucet: TokenFaucet, amount: BN, referrerInfo?: ReferrerInfo): Promise<[TransactionSignature, PublicKey]>;
|
|
122
123
|
withdraw(amount: BN, marketIndex: number, userTokenAccount: PublicKey, reduceOnly?: boolean): Promise<TransactionSignature>;
|
|
123
124
|
getWithdrawIx(amount: BN, marketIndex: number, userTokenAccount: PublicKey, reduceOnly?: boolean): Promise<TransactionInstruction>;
|
|
124
|
-
transferDeposit(amount: BN, marketIndex: number,
|
|
125
|
-
getTransferDepositIx(amount: BN, marketIndex: number,
|
|
125
|
+
transferDeposit(amount: BN, marketIndex: number, fromSubAccountId: number, toSubAccountId: number): Promise<TransactionSignature>;
|
|
126
|
+
getTransferDepositIx(amount: BN, marketIndex: number, fromSubAccountId: number, toSubAccountId: number): Promise<TransactionInstruction>;
|
|
126
127
|
updateSpotMarketCumulativeInterest(marketIndex: number): Promise<TransactionSignature>;
|
|
127
128
|
updateSpotMarketCumulativeInterestIx(marketIndex: number): Promise<TransactionInstruction>;
|
|
128
129
|
settleLP(settleeUserAccountPublicKey: PublicKey, marketIndex: number): Promise<TransactionSignature>;
|
|
129
130
|
settleLPIx(settleeUserAccountPublicKey: PublicKey, marketIndex: number): Promise<TransactionInstruction>;
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
131
|
+
removePerpLpShares(marketIndex: number, sharesToBurn?: BN): Promise<TransactionSignature>;
|
|
132
|
+
removePerpLpSharesInExpiringMarket(marketIndex: number, userAccountPublicKey: PublicKey, sharesToBurn?: BN): Promise<TransactionSignature>;
|
|
133
|
+
getRemovePerpLpSharesInExpiringMarket(marketIndex: number, userAccountPublicKey: PublicKey, sharesToBurn?: BN): Promise<TransactionInstruction>;
|
|
134
|
+
getRemovePerpLpSharesIx(marketIndex: number, sharesToBurn?: BN): Promise<TransactionInstruction>;
|
|
135
|
+
addPerpLpShares(amount: BN, marketIndex: number): Promise<TransactionSignature>;
|
|
136
|
+
getAddPerpLpSharesIx(amount: BN, marketIndex: number): Promise<TransactionInstruction>;
|
|
134
137
|
openPosition(direction: PositionDirection, amount: BN, marketIndex: number, limitPrice?: BN): Promise<TransactionSignature>;
|
|
135
138
|
sendSignedTx(tx: Transaction): Promise<TransactionSignature>;
|
|
136
139
|
/**
|
|
@@ -151,22 +154,30 @@ export declare class ClearingHouse {
|
|
|
151
154
|
getUpdateAMMsIx(marketIndexes: number[]): Promise<TransactionInstruction>;
|
|
152
155
|
settleExpiredMarket(marketIndex: number): Promise<TransactionSignature>;
|
|
153
156
|
getSettleExpiredMarketIx(marketIndex: number): Promise<TransactionInstruction>;
|
|
157
|
+
settleExpiredMarketPoolsToRevenuePool(perpMarketIndex: number): Promise<TransactionSignature>;
|
|
154
158
|
cancelOrder(orderId?: number): Promise<TransactionSignature>;
|
|
155
159
|
getCancelOrderIx(orderId?: number): Promise<TransactionInstruction>;
|
|
156
160
|
cancelOrderByUserId(userOrderId: number): Promise<TransactionSignature>;
|
|
157
161
|
getCancelOrderByUserIdIx(userOrderId: number): Promise<TransactionInstruction>;
|
|
162
|
+
cancelOrders(marketType?: MarketType, marketIndex?: number, direction?: PositionDirection): Promise<TransactionSignature>;
|
|
163
|
+
getCancelOrdersIx(marketType: MarketType | null, marketIndex: number | null, direction: PositionDirection | null): Promise<TransactionInstruction>;
|
|
158
164
|
fillOrder(userAccountPublicKey: PublicKey, user: UserAccount, order?: Pick<Order, 'marketIndex' | 'orderId'>, makerInfo?: MakerInfo, referrerInfo?: ReferrerInfo): Promise<TransactionSignature>;
|
|
159
165
|
getFillOrderIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, order: Pick<Order, 'marketIndex' | 'orderId'>, makerInfo?: MakerInfo, referrerInfo?: ReferrerInfo): Promise<TransactionInstruction>;
|
|
160
166
|
placeSpotOrder(orderParams: OptionalOrderParams): Promise<TransactionSignature>;
|
|
161
167
|
getPlaceSpotOrderIx(orderParams: OptionalOrderParams): Promise<TransactionInstruction>;
|
|
162
168
|
fillSpotOrder(userAccountPublicKey: PublicKey, user: UserAccount, order?: Order, fulfillmentConfig?: SerumV3FulfillmentConfigAccount, makerInfo?: MakerInfo, referrerInfo?: ReferrerInfo): Promise<TransactionSignature>;
|
|
163
169
|
getFillSpotOrderIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, order?: Order, fulfillmentConfig?: SerumV3FulfillmentConfigAccount, makerInfo?: MakerInfo, referrerInfo?: ReferrerInfo): Promise<TransactionInstruction>;
|
|
170
|
+
addSerumRemainingAccounts(marketIndex: number, remainingAccounts: AccountMeta[], fulfillmentConfig: SerumV3FulfillmentConfigAccount): void;
|
|
164
171
|
triggerOrder(userAccountPublicKey: PublicKey, user: UserAccount, order: Order): Promise<TransactionSignature>;
|
|
165
172
|
getTriggerOrderIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, order: Order): Promise<TransactionInstruction>;
|
|
166
173
|
placeAndTake(orderParams: OptionalOrderParams, makerInfo?: MakerInfo, referrerInfo?: ReferrerInfo): Promise<TransactionSignature>;
|
|
167
174
|
getPlaceAndTakeIx(orderParams: OptionalOrderParams, makerInfo?: MakerInfo, referrerInfo?: ReferrerInfo): Promise<TransactionInstruction>;
|
|
168
175
|
placeAndMake(orderParams: OptionalOrderParams, takerInfo: TakerInfo, referrerInfo?: ReferrerInfo): Promise<TransactionSignature>;
|
|
169
176
|
getPlaceAndMakeIx(orderParams: OptionalOrderParams, takerInfo: TakerInfo, referrerInfo?: ReferrerInfo): Promise<TransactionInstruction>;
|
|
177
|
+
placeAndTakeSpotOrder(orderParams: OptionalOrderParams, fulfillmentConfig?: SerumV3FulfillmentConfigAccount, makerInfo?: MakerInfo, referrerInfo?: ReferrerInfo): Promise<TransactionSignature>;
|
|
178
|
+
getPlaceAndTakeSpotOrderIx(orderParams: OptionalOrderParams, fulfillmentConfig?: SerumV3FulfillmentConfigAccount, makerInfo?: MakerInfo, referrerInfo?: ReferrerInfo): Promise<TransactionInstruction>;
|
|
179
|
+
placeAndMakeSpotOrder(orderParams: OptionalOrderParams, takerInfo: TakerInfo, referrerInfo?: ReferrerInfo): Promise<TransactionSignature>;
|
|
180
|
+
getPlaceAndMakeSpotOrderIx(orderParams: OptionalOrderParams, takerInfo: TakerInfo, referrerInfo?: ReferrerInfo): Promise<TransactionInstruction>;
|
|
170
181
|
/**
|
|
171
182
|
* Close an entire position. If you want to reduce a position, use the {@link openPosition} method in the opposite direction of the current position.
|
|
172
183
|
* @param marketIndex
|
|
@@ -179,8 +190,6 @@ export declare class ClearingHouse {
|
|
|
179
190
|
}[], marketIndex: number): Promise<TransactionSignature>;
|
|
180
191
|
settlePNL(settleeUserAccountPublicKey: PublicKey, settleeUserAccount: UserAccount, marketIndex: number): Promise<TransactionSignature>;
|
|
181
192
|
settlePNLIx(settleeUserAccountPublicKey: PublicKey, settleeUserAccount: UserAccount, marketIndex: number): Promise<TransactionInstruction>;
|
|
182
|
-
settleExpiredPosition(settleeUserAccountPublicKey: PublicKey, settleeUserAccount: UserAccount, marketIndex: number): Promise<TransactionSignature>;
|
|
183
|
-
getSettleExpiredPositionIx(settleeUserAccountPublicKey: PublicKey, settleeUserAccount: UserAccount, marketIndex: number): Promise<TransactionInstruction>;
|
|
184
193
|
liquidatePerp(userAccountPublicKey: PublicKey, userAccount: UserAccount, marketIndex: number, maxBaseAssetAmount: BN): Promise<TransactionSignature>;
|
|
185
194
|
getLiquidatePerpIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, marketIndex: number, maxBaseAssetAmount: BN): Promise<TransactionInstruction>;
|
|
186
195
|
liquidateSpot(userAccountPublicKey: PublicKey, userAccount: UserAccount, assetMarketIndex: number, liabilityMarketIndex: number, maxLiabilityTransfer: BN): Promise<TransactionSignature>;
|
|
@@ -193,12 +202,12 @@ export declare class ClearingHouse {
|
|
|
193
202
|
getResolvePerpBankruptcyIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, marketIndex: number): Promise<TransactionInstruction>;
|
|
194
203
|
resolveSpotBankruptcy(userAccountPublicKey: PublicKey, userAccount: UserAccount, marketIndex: number): Promise<TransactionSignature>;
|
|
195
204
|
getResolveSpotBankruptcyIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, marketIndex: number): Promise<TransactionInstruction>;
|
|
196
|
-
updateFundingRate(
|
|
197
|
-
getUpdateFundingRateIx(
|
|
205
|
+
updateFundingRate(perpMarketIndex: number, oracle: PublicKey): Promise<TransactionSignature>;
|
|
206
|
+
getUpdateFundingRateIx(perpMarketIndex: number, oracle: PublicKey): Promise<TransactionInstruction>;
|
|
198
207
|
settleFundingPayment(userAccountPublicKey: PublicKey): Promise<TransactionSignature>;
|
|
199
208
|
getSettleFundingPaymentIx(userAccountPublicKey: PublicKey): Promise<TransactionInstruction>;
|
|
200
209
|
triggerEvent(eventName: keyof ClearingHouseAccountEvents, data?: any): void;
|
|
201
|
-
|
|
210
|
+
getOracleDataForPerpMarket(marketIndex: number): OraclePriceData;
|
|
202
211
|
getOracleDataForSpotMarket(marketIndex: number): OraclePriceData;
|
|
203
212
|
initializeInsuranceFundStake(marketIndex: number): Promise<TransactionSignature>;
|
|
204
213
|
getInitializeInsuranceFundStakeIx(marketIndex: number): Promise<TransactionInstruction>;
|