@drift-labs/sdk 0.2.0-master.29 → 0.2.0-master.30
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/README.md +13 -13
- package/lib/accounts/pollingClearingHouseAccountSubscriber.d.ts +10 -11
- package/lib/accounts/pollingClearingHouseAccountSubscriber.js +4 -4
- package/lib/accounts/types.d.ts +4 -6
- package/lib/accounts/webSocketClearingHouseAccountSubscriber.d.ts +10 -11
- package/lib/accounts/webSocketClearingHouseAccountSubscriber.js +6 -8
- package/lib/addresses/marketAddresses.d.ts +1 -3
- package/lib/addresses/pda.d.ts +5 -5
- package/lib/addresses/pda.js +5 -5
- package/lib/admin.d.ts +27 -28
- package/lib/admin.js +12 -37
- package/lib/clearingHouse.d.ts +61 -62
- package/lib/clearingHouse.js +92 -110
- package/lib/clearingHouseConfig.d.ts +2 -4
- package/lib/clearingHouseUser.d.ts +16 -16
- package/lib/clearingHouseUser.js +16 -16
- package/lib/config.d.ts +2 -4
- package/lib/config.js +1 -1
- package/lib/constants/numericConstants.d.ts +7 -8
- package/lib/constants/numericConstants.js +17 -18
- package/lib/constants/perpMarkets.d.ts +2 -3
- package/lib/constants/perpMarkets.js +3 -3
- package/lib/constants/spotMarkets.d.ts +2 -1
- package/lib/constants/spotMarkets.js +6 -4
- package/lib/dlob/DLOB.d.ts +13 -13
- package/lib/dlob/DLOB.js +36 -40
- package/lib/dlob/DLOBNode.js +2 -2
- package/lib/events/sort.js +1 -1
- package/lib/examples/makeTradeExample.js +3 -3
- package/lib/idl/clearing_house.json +359 -310
- package/lib/math/amm.d.ts +2 -2
- package/lib/math/amm.js +10 -10
- package/lib/math/conversion.js +1 -1
- package/lib/math/funding.js +9 -9
- package/lib/math/margin.js +3 -3
- package/lib/math/market.d.ts +4 -4
- package/lib/math/market.js +7 -7
- package/lib/math/oracles.js +6 -8
- package/lib/math/position.d.ts +2 -2
- package/lib/math/position.js +9 -9
- package/lib/math/repeg.js +7 -6
- package/lib/math/spotBalance.js +5 -5
- package/lib/math/spotPosition.js +2 -2
- package/lib/math/trade.d.ts +6 -6
- package/lib/math/trade.js +15 -19
- package/lib/oracles/pythClient.js +1 -1
- package/lib/oracles/quoteAssetOracleClient.js +1 -1
- package/lib/oracles/switchboardClient.js +1 -1
- package/lib/types.d.ts +63 -51
- package/lib/types.js +1 -1
- package/package.json +2 -1
- package/src/accounts/pollingClearingHouseAccountSubscriber.ts +15 -15
- package/src/accounts/types.ts +4 -5
- package/src/accounts/webSocketClearingHouseAccountSubscriber.ts +17 -25
- package/src/addresses/marketAddresses.ts +1 -2
- package/src/addresses/pda.ts +10 -10
- package/src/admin.ts +42 -79
- package/src/clearingHouse.ts +164 -212
- package/src/clearingHouseConfig.ts +2 -3
- package/src/clearingHouseUser.ts +35 -35
- package/src/config.ts +3 -4
- package/src/constants/numericConstants.ts +19 -21
- package/src/constants/perpMarkets.ts +5 -5
- package/src/constants/spotMarkets.ts +8 -5
- package/src/dlob/DLOB.ts +54 -70
- package/src/dlob/DLOBNode.ts +5 -6
- package/src/events/sort.ts +1 -1
- package/src/examples/makeTradeExample.js +2 -2
- package/src/examples/makeTradeExample.ts +5 -8
- package/src/idl/clearing_house.json +359 -310
- package/src/math/amm.ts +14 -11
- package/src/math/conversion.ts +2 -2
- package/src/math/funding.ts +13 -11
- package/src/math/margin.ts +4 -5
- package/src/math/market.ts +5 -5
- package/src/math/oracles.ts +9 -9
- package/src/math/position.ts +11 -19
- package/src/math/repeg.ts +8 -7
- package/src/math/spotBalance.ts +6 -6
- package/src/math/spotPosition.ts +2 -2
- package/src/math/trade.ts +17 -21
- package/src/oracles/pythClient.ts +2 -2
- package/src/oracles/quoteAssetOracleClient.ts +2 -2
- package/src/oracles/switchboardClient.ts +2 -2
- package/src/types.ts +69 -51
- package/tests/dlob/helpers.ts +56 -4
- package/src/addresses/marketAddresses.js +0 -26
- package/src/constants/banks.js +0 -42
- package/src/constants/markets.js +0 -42
- package/src/events/txEventCache.js +0 -71
- package/src/factory/bigNum.js +0 -390
- package/src/factory/oracleClient.js +0 -20
- package/src/math/auction.js +0 -42
- package/src/math/conversion.js +0 -11
- package/src/math/funding.js +0 -248
- package/src/math/repeg.js +0 -128
- package/src/math/trade.js +0 -253
- package/src/math/utils.js +0 -26
- package/src/math/utils.js.map +0 -1
- package/src/oracles/oracleClientCache.js +0 -19
- package/src/oracles/pythClient.js +0 -46
- package/src/oracles/quoteAssetOracleClient.js +0 -32
- package/src/oracles/switchboardClient.js +0 -69
- package/src/oracles/types.js +0 -2
- package/src/userName.js +0 -20
- package/src/wallet.js +0 -35
package/lib/clearingHouse.d.ts
CHANGED
|
@@ -52,9 +52,9 @@ export declare class ClearingHouse {
|
|
|
52
52
|
signerPublicKey?: PublicKey;
|
|
53
53
|
getSignerPublicKey(): PublicKey;
|
|
54
54
|
getStateAccount(): StateAccount;
|
|
55
|
-
getPerpMarketAccount(marketIndex:
|
|
55
|
+
getPerpMarketAccount(marketIndex: number): PerpMarketAccount | undefined;
|
|
56
56
|
getPerpMarketAccounts(): PerpMarketAccount[];
|
|
57
|
-
getSpotMarketAccount(marketIndex:
|
|
57
|
+
getSpotMarketAccount(marketIndex: number): SpotMarketAccount | undefined;
|
|
58
58
|
getSpotMarketAccounts(): SpotMarketAccount[];
|
|
59
59
|
getQuoteSpotMarketAccount(): SpotMarketAccount;
|
|
60
60
|
getOraclePriceDataAndSlot(oraclePublicKey: PublicKey): DataAndSlot<OraclePriceData> | undefined;
|
|
@@ -83,20 +83,19 @@ export declare class ClearingHouse {
|
|
|
83
83
|
getUserAccountPublicKey(): Promise<PublicKey>;
|
|
84
84
|
getUserAccount(userId?: number): UserAccount | undefined;
|
|
85
85
|
getUserAccountAndSlot(userId?: number): DataAndSlot<UserAccount> | undefined;
|
|
86
|
-
getSpotPosition(marketIndex: number
|
|
86
|
+
getSpotPosition(marketIndex: number): SpotPosition | undefined;
|
|
87
87
|
getQuoteAssetTokenAmount(): BN;
|
|
88
88
|
getRemainingAccounts(params: {
|
|
89
|
-
writablePerpMarketIndex?:
|
|
90
|
-
writableSpotMarketIndex?:
|
|
91
|
-
readablePerpMarketIndex?:
|
|
92
|
-
readableSpotMarketIndex?:
|
|
89
|
+
writablePerpMarketIndex?: number;
|
|
90
|
+
writableSpotMarketIndex?: number;
|
|
91
|
+
readablePerpMarketIndex?: number;
|
|
92
|
+
readableSpotMarketIndex?: number;
|
|
93
93
|
}): AccountMeta[];
|
|
94
94
|
getOrder(orderId: BN | number): Order | undefined;
|
|
95
95
|
getOrderByUserId(userOrderId: number): Order | undefined;
|
|
96
|
-
deposit(amount: BN, marketIndex:
|
|
97
|
-
getDepositInstruction(amount: BN, marketIndex:
|
|
96
|
+
deposit(amount: BN, marketIndex: number, collateralAccountPublicKey: PublicKey, userId?: number, reduceOnly?: boolean): Promise<TransactionSignature>;
|
|
97
|
+
getDepositInstruction(amount: BN, marketIndex: number, userTokenAccount: PublicKey, userId?: number, reduceOnly?: boolean, userInitialized?: boolean): Promise<TransactionInstruction>;
|
|
98
98
|
private checkIfAccountExists;
|
|
99
|
-
private getSolWithdrawalIxs;
|
|
100
99
|
private getWrappedSolAccountCreationIxs;
|
|
101
100
|
getAssociatedTokenAccountCreationIx(tokenMintAddress: PublicKey, associatedTokenAddress: PublicKey): anchor.web3.TransactionInstruction;
|
|
102
101
|
/**
|
|
@@ -109,21 +108,21 @@ export declare class ClearingHouse {
|
|
|
109
108
|
* @param fromUserId
|
|
110
109
|
* @returns
|
|
111
110
|
*/
|
|
112
|
-
initializeUserAccountAndDepositCollateral(amount: BN, userTokenAccount: PublicKey, marketIndex?:
|
|
113
|
-
initializeUserAccountForDevnet(userId: number, name: string, marketIndex:
|
|
114
|
-
withdraw(amount: BN, marketIndex:
|
|
115
|
-
getWithdrawIx(amount: BN, marketIndex:
|
|
116
|
-
transferDeposit(amount: BN, marketIndex:
|
|
117
|
-
getTransferDepositIx(amount: BN, marketIndex:
|
|
118
|
-
updateSpotMarketCumulativeInterest(marketIndex:
|
|
119
|
-
updateSpotMarketCumulativeInterestIx(marketIndex:
|
|
120
|
-
settleLP(settleeUserAccountPublicKey: PublicKey, marketIndex:
|
|
121
|
-
settleLPIx(settleeUserAccountPublicKey: PublicKey, marketIndex:
|
|
122
|
-
removeLiquidity(marketIndex:
|
|
123
|
-
getRemoveLiquidityIx(marketIndex:
|
|
124
|
-
addLiquidity(amount: BN, marketIndex:
|
|
125
|
-
getAddLiquidityIx(amount: BN, marketIndex:
|
|
126
|
-
openPosition(direction: PositionDirection, amount: BN, marketIndex:
|
|
111
|
+
initializeUserAccountAndDepositCollateral(amount: BN, userTokenAccount: PublicKey, marketIndex?: number, userId?: number, name?: string, fromUserId?: number, referrerInfo?: ReferrerInfo): Promise<[TransactionSignature, PublicKey]>;
|
|
112
|
+
initializeUserAccountForDevnet(userId: number, name: string, marketIndex: number, tokenFaucet: TokenFaucet, amount: BN, referrerInfo?: ReferrerInfo): Promise<[TransactionSignature, PublicKey]>;
|
|
113
|
+
withdraw(amount: BN, marketIndex: number, userTokenAccount: PublicKey, reduceOnly?: boolean): Promise<TransactionSignature>;
|
|
114
|
+
getWithdrawIx(amount: BN, marketIndex: number, userTokenAccount: PublicKey, reduceOnly?: boolean): Promise<TransactionInstruction>;
|
|
115
|
+
transferDeposit(amount: BN, marketIndex: number, fromUserId: number, toUserId: number): Promise<TransactionSignature>;
|
|
116
|
+
getTransferDepositIx(amount: BN, marketIndex: number, fromUserId: number, toUserId: number): Promise<TransactionInstruction>;
|
|
117
|
+
updateSpotMarketCumulativeInterest(marketIndex: number): Promise<TransactionSignature>;
|
|
118
|
+
updateSpotMarketCumulativeInterestIx(marketIndex: number): Promise<TransactionInstruction>;
|
|
119
|
+
settleLP(settleeUserAccountPublicKey: PublicKey, marketIndex: number): Promise<TransactionSignature>;
|
|
120
|
+
settleLPIx(settleeUserAccountPublicKey: PublicKey, marketIndex: number): Promise<TransactionInstruction>;
|
|
121
|
+
removeLiquidity(marketIndex: number, sharesToBurn?: BN): Promise<TransactionSignature>;
|
|
122
|
+
getRemoveLiquidityIx(marketIndex: number, sharesToBurn?: BN): Promise<TransactionInstruction>;
|
|
123
|
+
addLiquidity(amount: BN, marketIndex: number): Promise<TransactionSignature>;
|
|
124
|
+
getAddLiquidityIx(amount: BN, marketIndex: number): Promise<TransactionInstruction>;
|
|
125
|
+
openPosition(direction: PositionDirection, amount: BN, marketIndex: number, limitPrice?: BN): Promise<TransactionSignature>;
|
|
127
126
|
sendSignedTx(tx: Transaction): Promise<TransactionSignature>;
|
|
128
127
|
/**
|
|
129
128
|
* Sends a market order and returns a signed tx which can fill the order against the vamm, which the caller can use to fill their own order if required.
|
|
@@ -139,10 +138,10 @@ export declare class ClearingHouse {
|
|
|
139
138
|
placeOrder(orderParams: OptionalOrderParams): Promise<TransactionSignature>;
|
|
140
139
|
getOrderParams(optionalOrderParams: OptionalOrderParams, marketType: MarketType): OrderParams;
|
|
141
140
|
getPlaceOrderIx(orderParams: OptionalOrderParams): Promise<TransactionInstruction>;
|
|
142
|
-
updateAMMs(marketIndexes:
|
|
143
|
-
getUpdateAMMsIx(marketIndexes:
|
|
144
|
-
settleExpiredMarket(marketIndex:
|
|
145
|
-
getSettleExpiredMarketIx(marketIndex:
|
|
141
|
+
updateAMMs(marketIndexes: number[]): Promise<TransactionSignature>;
|
|
142
|
+
getUpdateAMMsIx(marketIndexes: number[]): Promise<TransactionInstruction>;
|
|
143
|
+
settleExpiredMarket(marketIndex: number): Promise<TransactionSignature>;
|
|
144
|
+
getSettleExpiredMarketIx(marketIndex: number): Promise<TransactionInstruction>;
|
|
146
145
|
cancelOrder(orderId?: BN): Promise<TransactionSignature>;
|
|
147
146
|
getCancelOrderIx(orderId?: BN): Promise<TransactionInstruction>;
|
|
148
147
|
cancelOrderByUserId(userOrderId: number): Promise<TransactionSignature>;
|
|
@@ -166,46 +165,46 @@ export declare class ClearingHouse {
|
|
|
166
165
|
* @param marketIndex
|
|
167
166
|
* @returns
|
|
168
167
|
*/
|
|
169
|
-
closePosition(marketIndex:
|
|
168
|
+
closePosition(marketIndex: number, limitPrice?: BN): Promise<TransactionSignature>;
|
|
170
169
|
settlePNLs(users: {
|
|
171
170
|
settleeUserAccountPublicKey: PublicKey;
|
|
172
171
|
settleeUserAccount: UserAccount;
|
|
173
|
-
}[], marketIndex:
|
|
174
|
-
settlePNL(settleeUserAccountPublicKey: PublicKey, settleeUserAccount: UserAccount, marketIndex:
|
|
175
|
-
settlePNLIx(settleeUserAccountPublicKey: PublicKey, settleeUserAccount: UserAccount, marketIndex:
|
|
176
|
-
settleExpiredPosition(settleeUserAccountPublicKey: PublicKey, settleeUserAccount: UserAccount, marketIndex:
|
|
177
|
-
getSettleExpiredPositionIx(settleeUserAccountPublicKey: PublicKey, settleeUserAccount: UserAccount, marketIndex:
|
|
178
|
-
liquidatePerp(userAccountPublicKey: PublicKey, userAccount: UserAccount, marketIndex:
|
|
179
|
-
getLiquidatePerpIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, marketIndex:
|
|
180
|
-
liquidateBorrow(userAccountPublicKey: PublicKey, userAccount: UserAccount,
|
|
181
|
-
getLiquidateBorrowIx(userAccountPublicKey: PublicKey, userAccount: UserAccount,
|
|
182
|
-
liquidateBorrowForPerpPnl(userAccountPublicKey: PublicKey, userAccount: UserAccount, perpMarketIndex:
|
|
183
|
-
getLiquidateBorrowForPerpPnlIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, perpMarketIndex:
|
|
184
|
-
liquidatePerpPnlForDeposit(userAccountPublicKey: PublicKey, userAccount: UserAccount, perpMarketIndex:
|
|
185
|
-
getLiquidatePerpPnlForDepositIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, perpMarketIndex:
|
|
186
|
-
resolvePerpBankruptcy(userAccountPublicKey: PublicKey, userAccount: UserAccount, marketIndex:
|
|
187
|
-
getResolvePerpBankruptcyIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, marketIndex:
|
|
188
|
-
resolveBorrowBankruptcy(userAccountPublicKey: PublicKey, userAccount: UserAccount, marketIndex:
|
|
189
|
-
getResolveBorrowBankruptcyIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, marketIndex:
|
|
172
|
+
}[], marketIndex: number): Promise<TransactionSignature>;
|
|
173
|
+
settlePNL(settleeUserAccountPublicKey: PublicKey, settleeUserAccount: UserAccount, marketIndex: number): Promise<TransactionSignature>;
|
|
174
|
+
settlePNLIx(settleeUserAccountPublicKey: PublicKey, settleeUserAccount: UserAccount, marketIndex: number): Promise<TransactionInstruction>;
|
|
175
|
+
settleExpiredPosition(settleeUserAccountPublicKey: PublicKey, settleeUserAccount: UserAccount, marketIndex: number): Promise<TransactionSignature>;
|
|
176
|
+
getSettleExpiredPositionIx(settleeUserAccountPublicKey: PublicKey, settleeUserAccount: UserAccount, marketIndex: number): Promise<TransactionInstruction>;
|
|
177
|
+
liquidatePerp(userAccountPublicKey: PublicKey, userAccount: UserAccount, marketIndex: number, maxBaseAssetAmount: BN): Promise<TransactionSignature>;
|
|
178
|
+
getLiquidatePerpIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, marketIndex: number, maxBaseAssetAmount: BN): Promise<TransactionInstruction>;
|
|
179
|
+
liquidateBorrow(userAccountPublicKey: PublicKey, userAccount: UserAccount, assetMarketIndex: number, liabilityMarketIndex: number, maxLiabilityTransfer: BN): Promise<TransactionSignature>;
|
|
180
|
+
getLiquidateBorrowIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, assetMarketIndex: number, liabilityMarketIndex: number, maxLiabilityTransfer: BN): Promise<TransactionInstruction>;
|
|
181
|
+
liquidateBorrowForPerpPnl(userAccountPublicKey: PublicKey, userAccount: UserAccount, perpMarketIndex: number, liabilityMarketIndex: number, maxLiabilityTransfer: BN): Promise<TransactionSignature>;
|
|
182
|
+
getLiquidateBorrowForPerpPnlIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, perpMarketIndex: number, liabilityMarketIndex: number, maxLiabilityTransfer: BN): Promise<TransactionInstruction>;
|
|
183
|
+
liquidatePerpPnlForDeposit(userAccountPublicKey: PublicKey, userAccount: UserAccount, perpMarketIndex: number, assetMarketIndex: number, maxPnlTransfer: BN): Promise<TransactionSignature>;
|
|
184
|
+
getLiquidatePerpPnlForDepositIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, perpMarketIndex: number, assetMarketIndex: number, maxPnlTransfer: BN): Promise<TransactionInstruction>;
|
|
185
|
+
resolvePerpBankruptcy(userAccountPublicKey: PublicKey, userAccount: UserAccount, marketIndex: number): Promise<TransactionSignature>;
|
|
186
|
+
getResolvePerpBankruptcyIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, marketIndex: number): Promise<TransactionInstruction>;
|
|
187
|
+
resolveBorrowBankruptcy(userAccountPublicKey: PublicKey, userAccount: UserAccount, marketIndex: number): Promise<TransactionSignature>;
|
|
188
|
+
getResolveBorrowBankruptcyIx(userAccountPublicKey: PublicKey, userAccount: UserAccount, marketIndex: number): Promise<TransactionInstruction>;
|
|
190
189
|
getRemainingAccountsWithCounterparty(params: {
|
|
191
190
|
counterPartyUserAccount: UserAccount;
|
|
192
|
-
writablePerpMarketIndex?:
|
|
193
|
-
writableSpotMarketIndexes?:
|
|
191
|
+
writablePerpMarketIndex?: number;
|
|
192
|
+
writableSpotMarketIndexes?: number[];
|
|
194
193
|
}): AccountMeta[];
|
|
195
|
-
updateFundingRate(oracle: PublicKey, marketIndex:
|
|
196
|
-
getUpdateFundingRateIx(oracle: PublicKey, marketIndex:
|
|
194
|
+
updateFundingRate(oracle: PublicKey, marketIndex: number): Promise<TransactionSignature>;
|
|
195
|
+
getUpdateFundingRateIx(oracle: PublicKey, marketIndex: number): Promise<TransactionInstruction>;
|
|
197
196
|
settleFundingPayment(userAccount: PublicKey): Promise<TransactionSignature>;
|
|
198
197
|
getSettleFundingPaymentIx(userAccount: PublicKey): Promise<TransactionInstruction>;
|
|
199
198
|
triggerEvent(eventName: keyof ClearingHouseAccountEvents, data?: any): void;
|
|
200
|
-
getOracleDataForMarket(marketIndex:
|
|
201
|
-
getOracleDataForSpotMarket(marketIndex:
|
|
202
|
-
initializeInsuranceFundStake(marketIndex:
|
|
203
|
-
getInitializeInsuranceFundStakeIx(marketIndex:
|
|
204
|
-
addInsuranceFundStake(marketIndex:
|
|
205
|
-
requestRemoveInsuranceFundStake(marketIndex:
|
|
206
|
-
cancelRequestRemoveInsuranceFundStake(marketIndex:
|
|
207
|
-
removeInsuranceFundStake(marketIndex:
|
|
208
|
-
settleRevenueToInsuranceFund(marketIndex:
|
|
209
|
-
resolvePerpPnlDeficit(spotMarketIndex:
|
|
210
|
-
getResolvePerpPnlDeficitIx(spotMarketIndex:
|
|
199
|
+
getOracleDataForMarket(marketIndex: number): OraclePriceData;
|
|
200
|
+
getOracleDataForSpotMarket(marketIndex: number): OraclePriceData;
|
|
201
|
+
initializeInsuranceFundStake(marketIndex: number): Promise<TransactionSignature>;
|
|
202
|
+
getInitializeInsuranceFundStakeIx(marketIndex: number): Promise<TransactionInstruction>;
|
|
203
|
+
addInsuranceFundStake(marketIndex: number, amount: BN, collateralAccountPublicKey: PublicKey): Promise<TransactionSignature>;
|
|
204
|
+
requestRemoveInsuranceFundStake(marketIndex: number, amount: BN): Promise<TransactionSignature>;
|
|
205
|
+
cancelRequestRemoveInsuranceFundStake(marketIndex: number): Promise<TransactionSignature>;
|
|
206
|
+
removeInsuranceFundStake(marketIndex: number, collateralAccountPublicKey: PublicKey): Promise<TransactionSignature>;
|
|
207
|
+
settleRevenueToInsuranceFund(marketIndex: number): Promise<TransactionSignature>;
|
|
208
|
+
resolvePerpPnlDeficit(spotMarketIndex: number, perpMarketIndex: number): Promise<TransactionSignature>;
|
|
209
|
+
getResolvePerpPnlDeficitIx(spotMarketIndex: number, perpMarketIndex: number): Promise<TransactionInstruction>;
|
|
211
210
|
}
|