@drift-labs/sdk 0.2.0-master.38 → 0.2.0-master.39
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 +14 -14
- package/lib/accounts/bulkUserStatsSubscription.d.ts +2 -2
- package/lib/accounts/bulkUserSubscription.d.ts +2 -2
- package/lib/accounts/{pollingClearingHouseAccountSubscriber.d.ts → pollingDriftClientAccountSubscriber.d.ts} +3 -8
- package/lib/accounts/{pollingClearingHouseAccountSubscriber.js → pollingDriftClientAccountSubscriber.js} +6 -13
- package/lib/accounts/{pollingOracleSubscriber.d.ts → pollingOracleAccountSubscriber.d.ts} +2 -2
- package/lib/accounts/{pollingOracleSubscriber.js → pollingOracleAccountSubscriber.js} +3 -3
- package/lib/accounts/types.d.ts +4 -4
- package/lib/accounts/{webSocketClearingHouseAccountSubscriber.d.ts → webSocketDriftClientAccountSubscriber.d.ts} +3 -3
- package/lib/accounts/{webSocketClearingHouseAccountSubscriber.js → webSocketDriftClientAccountSubscriber.js} +4 -4
- package/lib/addresses/pda.d.ts +3 -3
- package/lib/addresses/pda.js +10 -10
- package/lib/{admin.d.ts → adminClient.d.ts} +9 -4
- package/lib/{admin.js → adminClient.js} +62 -15
- package/lib/config.js +1 -1
- package/lib/constants/numericConstants.d.ts +3 -0
- package/lib/constants/numericConstants.js +5 -2
- package/lib/dlob/DLOB.d.ts +2 -2
- package/lib/dlob/DLOB.js +4 -4
- package/lib/{clearingHouse.d.ts → driftClient.d.ts} +20 -20
- package/lib/{clearingHouse.js → driftClient.js} +28 -28
- package/lib/{clearingHouseConfig.d.ts → driftClientConfig.d.ts} +3 -3
- package/lib/{clearingHouseConfig.js → driftClientConfig.js} +0 -0
- package/lib/examples/makeTradeExample.js +13 -13
- package/lib/idl/{clearing_house.json → drift.json} +603 -119
- package/lib/index.d.ts +10 -10
- package/lib/index.js +10 -10
- package/lib/math/orders.d.ts +4 -4
- package/lib/math/orders.js +3 -3
- package/lib/serum/serumFulfillmentConfigMap.d.ts +3 -3
- package/lib/serum/serumFulfillmentConfigMap.js +3 -3
- package/lib/types.d.ts +38 -2
- package/lib/types.js +2 -1
- package/lib/{clearingHouseUser.d.ts → user.d.ts} +16 -10
- package/lib/{clearingHouseUser.js → user.js} +53 -45
- package/lib/userConfig.d.ts +14 -0
- package/lib/{clearingHouseUserConfig.js → userConfig.js} +0 -0
- package/lib/userMap/userMap.d.ts +17 -17
- package/lib/userMap/userMap.js +15 -15
- package/lib/userMap/userStatsMap.d.ts +7 -7
- package/lib/userMap/userStatsMap.js +10 -10
- package/lib/{clearingHouseUserStats.d.ts → userStats.d.ts} +5 -5
- package/lib/{clearingHouseUserStats.js → userStats.js} +8 -8
- package/lib/userStatsConfig.d.ts +14 -0
- package/lib/{clearingHouseUserStatsConfig.js → userStatsConfig.js} +0 -0
- package/package.json +1 -1
- package/src/accounts/bulkUserStatsSubscription.ts +2 -2
- package/src/accounts/bulkUserSubscription.ts +2 -2
- package/src/accounts/{pollingClearingHouseAccountSubscriber.ts → pollingDriftClientAccountSubscriber.ts} +11 -25
- package/src/accounts/{pollingOracleSubscriber.ts → pollingOracleAccountSubscriber.ts} +2 -2
- package/src/accounts/types.ts +4 -4
- package/src/accounts/{webSocketClearingHouseAccountSubscriber.ts → webSocketDriftClientAccountSubscriber.ts} +7 -7
- package/src/addresses/pda.ts +6 -8
- package/src/{admin.ts → adminClient.ts} +125 -18
- package/src/config.ts +1 -1
- package/src/constants/numericConstants.ts +4 -0
- package/src/dlob/DLOB.ts +5 -5
- package/src/{clearingHouse.ts → driftClient.ts} +45 -47
- package/src/{clearingHouseConfig.ts → driftClientConfig.ts} +3 -3
- package/src/examples/makeTradeExample.ts +15 -17
- package/src/idl/{clearing_house.json → drift.json} +603 -119
- package/src/index.ts +10 -10
- package/src/math/orders.ts +7 -13
- package/src/serum/serumFulfillmentConfigMap.ts +5 -5
- package/src/types.ts +41 -2
- package/src/{clearingHouseUser.ts → user.ts} +59 -53
- package/src/{clearingHouseUserConfig.ts → userConfig.ts} +5 -5
- package/src/userMap/userMap.ts +29 -29
- package/src/userMap/userStatsMap.ts +21 -23
- package/src/{clearingHouseUserStats.ts → userStats.ts} +10 -10
- package/src/userStatsConfig.ts +18 -0
- package/tests/dlob/helpers.ts +55 -13
- package/lib/clearingHouseUserConfig.d.ts +0 -14
- package/lib/clearingHouseUserStatsConfig.d.ts +0 -14
- package/src/clearingHouseUserStatsConfig.ts +0 -18
package/README.md
CHANGED
|
@@ -89,8 +89,8 @@ import { Token, TOKEN_PROGRAM_ID } from '@solana/spl-token';
|
|
|
89
89
|
import { Connection, Keypair, PublicKey } from '@solana/web3.js';
|
|
90
90
|
import {
|
|
91
91
|
calculateReservePrice,
|
|
92
|
-
|
|
93
|
-
|
|
92
|
+
DriftClient,
|
|
93
|
+
User,
|
|
94
94
|
initialize,
|
|
95
95
|
Markets,
|
|
96
96
|
PositionDirection,
|
|
@@ -141,19 +141,19 @@ const main = async () => {
|
|
|
141
141
|
wallet.publicKey.toString()
|
|
142
142
|
);
|
|
143
143
|
|
|
144
|
-
// Set up the Drift
|
|
145
|
-
const
|
|
144
|
+
// Set up the Drift Client
|
|
145
|
+
const driftClientPublicKey = new PublicKey(
|
|
146
146
|
sdkConfig.CLEARING_HOUSE_PROGRAM_ID
|
|
147
147
|
);
|
|
148
|
-
const
|
|
148
|
+
const driftClient = DriftClient.from(
|
|
149
149
|
connection,
|
|
150
150
|
provider.wallet,
|
|
151
|
-
|
|
151
|
+
driftClientPublicKey
|
|
152
152
|
);
|
|
153
|
-
await
|
|
153
|
+
await driftClient.subscribe();
|
|
154
154
|
|
|
155
155
|
// Set up Clearing House user client
|
|
156
|
-
const user =
|
|
156
|
+
const user = User.from(driftClient, wallet.publicKey);
|
|
157
157
|
|
|
158
158
|
//// Check if clearing house account exists for the current wallet
|
|
159
159
|
const userAccountExists = await user.exists();
|
|
@@ -161,7 +161,7 @@ const main = async () => {
|
|
|
161
161
|
if (!userAccountExists) {
|
|
162
162
|
//// Create a Clearing House account by Depositing some USDC ($10,000 in this case)
|
|
163
163
|
const depositAmount = new BN(10000).mul(QUOTE_PRECISION);
|
|
164
|
-
await
|
|
164
|
+
await driftClient.initializeUserAccountAndDepositCollateral(
|
|
165
165
|
depositAmount,
|
|
166
166
|
await getTokenAddress(
|
|
167
167
|
usdcTokenAddress.toString(),
|
|
@@ -178,7 +178,7 @@ const main = async () => {
|
|
|
178
178
|
);
|
|
179
179
|
|
|
180
180
|
const currentMarketPrice = calculateReservePrice(
|
|
181
|
-
|
|
181
|
+
driftClient.getMarket(solMarketInfo.marketIndex)
|
|
182
182
|
);
|
|
183
183
|
|
|
184
184
|
const formattedPrice = convertToNumber(currentMarketPrice, PRICE_PRECISION);
|
|
@@ -186,7 +186,7 @@ const main = async () => {
|
|
|
186
186
|
console.log(`Current Market Price is $${formattedPrice}`);
|
|
187
187
|
|
|
188
188
|
// Estimate the slippage for a $5000 LONG trade
|
|
189
|
-
const solMarketAccount =
|
|
189
|
+
const solMarketAccount = driftClient.getMarket(solMarketInfo.marketIndex);
|
|
190
190
|
|
|
191
191
|
const slippage = convertToNumber(
|
|
192
192
|
calculateTradeSlippage(
|
|
@@ -202,7 +202,7 @@ const main = async () => {
|
|
|
202
202
|
);
|
|
203
203
|
|
|
204
204
|
// Make a $5000 LONG trade
|
|
205
|
-
await
|
|
205
|
+
await driftClient.openPosition(
|
|
206
206
|
PositionDirection.LONG,
|
|
207
207
|
new BN(5000).mul(QUOTE_PRECISION),
|
|
208
208
|
solMarketInfo.marketIndex
|
|
@@ -210,14 +210,14 @@ const main = async () => {
|
|
|
210
210
|
console.log(`LONGED $5000 worth of SOL`);
|
|
211
211
|
|
|
212
212
|
// Reduce the position by $2000
|
|
213
|
-
await
|
|
213
|
+
await driftClient.openPosition(
|
|
214
214
|
PositionDirection.SHORT,
|
|
215
215
|
new BN(2000).mul(QUOTE_PRECISION),
|
|
216
216
|
solMarketInfo.marketIndex
|
|
217
217
|
);
|
|
218
218
|
|
|
219
219
|
// Close the rest of the position
|
|
220
|
-
await
|
|
220
|
+
await driftClient.closePosition(solMarketInfo.marketIndex);
|
|
221
221
|
};
|
|
222
222
|
|
|
223
223
|
main();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { UserStats } from '../userStats';
|
|
2
2
|
import { BulkAccountLoader } from './bulkAccountLoader';
|
|
3
3
|
/**
|
|
4
4
|
* @param userStats
|
|
5
5
|
* @param accountLoader
|
|
6
6
|
*/
|
|
7
|
-
export declare function bulkPollingUserStatsSubscribe(userStats:
|
|
7
|
+
export declare function bulkPollingUserStatsSubscribe(userStats: UserStats[], accountLoader: BulkAccountLoader): Promise<void>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { User } from '../user';
|
|
2
2
|
import { BulkAccountLoader } from './bulkAccountLoader';
|
|
3
3
|
/**
|
|
4
4
|
* @param users
|
|
5
5
|
* @param accountLoader
|
|
6
6
|
*/
|
|
7
|
-
export declare function bulkPollingUserSubscribe(users:
|
|
7
|
+
export declare function bulkPollingUserSubscribe(users: User[], accountLoader: BulkAccountLoader): Promise<void>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { DataAndSlot, AccountToPoll,
|
|
2
|
+
import { DataAndSlot, AccountToPoll, DriftClientAccountEvents, DriftClientAccountSubscriber, OraclesToPoll } from './types';
|
|
3
3
|
import { Program } from '@project-serum/anchor';
|
|
4
4
|
import StrictEventEmitter from 'strict-event-emitter-types';
|
|
5
5
|
import { EventEmitter } from 'events';
|
|
@@ -8,14 +8,14 @@ import { BulkAccountLoader } from './bulkAccountLoader';
|
|
|
8
8
|
import { PublicKey } from '@solana/web3.js';
|
|
9
9
|
import { OracleInfo, OraclePriceData } from '../oracles/types';
|
|
10
10
|
import { OracleClientCache } from '../oracles/oracleClientCache';
|
|
11
|
-
export declare class
|
|
11
|
+
export declare class PollingDriftClientAccountSubscriber implements DriftClientAccountSubscriber {
|
|
12
12
|
isSubscribed: boolean;
|
|
13
13
|
program: Program;
|
|
14
14
|
perpMarketIndexes: number[];
|
|
15
15
|
spotMarketIndexes: number[];
|
|
16
16
|
oracleInfos: OracleInfo[];
|
|
17
17
|
oracleClientCache: OracleClientCache;
|
|
18
|
-
eventEmitter: StrictEventEmitter<EventEmitter,
|
|
18
|
+
eventEmitter: StrictEventEmitter<EventEmitter, DriftClientAccountEvents>;
|
|
19
19
|
accountLoader: BulkAccountLoader;
|
|
20
20
|
accountsToPoll: Map<string, AccountToPoll>;
|
|
21
21
|
oraclesToPoll: Map<string, OraclesToPoll>;
|
|
@@ -37,7 +37,6 @@ export declare class PollingClearingHouseAccountSubscriber implements ClearingHo
|
|
|
37
37
|
addSpotMarketAccountToPoll(marketIndex: number): Promise<boolean>;
|
|
38
38
|
updateOraclesToPoll(): boolean;
|
|
39
39
|
addOracleToPoll(oracleInfo: OracleInfo): boolean;
|
|
40
|
-
getClearingHouseAccounts(): Promise<ClearingHouseAccounts>;
|
|
41
40
|
addToAccountLoader(): Promise<void>;
|
|
42
41
|
addAccountToAccountLoader(accountToPoll: AccountToPoll): void;
|
|
43
42
|
addOracleToAccountLoader(oracleToPoll: OraclesToPoll): void;
|
|
@@ -55,7 +54,3 @@ export declare class PollingClearingHouseAccountSubscriber implements ClearingHo
|
|
|
55
54
|
getSpotMarketAccountsAndSlots(): DataAndSlot<SpotMarketAccount>[];
|
|
56
55
|
getOraclePriceDataAndSlot(oraclePublicKey: PublicKey): DataAndSlot<OraclePriceData> | undefined;
|
|
57
56
|
}
|
|
58
|
-
declare type ClearingHouseAccounts = {
|
|
59
|
-
state: PublicKey;
|
|
60
|
-
};
|
|
61
|
-
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.PollingDriftClientAccountSubscriber = void 0;
|
|
4
4
|
const types_1 = require("./types");
|
|
5
5
|
const events_1 = require("events");
|
|
6
6
|
const pda_1 = require("../addresses/pda");
|
|
@@ -8,7 +8,7 @@ const utils_1 = require("./utils");
|
|
|
8
8
|
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
|
-
class
|
|
11
|
+
class PollingDriftClientAccountSubscriber {
|
|
12
12
|
constructor(program, accountLoader, perpMarketIndexes, spotMarketIndexes, oracleInfos) {
|
|
13
13
|
this.oracleClientCache = new oracleClientCache_1.OracleClientCache();
|
|
14
14
|
this.accountsToPoll = new Map();
|
|
@@ -58,10 +58,10 @@ class PollingClearingHouseAccountSubscriber {
|
|
|
58
58
|
if (this.accountsToPoll.size > 0) {
|
|
59
59
|
return;
|
|
60
60
|
}
|
|
61
|
-
const
|
|
62
|
-
this.accountsToPoll.set(
|
|
61
|
+
const statePublicKey = await (0, pda_1.getDriftStateAccountPublicKey)(this.program.programId);
|
|
62
|
+
this.accountsToPoll.set(statePublicKey.toString(), {
|
|
63
63
|
key: 'state',
|
|
64
|
-
publicKey:
|
|
64
|
+
publicKey: statePublicKey,
|
|
65
65
|
eventType: 'stateAccountUpdate',
|
|
66
66
|
});
|
|
67
67
|
await this.updatePerpMarketAccountsToPoll();
|
|
@@ -114,13 +114,6 @@ class PollingClearingHouseAccountSubscriber {
|
|
|
114
114
|
});
|
|
115
115
|
return true;
|
|
116
116
|
}
|
|
117
|
-
async getClearingHouseAccounts() {
|
|
118
|
-
const statePublicKey = await (0, pda_1.getClearingHouseStateAccountPublicKey)(this.program.programId);
|
|
119
|
-
const accounts = {
|
|
120
|
-
state: statePublicKey,
|
|
121
|
-
};
|
|
122
|
-
return accounts;
|
|
123
|
-
}
|
|
124
117
|
async addToAccountLoader() {
|
|
125
118
|
for (const [_, accountToPoll] of this.accountsToPoll) {
|
|
126
119
|
this.addAccountToAccountLoader(accountToPoll);
|
|
@@ -276,4 +269,4 @@ class PollingClearingHouseAccountSubscriber {
|
|
|
276
269
|
return this.oracles.get(oraclePublicKey.toString());
|
|
277
270
|
}
|
|
278
271
|
}
|
|
279
|
-
exports.
|
|
272
|
+
exports.PollingDriftClientAccountSubscriber = PollingDriftClientAccountSubscriber;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { DataAndSlot, OracleEvents,
|
|
2
|
+
import { DataAndSlot, OracleEvents, OracleAccountSubscriber } from './types';
|
|
3
3
|
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
7
|
import { BulkAccountLoader } from './bulkAccountLoader';
|
|
8
8
|
import { OracleClient, OraclePriceData } from '../oracles/types';
|
|
9
|
-
export declare class
|
|
9
|
+
export declare class PollingOracleAccountSubscriber implements OracleAccountSubscriber {
|
|
10
10
|
isSubscribed: boolean;
|
|
11
11
|
program: Program;
|
|
12
12
|
eventEmitter: StrictEventEmitter<EventEmitter, OracleEvents>;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.PollingOracleAccountSubscriber = void 0;
|
|
4
4
|
const types_1 = require("./types");
|
|
5
5
|
const events_1 = require("events");
|
|
6
|
-
class
|
|
6
|
+
class PollingOracleAccountSubscriber {
|
|
7
7
|
constructor(publicKey, oracleClient, accountLoader) {
|
|
8
8
|
this.isSubscribed = false;
|
|
9
9
|
this.publicKey = publicKey;
|
|
@@ -75,4 +75,4 @@ class PollingOracleSubscriber {
|
|
|
75
75
|
return !!this.oraclePriceData;
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
|
-
exports.
|
|
78
|
+
exports.PollingOracleAccountSubscriber = PollingOracleAccountSubscriber;
|
package/lib/accounts/types.d.ts
CHANGED
|
@@ -15,7 +15,7 @@ export interface AccountSubscriber<T> {
|
|
|
15
15
|
export declare class NotSubscribedError extends Error {
|
|
16
16
|
name: string;
|
|
17
17
|
}
|
|
18
|
-
export interface
|
|
18
|
+
export interface DriftClientAccountEvents {
|
|
19
19
|
stateAccountUpdate: (payload: StateAccount) => void;
|
|
20
20
|
perpMarketAccountUpdate: (payload: PerpMarketAccount) => void;
|
|
21
21
|
spotMarketAccountUpdate: (payload: SpotMarketAccount) => void;
|
|
@@ -24,8 +24,8 @@ export interface ClearingHouseAccountEvents {
|
|
|
24
24
|
update: void;
|
|
25
25
|
error: (e: Error) => void;
|
|
26
26
|
}
|
|
27
|
-
export interface
|
|
28
|
-
eventEmitter: StrictEventEmitter<EventEmitter,
|
|
27
|
+
export interface DriftClientAccountSubscriber {
|
|
28
|
+
eventEmitter: StrictEventEmitter<EventEmitter, DriftClientAccountEvents>;
|
|
29
29
|
isSubscribed: boolean;
|
|
30
30
|
subscribe(): Promise<boolean>;
|
|
31
31
|
fetch(): Promise<void>;
|
|
@@ -71,7 +71,7 @@ export interface OracleEvents {
|
|
|
71
71
|
update: void;
|
|
72
72
|
error: (e: Error) => void;
|
|
73
73
|
}
|
|
74
|
-
export interface
|
|
74
|
+
export interface OracleAccountSubscriber {
|
|
75
75
|
eventEmitter: StrictEventEmitter<EventEmitter, OracleEvents>;
|
|
76
76
|
isSubscribed: boolean;
|
|
77
77
|
subscribe(): Promise<boolean>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import {
|
|
2
|
+
import { DriftClientAccountSubscriber, DriftClientAccountEvents, DataAndSlot } from './types';
|
|
3
3
|
import { AccountSubscriber } from './types';
|
|
4
4
|
import { SpotMarketAccount, PerpMarketAccount, StateAccount } from '../types';
|
|
5
5
|
import { Program } from '@project-serum/anchor';
|
|
@@ -8,14 +8,14 @@ import { EventEmitter } from 'events';
|
|
|
8
8
|
import { PublicKey } from '@solana/web3.js';
|
|
9
9
|
import { OracleInfo, OraclePriceData } from '../oracles/types';
|
|
10
10
|
import { OracleClientCache } from '../oracles/oracleClientCache';
|
|
11
|
-
export declare class
|
|
11
|
+
export declare class WebSocketDriftClientAccountSubscriber implements DriftClientAccountSubscriber {
|
|
12
12
|
isSubscribed: boolean;
|
|
13
13
|
program: Program;
|
|
14
14
|
perpMarketIndexes: number[];
|
|
15
15
|
spotMarketIndexes: number[];
|
|
16
16
|
oracleInfos: OracleInfo[];
|
|
17
17
|
oracleClientCache: OracleClientCache;
|
|
18
|
-
eventEmitter: StrictEventEmitter<EventEmitter,
|
|
18
|
+
eventEmitter: StrictEventEmitter<EventEmitter, DriftClientAccountEvents>;
|
|
19
19
|
stateAccountSubscriber?: AccountSubscriber<StateAccount>;
|
|
20
20
|
perpMarketAccountSubscribers: Map<number, AccountSubscriber<PerpMarketAccount>>;
|
|
21
21
|
spotMarketAccountSubscribers: Map<number, AccountSubscriber<SpotMarketAccount>>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.WebSocketDriftClientAccountSubscriber = void 0;
|
|
4
4
|
const types_1 = require("./types");
|
|
5
5
|
const events_1 = require("events");
|
|
6
6
|
const pda_1 = require("../addresses/pda");
|
|
@@ -8,7 +8,7 @@ const webSocketAccountSubscriber_1 = require("./webSocketAccountSubscriber");
|
|
|
8
8
|
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
|
-
class
|
|
11
|
+
class WebSocketDriftClientAccountSubscriber {
|
|
12
12
|
constructor(program, perpMarketIndexes, spotMarketIndexes, oracleInfos) {
|
|
13
13
|
this.oracleClientCache = new oracleClientCache_1.OracleClientCache();
|
|
14
14
|
this.perpMarketAccountSubscribers = new Map();
|
|
@@ -33,7 +33,7 @@ class WebSocketClearingHouseAccountSubscriber {
|
|
|
33
33
|
this.subscriptionPromise = new Promise((res) => {
|
|
34
34
|
this.subscriptionPromiseResolver = res;
|
|
35
35
|
});
|
|
36
|
-
const statePublicKey = await (0, pda_1.
|
|
36
|
+
const statePublicKey = await (0, pda_1.getDriftStateAccountPublicKey)(this.program.programId);
|
|
37
37
|
// create and activate main state account subscription
|
|
38
38
|
this.stateAccountSubscriber = new webSocketAccountSubscriber_1.WebSocketAccountSubscriber('state', this.program, statePublicKey);
|
|
39
39
|
await this.stateAccountSubscriber.subscribe((data) => {
|
|
@@ -193,4 +193,4 @@ class WebSocketClearingHouseAccountSubscriber {
|
|
|
193
193
|
return this.oracleSubscribers.get(oraclePublicKey.toString()).dataAndSlot;
|
|
194
194
|
}
|
|
195
195
|
}
|
|
196
|
-
exports.
|
|
196
|
+
exports.WebSocketDriftClientAccountSubscriber = WebSocketDriftClientAccountSubscriber;
|
package/lib/addresses/pda.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/// <reference types="bn.js" />
|
|
2
2
|
import { PublicKey } from '@solana/web3.js';
|
|
3
3
|
import { BN } from '@project-serum/anchor';
|
|
4
|
-
export declare function
|
|
5
|
-
export declare function
|
|
4
|
+
export declare function getDriftStateAccountPublicKeyAndNonce(programId: PublicKey): Promise<[PublicKey, number]>;
|
|
5
|
+
export declare function getDriftStateAccountPublicKey(programId: PublicKey): Promise<PublicKey>;
|
|
6
6
|
export declare function getUserAccountPublicKeyAndNonce(programId: PublicKey, authority: PublicKey, subAccountId?: number): Promise<[PublicKey, number]>;
|
|
7
7
|
export declare function getUserAccountPublicKey(programId: PublicKey, authority: PublicKey, subAccountId?: number): Promise<PublicKey>;
|
|
8
8
|
export declare function getUserAccountPublicKeySync(programId: PublicKey, authority: PublicKey, subAccountId?: number): PublicKey;
|
|
@@ -12,7 +12,7 @@ export declare function getSpotMarketPublicKey(programId: PublicKey, marketIndex
|
|
|
12
12
|
export declare function getSpotMarketVaultPublicKey(programId: PublicKey, marketIndex: number): Promise<PublicKey>;
|
|
13
13
|
export declare function getInsuranceFundVaultPublicKey(programId: PublicKey, marketIndex: number): Promise<PublicKey>;
|
|
14
14
|
export declare function getInsuranceFundStakeAccountPublicKey(programId: PublicKey, authority: PublicKey, marketIndex: number): PublicKey;
|
|
15
|
-
export declare function
|
|
15
|
+
export declare function getDriftSignerPublicKey(programId: PublicKey): PublicKey;
|
|
16
16
|
export declare function getSerumOpenOrdersPublicKey(programId: PublicKey, market: PublicKey): PublicKey;
|
|
17
17
|
export declare function getSerumSignerPublicKey(programId: PublicKey, market: PublicKey, nonce: BN): PublicKey;
|
|
18
18
|
export declare function getSerumFulfillmentConfigPublicKey(programId: PublicKey, market: PublicKey): PublicKey;
|
package/lib/addresses/pda.js
CHANGED
|
@@ -23,17 +23,17 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.getSerumFulfillmentConfigPublicKey = exports.getSerumSignerPublicKey = exports.getSerumOpenOrdersPublicKey = exports.
|
|
26
|
+
exports.getSerumFulfillmentConfigPublicKey = exports.getSerumSignerPublicKey = exports.getSerumOpenOrdersPublicKey = exports.getDriftSignerPublicKey = exports.getInsuranceFundStakeAccountPublicKey = exports.getInsuranceFundVaultPublicKey = exports.getSpotMarketVaultPublicKey = exports.getSpotMarketPublicKey = exports.getPerpMarketPublicKey = exports.getUserStatsAccountPublicKey = exports.getUserAccountPublicKeySync = exports.getUserAccountPublicKey = exports.getUserAccountPublicKeyAndNonce = exports.getDriftStateAccountPublicKey = exports.getDriftStateAccountPublicKeyAndNonce = void 0;
|
|
27
27
|
const web3_js_1 = require("@solana/web3.js");
|
|
28
28
|
const anchor = __importStar(require("@project-serum/anchor"));
|
|
29
|
-
async function
|
|
30
|
-
return web3_js_1.PublicKey.findProgramAddress([Buffer.from(anchor.utils.bytes.utf8.encode('
|
|
29
|
+
async function getDriftStateAccountPublicKeyAndNonce(programId) {
|
|
30
|
+
return web3_js_1.PublicKey.findProgramAddress([Buffer.from(anchor.utils.bytes.utf8.encode('drift_state'))], programId);
|
|
31
31
|
}
|
|
32
|
-
exports.
|
|
33
|
-
async function
|
|
34
|
-
return (await
|
|
32
|
+
exports.getDriftStateAccountPublicKeyAndNonce = getDriftStateAccountPublicKeyAndNonce;
|
|
33
|
+
async function getDriftStateAccountPublicKey(programId) {
|
|
34
|
+
return (await getDriftStateAccountPublicKeyAndNonce(programId))[0];
|
|
35
35
|
}
|
|
36
|
-
exports.
|
|
36
|
+
exports.getDriftStateAccountPublicKey = getDriftStateAccountPublicKey;
|
|
37
37
|
async function getUserAccountPublicKeyAndNonce(programId, authority, subAccountId = 0) {
|
|
38
38
|
return web3_js_1.PublicKey.findProgramAddress([
|
|
39
39
|
Buffer.from(anchor.utils.bytes.utf8.encode('user')),
|
|
@@ -97,10 +97,10 @@ function getInsuranceFundStakeAccountPublicKey(programId, authority, marketIndex
|
|
|
97
97
|
], programId)[0];
|
|
98
98
|
}
|
|
99
99
|
exports.getInsuranceFundStakeAccountPublicKey = getInsuranceFundStakeAccountPublicKey;
|
|
100
|
-
function
|
|
101
|
-
return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from(anchor.utils.bytes.utf8.encode('
|
|
100
|
+
function getDriftSignerPublicKey(programId) {
|
|
101
|
+
return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from(anchor.utils.bytes.utf8.encode('drift_signer'))], programId)[0];
|
|
102
102
|
}
|
|
103
|
-
exports.
|
|
103
|
+
exports.getDriftSignerPublicKey = getDriftSignerPublicKey;
|
|
104
104
|
function getSerumOpenOrdersPublicKey(programId, market) {
|
|
105
105
|
return web3_js_1.PublicKey.findProgramAddressSync([
|
|
106
106
|
Buffer.from(anchor.utils.bytes.utf8.encode('serum_open_orders')),
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
import { PublicKey, TransactionSignature } from '@solana/web3.js';
|
|
3
3
|
import { FeeStructure, OracleGuardRails, OracleSource, ExchangeStatus, MarketStatus, ContractTier, AssetTier } from './types';
|
|
4
4
|
import { BN } from '@project-serum/anchor';
|
|
5
|
-
import {
|
|
6
|
-
export declare class
|
|
5
|
+
import { DriftClient } from './driftClient';
|
|
6
|
+
export declare class AdminClient extends DriftClient {
|
|
7
7
|
initialize(usdcMint: PublicKey, _adminControlsPrices: boolean): Promise<[TransactionSignature]>;
|
|
8
|
-
initializeSpotMarket(mint: PublicKey, optimalUtilization: number, optimalRate: number, maxRate: number, oracle: PublicKey, oracleSource: OracleSource, initialAssetWeight: number, maintenanceAssetWeight: number, initialLiabilityWeight: number, maintenanceLiabilityWeight: number, imfFactor?: number,
|
|
8
|
+
initializeSpotMarket(mint: PublicKey, optimalUtilization: number, optimalRate: number, maxRate: number, oracle: PublicKey, oracleSource: OracleSource, initialAssetWeight: number, maintenanceAssetWeight: number, initialLiabilityWeight: number, maintenanceLiabilityWeight: number, imfFactor?: number, liquidatorFee?: number, activeStatus?: boolean, name?: string): Promise<TransactionSignature>;
|
|
9
9
|
initializeSerumFulfillmentConfig(marketIndex: number, serumMarket: PublicKey, serumProgram: PublicKey): Promise<TransactionSignature>;
|
|
10
|
-
initializePerpMarket(priceOracle: PublicKey, baseAssetReserve: BN, quoteAssetReserve: BN, periodicity: BN, pegMultiplier?: BN, oracleSource?: OracleSource, marginRatioInitial?: number, marginRatioMaintenance?: number,
|
|
10
|
+
initializePerpMarket(priceOracle: PublicKey, baseAssetReserve: BN, quoteAssetReserve: BN, periodicity: BN, pegMultiplier?: BN, oracleSource?: OracleSource, marginRatioInitial?: number, marginRatioMaintenance?: number, liquidatorFee?: number, activeStatus?: boolean, name?: string): Promise<TransactionSignature>;
|
|
11
11
|
moveAmmPrice(perpMarketIndex: number, baseAssetReserve: BN, quoteAssetReserve: BN, sqrtK?: BN): Promise<TransactionSignature>;
|
|
12
12
|
updateK(perpMarketIndex: number, sqrtK: BN): Promise<TransactionSignature>;
|
|
13
13
|
updatePerpMarketConcentrationScale(perpMarketIndex: number, concentrationScale: BN): Promise<TransactionSignature>;
|
|
@@ -19,9 +19,11 @@ export declare class Admin extends ClearingHouse {
|
|
|
19
19
|
updateAdmin(admin: PublicKey): Promise<TransactionSignature>;
|
|
20
20
|
updatePerpMarketCurveUpdateIntensity(perpMarketIndex: number, curveUpdateIntensity: number): Promise<TransactionSignature>;
|
|
21
21
|
updatePerpMarketMarginRatio(perpMarketIndex: number, marginRatioInitial: number, marginRatioMaintenance: number): Promise<TransactionSignature>;
|
|
22
|
+
updatePerpMarketImfFactor(perpMarketIndex: number, imfFactor: number, unrealizedPnlImfFactor: number): Promise<TransactionSignature>;
|
|
22
23
|
updatePerpMarketBaseSpread(perpMarketIndex: number, baseSpread: number): Promise<TransactionSignature>;
|
|
23
24
|
updateAmmJitIntensity(perpMarketIndex: number, ammJitIntensity: number): Promise<TransactionSignature>;
|
|
24
25
|
updatePerpMarketName(perpMarketIndex: number, name: string): Promise<TransactionSignature>;
|
|
26
|
+
updateSpotMarketName(spotMarketIndex: number, name: string): Promise<TransactionSignature>;
|
|
25
27
|
updatePerpMarketMaxSpread(perpMarketIndex: number, maxSpread: number): Promise<TransactionSignature>;
|
|
26
28
|
updatePerpFeeStructure(feeStructure: FeeStructure): Promise<TransactionSignature>;
|
|
27
29
|
updateSpotFeeStructure(feeStructure: FeeStructure): Promise<TransactionSignature>;
|
|
@@ -54,7 +56,10 @@ export declare class Admin extends ClearingHouse {
|
|
|
54
56
|
updateSpotAuctionDuration(defaultAuctionDuration: number): Promise<TransactionSignature>;
|
|
55
57
|
updatePerpMarketMaxFillReserveFraction(perpMarketIndex: number, maxBaseAssetAmountRatio: number): Promise<TransactionSignature>;
|
|
56
58
|
updateMaxSlippageRatio(perpMarketIndex: number, maxSlippageRatio: number): Promise<TransactionSignature>;
|
|
59
|
+
updatePerpMarketUnrealizedAssetWeight(perpMarketIndex: number, unrealizedInitialAssetWeight: number, unrealizedMaintenanceAssetWeight: number): Promise<TransactionSignature>;
|
|
57
60
|
updatePerpMarketMaxImbalances(perpMarketIndex: number, unrealizedMaxImbalance: BN, maxRevenueWithdrawPerPeriod: BN, quoteMaxInsurance: BN): Promise<TransactionSignature>;
|
|
58
61
|
updatePerpMarketMaxOpenInterest(perpMarketIndex: number, maxOpenInterest: BN): Promise<TransactionSignature>;
|
|
59
62
|
updateSerumVault(srmVault: PublicKey): Promise<TransactionSignature>;
|
|
63
|
+
updatePerpMarketLiquidationFee(perpMarketIndex: number, liquidatorFee: number, ifLiquidationFee: number): Promise<TransactionSignature>;
|
|
64
|
+
updateSpotMarketLiquidationFee(spotMarketIndex: number, liquidatorFee: number, ifLiquidationFee: number): Promise<TransactionSignature>;
|
|
60
65
|
}
|
|
@@ -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.AdminClient = void 0;
|
|
27
27
|
const web3_js_1 = require("@solana/web3.js");
|
|
28
28
|
const types_1 = require("./types");
|
|
29
29
|
const userName_1 = require("./userName");
|
|
@@ -32,24 +32,24 @@ const anchor = __importStar(require("@project-serum/anchor"));
|
|
|
32
32
|
const pda_1 = require("./addresses/pda");
|
|
33
33
|
const utils_1 = require("./math/utils");
|
|
34
34
|
const spl_token_1 = require("@solana/spl-token");
|
|
35
|
-
const
|
|
35
|
+
const driftClient_1 = require("./driftClient");
|
|
36
36
|
const numericConstants_1 = require("./constants/numericConstants");
|
|
37
37
|
const trade_1 = require("./math/trade");
|
|
38
38
|
const amm_1 = require("./math/amm");
|
|
39
|
-
class
|
|
39
|
+
class AdminClient extends driftClient_1.DriftClient {
|
|
40
40
|
async initialize(usdcMint, _adminControlsPrices) {
|
|
41
41
|
const stateAccountRPCResponse = await this.connection.getParsedAccountInfo(await this.getStatePublicKey());
|
|
42
42
|
if (stateAccountRPCResponse.value !== null) {
|
|
43
43
|
throw new Error('Clearing house already initialized');
|
|
44
44
|
}
|
|
45
|
-
const [
|
|
45
|
+
const [driftStatePublicKey] = await (0, pda_1.getDriftStateAccountPublicKeyAndNonce)(this.program.programId);
|
|
46
46
|
const initializeTx = await this.program.transaction.initialize({
|
|
47
47
|
accounts: {
|
|
48
48
|
admin: this.wallet.publicKey,
|
|
49
|
-
state:
|
|
49
|
+
state: driftStatePublicKey,
|
|
50
50
|
quoteAssetMint: usdcMint,
|
|
51
51
|
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
|
52
|
-
|
|
52
|
+
driftSigner: this.getSignerPublicKey(),
|
|
53
53
|
systemProgram: anchor.web3.SystemProgram.programId,
|
|
54
54
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
55
55
|
},
|
|
@@ -57,19 +57,20 @@ class Admin extends clearingHouse_1.ClearingHouse {
|
|
|
57
57
|
const { txSig: initializeTxSig } = await this.txSender.send(initializeTx, [], this.opts);
|
|
58
58
|
return [initializeTxSig];
|
|
59
59
|
}
|
|
60
|
-
async initializeSpotMarket(mint, optimalUtilization, optimalRate, maxRate, oracle, oracleSource, initialAssetWeight, maintenanceAssetWeight, initialLiabilityWeight, maintenanceLiabilityWeight, imfFactor = 0,
|
|
60
|
+
async initializeSpotMarket(mint, optimalUtilization, optimalRate, maxRate, oracle, oracleSource, initialAssetWeight, maintenanceAssetWeight, initialLiabilityWeight, maintenanceLiabilityWeight, imfFactor = 0, liquidatorFee = 0, activeStatus = true, name = userName_1.DEFAULT_MARKET_NAME) {
|
|
61
61
|
const spotMarketIndex = this.getStateAccount().numberOfSpotMarkets;
|
|
62
62
|
const spotMarket = await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex);
|
|
63
63
|
const spotMarketVault = await (0, pda_1.getSpotMarketVaultPublicKey)(this.program.programId, spotMarketIndex);
|
|
64
64
|
const insuranceFundVault = await (0, pda_1.getInsuranceFundVaultPublicKey)(this.program.programId, spotMarketIndex);
|
|
65
|
-
const
|
|
65
|
+
const nameBuffer = (0, userName_1.encodeName)(name);
|
|
66
|
+
const initializeTx = await this.program.transaction.initializeSpotMarket(optimalUtilization, optimalRate, maxRate, oracleSource, initialAssetWeight, maintenanceAssetWeight, initialLiabilityWeight, maintenanceLiabilityWeight, imfFactor, liquidatorFee, activeStatus, nameBuffer, {
|
|
66
67
|
accounts: {
|
|
67
68
|
admin: this.wallet.publicKey,
|
|
68
69
|
state: await this.getStatePublicKey(),
|
|
69
70
|
spotMarket,
|
|
70
71
|
spotMarketVault,
|
|
71
72
|
insuranceFundVault,
|
|
72
|
-
|
|
73
|
+
driftSigner: this.getSignerPublicKey(),
|
|
73
74
|
spotMarketMint: mint,
|
|
74
75
|
oracle,
|
|
75
76
|
rent: web3_js_1.SYSVAR_RENT_PUBKEY,
|
|
@@ -94,7 +95,7 @@ class Admin extends clearingHouse_1.ClearingHouse {
|
|
|
94
95
|
state: await this.getStatePublicKey(),
|
|
95
96
|
baseSpotMarket: this.getSpotMarketAccount(marketIndex).pubkey,
|
|
96
97
|
quoteSpotMarket: this.getQuoteSpotMarketAccount().pubkey,
|
|
97
|
-
|
|
98
|
+
driftSigner: this.getSignerPublicKey(),
|
|
98
99
|
serumProgram,
|
|
99
100
|
serumMarket,
|
|
100
101
|
serumOpenOrders,
|
|
@@ -104,10 +105,10 @@ class Admin extends clearingHouse_1.ClearingHouse {
|
|
|
104
105
|
},
|
|
105
106
|
});
|
|
106
107
|
}
|
|
107
|
-
async initializePerpMarket(priceOracle, baseAssetReserve, quoteAssetReserve, periodicity, pegMultiplier = numericConstants_1.PEG_PRECISION, oracleSource = types_1.OracleSource.PYTH, marginRatioInitial = 2000, marginRatioMaintenance = 500,
|
|
108
|
+
async initializePerpMarket(priceOracle, baseAssetReserve, quoteAssetReserve, periodicity, pegMultiplier = numericConstants_1.PEG_PRECISION, oracleSource = types_1.OracleSource.PYTH, marginRatioInitial = 2000, marginRatioMaintenance = 500, liquidatorFee = 0, activeStatus = true, name = userName_1.DEFAULT_MARKET_NAME) {
|
|
108
109
|
const perpMarketPublicKey = await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, this.getStateAccount().numberOfMarkets);
|
|
109
110
|
const nameBuffer = (0, userName_1.encodeName)(name);
|
|
110
|
-
const initializeMarketTx = await this.program.transaction.initializePerpMarket(baseAssetReserve, quoteAssetReserve, periodicity, pegMultiplier, oracleSource, marginRatioInitial, marginRatioMaintenance,
|
|
111
|
+
const initializeMarketTx = await this.program.transaction.initializePerpMarket(baseAssetReserve, quoteAssetReserve, periodicity, pegMultiplier, oracleSource, marginRatioInitial, marginRatioMaintenance, liquidatorFee, activeStatus, nameBuffer, {
|
|
111
112
|
accounts: {
|
|
112
113
|
state: await this.getStatePublicKey(),
|
|
113
114
|
admin: this.wallet.publicKey,
|
|
@@ -215,7 +216,7 @@ class Admin extends clearingHouse_1.ClearingHouse {
|
|
|
215
216
|
state: await this.getStatePublicKey(),
|
|
216
217
|
perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
|
|
217
218
|
sourceVault,
|
|
218
|
-
|
|
219
|
+
driftSigner: this.getSignerPublicKey(),
|
|
219
220
|
quoteSpotMarket: spotMarket.pubkey,
|
|
220
221
|
spotMarketVault: spotMarket.vault,
|
|
221
222
|
tokenProgram: spl_token_1.TOKEN_PROGRAM_ID,
|
|
@@ -250,6 +251,15 @@ class Admin extends clearingHouse_1.ClearingHouse {
|
|
|
250
251
|
},
|
|
251
252
|
});
|
|
252
253
|
}
|
|
254
|
+
async updatePerpMarketImfFactor(perpMarketIndex, imfFactor, unrealizedPnlImfFactor) {
|
|
255
|
+
return await this.program.rpc.updatePerpMarketImfFactor(imfFactor, unrealizedPnlImfFactor, {
|
|
256
|
+
accounts: {
|
|
257
|
+
admin: this.wallet.publicKey,
|
|
258
|
+
state: await this.getStatePublicKey(),
|
|
259
|
+
perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
|
|
260
|
+
},
|
|
261
|
+
});
|
|
262
|
+
}
|
|
253
263
|
async updatePerpMarketBaseSpread(perpMarketIndex, baseSpread) {
|
|
254
264
|
return await this.program.rpc.updatePerpMarketBaseSpread(baseSpread, {
|
|
255
265
|
accounts: {
|
|
@@ -278,6 +288,16 @@ class Admin extends clearingHouse_1.ClearingHouse {
|
|
|
278
288
|
},
|
|
279
289
|
});
|
|
280
290
|
}
|
|
291
|
+
async updateSpotMarketName(spotMarketIndex, name) {
|
|
292
|
+
const nameBuffer = (0, userName_1.encodeName)(name);
|
|
293
|
+
return await this.program.rpc.updateSpotMarketName(nameBuffer, {
|
|
294
|
+
accounts: {
|
|
295
|
+
admin: this.wallet.publicKey,
|
|
296
|
+
state: await this.getStatePublicKey(),
|
|
297
|
+
spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex),
|
|
298
|
+
},
|
|
299
|
+
});
|
|
300
|
+
}
|
|
281
301
|
async updatePerpMarketMaxSpread(perpMarketIndex, maxSpread) {
|
|
282
302
|
const perpMarketPublicKey = await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex);
|
|
283
303
|
return await this.program.rpc.updatePerpMarketMaxSpread(maxSpread, {
|
|
@@ -546,7 +566,7 @@ class Admin extends clearingHouse_1.ClearingHouse {
|
|
|
546
566
|
accounts: {
|
|
547
567
|
admin: this.wallet.publicKey,
|
|
548
568
|
state: await this.getStatePublicKey(),
|
|
549
|
-
perpMarket: this.
|
|
569
|
+
perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
|
|
550
570
|
},
|
|
551
571
|
});
|
|
552
572
|
}
|
|
@@ -559,6 +579,15 @@ class Admin extends clearingHouse_1.ClearingHouse {
|
|
|
559
579
|
},
|
|
560
580
|
});
|
|
561
581
|
}
|
|
582
|
+
async updatePerpMarketUnrealizedAssetWeight(perpMarketIndex, unrealizedInitialAssetWeight, unrealizedMaintenanceAssetWeight) {
|
|
583
|
+
return await this.program.rpc.updatePerpMarketUnrealizedAssetWeight(unrealizedInitialAssetWeight, unrealizedMaintenanceAssetWeight, {
|
|
584
|
+
accounts: {
|
|
585
|
+
admin: this.wallet.publicKey,
|
|
586
|
+
state: await this.getStatePublicKey(),
|
|
587
|
+
perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
|
|
588
|
+
},
|
|
589
|
+
});
|
|
590
|
+
}
|
|
562
591
|
async updatePerpMarketMaxImbalances(perpMarketIndex, unrealizedMaxImbalance, maxRevenueWithdrawPerPeriod, quoteMaxInsurance) {
|
|
563
592
|
return await this.program.rpc.updatePerpMarketMaxImbalances(unrealizedMaxImbalance, maxRevenueWithdrawPerPeriod, quoteMaxInsurance, {
|
|
564
593
|
accounts: {
|
|
@@ -586,5 +615,23 @@ class Admin extends clearingHouse_1.ClearingHouse {
|
|
|
586
615
|
},
|
|
587
616
|
});
|
|
588
617
|
}
|
|
618
|
+
async updatePerpMarketLiquidationFee(perpMarketIndex, liquidatorFee, ifLiquidationFee) {
|
|
619
|
+
return await this.program.rpc.updatePerpMarketLiquidationFee(liquidatorFee, ifLiquidationFee, {
|
|
620
|
+
accounts: {
|
|
621
|
+
admin: this.wallet.publicKey,
|
|
622
|
+
state: await this.getStatePublicKey(),
|
|
623
|
+
perpMarket: await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, perpMarketIndex),
|
|
624
|
+
},
|
|
625
|
+
});
|
|
626
|
+
}
|
|
627
|
+
async updateSpotMarketLiquidationFee(spotMarketIndex, liquidatorFee, ifLiquidationFee) {
|
|
628
|
+
return await this.program.rpc.updateSpotMarketLiquidationFee(liquidatorFee, ifLiquidationFee, {
|
|
629
|
+
accounts: {
|
|
630
|
+
admin: this.wallet.publicKey,
|
|
631
|
+
state: await this.getStatePublicKey(),
|
|
632
|
+
spotMarket: await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, spotMarketIndex),
|
|
633
|
+
},
|
|
634
|
+
});
|
|
635
|
+
}
|
|
589
636
|
}
|
|
590
|
-
exports.
|
|
637
|
+
exports.AdminClient = AdminClient;
|
package/lib/config.js
CHANGED
|
@@ -7,7 +7,7 @@ exports.configs = {
|
|
|
7
7
|
devnet: {
|
|
8
8
|
ENV: 'devnet',
|
|
9
9
|
PYTH_ORACLE_MAPPING_ADDRESS: 'BmA9Z6FjioHJPpjT39QazZyhDRUdZy2ezwx4GiDdE2u2',
|
|
10
|
-
CLEARING_HOUSE_PROGRAM_ID: '
|
|
10
|
+
CLEARING_HOUSE_PROGRAM_ID: 'H4G1xzAoqSW8n1Edmeowqsgc895tSNCeDPafYjv4Md7i',
|
|
11
11
|
USDC_MINT_ADDRESS: '8zGuJQqwhZafTah7Uc7Z4tXRnguqkn5KLFAP8oV6PHe2',
|
|
12
12
|
SERUM_V3: 'DESVgJVGajEgKGXhb6XmqDHGz3VjdgP7rEVESBgxmroY',
|
|
13
13
|
V2_ALPHA_TICKET_MINT_ADDRESS: 'DeEiGWfCMP9psnLGkxGrBBMEAW5Jv8bBGMN8DCtFRCyB',
|
|
@@ -15,6 +15,9 @@ export declare const TEN_THOUSAND: BN;
|
|
|
15
15
|
export declare const BN_MAX: BN;
|
|
16
16
|
export declare const TEN_MILLION: BN;
|
|
17
17
|
export declare const MAX_LEVERAGE: BN;
|
|
18
|
+
export declare const PERCENTAGE_PRECISION_EXP: BN;
|
|
19
|
+
export declare const PERCENTAGE_PRECISION: BN;
|
|
20
|
+
export declare const CONCENTRATION_PRECISION: BN;
|
|
18
21
|
export declare const QUOTE_PRECISION_EXP: BN;
|
|
19
22
|
export declare const FUNDING_RATE_BUFFER_PRECISION_EXP: BN;
|
|
20
23
|
export declare const PRICE_PRECISION_EXP: BN;
|