@drift-labs/sdk 0.1.36-master.2 → 0.1.36-master.5
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/admin.js +1 -1
- package/lib/clearingHouse.d.ts +6 -4
- package/lib/clearingHouse.js +46 -8
- package/lib/examples/makeTradeExample.js +1 -1
- package/lib/factory/clearingHouse.js +4 -4
- package/lib/idl/clearing_house.json +377 -306
- package/lib/mockUSDCFaucet.d.ts +2 -2
- package/lib/mockUSDCFaucet.js +3 -3
- package/lib/oracles/switchboardClient.js +1 -1
- package/lib/tx/defaultTxSender.d.ts +3 -3
- package/lib/tx/defaultTxSender.js +1 -1
- package/lib/tx/retryTxSender.d.ts +3 -3
- package/package.json +2 -2
- package/src/accounts/webSocketAccountSubscriber.ts +3 -3
- package/src/admin.ts +2 -2
- package/src/clearingHouse.ts +81 -10
- package/src/examples/makeTradeExample.ts +6 -2
- package/src/factory/clearingHouse.ts +13 -5
- package/src/idl/clearing_house.json +377 -306
- package/src/mockUSDCFaucet.ts +5 -5
- package/src/oracles/switchboardClient.ts +2 -2
- package/src/tx/defaultTxSender.ts +4 -4
- package/src/tx/retryTxSender.ts +3 -3
package/lib/admin.js
CHANGED
|
@@ -45,7 +45,7 @@ const trade_1 = require("./math/trade");
|
|
|
45
45
|
const amm_1 = require("./math/amm");
|
|
46
46
|
const clearingHouse_2 = require("./factory/clearingHouse");
|
|
47
47
|
class Admin extends clearingHouse_1.ClearingHouse {
|
|
48
|
-
static from(connection, wallet, clearingHouseProgramId, opts = anchor_1.
|
|
48
|
+
static from(connection, wallet, clearingHouseProgramId, opts = anchor_1.AnchorProvider.defaultOptions()) {
|
|
49
49
|
const config = (0, clearingHouse_2.getWebSocketClearingHouseConfig)(connection, wallet, clearingHouseProgramId, opts);
|
|
50
50
|
return (0, clearingHouse_2.getAdmin)(config);
|
|
51
51
|
}
|
package/lib/clearingHouse.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="bn.js" />
|
|
3
|
-
import { BN, Program
|
|
3
|
+
import { AnchorProvider, BN, Program } from '@project-serum/anchor';
|
|
4
4
|
import { MarketsAccount, StateAccount, DepositHistoryAccount, FundingPaymentHistoryAccount, FundingRateHistoryAccount, IWallet, LiquidationHistoryAccount, PositionDirection, TradeHistoryAccount, UserAccount, Market, OrderHistoryAccount, OrderStateAccount, OrderParams, Order, ExtendedCurveHistoryAccount, UserPositionsAccount } from './types';
|
|
5
5
|
import { Connection, PublicKey, TransactionSignature, Keypair, ConfirmOptions, TransactionInstruction } from '@solana/web3.js';
|
|
6
6
|
import { MockUSDCFaucet } from './mockUSDCFaucet';
|
|
@@ -19,7 +19,7 @@ export declare class ClearingHouse {
|
|
|
19
19
|
connection: Connection;
|
|
20
20
|
wallet: IWallet;
|
|
21
21
|
program: Program;
|
|
22
|
-
provider:
|
|
22
|
+
provider: AnchorProvider;
|
|
23
23
|
opts?: ConfirmOptions;
|
|
24
24
|
accountSubscriber: ClearingHouseAccountSubscriber;
|
|
25
25
|
eventEmitter: StrictEventEmitter<EventEmitter, ClearingHouseAccountEvents>;
|
|
@@ -126,8 +126,10 @@ export declare class ClearingHouse {
|
|
|
126
126
|
getCancelOrderIx(orderId: BN, oracle?: PublicKey): Promise<TransactionInstruction>;
|
|
127
127
|
cancelOrderByUserId(userOrderId: number, oracle?: PublicKey): Promise<TransactionSignature>;
|
|
128
128
|
getCancelOrderByUserIdIx(userOrderId: number, oracle?: PublicKey): Promise<TransactionInstruction>;
|
|
129
|
-
cancelAllOrders(oracles?: PublicKey[]): Promise<TransactionSignature>;
|
|
130
|
-
getCancelAllOrdersIx(oracles: PublicKey[]): Promise<TransactionInstruction>;
|
|
129
|
+
cancelAllOrders(oracles?: PublicKey[], bestEffort?: boolean): Promise<TransactionSignature>;
|
|
130
|
+
getCancelAllOrdersIx(oracles: PublicKey[], bestEffort?: boolean): Promise<TransactionInstruction>;
|
|
131
|
+
cancelOrdersByMarketAndSide(oracles?: PublicKey[], bestEffort?: boolean, marketIndexOnly?: BN, directionOnly?: PositionDirection): Promise<TransactionSignature>;
|
|
132
|
+
getCancelOrdersByMarketAndSideIx(oracles: PublicKey[], bestEffort?: boolean, marketIndexOnly?: BN, directionOnly?: PositionDirection): Promise<TransactionInstruction>;
|
|
131
133
|
fillOrder(userAccountPublicKey: PublicKey, userOrdersAccountPublicKey: PublicKey, order: Order): Promise<TransactionSignature>;
|
|
132
134
|
getFillOrderIx(userAccountPublicKey: PublicKey, userOrdersAccountPublicKey: PublicKey, order: Order): Promise<TransactionInstruction>;
|
|
133
135
|
initializeUserOrdersThenPlaceAndFillOrder(orderParams: OrderParams, discountToken?: PublicKey, referrer?: PublicKey): Promise<TransactionSignature>;
|
package/lib/clearingHouse.js
CHANGED
|
@@ -77,7 +77,7 @@ class ClearingHouse {
|
|
|
77
77
|
* @param opts
|
|
78
78
|
* @returns
|
|
79
79
|
*/
|
|
80
|
-
static from(connection, wallet, clearingHouseProgramId, opts = anchor_1.
|
|
80
|
+
static from(connection, wallet, clearingHouseProgramId, opts = anchor_1.AnchorProvider.defaultOptions()) {
|
|
81
81
|
const config = (0, clearingHouse_1.getWebSocketClearingHouseConfig)(connection, wallet, clearingHouseProgramId, opts);
|
|
82
82
|
return (0, clearingHouse_1.getClearingHouse)(config);
|
|
83
83
|
}
|
|
@@ -185,7 +185,7 @@ class ClearingHouse {
|
|
|
185
185
|
* @param newWallet
|
|
186
186
|
*/
|
|
187
187
|
updateWallet(newWallet) {
|
|
188
|
-
const newProvider = new anchor_1.
|
|
188
|
+
const newProvider = new anchor_1.AnchorProvider(this.connection, newWallet, this.opts);
|
|
189
189
|
const newProgram = new anchor_1.Program(clearing_house_json_1.default, this.program.programId, newProvider);
|
|
190
190
|
// Update provider for txSender with new wallet details
|
|
191
191
|
this.txSender.provider = newProvider;
|
|
@@ -352,7 +352,7 @@ class ClearingHouse {
|
|
|
352
352
|
.add(initializeUserAccountIx)
|
|
353
353
|
.add(initializeUserOrdersAccountIx)
|
|
354
354
|
.add(depositCollateralIx);
|
|
355
|
-
const txSig = yield this.
|
|
355
|
+
const txSig = yield this.txSender.send(tx, [userPositionsAccount]);
|
|
356
356
|
return [txSig, userAccountPublicKey];
|
|
357
357
|
});
|
|
358
358
|
}
|
|
@@ -367,7 +367,9 @@ class ClearingHouse {
|
|
|
367
367
|
.add(initializeUserAccountIx)
|
|
368
368
|
.add(initializeUserOrdersAccountIx)
|
|
369
369
|
.add(depositCollateralIx);
|
|
370
|
-
const txSig = yield this.program.provider.
|
|
370
|
+
const txSig = yield this.program.provider.sendAndConfirm(tx, [
|
|
371
|
+
userPositionsAccount,
|
|
372
|
+
]);
|
|
371
373
|
return [txSig, userAccountPublicKey];
|
|
372
374
|
});
|
|
373
375
|
}
|
|
@@ -620,12 +622,48 @@ class ClearingHouse {
|
|
|
620
622
|
});
|
|
621
623
|
});
|
|
622
624
|
}
|
|
623
|
-
cancelAllOrders(oracles) {
|
|
625
|
+
cancelAllOrders(oracles, bestEffort) {
|
|
626
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
627
|
+
return yield this.txSender.send((0, utils_1.wrapInTx)(yield this.getCancelAllOrdersIx(oracles, bestEffort)), [], this.opts);
|
|
628
|
+
});
|
|
629
|
+
}
|
|
630
|
+
getCancelAllOrdersIx(oracles, bestEffort) {
|
|
631
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
632
|
+
const userAccountPublicKey = yield this.getUserAccountPublicKey();
|
|
633
|
+
const userAccount = yield this.getUserAccount();
|
|
634
|
+
const state = this.getStateAccount();
|
|
635
|
+
const orderState = this.getOrderStateAccount();
|
|
636
|
+
const remainingAccounts = [];
|
|
637
|
+
for (const oracle of oracles) {
|
|
638
|
+
remainingAccounts.push({
|
|
639
|
+
pubkey: oracle,
|
|
640
|
+
isWritable: false,
|
|
641
|
+
isSigner: false,
|
|
642
|
+
});
|
|
643
|
+
}
|
|
644
|
+
return yield this.program.instruction.cancelAllOrders(bestEffort, {
|
|
645
|
+
accounts: {
|
|
646
|
+
state: yield this.getStatePublicKey(),
|
|
647
|
+
user: userAccountPublicKey,
|
|
648
|
+
authority: this.wallet.publicKey,
|
|
649
|
+
markets: state.markets,
|
|
650
|
+
userOrders: yield this.getUserOrdersAccountPublicKey(),
|
|
651
|
+
userPositions: userAccount.positions,
|
|
652
|
+
fundingPaymentHistory: state.fundingPaymentHistory,
|
|
653
|
+
fundingRateHistory: state.fundingRateHistory,
|
|
654
|
+
orderState: yield this.getOrderStatePublicKey(),
|
|
655
|
+
orderHistory: orderState.orderHistory,
|
|
656
|
+
},
|
|
657
|
+
remainingAccounts,
|
|
658
|
+
});
|
|
659
|
+
});
|
|
660
|
+
}
|
|
661
|
+
cancelOrdersByMarketAndSide(oracles, bestEffort, marketIndexOnly, directionOnly) {
|
|
624
662
|
return __awaiter(this, void 0, void 0, function* () {
|
|
625
|
-
return yield this.txSender.send((0, utils_1.wrapInTx)(yield this.
|
|
663
|
+
return yield this.txSender.send((0, utils_1.wrapInTx)(yield this.getCancelOrdersByMarketAndSideIx(oracles, bestEffort, marketIndexOnly, directionOnly)), [], this.opts);
|
|
626
664
|
});
|
|
627
665
|
}
|
|
628
|
-
|
|
666
|
+
getCancelOrdersByMarketAndSideIx(oracles, bestEffort, marketIndexOnly, directionOnly) {
|
|
629
667
|
return __awaiter(this, void 0, void 0, function* () {
|
|
630
668
|
const userAccountPublicKey = yield this.getUserAccountPublicKey();
|
|
631
669
|
const userAccount = yield this.getUserAccount();
|
|
@@ -639,7 +677,7 @@ class ClearingHouse {
|
|
|
639
677
|
isSigner: false,
|
|
640
678
|
});
|
|
641
679
|
}
|
|
642
|
-
return yield this.program.instruction.
|
|
680
|
+
return yield this.program.instruction.cancelOrdersByMarketAndSide(bestEffort, marketIndexOnly, directionOnly, {
|
|
643
681
|
accounts: {
|
|
644
682
|
state: yield this.getStatePublicKey(),
|
|
645
683
|
user: userAccountPublicKey,
|
|
@@ -30,7 +30,7 @@ const main = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
|
30
30
|
const rpcAddress = process.env.RPC_ADDRESS; // can use: https://api.devnet.solana.com for devnet; https://api.mainnet-beta.solana.com for mainnet;
|
|
31
31
|
const connection = new web3_js_1.Connection(rpcAddress);
|
|
32
32
|
// Set up the Provider
|
|
33
|
-
const provider = new anchor_1.
|
|
33
|
+
const provider = new anchor_1.AnchorProvider(connection, wallet, anchor_1.AnchorProvider.defaultOptions());
|
|
34
34
|
// Check SOL Balance
|
|
35
35
|
const lamportsBalance = yield connection.getBalance(wallet.publicKey);
|
|
36
36
|
console.log('SOL balance:', lamportsBalance / Math.pow(10, 9));
|
|
@@ -12,7 +12,7 @@ const defaultTxSender_1 = require("../tx/defaultTxSender");
|
|
|
12
12
|
const pollingClearingHouseAccountSubscriber_1 = require("../accounts/pollingClearingHouseAccountSubscriber");
|
|
13
13
|
const admin_1 = require("../admin");
|
|
14
14
|
const retryTxSender_1 = require("../tx/retryTxSender");
|
|
15
|
-
function getWebSocketClearingHouseConfig(connection, wallet, programID, opts = anchor_1.
|
|
15
|
+
function getWebSocketClearingHouseConfig(connection, wallet, programID, opts = anchor_1.AnchorProvider.defaultOptions(), txSenderConfig) {
|
|
16
16
|
return {
|
|
17
17
|
type: 'websocket',
|
|
18
18
|
connection,
|
|
@@ -23,7 +23,7 @@ function getWebSocketClearingHouseConfig(connection, wallet, programID, opts = a
|
|
|
23
23
|
};
|
|
24
24
|
}
|
|
25
25
|
exports.getWebSocketClearingHouseConfig = getWebSocketClearingHouseConfig;
|
|
26
|
-
function getPollingClearingHouseConfig(connection, wallet, programID, accountLoader, opts = anchor_1.
|
|
26
|
+
function getPollingClearingHouseConfig(connection, wallet, programID, accountLoader, opts = anchor_1.AnchorProvider.defaultOptions(), txSenderConfig) {
|
|
27
27
|
return {
|
|
28
28
|
type: 'polling',
|
|
29
29
|
connection,
|
|
@@ -37,7 +37,7 @@ function getPollingClearingHouseConfig(connection, wallet, programID, accountLoa
|
|
|
37
37
|
exports.getPollingClearingHouseConfig = getPollingClearingHouseConfig;
|
|
38
38
|
function getClearingHouse(config) {
|
|
39
39
|
var _a;
|
|
40
|
-
const provider = new anchor_1.
|
|
40
|
+
const provider = new anchor_1.AnchorProvider(config.connection, config.wallet, config.opts);
|
|
41
41
|
const program = new anchor_1.Program(clearing_house_json_1.default, config.programID, provider);
|
|
42
42
|
let accountSubscriber;
|
|
43
43
|
if (config.type === 'websocket') {
|
|
@@ -59,7 +59,7 @@ function getClearingHouse(config) {
|
|
|
59
59
|
exports.getClearingHouse = getClearingHouse;
|
|
60
60
|
function getAdmin(config) {
|
|
61
61
|
var _a;
|
|
62
|
-
const provider = new anchor_1.
|
|
62
|
+
const provider = new anchor_1.AnchorProvider(config.connection, config.wallet, config.opts);
|
|
63
63
|
const program = new anchor_1.Program(clearing_house_json_1.default, config.programID, provider);
|
|
64
64
|
let accountSubscriber;
|
|
65
65
|
if (config.type === 'websocket') {
|