@drift-labs/sdk 0.2.0-master.3 → 0.2.0-master.30
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 +13 -13
- package/lib/accounts/bulkUserStatsSubscription.d.ts +7 -0
- package/lib/accounts/bulkUserStatsSubscription.js +21 -0
- package/lib/accounts/bulkUserSubscription.js +0 -1
- package/lib/accounts/fetch.d.ts +2 -1
- package/lib/accounts/fetch.js +9 -1
- package/lib/accounts/pollingClearingHouseAccountSubscriber.d.ts +16 -16
- package/lib/accounts/pollingClearingHouseAccountSubscriber.js +31 -28
- package/lib/accounts/pollingUserStatsAccountSubscriber.d.ts +27 -0
- package/lib/accounts/pollingUserStatsAccountSubscriber.js +113 -0
- package/lib/accounts/types.d.ts +22 -11
- package/lib/accounts/webSocketClearingHouseAccountSubscriber.d.ts +17 -17
- package/lib/accounts/webSocketClearingHouseAccountSubscriber.js +37 -35
- package/lib/accounts/webSocketUserStatsAccountSubsriber.d.ts +20 -0
- package/lib/accounts/webSocketUserStatsAccountSubsriber.js +47 -0
- package/lib/addresses/marketAddresses.d.ts +1 -3
- package/lib/addresses/pda.d.ts +10 -4
- package/lib/addresses/pda.js +51 -14
- package/lib/admin.d.ts +34 -22
- package/lib/admin.js +182 -73
- package/lib/clearingHouse.d.ts +120 -42
- package/lib/clearingHouse.js +1505 -254
- package/lib/clearingHouseConfig.d.ts +4 -4
- package/lib/clearingHouseUser.d.ts +50 -38
- package/lib/clearingHouseUser.js +410 -190
- package/lib/clearingHouseUserStats.d.ts +18 -0
- package/lib/clearingHouseUserStats.js +49 -0
- package/lib/clearingHouseUserStatsConfig.d.ts +14 -0
- package/lib/clearingHouseUserStatsConfig.js +2 -0
- package/lib/config.d.ts +7 -9
- package/lib/config.js +21 -21
- package/lib/constants/numericConstants.d.ts +18 -12
- package/lib/constants/numericConstants.js +28 -21
- package/lib/constants/perpMarkets.d.ts +18 -0
- package/lib/constants/{markets.js → perpMarkets.js} +7 -7
- package/lib/constants/spotMarkets.d.ts +19 -0
- package/lib/constants/spotMarkets.js +53 -0
- package/lib/dlob/DLOB.d.ts +73 -0
- package/lib/dlob/DLOB.js +553 -0
- package/lib/dlob/DLOBNode.d.ts +52 -0
- package/lib/dlob/DLOBNode.js +82 -0
- package/lib/dlob/NodeList.d.ts +26 -0
- package/lib/dlob/NodeList.js +138 -0
- package/lib/events/eventList.js +3 -0
- 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/sort.js +8 -11
- package/lib/events/types.d.ts +7 -2
- package/lib/events/types.js +5 -0
- package/lib/examples/makeTradeExample.js +20 -8
- package/lib/factory/bigNum.d.ts +1 -0
- package/lib/factory/bigNum.js +34 -10
- package/lib/idl/clearing_house.json +4313 -1433
- package/lib/idl/{mock_usdc_faucet.json → token_faucet.json} +46 -23
- package/lib/index.d.ts +21 -6
- package/lib/index.js +25 -6
- package/lib/math/amm.d.ts +8 -5
- package/lib/math/amm.js +68 -46
- package/lib/math/auction.js +4 -1
- package/lib/math/conversion.js +1 -1
- package/lib/math/funding.d.ts +6 -6
- package/lib/math/funding.js +11 -10
- package/lib/math/insurance.d.ts +4 -0
- package/lib/math/insurance.js +27 -0
- package/lib/math/margin.d.ts +11 -0
- package/lib/math/margin.js +77 -0
- package/lib/math/market.d.ts +14 -9
- package/lib/math/market.js +69 -7
- package/lib/math/oracles.d.ts +4 -0
- package/lib/math/oracles.js +36 -8
- package/lib/math/orders.d.ts +6 -2
- package/lib/math/orders.js +78 -3
- package/lib/math/position.d.ts +21 -13
- package/lib/math/position.js +76 -36
- package/lib/math/repeg.js +14 -5
- package/lib/math/spotBalance.d.ts +22 -0
- package/lib/math/spotBalance.js +193 -0
- package/lib/math/spotMarket.d.ts +4 -0
- package/lib/math/spotMarket.js +8 -0
- package/lib/math/spotPosition.d.ts +6 -0
- package/lib/math/spotPosition.js +23 -0
- package/lib/math/trade.d.ts +10 -10
- package/lib/math/trade.js +22 -29
- package/lib/oracles/pythClient.js +1 -1
- package/lib/oracles/quoteAssetOracleClient.js +1 -1
- package/lib/oracles/switchboardClient.js +1 -1
- package/lib/orderParams.d.ts +14 -5
- package/lib/orderParams.js +12 -92
- 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/slot/SlotSubscriber.d.ts +7 -0
- package/lib/slot/SlotSubscriber.js +3 -0
- package/lib/{mockUSDCFaucet.d.ts → tokenFaucet.d.ts} +8 -5
- package/lib/{mockUSDCFaucet.js → tokenFaucet.js} +63 -51
- package/lib/tx/retryTxSender.d.ts +1 -1
- package/lib/tx/retryTxSender.js +13 -4
- package/lib/tx/types.d.ts +1 -1
- package/lib/tx/utils.js +1 -1
- package/lib/types.d.ts +474 -123
- package/lib/types.js +99 -5
- package/lib/userMap/userMap.d.ts +25 -0
- package/lib/userMap/userMap.js +73 -0
- package/lib/userMap/userStatsMap.d.ts +19 -0
- package/lib/userMap/userStatsMap.js +68 -0
- package/lib/util/computeUnits.js +1 -1
- package/lib/util/getTokenAddress.d.ts +2 -0
- package/lib/util/getTokenAddress.js +9 -0
- package/package.json +9 -5
- package/src/accounts/bulkUserStatsSubscription.ts +33 -0
- package/src/accounts/bulkUserSubscription.ts +0 -1
- package/src/accounts/fetch.ts +27 -2
- package/src/accounts/pollingClearingHouseAccountSubscriber.ts +46 -42
- package/src/accounts/pollingUserStatsAccountSubscriber.ts +172 -0
- package/src/accounts/types.ts +31 -11
- package/src/accounts/webSocketClearingHouseAccountSubscriber.ts +64 -59
- package/src/accounts/webSocketUserStatsAccountSubsriber.ts +80 -0
- package/src/addresses/marketAddresses.ts +1 -2
- package/src/addresses/pda.ts +88 -14
- package/src/admin.ts +333 -128
- package/src/assert/assert.js +9 -0
- package/src/clearingHouse.ts +2464 -458
- package/src/clearingHouseConfig.ts +4 -3
- package/src/clearingHouseUser.ts +747 -291
- package/src/clearingHouseUserStats.ts +75 -0
- package/src/clearingHouseUserStatsConfig.ts +18 -0
- package/src/config.ts +30 -31
- package/src/constants/numericConstants.ts +41 -25
- package/src/constants/{markets.ts → perpMarkets.ts} +10 -10
- package/src/constants/spotMarkets.ts +72 -0
- package/src/dlob/DLOB.ts +868 -0
- package/src/dlob/DLOBNode.ts +162 -0
- package/src/dlob/NodeList.ts +185 -0
- package/src/events/eventList.js +77 -0
- package/src/events/eventList.ts +3 -0
- package/src/events/eventSubscriber.ts +20 -12
- package/src/events/fetchLogs.ts +35 -8
- package/src/events/pollingLogProvider.ts +10 -2
- package/src/events/sort.ts +11 -15
- package/src/events/types.ts +16 -1
- package/src/examples/makeTradeExample.js +157 -0
- package/src/examples/makeTradeExample.ts +32 -14
- package/src/factory/bigNum.ts +42 -13
- package/src/idl/clearing_house.json +4313 -1433
- package/src/idl/{mock_usdc_faucet.json → token_faucet.json} +46 -23
- package/src/index.ts +21 -6
- package/src/math/amm.ts +136 -66
- package/src/math/auction.ts +5 -1
- package/src/math/conversion.ts +2 -2
- package/src/math/funding.ts +20 -18
- package/src/math/insurance.ts +35 -0
- package/src/math/margin.ts +127 -0
- package/src/math/market.ts +138 -12
- package/src/math/oracles.ts +63 -9
- package/src/math/orders.ts +138 -4
- package/src/math/position.ts +119 -58
- package/src/math/repeg.ts +16 -6
- package/src/math/spotBalance.ts +316 -0
- package/src/math/spotMarket.ts +9 -0
- package/src/math/spotPosition.ts +47 -0
- package/src/math/trade.ts +43 -49
- package/src/oracles/pythClient.ts +2 -2
- package/src/oracles/quoteAssetOracleClient.ts +2 -2
- package/src/oracles/switchboardClient.ts +2 -2
- package/src/orderParams.ts +24 -137
- package/src/serum/serumSubscriber.ts +80 -0
- package/src/serum/types.ts +13 -0
- package/src/slot/SlotSubscriber.ts +11 -1
- package/src/token/index.js +38 -0
- package/src/{mockUSDCFaucet.ts → tokenFaucet.ts} +82 -70
- package/src/tx/retryTxSender.ts +16 -5
- package/src/tx/types.js +2 -0
- package/src/tx/types.ts +2 -1
- package/src/tx/utils.js +17 -0
- package/src/tx/utils.ts +1 -1
- package/src/types.ts +477 -125
- package/src/userMap/userMap.ts +100 -0
- package/src/userMap/userStatsMap.ts +110 -0
- package/src/util/computeUnits.js +21 -11
- package/src/util/computeUnits.ts +1 -1
- package/src/util/getTokenAddress.js +9 -0
- package/src/util/getTokenAddress.ts +18 -0
- package/src/util/promiseTimeout.js +14 -0
- package/src/util/tps.js +27 -0
- package/tests/bn/test.ts +12 -3
- package/tests/dlob/helpers.ts +374 -0
- package/tests/dlob/test.ts +2865 -0
- package/lib/constants/banks.d.ts +0 -16
- package/lib/constants/banks.js +0 -34
- package/lib/constants/markets.d.ts +0 -19
- package/lib/math/bankBalance.d.ts +0 -9
- package/lib/math/bankBalance.js +0 -75
- package/lib/math/state.d.ts +0 -8
- package/lib/math/state.js +0 -15
- package/lib/orders.d.ts +0 -8
- package/lib/orders.js +0 -134
- package/src/constants/banks.ts +0 -43
- package/src/math/bankBalance.ts +0 -112
- package/src/math/state.ts +0 -14
- package/src/math/utils.js +0 -27
- package/src/math/utils.js.map +0 -1
- package/src/orders.ts +0 -244
- package/src/util/computeUnits.js.map +0 -1
|
@@ -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, 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, 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)) {
|
|
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)) {
|
|
149
149
|
return true;
|
|
150
150
|
}
|
|
151
151
|
return this.subscribeToMarketAccount(marketIndex);
|
|
@@ -170,15 +170,17 @@ class WebSocketClearingHouseAccountSubscriber {
|
|
|
170
170
|
}
|
|
171
171
|
getMarketAccountAndSlot(marketIndex) {
|
|
172
172
|
this.assertIsSubscribed();
|
|
173
|
-
return this.
|
|
174
|
-
.dataAndSlot;
|
|
173
|
+
return this.perpMarketAccountSubscribers.get(marketIndex).dataAndSlot;
|
|
175
174
|
}
|
|
176
175
|
getMarketAccountsAndSlots() {
|
|
177
|
-
return Array.from(this.
|
|
176
|
+
return Array.from(this.perpMarketAccountSubscribers.values()).map((subscriber) => subscriber.dataAndSlot);
|
|
178
177
|
}
|
|
179
|
-
|
|
178
|
+
getSpotMarketAccountAndSlot(marketIndex) {
|
|
180
179
|
this.assertIsSubscribed();
|
|
181
|
-
return this.
|
|
180
|
+
return this.spotMarketAccountSubscribers.get(marketIndex).dataAndSlot;
|
|
181
|
+
}
|
|
182
|
+
getSpotMarketAccountsAndSlots() {
|
|
183
|
+
return Array.from(this.spotMarketAccountSubscribers.values()).map((subscriber) => subscriber.dataAndSlot);
|
|
182
184
|
}
|
|
183
185
|
getOraclePriceDataAndSlot(oraclePublicKey) {
|
|
184
186
|
this.assertIsSubscribed();
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { DataAndSlot, AccountSubscriber, UserStatsAccountSubscriber, UserStatsAccountEvents } from './types';
|
|
3
|
+
import { Program } from '@project-serum/anchor';
|
|
4
|
+
import StrictEventEmitter from 'strict-event-emitter-types';
|
|
5
|
+
import { EventEmitter } from 'events';
|
|
6
|
+
import { PublicKey } from '@solana/web3.js';
|
|
7
|
+
import { UserStatsAccount } from '../types';
|
|
8
|
+
export declare class WebSocketUserStatsAccountSubscriber implements UserStatsAccountSubscriber {
|
|
9
|
+
isSubscribed: boolean;
|
|
10
|
+
program: Program;
|
|
11
|
+
eventEmitter: StrictEventEmitter<EventEmitter, UserStatsAccountEvents>;
|
|
12
|
+
userStatsAccountPublicKey: PublicKey;
|
|
13
|
+
userStatsAccountSubscriber: AccountSubscriber<UserStatsAccount>;
|
|
14
|
+
constructor(program: Program, userStatsAccountPublicKey: PublicKey);
|
|
15
|
+
subscribe(): Promise<boolean>;
|
|
16
|
+
fetch(): Promise<void>;
|
|
17
|
+
unsubscribe(): Promise<void>;
|
|
18
|
+
assertIsSubscribed(): void;
|
|
19
|
+
getUserStatsAccountAndSlot(): DataAndSlot<UserStatsAccount>;
|
|
20
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WebSocketUserStatsAccountSubscriber = void 0;
|
|
4
|
+
const types_1 = require("./types");
|
|
5
|
+
const events_1 = require("events");
|
|
6
|
+
const webSocketAccountSubscriber_1 = require("./webSocketAccountSubscriber");
|
|
7
|
+
class WebSocketUserStatsAccountSubscriber {
|
|
8
|
+
constructor(program, userStatsAccountPublicKey) {
|
|
9
|
+
this.isSubscribed = false;
|
|
10
|
+
this.program = program;
|
|
11
|
+
this.userStatsAccountPublicKey = userStatsAccountPublicKey;
|
|
12
|
+
this.eventEmitter = new events_1.EventEmitter();
|
|
13
|
+
}
|
|
14
|
+
async subscribe() {
|
|
15
|
+
if (this.isSubscribed) {
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
this.userStatsAccountSubscriber = new webSocketAccountSubscriber_1.WebSocketAccountSubscriber('userStats', this.program, this.userStatsAccountPublicKey);
|
|
19
|
+
await this.userStatsAccountSubscriber.subscribe((data) => {
|
|
20
|
+
this.eventEmitter.emit('userStatsAccountUpdate', data);
|
|
21
|
+
this.eventEmitter.emit('update');
|
|
22
|
+
});
|
|
23
|
+
this.eventEmitter.emit('update');
|
|
24
|
+
this.isSubscribed = true;
|
|
25
|
+
return true;
|
|
26
|
+
}
|
|
27
|
+
async fetch() {
|
|
28
|
+
await Promise.all([this.userStatsAccountSubscriber.fetch()]);
|
|
29
|
+
}
|
|
30
|
+
async unsubscribe() {
|
|
31
|
+
if (!this.isSubscribed) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
await Promise.all([this.userStatsAccountSubscriber.unsubscribe()]);
|
|
35
|
+
this.isSubscribed = false;
|
|
36
|
+
}
|
|
37
|
+
assertIsSubscribed() {
|
|
38
|
+
if (!this.isSubscribed) {
|
|
39
|
+
throw new types_1.NotSubscribedError('You must call `subscribe` before using this function');
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
getUserStatsAccountAndSlot() {
|
|
43
|
+
this.assertIsSubscribed();
|
|
44
|
+
return this.userStatsAccountSubscriber.dataAndSlot;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
exports.WebSocketUserStatsAccountSubscriber = WebSocketUserStatsAccountSubscriber;
|
|
@@ -1,4 +1,2 @@
|
|
|
1
|
-
/// <reference types="bn.js" />
|
|
2
1
|
import { PublicKey } from '@solana/web3.js';
|
|
3
|
-
|
|
4
|
-
export declare function getMarketAddress(programId: PublicKey, marketIndex: BN): Promise<PublicKey>;
|
|
2
|
+
export declare function getMarketAddress(programId: PublicKey, marketIndex: number): Promise<PublicKey>;
|
package/lib/addresses/pda.d.ts
CHANGED
|
@@ -6,7 +6,13 @@ export declare function getClearingHouseStateAccountPublicKey(programId: PublicK
|
|
|
6
6
|
export declare function getUserAccountPublicKeyAndNonce(programId: PublicKey, authority: PublicKey, userId?: number): Promise<[PublicKey, number]>;
|
|
7
7
|
export declare function getUserAccountPublicKey(programId: PublicKey, authority: PublicKey, userId?: number): Promise<PublicKey>;
|
|
8
8
|
export declare function getUserAccountPublicKeySync(programId: PublicKey, authority: PublicKey, userId?: number): PublicKey;
|
|
9
|
-
export declare function
|
|
10
|
-
export declare function
|
|
11
|
-
export declare function
|
|
12
|
-
export declare function
|
|
9
|
+
export declare function getUserStatsAccountPublicKey(programId: PublicKey, authority: PublicKey): PublicKey;
|
|
10
|
+
export declare function getMarketPublicKey(programId: PublicKey, marketIndex: number): Promise<PublicKey>;
|
|
11
|
+
export declare function getSpotMarketPublicKey(programId: PublicKey, marketIndex: number): Promise<PublicKey>;
|
|
12
|
+
export declare function getSpotMarketVaultPublicKey(programId: PublicKey, marketIndex: number): Promise<PublicKey>;
|
|
13
|
+
export declare function getInsuranceFundVaultPublicKey(programId: PublicKey, marketIndex: number): Promise<PublicKey>;
|
|
14
|
+
export declare function getInsuranceFundStakeAccountPublicKey(programId: PublicKey, authority: PublicKey, marketIndex: number): 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);
|
|
@@ -53,31 +53,68 @@ function getUserAccountPublicKeySync(programId, authority, userId = 0) {
|
|
|
53
53
|
], programId)[0];
|
|
54
54
|
}
|
|
55
55
|
exports.getUserAccountPublicKeySync = getUserAccountPublicKeySync;
|
|
56
|
+
function getUserStatsAccountPublicKey(programId, authority) {
|
|
57
|
+
return anchor.web3.PublicKey.findProgramAddressSync([
|
|
58
|
+
Buffer.from(anchor.utils.bytes.utf8.encode('user_stats')),
|
|
59
|
+
authority.toBuffer(),
|
|
60
|
+
], programId)[0];
|
|
61
|
+
}
|
|
62
|
+
exports.getUserStatsAccountPublicKey = getUserStatsAccountPublicKey;
|
|
56
63
|
async function getMarketPublicKey(programId, marketIndex) {
|
|
57
64
|
return (await anchor.web3.PublicKey.findProgramAddress([
|
|
58
65
|
Buffer.from(anchor.utils.bytes.utf8.encode('market')),
|
|
59
|
-
marketIndex.toArrayLike(Buffer, 'le',
|
|
66
|
+
new anchor.BN(marketIndex).toArrayLike(Buffer, 'le', 2),
|
|
60
67
|
], programId))[0];
|
|
61
68
|
}
|
|
62
69
|
exports.getMarketPublicKey = getMarketPublicKey;
|
|
63
|
-
async function
|
|
70
|
+
async function getSpotMarketPublicKey(programId, marketIndex) {
|
|
64
71
|
return (await anchor.web3.PublicKey.findProgramAddress([
|
|
65
|
-
Buffer.from(anchor.utils.bytes.utf8.encode('
|
|
66
|
-
|
|
72
|
+
Buffer.from(anchor.utils.bytes.utf8.encode('spot_market')),
|
|
73
|
+
new anchor.BN(marketIndex).toArrayLike(Buffer, 'le', 2),
|
|
67
74
|
], programId))[0];
|
|
68
75
|
}
|
|
69
|
-
exports.
|
|
70
|
-
async function
|
|
76
|
+
exports.getSpotMarketPublicKey = getSpotMarketPublicKey;
|
|
77
|
+
async function getSpotMarketVaultPublicKey(programId, marketIndex) {
|
|
71
78
|
return (await anchor.web3.PublicKey.findProgramAddress([
|
|
72
|
-
Buffer.from(anchor.utils.bytes.utf8.encode('
|
|
73
|
-
|
|
79
|
+
Buffer.from(anchor.utils.bytes.utf8.encode('spot_market_vault')),
|
|
80
|
+
new anchor.BN(marketIndex).toArrayLike(Buffer, 'le', 2),
|
|
74
81
|
], programId))[0];
|
|
75
82
|
}
|
|
76
|
-
exports.
|
|
77
|
-
async function
|
|
83
|
+
exports.getSpotMarketVaultPublicKey = getSpotMarketVaultPublicKey;
|
|
84
|
+
async function getInsuranceFundVaultPublicKey(programId, marketIndex) {
|
|
78
85
|
return (await anchor.web3.PublicKey.findProgramAddress([
|
|
79
|
-
Buffer.from(anchor.utils.bytes.utf8.encode('
|
|
80
|
-
|
|
86
|
+
Buffer.from(anchor.utils.bytes.utf8.encode('insurance_fund_vault')),
|
|
87
|
+
new anchor.BN(marketIndex).toArrayLike(Buffer, 'le', 2),
|
|
81
88
|
], programId))[0];
|
|
82
89
|
}
|
|
83
|
-
exports.
|
|
90
|
+
exports.getInsuranceFundVaultPublicKey = getInsuranceFundVaultPublicKey;
|
|
91
|
+
function getInsuranceFundStakeAccountPublicKey(programId, authority, marketIndex) {
|
|
92
|
+
return anchor.web3.PublicKey.findProgramAddressSync([
|
|
93
|
+
Buffer.from(anchor.utils.bytes.utf8.encode('insurance_fund_stake')),
|
|
94
|
+
authority.toBuffer(),
|
|
95
|
+
new anchor.BN(marketIndex).toArrayLike(Buffer, 'le', 2),
|
|
96
|
+
], programId)[0];
|
|
97
|
+
}
|
|
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
|
@@ -1,42 +1,54 @@
|
|
|
1
1
|
/// <reference types="bn.js" />
|
|
2
2
|
import { PublicKey, TransactionSignature } from '@solana/web3.js';
|
|
3
|
-
import { FeeStructure, OracleGuardRails, OracleSource
|
|
3
|
+
import { FeeStructure, OracleGuardRails, OracleSource } 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
|
initialize(usdcMint: PublicKey, adminControlsPrices: boolean): Promise<[TransactionSignature]>;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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: number, serumMarket: PublicKey, serumProgram: PublicKey): Promise<TransactionSignature>;
|
|
10
|
+
initializeMarket(priceOracle: PublicKey, baseAssetReserve: BN, quoteAssetReserve: BN, periodicity: BN, pegMultiplier?: BN, oracleSource?: OracleSource, marginRatioInitial?: number, marginRatioMaintenance?: number, liquidationFee?: BN): Promise<TransactionSignature>;
|
|
11
|
+
moveAmmPrice(marketIndex: number, baseAssetReserve: BN, quoteAssetReserve: BN, sqrtK?: BN): Promise<TransactionSignature>;
|
|
12
|
+
updateK(sqrtK: BN, marketIndex: number): Promise<TransactionSignature>;
|
|
13
|
+
updateConcentrationScale(marketIndex: number, concentrationScale: BN): Promise<TransactionSignature>;
|
|
14
|
+
moveAmmToPrice(perpMarketIndex: number, targetPrice: BN): Promise<TransactionSignature>;
|
|
15
|
+
repegAmmCurve(newPeg: BN, marketIndex: number): Promise<TransactionSignature>;
|
|
16
|
+
updateAmmOracleTwap(marketIndex: number): Promise<TransactionSignature>;
|
|
17
|
+
resetAmmOracleTwap(marketIndex: number): Promise<TransactionSignature>;
|
|
18
|
+
depositIntoMarketFeePool(marketIndex: number, amount: BN, sourceVault: PublicKey): Promise<TransactionSignature>;
|
|
19
19
|
updateAdmin(admin: PublicKey): Promise<TransactionSignature>;
|
|
20
|
-
updateCurveUpdateIntensity(marketIndex:
|
|
21
|
-
updateMarginRatio(marketIndex:
|
|
22
|
-
updateMarketBaseSpread(marketIndex:
|
|
23
|
-
|
|
20
|
+
updateCurveUpdateIntensity(marketIndex: number, curveUpdateIntensity: number): Promise<TransactionSignature>;
|
|
21
|
+
updateMarginRatio(marketIndex: number, marginRatioInitial: number, marginRatioMaintenance: number): Promise<TransactionSignature>;
|
|
22
|
+
updateMarketBaseSpread(marketIndex: number, baseSpread: number): Promise<TransactionSignature>;
|
|
23
|
+
updateAmmJitIntensity(marketIndex: number, ammJitIntensity: number): Promise<TransactionSignature>;
|
|
24
|
+
updateMarketMaxSpread(marketIndex: number, maxSpread: number): Promise<TransactionSignature>;
|
|
24
25
|
updatePartialLiquidationClosePercentage(numerator: BN, denominator: BN): Promise<TransactionSignature>;
|
|
25
26
|
updatePartialLiquidationPenaltyPercentage(numerator: BN, denominator: BN): Promise<TransactionSignature>;
|
|
26
27
|
updateFullLiquidationPenaltyPercentage(numerator: BN, denominator: BN): Promise<TransactionSignature>;
|
|
27
28
|
updatePartialLiquidationShareDenominator(denominator: BN): Promise<TransactionSignature>;
|
|
28
29
|
updateFullLiquidationShareDenominator(denominator: BN): Promise<TransactionSignature>;
|
|
29
|
-
|
|
30
|
-
|
|
30
|
+
updatePerpFeeStructure(feeStructure: FeeStructure): Promise<TransactionSignature>;
|
|
31
|
+
updateSpotFeeStructure(feeStructure: FeeStructure): Promise<TransactionSignature>;
|
|
31
32
|
updateOracleGuardRails(oracleGuardRails: OracleGuardRails): Promise<TransactionSignature>;
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
updateWithdrawGuardThreshold(marketIndex: number, withdrawGuardThreshold: BN): Promise<TransactionSignature>;
|
|
34
|
+
updateSpotMarketIfFactor(marketIndex: number, userIfFactor: BN, totalIfFactor: BN): Promise<TransactionSignature>;
|
|
35
|
+
updateSpotMarketRevenueSettlePeriod(marketIndex: number, revenueSettlePeriod: BN): Promise<TransactionSignature>;
|
|
36
|
+
updateInsuranceWithdrawEscrowPeriod(marketIndex: number, insuranceWithdrawEscrowPeriod: BN): Promise<TransactionSignature>;
|
|
37
|
+
updateLpCooldownTime(marketIndex: number, cooldownTime: BN): Promise<TransactionSignature>;
|
|
38
|
+
updateMarketOracle(marketIndex: number, oracle: PublicKey, oracleSource: OracleSource): Promise<TransactionSignature>;
|
|
39
|
+
updateMarketMinimumQuoteAssetTradeSize(marketIndex: number, minimumTradeSize: BN): Promise<TransactionSignature>;
|
|
40
|
+
updateMarketBaseAssetAmountStepSize(marketIndex: number, stepSize: BN): Promise<TransactionSignature>;
|
|
41
|
+
updateMarketExpiry(perpMarketIndex: number, expiryTs: BN): Promise<TransactionSignature>;
|
|
35
42
|
updateWhitelistMint(whitelistMint?: PublicKey): Promise<TransactionSignature>;
|
|
36
43
|
updateDiscountMint(discountMint: PublicKey): Promise<TransactionSignature>;
|
|
37
44
|
updateMaxDeposit(maxDeposit: BN): Promise<TransactionSignature>;
|
|
38
45
|
updateFundingPaused(fundingPaused: boolean): Promise<TransactionSignature>;
|
|
39
46
|
updateExchangePaused(exchangePaused: boolean): Promise<TransactionSignature>;
|
|
40
47
|
disableAdminControlsPrices(): Promise<TransactionSignature>;
|
|
41
|
-
|
|
48
|
+
updatePerpAuctionDuration(minDuration: BN | number): Promise<TransactionSignature>;
|
|
49
|
+
updateSpotAuctionDuration(defaultAuctionDuration: number): Promise<TransactionSignature>;
|
|
50
|
+
updateMaxBaseAssetAmountRatio(marketIndex: number, maxBaseAssetAmountRatio: number): Promise<TransactionSignature>;
|
|
51
|
+
updateMaxSlippageRatio(marketIndex: number, maxSlippageRatio: number): Promise<TransactionSignature>;
|
|
52
|
+
updateMarketMaxImbalances(marketIndex: number, unrealizedMaxImbalance: BN, maxRevenueWithdrawPerPeriod: BN, quoteMaxInsurance: BN): Promise<TransactionSignature>;
|
|
53
|
+
updateSerumVault(srmVault: PublicKey): Promise<TransactionSignature>;
|
|
42
54
|
}
|