@drift-labs/sdk 2.38.1-beta.3 → 2.38.1-beta.5
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/VERSION +1 -1
- package/lib/accounts/pollingUserAccountSubscriber.js +2 -2
- package/lib/accounts/webSocketAccountSubscriber.js +1 -1
- package/lib/driftClient.js +7 -2
- package/lib/examples/loadDlob.js +3 -1
- package/lib/examples/makeTradeExample.js +3 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/orderSubscriber/OrderSubscriber.js +1 -1
- package/lib/priorityFee/priorityFeeSubscriber.d.ts +22 -0
- package/lib/priorityFee/priorityFeeSubscriber.js +46 -0
- package/lib/tokenFaucet.js +1 -0
- package/lib/userMap/userMap.js +2 -2
- package/lib/userMap/userStatsMap.js +1 -1
- package/package.json +2 -2
- package/src/accounts/pollingUserAccountSubscriber.ts +5 -6
- package/src/accounts/webSocketAccountSubscriber.ts +4 -3
- package/src/driftClient.ts +3 -0
- package/src/examples/loadDlob.ts +1 -0
- package/src/examples/makeTradeExample.ts +1 -0
- package/src/index.ts +1 -0
- package/src/orderSubscriber/OrderSubscriber.ts +1 -1
- package/src/priorityFee/priorityFeeSubscriber.ts +75 -0
- package/src/tokenFaucet.ts +1 -0
- package/src/userMap/userMap.ts +2 -2
- package/src/userMap/userStatsMap.ts +1 -1
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.38.1-beta.
|
|
1
|
+
2.38.1-beta.5
|
|
@@ -37,7 +37,7 @@ class PollingUserAccountSubscriber {
|
|
|
37
37
|
if (this.user && this.user.slot > slot) {
|
|
38
38
|
return;
|
|
39
39
|
}
|
|
40
|
-
const account = this.program.account.user.coder.accounts.
|
|
40
|
+
const account = this.program.account.user.coder.accounts.decode('User', buffer);
|
|
41
41
|
this.user = { data: account, slot };
|
|
42
42
|
this.eventEmitter.emit('userAccountUpdate', account);
|
|
43
43
|
this.eventEmitter.emit('update');
|
|
@@ -57,7 +57,7 @@ class PollingUserAccountSubscriber {
|
|
|
57
57
|
const { buffer, slot } = this.accountLoader.getBufferAndSlot(this.userAccountPublicKey);
|
|
58
58
|
const currentSlot = (_b = (_a = this.user) === null || _a === void 0 ? void 0 : _a.slot) !== null && _b !== void 0 ? _b : 0;
|
|
59
59
|
if (buffer && slot > currentSlot) {
|
|
60
|
-
const account = this.program.account.user.coder.accounts.
|
|
60
|
+
const account = this.program.account.user.coder.accounts.decode('User', buffer);
|
|
61
61
|
this.user = { data: account, slot };
|
|
62
62
|
}
|
|
63
63
|
}
|
|
@@ -78,7 +78,7 @@ class WebSocketAccountSubscriber {
|
|
|
78
78
|
return this.decodeBufferFn(buffer);
|
|
79
79
|
}
|
|
80
80
|
else {
|
|
81
|
-
return this.program.account[this.accountName].coder.accounts.
|
|
81
|
+
return this.program.account[this.accountName].coder.accounts.decode((0, utils_1.capitalize)(this.accountName), buffer);
|
|
82
82
|
}
|
|
83
83
|
}
|
|
84
84
|
unsubscribe() {
|
package/lib/driftClient.js
CHANGED
|
@@ -76,7 +76,9 @@ class DriftClient {
|
|
|
76
76
|
this.connection = config.connection;
|
|
77
77
|
this.wallet = config.wallet;
|
|
78
78
|
this.opts = config.opts || anchor_1.AnchorProvider.defaultOptions();
|
|
79
|
-
this.provider = new anchor_1.AnchorProvider(config.connection,
|
|
79
|
+
this.provider = new anchor_1.AnchorProvider(config.connection,
|
|
80
|
+
// @ts-ignore
|
|
81
|
+
config.wallet, this.opts);
|
|
80
82
|
this.program = new anchor_1.Program(drift_json_1.default, (_a = config.programID) !== null && _a !== void 0 ? _a : new web3_js_1.PublicKey(config_1.DRIFT_PROGRAM_ID), this.provider);
|
|
81
83
|
this.authority = (_b = config.authority) !== null && _b !== void 0 ? _b : this.wallet.publicKey;
|
|
82
84
|
this.activeSubAccountId = (_c = config.activeSubAccountId) !== null && _c !== void 0 ? _c : 0;
|
|
@@ -292,7 +294,9 @@ class DriftClient {
|
|
|
292
294
|
* @param includeDelegates
|
|
293
295
|
*/
|
|
294
296
|
async updateWallet(newWallet, subAccountIds, activeSubAccountId, includeDelegates, authoritySubaccountMap) {
|
|
295
|
-
const newProvider = new anchor_1.AnchorProvider(this.connection,
|
|
297
|
+
const newProvider = new anchor_1.AnchorProvider(this.connection,
|
|
298
|
+
// @ts-ignore
|
|
299
|
+
newWallet, this.opts);
|
|
296
300
|
const newProgram = new anchor_1.Program(drift_json_1.default, this.program.programId, newProvider);
|
|
297
301
|
this.skipLoadUsers = false;
|
|
298
302
|
// Update provider for txSender with new wallet details
|
|
@@ -1374,6 +1378,7 @@ class DriftClient {
|
|
|
1374
1378
|
]);
|
|
1375
1379
|
const { txSig, slot } = await this.txSender.sendRawTransaction(signedVersionedMarketOrderTx.serialize(), this.opts);
|
|
1376
1380
|
this.perpMarketLastSlotCache.set(orderParams.marketIndex, slot);
|
|
1381
|
+
// @ts-ignore
|
|
1377
1382
|
return { txSig, signedFillTx: signedVersionedFillTx };
|
|
1378
1383
|
}
|
|
1379
1384
|
else {
|
package/lib/examples/loadDlob.js
CHANGED
|
@@ -16,7 +16,9 @@ const main = async () => {
|
|
|
16
16
|
const rpcAddress = process.env.RPC_ADDRESS; // can use: https://api.devnet.solana.com for devnet; https://api.mainnet-beta.solana.com for mainnet;
|
|
17
17
|
const connection = new web3_js_1.Connection(rpcAddress);
|
|
18
18
|
// Set up the Provider
|
|
19
|
-
const provider = new anchor_1.AnchorProvider(connection,
|
|
19
|
+
const provider = new anchor_1.AnchorProvider(connection,
|
|
20
|
+
// @ts-ignore
|
|
21
|
+
wallet, anchor_1.AnchorProvider.defaultOptions());
|
|
20
22
|
// Set up the Drift Clearing House
|
|
21
23
|
const driftPublicKey = new web3_js_1.PublicKey(sdkConfig.DRIFT_PROGRAM_ID);
|
|
22
24
|
const bulkAccountLoader = new __2.BulkAccountLoader(connection, 'confirmed', 1000);
|
|
@@ -23,7 +23,9 @@ const main = async () => {
|
|
|
23
23
|
const rpcAddress = process.env.RPC_ADDRESS; // can use: https://api.devnet.solana.com for devnet; https://api.mainnet-beta.solana.com for mainnet;
|
|
24
24
|
const connection = new web3_js_1.Connection(rpcAddress);
|
|
25
25
|
// Set up the Provider
|
|
26
|
-
const provider = new anchor_1.AnchorProvider(connection,
|
|
26
|
+
const provider = new anchor_1.AnchorProvider(connection,
|
|
27
|
+
// @ts-ignore
|
|
28
|
+
wallet, anchor_1.AnchorProvider.defaultOptions());
|
|
27
29
|
// Check SOL Balance
|
|
28
30
|
const lamportsBalance = await connection.getBalance(wallet.publicKey);
|
|
29
31
|
console.log('SOL balance:', lamportsBalance / 10 ** 9);
|
package/lib/index.d.ts
CHANGED
|
@@ -59,6 +59,7 @@ export * from './constants/numericConstants';
|
|
|
59
59
|
export * from './serum/serumSubscriber';
|
|
60
60
|
export * from './serum/serumFulfillmentConfigMap';
|
|
61
61
|
export * from './phoenix/phoenixSubscriber';
|
|
62
|
+
export * from './priorityFee/priorityFeeSubscriber';
|
|
62
63
|
export * from './phoenix/phoenixFulfillmentConfigMap';
|
|
63
64
|
export * from './tx/fastSingleTxSender';
|
|
64
65
|
export * from './tx/retryTxSender';
|
package/lib/index.js
CHANGED
|
@@ -82,6 +82,7 @@ __exportStar(require("./constants/numericConstants"), exports);
|
|
|
82
82
|
__exportStar(require("./serum/serumSubscriber"), exports);
|
|
83
83
|
__exportStar(require("./serum/serumFulfillmentConfigMap"), exports);
|
|
84
84
|
__exportStar(require("./phoenix/phoenixSubscriber"), exports);
|
|
85
|
+
__exportStar(require("./priorityFee/priorityFeeSubscriber"), exports);
|
|
85
86
|
__exportStar(require("./phoenix/phoenixFulfillmentConfigMap"), exports);
|
|
86
87
|
__exportStar(require("./tx/fastSingleTxSender"), exports);
|
|
87
88
|
__exportStar(require("./tx/retryTxSender"), exports);
|
|
@@ -76,7 +76,7 @@ class OrderSubscriber {
|
|
|
76
76
|
tryUpdateUserAccount(key, buffer, slot) {
|
|
77
77
|
const slotAndUserAccount = this.usersAccounts.get(key);
|
|
78
78
|
if (!slotAndUserAccount || slotAndUserAccount.slot < slot) {
|
|
79
|
-
const userAccount = this.driftClient.program.account.user.coder.accounts.
|
|
79
|
+
const userAccount = this.driftClient.program.account.user.coder.accounts.decode('User', buffer);
|
|
80
80
|
const newOrders = userAccount.orders.filter((order) => {
|
|
81
81
|
var _a;
|
|
82
82
|
return order.slot.toNumber() > ((_a = slotAndUserAccount === null || slotAndUserAccount === void 0 ? void 0 : slotAndUserAccount.slot) !== null && _a !== void 0 ? _a : 0) &&
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Connection, PublicKey } from '@solana/web3.js';
|
|
3
|
+
export declare class PriorityFeeSubscriber {
|
|
4
|
+
connection: Connection;
|
|
5
|
+
frequencyMs: number;
|
|
6
|
+
addresses: PublicKey[];
|
|
7
|
+
slotsToCheck: number;
|
|
8
|
+
intervalId?: NodeJS.Timer;
|
|
9
|
+
latestPriorityFee: number;
|
|
10
|
+
avgPriorityFee: number;
|
|
11
|
+
maxPriorityFee: number;
|
|
12
|
+
lastSlotSeen: number;
|
|
13
|
+
constructor({ connection, frequencyMs, addresses, slotsToCheck, }: {
|
|
14
|
+
connection: Connection;
|
|
15
|
+
frequencyMs: number;
|
|
16
|
+
addresses: PublicKey[];
|
|
17
|
+
slotsToCheck?: number;
|
|
18
|
+
});
|
|
19
|
+
subscribe(): Promise<void>;
|
|
20
|
+
load(): Promise<void>;
|
|
21
|
+
unsubscribe(): Promise<void>;
|
|
22
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PriorityFeeSubscriber = void 0;
|
|
4
|
+
class PriorityFeeSubscriber {
|
|
5
|
+
constructor({ connection, frequencyMs, addresses, slotsToCheck = 10, }) {
|
|
6
|
+
this.latestPriorityFee = 0;
|
|
7
|
+
// avg of last {slotsToCheck} slots
|
|
8
|
+
this.avgPriorityFee = 0;
|
|
9
|
+
// max of last {slotsToCheck} slots
|
|
10
|
+
this.maxPriorityFee = 0;
|
|
11
|
+
this.lastSlotSeen = 0;
|
|
12
|
+
this.connection = connection;
|
|
13
|
+
this.frequencyMs = frequencyMs;
|
|
14
|
+
this.addresses = addresses;
|
|
15
|
+
this.slotsToCheck = slotsToCheck;
|
|
16
|
+
}
|
|
17
|
+
async subscribe() {
|
|
18
|
+
if (this.intervalId) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
this.intervalId = setInterval(this.load.bind(this), this.frequencyMs);
|
|
22
|
+
}
|
|
23
|
+
async load() {
|
|
24
|
+
var _a, _b, _c;
|
|
25
|
+
// @ts-ignore
|
|
26
|
+
const rpcJSONResponse = await this.connection._rpcRequest('getRecentPrioritizationFees', [this.addresses]);
|
|
27
|
+
const descResults = (_c = (_b = (_a = rpcJSONResponse === null || rpcJSONResponse === void 0 ? void 0 : rpcJSONResponse.result) === null || _a === void 0 ? void 0 : _a.sort((a, b) => b.slot - a.slot)) === null || _b === void 0 ? void 0 : _b.slice(0, this.slotsToCheck)) !== null && _c !== void 0 ? _c : [];
|
|
28
|
+
if (!(descResults === null || descResults === void 0 ? void 0 : descResults.length))
|
|
29
|
+
return;
|
|
30
|
+
const mostRecentResult = descResults[0];
|
|
31
|
+
this.latestPriorityFee = mostRecentResult.prioritizationFee;
|
|
32
|
+
this.lastSlotSeen = mostRecentResult.slot;
|
|
33
|
+
this.avgPriorityFee =
|
|
34
|
+
descResults.reduce((a, b) => {
|
|
35
|
+
return a + b.prioritizationFee;
|
|
36
|
+
}, 0) / descResults.length;
|
|
37
|
+
this.maxPriorityFee = Math.max(...descResults.map((result) => result.prioritizationFee));
|
|
38
|
+
}
|
|
39
|
+
async unsubscribe() {
|
|
40
|
+
if (this.intervalId) {
|
|
41
|
+
clearInterval(this.intervalId);
|
|
42
|
+
this.intervalId = undefined;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
exports.PriorityFeeSubscriber = PriorityFeeSubscriber;
|
package/lib/tokenFaucet.js
CHANGED
|
@@ -37,6 +37,7 @@ class TokenFaucet {
|
|
|
37
37
|
this.connection = connection;
|
|
38
38
|
this.wallet = wallet;
|
|
39
39
|
this.opts = opts || anchor_1.AnchorProvider.defaultOptions();
|
|
40
|
+
// @ts-ignore
|
|
40
41
|
const provider = new anchor_1.AnchorProvider(connection, wallet, this.opts);
|
|
41
42
|
this.provider = provider;
|
|
42
43
|
this.program = new anchor_1.Program(token_faucet_json_1.default, programId, provider);
|
package/lib/userMap/userMap.js
CHANGED
|
@@ -165,7 +165,7 @@ class UserMap {
|
|
|
165
165
|
}
|
|
166
166
|
for (const [key, buffer] of programAccountBufferMap.entries()) {
|
|
167
167
|
if (!this.has(key)) {
|
|
168
|
-
const userAccount = this.driftClient.program.account.user.coder.accounts.
|
|
168
|
+
const userAccount = this.driftClient.program.account.user.coder.accounts.decode('User', buffer);
|
|
169
169
|
await this.addPubkey(new web3_js_1.PublicKey(key), userAccount);
|
|
170
170
|
}
|
|
171
171
|
}
|
|
@@ -175,7 +175,7 @@ class UserMap {
|
|
|
175
175
|
this.userMap.delete(key);
|
|
176
176
|
}
|
|
177
177
|
else {
|
|
178
|
-
const userAccount = this.driftClient.program.account.user.coder.accounts.
|
|
178
|
+
const userAccount = this.driftClient.program.account.user.coder.accounts.decode('User', programAccountBufferMap.get(key));
|
|
179
179
|
user.accountSubscriber.updateData(userAccount, slot);
|
|
180
180
|
}
|
|
181
181
|
}
|
|
@@ -141,7 +141,7 @@ class UserStatsMap {
|
|
|
141
141
|
}
|
|
142
142
|
for (const key of programAccountMap.keys()) {
|
|
143
143
|
if (!this.has(key)) {
|
|
144
|
-
const userStatsAccount = this.driftClient.program.account.userStats.coder.accounts.
|
|
144
|
+
const userStatsAccount = this.driftClient.program.account.userStats.coder.accounts.decode('UserStats', programAccountMap.get(key).data);
|
|
145
145
|
await this.addUserStat(new web3_js_1.PublicKey(key), userStatsAccount);
|
|
146
146
|
}
|
|
147
147
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@drift-labs/sdk",
|
|
3
|
-
"version": "2.38.1-beta.
|
|
3
|
+
"version": "2.38.1-beta.5",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"types": "lib/index.d.ts",
|
|
6
6
|
"author": "crispheaney",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"access": "public"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@coral-xyz/anchor": "0.
|
|
37
|
+
"@coral-xyz/anchor": "0.28.1-beta.2",
|
|
38
38
|
"@ellipsis-labs/phoenix-sdk": "^1.4.2",
|
|
39
39
|
"@project-serum/serum": "^0.13.38",
|
|
40
40
|
"@pythnetwork/client": "2.5.3",
|
|
@@ -71,11 +71,10 @@ export class PollingUserAccountSubscriber implements UserAccountSubscriber {
|
|
|
71
71
|
return;
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
const account =
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
);
|
|
74
|
+
const account = this.program.account.user.coder.accounts.decode(
|
|
75
|
+
'User',
|
|
76
|
+
buffer
|
|
77
|
+
);
|
|
79
78
|
this.user = { data: account, slot };
|
|
80
79
|
this.eventEmitter.emit('userAccountUpdate', account);
|
|
81
80
|
this.eventEmitter.emit('update');
|
|
@@ -100,7 +99,7 @@ export class PollingUserAccountSubscriber implements UserAccountSubscriber {
|
|
|
100
99
|
);
|
|
101
100
|
const currentSlot = this.user?.slot ?? 0;
|
|
102
101
|
if (buffer && slot > currentSlot) {
|
|
103
|
-
const account = this.program.account.user.coder.accounts.
|
|
102
|
+
const account = this.program.account.user.coder.accounts.decode(
|
|
104
103
|
'User',
|
|
105
104
|
buffer
|
|
106
105
|
);
|
|
@@ -112,9 +112,10 @@ export class WebSocketAccountSubscriber<T> implements AccountSubscriber<T> {
|
|
|
112
112
|
if (this.decodeBufferFn) {
|
|
113
113
|
return this.decodeBufferFn(buffer);
|
|
114
114
|
} else {
|
|
115
|
-
return this.program.account[
|
|
116
|
-
this.accountName
|
|
117
|
-
|
|
115
|
+
return this.program.account[this.accountName].coder.accounts.decode(
|
|
116
|
+
capitalize(this.accountName),
|
|
117
|
+
buffer
|
|
118
|
+
);
|
|
118
119
|
}
|
|
119
120
|
}
|
|
120
121
|
|
package/src/driftClient.ts
CHANGED
|
@@ -174,6 +174,7 @@ export class DriftClient {
|
|
|
174
174
|
this.opts = config.opts || AnchorProvider.defaultOptions();
|
|
175
175
|
this.provider = new AnchorProvider(
|
|
176
176
|
config.connection,
|
|
177
|
+
// @ts-ignore
|
|
177
178
|
config.wallet,
|
|
178
179
|
this.opts
|
|
179
180
|
);
|
|
@@ -512,6 +513,7 @@ export class DriftClient {
|
|
|
512
513
|
): Promise<boolean> {
|
|
513
514
|
const newProvider = new AnchorProvider(
|
|
514
515
|
this.connection,
|
|
516
|
+
// @ts-ignore
|
|
515
517
|
newWallet,
|
|
516
518
|
this.opts
|
|
517
519
|
);
|
|
@@ -2473,6 +2475,7 @@ export class DriftClient {
|
|
|
2473
2475
|
);
|
|
2474
2476
|
this.perpMarketLastSlotCache.set(orderParams.marketIndex, slot);
|
|
2475
2477
|
|
|
2478
|
+
// @ts-ignore
|
|
2476
2479
|
return { txSig, signedFillTx: signedVersionedFillTx };
|
|
2477
2480
|
} else {
|
|
2478
2481
|
const marketOrderTx = wrapInTx(
|
package/src/examples/loadDlob.ts
CHANGED
package/src/index.ts
CHANGED
|
@@ -60,6 +60,7 @@ export * from './constants/numericConstants';
|
|
|
60
60
|
export * from './serum/serumSubscriber';
|
|
61
61
|
export * from './serum/serumFulfillmentConfigMap';
|
|
62
62
|
export * from './phoenix/phoenixSubscriber';
|
|
63
|
+
export * from './priorityFee/priorityFeeSubscriber';
|
|
63
64
|
export * from './phoenix/phoenixFulfillmentConfigMap';
|
|
64
65
|
export * from './tx/fastSingleTxSender';
|
|
65
66
|
export * from './tx/retryTxSender';
|
|
@@ -106,7 +106,7 @@ export class OrderSubscriber {
|
|
|
106
106
|
const slotAndUserAccount = this.usersAccounts.get(key);
|
|
107
107
|
if (!slotAndUserAccount || slotAndUserAccount.slot < slot) {
|
|
108
108
|
const userAccount =
|
|
109
|
-
this.driftClient.program.account.user.coder.accounts.
|
|
109
|
+
this.driftClient.program.account.user.coder.accounts.decode(
|
|
110
110
|
'User',
|
|
111
111
|
buffer
|
|
112
112
|
) as UserAccount;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { Connection, PublicKey } from '@solana/web3.js';
|
|
2
|
+
|
|
3
|
+
export class PriorityFeeSubscriber {
|
|
4
|
+
connection: Connection;
|
|
5
|
+
frequencyMs: number;
|
|
6
|
+
addresses: PublicKey[];
|
|
7
|
+
slotsToCheck: number;
|
|
8
|
+
|
|
9
|
+
intervalId?: NodeJS.Timer;
|
|
10
|
+
|
|
11
|
+
latestPriorityFee = 0;
|
|
12
|
+
// avg of last {slotsToCheck} slots
|
|
13
|
+
avgPriorityFee = 0;
|
|
14
|
+
// max of last {slotsToCheck} slots
|
|
15
|
+
maxPriorityFee = 0;
|
|
16
|
+
lastSlotSeen = 0;
|
|
17
|
+
|
|
18
|
+
public constructor({
|
|
19
|
+
connection,
|
|
20
|
+
frequencyMs,
|
|
21
|
+
addresses,
|
|
22
|
+
slotsToCheck = 10,
|
|
23
|
+
}: {
|
|
24
|
+
connection: Connection;
|
|
25
|
+
frequencyMs: number;
|
|
26
|
+
addresses: PublicKey[];
|
|
27
|
+
slotsToCheck?: number;
|
|
28
|
+
}) {
|
|
29
|
+
this.connection = connection;
|
|
30
|
+
this.frequencyMs = frequencyMs;
|
|
31
|
+
this.addresses = addresses;
|
|
32
|
+
this.slotsToCheck = slotsToCheck;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
public async subscribe(): Promise<void> {
|
|
36
|
+
if (this.intervalId) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
this.intervalId = setInterval(this.load.bind(this), this.frequencyMs);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
public async load(): Promise<void> {
|
|
44
|
+
// @ts-ignore
|
|
45
|
+
const rpcJSONResponse: any = await this.connection._rpcRequest(
|
|
46
|
+
'getRecentPrioritizationFees',
|
|
47
|
+
[this.addresses]
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
const descResults: { slot: number; prioritizationFee: number }[] =
|
|
51
|
+
rpcJSONResponse?.result
|
|
52
|
+
?.sort((a, b) => b.slot - a.slot)
|
|
53
|
+
?.slice(0, this.slotsToCheck) ?? [];
|
|
54
|
+
|
|
55
|
+
if (!descResults?.length) return;
|
|
56
|
+
|
|
57
|
+
const mostRecentResult = descResults[0];
|
|
58
|
+
this.latestPriorityFee = mostRecentResult.prioritizationFee;
|
|
59
|
+
this.lastSlotSeen = mostRecentResult.slot;
|
|
60
|
+
this.avgPriorityFee =
|
|
61
|
+
descResults.reduce((a, b) => {
|
|
62
|
+
return a + b.prioritizationFee;
|
|
63
|
+
}, 0) / descResults.length;
|
|
64
|
+
this.maxPriorityFee = Math.max(
|
|
65
|
+
...descResults.map((result) => result.prioritizationFee)
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
public async unsubscribe(): Promise<void> {
|
|
70
|
+
if (this.intervalId) {
|
|
71
|
+
clearInterval(this.intervalId);
|
|
72
|
+
this.intervalId = undefined;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
package/src/tokenFaucet.ts
CHANGED
|
@@ -38,6 +38,7 @@ export class TokenFaucet {
|
|
|
38
38
|
this.connection = connection;
|
|
39
39
|
this.wallet = wallet;
|
|
40
40
|
this.opts = opts || AnchorProvider.defaultOptions();
|
|
41
|
+
// @ts-ignore
|
|
41
42
|
const provider = new AnchorProvider(connection, wallet, this.opts);
|
|
42
43
|
this.provider = provider;
|
|
43
44
|
this.program = new Program(tokenFaucet as Idl, programId, provider);
|
package/src/userMap/userMap.ts
CHANGED
|
@@ -235,7 +235,7 @@ export class UserMap implements UserMapInterface {
|
|
|
235
235
|
for (const [key, buffer] of programAccountBufferMap.entries()) {
|
|
236
236
|
if (!this.has(key)) {
|
|
237
237
|
const userAccount =
|
|
238
|
-
this.driftClient.program.account.user.coder.accounts.
|
|
238
|
+
this.driftClient.program.account.user.coder.accounts.decode(
|
|
239
239
|
'User',
|
|
240
240
|
buffer
|
|
241
241
|
);
|
|
@@ -249,7 +249,7 @@ export class UserMap implements UserMapInterface {
|
|
|
249
249
|
this.userMap.delete(key);
|
|
250
250
|
} else {
|
|
251
251
|
const userAccount =
|
|
252
|
-
this.driftClient.program.account.user.coder.accounts.
|
|
252
|
+
this.driftClient.program.account.user.coder.accounts.decode(
|
|
253
253
|
'User',
|
|
254
254
|
programAccountBufferMap.get(key)
|
|
255
255
|
);
|
|
@@ -197,7 +197,7 @@ export class UserStatsMap {
|
|
|
197
197
|
for (const key of programAccountMap.keys()) {
|
|
198
198
|
if (!this.has(key)) {
|
|
199
199
|
const userStatsAccount =
|
|
200
|
-
this.driftClient.program.account.userStats.coder.accounts.
|
|
200
|
+
this.driftClient.program.account.userStats.coder.accounts.decode(
|
|
201
201
|
'UserStats',
|
|
202
202
|
programAccountMap.get(key).data
|
|
203
203
|
);
|