@drift-labs/sdk 0.2.0-master.24 → 0.2.0-master.26
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/pollingClearingHouseAccountSubscriber.d.ts +13 -13
- package/lib/accounts/pollingClearingHouseAccountSubscriber.js +27 -27
- package/lib/accounts/types.d.ts +8 -9
- package/lib/accounts/webSocketClearingHouseAccountSubscriber.d.ts +14 -14
- package/lib/accounts/webSocketClearingHouseAccountSubscriber.js +35 -34
- package/lib/addresses/pda.d.ts +8 -6
- package/lib/addresses/pda.js +35 -27
- package/lib/admin.d.ts +9 -6
- package/lib/admin.js +90 -54
- package/lib/clearingHouse.d.ts +71 -42
- package/lib/clearingHouse.js +765 -282
- package/lib/clearingHouseConfig.d.ts +2 -2
- package/lib/clearingHouseUser.d.ts +19 -17
- package/lib/clearingHouseUser.js +145 -123
- package/lib/config.d.ts +7 -7
- package/lib/config.js +21 -21
- package/lib/constants/numericConstants.d.ts +12 -12
- package/lib/constants/numericConstants.js +13 -13
- package/lib/constants/{markets.d.ts → perpMarkets.d.ts} +5 -5
- package/{src/constants/markets.js → lib/constants/perpMarkets.js} +4 -4
- package/lib/constants/{banks.d.ts → spotMarkets.d.ts} +6 -6
- package/lib/constants/{banks.js → spotMarkets.js} +16 -16
- package/lib/events/eventSubscriber.d.ts +4 -2
- package/lib/events/eventSubscriber.js +16 -9
- package/lib/events/fetchLogs.d.ts +10 -1
- package/lib/events/fetchLogs.js +27 -7
- package/lib/events/pollingLogProvider.d.ts +2 -1
- package/lib/events/pollingLogProvider.js +6 -2
- package/lib/events/types.d.ts +4 -2
- package/lib/events/types.js +2 -0
- package/lib/examples/makeTradeExample.js +18 -6
- package/lib/idl/clearing_house.json +1128 -347
- package/lib/index.d.ts +6 -3
- package/lib/index.js +6 -3
- package/lib/math/amm.d.ts +5 -3
- package/lib/math/amm.js +42 -4
- package/lib/math/funding.d.ts +6 -6
- package/lib/math/funding.js +2 -1
- package/lib/math/margin.d.ts +4 -4
- package/lib/math/margin.js +18 -11
- package/lib/math/market.d.ts +10 -9
- package/lib/math/market.js +29 -6
- package/lib/math/oracles.d.ts +2 -1
- package/lib/math/oracles.js +11 -1
- package/lib/math/orders.d.ts +5 -5
- package/lib/math/position.d.ts +13 -13
- package/lib/math/position.js +19 -19
- package/lib/math/spotBalance.d.ts +19 -0
- package/lib/math/spotBalance.js +176 -0
- package/lib/math/spotMarket.d.ts +4 -0
- package/lib/math/spotMarket.js +8 -0
- package/lib/math/spotPosition.d.ts +2 -0
- package/lib/math/spotPosition.js +8 -0
- package/lib/math/state.js +2 -2
- package/lib/math/trade.d.ts +4 -4
- package/lib/orderParams.d.ts +4 -4
- package/lib/orderParams.js +12 -4
- package/lib/serum/serumSubscriber.d.ts +23 -0
- package/lib/serum/serumSubscriber.js +41 -0
- package/lib/serum/types.d.ts +11 -0
- package/lib/serum/types.js +2 -0
- package/lib/tx/retryTxSender.d.ts +1 -1
- package/lib/tx/retryTxSender.js +4 -2
- package/lib/tx/types.d.ts +1 -1
- package/lib/types.d.ts +148 -39
- package/lib/types.js +37 -9
- package/my-script/.env +7 -0
- package/my-script/getUserStats.ts +106 -0
- package/my-script/multiConnections.ts +119 -0
- package/my-script/test-regex.ts +11 -0
- package/my-script/utils.ts +52 -0
- package/package.json +1 -1
- package/src/accounts/bulkAccountLoader.js +249 -0
- package/src/accounts/bulkUserStatsSubscription.js +75 -0
- package/src/accounts/bulkUserSubscription.js +75 -0
- package/src/accounts/fetch.js +92 -0
- package/src/accounts/pollingClearingHouseAccountSubscriber.js +465 -0
- package/src/accounts/pollingClearingHouseAccountSubscriber.ts +38 -38
- package/src/accounts/pollingOracleSubscriber.js +156 -0
- package/src/accounts/pollingTokenAccountSubscriber.js +141 -0
- package/src/accounts/pollingUserAccountSubscriber.js +208 -0
- package/src/accounts/pollingUserStatsAccountSubscriber.js +208 -0
- package/src/accounts/types.js +28 -0
- package/src/accounts/types.ts +11 -9
- package/src/accounts/utils.js +7 -0
- package/src/accounts/webSocketAccountSubscriber.js +138 -0
- package/src/accounts/webSocketClearingHouseAccountSubscriber.js +433 -0
- package/src/accounts/webSocketClearingHouseAccountSubscriber.ts +59 -52
- package/src/accounts/webSocketUserAccountSubscriber.js +113 -0
- package/src/accounts/webSocketUserStatsAccountSubsriber.js +113 -0
- package/src/addresses/pda.js +186 -0
- package/src/addresses/pda.ts +56 -42
- package/src/admin.js +1284 -0
- package/src/admin.ts +149 -75
- package/src/assert/assert.js +1 -1
- package/src/clearingHouse.js +3433 -0
- package/src/clearingHouse.ts +1097 -380
- package/src/clearingHouseConfig.js +2 -0
- package/src/clearingHouseConfig.ts +2 -2
- package/src/clearingHouseUser.js +874 -0
- package/src/clearingHouseUser.ts +237 -172
- package/src/clearingHouseUserConfig.js +2 -0
- package/src/clearingHouseUserStats.js +115 -0
- package/src/clearingHouseUserStatsConfig.js +2 -0
- package/src/config.js +80 -0
- package/src/config.ts +30 -30
- package/src/constants/numericConstants.js +18 -11
- package/src/constants/numericConstants.ts +17 -15
- package/{lib/constants/markets.js → src/constants/perpMarkets.js} +11 -11
- package/src/constants/{markets.ts → perpMarkets.ts} +5 -5
- package/src/constants/spotMarkets.js +51 -0
- package/src/constants/{banks.ts → spotMarkets.ts} +19 -19
- package/src/events/eventList.js +66 -23
- package/src/events/eventSubscriber.js +202 -0
- package/src/events/eventSubscriber.ts +20 -12
- package/src/events/fetchLogs.js +117 -0
- package/src/events/fetchLogs.ts +35 -8
- package/src/events/pollingLogProvider.js +113 -0
- package/src/events/pollingLogProvider.ts +10 -2
- package/src/events/sort.js +41 -0
- package/src/events/txEventCache.js +22 -19
- package/src/events/types.js +25 -0
- package/src/events/types.ts +7 -1
- package/src/events/webSocketLogProvider.js +76 -0
- package/src/examples/makeTradeExample.ts +27 -6
- package/src/factory/bigNum.js +183 -180
- package/src/factory/oracleClient.js +9 -9
- package/src/idl/clearing_house.json +1128 -347
- package/src/index.js +75 -0
- package/src/index.ts +6 -3
- package/src/math/amm.js +422 -0
- package/src/math/amm.ts +73 -5
- package/src/math/auction.js +10 -10
- package/src/math/conversion.js +4 -3
- package/src/math/funding.js +223 -175
- package/src/math/funding.ts +7 -7
- package/src/math/insurance.js +27 -0
- package/src/math/margin.js +77 -0
- package/src/math/margin.ts +34 -23
- package/src/math/market.js +105 -0
- package/src/math/market.ts +71 -19
- package/src/math/oracles.js +40 -10
- package/src/math/oracles.ts +18 -1
- package/src/math/orders.js +153 -0
- package/src/math/orders.ts +5 -5
- package/src/math/position.js +172 -0
- package/src/math/position.ts +31 -31
- package/src/math/repeg.js +40 -40
- package/src/math/spotBalance.js +176 -0
- package/src/math/spotBalance.ts +290 -0
- package/src/math/spotMarket.js +8 -0
- package/src/math/spotMarket.ts +9 -0
- package/src/math/spotPosition.js +8 -0
- package/src/math/spotPosition.ts +6 -0
- package/src/math/state.ts +2 -2
- package/src/math/trade.js +81 -74
- package/src/math/trade.ts +4 -4
- package/src/math/utils.js +8 -7
- package/src/oracles/oracleClientCache.js +10 -9
- package/src/oracles/pythClient.js +52 -17
- package/src/oracles/quoteAssetOracleClient.js +44 -13
- package/src/oracles/switchboardClient.js +69 -37
- package/src/oracles/types.js +1 -1
- package/src/orderParams.js +14 -6
- package/src/orderParams.ts +16 -8
- package/src/serum/serumSubscriber.js +102 -0
- package/src/serum/serumSubscriber.ts +80 -0
- package/src/serum/types.js +2 -0
- package/src/serum/types.ts +13 -0
- package/src/slot/SlotSubscriber.js +67 -20
- package/src/token/index.js +4 -4
- package/src/tokenFaucet.js +288 -154
- package/src/tx/retryTxSender.js +280 -0
- package/src/tx/retryTxSender.ts +5 -2
- package/src/tx/types.js +1 -1
- package/src/tx/types.ts +2 -1
- package/src/tx/utils.js +7 -6
- package/src/types.js +216 -0
- package/src/types.ts +131 -39
- package/src/userName.js +5 -5
- package/src/util/computeUnits.js +46 -11
- package/src/util/promiseTimeout.js +5 -5
- package/src/util/tps.js +46 -12
- package/src/wallet.js +55 -18
- package/lib/math/bankBalance.d.ts +0 -15
- package/lib/math/bankBalance.js +0 -150
- package/src/addresses/marketAddresses.js +0 -26
- package/src/constants/banks.js +0 -42
- package/src/examples/makeTradeExample.js +0 -80
- package/src/math/bankBalance.ts +0 -258
- package/src/math/state.js +0 -15
- package/src/math/utils.js.map +0 -1
- package/src/util/getTokenAddress.js +0 -9
|
@@ -4,7 +4,7 @@ import { DataAndSlot, AccountToPoll, ClearingHouseAccountEvents, ClearingHouseAc
|
|
|
4
4
|
import { BN, Program } from '@project-serum/anchor';
|
|
5
5
|
import StrictEventEmitter from 'strict-event-emitter-types';
|
|
6
6
|
import { EventEmitter } from 'events';
|
|
7
|
-
import {
|
|
7
|
+
import { SpotMarketAccount, PerpMarketAccount, StateAccount, UserAccount } from '../types';
|
|
8
8
|
import { BulkAccountLoader } from './bulkAccountLoader';
|
|
9
9
|
import { PublicKey } from '@solana/web3.js';
|
|
10
10
|
import { OracleInfo, OraclePriceData } from '../oracles/types';
|
|
@@ -12,8 +12,8 @@ import { OracleClientCache } from '../oracles/oracleClientCache';
|
|
|
12
12
|
export declare class PollingClearingHouseAccountSubscriber implements ClearingHouseAccountSubscriber {
|
|
13
13
|
isSubscribed: boolean;
|
|
14
14
|
program: Program;
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
perpMarketIndexes: BN[];
|
|
16
|
+
spotMarketIndexes: BN[];
|
|
17
17
|
oracleInfos: OracleInfo[];
|
|
18
18
|
oracleClientCache: OracleClientCache;
|
|
19
19
|
eventEmitter: StrictEventEmitter<EventEmitter, ClearingHouseAccountEvents>;
|
|
@@ -22,20 +22,20 @@ export declare class PollingClearingHouseAccountSubscriber implements ClearingHo
|
|
|
22
22
|
oraclesToPoll: Map<string, OraclesToPoll>;
|
|
23
23
|
errorCallbackId?: string;
|
|
24
24
|
state?: DataAndSlot<StateAccount>;
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
perpMarket: Map<number, DataAndSlot<PerpMarketAccount>>;
|
|
26
|
+
spotMarket: Map<number, DataAndSlot<SpotMarketAccount>>;
|
|
27
27
|
oracles: Map<string, DataAndSlot<OraclePriceData>>;
|
|
28
28
|
user?: DataAndSlot<UserAccount>;
|
|
29
29
|
private isSubscribing;
|
|
30
30
|
private subscriptionPromise;
|
|
31
31
|
private subscriptionPromiseResolver;
|
|
32
|
-
constructor(program: Program, accountLoader: BulkAccountLoader,
|
|
32
|
+
constructor(program: Program, accountLoader: BulkAccountLoader, perpMarketIndexes: BN[], spotMarketIndexes: BN[], oracleInfos: OracleInfo[]);
|
|
33
33
|
subscribe(): Promise<boolean>;
|
|
34
34
|
updateAccountsToPoll(): Promise<void>;
|
|
35
35
|
updateMarketAccountsToPoll(): Promise<boolean>;
|
|
36
36
|
addMarketAccountToPoll(marketIndex: BN): Promise<boolean>;
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
updateSpotMarketAccountsToPoll(): Promise<boolean>;
|
|
38
|
+
addSpotMarketAccountToPoll(marketIndex: BN): Promise<boolean>;
|
|
39
39
|
updateOraclesToPoll(): boolean;
|
|
40
40
|
addOracleToPoll(oracleInfo: OracleInfo): boolean;
|
|
41
41
|
getClearingHouseAccounts(): Promise<ClearingHouseAccounts>;
|
|
@@ -45,14 +45,14 @@ export declare class PollingClearingHouseAccountSubscriber implements ClearingHo
|
|
|
45
45
|
fetch(): Promise<void>;
|
|
46
46
|
didSubscriptionSucceed(): boolean;
|
|
47
47
|
unsubscribe(): Promise<void>;
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
addSpotMarket(marketIndex: BN): Promise<boolean>;
|
|
49
|
+
addPerpMarket(marketIndex: BN): Promise<boolean>;
|
|
50
50
|
addOracle(oracleInfo: OracleInfo): Promise<boolean>;
|
|
51
51
|
assertIsSubscribed(): void;
|
|
52
52
|
getStateAccountAndSlot(): DataAndSlot<StateAccount>;
|
|
53
|
-
getMarketAccountAndSlot(marketIndex: BN): DataAndSlot<
|
|
54
|
-
getMarketAccountsAndSlots(): DataAndSlot<
|
|
55
|
-
|
|
53
|
+
getMarketAccountAndSlot(marketIndex: BN): DataAndSlot<PerpMarketAccount> | undefined;
|
|
54
|
+
getMarketAccountsAndSlots(): DataAndSlot<PerpMarketAccount>[];
|
|
55
|
+
getSpotMarketAccountAndSlot(marketIndex: BN): DataAndSlot<SpotMarketAccount> | undefined;
|
|
56
56
|
getOraclePriceDataAndSlot(oraclePublicKey: PublicKey): DataAndSlot<OraclePriceData> | undefined;
|
|
57
57
|
}
|
|
58
58
|
declare type ClearingHouseAccounts = {
|
|
@@ -9,20 +9,20 @@ const web3_js_1 = require("@solana/web3.js");
|
|
|
9
9
|
const oracleClientCache_1 = require("../oracles/oracleClientCache");
|
|
10
10
|
const quoteAssetOracleClient_1 = require("../oracles/quoteAssetOracleClient");
|
|
11
11
|
class PollingClearingHouseAccountSubscriber {
|
|
12
|
-
constructor(program, accountLoader,
|
|
12
|
+
constructor(program, accountLoader, perpMarketIndexes, spotMarketIndexes, oracleInfos) {
|
|
13
13
|
this.oracleClientCache = new oracleClientCache_1.OracleClientCache();
|
|
14
14
|
this.accountsToPoll = new Map();
|
|
15
15
|
this.oraclesToPoll = new Map();
|
|
16
|
-
this.
|
|
17
|
-
this.
|
|
16
|
+
this.perpMarket = new Map();
|
|
17
|
+
this.spotMarket = new Map();
|
|
18
18
|
this.oracles = new Map();
|
|
19
19
|
this.isSubscribing = false;
|
|
20
20
|
this.isSubscribed = false;
|
|
21
21
|
this.program = program;
|
|
22
22
|
this.eventEmitter = new events_1.EventEmitter();
|
|
23
23
|
this.accountLoader = accountLoader;
|
|
24
|
-
this.
|
|
25
|
-
this.
|
|
24
|
+
this.perpMarketIndexes = perpMarketIndexes;
|
|
25
|
+
this.spotMarketIndexes = spotMarketIndexes;
|
|
26
26
|
this.oracleInfos = oracleInfos;
|
|
27
27
|
}
|
|
28
28
|
async subscribe() {
|
|
@@ -65,10 +65,10 @@ class PollingClearingHouseAccountSubscriber {
|
|
|
65
65
|
eventType: 'stateAccountUpdate',
|
|
66
66
|
});
|
|
67
67
|
await this.updateMarketAccountsToPoll();
|
|
68
|
-
await this.
|
|
68
|
+
await this.updateSpotMarketAccountsToPoll();
|
|
69
69
|
}
|
|
70
70
|
async updateMarketAccountsToPoll() {
|
|
71
|
-
for (const marketIndex of this.
|
|
71
|
+
for (const marketIndex of this.perpMarketIndexes) {
|
|
72
72
|
await this.addMarketAccountToPoll(marketIndex);
|
|
73
73
|
}
|
|
74
74
|
return true;
|
|
@@ -76,26 +76,26 @@ class PollingClearingHouseAccountSubscriber {
|
|
|
76
76
|
async addMarketAccountToPoll(marketIndex) {
|
|
77
77
|
const marketPublicKey = await (0, pda_1.getMarketPublicKey)(this.program.programId, marketIndex);
|
|
78
78
|
this.accountsToPoll.set(marketPublicKey.toString(), {
|
|
79
|
-
key: '
|
|
79
|
+
key: 'perpMarket',
|
|
80
80
|
publicKey: marketPublicKey,
|
|
81
|
-
eventType: '
|
|
81
|
+
eventType: 'perpMarketAccountUpdate',
|
|
82
82
|
mapKey: marketIndex.toNumber(),
|
|
83
83
|
});
|
|
84
84
|
return true;
|
|
85
85
|
}
|
|
86
|
-
async
|
|
87
|
-
for (const
|
|
88
|
-
await this.
|
|
86
|
+
async updateSpotMarketAccountsToPoll() {
|
|
87
|
+
for (const marketIndex of this.spotMarketIndexes) {
|
|
88
|
+
await this.addSpotMarketAccountToPoll(marketIndex);
|
|
89
89
|
}
|
|
90
90
|
return true;
|
|
91
91
|
}
|
|
92
|
-
async
|
|
93
|
-
const
|
|
94
|
-
this.accountsToPoll.set(
|
|
95
|
-
key: '
|
|
96
|
-
publicKey:
|
|
97
|
-
eventType: '
|
|
98
|
-
mapKey:
|
|
92
|
+
async addSpotMarketAccountToPoll(marketIndex) {
|
|
93
|
+
const marketPublicKey = await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, marketIndex);
|
|
94
|
+
this.accountsToPoll.set(marketPublicKey.toString(), {
|
|
95
|
+
key: 'spotMarket',
|
|
96
|
+
publicKey: marketPublicKey,
|
|
97
|
+
eventType: 'spotMarketAccountUpdate',
|
|
98
|
+
mapKey: marketIndex.toNumber(),
|
|
99
99
|
});
|
|
100
100
|
return true;
|
|
101
101
|
}
|
|
@@ -223,13 +223,13 @@ class PollingClearingHouseAccountSubscriber {
|
|
|
223
223
|
this.oraclesToPoll.clear();
|
|
224
224
|
this.isSubscribed = false;
|
|
225
225
|
}
|
|
226
|
-
async
|
|
227
|
-
await this.
|
|
228
|
-
const accountToPoll = this.accountsToPoll.get(
|
|
226
|
+
async addSpotMarket(marketIndex) {
|
|
227
|
+
await this.addSpotMarketAccountToPoll(marketIndex);
|
|
228
|
+
const accountToPoll = this.accountsToPoll.get(marketIndex.toString());
|
|
229
229
|
this.addAccountToAccountLoader(accountToPoll);
|
|
230
230
|
return true;
|
|
231
231
|
}
|
|
232
|
-
async
|
|
232
|
+
async addPerpMarket(marketIndex) {
|
|
233
233
|
await this.addMarketAccountToPoll(marketIndex);
|
|
234
234
|
const accountToPoll = this.accountsToPoll.get(marketIndex.toString());
|
|
235
235
|
this.addAccountToAccountLoader(accountToPoll);
|
|
@@ -254,13 +254,13 @@ class PollingClearingHouseAccountSubscriber {
|
|
|
254
254
|
return this.state;
|
|
255
255
|
}
|
|
256
256
|
getMarketAccountAndSlot(marketIndex) {
|
|
257
|
-
return this.
|
|
257
|
+
return this.perpMarket.get(marketIndex.toNumber());
|
|
258
258
|
}
|
|
259
259
|
getMarketAccountsAndSlots() {
|
|
260
|
-
return Array.from(this.
|
|
260
|
+
return Array.from(this.perpMarket.values());
|
|
261
261
|
}
|
|
262
|
-
|
|
263
|
-
return this.
|
|
262
|
+
getSpotMarketAccountAndSlot(marketIndex) {
|
|
263
|
+
return this.spotMarket.get(marketIndex.toNumber());
|
|
264
264
|
}
|
|
265
265
|
getOraclePriceDataAndSlot(oraclePublicKey) {
|
|
266
266
|
this.assertIsSubscribed();
|
package/lib/accounts/types.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="bn.js" />
|
|
3
|
-
|
|
4
|
-
import { BankAccount, MarketAccount, OracleSource, StateAccount, UserAccount, UserStatsAccount } from '../types';
|
|
3
|
+
import { SpotMarketAccount, PerpMarketAccount, OracleSource, StateAccount, UserAccount, UserStatsAccount } from '../types';
|
|
5
4
|
import StrictEventEmitter from 'strict-event-emitter-types';
|
|
6
5
|
import { EventEmitter } from 'events';
|
|
7
6
|
import { PublicKey } from '@solana/web3.js';
|
|
@@ -19,8 +18,8 @@ export declare class NotSubscribedError extends Error {
|
|
|
19
18
|
}
|
|
20
19
|
export interface ClearingHouseAccountEvents {
|
|
21
20
|
stateAccountUpdate: (payload: StateAccount) => void;
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
perpMarketAccountUpdate: (payload: PerpMarketAccount) => void;
|
|
22
|
+
spotMarketAccountUpdate: (payload: SpotMarketAccount) => void;
|
|
24
23
|
oraclePriceUpdate: (publicKey: PublicKey, data: OraclePriceData) => void;
|
|
25
24
|
userAccountUpdate: (payload: UserAccount) => void;
|
|
26
25
|
update: void;
|
|
@@ -32,13 +31,13 @@ export interface ClearingHouseAccountSubscriber {
|
|
|
32
31
|
subscribe(): Promise<boolean>;
|
|
33
32
|
fetch(): Promise<void>;
|
|
34
33
|
unsubscribe(): Promise<void>;
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
addPerpMarket(marketIndex: BN): Promise<boolean>;
|
|
35
|
+
addSpotMarket(marketIndex: BN): Promise<boolean>;
|
|
37
36
|
addOracle(oracleInfo: OracleInfo): Promise<boolean>;
|
|
38
37
|
getStateAccountAndSlot(): DataAndSlot<StateAccount>;
|
|
39
|
-
getMarketAccountAndSlot(marketIndex: BN): DataAndSlot<
|
|
40
|
-
getMarketAccountsAndSlots(): DataAndSlot<
|
|
41
|
-
|
|
38
|
+
getMarketAccountAndSlot(marketIndex: BN): DataAndSlot<PerpMarketAccount> | undefined;
|
|
39
|
+
getMarketAccountsAndSlots(): DataAndSlot<PerpMarketAccount>[];
|
|
40
|
+
getSpotMarketAccountAndSlot(marketIndex: BN): DataAndSlot<SpotMarketAccount> | undefined;
|
|
42
41
|
getOraclePriceDataAndSlot(oraclePublicKey: PublicKey): DataAndSlot<OraclePriceData> | undefined;
|
|
43
42
|
}
|
|
44
43
|
export interface UserAccountEvents {
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
/// <reference types="node" />
|
|
3
3
|
import { ClearingHouseAccountSubscriber, ClearingHouseAccountEvents, DataAndSlot } from './types';
|
|
4
4
|
import { AccountSubscriber } from './types';
|
|
5
|
-
import {
|
|
5
|
+
import { SpotMarketAccount, PerpMarketAccount, StateAccount } from '../types';
|
|
6
6
|
import { BN, Program } from '@project-serum/anchor';
|
|
7
7
|
import StrictEventEmitter from 'strict-event-emitter-types';
|
|
8
8
|
import { EventEmitter } from 'events';
|
|
@@ -12,38 +12,38 @@ import { OracleClientCache } from '../oracles/oracleClientCache';
|
|
|
12
12
|
export declare class WebSocketClearingHouseAccountSubscriber implements ClearingHouseAccountSubscriber {
|
|
13
13
|
isSubscribed: boolean;
|
|
14
14
|
program: Program;
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
perpMarketIndexes: BN[];
|
|
16
|
+
spotMarketIndexes: BN[];
|
|
17
17
|
oracleInfos: OracleInfo[];
|
|
18
18
|
oracleClientCache: OracleClientCache;
|
|
19
19
|
eventEmitter: StrictEventEmitter<EventEmitter, ClearingHouseAccountEvents>;
|
|
20
20
|
stateAccountSubscriber?: AccountSubscriber<StateAccount>;
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
perpMarketAccountSubscribers: Map<number, AccountSubscriber<PerpMarketAccount>>;
|
|
22
|
+
spotMarketAccountSubscribers: Map<number, AccountSubscriber<SpotMarketAccount>>;
|
|
23
23
|
oracleSubscribers: Map<string, AccountSubscriber<OraclePriceData>>;
|
|
24
24
|
private isSubscribing;
|
|
25
25
|
private subscriptionPromise;
|
|
26
26
|
private subscriptionPromiseResolver;
|
|
27
|
-
constructor(program: Program,
|
|
27
|
+
constructor(program: Program, perpMarketIndexes: BN[], spotMarketIndexes: BN[], oracleInfos: OracleInfo[]);
|
|
28
28
|
subscribe(): Promise<boolean>;
|
|
29
29
|
subscribeToMarketAccounts(): Promise<boolean>;
|
|
30
30
|
subscribeToMarketAccount(marketIndex: BN): Promise<boolean>;
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
subscribeToSpotMarketAccounts(): Promise<boolean>;
|
|
32
|
+
subscribeToSpotMarketAccount(marketIndex: BN): Promise<boolean>;
|
|
33
33
|
subscribeToOracles(): Promise<boolean>;
|
|
34
34
|
subscribeToOracle(oracleInfo: OracleInfo): Promise<boolean>;
|
|
35
35
|
unsubscribeFromMarketAccounts(): Promise<void>;
|
|
36
|
-
|
|
36
|
+
unsubscribeFromSpotMarketAccounts(): Promise<void>;
|
|
37
37
|
unsubscribeFromOracles(): Promise<void>;
|
|
38
38
|
fetch(): Promise<void>;
|
|
39
39
|
unsubscribe(): Promise<void>;
|
|
40
|
-
|
|
41
|
-
|
|
40
|
+
addSpotMarket(marketIndex: BN): Promise<boolean>;
|
|
41
|
+
addPerpMarket(marketIndex: BN): Promise<boolean>;
|
|
42
42
|
addOracle(oracleInfo: OracleInfo): Promise<boolean>;
|
|
43
43
|
assertIsSubscribed(): void;
|
|
44
44
|
getStateAccountAndSlot(): DataAndSlot<StateAccount>;
|
|
45
|
-
getMarketAccountAndSlot(marketIndex: BN): DataAndSlot<
|
|
46
|
-
getMarketAccountsAndSlots(): DataAndSlot<
|
|
47
|
-
|
|
45
|
+
getMarketAccountAndSlot(marketIndex: BN): DataAndSlot<PerpMarketAccount> | undefined;
|
|
46
|
+
getMarketAccountsAndSlots(): DataAndSlot<PerpMarketAccount>[];
|
|
47
|
+
getSpotMarketAccountAndSlot(marketIndex: BN): DataAndSlot<SpotMarketAccount> | undefined;
|
|
48
48
|
getOraclePriceDataAndSlot(oraclePublicKey: PublicKey): DataAndSlot<OraclePriceData> | undefined;
|
|
49
49
|
}
|
|
@@ -9,17 +9,17 @@ const web3_js_1 = require("@solana/web3.js");
|
|
|
9
9
|
const oracleClientCache_1 = require("../oracles/oracleClientCache");
|
|
10
10
|
const quoteAssetOracleClient_1 = require("../oracles/quoteAssetOracleClient");
|
|
11
11
|
class WebSocketClearingHouseAccountSubscriber {
|
|
12
|
-
constructor(program,
|
|
12
|
+
constructor(program, perpMarketIndexes, spotMarketIndexes, oracleInfos) {
|
|
13
13
|
this.oracleClientCache = new oracleClientCache_1.OracleClientCache();
|
|
14
|
-
this.
|
|
15
|
-
this.
|
|
14
|
+
this.perpMarketAccountSubscribers = new Map();
|
|
15
|
+
this.spotMarketAccountSubscribers = new Map();
|
|
16
16
|
this.oracleSubscribers = new Map();
|
|
17
17
|
this.isSubscribing = false;
|
|
18
18
|
this.isSubscribed = false;
|
|
19
19
|
this.program = program;
|
|
20
20
|
this.eventEmitter = new events_1.EventEmitter();
|
|
21
|
-
this.
|
|
22
|
-
this.
|
|
21
|
+
this.perpMarketIndexes = perpMarketIndexes;
|
|
22
|
+
this.spotMarketIndexes = spotMarketIndexes;
|
|
23
23
|
this.oracleInfos = oracleInfos;
|
|
24
24
|
}
|
|
25
25
|
async subscribe() {
|
|
@@ -42,8 +42,8 @@ class WebSocketClearingHouseAccountSubscriber {
|
|
|
42
42
|
});
|
|
43
43
|
// subscribe to market accounts
|
|
44
44
|
await this.subscribeToMarketAccounts();
|
|
45
|
-
// subscribe to
|
|
46
|
-
await this.
|
|
45
|
+
// subscribe to spot market accounts
|
|
46
|
+
await this.subscribeToSpotMarketAccounts();
|
|
47
47
|
// subscribe to oracles
|
|
48
48
|
await this.subscribeToOracles();
|
|
49
49
|
this.eventEmitter.emit('update');
|
|
@@ -53,35 +53,35 @@ class WebSocketClearingHouseAccountSubscriber {
|
|
|
53
53
|
return true;
|
|
54
54
|
}
|
|
55
55
|
async subscribeToMarketAccounts() {
|
|
56
|
-
for (const marketIndex of this.
|
|
56
|
+
for (const marketIndex of this.perpMarketIndexes) {
|
|
57
57
|
await this.subscribeToMarketAccount(marketIndex);
|
|
58
58
|
}
|
|
59
59
|
return true;
|
|
60
60
|
}
|
|
61
61
|
async subscribeToMarketAccount(marketIndex) {
|
|
62
62
|
const marketPublicKey = await (0, pda_1.getMarketPublicKey)(this.program.programId, marketIndex);
|
|
63
|
-
const accountSubscriber = new webSocketAccountSubscriber_1.WebSocketAccountSubscriber('
|
|
63
|
+
const accountSubscriber = new webSocketAccountSubscriber_1.WebSocketAccountSubscriber('perpMarket', this.program, marketPublicKey);
|
|
64
64
|
await accountSubscriber.subscribe((data) => {
|
|
65
|
-
this.eventEmitter.emit('
|
|
65
|
+
this.eventEmitter.emit('perpMarketAccountUpdate', data);
|
|
66
66
|
this.eventEmitter.emit('update');
|
|
67
67
|
});
|
|
68
|
-
this.
|
|
68
|
+
this.perpMarketAccountSubscribers.set(marketIndex.toNumber(), accountSubscriber);
|
|
69
69
|
return true;
|
|
70
70
|
}
|
|
71
|
-
async
|
|
72
|
-
for (const
|
|
73
|
-
await this.
|
|
71
|
+
async subscribeToSpotMarketAccounts() {
|
|
72
|
+
for (const marketIndex of this.spotMarketIndexes) {
|
|
73
|
+
await this.subscribeToSpotMarketAccount(marketIndex);
|
|
74
74
|
}
|
|
75
75
|
return true;
|
|
76
76
|
}
|
|
77
|
-
async
|
|
78
|
-
const
|
|
79
|
-
const accountSubscriber = new webSocketAccountSubscriber_1.WebSocketAccountSubscriber('
|
|
77
|
+
async subscribeToSpotMarketAccount(marketIndex) {
|
|
78
|
+
const marketPublicKey = await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, marketIndex);
|
|
79
|
+
const accountSubscriber = new webSocketAccountSubscriber_1.WebSocketAccountSubscriber('spotMarket', this.program, marketPublicKey);
|
|
80
80
|
await accountSubscriber.subscribe((data) => {
|
|
81
|
-
this.eventEmitter.emit('
|
|
81
|
+
this.eventEmitter.emit('spotMarketAccountUpdate', data);
|
|
82
82
|
this.eventEmitter.emit('update');
|
|
83
83
|
});
|
|
84
|
-
this.
|
|
84
|
+
this.spotMarketAccountSubscribers.set(marketIndex.toNumber(), accountSubscriber);
|
|
85
85
|
return true;
|
|
86
86
|
}
|
|
87
87
|
async subscribeToOracles() {
|
|
@@ -105,12 +105,12 @@ class WebSocketClearingHouseAccountSubscriber {
|
|
|
105
105
|
return true;
|
|
106
106
|
}
|
|
107
107
|
async unsubscribeFromMarketAccounts() {
|
|
108
|
-
for (const accountSubscriber of this.
|
|
108
|
+
for (const accountSubscriber of this.perpMarketAccountSubscribers.values()) {
|
|
109
109
|
await accountSubscriber.unsubscribe();
|
|
110
110
|
}
|
|
111
111
|
}
|
|
112
|
-
async
|
|
113
|
-
for (const accountSubscriber of this.
|
|
112
|
+
async unsubscribeFromSpotMarketAccounts() {
|
|
113
|
+
for (const accountSubscriber of this.spotMarketAccountSubscribers.values()) {
|
|
114
114
|
await accountSubscriber.unsubscribe();
|
|
115
115
|
}
|
|
116
116
|
}
|
|
@@ -124,8 +124,8 @@ class WebSocketClearingHouseAccountSubscriber {
|
|
|
124
124
|
return;
|
|
125
125
|
}
|
|
126
126
|
const promises = [this.stateAccountSubscriber.fetch()]
|
|
127
|
-
.concat(Array.from(this.
|
|
128
|
-
.concat(Array.from(this.
|
|
127
|
+
.concat(Array.from(this.perpMarketAccountSubscribers.values()).map((subscriber) => subscriber.fetch()))
|
|
128
|
+
.concat(Array.from(this.spotMarketAccountSubscribers.values()).map((subscriber) => subscriber.fetch()));
|
|
129
129
|
await Promise.all(promises);
|
|
130
130
|
}
|
|
131
131
|
async unsubscribe() {
|
|
@@ -134,18 +134,18 @@ class WebSocketClearingHouseAccountSubscriber {
|
|
|
134
134
|
}
|
|
135
135
|
await this.stateAccountSubscriber.unsubscribe();
|
|
136
136
|
await this.unsubscribeFromMarketAccounts();
|
|
137
|
-
await this.
|
|
137
|
+
await this.unsubscribeFromSpotMarketAccounts();
|
|
138
138
|
await this.unsubscribeFromOracles();
|
|
139
139
|
this.isSubscribed = false;
|
|
140
140
|
}
|
|
141
|
-
async
|
|
142
|
-
if (this.
|
|
141
|
+
async addSpotMarket(marketIndex) {
|
|
142
|
+
if (this.spotMarketAccountSubscribers.has(marketIndex.toNumber())) {
|
|
143
143
|
return true;
|
|
144
144
|
}
|
|
145
|
-
return this.
|
|
145
|
+
return this.subscribeToSpotMarketAccount(marketIndex);
|
|
146
146
|
}
|
|
147
|
-
async
|
|
148
|
-
if (this.
|
|
147
|
+
async addPerpMarket(marketIndex) {
|
|
148
|
+
if (this.perpMarketAccountSubscribers.has(marketIndex.toNumber())) {
|
|
149
149
|
return true;
|
|
150
150
|
}
|
|
151
151
|
return this.subscribeToMarketAccount(marketIndex);
|
|
@@ -170,15 +170,16 @@ class WebSocketClearingHouseAccountSubscriber {
|
|
|
170
170
|
}
|
|
171
171
|
getMarketAccountAndSlot(marketIndex) {
|
|
172
172
|
this.assertIsSubscribed();
|
|
173
|
-
return this.
|
|
173
|
+
return this.perpMarketAccountSubscribers.get(marketIndex.toNumber())
|
|
174
174
|
.dataAndSlot;
|
|
175
175
|
}
|
|
176
176
|
getMarketAccountsAndSlots() {
|
|
177
|
-
return Array.from(this.
|
|
177
|
+
return Array.from(this.perpMarketAccountSubscribers.values()).map((subscriber) => subscriber.dataAndSlot);
|
|
178
178
|
}
|
|
179
|
-
|
|
179
|
+
getSpotMarketAccountAndSlot(marketIndex) {
|
|
180
180
|
this.assertIsSubscribed();
|
|
181
|
-
return this.
|
|
181
|
+
return this.spotMarketAccountSubscribers.get(marketIndex.toNumber())
|
|
182
|
+
.dataAndSlot;
|
|
182
183
|
}
|
|
183
184
|
getOraclePriceDataAndSlot(oraclePublicKey) {
|
|
184
185
|
this.assertIsSubscribed();
|
package/lib/addresses/pda.d.ts
CHANGED
|
@@ -8,9 +8,11 @@ export declare function getUserAccountPublicKey(programId: PublicKey, authority:
|
|
|
8
8
|
export declare function getUserAccountPublicKeySync(programId: PublicKey, authority: PublicKey, userId?: number): PublicKey;
|
|
9
9
|
export declare function getUserStatsAccountPublicKey(programId: PublicKey, authority: PublicKey): PublicKey;
|
|
10
10
|
export declare function getMarketPublicKey(programId: PublicKey, marketIndex: BN): Promise<PublicKey>;
|
|
11
|
-
export declare function
|
|
12
|
-
export declare function
|
|
13
|
-
export declare function
|
|
14
|
-
export declare function
|
|
15
|
-
export declare function
|
|
16
|
-
export declare function
|
|
11
|
+
export declare function getSpotMarketPublicKey(programId: PublicKey, marketIndex: BN): Promise<PublicKey>;
|
|
12
|
+
export declare function getSpotMarketVaultPublicKey(programId: PublicKey, marketIndex: BN): Promise<PublicKey>;
|
|
13
|
+
export declare function getInsuranceFundVaultPublicKey(programId: PublicKey, marketIndex: BN): Promise<PublicKey>;
|
|
14
|
+
export declare function getInsuranceFundStakeAccountPublicKey(programId: PublicKey, authority: PublicKey, marketIndex: BN): PublicKey;
|
|
15
|
+
export declare function getClearingHouseSignerPublicKey(programId: PublicKey): PublicKey;
|
|
16
|
+
export declare function getSerumOpenOrdersPublicKey(programId: PublicKey, market: PublicKey): PublicKey;
|
|
17
|
+
export declare function getSerumSignerPublicKey(programId: PublicKey, market: PublicKey, nonce: BN): PublicKey;
|
|
18
|
+
export declare function getSerumFulfillmentConfigPublicKey(programId: PublicKey, market: PublicKey): PublicKey;
|
package/lib/addresses/pda.js
CHANGED
|
@@ -23,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.
|
|
26
|
+
exports.getSerumFulfillmentConfigPublicKey = exports.getSerumSignerPublicKey = exports.getSerumOpenOrdersPublicKey = exports.getClearingHouseSignerPublicKey = exports.getInsuranceFundStakeAccountPublicKey = exports.getInsuranceFundVaultPublicKey = exports.getSpotMarketVaultPublicKey = exports.getSpotMarketPublicKey = exports.getMarketPublicKey = exports.getUserStatsAccountPublicKey = exports.getUserAccountPublicKeySync = exports.getUserAccountPublicKey = exports.getUserAccountPublicKeyAndNonce = exports.getClearingHouseStateAccountPublicKey = exports.getClearingHouseStateAccountPublicKeyAndNonce = void 0;
|
|
27
27
|
const anchor = __importStar(require("@project-serum/anchor"));
|
|
28
28
|
async function getClearingHouseStateAccountPublicKeyAndNonce(programId) {
|
|
29
29
|
return anchor.web3.PublicKey.findProgramAddress([Buffer.from(anchor.utils.bytes.utf8.encode('clearing_house'))], programId);
|
|
@@ -67,46 +67,54 @@ async function getMarketPublicKey(programId, marketIndex) {
|
|
|
67
67
|
], programId))[0];
|
|
68
68
|
}
|
|
69
69
|
exports.getMarketPublicKey = getMarketPublicKey;
|
|
70
|
-
async function
|
|
70
|
+
async function getSpotMarketPublicKey(programId, marketIndex) {
|
|
71
71
|
return (await anchor.web3.PublicKey.findProgramAddress([
|
|
72
|
-
Buffer.from(anchor.utils.bytes.utf8.encode('
|
|
73
|
-
|
|
74
|
-
], programId))[0];
|
|
75
|
-
}
|
|
76
|
-
exports.getBankPublicKey = getBankPublicKey;
|
|
77
|
-
async function getBankVaultPublicKey(programId, bankIndex) {
|
|
78
|
-
return (await anchor.web3.PublicKey.findProgramAddress([
|
|
79
|
-
Buffer.from(anchor.utils.bytes.utf8.encode('bank_vault')),
|
|
80
|
-
bankIndex.toArrayLike(Buffer, 'le', 8),
|
|
72
|
+
Buffer.from(anchor.utils.bytes.utf8.encode('spot_market')),
|
|
73
|
+
marketIndex.toArrayLike(Buffer, 'le', 8),
|
|
81
74
|
], programId))[0];
|
|
82
75
|
}
|
|
83
|
-
exports.
|
|
84
|
-
async function
|
|
76
|
+
exports.getSpotMarketPublicKey = getSpotMarketPublicKey;
|
|
77
|
+
async function getSpotMarketVaultPublicKey(programId, marketIndex) {
|
|
85
78
|
return (await anchor.web3.PublicKey.findProgramAddress([
|
|
86
|
-
Buffer.from(anchor.utils.bytes.utf8.encode('
|
|
87
|
-
|
|
79
|
+
Buffer.from(anchor.utils.bytes.utf8.encode('spot_market_vault')),
|
|
80
|
+
marketIndex.toArrayLike(Buffer, 'le', 8),
|
|
88
81
|
], programId))[0];
|
|
89
82
|
}
|
|
90
|
-
exports.
|
|
91
|
-
async function getInsuranceFundVaultPublicKey(programId,
|
|
83
|
+
exports.getSpotMarketVaultPublicKey = getSpotMarketVaultPublicKey;
|
|
84
|
+
async function getInsuranceFundVaultPublicKey(programId, marketIndex) {
|
|
92
85
|
return (await anchor.web3.PublicKey.findProgramAddress([
|
|
93
86
|
Buffer.from(anchor.utils.bytes.utf8.encode('insurance_fund_vault')),
|
|
94
|
-
|
|
87
|
+
marketIndex.toArrayLike(Buffer, 'le', 8),
|
|
95
88
|
], programId))[0];
|
|
96
89
|
}
|
|
97
90
|
exports.getInsuranceFundVaultPublicKey = getInsuranceFundVaultPublicKey;
|
|
98
|
-
|
|
99
|
-
return (await anchor.web3.PublicKey.findProgramAddress([
|
|
100
|
-
Buffer.from(anchor.utils.bytes.utf8.encode('insurance_fund_vault_authority')),
|
|
101
|
-
bankIndex.toArrayLike(Buffer, 'le', 8),
|
|
102
|
-
], programId))[0];
|
|
103
|
-
}
|
|
104
|
-
exports.getInsuranceFundVaultAuthorityPublicKey = getInsuranceFundVaultAuthorityPublicKey;
|
|
105
|
-
function getInsuranceFundStakeAccountPublicKey(programId, authority, bankIndex) {
|
|
91
|
+
function getInsuranceFundStakeAccountPublicKey(programId, authority, marketIndex) {
|
|
106
92
|
return anchor.web3.PublicKey.findProgramAddressSync([
|
|
107
93
|
Buffer.from(anchor.utils.bytes.utf8.encode('insurance_fund_stake')),
|
|
108
94
|
authority.toBuffer(),
|
|
109
|
-
|
|
95
|
+
marketIndex.toArrayLike(Buffer, 'le', 8),
|
|
110
96
|
], programId)[0];
|
|
111
97
|
}
|
|
112
98
|
exports.getInsuranceFundStakeAccountPublicKey = getInsuranceFundStakeAccountPublicKey;
|
|
99
|
+
function getClearingHouseSignerPublicKey(programId) {
|
|
100
|
+
return anchor.web3.PublicKey.findProgramAddressSync([Buffer.from(anchor.utils.bytes.utf8.encode('clearing_house_signer'))], programId)[0];
|
|
101
|
+
}
|
|
102
|
+
exports.getClearingHouseSignerPublicKey = getClearingHouseSignerPublicKey;
|
|
103
|
+
function getSerumOpenOrdersPublicKey(programId, market) {
|
|
104
|
+
return anchor.web3.PublicKey.findProgramAddressSync([
|
|
105
|
+
Buffer.from(anchor.utils.bytes.utf8.encode('serum_open_orders')),
|
|
106
|
+
market.toBuffer(),
|
|
107
|
+
], programId)[0];
|
|
108
|
+
}
|
|
109
|
+
exports.getSerumOpenOrdersPublicKey = getSerumOpenOrdersPublicKey;
|
|
110
|
+
function getSerumSignerPublicKey(programId, market, nonce) {
|
|
111
|
+
return anchor.web3.PublicKey.createProgramAddressSync([market.toBuffer(), nonce.toArrayLike(Buffer, 'le', 8)], programId);
|
|
112
|
+
}
|
|
113
|
+
exports.getSerumSignerPublicKey = getSerumSignerPublicKey;
|
|
114
|
+
function getSerumFulfillmentConfigPublicKey(programId, market) {
|
|
115
|
+
return anchor.web3.PublicKey.findProgramAddressSync([
|
|
116
|
+
Buffer.from(anchor.utils.bytes.utf8.encode('serum_fulfillment_config')),
|
|
117
|
+
market.toBuffer(),
|
|
118
|
+
], programId)[0];
|
|
119
|
+
}
|
|
120
|
+
exports.getSerumFulfillmentConfigPublicKey = getSerumFulfillmentConfigPublicKey;
|
package/lib/admin.d.ts
CHANGED
|
@@ -5,11 +5,12 @@ import { BN } from '@project-serum/anchor';
|
|
|
5
5
|
import { ClearingHouse } from './clearingHouse';
|
|
6
6
|
export declare class Admin extends ClearingHouse {
|
|
7
7
|
initialize(usdcMint: PublicKey, adminControlsPrices: boolean): Promise<[TransactionSignature]>;
|
|
8
|
-
|
|
8
|
+
initializeSpotMarket(mint: PublicKey, optimalUtilization: BN, optimalRate: BN, maxRate: BN, oracle: PublicKey, oracleSource: OracleSource, initialAssetWeight: BN, maintenanceAssetWeight: BN, initialLiabilityWeight: BN, maintenanceLiabilityWeight: BN, imfFactor?: BN, liquidationFee?: BN): Promise<TransactionSignature>;
|
|
9
|
+
initializeSerumFulfillmentConfig(marketIndex: BN, serumMarket: PublicKey, serumProgram: PublicKey): Promise<TransactionSignature>;
|
|
9
10
|
initializeMarket(priceOracle: PublicKey, baseAssetReserve: BN, quoteAssetReserve: BN, periodicity: BN, pegMultiplier?: BN, oracleSource?: OracleSource, marginRatioInitial?: number, marginRatioMaintenance?: number, liquidationFee?: BN): Promise<TransactionSignature>;
|
|
10
|
-
moveAmmPrice(baseAssetReserve: BN, quoteAssetReserve: BN,
|
|
11
|
+
moveAmmPrice(marketIndex: BN, baseAssetReserve: BN, quoteAssetReserve: BN, sqrtK?: BN): Promise<TransactionSignature>;
|
|
11
12
|
updateK(sqrtK: BN, marketIndex: BN): Promise<TransactionSignature>;
|
|
12
|
-
moveAmmToPrice(
|
|
13
|
+
moveAmmToPrice(perpMarketIndex: BN, targetPrice: BN): Promise<TransactionSignature>;
|
|
13
14
|
repegAmmCurve(newPeg: BN, marketIndex: BN): Promise<TransactionSignature>;
|
|
14
15
|
updateAmmOracleTwap(marketIndex: BN): Promise<TransactionSignature>;
|
|
15
16
|
resetAmmOracleTwap(marketIndex: BN): Promise<TransactionSignature>;
|
|
@@ -30,13 +31,14 @@ export declare class Admin extends ClearingHouse {
|
|
|
30
31
|
updateOrderFillerRewardStructure(orderFillerRewardStructure: OrderFillerRewardStructure): Promise<TransactionSignature>;
|
|
31
32
|
updateFee(fees: FeeStructure): Promise<TransactionSignature>;
|
|
32
33
|
updateOracleGuardRails(oracleGuardRails: OracleGuardRails): Promise<TransactionSignature>;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
updateWithdrawGuardThreshold(marketIndex: BN, withdrawGuardThreshold: BN): Promise<TransactionSignature>;
|
|
35
|
+
updateSpotMarketIfFactor(marketIndex: BN, userIfFactor: BN, totalIfFactor: BN, liquidationIfFactor: BN): Promise<TransactionSignature>;
|
|
36
|
+
updateInsuranceWithdrawEscrowPeriod(marketIndex: BN, insuranceWithdrawEscrowPeriod: BN): Promise<TransactionSignature>;
|
|
36
37
|
updateLpCooldownTime(marketIndex: BN, cooldownTime: BN): Promise<TransactionSignature>;
|
|
37
38
|
updateMarketOracle(marketIndex: BN, oracle: PublicKey, oracleSource: OracleSource): Promise<TransactionSignature>;
|
|
38
39
|
updateMarketMinimumQuoteAssetTradeSize(marketIndex: BN, minimumTradeSize: BN): Promise<TransactionSignature>;
|
|
39
40
|
updateMarketBaseAssetAmountStepSize(marketIndex: BN, stepSize: BN): Promise<TransactionSignature>;
|
|
41
|
+
updateMarketExpiry(perpMarketIndex: BN, expiryTs: BN): Promise<TransactionSignature>;
|
|
40
42
|
updateWhitelistMint(whitelistMint?: PublicKey): Promise<TransactionSignature>;
|
|
41
43
|
updateDiscountMint(discountMint: PublicKey): Promise<TransactionSignature>;
|
|
42
44
|
updateMaxDeposit(maxDeposit: BN): Promise<TransactionSignature>;
|
|
@@ -46,4 +48,5 @@ export declare class Admin extends ClearingHouse {
|
|
|
46
48
|
updateAuctionDuration(minDuration: BN | number, maxDuration: BN | number): Promise<TransactionSignature>;
|
|
47
49
|
updateMaxBaseAssetAmountRatio(marketIndex: BN, maxBaseAssetAmountRatio: number): Promise<TransactionSignature>;
|
|
48
50
|
updateMaxSlippageRatio(marketIndex: BN, maxSlippageRatio: number): Promise<TransactionSignature>;
|
|
51
|
+
updateMarketMaxImbalances(marketIndex: BN, unrealizedMaxImbalance: BN, maxRevenueWithdrawPerPeriod: BN, quoteMaxInsurance: BN): Promise<TransactionSignature>;
|
|
49
52
|
}
|