@drift-labs/sdk 2.20.0-beta.0 → 2.20.0-beta.2
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.d.ts +2 -1
- package/lib/accounts/bulkAccountLoader.js +7 -7
- package/lib/accounts/fetch.d.ts +1 -0
- package/lib/accounts/fetch.js +8 -4
- package/lib/accounts/pollingDriftClientAccountSubscriber.js +7 -7
- package/lib/accounts/pollingTokenAccountSubscriber.js +2 -2
- package/lib/accounts/pollingUserAccountSubscriber.js +2 -2
- package/lib/accounts/pollingUserStatsAccountSubscriber.js +2 -2
- package/lib/accounts/types.d.ts +5 -4
- package/lib/accounts/webSocketAccountSubscriber.js +1 -1
- package/lib/accounts/webSocketDriftClientAccountSubscriber.js +3 -3
- package/lib/addresses/marketAddresses.js +1 -1
- package/lib/addresses/pda.d.ts +1 -0
- package/lib/addresses/pda.js +13 -2
- package/lib/adminClient.js +61 -57
- package/lib/config.d.ts +2 -2
- package/lib/constants/perpMarkets.d.ts +1 -1
- package/lib/constants/spotMarkets.d.ts +1 -1
- package/lib/dlob/DLOB.d.ts +6 -5
- package/lib/dlob/DLOB.js +105 -75
- package/lib/dlob/DLOBNode.d.ts +2 -2
- package/lib/dlob/DLOBNode.js +7 -7
- package/lib/dlob/DLOBOrders.d.ts +2 -2
- package/lib/dlob/NodeList.d.ts +1 -1
- package/lib/dlob/NodeList.js +2 -2
- package/lib/driftClient.d.ts +5 -2
- package/lib/driftClient.js +137 -95
- package/lib/driftClientConfig.d.ts +3 -3
- package/lib/events/eventSubscriber.js +2 -2
- package/lib/events/fetchLogs.d.ts +2 -2
- package/lib/events/pollingLogProvider.js +1 -1
- package/lib/events/types.d.ts +14 -14
- package/lib/examples/loadDlob.js +2 -2
- package/lib/examples/makeTradeExample.js +9 -9
- package/lib/factory/bigNum.js +13 -13
- package/lib/factory/oracleClient.js +4 -4
- package/lib/idl/drift.json +82 -4
- package/lib/index.js +5 -1
- package/lib/math/amm.d.ts +1 -1
- package/lib/math/amm.js +23 -23
- package/lib/math/auction.js +6 -6
- package/lib/math/exchangeStatus.js +2 -2
- package/lib/math/funding.js +2 -2
- package/lib/math/margin.js +4 -4
- package/lib/math/market.js +15 -15
- package/lib/math/oracles.js +1 -1
- package/lib/math/orders.js +27 -24
- package/lib/math/position.js +5 -5
- package/lib/math/repeg.js +1 -1
- package/lib/math/spotBalance.js +9 -9
- package/lib/math/spotMarket.js +3 -3
- package/lib/math/spotPosition.js +3 -3
- package/lib/math/trade.d.ts +1 -1
- package/lib/math/trade.js +42 -42
- package/lib/math/utils.js +1 -1
- package/lib/oracles/oracleClientCache.js +1 -1
- package/lib/oracles/pythClient.js +1 -1
- package/lib/oracles/types.d.ts +2 -2
- package/lib/serum/types.d.ts +1 -1
- package/lib/slot/SlotSubscriber.d.ts +1 -1
- package/lib/tokenFaucet.js +5 -1
- package/lib/tx/retryTxSender.d.ts +1 -1
- package/lib/tx/retryTxSender.js +1 -1
- package/lib/tx/types.d.ts +1 -1
- package/lib/types.d.ts +71 -44
- package/lib/user.js +63 -63
- package/lib/userConfig.d.ts +2 -2
- package/lib/userMap/userMap.js +1 -1
- package/lib/userMap/userStatsMap.js +3 -3
- package/lib/userStats.js +2 -2
- package/lib/userStatsConfig.d.ts +2 -2
- package/package.json +1 -1
- package/src/accounts/bulkAccountLoader.ts +5 -5
- package/src/accounts/fetch.ts +8 -0
- package/src/addresses/pda.ts +13 -0
- package/src/dlob/DLOB.ts +55 -8
- package/src/driftClient.ts +77 -0
- package/src/idl/drift.json +82 -4
- package/src/math/orders.ts +5 -1
- package/src/types.ts +29 -0
- package/src/userMap/userStatsMap.ts +1 -4
- package/tests/amm/test.ts +24 -28
- package/tests/dlob/test.ts +67 -73
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
+
/// <reference types="node" />
|
|
2
3
|
import { Commitment, Connection, PublicKey } from '@solana/web3.js';
|
|
3
4
|
import { BufferAndSlot } from './types';
|
|
4
|
-
|
|
5
|
+
type AccountToLoad = {
|
|
5
6
|
publicKey: PublicKey;
|
|
6
7
|
callbacks: Map<string, (buffer: Buffer, slot: number) => void>;
|
|
7
8
|
};
|
|
@@ -18,7 +18,7 @@ class BulkAccountLoader {
|
|
|
18
18
|
}
|
|
19
19
|
async addAccount(publicKey, callback) {
|
|
20
20
|
const existingSize = this.accountsToLoad.size;
|
|
21
|
-
const callbackId = uuid_1.v4();
|
|
21
|
+
const callbackId = (0, uuid_1.v4)();
|
|
22
22
|
const existingAccountToLoad = this.accountsToLoad.get(publicKey.toString());
|
|
23
23
|
if (existingAccountToLoad) {
|
|
24
24
|
existingAccountToLoad.callbacks.set(callbackId, callback);
|
|
@@ -52,7 +52,7 @@ class BulkAccountLoader {
|
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
54
|
addErrorCallbacks(callback) {
|
|
55
|
-
const callbackId = uuid_1.v4();
|
|
55
|
+
const callbackId = (0, uuid_1.v4)();
|
|
56
56
|
this.errorCallbacks.set(callbackId, callback);
|
|
57
57
|
return callbackId;
|
|
58
58
|
}
|
|
@@ -114,7 +114,7 @@ class BulkAccountLoader {
|
|
|
114
114
|
args,
|
|
115
115
|
});
|
|
116
116
|
}
|
|
117
|
-
const rpcResponses = await promiseTimeout_1.promiseTimeout(
|
|
117
|
+
const rpcResponses = await (0, promiseTimeout_1.promiseTimeout)(
|
|
118
118
|
// @ts-ignore
|
|
119
119
|
this.connection._rpcBatchRequest(requests), 10 * 1000 // 30 second timeout
|
|
120
120
|
);
|
|
@@ -131,8 +131,11 @@ class BulkAccountLoader {
|
|
|
131
131
|
const accountsToLoad = accountsToLoadChunks[i];
|
|
132
132
|
for (const j in accountsToLoad) {
|
|
133
133
|
const accountToLoad = accountsToLoad[j];
|
|
134
|
-
const key = accountToLoad.publicKey.
|
|
134
|
+
const key = accountToLoad.publicKey.toBase58();
|
|
135
135
|
const oldRPCResponse = this.bufferAndSlotMap.get(key);
|
|
136
|
+
if (oldRPCResponse && newSlot <= oldRPCResponse.slot) {
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
136
139
|
let newBuffer = undefined;
|
|
137
140
|
if (rpcResponse.result.value[j]) {
|
|
138
141
|
const raw = rpcResponse.result.value[j].data[0];
|
|
@@ -147,9 +150,6 @@ class BulkAccountLoader {
|
|
|
147
150
|
this.handleAccountCallbacks(accountToLoad, newBuffer, newSlot);
|
|
148
151
|
continue;
|
|
149
152
|
}
|
|
150
|
-
if (newSlot <= oldRPCResponse.slot) {
|
|
151
|
-
continue;
|
|
152
|
-
}
|
|
153
153
|
const oldBuffer = oldRPCResponse.buffer;
|
|
154
154
|
if (newBuffer && (!oldBuffer || !newBuffer.equals(oldBuffer))) {
|
|
155
155
|
this.bufferAndSlotMap.set(key, {
|
package/lib/accounts/fetch.d.ts
CHANGED
|
@@ -2,4 +2,5 @@ import { Connection, PublicKey } from '@solana/web3.js';
|
|
|
2
2
|
import { UserAccount, UserStatsAccount } from '../types';
|
|
3
3
|
import { Program } from '@project-serum/anchor';
|
|
4
4
|
export declare function fetchUserAccounts(connection: Connection, program: Program, authority: PublicKey, limit?: number): Promise<(UserAccount | undefined)[]>;
|
|
5
|
+
export declare function fetchUserAccountsUsingKeys(connection: Connection, program: Program, userAccountPublicKeys: PublicKey[]): Promise<(UserAccount | undefined)[]>;
|
|
5
6
|
export declare function fetchUserStatsAccount(connection: Connection, program: Program, authority: PublicKey): Promise<UserStatsAccount | undefined>;
|
package/lib/accounts/fetch.js
CHANGED
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.fetchUserStatsAccount = exports.fetchUserAccounts = void 0;
|
|
3
|
+
exports.fetchUserStatsAccount = exports.fetchUserAccountsUsingKeys = exports.fetchUserAccounts = void 0;
|
|
4
4
|
const pda_1 = require("../addresses/pda");
|
|
5
5
|
async function fetchUserAccounts(connection, program, authority, limit = 8) {
|
|
6
6
|
const userAccountPublicKeys = new Array();
|
|
7
7
|
for (let i = 0; i < limit; i++) {
|
|
8
|
-
userAccountPublicKeys.push(await pda_1.getUserAccountPublicKey(program.programId, authority, i));
|
|
8
|
+
userAccountPublicKeys.push(await (0, pda_1.getUserAccountPublicKey)(program.programId, authority, i));
|
|
9
9
|
}
|
|
10
|
+
return fetchUserAccountsUsingKeys(connection, program, userAccountPublicKeys);
|
|
11
|
+
}
|
|
12
|
+
exports.fetchUserAccounts = fetchUserAccounts;
|
|
13
|
+
async function fetchUserAccountsUsingKeys(connection, program, userAccountPublicKeys) {
|
|
10
14
|
const accountInfos = await connection.getMultipleAccountsInfo(userAccountPublicKeys, 'confirmed');
|
|
11
15
|
return accountInfos.map((accountInfo) => {
|
|
12
16
|
if (!accountInfo) {
|
|
@@ -15,9 +19,9 @@ async function fetchUserAccounts(connection, program, authority, limit = 8) {
|
|
|
15
19
|
return program.account.user.coder.accounts.decode('User', accountInfo.data);
|
|
16
20
|
});
|
|
17
21
|
}
|
|
18
|
-
exports.
|
|
22
|
+
exports.fetchUserAccountsUsingKeys = fetchUserAccountsUsingKeys;
|
|
19
23
|
async function fetchUserStatsAccount(connection, program, authority) {
|
|
20
|
-
const userStatsPublicKey = pda_1.getUserStatsAccountPublicKey(program.programId, authority);
|
|
24
|
+
const userStatsPublicKey = (0, pda_1.getUserStatsAccountPublicKey)(program.programId, authority);
|
|
21
25
|
const accountInfo = await connection.getAccountInfo(userStatsPublicKey, 'confirmed');
|
|
22
26
|
return accountInfo
|
|
23
27
|
? program.account.user.coder.accounts.decode('UserStats', accountInfo.data)
|
|
@@ -58,7 +58,7 @@ class PollingDriftClientAccountSubscriber {
|
|
|
58
58
|
if (this.accountsToPoll.size > 0) {
|
|
59
59
|
return;
|
|
60
60
|
}
|
|
61
|
-
const statePublicKey = await pda_1.getDriftStateAccountPublicKey(this.program.programId);
|
|
61
|
+
const statePublicKey = await (0, pda_1.getDriftStateAccountPublicKey)(this.program.programId);
|
|
62
62
|
this.accountsToPoll.set(statePublicKey.toString(), {
|
|
63
63
|
key: 'state',
|
|
64
64
|
publicKey: statePublicKey,
|
|
@@ -74,7 +74,7 @@ class PollingDriftClientAccountSubscriber {
|
|
|
74
74
|
return true;
|
|
75
75
|
}
|
|
76
76
|
async addPerpMarketAccountToPoll(marketIndex) {
|
|
77
|
-
const perpMarketPublicKey = await pda_1.getPerpMarketPublicKey(this.program.programId, marketIndex);
|
|
77
|
+
const perpMarketPublicKey = await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, marketIndex);
|
|
78
78
|
this.accountsToPoll.set(perpMarketPublicKey.toString(), {
|
|
79
79
|
key: 'perpMarket',
|
|
80
80
|
publicKey: perpMarketPublicKey,
|
|
@@ -90,7 +90,7 @@ class PollingDriftClientAccountSubscriber {
|
|
|
90
90
|
return true;
|
|
91
91
|
}
|
|
92
92
|
async addSpotMarketAccountToPoll(marketIndex) {
|
|
93
|
-
const marketPublicKey = await pda_1.getSpotMarketPublicKey(this.program.programId, marketIndex);
|
|
93
|
+
const marketPublicKey = await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, marketIndex);
|
|
94
94
|
this.accountsToPoll.set(marketPublicKey.toString(), {
|
|
95
95
|
key: 'spotMarket',
|
|
96
96
|
publicKey: marketPublicKey,
|
|
@@ -129,7 +129,7 @@ class PollingDriftClientAccountSubscriber {
|
|
|
129
129
|
accountToPoll.callbackId = await this.accountLoader.addAccount(accountToPoll.publicKey, (buffer, slot) => {
|
|
130
130
|
if (!buffer)
|
|
131
131
|
return;
|
|
132
|
-
const account = this.program.account[accountToPoll.key].coder.accounts.decode(utils_1.capitalize(accountToPoll.key), buffer);
|
|
132
|
+
const account = this.program.account[accountToPoll.key].coder.accounts.decode((0, utils_1.capitalize)(accountToPoll.key), buffer);
|
|
133
133
|
const dataAndSlot = {
|
|
134
134
|
data: account,
|
|
135
135
|
slot,
|
|
@@ -168,7 +168,7 @@ class PollingDriftClientAccountSubscriber {
|
|
|
168
168
|
for (const [_, accountToPoll] of this.accountsToPoll) {
|
|
169
169
|
const { buffer, slot } = this.accountLoader.getBufferAndSlot(accountToPoll.publicKey);
|
|
170
170
|
if (buffer) {
|
|
171
|
-
const account = this.program.account[accountToPoll.key].coder.accounts.decode(utils_1.capitalize(accountToPoll.key), buffer);
|
|
171
|
+
const account = this.program.account[accountToPoll.key].coder.accounts.decode((0, utils_1.capitalize)(accountToPoll.key), buffer);
|
|
172
172
|
if (accountToPoll.mapKey != undefined) {
|
|
173
173
|
this[accountToPoll.key].set(accountToPoll.mapKey, {
|
|
174
174
|
data: account,
|
|
@@ -214,7 +214,7 @@ class PollingDriftClientAccountSubscriber {
|
|
|
214
214
|
this.isSubscribed = false;
|
|
215
215
|
}
|
|
216
216
|
async addSpotMarket(marketIndex) {
|
|
217
|
-
const marketPublicKey = await pda_1.getSpotMarketPublicKey(this.program.programId, marketIndex);
|
|
217
|
+
const marketPublicKey = await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, marketIndex);
|
|
218
218
|
if (this.accountsToPoll.has(marketPublicKey.toString())) {
|
|
219
219
|
return true;
|
|
220
220
|
}
|
|
@@ -224,7 +224,7 @@ class PollingDriftClientAccountSubscriber {
|
|
|
224
224
|
return true;
|
|
225
225
|
}
|
|
226
226
|
async addPerpMarket(marketIndex) {
|
|
227
|
-
const marketPublicKey = await pda_1.getPerpMarketPublicKey(this.program.programId, marketIndex);
|
|
227
|
+
const marketPublicKey = await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, marketIndex);
|
|
228
228
|
if (this.accountsToPoll.has(marketPublicKey.toString())) {
|
|
229
229
|
return true;
|
|
230
230
|
}
|
|
@@ -34,7 +34,7 @@ class PollingTokenAccountSubscriber {
|
|
|
34
34
|
return;
|
|
35
35
|
}
|
|
36
36
|
this.callbackId = await this.accountLoader.addAccount(this.publicKey, (buffer, slot) => {
|
|
37
|
-
const tokenAccount = token_1.parseTokenAccount(buffer);
|
|
37
|
+
const tokenAccount = (0, token_1.parseTokenAccount)(buffer);
|
|
38
38
|
this.tokenAccountAndSlot = { data: tokenAccount, slot };
|
|
39
39
|
// @ts-ignore
|
|
40
40
|
this.eventEmitter.emit('tokenAccountUpdate', tokenAccount);
|
|
@@ -47,7 +47,7 @@ class PollingTokenAccountSubscriber {
|
|
|
47
47
|
async fetch() {
|
|
48
48
|
await this.accountLoader.load();
|
|
49
49
|
const { buffer, slot } = this.accountLoader.getBufferAndSlot(this.publicKey);
|
|
50
|
-
this.tokenAccountAndSlot = { data: token_1.parseTokenAccount(buffer), slot };
|
|
50
|
+
this.tokenAccountAndSlot = { data: (0, token_1.parseTokenAccount)(buffer), slot };
|
|
51
51
|
}
|
|
52
52
|
async unsubscribe() {
|
|
53
53
|
if (!this.isSubscribed) {
|
|
@@ -39,7 +39,7 @@ class PollingUserAccountSubscriber {
|
|
|
39
39
|
if (!buffer) {
|
|
40
40
|
return;
|
|
41
41
|
}
|
|
42
|
-
const account = this.program.account[accountToPoll.key].coder.accounts.decode(utils_1.capitalize(accountToPoll.key), buffer);
|
|
42
|
+
const account = this.program.account[accountToPoll.key].coder.accounts.decode((0, utils_1.capitalize)(accountToPoll.key), buffer);
|
|
43
43
|
this[accountToPoll.key] = { data: account, slot };
|
|
44
44
|
// @ts-ignore
|
|
45
45
|
this.eventEmitter.emit(accountToPoll.eventType, account);
|
|
@@ -67,7 +67,7 @@ class PollingUserAccountSubscriber {
|
|
|
67
67
|
for (const [_, accountToPoll] of this.accountsToPoll) {
|
|
68
68
|
const { buffer, slot } = this.accountLoader.getBufferAndSlot(accountToPoll.publicKey);
|
|
69
69
|
if (buffer) {
|
|
70
|
-
const account = this.program.account[accountToPoll.key].coder.accounts.decode(utils_1.capitalize(accountToPoll.key), buffer);
|
|
70
|
+
const account = this.program.account[accountToPoll.key].coder.accounts.decode((0, utils_1.capitalize)(accountToPoll.key), buffer);
|
|
71
71
|
this[accountToPoll.key] = { data: account, slot };
|
|
72
72
|
}
|
|
73
73
|
}
|
|
@@ -39,7 +39,7 @@ class PollingUserStatsAccountSubscriber {
|
|
|
39
39
|
if (!buffer) {
|
|
40
40
|
return;
|
|
41
41
|
}
|
|
42
|
-
const account = this.program.account[accountToPoll.key].coder.accounts.decode(utils_1.capitalize(accountToPoll.key), buffer);
|
|
42
|
+
const account = this.program.account[accountToPoll.key].coder.accounts.decode((0, utils_1.capitalize)(accountToPoll.key), buffer);
|
|
43
43
|
this[accountToPoll.key] = { data: account, slot };
|
|
44
44
|
// @ts-ignore
|
|
45
45
|
this.eventEmitter.emit(accountToPoll.eventType, account);
|
|
@@ -67,7 +67,7 @@ class PollingUserStatsAccountSubscriber {
|
|
|
67
67
|
for (const [_, accountToPoll] of this.accountsToPoll) {
|
|
68
68
|
const { buffer, slot } = this.accountLoader.getBufferAndSlot(accountToPoll.publicKey);
|
|
69
69
|
if (buffer) {
|
|
70
|
-
const account = this.program.account[accountToPoll.key].coder.accounts.decode(utils_1.capitalize(accountToPoll.key), buffer);
|
|
70
|
+
const account = this.program.account[accountToPoll.key].coder.accounts.decode((0, utils_1.capitalize)(accountToPoll.key), buffer);
|
|
71
71
|
this[accountToPoll.key] = { data: account, slot };
|
|
72
72
|
}
|
|
73
73
|
}
|
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';
|
|
@@ -79,23 +80,23 @@ export interface OracleAccountSubscriber {
|
|
|
79
80
|
unsubscribe(): Promise<void>;
|
|
80
81
|
getOraclePriceData(): DataAndSlot<OraclePriceData>;
|
|
81
82
|
}
|
|
82
|
-
export
|
|
83
|
+
export type AccountToPoll = {
|
|
83
84
|
key: string;
|
|
84
85
|
publicKey: PublicKey;
|
|
85
86
|
eventType: string;
|
|
86
87
|
callbackId?: string;
|
|
87
88
|
mapKey?: number;
|
|
88
89
|
};
|
|
89
|
-
export
|
|
90
|
+
export type OraclesToPoll = {
|
|
90
91
|
publicKey: PublicKey;
|
|
91
92
|
source: OracleSource;
|
|
92
93
|
callbackId?: string;
|
|
93
94
|
};
|
|
94
|
-
export
|
|
95
|
+
export type BufferAndSlot = {
|
|
95
96
|
slot: number;
|
|
96
97
|
buffer: Buffer | undefined;
|
|
97
98
|
};
|
|
98
|
-
export
|
|
99
|
+
export type DataAndSlot<T> = {
|
|
99
100
|
data: T;
|
|
100
101
|
slot: number;
|
|
101
102
|
};
|
|
@@ -77,7 +77,7 @@ class WebSocketAccountSubscriber {
|
|
|
77
77
|
return this.decodeBufferFn(buffer);
|
|
78
78
|
}
|
|
79
79
|
else {
|
|
80
|
-
return this.program.account[this.accountName].coder.accounts.decode(utils_1.capitalize(this.accountName), buffer);
|
|
80
|
+
return this.program.account[this.accountName].coder.accounts.decode((0, utils_1.capitalize)(this.accountName), buffer);
|
|
81
81
|
}
|
|
82
82
|
}
|
|
83
83
|
unsubscribe() {
|
|
@@ -33,7 +33,7 @@ class WebSocketDriftClientAccountSubscriber {
|
|
|
33
33
|
this.subscriptionPromise = new Promise((res) => {
|
|
34
34
|
this.subscriptionPromiseResolver = res;
|
|
35
35
|
});
|
|
36
|
-
const statePublicKey = await pda_1.getDriftStateAccountPublicKey(this.program.programId);
|
|
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) => {
|
|
@@ -59,7 +59,7 @@ class WebSocketDriftClientAccountSubscriber {
|
|
|
59
59
|
return true;
|
|
60
60
|
}
|
|
61
61
|
async subscribeToPerpMarketAccount(marketIndex) {
|
|
62
|
-
const perpMarketPublicKey = await pda_1.getPerpMarketPublicKey(this.program.programId, marketIndex);
|
|
62
|
+
const perpMarketPublicKey = await (0, pda_1.getPerpMarketPublicKey)(this.program.programId, marketIndex);
|
|
63
63
|
const accountSubscriber = new webSocketAccountSubscriber_1.WebSocketAccountSubscriber('perpMarket', this.program, perpMarketPublicKey);
|
|
64
64
|
await accountSubscriber.subscribe((data) => {
|
|
65
65
|
this.eventEmitter.emit('perpMarketAccountUpdate', data);
|
|
@@ -75,7 +75,7 @@ class WebSocketDriftClientAccountSubscriber {
|
|
|
75
75
|
return true;
|
|
76
76
|
}
|
|
77
77
|
async subscribeToSpotMarketAccount(marketIndex) {
|
|
78
|
-
const marketPublicKey = await pda_1.getSpotMarketPublicKey(this.program.programId, marketIndex);
|
|
78
|
+
const marketPublicKey = await (0, pda_1.getSpotMarketPublicKey)(this.program.programId, marketIndex);
|
|
79
79
|
const accountSubscriber = new webSocketAccountSubscriber_1.WebSocketAccountSubscriber('spotMarket', this.program, marketPublicKey);
|
|
80
80
|
await accountSubscriber.subscribe((data) => {
|
|
81
81
|
this.eventEmitter.emit('spotMarketAccountUpdate', data);
|
|
@@ -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 pda_1.getPerpMarketPublicKey(programId, marketIndex);
|
|
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
|
@@ -16,3 +16,4 @@ 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;
|
|
19
|
+
export declare function getReferrerNamePublicKeySync(programId: PublicKey, nameBuffer: number[]): PublicKey;
|
package/lib/addresses/pda.js
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
3
|
if (k2 === undefined) k2 = k;
|
|
4
|
-
Object.
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
5
9
|
}) : (function(o, m, k, k2) {
|
|
6
10
|
if (k2 === undefined) k2 = k;
|
|
7
11
|
o[k2] = m[k];
|
|
@@ -19,7 +23,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
19
23
|
return result;
|
|
20
24
|
};
|
|
21
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
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;
|
|
26
|
+
exports.getReferrerNamePublicKeySync = 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;
|
|
23
27
|
const web3_js_1 = require("@solana/web3.js");
|
|
24
28
|
const anchor = __importStar(require("@project-serum/anchor"));
|
|
25
29
|
async function getDriftStateAccountPublicKeyAndNonce(programId) {
|
|
@@ -115,3 +119,10 @@ function getSerumFulfillmentConfigPublicKey(programId, market) {
|
|
|
115
119
|
], programId)[0];
|
|
116
120
|
}
|
|
117
121
|
exports.getSerumFulfillmentConfigPublicKey = getSerumFulfillmentConfigPublicKey;
|
|
122
|
+
function getReferrerNamePublicKeySync(programId, nameBuffer) {
|
|
123
|
+
return web3_js_1.PublicKey.findProgramAddressSync([
|
|
124
|
+
Buffer.from(anchor.utils.bytes.utf8.encode('referrer_name')),
|
|
125
|
+
Buffer.from(nameBuffer),
|
|
126
|
+
], programId)[0];
|
|
127
|
+
}
|
|
128
|
+
exports.getReferrerNamePublicKeySync = getReferrerNamePublicKeySync;
|