@drift-labs/sdk 0.2.0-master.32 → 0.2.0-master.34
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/bulkAccountLoader.js +2 -1
- package/lib/accounts/pollingClearingHouseAccountSubscriber.d.ts +2 -2
- package/lib/accounts/pollingClearingHouseAccountSubscriber.js +8 -8
- package/lib/accounts/types.d.ts +1 -0
- package/lib/accounts/webSocketClearingHouseAccountSubscriber.d.ts +2 -2
- package/lib/accounts/webSocketClearingHouseAccountSubscriber.js +7 -7
- package/lib/addresses/marketAddresses.js +1 -1
- package/lib/addresses/pda.d.ts +4 -4
- package/lib/addresses/pda.js +23 -22
- package/lib/admin.d.ts +30 -32
- package/lib/admin.js +111 -119
- package/lib/clearingHouse.d.ts +43 -34
- package/lib/clearingHouse.js +353 -193
- package/lib/clearingHouseConfig.d.ts +2 -2
- package/lib/clearingHouseUser.d.ts +26 -5
- package/lib/clearingHouseUser.js +151 -51
- package/lib/config.d.ts +2 -0
- package/lib/config.js +5 -1
- package/lib/constants/numericConstants.d.ts +1 -0
- package/lib/constants/numericConstants.js +3 -2
- package/lib/dlob/DLOB.d.ts +18 -11
- package/lib/dlob/DLOB.js +179 -107
- package/lib/dlob/DLOBNode.js +2 -10
- package/lib/dlob/NodeList.js +1 -1
- package/lib/events/eventSubscriber.d.ts +1 -0
- package/lib/events/eventSubscriber.js +11 -4
- package/lib/events/fetchLogs.d.ts +3 -1
- package/lib/events/fetchLogs.js +13 -5
- package/lib/events/pollingLogProvider.js +1 -1
- package/lib/events/types.d.ts +1 -1
- package/lib/events/webSocketLogProvider.js +1 -1
- package/lib/factory/bigNum.d.ts +5 -4
- package/lib/factory/bigNum.js +36 -6
- package/lib/idl/clearing_house.json +1540 -1246
- package/lib/index.d.ts +3 -0
- package/lib/index.js +3 -0
- package/lib/math/amm.js +9 -9
- package/lib/math/exchangeStatus.d.ts +4 -0
- package/lib/math/exchangeStatus.js +18 -0
- package/lib/math/funding.js +10 -10
- package/lib/math/margin.js +6 -1
- package/lib/math/market.js +9 -9
- package/lib/math/orders.d.ts +7 -3
- package/lib/math/orders.js +39 -31
- package/lib/math/repeg.js +3 -3
- package/lib/math/spotBalance.js +3 -3
- package/lib/math/spotPosition.js +2 -2
- package/lib/serum/serumFulfillmentConfigMap.d.ts +10 -0
- package/lib/serum/serumFulfillmentConfigMap.js +17 -0
- package/lib/serum/serumSubscriber.d.ts +4 -0
- package/lib/serum/serumSubscriber.js +16 -1
- package/lib/types.d.ts +60 -75
- package/lib/types.js +2 -1
- package/lib/userMap/userMap.d.ts +17 -1
- package/lib/userMap/userMap.js +12 -0
- package/lib/userName.d.ts +1 -0
- package/lib/userName.js +3 -2
- package/package.json +1 -1
- package/src/accounts/bulkAccountLoader.ts +5 -1
- package/src/accounts/pollingClearingHouseAccountSubscriber.ts +9 -9
- package/src/accounts/webSocketClearingHouseAccountSubscriber.ts +8 -8
- package/src/addresses/marketAddresses.ts +2 -2
- package/src/addresses/pda.ts +20 -20
- package/src/admin.ts +246 -221
- package/src/assert/assert.js +9 -0
- package/src/clearingHouse.ts +556 -236
- package/src/clearingHouseConfig.ts +2 -2
- package/src/clearingHouseUser.ts +237 -87
- package/src/config.ts +8 -1
- package/src/constants/numericConstants.ts +5 -1
- package/src/dlob/DLOB.ts +257 -120
- package/src/dlob/DLOBNode.ts +2 -14
- package/src/dlob/NodeList.ts +1 -1
- package/src/events/eventList.js +77 -0
- package/src/events/eventSubscriber.ts +18 -4
- package/src/events/fetchLogs.ts +20 -5
- package/src/events/pollingLogProvider.ts +1 -1
- package/src/events/types.ts +2 -1
- package/src/events/webSocketLogProvider.ts +1 -1
- package/src/examples/makeTradeExample.js +157 -0
- package/src/factory/bigNum.ts +59 -6
- package/src/idl/clearing_house.json +1540 -1246
- package/src/idl/pyth.json +98 -2
- package/src/index.ts +3 -0
- package/src/math/amm.ts +9 -9
- package/src/math/exchangeStatus.ts +31 -0
- package/src/math/funding.ts +20 -10
- package/src/math/margin.ts +7 -1
- package/src/math/market.ts +9 -9
- package/src/math/orders.ts +44 -29
- package/src/math/repeg.ts +3 -3
- package/src/math/spotBalance.ts +4 -4
- package/src/math/spotPosition.ts +2 -2
- package/src/serum/serumFulfillmentConfigMap.ts +26 -0
- package/src/serum/serumSubscriber.ts +20 -1
- package/src/token/index.js +38 -0
- package/src/tx/types.js +2 -0
- package/src/tx/utils.js +17 -0
- package/src/types.ts +65 -51
- package/src/userMap/userMap.ts +25 -1
- package/src/userName.ts +2 -1
- package/src/util/computeUnits.js +27 -0
- package/src/util/getTokenAddress.js +9 -0
- package/src/util/promiseTimeout.js +14 -0
- package/src/util/tps.js +27 -0
- package/tests/bn/test.ts +22 -1
- package/tests/dlob/helpers.ts +252 -81
- package/tests/dlob/test.ts +1040 -219
|
@@ -162,7 +162,8 @@ class BulkAccountLoader {
|
|
|
162
162
|
if (this.intervalId) {
|
|
163
163
|
return;
|
|
164
164
|
}
|
|
165
|
-
|
|
165
|
+
if (this.pollingFrequency !== 0)
|
|
166
|
+
this.intervalId = setInterval(this.load.bind(this), this.pollingFrequency);
|
|
166
167
|
}
|
|
167
168
|
stopPolling() {
|
|
168
169
|
if (this.intervalId) {
|
|
@@ -31,8 +31,8 @@ export declare class PollingClearingHouseAccountSubscriber implements ClearingHo
|
|
|
31
31
|
constructor(program: Program, accountLoader: BulkAccountLoader, perpMarketIndexes: number[], spotMarketIndexes: number[], oracleInfos: OracleInfo[]);
|
|
32
32
|
subscribe(): Promise<boolean>;
|
|
33
33
|
updateAccountsToPoll(): Promise<void>;
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
updatePerpMarketAccountsToPoll(): Promise<boolean>;
|
|
35
|
+
addPerpMarketAccountToPoll(marketIndex: number): Promise<boolean>;
|
|
36
36
|
updateSpotMarketAccountsToPoll(): Promise<boolean>;
|
|
37
37
|
addSpotMarketAccountToPoll(marketIndex: number): Promise<boolean>;
|
|
38
38
|
updateOraclesToPoll(): boolean;
|
|
@@ -64,20 +64,20 @@ class PollingClearingHouseAccountSubscriber {
|
|
|
64
64
|
publicKey: accounts.state,
|
|
65
65
|
eventType: 'stateAccountUpdate',
|
|
66
66
|
});
|
|
67
|
-
await this.
|
|
67
|
+
await this.updatePerpMarketAccountsToPoll();
|
|
68
68
|
await this.updateSpotMarketAccountsToPoll();
|
|
69
69
|
}
|
|
70
|
-
async
|
|
70
|
+
async updatePerpMarketAccountsToPoll() {
|
|
71
71
|
for (const marketIndex of this.perpMarketIndexes) {
|
|
72
|
-
await this.
|
|
72
|
+
await this.addPerpMarketAccountToPoll(marketIndex);
|
|
73
73
|
}
|
|
74
74
|
return true;
|
|
75
75
|
}
|
|
76
|
-
async
|
|
77
|
-
const
|
|
78
|
-
this.accountsToPoll.set(
|
|
76
|
+
async addPerpMarketAccountToPoll(marketIndex) {
|
|
77
|
+
const perpMarketPublicKey = await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, marketIndex);
|
|
78
|
+
this.accountsToPoll.set(perpMarketPublicKey.toString(), {
|
|
79
79
|
key: 'perpMarket',
|
|
80
|
-
publicKey:
|
|
80
|
+
publicKey: perpMarketPublicKey,
|
|
81
81
|
eventType: 'perpMarketAccountUpdate',
|
|
82
82
|
mapKey: marketIndex,
|
|
83
83
|
});
|
|
@@ -230,7 +230,7 @@ class PollingClearingHouseAccountSubscriber {
|
|
|
230
230
|
return true;
|
|
231
231
|
}
|
|
232
232
|
async addPerpMarket(marketIndex) {
|
|
233
|
-
await this.
|
|
233
|
+
await this.addPerpMarketAccountToPoll(marketIndex);
|
|
234
234
|
const accountToPoll = this.accountsToPoll.get(marketIndex.toString());
|
|
235
235
|
this.addAccountToAccountLoader(accountToPoll);
|
|
236
236
|
return true;
|
package/lib/accounts/types.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
2
3
|
import { SpotMarketAccount, PerpMarketAccount, OracleSource, StateAccount, UserAccount, UserStatsAccount } from '../types';
|
|
3
4
|
import StrictEventEmitter from 'strict-event-emitter-types';
|
|
4
5
|
import { EventEmitter } from 'events';
|
|
@@ -25,8 +25,8 @@ export declare class WebSocketClearingHouseAccountSubscriber implements Clearing
|
|
|
25
25
|
private subscriptionPromiseResolver;
|
|
26
26
|
constructor(program: Program, perpMarketIndexes: number[], spotMarketIndexes: number[], oracleInfos: OracleInfo[]);
|
|
27
27
|
subscribe(): Promise<boolean>;
|
|
28
|
-
|
|
29
|
-
|
|
28
|
+
subscribeToPerpMarketAccounts(): Promise<boolean>;
|
|
29
|
+
subscribeToPerpMarketAccount(marketIndex: number): Promise<boolean>;
|
|
30
30
|
subscribeToSpotMarketAccounts(): Promise<boolean>;
|
|
31
31
|
subscribeToSpotMarketAccount(marketIndex: number): Promise<boolean>;
|
|
32
32
|
subscribeToOracles(): Promise<boolean>;
|
|
@@ -41,7 +41,7 @@ class WebSocketClearingHouseAccountSubscriber {
|
|
|
41
41
|
this.eventEmitter.emit('update');
|
|
42
42
|
});
|
|
43
43
|
// subscribe to market accounts
|
|
44
|
-
await this.
|
|
44
|
+
await this.subscribeToPerpMarketAccounts();
|
|
45
45
|
// subscribe to spot market accounts
|
|
46
46
|
await this.subscribeToSpotMarketAccounts();
|
|
47
47
|
// subscribe to oracles
|
|
@@ -52,15 +52,15 @@ class WebSocketClearingHouseAccountSubscriber {
|
|
|
52
52
|
this.subscriptionPromiseResolver(true);
|
|
53
53
|
return true;
|
|
54
54
|
}
|
|
55
|
-
async
|
|
55
|
+
async subscribeToPerpMarketAccounts() {
|
|
56
56
|
for (const marketIndex of this.perpMarketIndexes) {
|
|
57
|
-
await this.
|
|
57
|
+
await this.subscribeToPerpMarketAccount(marketIndex);
|
|
58
58
|
}
|
|
59
59
|
return true;
|
|
60
60
|
}
|
|
61
|
-
async
|
|
62
|
-
const
|
|
63
|
-
const accountSubscriber = new webSocketAccountSubscriber_1.WebSocketAccountSubscriber('perpMarket', this.program,
|
|
61
|
+
async subscribeToPerpMarketAccount(marketIndex) {
|
|
62
|
+
const perpMarketPublicKey = await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, marketIndex);
|
|
63
|
+
const accountSubscriber = new webSocketAccountSubscriber_1.WebSocketAccountSubscriber('perpMarket', this.program, perpMarketPublicKey);
|
|
64
64
|
await accountSubscriber.subscribe((data) => {
|
|
65
65
|
this.eventEmitter.emit('perpMarketAccountUpdate', data);
|
|
66
66
|
this.eventEmitter.emit('update');
|
|
@@ -148,7 +148,7 @@ class WebSocketClearingHouseAccountSubscriber {
|
|
|
148
148
|
if (this.perpMarketAccountSubscribers.has(marketIndex)) {
|
|
149
149
|
return true;
|
|
150
150
|
}
|
|
151
|
-
return this.
|
|
151
|
+
return this.subscribeToPerpMarketAccount(marketIndex);
|
|
152
152
|
}
|
|
153
153
|
async addOracle(oracleInfo) {
|
|
154
154
|
if (this.oracleSubscribers.has(oracleInfo.publicKey.toString())) {
|
|
@@ -8,7 +8,7 @@ async function getMarketAddress(programId, marketIndex) {
|
|
|
8
8
|
if (CACHE.has(cacheKey)) {
|
|
9
9
|
return CACHE.get(cacheKey);
|
|
10
10
|
}
|
|
11
|
-
const publicKey = await (0, pda_1.
|
|
11
|
+
const publicKey = await (0, pda_1.getPerpMarketPublicKey)(programId, marketIndex);
|
|
12
12
|
CACHE.set(cacheKey, publicKey);
|
|
13
13
|
return publicKey;
|
|
14
14
|
}
|
package/lib/addresses/pda.d.ts
CHANGED
|
@@ -3,11 +3,11 @@ import { PublicKey } from '@solana/web3.js';
|
|
|
3
3
|
import { BN } from '@project-serum/anchor';
|
|
4
4
|
export declare function getClearingHouseStateAccountPublicKeyAndNonce(programId: PublicKey): Promise<[PublicKey, number]>;
|
|
5
5
|
export declare function getClearingHouseStateAccountPublicKey(programId: PublicKey): Promise<PublicKey>;
|
|
6
|
-
export declare function getUserAccountPublicKeyAndNonce(programId: PublicKey, authority: PublicKey,
|
|
7
|
-
export declare function getUserAccountPublicKey(programId: PublicKey, authority: PublicKey,
|
|
8
|
-
export declare function getUserAccountPublicKeySync(programId: PublicKey, authority: PublicKey,
|
|
6
|
+
export declare function getUserAccountPublicKeyAndNonce(programId: PublicKey, authority: PublicKey, subAccountId?: number): Promise<[PublicKey, number]>;
|
|
7
|
+
export declare function getUserAccountPublicKey(programId: PublicKey, authority: PublicKey, subAccountId?: number): Promise<PublicKey>;
|
|
8
|
+
export declare function getUserAccountPublicKeySync(programId: PublicKey, authority: PublicKey, subAccountId?: number): PublicKey;
|
|
9
9
|
export declare function getUserStatsAccountPublicKey(programId: PublicKey, authority: PublicKey): PublicKey;
|
|
10
|
-
export declare function
|
|
10
|
+
export declare function getPerpMarketPublicKey(programId: PublicKey, marketIndex: number): Promise<PublicKey>;
|
|
11
11
|
export declare function getSpotMarketPublicKey(programId: PublicKey, marketIndex: number): Promise<PublicKey>;
|
|
12
12
|
export declare function getSpotMarketVaultPublicKey(programId: PublicKey, marketIndex: number): Promise<PublicKey>;
|
|
13
13
|
export declare function getInsuranceFundVaultPublicKey(programId: PublicKey, marketIndex: number): Promise<PublicKey>;
|
package/lib/addresses/pda.js
CHANGED
|
@@ -23,73 +23,74 @@ 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.getClearingHouseSignerPublicKey = exports.getInsuranceFundStakeAccountPublicKey = exports.getInsuranceFundVaultPublicKey = exports.getSpotMarketVaultPublicKey = exports.getSpotMarketPublicKey = exports.
|
|
26
|
+
exports.getSerumFulfillmentConfigPublicKey = exports.getSerumSignerPublicKey = exports.getSerumOpenOrdersPublicKey = exports.getClearingHouseSignerPublicKey = exports.getInsuranceFundStakeAccountPublicKey = exports.getInsuranceFundVaultPublicKey = exports.getSpotMarketVaultPublicKey = exports.getSpotMarketPublicKey = exports.getPerpMarketPublicKey = exports.getUserStatsAccountPublicKey = exports.getUserAccountPublicKeySync = exports.getUserAccountPublicKey = exports.getUserAccountPublicKeyAndNonce = exports.getClearingHouseStateAccountPublicKey = exports.getClearingHouseStateAccountPublicKeyAndNonce = void 0;
|
|
27
|
+
const web3_js_1 = require("@solana/web3.js");
|
|
27
28
|
const anchor = __importStar(require("@project-serum/anchor"));
|
|
28
29
|
async function getClearingHouseStateAccountPublicKeyAndNonce(programId) {
|
|
29
|
-
return
|
|
30
|
+
return web3_js_1.PublicKey.findProgramAddress([Buffer.from(anchor.utils.bytes.utf8.encode('clearing_house'))], programId);
|
|
30
31
|
}
|
|
31
32
|
exports.getClearingHouseStateAccountPublicKeyAndNonce = getClearingHouseStateAccountPublicKeyAndNonce;
|
|
32
33
|
async function getClearingHouseStateAccountPublicKey(programId) {
|
|
33
34
|
return (await getClearingHouseStateAccountPublicKeyAndNonce(programId))[0];
|
|
34
35
|
}
|
|
35
36
|
exports.getClearingHouseStateAccountPublicKey = getClearingHouseStateAccountPublicKey;
|
|
36
|
-
async function getUserAccountPublicKeyAndNonce(programId, authority,
|
|
37
|
-
return
|
|
37
|
+
async function getUserAccountPublicKeyAndNonce(programId, authority, subAccountId = 0) {
|
|
38
|
+
return web3_js_1.PublicKey.findProgramAddress([
|
|
38
39
|
Buffer.from(anchor.utils.bytes.utf8.encode('user')),
|
|
39
40
|
authority.toBuffer(),
|
|
40
|
-
Uint8Array.from([
|
|
41
|
+
Uint8Array.from([subAccountId]),
|
|
41
42
|
], programId);
|
|
42
43
|
}
|
|
43
44
|
exports.getUserAccountPublicKeyAndNonce = getUserAccountPublicKeyAndNonce;
|
|
44
|
-
async function getUserAccountPublicKey(programId, authority,
|
|
45
|
-
return (await getUserAccountPublicKeyAndNonce(programId, authority,
|
|
45
|
+
async function getUserAccountPublicKey(programId, authority, subAccountId = 0) {
|
|
46
|
+
return (await getUserAccountPublicKeyAndNonce(programId, authority, subAccountId))[0];
|
|
46
47
|
}
|
|
47
48
|
exports.getUserAccountPublicKey = getUserAccountPublicKey;
|
|
48
|
-
function getUserAccountPublicKeySync(programId, authority,
|
|
49
|
-
return
|
|
49
|
+
function getUserAccountPublicKeySync(programId, authority, subAccountId = 0) {
|
|
50
|
+
return web3_js_1.PublicKey.findProgramAddressSync([
|
|
50
51
|
Buffer.from(anchor.utils.bytes.utf8.encode('user')),
|
|
51
52
|
authority.toBuffer(),
|
|
52
|
-
Uint8Array.from([
|
|
53
|
+
Uint8Array.from([subAccountId]),
|
|
53
54
|
], programId)[0];
|
|
54
55
|
}
|
|
55
56
|
exports.getUserAccountPublicKeySync = getUserAccountPublicKeySync;
|
|
56
57
|
function getUserStatsAccountPublicKey(programId, authority) {
|
|
57
|
-
return
|
|
58
|
+
return web3_js_1.PublicKey.findProgramAddressSync([
|
|
58
59
|
Buffer.from(anchor.utils.bytes.utf8.encode('user_stats')),
|
|
59
60
|
authority.toBuffer(),
|
|
60
61
|
], programId)[0];
|
|
61
62
|
}
|
|
62
63
|
exports.getUserStatsAccountPublicKey = getUserStatsAccountPublicKey;
|
|
63
|
-
async function
|
|
64
|
-
return (await
|
|
65
|
-
Buffer.from(anchor.utils.bytes.utf8.encode('
|
|
64
|
+
async function getPerpMarketPublicKey(programId, marketIndex) {
|
|
65
|
+
return (await web3_js_1.PublicKey.findProgramAddress([
|
|
66
|
+
Buffer.from(anchor.utils.bytes.utf8.encode('perp_market')),
|
|
66
67
|
new anchor.BN(marketIndex).toArrayLike(Buffer, 'le', 2),
|
|
67
68
|
], programId))[0];
|
|
68
69
|
}
|
|
69
|
-
exports.
|
|
70
|
+
exports.getPerpMarketPublicKey = getPerpMarketPublicKey;
|
|
70
71
|
async function getSpotMarketPublicKey(programId, marketIndex) {
|
|
71
|
-
return (await
|
|
72
|
+
return (await web3_js_1.PublicKey.findProgramAddress([
|
|
72
73
|
Buffer.from(anchor.utils.bytes.utf8.encode('spot_market')),
|
|
73
74
|
new anchor.BN(marketIndex).toArrayLike(Buffer, 'le', 2),
|
|
74
75
|
], programId))[0];
|
|
75
76
|
}
|
|
76
77
|
exports.getSpotMarketPublicKey = getSpotMarketPublicKey;
|
|
77
78
|
async function getSpotMarketVaultPublicKey(programId, marketIndex) {
|
|
78
|
-
return (await
|
|
79
|
+
return (await web3_js_1.PublicKey.findProgramAddress([
|
|
79
80
|
Buffer.from(anchor.utils.bytes.utf8.encode('spot_market_vault')),
|
|
80
81
|
new anchor.BN(marketIndex).toArrayLike(Buffer, 'le', 2),
|
|
81
82
|
], programId))[0];
|
|
82
83
|
}
|
|
83
84
|
exports.getSpotMarketVaultPublicKey = getSpotMarketVaultPublicKey;
|
|
84
85
|
async function getInsuranceFundVaultPublicKey(programId, marketIndex) {
|
|
85
|
-
return (await
|
|
86
|
+
return (await web3_js_1.PublicKey.findProgramAddress([
|
|
86
87
|
Buffer.from(anchor.utils.bytes.utf8.encode('insurance_fund_vault')),
|
|
87
88
|
new anchor.BN(marketIndex).toArrayLike(Buffer, 'le', 2),
|
|
88
89
|
], programId))[0];
|
|
89
90
|
}
|
|
90
91
|
exports.getInsuranceFundVaultPublicKey = getInsuranceFundVaultPublicKey;
|
|
91
92
|
function getInsuranceFundStakeAccountPublicKey(programId, authority, marketIndex) {
|
|
92
|
-
return
|
|
93
|
+
return web3_js_1.PublicKey.findProgramAddressSync([
|
|
93
94
|
Buffer.from(anchor.utils.bytes.utf8.encode('insurance_fund_stake')),
|
|
94
95
|
authority.toBuffer(),
|
|
95
96
|
new anchor.BN(marketIndex).toArrayLike(Buffer, 'le', 2),
|
|
@@ -97,11 +98,11 @@ function getInsuranceFundStakeAccountPublicKey(programId, authority, marketIndex
|
|
|
97
98
|
}
|
|
98
99
|
exports.getInsuranceFundStakeAccountPublicKey = getInsuranceFundStakeAccountPublicKey;
|
|
99
100
|
function getClearingHouseSignerPublicKey(programId) {
|
|
100
|
-
return
|
|
101
|
+
return web3_js_1.PublicKey.findProgramAddressSync([Buffer.from(anchor.utils.bytes.utf8.encode('clearing_house_signer'))], programId)[0];
|
|
101
102
|
}
|
|
102
103
|
exports.getClearingHouseSignerPublicKey = getClearingHouseSignerPublicKey;
|
|
103
104
|
function getSerumOpenOrdersPublicKey(programId, market) {
|
|
104
|
-
return
|
|
105
|
+
return web3_js_1.PublicKey.findProgramAddressSync([
|
|
105
106
|
Buffer.from(anchor.utils.bytes.utf8.encode('serum_open_orders')),
|
|
106
107
|
market.toBuffer(),
|
|
107
108
|
], programId)[0];
|
|
@@ -112,7 +113,7 @@ function getSerumSignerPublicKey(programId, market, nonce) {
|
|
|
112
113
|
}
|
|
113
114
|
exports.getSerumSignerPublicKey = getSerumSignerPublicKey;
|
|
114
115
|
function getSerumFulfillmentConfigPublicKey(programId, market) {
|
|
115
|
-
return
|
|
116
|
+
return web3_js_1.PublicKey.findProgramAddressSync([
|
|
116
117
|
Buffer.from(anchor.utils.bytes.utf8.encode('serum_fulfillment_config')),
|
|
117
118
|
market.toBuffer(),
|
|
118
119
|
], programId)[0];
|
package/lib/admin.d.ts
CHANGED
|
@@ -7,42 +7,40 @@ export declare class Admin extends ClearingHouse {
|
|
|
7
7
|
initialize(usdcMint: PublicKey, _adminControlsPrices: boolean): Promise<[TransactionSignature]>;
|
|
8
8
|
initializeSpotMarket(mint: PublicKey, optimalUtilization: number, optimalRate: number, maxRate: number, oracle: PublicKey, oracleSource: OracleSource, initialAssetWeight: BN, maintenanceAssetWeight: BN, initialLiabilityWeight: BN, maintenanceLiabilityWeight: BN, imfFactor?: BN, liquidationFee?: BN, activeStatus?: boolean): Promise<TransactionSignature>;
|
|
9
9
|
initializeSerumFulfillmentConfig(marketIndex: number, serumMarket: PublicKey, serumProgram: PublicKey): Promise<TransactionSignature>;
|
|
10
|
-
|
|
11
|
-
moveAmmPrice(
|
|
12
|
-
updateK(
|
|
13
|
-
|
|
10
|
+
initializePerpMarket(priceOracle: PublicKey, baseAssetReserve: BN, quoteAssetReserve: BN, periodicity: BN, pegMultiplier?: BN, oracleSource?: OracleSource, marginRatioInitial?: number, marginRatioMaintenance?: number, liquidationFee?: BN, activeStatus?: boolean, name?: string): Promise<TransactionSignature>;
|
|
11
|
+
moveAmmPrice(perpMarketIndex: number, baseAssetReserve: BN, quoteAssetReserve: BN, sqrtK?: BN): Promise<TransactionSignature>;
|
|
12
|
+
updateK(perpMarketIndex: number, sqrtK: BN): Promise<TransactionSignature>;
|
|
13
|
+
updatePerpMarketConcentrationScale(perpMarketIndex: number, concentrationScale: BN): Promise<TransactionSignature>;
|
|
14
14
|
moveAmmToPrice(perpMarketIndex: number, targetPrice: BN): Promise<TransactionSignature>;
|
|
15
|
-
repegAmmCurve(newPeg: BN,
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
15
|
+
repegAmmCurve(newPeg: BN, perpMarketIndex: number): Promise<TransactionSignature>;
|
|
16
|
+
updatePerpMarketAmmOracleTwap(perpMarketIndex: number): Promise<TransactionSignature>;
|
|
17
|
+
resetPerpMarketAmmOracleTwap(perpMarketIndex: number): Promise<TransactionSignature>;
|
|
18
|
+
depositIntoPerpMarketFeePool(perpMarketIndex: number, amount: BN, sourceVault: PublicKey): Promise<TransactionSignature>;
|
|
19
19
|
updateAdmin(admin: PublicKey): Promise<TransactionSignature>;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
updateAmmJitIntensity(
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
updatePartialLiquidationPenaltyPercentage(numerator: BN, denominator: BN): Promise<TransactionSignature>;
|
|
27
|
-
updateFullLiquidationPenaltyPercentage(numerator: BN, denominator: BN): Promise<TransactionSignature>;
|
|
28
|
-
updatePartialLiquidationShareDenominator(denominator: BN): Promise<TransactionSignature>;
|
|
29
|
-
updateFullLiquidationShareDenominator(denominator: BN): Promise<TransactionSignature>;
|
|
20
|
+
updatePerpMarketCurveUpdateIntensity(perpMarketIndex: number, curveUpdateIntensity: number): Promise<TransactionSignature>;
|
|
21
|
+
updatePerpMarketMarginRatio(perpMarketIndex: number, marginRatioInitial: number, marginRatioMaintenance: number): Promise<TransactionSignature>;
|
|
22
|
+
updatePerpMarketBaseSpread(perpMarketIndex: number, baseSpread: number): Promise<TransactionSignature>;
|
|
23
|
+
updateAmmJitIntensity(perpMarketIndex: number, ammJitIntensity: number): Promise<TransactionSignature>;
|
|
24
|
+
updatePerpMarketName(perpMarketIndex: number, name: string): Promise<TransactionSignature>;
|
|
25
|
+
updatePerpMarketMaxSpread(perpMarketIndex: number, maxSpread: number): Promise<TransactionSignature>;
|
|
30
26
|
updatePerpFeeStructure(feeStructure: FeeStructure): Promise<TransactionSignature>;
|
|
31
27
|
updateSpotFeeStructure(feeStructure: FeeStructure): Promise<TransactionSignature>;
|
|
32
28
|
updateOracleGuardRails(oracleGuardRails: OracleGuardRails): Promise<TransactionSignature>;
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
29
|
+
updateStateSettlementDuration(settlementDuration: number): Promise<TransactionSignature>;
|
|
30
|
+
updateWithdrawGuardThreshold(spotMarketIndex: number, withdrawGuardThreshold: BN): Promise<TransactionSignature>;
|
|
31
|
+
updateSpotMarketIfFactor(spotMarketIndex: number, userIfFactor: BN, totalIfFactor: BN): Promise<TransactionSignature>;
|
|
32
|
+
updateSpotMarketRevenueSettlePeriod(spotMarketIndex: number, revenueSettlePeriod: BN): Promise<TransactionSignature>;
|
|
33
|
+
updateSpotMarketMaxTokenDeposits(spotMarketIndex: number, maxTokenDeposits: BN): Promise<TransactionSignature>;
|
|
34
|
+
updateInsuranceFundUnstakingPeriod(spotMarketIndex: number, insuranceWithdrawEscrowPeriod: BN): Promise<TransactionSignature>;
|
|
35
|
+
updateLpCooldownTime(cooldownTime: BN): Promise<TransactionSignature>;
|
|
36
|
+
updatePerpMarketOracle(perpMarketIndex: number, oracle: PublicKey, oracleSource: OracleSource): Promise<TransactionSignature>;
|
|
37
|
+
updatePerpMarketStepSizeAndTickSize(perpMarketIndex: number, stepSize: BN, tickSize: BN): Promise<TransactionSignature>;
|
|
38
|
+
updatePerpMarketMinOrderSize(perpMarketIndex: number, orderSize: BN): Promise<TransactionSignature>;
|
|
39
|
+
updatePerpMarketExpiry(perpMarketIndex: number, expiryTs: BN): Promise<TransactionSignature>;
|
|
40
|
+
updateSpotMarketOracle(spotMarketIndex: number, oracle: PublicKey, oracleSource: OracleSource): Promise<TransactionSignature>;
|
|
41
|
+
updateSpotMarketExpiry(spotMarketIndex: number, expiryTs: BN): Promise<TransactionSignature>;
|
|
43
42
|
updateWhitelistMint(whitelistMint?: PublicKey): Promise<TransactionSignature>;
|
|
44
43
|
updateDiscountMint(discountMint: PublicKey): Promise<TransactionSignature>;
|
|
45
|
-
updateMaxDeposit(maxDeposit: BN): Promise<TransactionSignature>;
|
|
46
44
|
updateSpotMarketMarginWeights(spotMarketIndex: number, initialAssetWeight: BN, maintenanceAssetWeight: BN, initialLiabilityWeight: BN, maintenanceLiabilityWeight: BN, imfFactor?: BN): Promise<TransactionSignature>;
|
|
47
45
|
updateSpotMarketAssetTier(spotMarketIndex: number, assetTier: AssetTier): Promise<TransactionSignature>;
|
|
48
46
|
updateSpotMarketStatus(spotMarketIndex: number, marketStatus: MarketStatus): Promise<TransactionSignature>;
|
|
@@ -51,8 +49,8 @@ export declare class Admin extends ClearingHouse {
|
|
|
51
49
|
updateExchangeStatus(exchangeStatus: ExchangeStatus): Promise<TransactionSignature>;
|
|
52
50
|
updatePerpAuctionDuration(minDuration: BN | number): Promise<TransactionSignature>;
|
|
53
51
|
updateSpotAuctionDuration(defaultAuctionDuration: number): Promise<TransactionSignature>;
|
|
54
|
-
|
|
55
|
-
updateMaxSlippageRatio(
|
|
56
|
-
|
|
52
|
+
updatePerpMarketMaxFillReserveFraction(perpMarketIndex: number, maxBaseAssetAmountRatio: number): Promise<TransactionSignature>;
|
|
53
|
+
updateMaxSlippageRatio(perpMarketIndex: number, maxSlippageRatio: number): Promise<TransactionSignature>;
|
|
54
|
+
updatePerpMarketMaxImbalances(perpMarketIndex: number, unrealizedMaxImbalance: BN, maxRevenueWithdrawPerPeriod: BN, quoteMaxInsurance: BN): Promise<TransactionSignature>;
|
|
57
55
|
updateSerumVault(srmVault: PublicKey): Promise<TransactionSignature>;
|
|
58
56
|
}
|