@drift-labs/sdk 0.1.17 → 0.1.18-orders.0
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/defaultClearingHouseAccountSubscriber.d.ts +5 -2
- package/lib/accounts/defaultClearingHouseAccountSubscriber.js +25 -0
- package/lib/accounts/defaultHistoryAccountSubscriber.d.ts +28 -0
- package/lib/accounts/defaultHistoryAccountSubscriber.js +110 -0
- package/lib/accounts/defaultUserAccountSubscriber.d.ts +3 -2
- package/lib/accounts/defaultUserAccountSubscriber.js +11 -0
- package/lib/accounts/types.d.ts +29 -3
- package/lib/accounts/webSocketAccountSubscriber.d.ts +0 -1
- package/lib/addresses.d.ts +4 -1
- package/lib/addresses.js +28 -1
- package/lib/admin.d.ts +10 -4
- package/lib/admin.js +48 -3
- package/lib/assert/assert.d.ts +0 -1
- package/lib/clearingHouse.d.ts +21 -2
- package/lib/clearingHouse.js +238 -7
- package/lib/clearingHouseUser.d.ts +10 -17
- package/lib/clearingHouseUser.js +98 -84
- package/lib/config.d.ts +0 -1
- package/lib/config.js +1 -1
- package/lib/constants/markets.d.ts +0 -1
- package/lib/constants/numericConstants.d.ts +0 -1
- package/lib/examples/makeTradeExample.d.ts +0 -1
- package/lib/idl/clearing_house.json +956 -59
- package/lib/index.d.ts +3 -1
- package/lib/index.js +3 -0
- package/lib/math/amm.d.ts +1 -1
- package/lib/math/amm.js +31 -8
- package/lib/math/conversion.d.ts +0 -1
- package/lib/math/funding.d.ts +0 -1
- package/lib/math/insuranceFund.d.ts +0 -1
- package/lib/math/market.d.ts +2 -2
- package/lib/math/market.js +11 -1
- package/lib/math/orders.d.ts +3 -0
- package/lib/math/orders.js +30 -0
- package/lib/math/position.d.ts +4 -2
- package/lib/math/position.js +18 -4
- package/lib/math/trade.d.ts +0 -1
- package/lib/math/utils.d.ts +0 -1
- package/lib/mockUSDCFaucet.d.ts +0 -1
- package/lib/orderParams.d.ts +7 -0
- package/lib/orderParams.js +88 -0
- package/lib/orders.d.ts +5 -0
- package/lib/orders.js +136 -0
- package/lib/pythClient.d.ts +0 -1
- 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 +137 -2
- 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 +1 -1
- package/src/accounts/defaultClearingHouseAccountSubscriber.ts +47 -0
- package/src/accounts/defaultHistoryAccountSubscriber.ts +176 -0
- package/src/accounts/defaultUserAccountSubscriber.ts +29 -2
- package/src/accounts/types.ts +38 -1
- package/src/addresses.ts +35 -0
- package/src/admin.ts +84 -6
- package/src/clearingHouse.ts +338 -5
- package/src/clearingHouseUser.ts +154 -102
- package/src/config.ts +1 -1
- package/src/idl/clearing_house.json +956 -59
- package/src/index.ts +3 -0
- package/src/math/amm.ts +47 -14
- package/src/math/market.ts +28 -2
- package/src/math/orders.ts +39 -0
- package/src/math/position.ts +23 -3
- package/src/orderParams.ts +128 -0
- package/src/orders.ts +230 -0
- package/src/types.ts +121 -1
- 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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { ClearingHouseAccountSubscriber, ClearingHouseAccountEvents, ClearingHouseAccountTypes } from './types';
|
|
3
3
|
import { AccountSubscriber } from './types';
|
|
4
|
-
import { CurveHistoryAccount, DepositHistoryAccount, FundingPaymentHistoryAccount, FundingRateHistoryAccount, LiquidationHistoryAccount, MarketsAccount, StateAccount, TradeHistoryAccount } from '../types';
|
|
4
|
+
import { CurveHistoryAccount, DepositHistoryAccount, FundingPaymentHistoryAccount, FundingRateHistoryAccount, LiquidationHistoryAccount, MarketsAccount, OrderHistoryAccount, OrderStateAccount, StateAccount, TradeHistoryAccount } from '../types';
|
|
5
5
|
import { Program } from '@project-serum/anchor';
|
|
6
6
|
import StrictEventEmitter from 'strict-event-emitter-types';
|
|
7
7
|
import { EventEmitter } from 'events';
|
|
@@ -17,6 +17,8 @@ export declare class DefaultClearingHouseAccountSubscriber implements ClearingHo
|
|
|
17
17
|
fundingRateHistoryAccountSubscriber?: AccountSubscriber<FundingRateHistoryAccount>;
|
|
18
18
|
curveHistoryAccountSubscriber?: AccountSubscriber<CurveHistoryAccount>;
|
|
19
19
|
liquidationHistoryAccountSubscriber?: AccountSubscriber<LiquidationHistoryAccount>;
|
|
20
|
+
orderStateAccountSubscriber?: AccountSubscriber<OrderStateAccount>;
|
|
21
|
+
orderHistoryAccountSubscriber?: AccountSubscriber<OrderHistoryAccount>;
|
|
20
22
|
optionalExtraSubscriptions: ClearingHouseAccountTypes[];
|
|
21
23
|
private isSubscribing;
|
|
22
24
|
private subscriptionPromise;
|
|
@@ -35,5 +37,6 @@ export declare class DefaultClearingHouseAccountSubscriber implements ClearingHo
|
|
|
35
37
|
getFundingRateHistoryAccount(): FundingRateHistoryAccount;
|
|
36
38
|
getCurveHistoryAccount(): CurveHistoryAccount;
|
|
37
39
|
getLiquidationHistoryAccount(): LiquidationHistoryAccount;
|
|
40
|
+
getOrderHistoryAccount(): OrderHistoryAccount;
|
|
41
|
+
getOrderStateAccount(): OrderStateAccount;
|
|
38
42
|
}
|
|
39
|
-
//# sourceMappingURL=defaultClearingHouseAccountSubscriber.d.ts.map
|
|
@@ -47,6 +47,12 @@ class DefaultClearingHouseAccountSubscriber {
|
|
|
47
47
|
this.eventEmitter.emit('marketsAccountUpdate', data);
|
|
48
48
|
this.eventEmitter.emit('update');
|
|
49
49
|
});
|
|
50
|
+
this.orderStateAccountSubscriber = new webSocketAccountSubscriber_1.WebSocketAccountSubscriber('orderState', this.program, state.orderState);
|
|
51
|
+
yield this.orderStateAccountSubscriber.subscribe((data) => {
|
|
52
|
+
this.eventEmitter.emit('orderStateAccountUpdate', data);
|
|
53
|
+
this.eventEmitter.emit('update');
|
|
54
|
+
});
|
|
55
|
+
const orderState = this.orderStateAccountSubscriber.data;
|
|
50
56
|
// create subscribers for other state accounts
|
|
51
57
|
this.tradeHistoryAccountSubscriber = new webSocketAccountSubscriber_1.WebSocketAccountSubscriber('tradeHistory', this.program, state.tradeHistory);
|
|
52
58
|
this.depositHistoryAccountSubscriber = new webSocketAccountSubscriber_1.WebSocketAccountSubscriber('depositHistory', this.program, state.depositHistory);
|
|
@@ -55,6 +61,7 @@ class DefaultClearingHouseAccountSubscriber {
|
|
|
55
61
|
this.fundingRateHistoryAccountSubscriber = new webSocketAccountSubscriber_1.WebSocketAccountSubscriber('fundingRateHistory', this.program, state.fundingRateHistory);
|
|
56
62
|
this.liquidationHistoryAccountSubscriber = new webSocketAccountSubscriber_1.WebSocketAccountSubscriber('liquidationHistory', this.program, state.liquidationHistory);
|
|
57
63
|
this.curveHistoryAccountSubscriber = new webSocketAccountSubscriber_1.WebSocketAccountSubscriber('curveHistory', this.program, state.curveHistory);
|
|
64
|
+
this.orderHistoryAccountSubscriber = new webSocketAccountSubscriber_1.WebSocketAccountSubscriber('orderHistory', this.program, orderState.orderHistory);
|
|
58
65
|
const extraSusbcribersToUse = [];
|
|
59
66
|
if (optionalSubscriptions === null || optionalSubscriptions === void 0 ? void 0 : optionalSubscriptions.includes('tradeHistoryAccount'))
|
|
60
67
|
extraSusbcribersToUse.push({
|
|
@@ -86,6 +93,11 @@ class DefaultClearingHouseAccountSubscriber {
|
|
|
86
93
|
subscriber: this.curveHistoryAccountSubscriber,
|
|
87
94
|
eventType: 'curveHistoryAccountUpdate',
|
|
88
95
|
});
|
|
96
|
+
if (optionalSubscriptions === null || optionalSubscriptions === void 0 ? void 0 : optionalSubscriptions.includes('orderHistoryAccount'))
|
|
97
|
+
extraSusbcribersToUse.push({
|
|
98
|
+
subscriber: this.orderHistoryAccountSubscriber,
|
|
99
|
+
eventType: 'orderHistoryAccountUpdate',
|
|
100
|
+
});
|
|
89
101
|
this.optionalExtraSubscriptions = optionalSubscriptions !== null && optionalSubscriptions !== void 0 ? optionalSubscriptions : [];
|
|
90
102
|
// await all subcriptions in parallel to boost performance
|
|
91
103
|
//// the state account subscription above can't happen in here, because some of these susbcriptions are dependent on clearing house state being available
|
|
@@ -124,6 +136,7 @@ class DefaultClearingHouseAccountSubscriber {
|
|
|
124
136
|
}
|
|
125
137
|
yield this.stateAccountSubscriber.unsubscribe();
|
|
126
138
|
yield this.marketsAccountSubscriber.unsubscribe();
|
|
139
|
+
yield this.orderStateAccountSubscriber.unsubscribe();
|
|
127
140
|
if (this.optionalExtraSubscriptions.includes('tradeHistoryAccount')) {
|
|
128
141
|
yield this.tradeHistoryAccountSubscriber.unsubscribe();
|
|
129
142
|
}
|
|
@@ -142,6 +155,9 @@ class DefaultClearingHouseAccountSubscriber {
|
|
|
142
155
|
if (this.optionalExtraSubscriptions.includes('liquidationHistoryAccount')) {
|
|
143
156
|
yield this.liquidationHistoryAccountSubscriber.unsubscribe();
|
|
144
157
|
}
|
|
158
|
+
if (this.optionalExtraSubscriptions.includes('orderHistoryAccount')) {
|
|
159
|
+
yield this.orderHistoryAccountSubscriber.unsubscribe();
|
|
160
|
+
}
|
|
145
161
|
this.isSubscribed = false;
|
|
146
162
|
});
|
|
147
163
|
}
|
|
@@ -196,5 +212,14 @@ class DefaultClearingHouseAccountSubscriber {
|
|
|
196
212
|
this.assertOptionalIsSubscribed('liquidationHistoryAccount');
|
|
197
213
|
return this.liquidationHistoryAccountSubscriber.data;
|
|
198
214
|
}
|
|
215
|
+
getOrderHistoryAccount() {
|
|
216
|
+
this.assertIsSubscribed();
|
|
217
|
+
this.assertOptionalIsSubscribed('orderHistoryAccount');
|
|
218
|
+
return this.orderHistoryAccountSubscriber.data;
|
|
219
|
+
}
|
|
220
|
+
getOrderStateAccount() {
|
|
221
|
+
this.assertIsSubscribed();
|
|
222
|
+
return this.orderStateAccountSubscriber.data;
|
|
223
|
+
}
|
|
199
224
|
}
|
|
200
225
|
exports.DefaultClearingHouseAccountSubscriber = DefaultClearingHouseAccountSubscriber;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { ClearingHouseAccountEvents, HistoryAccountSubscriber } from './types';
|
|
3
|
+
import { AccountSubscriber } from './types';
|
|
4
|
+
import { CurveHistoryAccount, DepositHistoryAccount, FundingPaymentHistoryAccount, FundingRateHistoryAccount, LiquidationHistoryAccount, TradeHistoryAccount } from '../types';
|
|
5
|
+
import { Program } from '@project-serum/anchor';
|
|
6
|
+
import StrictEventEmitter from 'strict-event-emitter-types';
|
|
7
|
+
import { EventEmitter } from 'events';
|
|
8
|
+
export declare class DefaultHistoryAccountSubscriber implements HistoryAccountSubscriber {
|
|
9
|
+
isSubscribed: boolean;
|
|
10
|
+
program: Program;
|
|
11
|
+
eventEmitter: StrictEventEmitter<EventEmitter, ClearingHouseAccountEvents>;
|
|
12
|
+
tradeHistoryAccountSubscriber?: AccountSubscriber<TradeHistoryAccount>;
|
|
13
|
+
depositHistoryAccountSubscriber?: AccountSubscriber<DepositHistoryAccount>;
|
|
14
|
+
fundingPaymentHistoryAccountSubscriber?: AccountSubscriber<FundingPaymentHistoryAccount>;
|
|
15
|
+
fundingRateHistoryAccountSubscriber?: AccountSubscriber<FundingRateHistoryAccount>;
|
|
16
|
+
curveHistoryAccountSubscriber?: AccountSubscriber<CurveHistoryAccount>;
|
|
17
|
+
liquidationHistoryAccountSubscriber?: AccountSubscriber<LiquidationHistoryAccount>;
|
|
18
|
+
constructor(program: Program);
|
|
19
|
+
subscribe(): Promise<boolean>;
|
|
20
|
+
unsubscribe(): Promise<void>;
|
|
21
|
+
assertIsSubscribed(): void;
|
|
22
|
+
getTradeHistoryAccount(): TradeHistoryAccount;
|
|
23
|
+
getDepositHistoryAccount(): DepositHistoryAccount;
|
|
24
|
+
getFundingPaymentHistoryAccount(): FundingPaymentHistoryAccount;
|
|
25
|
+
getFundingRateHistoryAccount(): FundingRateHistoryAccount;
|
|
26
|
+
getCurveHistoryAccount(): CurveHistoryAccount;
|
|
27
|
+
getLiquidationHistoryAccount(): LiquidationHistoryAccount;
|
|
28
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.DefaultHistoryAccountSubscriber = void 0;
|
|
13
|
+
const types_1 = require("./types");
|
|
14
|
+
const events_1 = require("events");
|
|
15
|
+
const addresses_1 = require("../addresses");
|
|
16
|
+
const webSocketAccountSubscriber_1 = require("./webSocketAccountSubscriber");
|
|
17
|
+
class DefaultHistoryAccountSubscriber {
|
|
18
|
+
constructor(program) {
|
|
19
|
+
this.isSubscribed = false;
|
|
20
|
+
this.program = program;
|
|
21
|
+
this.eventEmitter = new events_1.EventEmitter();
|
|
22
|
+
}
|
|
23
|
+
subscribe() {
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
if (this.isSubscribed) {
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
const statePublicKey = yield addresses_1.getClearingHouseStateAccountPublicKey(this.program.programId);
|
|
29
|
+
const state = yield this.program.account.state.fetch(statePublicKey);
|
|
30
|
+
this.tradeHistoryAccountSubscriber = new webSocketAccountSubscriber_1.WebSocketAccountSubscriber('tradeHistory', this.program, state.tradeHistory);
|
|
31
|
+
yield this.tradeHistoryAccountSubscriber.subscribe((data) => {
|
|
32
|
+
this.eventEmitter.emit('tradeHistoryAccountUpdate', data);
|
|
33
|
+
this.eventEmitter.emit('update');
|
|
34
|
+
});
|
|
35
|
+
this.depositHistoryAccountSubscriber = new webSocketAccountSubscriber_1.WebSocketAccountSubscriber('depositHistory', this.program, state.depositHistory);
|
|
36
|
+
yield this.depositHistoryAccountSubscriber.subscribe((data) => {
|
|
37
|
+
this.eventEmitter.emit('depositHistoryAccountUpdate', data);
|
|
38
|
+
this.eventEmitter.emit('update');
|
|
39
|
+
});
|
|
40
|
+
this.fundingPaymentHistoryAccountSubscriber =
|
|
41
|
+
new webSocketAccountSubscriber_1.WebSocketAccountSubscriber('fundingPaymentHistory', this.program, state.fundingPaymentHistory);
|
|
42
|
+
yield this.fundingPaymentHistoryAccountSubscriber.subscribe((data) => {
|
|
43
|
+
this.eventEmitter.emit('fundingPaymentHistoryAccountUpdate', data);
|
|
44
|
+
this.eventEmitter.emit('update');
|
|
45
|
+
});
|
|
46
|
+
this.fundingRateHistoryAccountSubscriber = new webSocketAccountSubscriber_1.WebSocketAccountSubscriber('fundingRateHistory', this.program, state.fundingRateHistory);
|
|
47
|
+
yield this.fundingRateHistoryAccountSubscriber.subscribe((data) => {
|
|
48
|
+
this.eventEmitter.emit('fundingRateHistoryAccountUpdate', data);
|
|
49
|
+
this.eventEmitter.emit('update');
|
|
50
|
+
});
|
|
51
|
+
this.liquidationHistoryAccountSubscriber = new webSocketAccountSubscriber_1.WebSocketAccountSubscriber('liquidationHistory', this.program, state.liquidationHistory);
|
|
52
|
+
yield this.liquidationHistoryAccountSubscriber.subscribe((data) => {
|
|
53
|
+
this.eventEmitter.emit('liquidationHistoryAccountUpdate', data);
|
|
54
|
+
this.eventEmitter.emit('update');
|
|
55
|
+
});
|
|
56
|
+
this.curveHistoryAccountSubscriber = new webSocketAccountSubscriber_1.WebSocketAccountSubscriber('curveHistory', this.program, state.curveHistory);
|
|
57
|
+
yield this.curveHistoryAccountSubscriber.subscribe((data) => {
|
|
58
|
+
this.eventEmitter.emit('curveHistoryAccountUpdate', data);
|
|
59
|
+
this.eventEmitter.emit('update');
|
|
60
|
+
});
|
|
61
|
+
this.eventEmitter.emit('update');
|
|
62
|
+
this.isSubscribed = true;
|
|
63
|
+
return true;
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
unsubscribe() {
|
|
67
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
68
|
+
if (!this.isSubscribed) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
yield this.tradeHistoryAccountSubscriber.unsubscribe();
|
|
72
|
+
yield this.fundingRateHistoryAccountSubscriber.unsubscribe();
|
|
73
|
+
yield this.fundingPaymentHistoryAccountSubscriber.unsubscribe();
|
|
74
|
+
yield this.depositHistoryAccountSubscriber.unsubscribe();
|
|
75
|
+
yield this.curveHistoryAccountSubscriber.unsubscribe();
|
|
76
|
+
yield this.liquidationHistoryAccountSubscriber.unsubscribe();
|
|
77
|
+
this.isSubscribed = false;
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
assertIsSubscribed() {
|
|
81
|
+
if (!this.isSubscribed) {
|
|
82
|
+
throw new types_1.NotSubscribedError('You must call `subscribe` before using this function');
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
getTradeHistoryAccount() {
|
|
86
|
+
this.assertIsSubscribed();
|
|
87
|
+
return this.tradeHistoryAccountSubscriber.data;
|
|
88
|
+
}
|
|
89
|
+
getDepositHistoryAccount() {
|
|
90
|
+
this.assertIsSubscribed();
|
|
91
|
+
return this.depositHistoryAccountSubscriber.data;
|
|
92
|
+
}
|
|
93
|
+
getFundingPaymentHistoryAccount() {
|
|
94
|
+
this.assertIsSubscribed();
|
|
95
|
+
return this.fundingPaymentHistoryAccountSubscriber.data;
|
|
96
|
+
}
|
|
97
|
+
getFundingRateHistoryAccount() {
|
|
98
|
+
this.assertIsSubscribed();
|
|
99
|
+
return this.fundingRateHistoryAccountSubscriber.data;
|
|
100
|
+
}
|
|
101
|
+
getCurveHistoryAccount() {
|
|
102
|
+
this.assertIsSubscribed();
|
|
103
|
+
return this.curveHistoryAccountSubscriber.data;
|
|
104
|
+
}
|
|
105
|
+
getLiquidationHistoryAccount() {
|
|
106
|
+
this.assertIsSubscribed();
|
|
107
|
+
return this.liquidationHistoryAccountSubscriber.data;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
exports.DefaultHistoryAccountSubscriber = DefaultHistoryAccountSubscriber;
|
|
@@ -4,7 +4,7 @@ import { Program } from '@project-serum/anchor';
|
|
|
4
4
|
import StrictEventEmitter from 'strict-event-emitter-types';
|
|
5
5
|
import { EventEmitter } from 'events';
|
|
6
6
|
import { PublicKey } from '@solana/web3.js';
|
|
7
|
-
import { UserAccount, UserPositionsAccount } from '../types';
|
|
7
|
+
import { UserAccount, UserOrdersAccount, UserPositionsAccount } from '../types';
|
|
8
8
|
export declare class DefaultUserAccountSubscriber implements UserAccountSubscriber {
|
|
9
9
|
isSubscribed: boolean;
|
|
10
10
|
program: Program;
|
|
@@ -12,6 +12,7 @@ export declare class DefaultUserAccountSubscriber implements UserAccountSubscrib
|
|
|
12
12
|
authority: PublicKey;
|
|
13
13
|
userDataAccountSubscriber: AccountSubscriber<UserAccount>;
|
|
14
14
|
userPositionsAccountSubscriber: AccountSubscriber<UserPositionsAccount>;
|
|
15
|
+
userOrdersAccountSubscriber: AccountSubscriber<UserOrdersAccount>;
|
|
15
16
|
constructor(program: Program, authority: PublicKey);
|
|
16
17
|
subscribe(): Promise<boolean>;
|
|
17
18
|
fetch(): Promise<void>;
|
|
@@ -19,5 +20,5 @@ export declare class DefaultUserAccountSubscriber implements UserAccountSubscrib
|
|
|
19
20
|
assertIsSubscribed(): void;
|
|
20
21
|
getUserAccount(): UserAccount;
|
|
21
22
|
getUserPositionsAccount(): UserPositionsAccount;
|
|
23
|
+
getUserOrdersAccount(): UserOrdersAccount;
|
|
22
24
|
}
|
|
23
|
-
//# sourceMappingURL=defaultUserAccountSubscriber.d.ts.map
|
|
@@ -38,6 +38,12 @@ class DefaultUserAccountSubscriber {
|
|
|
38
38
|
this.eventEmitter.emit('userPositionsData', data);
|
|
39
39
|
this.eventEmitter.emit('update');
|
|
40
40
|
});
|
|
41
|
+
const userOrdersPublicKey = yield addresses_1.getUserOrdersAccountPublicKey(this.program.programId, this.authority);
|
|
42
|
+
this.userOrdersAccountSubscriber = new webSocketAccountSubscriber_1.WebSocketAccountSubscriber('userOrders', this.program, userOrdersPublicKey);
|
|
43
|
+
yield this.userOrdersAccountSubscriber.subscribe((data) => {
|
|
44
|
+
this.eventEmitter.emit('userOrdersData', data);
|
|
45
|
+
this.eventEmitter.emit('update');
|
|
46
|
+
});
|
|
41
47
|
this.eventEmitter.emit('update');
|
|
42
48
|
this.isSubscribed = true;
|
|
43
49
|
return true;
|
|
@@ -48,6 +54,7 @@ class DefaultUserAccountSubscriber {
|
|
|
48
54
|
yield Promise.all([
|
|
49
55
|
this.userDataAccountSubscriber.fetch(),
|
|
50
56
|
this.userPositionsAccountSubscriber.fetch(),
|
|
57
|
+
this.userOrdersAccountSubscriber.fetch(),
|
|
51
58
|
]);
|
|
52
59
|
});
|
|
53
60
|
}
|
|
@@ -58,6 +65,7 @@ class DefaultUserAccountSubscriber {
|
|
|
58
65
|
}
|
|
59
66
|
this.userDataAccountSubscriber.unsubscribe();
|
|
60
67
|
this.userPositionsAccountSubscriber.unsubscribe();
|
|
68
|
+
this.userOrdersAccountSubscriber.unsubscribe();
|
|
61
69
|
this.isSubscribed = false;
|
|
62
70
|
});
|
|
63
71
|
}
|
|
@@ -74,5 +82,8 @@ class DefaultUserAccountSubscriber {
|
|
|
74
82
|
this.assertIsSubscribed();
|
|
75
83
|
return this.userPositionsAccountSubscriber.data;
|
|
76
84
|
}
|
|
85
|
+
getUserOrdersAccount() {
|
|
86
|
+
return this.userOrdersAccountSubscriber.data;
|
|
87
|
+
}
|
|
77
88
|
}
|
|
78
89
|
exports.DefaultUserAccountSubscriber = DefaultUserAccountSubscriber;
|
package/lib/accounts/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { CurveHistoryAccount, DepositHistoryAccount, FundingPaymentHistoryAccount, FundingRateHistoryAccount, LiquidationHistoryAccount, MarketsAccount, StateAccount, TradeHistoryAccount, UserAccount, UserPositionsAccount } from '../types';
|
|
2
|
+
import { CurveHistoryAccount, DepositHistoryAccount, FundingPaymentHistoryAccount, FundingRateHistoryAccount, LiquidationHistoryAccount, MarketsAccount, OrderHistoryAccount, OrderStateAccount, StateAccount, TradeHistoryAccount, UserAccount, UserOrdersAccount, UserPositionsAccount } from '../types';
|
|
3
3
|
import StrictEventEmitter from 'strict-event-emitter-types';
|
|
4
4
|
import { EventEmitter } from 'events';
|
|
5
5
|
export interface AccountSubscriber<T> {
|
|
@@ -20,9 +20,11 @@ export interface ClearingHouseAccountEvents {
|
|
|
20
20
|
liquidationHistoryAccountUpdate: (payload: LiquidationHistoryAccount) => void;
|
|
21
21
|
depositHistoryAccountUpdate: (payload: DepositHistoryAccount) => void;
|
|
22
22
|
curveHistoryAccountUpdate: (payload: CurveHistoryAccount) => void;
|
|
23
|
+
orderHistoryAccountUpdate: (payload: OrderHistoryAccount) => void;
|
|
24
|
+
orderStateAccountUpdate: (payload: OrderStateAccount) => void;
|
|
23
25
|
update: void;
|
|
24
26
|
}
|
|
25
|
-
export declare type ClearingHouseAccountTypes = 'tradeHistoryAccount' | 'depositHistoryAccount' | 'fundingPaymentHistoryAccount' | 'fundingRateHistoryAccount' | 'curveHistoryAccount' | 'liquidationHistoryAccount';
|
|
27
|
+
export declare type ClearingHouseAccountTypes = 'tradeHistoryAccount' | 'depositHistoryAccount' | 'fundingPaymentHistoryAccount' | 'fundingRateHistoryAccount' | 'curveHistoryAccount' | 'liquidationHistoryAccount' | 'orderHistoryAccount';
|
|
26
28
|
export interface ClearingHouseAccountSubscriber {
|
|
27
29
|
eventEmitter: StrictEventEmitter<EventEmitter, ClearingHouseAccountEvents>;
|
|
28
30
|
isSubscribed: boolean;
|
|
@@ -38,10 +40,34 @@ export interface ClearingHouseAccountSubscriber {
|
|
|
38
40
|
getFundingRateHistoryAccount(): FundingRateHistoryAccount;
|
|
39
41
|
getCurveHistoryAccount(): CurveHistoryAccount;
|
|
40
42
|
getLiquidationHistoryAccount(): LiquidationHistoryAccount;
|
|
43
|
+
getOrderStateAccount(): OrderStateAccount;
|
|
44
|
+
getOrderHistoryAccount(): OrderHistoryAccount;
|
|
45
|
+
}
|
|
46
|
+
export interface HistoryAccountEvents {
|
|
47
|
+
fundingPaymentHistoryAccountUpdate: (payload: FundingPaymentHistoryAccount) => void;
|
|
48
|
+
fundingRateHistoryAccountUpdate: (payload: FundingRateHistoryAccount) => void;
|
|
49
|
+
tradeHistoryAccountUpdate: (payload: TradeHistoryAccount) => void;
|
|
50
|
+
liquidationHistoryAccountUpdate: (payload: LiquidationHistoryAccount) => void;
|
|
51
|
+
depositHistoryAccountUpdate: (payload: DepositHistoryAccount) => void;
|
|
52
|
+
curveHistoryAccountUpdate: (payload: CurveHistoryAccount) => void;
|
|
53
|
+
update: void;
|
|
54
|
+
}
|
|
55
|
+
export interface HistoryAccountSubscriber {
|
|
56
|
+
eventEmitter: StrictEventEmitter<EventEmitter, HistoryAccountEvents>;
|
|
57
|
+
isSubscribed: boolean;
|
|
58
|
+
subscribe(): Promise<boolean>;
|
|
59
|
+
unsubscribe(): Promise<void>;
|
|
60
|
+
getTradeHistoryAccount(): TradeHistoryAccount;
|
|
61
|
+
getDepositHistoryAccount(): DepositHistoryAccount;
|
|
62
|
+
getFundingPaymentHistoryAccount(): FundingPaymentHistoryAccount;
|
|
63
|
+
getFundingRateHistoryAccount(): FundingRateHistoryAccount;
|
|
64
|
+
getCurveHistoryAccount(): CurveHistoryAccount;
|
|
65
|
+
getLiquidationHistoryAccount(): LiquidationHistoryAccount;
|
|
41
66
|
}
|
|
42
67
|
export interface UserAccountEvents {
|
|
43
68
|
userAccountData: (payload: UserAccount) => void;
|
|
44
69
|
userPositionsData: (payload: UserPositionsAccount) => void;
|
|
70
|
+
userOrdersData: (payload: UserOrdersAccount) => void;
|
|
45
71
|
update: void;
|
|
46
72
|
}
|
|
47
73
|
export interface UserAccountSubscriber {
|
|
@@ -52,5 +78,5 @@ export interface UserAccountSubscriber {
|
|
|
52
78
|
unsubscribe(): Promise<void>;
|
|
53
79
|
getUserAccount(): UserAccount;
|
|
54
80
|
getUserPositionsAccount(): UserPositionsAccount;
|
|
81
|
+
getUserOrdersAccount(): UserOrdersAccount;
|
|
55
82
|
}
|
|
56
|
-
//# sourceMappingURL=types.d.ts.map
|
package/lib/addresses.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { PublicKey } from '@solana/web3.js';
|
|
2
2
|
export declare function getClearingHouseStateAccountPublicKeyAndNonce(programId: PublicKey): Promise<[PublicKey, number]>;
|
|
3
|
+
export declare function getOrderStateAccountPublicKey(programId: PublicKey): Promise<PublicKey>;
|
|
4
|
+
export declare function getOrderStateAccountPublicKeyAndNonce(programId: PublicKey): Promise<[PublicKey, number]>;
|
|
3
5
|
export declare function getClearingHouseStateAccountPublicKey(programId: PublicKey): Promise<PublicKey>;
|
|
4
6
|
export declare function getUserAccountPublicKeyAndNonce(programId: PublicKey, authority: PublicKey): Promise<[PublicKey, number]>;
|
|
5
7
|
export declare function getUserAccountPublicKey(programId: PublicKey, authority: PublicKey): Promise<PublicKey>;
|
|
6
|
-
|
|
8
|
+
export declare function getUserOrdersAccountPublicKeyAndNonce(programId: PublicKey, authority: PublicKey): Promise<[PublicKey, number]>;
|
|
9
|
+
export declare function getUserOrdersAccountPublicKey(programId: PublicKey, authority: PublicKey): Promise<PublicKey>;
|
package/lib/addresses.js
CHANGED
|
@@ -28,7 +28,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
28
28
|
});
|
|
29
29
|
};
|
|
30
30
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
31
|
-
exports.getUserAccountPublicKey = exports.getUserAccountPublicKeyAndNonce = exports.getClearingHouseStateAccountPublicKey = exports.getClearingHouseStateAccountPublicKeyAndNonce = void 0;
|
|
31
|
+
exports.getUserOrdersAccountPublicKey = exports.getUserOrdersAccountPublicKeyAndNonce = exports.getUserAccountPublicKey = exports.getUserAccountPublicKeyAndNonce = exports.getClearingHouseStateAccountPublicKey = exports.getOrderStateAccountPublicKeyAndNonce = exports.getOrderStateAccountPublicKey = exports.getClearingHouseStateAccountPublicKeyAndNonce = void 0;
|
|
32
32
|
const anchor = __importStar(require("@project-serum/anchor"));
|
|
33
33
|
function getClearingHouseStateAccountPublicKeyAndNonce(programId) {
|
|
34
34
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -36,6 +36,18 @@ function getClearingHouseStateAccountPublicKeyAndNonce(programId) {
|
|
|
36
36
|
});
|
|
37
37
|
}
|
|
38
38
|
exports.getClearingHouseStateAccountPublicKeyAndNonce = getClearingHouseStateAccountPublicKeyAndNonce;
|
|
39
|
+
function getOrderStateAccountPublicKey(programId) {
|
|
40
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
41
|
+
return (yield getOrderStateAccountPublicKeyAndNonce(programId))[0];
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
exports.getOrderStateAccountPublicKey = getOrderStateAccountPublicKey;
|
|
45
|
+
function getOrderStateAccountPublicKeyAndNonce(programId) {
|
|
46
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
47
|
+
return anchor.web3.PublicKey.findProgramAddress([Buffer.from(anchor.utils.bytes.utf8.encode('order_state'))], programId);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
exports.getOrderStateAccountPublicKeyAndNonce = getOrderStateAccountPublicKeyAndNonce;
|
|
39
51
|
function getClearingHouseStateAccountPublicKey(programId) {
|
|
40
52
|
return __awaiter(this, void 0, void 0, function* () {
|
|
41
53
|
return (yield getClearingHouseStateAccountPublicKeyAndNonce(programId))[0];
|
|
@@ -54,3 +66,18 @@ function getUserAccountPublicKey(programId, authority) {
|
|
|
54
66
|
});
|
|
55
67
|
}
|
|
56
68
|
exports.getUserAccountPublicKey = getUserAccountPublicKey;
|
|
69
|
+
function getUserOrdersAccountPublicKeyAndNonce(programId, authority) {
|
|
70
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
71
|
+
return anchor.web3.PublicKey.findProgramAddress([
|
|
72
|
+
Buffer.from(anchor.utils.bytes.utf8.encode('user_orders')),
|
|
73
|
+
authority.toBuffer(),
|
|
74
|
+
], programId);
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
exports.getUserOrdersAccountPublicKeyAndNonce = getUserOrdersAccountPublicKeyAndNonce;
|
|
78
|
+
function getUserOrdersAccountPublicKey(programId, authority) {
|
|
79
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
80
|
+
return (yield getUserOrdersAccountPublicKeyAndNonce(programId, authority))[0];
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
exports.getUserOrdersAccountPublicKey = getUserOrdersAccountPublicKey;
|
package/lib/admin.d.ts
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
/// <reference types="bn.js" />
|
|
2
2
|
import { ConfirmOptions, Connection, PublicKey, TransactionSignature } from '@solana/web3.js';
|
|
3
|
-
import { FeeStructure, IWallet, OracleGuardRails, OracleSource } from './types';
|
|
3
|
+
import { FeeStructure, IWallet, OracleGuardRails, OracleSource, OrderFillerRewardStructure } from './types';
|
|
4
4
|
import { BN } from '@project-serum/anchor';
|
|
5
5
|
import { ClearingHouse } from './clearingHouse';
|
|
6
6
|
export declare class Admin extends ClearingHouse {
|
|
7
7
|
static from(connection: Connection, wallet: IWallet, clearingHouseProgramId: PublicKey, opts?: ConfirmOptions): Admin;
|
|
8
|
-
initialize(usdcMint: PublicKey, adminControlsPrices: boolean): Promise<[
|
|
8
|
+
initialize(usdcMint: PublicKey, adminControlsPrices: boolean): Promise<[
|
|
9
|
+
TransactionSignature,
|
|
10
|
+
TransactionSignature,
|
|
11
|
+
TransactionSignature
|
|
12
|
+
]>;
|
|
13
|
+
initializeOrderState(): Promise<TransactionSignature>;
|
|
9
14
|
initializeMarket(marketIndex: BN, priceOracle: PublicKey, baseAssetReserve: BN, quoteAssetReserve: BN, periodicity: BN, pegMultiplier?: BN): Promise<TransactionSignature>;
|
|
10
15
|
moveAmmPrice(baseAssetReserve: BN, quoteAssetReserve: BN, marketIndex: BN): Promise<TransactionSignature>;
|
|
11
16
|
updateK(sqrtK: BN, marketIndex: BN): Promise<TransactionSignature>;
|
|
@@ -21,10 +26,12 @@ export declare class Admin extends ClearingHouse {
|
|
|
21
26
|
updateFullLiquidationPenaltyPercentage(numerator: BN, denominator: BN): Promise<TransactionSignature>;
|
|
22
27
|
updatePartialLiquidationShareDenominator(denominator: BN): Promise<TransactionSignature>;
|
|
23
28
|
updateFullLiquidationShareDenominator(denominator: BN): Promise<TransactionSignature>;
|
|
29
|
+
updateOrderFillerRewardStructure(orderFillerRewardStructure: OrderFillerRewardStructure): Promise<TransactionSignature>;
|
|
24
30
|
updateFee(fees: FeeStructure): Promise<TransactionSignature>;
|
|
25
31
|
updateOracleGuardRails(oracleGuardRails: OracleGuardRails): Promise<TransactionSignature>;
|
|
26
32
|
updateMarketOracle(marketIndex: BN, oracle: PublicKey, oracleSource: OracleSource): Promise<TransactionSignature>;
|
|
27
|
-
|
|
33
|
+
updateMarketMinimumQuoteAssetTradeSize(marketIndex: BN, minimumTradeSize: BN): Promise<TransactionSignature>;
|
|
34
|
+
updateMarketMinimumBaseAssetTradeSize(marketIndex: BN, minimumTradeSize: BN): Promise<TransactionSignature>;
|
|
28
35
|
updateWhitelistMint(whitelistMint?: PublicKey): Promise<TransactionSignature>;
|
|
29
36
|
updateDiscountMint(discountMint: PublicKey): Promise<TransactionSignature>;
|
|
30
37
|
updateMaxDeposit(maxDeposit: BN): Promise<TransactionSignature>;
|
|
@@ -32,4 +39,3 @@ export declare class Admin extends ClearingHouse {
|
|
|
32
39
|
updateExchangePaused(exchangePaused: boolean): Promise<TransactionSignature>;
|
|
33
40
|
disableAdminControlsPrices(): Promise<TransactionSignature>;
|
|
34
41
|
}
|
|
35
|
-
//# sourceMappingURL=admin.d.ts.map
|
package/lib/admin.js
CHANGED
|
@@ -119,7 +119,29 @@ class Admin extends clearingHouse_1.ClearingHouse {
|
|
|
119
119
|
fundingRateHistory,
|
|
120
120
|
curveHistory,
|
|
121
121
|
], this.opts);
|
|
122
|
-
|
|
122
|
+
const initializeOrderStateTxSig = yield this.initializeOrderState();
|
|
123
|
+
return [initializeTxSig, initializeHistoryTxSig, initializeOrderStateTxSig];
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
initializeOrderState() {
|
|
127
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
128
|
+
const orderHistory = anchor.web3.Keypair.generate();
|
|
129
|
+
const [orderStatePublicKey, orderStateNonce] = yield addresses_1.getOrderStateAccountPublicKeyAndNonce(this.program.programId);
|
|
130
|
+
const clearingHouseStatePublicKey = yield addresses_1.getClearingHouseStateAccountPublicKey(this.program.programId);
|
|
131
|
+
const initializeOrderStateTx = yield this.program.transaction.initializeOrderState(orderStateNonce, {
|
|
132
|
+
accounts: {
|
|
133
|
+
admin: this.wallet.publicKey,
|
|
134
|
+
state: clearingHouseStatePublicKey,
|
|
135
|
+
orderHistory: orderHistory.publicKey,
|
|
136
|
+
orderState: orderStatePublicKey,
|
|
137
|
+
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
|
138
|
+
systemProgram: anchor.web3.SystemProgram.programId,
|
|
139
|
+
},
|
|
140
|
+
instructions: [
|
|
141
|
+
yield this.program.account.orderHistory.createInstruction(orderHistory),
|
|
142
|
+
],
|
|
143
|
+
});
|
|
144
|
+
return yield this.txSender.send(initializeOrderStateTx, [orderHistory], this.opts);
|
|
123
145
|
});
|
|
124
146
|
}
|
|
125
147
|
initializeMarket(marketIndex, priceOracle, baseAssetReserve, quoteAssetReserve, periodicity, pegMultiplier = numericConstants_1.PEG_PRECISION) {
|
|
@@ -312,6 +334,17 @@ class Admin extends clearingHouse_1.ClearingHouse {
|
|
|
312
334
|
});
|
|
313
335
|
});
|
|
314
336
|
}
|
|
337
|
+
updateOrderFillerRewardStructure(orderFillerRewardStructure) {
|
|
338
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
339
|
+
return yield this.program.rpc.updateOrderFillerRewardStructure(orderFillerRewardStructure, {
|
|
340
|
+
accounts: {
|
|
341
|
+
admin: this.wallet.publicKey,
|
|
342
|
+
state: yield this.getStatePublicKey(),
|
|
343
|
+
orderState: yield this.getOrderStatePublicKey(),
|
|
344
|
+
},
|
|
345
|
+
});
|
|
346
|
+
});
|
|
347
|
+
}
|
|
315
348
|
updateFee(fees) {
|
|
316
349
|
return __awaiter(this, void 0, void 0, function* () {
|
|
317
350
|
return yield this.program.rpc.updateFee(fees, {
|
|
@@ -344,10 +377,22 @@ class Admin extends clearingHouse_1.ClearingHouse {
|
|
|
344
377
|
});
|
|
345
378
|
});
|
|
346
379
|
}
|
|
347
|
-
|
|
380
|
+
updateMarketMinimumQuoteAssetTradeSize(marketIndex, minimumTradeSize) {
|
|
381
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
382
|
+
const state = this.getStateAccount();
|
|
383
|
+
return yield this.program.rpc.updateMarketMinimumQuoteAssetTradeSize(marketIndex, minimumTradeSize, {
|
|
384
|
+
accounts: {
|
|
385
|
+
admin: this.wallet.publicKey,
|
|
386
|
+
state: yield this.getStatePublicKey(),
|
|
387
|
+
markets: state.markets,
|
|
388
|
+
},
|
|
389
|
+
});
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
updateMarketMinimumBaseAssetTradeSize(marketIndex, minimumTradeSize) {
|
|
348
393
|
return __awaiter(this, void 0, void 0, function* () {
|
|
349
394
|
const state = this.getStateAccount();
|
|
350
|
-
return yield this.program.rpc.
|
|
395
|
+
return yield this.program.rpc.updateMarketMinimumBaseAssetTradeSize(marketIndex, minimumTradeSize, {
|
|
351
396
|
accounts: {
|
|
352
397
|
admin: this.wallet.publicKey,
|
|
353
398
|
state: yield this.getStatePublicKey(),
|
package/lib/assert/assert.d.ts
CHANGED
package/lib/clearingHouse.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="bn.js" />
|
|
3
3
|
import { BN, Program, Provider } from '@project-serum/anchor';
|
|
4
|
-
import { MarketsAccount, StateAccount, CurveHistoryAccount, DepositHistoryAccount, FundingPaymentHistoryAccount, FundingRateHistoryAccount, IWallet, LiquidationHistoryAccount, PositionDirection, TradeHistoryAccount, UserAccount, Market } from './types';
|
|
4
|
+
import { MarketsAccount, StateAccount, CurveHistoryAccount, DepositHistoryAccount, FundingPaymentHistoryAccount, FundingRateHistoryAccount, IWallet, LiquidationHistoryAccount, PositionDirection, TradeHistoryAccount, UserAccount, Market, OrderHistoryAccount, OrderStateAccount, OrderParams, Order } from './types';
|
|
5
5
|
import { Connection, PublicKey, TransactionSignature, Keypair, ConfirmOptions, TransactionInstruction } from '@solana/web3.js';
|
|
6
6
|
import { MockUSDCFaucet } from './mockUSDCFaucet';
|
|
7
7
|
import { EventEmitter } from 'events';
|
|
@@ -57,6 +57,10 @@ export declare class ClearingHouse {
|
|
|
57
57
|
getLiquidationHistoryAccount(): LiquidationHistoryAccount;
|
|
58
58
|
getDepositHistoryAccount(): DepositHistoryAccount;
|
|
59
59
|
getCurveHistoryAccount(): CurveHistoryAccount;
|
|
60
|
+
getOrderHistoryAccount(): OrderHistoryAccount;
|
|
61
|
+
orderStatePublicKey?: PublicKey;
|
|
62
|
+
getOrderStatePublicKey(): Promise<PublicKey>;
|
|
63
|
+
getOrderStateAccount(): OrderStateAccount;
|
|
60
64
|
/**
|
|
61
65
|
* Update the wallet to use for clearing house transactions and linked user account
|
|
62
66
|
* @param newWallet
|
|
@@ -69,8 +73,10 @@ export declare class ClearingHouse {
|
|
|
69
73
|
getInitializeUserInstructions(): Promise<[
|
|
70
74
|
Keypair,
|
|
71
75
|
PublicKey,
|
|
76
|
+
TransactionInstruction,
|
|
72
77
|
TransactionInstruction
|
|
73
78
|
]>;
|
|
79
|
+
getInitializeUserOrdersInstruction(userAccountPublicKey?: PublicKey): Promise<TransactionInstruction>;
|
|
74
80
|
userAccountPublicKey?: PublicKey;
|
|
75
81
|
/**
|
|
76
82
|
* Get the address for the Clearing House User's account. NOT the user's wallet address.
|
|
@@ -79,6 +85,12 @@ export declare class ClearingHouse {
|
|
|
79
85
|
getUserAccountPublicKey(): Promise<PublicKey>;
|
|
80
86
|
userAccount?: UserAccount;
|
|
81
87
|
getUserAccount(): Promise<UserAccount>;
|
|
88
|
+
userOrdersAccountPublicKey?: PublicKey;
|
|
89
|
+
/**
|
|
90
|
+
* Get the address for the Clearing House User Order's account. NOT the user's wallet address.
|
|
91
|
+
* @returns
|
|
92
|
+
*/
|
|
93
|
+
getUserOrdersAccountPublicKey(): Promise<PublicKey>;
|
|
82
94
|
depositCollateral(amount: BN, collateralAccountPublicKey: PublicKey, userPositionsAccountPublicKey?: PublicKey): Promise<TransactionSignature>;
|
|
83
95
|
getDepositCollateralInstruction(amount: BN, collateralAccountPublicKey: PublicKey, userPositionsAccountPublicKey?: PublicKey): Promise<TransactionInstruction>;
|
|
84
96
|
/**
|
|
@@ -94,6 +106,14 @@ export declare class ClearingHouse {
|
|
|
94
106
|
getWithdrawCollateralIx(amount: BN, collateralAccountPublicKey: PublicKey): Promise<TransactionInstruction>;
|
|
95
107
|
openPosition(direction: PositionDirection, amount: BN, marketIndex: BN, limitPrice?: BN, discountToken?: PublicKey, referrer?: PublicKey): Promise<TransactionSignature>;
|
|
96
108
|
getOpenPositionIx(direction: PositionDirection, amount: BN, marketIndex: BN, limitPrice?: BN, discountToken?: PublicKey, referrer?: PublicKey): Promise<TransactionInstruction>;
|
|
109
|
+
placeOrder(orderParams: OrderParams, discountToken?: PublicKey, referrer?: PublicKey): Promise<TransactionSignature>;
|
|
110
|
+
getPlaceOrderIx(orderParams: OrderParams, discountToken?: PublicKey, referrer?: PublicKey): Promise<TransactionInstruction>;
|
|
111
|
+
cancelOrder(orderId: BN): Promise<TransactionSignature>;
|
|
112
|
+
getCancelOrderIx(orderId: BN): Promise<TransactionInstruction>;
|
|
113
|
+
fillOrder(userAccountPublicKey: PublicKey, userOrdersAccountPublicKey: PublicKey, order: Order): Promise<TransactionSignature>;
|
|
114
|
+
getFillOrderIx(userAccountPublicKey: PublicKey, userOrdersAccountPublicKey: PublicKey, order: Order): Promise<TransactionInstruction>;
|
|
115
|
+
placeAndFillOrder(orderParams: OrderParams, discountToken?: PublicKey, referrer?: PublicKey): Promise<TransactionSignature>;
|
|
116
|
+
getPlaceAndFillOrderIx(orderParams: OrderParams, discountToken?: PublicKey, referrer?: PublicKey): Promise<TransactionInstruction>;
|
|
97
117
|
/**
|
|
98
118
|
* Close an entire position. If you want to reduce a position, use the {@link openPosition} method in the opposite direction of the current position.
|
|
99
119
|
* @param marketIndex
|
|
@@ -111,4 +131,3 @@ export declare class ClearingHouse {
|
|
|
111
131
|
getSettleFundingPaymentIx(userAccount: PublicKey, userPositionsAccount: PublicKey): Promise<TransactionInstruction>;
|
|
112
132
|
triggerEvent(eventName: keyof ClearingHouseAccountEvents, data?: any): void;
|
|
113
133
|
}
|
|
114
|
-
//# sourceMappingURL=clearingHouse.d.ts.map
|