@drift-labs/sdk 0.1.18-orders.1 → 0.1.18-orders.2
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 +2 -1
- package/lib/accounts/bulkAccountLoader.d.ts +32 -0
- package/lib/accounts/bulkAccountLoader.js +156 -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 +133 -0
- package/lib/accounts/types.d.ts +30 -25
- package/lib/accounts/utils.d.ts +1 -0
- package/lib/accounts/utils.js +7 -0
- package/lib/accounts/{defaultClearingHouseAccountSubscriber.d.ts → webSocketClearingHouseAccountSubscriber.d.ts} +6 -4
- package/lib/accounts/{defaultClearingHouseAccountSubscriber.js → webSocketClearingHouseAccountSubscriber.js} +5 -4
- package/lib/accounts/{defaultUserAccountSubscriber.d.ts → webSocketUserAccountSubscriber.d.ts} +3 -1
- package/lib/accounts/{defaultUserAccountSubscriber.js → webSocketUserAccountSubscriber.js} +10 -7
- package/lib/addresses.d.ts +2 -2
- package/lib/addresses.js +4 -4
- package/lib/admin.d.ts +3 -0
- package/lib/admin.js +61 -13
- package/lib/clearingHouse.d.ts +16 -4
- package/lib/clearingHouse.js +50 -10
- package/lib/clearingHouseUser.d.ts +9 -1
- package/lib/clearingHouseUser.js +19 -5
- package/lib/config.js +1 -1
- package/lib/constants/markets.js +16 -0
- 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 +360 -15
- package/lib/index.d.ts +9 -4
- package/lib/index.js +14 -5
- package/lib/math/funding.js +4 -1
- package/lib/math/utils.d.ts +2 -2
- package/lib/math/utils.js +6 -3
- package/lib/orderParams.d.ts +3 -3
- package/lib/orderParams.js +23 -3
- package/lib/token/index.d.ts +3 -0
- package/lib/token/index.js +38 -0
- package/lib/types.d.ts +13 -3
- package/package.json +3 -3
- package/src/accounts/bulkAccountLoader.ts +195 -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 +186 -0
- package/src/accounts/types.ts +35 -30
- package/src/accounts/utils.ts +3 -0
- package/src/accounts/{defaultClearingHouseAccountSubscriber.ts → webSocketClearingHouseAccountSubscriber.ts} +9 -6
- package/src/accounts/{defaultUserAccountSubscriber.ts → webSocketUserAccountSubscriber.ts} +10 -5
- package/src/addresses.ts +6 -4
- package/src/admin.ts +73 -20
- package/src/clearingHouse.ts +69 -25
- package/src/clearingHouseUser.ts +26 -6
- package/src/config.ts +1 -1
- package/src/constants/markets.ts +16 -0
- package/src/factory/clearingHouse.ts +125 -0
- package/src/factory/clearingHouseUser.ts +73 -0
- package/src/idl/clearing_house.json +360 -15
- package/src/index.ts +9 -4
- package/src/math/funding.ts +5 -1
- package/src/math/utils.ts +1 -1
- package/src/orderParams.ts +26 -3
- package/src/token/index.ts +37 -0
- package/src/types.ts +13 -3
- package/lib/accounts/defaultHistoryAccountSubscriber.d.ts +0 -28
- package/lib/accounts/defaultHistoryAccountSubscriber.js +0 -110
- package/src/accounts/defaultHistoryAccountSubscriber.ts +0 -176
package/lib/clearingHouse.js
CHANGED
|
@@ -38,19 +38,19 @@ const anchor = __importStar(require("@project-serum/anchor"));
|
|
|
38
38
|
const clearing_house_json_1 = __importDefault(require("./idl/clearing_house.json"));
|
|
39
39
|
const web3_js_1 = require("@solana/web3.js");
|
|
40
40
|
const addresses_1 = require("./addresses");
|
|
41
|
-
const defaultClearingHouseAccountSubscriber_1 = require("./accounts/defaultClearingHouseAccountSubscriber");
|
|
42
41
|
const defaultTxSender_1 = require("./tx/defaultTxSender");
|
|
43
42
|
const utils_1 = require("./tx/utils");
|
|
43
|
+
const clearingHouse_1 = require("./factory/clearingHouse");
|
|
44
44
|
/**
|
|
45
45
|
* # ClearingHouse
|
|
46
46
|
* This class is the main way to interact with Drift Protocol. It allows you to subscribe to the various accounts where the Market's state is stored, as well as: opening positions, liquidating, settling funding, depositing & withdrawing, and more.
|
|
47
47
|
*
|
|
48
|
-
* The default way to construct a ClearingHouse instance is using the {@link from} method. This will create an instance using the static {@link
|
|
48
|
+
* The default way to construct a ClearingHouse instance is using the {@link from} method. This will create an instance using the static {@link WebSocketClearingHouseAccountSubscriber}, which will use a websocket for each state account subscription.
|
|
49
49
|
* Alternatively, if you want to implement your own method of subscribing to the state accounts on the blockchain, you can implement a {@link ClearingHouseAccountSubscriber} and use it in the {@link ClearingHouse.constructor}
|
|
50
50
|
*/
|
|
51
51
|
class ClearingHouse {
|
|
52
52
|
constructor(connection, wallet, program, accountSubscriber, txSender, opts) {
|
|
53
|
-
this.
|
|
53
|
+
this._isSubscribed = false;
|
|
54
54
|
this.connection = connection;
|
|
55
55
|
this.wallet = wallet;
|
|
56
56
|
this.opts = opts;
|
|
@@ -59,12 +59,23 @@ class ClearingHouse {
|
|
|
59
59
|
this.eventEmitter = this.accountSubscriber.eventEmitter;
|
|
60
60
|
this.txSender = txSender;
|
|
61
61
|
}
|
|
62
|
+
get isSubscribed() {
|
|
63
|
+
return this._isSubscribed && this.accountSubscriber.isSubscribed;
|
|
64
|
+
}
|
|
65
|
+
set isSubscribed(val) {
|
|
66
|
+
this._isSubscribed = val;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* @deprecated You should use the getClearingHouse factory method instead
|
|
70
|
+
* @param connection
|
|
71
|
+
* @param wallet
|
|
72
|
+
* @param clearingHouseProgramId
|
|
73
|
+
* @param opts
|
|
74
|
+
* @returns
|
|
75
|
+
*/
|
|
62
76
|
static from(connection, wallet, clearingHouseProgramId, opts = anchor_1.Provider.defaultOptions()) {
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
const accountSubscriber = new defaultClearingHouseAccountSubscriber_1.DefaultClearingHouseAccountSubscriber(program);
|
|
66
|
-
const txSender = new defaultTxSender_1.DefaultTxSender(provider);
|
|
67
|
-
return new ClearingHouse(connection, wallet, program, accountSubscriber, txSender, opts);
|
|
77
|
+
const config = clearingHouse_1.getWebSocketClearingHouseConfig(connection, wallet, clearingHouseProgramId, opts);
|
|
78
|
+
return clearingHouse_1.getClearingHouse(config);
|
|
68
79
|
}
|
|
69
80
|
/**
|
|
70
81
|
*
|
|
@@ -230,10 +241,10 @@ class ClearingHouse {
|
|
|
230
241
|
}
|
|
231
242
|
getInitializeUserOrdersInstruction(userAccountPublicKey) {
|
|
232
243
|
return __awaiter(this, void 0, void 0, function* () {
|
|
233
|
-
const [userOrdersAccountPublicKey, userOrdersAccountNonce] = yield addresses_1.getUserOrdersAccountPublicKeyAndNonce(this.program.programId, this.wallet.publicKey);
|
|
234
244
|
if (!userAccountPublicKey) {
|
|
235
245
|
userAccountPublicKey = yield this.getUserAccountPublicKey();
|
|
236
246
|
}
|
|
247
|
+
const [userOrdersAccountPublicKey, userOrdersAccountNonce] = yield addresses_1.getUserOrdersAccountPublicKeyAndNonce(this.program.programId, userAccountPublicKey);
|
|
237
248
|
return yield this.program.instruction.initializeUserOrders(userOrdersAccountNonce, {
|
|
238
249
|
accounts: {
|
|
239
250
|
user: userAccountPublicKey,
|
|
@@ -277,7 +288,7 @@ class ClearingHouse {
|
|
|
277
288
|
if (this.userOrdersAccountPublicKey) {
|
|
278
289
|
return this.userOrdersAccountPublicKey;
|
|
279
290
|
}
|
|
280
|
-
this.userOrdersAccountPublicKey = yield addresses_1.getUserOrdersAccountPublicKey(this.program.programId, this.
|
|
291
|
+
this.userOrdersAccountPublicKey = yield addresses_1.getUserOrdersAccountPublicKey(this.program.programId, yield this.getUserAccountPublicKey());
|
|
281
292
|
return this.userOrdersAccountPublicKey;
|
|
282
293
|
});
|
|
283
294
|
}
|
|
@@ -517,6 +528,33 @@ class ClearingHouse {
|
|
|
517
528
|
});
|
|
518
529
|
});
|
|
519
530
|
}
|
|
531
|
+
cancelOrderByUserId(userOrderId) {
|
|
532
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
533
|
+
return yield this.txSender.send(utils_1.wrapInTx(yield this.getCancelOrderByUserIdIx(userOrderId)), [], this.opts);
|
|
534
|
+
});
|
|
535
|
+
}
|
|
536
|
+
getCancelOrderByUserIdIx(userOrderId) {
|
|
537
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
538
|
+
const userAccountPublicKey = yield this.getUserAccountPublicKey();
|
|
539
|
+
const userAccount = yield this.getUserAccount();
|
|
540
|
+
const state = this.getStateAccount();
|
|
541
|
+
const orderState = this.getOrderStateAccount();
|
|
542
|
+
return yield this.program.instruction.cancelOrderByUserId(userOrderId, {
|
|
543
|
+
accounts: {
|
|
544
|
+
state: yield this.getStatePublicKey(),
|
|
545
|
+
user: userAccountPublicKey,
|
|
546
|
+
authority: this.wallet.publicKey,
|
|
547
|
+
markets: state.markets,
|
|
548
|
+
userOrders: yield this.getUserOrdersAccountPublicKey(),
|
|
549
|
+
userPositions: userAccount.positions,
|
|
550
|
+
fundingPaymentHistory: state.fundingPaymentHistory,
|
|
551
|
+
fundingRateHistory: state.fundingRateHistory,
|
|
552
|
+
orderState: yield this.getOrderStatePublicKey(),
|
|
553
|
+
orderHistory: orderState.orderHistory,
|
|
554
|
+
},
|
|
555
|
+
});
|
|
556
|
+
});
|
|
557
|
+
}
|
|
520
558
|
fillOrder(userAccountPublicKey, userOrdersAccountPublicKey, order) {
|
|
521
559
|
return __awaiter(this, void 0, void 0, function* () {
|
|
522
560
|
return yield this.txSender.send(utils_1.wrapInTx(yield this.getFillOrderIx(userAccountPublicKey, userOrdersAccountPublicKey, order)), [], this.opts);
|
|
@@ -553,6 +591,7 @@ class ClearingHouse {
|
|
|
553
591
|
fundingRateHistory: state.fundingRateHistory,
|
|
554
592
|
orderState: yield this.getOrderStatePublicKey(),
|
|
555
593
|
orderHistory: orderState.orderHistory,
|
|
594
|
+
extendedCurveHistory: state.extendedCurveHistory,
|
|
556
595
|
oracle: oracle,
|
|
557
596
|
},
|
|
558
597
|
remainingAccounts,
|
|
@@ -606,6 +645,7 @@ class ClearingHouse {
|
|
|
606
645
|
fundingRateHistory: state.fundingRateHistory,
|
|
607
646
|
orderState: yield this.getOrderStatePublicKey(),
|
|
608
647
|
orderHistory: orderState.orderHistory,
|
|
648
|
+
extendedCurveHistory: state.extendedCurveHistory,
|
|
609
649
|
oracle: priceOracle,
|
|
610
650
|
},
|
|
611
651
|
remainingAccounts,
|
|
@@ -13,8 +13,16 @@ export declare class ClearingHouseUser {
|
|
|
13
13
|
accountSubscriber: UserAccountSubscriber;
|
|
14
14
|
userAccountPublicKey?: PublicKey;
|
|
15
15
|
userOrdersAccountPublicKey?: PublicKey;
|
|
16
|
-
|
|
16
|
+
_isSubscribed: boolean;
|
|
17
17
|
eventEmitter: StrictEventEmitter<EventEmitter, UserAccountEvents>;
|
|
18
|
+
get isSubscribed(): boolean;
|
|
19
|
+
set isSubscribed(val: boolean);
|
|
20
|
+
/**
|
|
21
|
+
* @deprecated You should use getClearingHouseUser factory method instead
|
|
22
|
+
* @param clearingHouse
|
|
23
|
+
* @param authority
|
|
24
|
+
* @returns
|
|
25
|
+
*/
|
|
18
26
|
static from(clearingHouse: ClearingHouse, authority: PublicKey): ClearingHouseUser;
|
|
19
27
|
constructor(clearingHouse: ClearingHouse, authority: PublicKey, accountSubscriber: UserAccountSubscriber);
|
|
20
28
|
/**
|
package/lib/clearingHouseUser.js
CHANGED
|
@@ -16,20 +16,34 @@ exports.ClearingHouseUser = void 0;
|
|
|
16
16
|
const bn_js_1 = __importDefault(require("bn.js"));
|
|
17
17
|
const position_1 = require("./math/position");
|
|
18
18
|
const numericConstants_1 = require("./constants/numericConstants");
|
|
19
|
-
const defaultUserAccountSubscriber_1 = require("./accounts/defaultUserAccountSubscriber");
|
|
20
19
|
const _1 = require(".");
|
|
21
20
|
const addresses_1 = require("./addresses");
|
|
21
|
+
const clearingHouseUser_1 = require("./factory/clearingHouseUser");
|
|
22
22
|
class ClearingHouseUser {
|
|
23
23
|
constructor(clearingHouse, authority, accountSubscriber) {
|
|
24
|
-
this.
|
|
24
|
+
this._isSubscribed = false;
|
|
25
25
|
this.clearingHouse = clearingHouse;
|
|
26
26
|
this.authority = authority;
|
|
27
27
|
this.accountSubscriber = accountSubscriber;
|
|
28
28
|
this.eventEmitter = this.accountSubscriber.eventEmitter;
|
|
29
29
|
}
|
|
30
|
+
get isSubscribed() {
|
|
31
|
+
return this._isSubscribed && this.accountSubscriber.isSubscribed;
|
|
32
|
+
}
|
|
33
|
+
set isSubscribed(val) {
|
|
34
|
+
this._isSubscribed = val;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* @deprecated You should use getClearingHouseUser factory method instead
|
|
38
|
+
* @param clearingHouse
|
|
39
|
+
* @param authority
|
|
40
|
+
* @returns
|
|
41
|
+
*/
|
|
30
42
|
static from(clearingHouse, authority) {
|
|
31
|
-
|
|
32
|
-
|
|
43
|
+
if (clearingHouse.accountSubscriber.type !== 'websocket')
|
|
44
|
+
throw 'This method only works for clearing houses with a websocket account listener. Try using the getClearingHouseUser factory method to initialize a ClearingHouseUser instead';
|
|
45
|
+
const config = clearingHouseUser_1.getWebSocketClearingHouseUserConfig(clearingHouse, authority);
|
|
46
|
+
return clearingHouseUser_1.getClearingHouseUser(config);
|
|
33
47
|
}
|
|
34
48
|
/**
|
|
35
49
|
* Subscribe to ClearingHouseUser state accounts
|
|
@@ -104,7 +118,7 @@ class ClearingHouseUser {
|
|
|
104
118
|
if (this.userOrdersAccountPublicKey) {
|
|
105
119
|
return this.userOrdersAccountPublicKey;
|
|
106
120
|
}
|
|
107
|
-
this.userOrdersAccountPublicKey = yield _1.getUserOrdersAccountPublicKey(this.clearingHouse.program.programId, this.
|
|
121
|
+
this.userOrdersAccountPublicKey = yield _1.getUserOrdersAccountPublicKey(this.clearingHouse.program.programId, yield this.getUserAccountPublicKey());
|
|
108
122
|
return this.userOrdersAccountPublicKey;
|
|
109
123
|
});
|
|
110
124
|
}
|
package/lib/config.js
CHANGED
|
@@ -5,7 +5,7 @@ exports.configs = {
|
|
|
5
5
|
devnet: {
|
|
6
6
|
ENV: 'devnet',
|
|
7
7
|
PYTH_ORACLE_MAPPING_ADDRESS: 'BmA9Z6FjioHJPpjT39QazZyhDRUdZy2ezwx4GiDdE2u2',
|
|
8
|
-
CLEARING_HOUSE_PROGRAM_ID: '
|
|
8
|
+
CLEARING_HOUSE_PROGRAM_ID: '8mKouB1uzsoMAhAu4qAXCiu8KAfwH7nonpuYfTM21Xg2',
|
|
9
9
|
USDC_MINT_ADDRESS: '8zGuJQqwhZafTah7Uc7Z4tXRnguqkn5KLFAP8oV6PHe2',
|
|
10
10
|
},
|
|
11
11
|
'mainnet-beta': {
|
package/lib/constants/markets.js
CHANGED
|
@@ -86,4 +86,20 @@ exports.Markets = [
|
|
|
86
86
|
mainnetPythOracle: '3pyn4svBbxJ9Wnn3RVeafyLWfzie6yC5eTig2S62v9SC',
|
|
87
87
|
launchTs: 1643084413000,
|
|
88
88
|
},
|
|
89
|
+
{
|
|
90
|
+
symbol: 'ALGO-PERP',
|
|
91
|
+
baseAssetSymbol: 'ALGO',
|
|
92
|
+
marketIndex: new bn_js_1.default(10),
|
|
93
|
+
devnetPythOracle: 'c1A946dY5NHuVda77C8XXtXytyR3wK1SCP3eA9VRfC3',
|
|
94
|
+
mainnetPythOracle: 'HqFyq1wh1xKvL7KDqqT7NJeSPdAqsDqnmBisUC2XdXAX',
|
|
95
|
+
launchTs: 1643686767000,
|
|
96
|
+
},
|
|
97
|
+
// {
|
|
98
|
+
// symbol: 'mSOL-PERP',
|
|
99
|
+
// baseAssetSymbol: 'mSOL',
|
|
100
|
+
// marketIndex: new BN(11), //todo
|
|
101
|
+
// devnetPythOracle: '9a6RNx3tCu1TSs6TBSfV2XRXEPEZXQ6WB7jRojZRvyeZ',
|
|
102
|
+
// mainnetPythOracle: 'E4v1BBgoso9s64TQvmyownAVJbhbEPGyzA3qn4n46qj9',
|
|
103
|
+
// launchTs: 1643346125000,
|
|
104
|
+
// },
|
|
89
105
|
];
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ConfirmOptions, Connection, PublicKey } from '@solana/web3.js';
|
|
2
|
+
import { IWallet } from '../types';
|
|
3
|
+
import { BulkAccountLoader } from '../accounts/bulkAccountLoader';
|
|
4
|
+
import { TxSender } from '../tx/types';
|
|
5
|
+
import { ClearingHouse } from '../clearingHouse';
|
|
6
|
+
import { Admin } from '../admin';
|
|
7
|
+
export declare type ClearingHouseConfigType = 'websocket' | 'polling' | 'custom';
|
|
8
|
+
declare type BaseClearingHouseConfig = {
|
|
9
|
+
type: ClearingHouseConfigType;
|
|
10
|
+
connection: Connection;
|
|
11
|
+
wallet: IWallet;
|
|
12
|
+
programID: PublicKey;
|
|
13
|
+
opts?: ConfirmOptions;
|
|
14
|
+
txSender?: TxSender;
|
|
15
|
+
};
|
|
16
|
+
declare type WebSocketClearingHouseConfiguration = BaseClearingHouseConfig;
|
|
17
|
+
declare type PollingClearingHouseConfiguration = BaseClearingHouseConfig & {
|
|
18
|
+
accountLoader: BulkAccountLoader;
|
|
19
|
+
};
|
|
20
|
+
declare type ClearingHouseConfig = PollingClearingHouseConfiguration | WebSocketClearingHouseConfiguration;
|
|
21
|
+
export declare function getWebSocketClearingHouseConfig(connection: Connection, wallet: IWallet, programID: PublicKey, opts?: ConfirmOptions, txSender?: TxSender): WebSocketClearingHouseConfiguration;
|
|
22
|
+
export declare function getPollingClearingHouseConfig(connection: Connection, wallet: IWallet, programID: PublicKey, accountLoader: BulkAccountLoader, opts?: ConfirmOptions, txSender?: TxSender): PollingClearingHouseConfiguration;
|
|
23
|
+
export declare function getClearingHouse(config: ClearingHouseConfig): ClearingHouse;
|
|
24
|
+
export declare function getAdmin(config: ClearingHouseConfig): Admin;
|
|
25
|
+
export {};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getAdmin = exports.getClearingHouse = exports.getPollingClearingHouseConfig = exports.getWebSocketClearingHouseConfig = void 0;
|
|
7
|
+
const anchor_1 = require("@project-serum/anchor");
|
|
8
|
+
const clearingHouse_1 = require("../clearingHouse");
|
|
9
|
+
const clearing_house_json_1 = __importDefault(require("../idl/clearing_house.json"));
|
|
10
|
+
const webSocketClearingHouseAccountSubscriber_1 = require("../accounts/webSocketClearingHouseAccountSubscriber");
|
|
11
|
+
const defaultTxSender_1 = require("../tx/defaultTxSender");
|
|
12
|
+
const pollingClearingHouseAccountSubscriber_1 = require("../accounts/pollingClearingHouseAccountSubscriber");
|
|
13
|
+
const admin_1 = require("../admin");
|
|
14
|
+
function getWebSocketClearingHouseConfig(connection, wallet, programID, opts = anchor_1.Provider.defaultOptions(), txSender) {
|
|
15
|
+
return {
|
|
16
|
+
type: 'websocket',
|
|
17
|
+
connection,
|
|
18
|
+
wallet,
|
|
19
|
+
programID,
|
|
20
|
+
opts,
|
|
21
|
+
txSender,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
exports.getWebSocketClearingHouseConfig = getWebSocketClearingHouseConfig;
|
|
25
|
+
function getPollingClearingHouseConfig(connection, wallet, programID, accountLoader, opts = anchor_1.Provider.defaultOptions(), txSender) {
|
|
26
|
+
return {
|
|
27
|
+
type: 'polling',
|
|
28
|
+
connection,
|
|
29
|
+
wallet,
|
|
30
|
+
programID,
|
|
31
|
+
accountLoader,
|
|
32
|
+
opts,
|
|
33
|
+
txSender,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
exports.getPollingClearingHouseConfig = getPollingClearingHouseConfig;
|
|
37
|
+
function getClearingHouse(config) {
|
|
38
|
+
const provider = new anchor_1.Provider(config.connection, config.wallet, config.opts);
|
|
39
|
+
const program = new anchor_1.Program(clearing_house_json_1.default, config.programID, provider);
|
|
40
|
+
let accountSubscriber;
|
|
41
|
+
if (config.type === 'websocket') {
|
|
42
|
+
accountSubscriber = new webSocketClearingHouseAccountSubscriber_1.WebSocketClearingHouseAccountSubscriber(program);
|
|
43
|
+
}
|
|
44
|
+
else if (config.type === 'polling') {
|
|
45
|
+
accountSubscriber = new pollingClearingHouseAccountSubscriber_1.PollingClearingHouseAccountSubscriber(program, config.accountLoader);
|
|
46
|
+
}
|
|
47
|
+
const txSender = config.txSender || new defaultTxSender_1.DefaultTxSender(provider);
|
|
48
|
+
return new clearingHouse_1.ClearingHouse(config.connection, config.wallet, program, accountSubscriber, txSender, config.opts);
|
|
49
|
+
}
|
|
50
|
+
exports.getClearingHouse = getClearingHouse;
|
|
51
|
+
function getAdmin(config) {
|
|
52
|
+
const provider = new anchor_1.Provider(config.connection, config.wallet, config.opts);
|
|
53
|
+
const program = new anchor_1.Program(clearing_house_json_1.default, config.programID, provider);
|
|
54
|
+
let accountSubscriber;
|
|
55
|
+
if (config.type === 'websocket') {
|
|
56
|
+
accountSubscriber = new webSocketClearingHouseAccountSubscriber_1.WebSocketClearingHouseAccountSubscriber(program);
|
|
57
|
+
}
|
|
58
|
+
else if (config.type === 'polling') {
|
|
59
|
+
accountSubscriber = new pollingClearingHouseAccountSubscriber_1.PollingClearingHouseAccountSubscriber(program, config.accountLoader);
|
|
60
|
+
}
|
|
61
|
+
const txSender = config.txSender || new defaultTxSender_1.DefaultTxSender(provider);
|
|
62
|
+
return new admin_1.Admin(config.connection, config.wallet, program, accountSubscriber, txSender, config.opts);
|
|
63
|
+
}
|
|
64
|
+
exports.getAdmin = getAdmin;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { PublicKey } from '@solana/web3.js';
|
|
2
|
+
import { ClearingHouse } from '../clearingHouse';
|
|
3
|
+
import { BulkAccountLoader } from '../accounts/bulkAccountLoader';
|
|
4
|
+
import { ClearingHouseUser } from '../clearingHouseUser';
|
|
5
|
+
export declare type ClearingHouseUserConfigType = 'websocket' | 'polling' | 'custom';
|
|
6
|
+
declare type BaseClearingHouseUserConfig = {
|
|
7
|
+
type: ClearingHouseUserConfigType;
|
|
8
|
+
clearingHouse: ClearingHouse;
|
|
9
|
+
authority: PublicKey;
|
|
10
|
+
};
|
|
11
|
+
declare type WebSocketClearingHouseUserConfig = BaseClearingHouseUserConfig;
|
|
12
|
+
declare type PollingClearingHouseUserConfig = BaseClearingHouseUserConfig & {
|
|
13
|
+
accountLoader: BulkAccountLoader;
|
|
14
|
+
};
|
|
15
|
+
declare type ClearingHouseUserConfig = PollingClearingHouseUserConfig | WebSocketClearingHouseUserConfig;
|
|
16
|
+
export declare function getWebSocketClearingHouseUserConfig(clearingHouse: ClearingHouse, authority: PublicKey): WebSocketClearingHouseUserConfig;
|
|
17
|
+
export declare function getPollingClearingHouseUserConfig(clearingHouse: ClearingHouse, authority: PublicKey, accountLoader: BulkAccountLoader): PollingClearingHouseUserConfig;
|
|
18
|
+
export declare function getClearingHouseUser(config: ClearingHouseUserConfig): ClearingHouseUser;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getClearingHouseUser = exports.getPollingClearingHouseUserConfig = exports.getWebSocketClearingHouseUserConfig = void 0;
|
|
4
|
+
const clearingHouseUser_1 = require("../clearingHouseUser");
|
|
5
|
+
const webSocketUserAccountSubscriber_1 = require("../accounts/webSocketUserAccountSubscriber");
|
|
6
|
+
const pollingUserAccountSubscriber_1 = require("../accounts/pollingUserAccountSubscriber");
|
|
7
|
+
function getWebSocketClearingHouseUserConfig(clearingHouse, authority) {
|
|
8
|
+
return {
|
|
9
|
+
type: 'websocket',
|
|
10
|
+
clearingHouse,
|
|
11
|
+
authority,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
exports.getWebSocketClearingHouseUserConfig = getWebSocketClearingHouseUserConfig;
|
|
15
|
+
function getPollingClearingHouseUserConfig(clearingHouse, authority, accountLoader) {
|
|
16
|
+
return {
|
|
17
|
+
type: 'polling',
|
|
18
|
+
clearingHouse,
|
|
19
|
+
authority,
|
|
20
|
+
accountLoader,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
exports.getPollingClearingHouseUserConfig = getPollingClearingHouseUserConfig;
|
|
24
|
+
function getClearingHouseUser(config) {
|
|
25
|
+
let accountSubscriber;
|
|
26
|
+
if (config.type === 'websocket') {
|
|
27
|
+
accountSubscriber = new webSocketUserAccountSubscriber_1.WebSocketUserAccountSubscriber(config.clearingHouse.program, config.authority);
|
|
28
|
+
}
|
|
29
|
+
else if (config.type === 'polling') {
|
|
30
|
+
accountSubscriber = new pollingUserAccountSubscriber_1.PollingUserAccountSubscriber(config.clearingHouse.program, config.authority, config.accountLoader);
|
|
31
|
+
}
|
|
32
|
+
return new clearingHouseUser_1.ClearingHouseUser(config.clearingHouse, config.authority, accountSubscriber);
|
|
33
|
+
}
|
|
34
|
+
exports.getClearingHouseUser = getClearingHouseUser;
|