@drift-labs/sdk 0.1.19-master.1 → 0.1.21-master.3
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.d.ts +31 -0
- package/lib/accounts/bulkAccountLoader.js +177 -0
- package/lib/accounts/bulkUserSubscription.d.ts +7 -0
- package/lib/accounts/bulkUserSubscription.js +28 -0
- package/lib/accounts/pollingClearingHouseAccountSubscriber.d.ts +49 -0
- package/lib/accounts/pollingClearingHouseAccountSubscriber.js +228 -0
- package/lib/accounts/pollingTokenAccountSubscriber.d.ts +25 -0
- package/lib/accounts/pollingTokenAccountSubscriber.js +79 -0
- package/lib/accounts/pollingUserAccountSubscriber.d.ts +32 -0
- package/lib/accounts/pollingUserAccountSubscriber.js +136 -0
- package/lib/accounts/types.d.ts +38 -3
- package/lib/accounts/utils.d.ts +1 -0
- package/lib/accounts/utils.js +7 -0
- package/lib/accounts/webSocketAccountSubscriber.d.ts +6 -3
- package/lib/accounts/webSocketAccountSubscriber.js +43 -12
- package/lib/accounts/{defaultClearingHouseAccountSubscriber.d.ts → webSocketClearingHouseAccountSubscriber.d.ts} +8 -3
- package/lib/accounts/{defaultClearingHouseAccountSubscriber.js → webSocketClearingHouseAccountSubscriber.js} +30 -4
- package/lib/accounts/{defaultUserAccountSubscriber.d.ts → webSocketUserAccountSubscriber.d.ts} +6 -3
- package/lib/accounts/{defaultUserAccountSubscriber.js → webSocketUserAccountSubscriber.js} +16 -4
- package/lib/addresses.d.ts +4 -1
- package/lib/addresses.js +28 -1
- package/lib/admin.d.ts +10 -4
- package/lib/admin.js +54 -17
- package/lib/assert/assert.d.ts +0 -1
- package/lib/clearingHouse.d.ts +39 -4
- package/lib/clearingHouse.js +334 -23
- package/lib/clearingHouseUser.d.ts +26 -20
- package/lib/clearingHouseUser.js +149 -118
- package/lib/config.d.ts +0 -1
- package/lib/constants/markets.d.ts +2 -2
- package/lib/constants/markets.js +28 -15
- package/lib/constants/numericConstants.d.ts +4 -2
- package/lib/constants/numericConstants.js +16 -17
- package/lib/examples/makeTradeExample.d.ts +0 -1
- package/lib/examples/makeTradeExample.js +6 -6
- package/lib/factory/clearingHouse.d.ts +25 -0
- package/lib/factory/clearingHouse.js +64 -0
- package/lib/factory/clearingHouseUser.d.ts +19 -0
- package/lib/factory/clearingHouseUser.js +34 -0
- package/lib/idl/clearing_house.json +1066 -39
- package/lib/index.d.ts +11 -3
- package/lib/index.js +12 -2
- package/lib/math/amm.d.ts +1 -1
- package/lib/math/amm.js +38 -15
- package/lib/math/conversion.d.ts +1 -2
- package/lib/math/conversion.js +1 -1
- package/lib/math/funding.d.ts +0 -1
- package/lib/math/funding.js +1 -1
- package/lib/math/insuranceFund.d.ts +2 -2
- package/lib/math/insuranceFund.js +3 -6
- package/lib/math/market.d.ts +2 -2
- package/lib/math/market.js +12 -2
- package/lib/math/orders.d.ts +3 -0
- package/lib/math/orders.js +32 -0
- package/lib/math/position.d.ts +6 -3
- package/lib/math/position.js +21 -10
- package/lib/math/trade.d.ts +0 -1
- package/lib/math/trade.js +16 -16
- package/lib/math/utils.d.ts +2 -2
- package/lib/math/utils.js +3 -3
- package/lib/mockUSDCFaucet.d.ts +2 -2
- package/lib/orderParams.d.ts +7 -0
- package/lib/orderParams.js +108 -0
- package/lib/orders.d.ts +6 -0
- package/lib/orders.js +136 -0
- package/lib/pythClient.d.ts +0 -1
- package/lib/pythClient.js +1 -1
- package/lib/token/index.d.ts +3 -0
- package/lib/token/index.js +38 -0
- package/lib/tx/defaultTxSender.d.ts +0 -1
- package/lib/tx/types.d.ts +0 -1
- package/lib/tx/utils.d.ts +0 -1
- package/lib/types.d.ts +147 -3
- package/lib/types.js +36 -1
- package/lib/util/computeUnits.d.ts +0 -1
- package/lib/util/tps.d.ts +0 -1
- package/lib/wallet.d.ts +0 -1
- package/package.json +11 -3
- package/src/accounts/bulkAccountLoader.ts +215 -0
- package/src/accounts/bulkUserSubscription.ts +28 -0
- package/src/accounts/pollingClearingHouseAccountSubscriber.ts +326 -0
- package/src/accounts/pollingTokenAccountSubscriber.ts +99 -0
- package/src/accounts/pollingUserAccountSubscriber.ts +194 -0
- package/src/accounts/types.ts +48 -1
- package/src/accounts/utils.ts +3 -0
- package/src/accounts/webSocketAccountSubscriber.ts +67 -17
- package/src/accounts/{defaultClearingHouseAccountSubscriber.ts → webSocketClearingHouseAccountSubscriber.ts} +51 -1
- package/src/accounts/{defaultUserAccountSubscriber.ts → webSocketUserAccountSubscriber.ts} +33 -3
- package/src/addresses.ts +37 -0
- package/src/admin.ts +92 -24
- package/src/clearingHouse.ts +455 -22
- package/src/clearingHouseUser.ts +190 -108
- package/src/constants/markets.ts +17 -1
- package/src/constants/numericConstants.ts +3 -1
- package/src/examples/makeTradeExample.ts +4 -1
- package/src/factory/clearingHouse.ts +125 -0
- package/src/factory/clearingHouseUser.ts +73 -0
- package/src/idl/clearing_house.json +1066 -39
- package/src/index.ts +11 -2
- package/src/math/amm.ts +47 -14
- package/src/math/conversion.ts +1 -1
- package/src/math/insuranceFund.ts +1 -1
- package/src/math/market.ts +28 -2
- package/src/math/orders.ts +44 -0
- package/src/math/position.ts +24 -4
- package/src/math/utils.ts +1 -1
- package/src/mockUSDCFaucet.ts +1 -1
- package/src/orderParams.ts +151 -0
- package/src/orders.ts +236 -0
- package/src/token/index.ts +37 -0
- package/src/types.ts +130 -2
- package/tsconfig.json +0 -1
- package/lib/accounts/defaultClearingHouseAccountSubscriber.d.ts.map +0 -1
- package/lib/accounts/defaultUserAccountSubscriber.d.ts.map +0 -1
- package/lib/accounts/types.d.ts.map +0 -1
- package/lib/accounts/webSocketAccountSubscriber.d.ts.map +0 -1
- package/lib/addresses.d.ts.map +0 -1
- package/lib/admin.d.ts.map +0 -1
- package/lib/assert/assert.d.ts.map +0 -1
- package/lib/clearingHouse.d.ts.map +0 -1
- package/lib/clearingHouseUser.d.ts.map +0 -1
- package/lib/config.d.ts.map +0 -1
- package/lib/constants/markets.d.ts.map +0 -1
- package/lib/constants/numericConstants.d.ts.map +0 -1
- package/lib/examples/makeTradeExample.d.ts.map +0 -1
- package/lib/index.d.ts.map +0 -1
- package/lib/math/amm.d.ts.map +0 -1
- package/lib/math/conversion.d.ts.map +0 -1
- package/lib/math/funding.d.ts.map +0 -1
- package/lib/math/insuranceFund.d.ts.map +0 -1
- package/lib/math/market.d.ts.map +0 -1
- package/lib/math/position.d.ts.map +0 -1
- package/lib/math/trade.d.ts.map +0 -1
- package/lib/math/utils.d.ts.map +0 -1
- package/lib/mockUSDCFaucet.d.ts.map +0 -1
- package/lib/pythClient.d.ts.map +0 -1
- package/lib/tx/defaultTxSender.d.ts.map +0 -1
- package/lib/tx/types.d.ts.map +0 -1
- package/lib/tx/utils.d.ts.map +0 -1
- package/lib/types.d.ts.map +0 -1
- package/lib/util/computeUnits.d.ts.map +0 -1
- package/lib/util/tps.d.ts.map +0 -1
- package/lib/wallet.d.ts.map +0 -1
package/src/admin.ts
CHANGED
|
@@ -5,18 +5,29 @@ import {
|
|
|
5
5
|
SYSVAR_RENT_PUBKEY,
|
|
6
6
|
TransactionSignature,
|
|
7
7
|
} from '@solana/web3.js';
|
|
8
|
-
import {
|
|
9
|
-
|
|
8
|
+
import {
|
|
9
|
+
FeeStructure,
|
|
10
|
+
IWallet,
|
|
11
|
+
OracleGuardRails,
|
|
12
|
+
OracleSource,
|
|
13
|
+
OrderFillerRewardStructure,
|
|
14
|
+
} from './types';
|
|
15
|
+
import { BN, Provider } from '@project-serum/anchor';
|
|
10
16
|
import * as anchor from '@project-serum/anchor';
|
|
11
|
-
import {
|
|
17
|
+
import {
|
|
18
|
+
getClearingHouseStateAccountPublicKey,
|
|
19
|
+
getClearingHouseStateAccountPublicKeyAndNonce,
|
|
20
|
+
getOrderStateAccountPublicKeyAndNonce,
|
|
21
|
+
} from './addresses';
|
|
12
22
|
import { TOKEN_PROGRAM_ID } from '@solana/spl-token';
|
|
13
23
|
import { ClearingHouse } from './clearingHouse';
|
|
14
24
|
import { PEG_PRECISION } from './constants/numericConstants';
|
|
15
|
-
import clearingHouseIDL from './idl/clearing_house.json';
|
|
16
|
-
import { DefaultClearingHouseAccountSubscriber } from './accounts/defaultClearingHouseAccountSubscriber';
|
|
17
|
-
import { DefaultTxSender } from './tx/defaultTxSender';
|
|
18
25
|
import { calculateTargetPriceTrade } from './math/trade';
|
|
19
26
|
import { calculateAmmReservesAfterSwap, getSwapDirection } from './math/amm';
|
|
27
|
+
import {
|
|
28
|
+
getAdmin,
|
|
29
|
+
getWebSocketClearingHouseConfig,
|
|
30
|
+
} from './factory/clearingHouse';
|
|
20
31
|
|
|
21
32
|
export class Admin extends ClearingHouse {
|
|
22
33
|
public static from(
|
|
@@ -25,30 +36,21 @@ export class Admin extends ClearingHouse {
|
|
|
25
36
|
clearingHouseProgramId: PublicKey,
|
|
26
37
|
opts: ConfirmOptions = Provider.defaultOptions()
|
|
27
38
|
): Admin {
|
|
28
|
-
const
|
|
29
|
-
const program = new Program(
|
|
30
|
-
clearingHouseIDL as Idl,
|
|
31
|
-
clearingHouseProgramId,
|
|
32
|
-
provider
|
|
33
|
-
);
|
|
34
|
-
const accountSubscriber = new DefaultClearingHouseAccountSubscriber(
|
|
35
|
-
program
|
|
36
|
-
);
|
|
37
|
-
const txSender = new DefaultTxSender(provider);
|
|
38
|
-
return new Admin(
|
|
39
|
+
const config = getWebSocketClearingHouseConfig(
|
|
39
40
|
connection,
|
|
40
41
|
wallet,
|
|
41
|
-
|
|
42
|
-
accountSubscriber,
|
|
43
|
-
txSender,
|
|
42
|
+
clearingHouseProgramId,
|
|
44
43
|
opts
|
|
45
44
|
);
|
|
45
|
+
return getAdmin(config);
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
public async initialize(
|
|
49
49
|
usdcMint: PublicKey,
|
|
50
50
|
adminControlsPrices: boolean
|
|
51
|
-
): Promise<
|
|
51
|
+
): Promise<
|
|
52
|
+
[TransactionSignature, TransactionSignature, TransactionSignature]
|
|
53
|
+
> {
|
|
52
54
|
const stateAccountRPCResponse = await this.connection.getParsedAccountInfo(
|
|
53
55
|
await this.getStatePublicKey()
|
|
54
56
|
);
|
|
@@ -172,7 +174,40 @@ export class Admin extends ClearingHouse {
|
|
|
172
174
|
this.opts
|
|
173
175
|
);
|
|
174
176
|
|
|
175
|
-
|
|
177
|
+
const initializeOrderStateTxSig = await this.initializeOrderState();
|
|
178
|
+
|
|
179
|
+
return [initializeTxSig, initializeHistoryTxSig, initializeOrderStateTxSig];
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
public async initializeOrderState(): Promise<TransactionSignature> {
|
|
183
|
+
const orderHistory = anchor.web3.Keypair.generate();
|
|
184
|
+
const [orderStatePublicKey, orderStateNonce] =
|
|
185
|
+
await getOrderStateAccountPublicKeyAndNonce(this.program.programId);
|
|
186
|
+
const clearingHouseStatePublicKey =
|
|
187
|
+
await getClearingHouseStateAccountPublicKey(this.program.programId);
|
|
188
|
+
|
|
189
|
+
const initializeOrderStateTx =
|
|
190
|
+
await this.program.transaction.initializeOrderState(orderStateNonce, {
|
|
191
|
+
accounts: {
|
|
192
|
+
admin: this.wallet.publicKey,
|
|
193
|
+
state: clearingHouseStatePublicKey,
|
|
194
|
+
orderHistory: orderHistory.publicKey,
|
|
195
|
+
orderState: orderStatePublicKey,
|
|
196
|
+
rent: SYSVAR_RENT_PUBKEY,
|
|
197
|
+
systemProgram: anchor.web3.SystemProgram.programId,
|
|
198
|
+
},
|
|
199
|
+
instructions: [
|
|
200
|
+
await this.program.account.orderHistory.createInstruction(
|
|
201
|
+
orderHistory
|
|
202
|
+
),
|
|
203
|
+
],
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
return await this.txSender.send(
|
|
207
|
+
initializeOrderStateTx,
|
|
208
|
+
[orderHistory],
|
|
209
|
+
this.opts
|
|
210
|
+
);
|
|
176
211
|
}
|
|
177
212
|
|
|
178
213
|
public async initializeMarket(
|
|
@@ -518,6 +553,21 @@ export class Admin extends ClearingHouse {
|
|
|
518
553
|
);
|
|
519
554
|
}
|
|
520
555
|
|
|
556
|
+
public async updateOrderFillerRewardStructure(
|
|
557
|
+
orderFillerRewardStructure: OrderFillerRewardStructure
|
|
558
|
+
): Promise<TransactionSignature> {
|
|
559
|
+
return await this.program.rpc.updateOrderFillerRewardStructure(
|
|
560
|
+
orderFillerRewardStructure,
|
|
561
|
+
{
|
|
562
|
+
accounts: {
|
|
563
|
+
admin: this.wallet.publicKey,
|
|
564
|
+
state: await this.getStatePublicKey(),
|
|
565
|
+
orderState: await this.getOrderStatePublicKey(),
|
|
566
|
+
},
|
|
567
|
+
}
|
|
568
|
+
);
|
|
569
|
+
}
|
|
570
|
+
|
|
521
571
|
public async updateFee(fees: FeeStructure): Promise<TransactionSignature> {
|
|
522
572
|
return await this.program.rpc.updateFee(fees, {
|
|
523
573
|
accounts: {
|
|
@@ -558,12 +608,30 @@ export class Admin extends ClearingHouse {
|
|
|
558
608
|
);
|
|
559
609
|
}
|
|
560
610
|
|
|
561
|
-
public async
|
|
611
|
+
public async updateMarketMinimumQuoteAssetTradeSize(
|
|
612
|
+
marketIndex: BN,
|
|
613
|
+
minimumTradeSize: BN
|
|
614
|
+
): Promise<TransactionSignature> {
|
|
615
|
+
const state = this.getStateAccount();
|
|
616
|
+
return await this.program.rpc.updateMarketMinimumQuoteAssetTradeSize(
|
|
617
|
+
marketIndex,
|
|
618
|
+
minimumTradeSize,
|
|
619
|
+
{
|
|
620
|
+
accounts: {
|
|
621
|
+
admin: this.wallet.publicKey,
|
|
622
|
+
state: await this.getStatePublicKey(),
|
|
623
|
+
markets: state.markets,
|
|
624
|
+
},
|
|
625
|
+
}
|
|
626
|
+
);
|
|
627
|
+
}
|
|
628
|
+
|
|
629
|
+
public async updateMarketMinimumBaseAssetTradeSize(
|
|
562
630
|
marketIndex: BN,
|
|
563
631
|
minimumTradeSize: BN
|
|
564
632
|
): Promise<TransactionSignature> {
|
|
565
633
|
const state = this.getStateAccount();
|
|
566
|
-
return await this.program.rpc.
|
|
634
|
+
return await this.program.rpc.updateMarketMinimumBaseAssetTradeSize(
|
|
567
635
|
marketIndex,
|
|
568
636
|
minimumTradeSize,
|
|
569
637
|
{
|