@drift-labs/sdk 2.25.4 → 2.26.0-beta.1
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/examples/phoenix.ts +40 -0
- package/lib/accounts/pollingUserAccountSubscriber.d.ts +5 -4
- package/lib/accounts/pollingUserAccountSubscriber.js +35 -48
- package/lib/accounts/pollingUserStatsAccountSubscriber.d.ts +4 -4
- package/lib/accounts/pollingUserStatsAccountSubscriber.js +30 -47
- package/lib/accounts/types.d.ts +2 -1
- package/lib/accounts/webSocketAccountSubscriber.d.ts +1 -1
- package/lib/accounts/webSocketAccountSubscriber.js +4 -3
- package/lib/accounts/webSocketUserAccountSubscriber.d.ts +1 -0
- package/lib/accounts/webSocketUserAccountSubscriber.js +9 -0
- package/lib/addresses/pda.d.ts +1 -0
- package/lib/addresses/pda.js +8 -1
- package/lib/adminClient.d.ts +1 -0
- package/lib/adminClient.js +20 -0
- package/lib/dlob/DLOBApiClient.d.ts +14 -0
- package/lib/dlob/DLOBApiClient.js +34 -0
- package/lib/dlob/DLOBSubscriber.d.ts +19 -0
- package/lib/dlob/DLOBSubscriber.js +42 -0
- package/lib/dlob/types.d.ts +16 -0
- package/lib/dlob/types.js +2 -0
- package/lib/driftClient.d.ts +13 -10
- package/lib/driftClient.js +124 -28
- package/lib/examples/loadDlob.js +2 -4
- package/lib/idl/drift.json +264 -82
- package/lib/index.d.ts +4 -0
- package/lib/index.js +4 -0
- package/lib/phoenix/phoenixFulfillmentConfigMap.d.ts +10 -0
- package/lib/phoenix/phoenixFulfillmentConfigMap.js +17 -0
- package/lib/phoenix/phoenixSubscriber.d.ts +34 -0
- package/lib/phoenix/phoenixSubscriber.js +79 -0
- package/lib/slot/SlotSubscriber.js +3 -0
- package/lib/tx/retryTxSender.d.ts +2 -1
- package/lib/tx/retryTxSender.js +5 -1
- package/lib/tx/types.d.ts +4 -1
- package/lib/types.d.ts +11 -0
- package/lib/userMap/userMap.d.ts +17 -6
- package/lib/userMap/userMap.js +74 -46
- package/lib/userMap/userStatsMap.d.ts +6 -3
- package/lib/userMap/userStatsMap.js +30 -30
- package/package.json +2 -1
- package/src/accounts/pollingUserAccountSubscriber.ts +51 -63
- package/src/accounts/pollingUserStatsAccountSubscriber.ts +46 -62
- package/src/accounts/types.ts +2 -1
- package/src/accounts/webSocketAccountSubscriber.ts +4 -3
- package/src/accounts/webSocketUserAccountSubscriber.ts +10 -0
- package/src/addresses/pda.ts +13 -0
- package/src/adminClient.ts +34 -0
- package/src/dlob/DLOBApiClient.ts +37 -0
- package/src/dlob/DLOBSubscriber.ts +57 -0
- package/src/dlob/types.ts +20 -0
- package/src/driftClient.ts +216 -59
- package/src/examples/loadDlob.ts +2 -4
- package/src/idl/drift.json +264 -82
- package/src/index.ts +4 -0
- package/src/phoenix/phoenixFulfillmentConfigMap.ts +26 -0
- package/src/phoenix/phoenixSubscriber.ts +156 -0
- package/src/slot/SlotSubscriber.ts +4 -0
- package/src/tx/retryTxSender.ts +19 -2
- package/src/tx/types.ts +13 -0
- package/src/types.ts +12 -0
- package/src/userMap/userMap.ts +111 -60
- package/src/userMap/userStatsMap.ts +43 -44
- package/tests/dlob/helpers.ts +3 -1
- package/src/assert/assert.js +0 -9
- package/src/token/index.js +0 -38
- package/src/util/computeUnits.js +0 -27
- package/src/util/getTokenAddress.js +0 -9
- package/src/util/promiseTimeout.js +0 -14
- package/src/util/tps.js +0 -27
package/src/userMap/userMap.ts
CHANGED
|
@@ -2,7 +2,6 @@ import {
|
|
|
2
2
|
User,
|
|
3
3
|
DriftClient,
|
|
4
4
|
UserAccount,
|
|
5
|
-
bulkPollingUserSubscribe,
|
|
6
5
|
OrderRecord,
|
|
7
6
|
UserSubscriptionConfig,
|
|
8
7
|
WrappedEvent,
|
|
@@ -13,14 +12,17 @@ import {
|
|
|
13
12
|
SettlePnlRecord,
|
|
14
13
|
NewUserRecord,
|
|
15
14
|
LPRecord,
|
|
15
|
+
StateAccount,
|
|
16
|
+
DLOB,
|
|
16
17
|
} from '..';
|
|
17
18
|
|
|
18
|
-
import {
|
|
19
|
+
import { PublicKey, RpcResponseAndContext } from '@solana/web3.js';
|
|
19
20
|
import { Buffer } from 'buffer';
|
|
20
21
|
import bs58 from 'bs58';
|
|
21
22
|
|
|
22
23
|
export interface UserMapInterface {
|
|
23
|
-
|
|
24
|
+
subscribe(): Promise<void>;
|
|
25
|
+
unsubscribe(): Promise<void>;
|
|
24
26
|
addPubkey(userAccountPublicKey: PublicKey): Promise<void>;
|
|
25
27
|
has(key: string): boolean;
|
|
26
28
|
get(key: string): User | undefined;
|
|
@@ -34,59 +36,48 @@ export class UserMap implements UserMapInterface {
|
|
|
34
36
|
private userMap = new Map<string, User>();
|
|
35
37
|
private driftClient: DriftClient;
|
|
36
38
|
private accountSubscription: UserSubscriptionConfig;
|
|
39
|
+
private includeIdle: boolean;
|
|
40
|
+
private lastNumberOfSubAccounts;
|
|
41
|
+
private syncCallback = async (state: StateAccount) => {
|
|
42
|
+
if (state.numberOfSubAccounts !== this.lastNumberOfSubAccounts) {
|
|
43
|
+
await this.sync();
|
|
44
|
+
this.lastNumberOfSubAccounts = state.numberOfSubAccounts;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
37
47
|
|
|
38
48
|
constructor(
|
|
39
49
|
driftClient: DriftClient,
|
|
40
|
-
accountSubscription: UserSubscriptionConfig
|
|
50
|
+
accountSubscription: UserSubscriptionConfig,
|
|
51
|
+
includeIdle = true
|
|
41
52
|
) {
|
|
42
53
|
this.driftClient = driftClient;
|
|
43
54
|
this.accountSubscription = accountSubscription;
|
|
55
|
+
this.includeIdle = includeIdle;
|
|
44
56
|
}
|
|
45
57
|
|
|
46
|
-
public async
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
const programUserAccounts = await this.driftClient.fetchAllUserAccounts(
|
|
51
|
-
includeIdle
|
|
52
|
-
);
|
|
53
|
-
for (const programUserAccount of programUserAccounts) {
|
|
54
|
-
if (this.userMap.has(programUserAccount.publicKey.toString())) {
|
|
55
|
-
continue;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const user = new User({
|
|
59
|
-
driftClient: this.driftClient,
|
|
60
|
-
userAccountPublicKey: programUserAccount.publicKey,
|
|
61
|
-
accountSubscription: this.accountSubscription,
|
|
62
|
-
});
|
|
63
|
-
userArray.push(user);
|
|
64
|
-
userAccountArray.push(programUserAccount.account);
|
|
58
|
+
public async subscribe() {
|
|
59
|
+
if (this.size() > 0) {
|
|
60
|
+
return;
|
|
65
61
|
}
|
|
66
62
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
);
|
|
72
|
-
} else {
|
|
73
|
-
await Promise.all(
|
|
74
|
-
userArray.map((user, i) => user.subscribe(userAccountArray[i]))
|
|
75
|
-
);
|
|
76
|
-
}
|
|
63
|
+
await this.driftClient.subscribe();
|
|
64
|
+
this.lastNumberOfSubAccounts =
|
|
65
|
+
this.driftClient.getStateAccount().numberOfSubAccounts;
|
|
66
|
+
this.driftClient.eventEmitter.on('stateAccountUpdate', this.syncCallback);
|
|
77
67
|
|
|
78
|
-
|
|
79
|
-
this.userMap.set(user.getUserAccountPublicKey().toString(), user);
|
|
80
|
-
}
|
|
68
|
+
await this.sync();
|
|
81
69
|
}
|
|
82
70
|
|
|
83
|
-
public async addPubkey(
|
|
71
|
+
public async addPubkey(
|
|
72
|
+
userAccountPublicKey: PublicKey,
|
|
73
|
+
userAccount?: UserAccount
|
|
74
|
+
) {
|
|
84
75
|
const user = new User({
|
|
85
76
|
driftClient: this.driftClient,
|
|
86
77
|
userAccountPublicKey,
|
|
87
78
|
accountSubscription: this.accountSubscription,
|
|
88
79
|
});
|
|
89
|
-
await user.subscribe();
|
|
80
|
+
await user.subscribe(userAccount);
|
|
90
81
|
this.userMap.set(userAccountPublicKey.toString(), user);
|
|
91
82
|
}
|
|
92
83
|
|
|
@@ -129,6 +120,17 @@ export class UserMap implements UserMapInterface {
|
|
|
129
120
|
return chUser.getUserAccount().authority;
|
|
130
121
|
}
|
|
131
122
|
|
|
123
|
+
/**
|
|
124
|
+
* implements the {@link DLOBSource} interface
|
|
125
|
+
* create a DLOB from all the subscribed users
|
|
126
|
+
* @param slot
|
|
127
|
+
*/
|
|
128
|
+
public async getDLOB(slot: number): Promise<DLOB> {
|
|
129
|
+
const dlob = new DLOB();
|
|
130
|
+
await dlob.initFromUserMap(this, slot);
|
|
131
|
+
return dlob;
|
|
132
|
+
}
|
|
133
|
+
|
|
132
134
|
public async updateWithOrderRecord(record: OrderRecord) {
|
|
133
135
|
if (!this.has(record.user.toString())) {
|
|
134
136
|
await this.addPubkey(record.user);
|
|
@@ -179,9 +181,9 @@ export class UserMap implements UserMapInterface {
|
|
|
179
181
|
return this.userMap.size;
|
|
180
182
|
}
|
|
181
183
|
|
|
182
|
-
public async sync(
|
|
184
|
+
public async sync() {
|
|
183
185
|
let filters = undefined;
|
|
184
|
-
if (!includeIdle) {
|
|
186
|
+
if (!this.includeIdle) {
|
|
185
187
|
filters = [
|
|
186
188
|
{
|
|
187
189
|
memcmp: {
|
|
@@ -192,39 +194,88 @@ export class UserMap implements UserMapInterface {
|
|
|
192
194
|
];
|
|
193
195
|
}
|
|
194
196
|
|
|
195
|
-
const
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
197
|
+
const rpcRequestArgs = [
|
|
198
|
+
this.driftClient.program.programId.toBase58(),
|
|
199
|
+
{
|
|
200
|
+
commitment: this.driftClient.connection.commitment,
|
|
201
|
+
filters: [
|
|
202
|
+
{
|
|
203
|
+
memcmp: this.driftClient.program.coder.accounts.memcmp('User'),
|
|
204
|
+
},
|
|
205
|
+
...(Array.isArray(filters) ? filters : []),
|
|
206
|
+
],
|
|
207
|
+
encoding: 'base64',
|
|
208
|
+
withContext: true,
|
|
209
|
+
},
|
|
210
|
+
];
|
|
211
|
+
|
|
212
|
+
// @ts-ignore
|
|
213
|
+
const rpcJSONResponse: any = await this.driftClient.connection._rpcRequest(
|
|
214
|
+
'getProgramAccounts',
|
|
215
|
+
rpcRequestArgs
|
|
216
|
+
);
|
|
217
|
+
|
|
218
|
+
const rpcResponseAndContext: RpcResponseAndContext<
|
|
219
|
+
Array<{
|
|
220
|
+
pubkey: PublicKey;
|
|
221
|
+
account: {
|
|
222
|
+
data: [string, string];
|
|
223
|
+
};
|
|
224
|
+
}>
|
|
225
|
+
> = rpcJSONResponse.result;
|
|
226
|
+
|
|
227
|
+
const slot = rpcResponseAndContext.context.slot;
|
|
208
228
|
|
|
209
|
-
const
|
|
210
|
-
for (const programAccount of
|
|
211
|
-
|
|
229
|
+
const programAccountBufferMap = new Map<string, Buffer>();
|
|
230
|
+
for (const programAccount of rpcResponseAndContext.value) {
|
|
231
|
+
programAccountBufferMap.set(
|
|
212
232
|
programAccount.pubkey.toString(),
|
|
213
|
-
|
|
233
|
+
// @ts-ignore
|
|
234
|
+
Buffer.from(
|
|
235
|
+
programAccount.account.data[0],
|
|
236
|
+
programAccount.account.data[1]
|
|
237
|
+
)
|
|
214
238
|
);
|
|
215
239
|
}
|
|
216
240
|
|
|
217
|
-
for (const key of
|
|
241
|
+
for (const [key, buffer] of programAccountBufferMap.entries()) {
|
|
218
242
|
if (!this.has(key)) {
|
|
219
|
-
|
|
243
|
+
const userAccount =
|
|
244
|
+
this.driftClient.program.account.user.coder.accounts.decode(
|
|
245
|
+
'User',
|
|
246
|
+
buffer
|
|
247
|
+
);
|
|
248
|
+
await this.addPubkey(new PublicKey(key), userAccount);
|
|
220
249
|
}
|
|
221
250
|
}
|
|
222
251
|
|
|
223
252
|
for (const [key, user] of this.userMap.entries()) {
|
|
224
|
-
if (!
|
|
253
|
+
if (!programAccountBufferMap.has(key)) {
|
|
225
254
|
await user.unsubscribe();
|
|
226
255
|
this.userMap.delete(key);
|
|
256
|
+
} else {
|
|
257
|
+
const userAccount =
|
|
258
|
+
this.driftClient.program.account.user.coder.accounts.decode(
|
|
259
|
+
'User',
|
|
260
|
+
programAccountBufferMap.get(key)
|
|
261
|
+
);
|
|
262
|
+
user.accountSubscriber.updateData(userAccount, slot);
|
|
227
263
|
}
|
|
228
264
|
}
|
|
229
265
|
}
|
|
266
|
+
|
|
267
|
+
public async unsubscribe() {
|
|
268
|
+
for (const [key, user] of this.userMap.entries()) {
|
|
269
|
+
await user.unsubscribe();
|
|
270
|
+
this.userMap.delete(key);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
if (this.lastNumberOfSubAccounts) {
|
|
274
|
+
this.driftClient.eventEmitter.removeListener(
|
|
275
|
+
'stateAccountUpdate',
|
|
276
|
+
this.syncCallback
|
|
277
|
+
);
|
|
278
|
+
this.lastNumberOfSubAccounts = undefined;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
230
281
|
}
|
|
@@ -5,7 +5,6 @@ import {
|
|
|
5
5
|
UserStatsAccount,
|
|
6
6
|
UserStats,
|
|
7
7
|
UserStatsSubscriptionConfig,
|
|
8
|
-
bulkPollingUserStatsSubscribe,
|
|
9
8
|
WrappedEvent,
|
|
10
9
|
DepositRecord,
|
|
11
10
|
FundingPaymentRecord,
|
|
@@ -15,8 +14,8 @@ import {
|
|
|
15
14
|
NewUserRecord,
|
|
16
15
|
LPRecord,
|
|
17
16
|
InsuranceFundStakeRecord,
|
|
17
|
+
StateAccount,
|
|
18
18
|
} from '..';
|
|
19
|
-
import { ProgramAccount } from '@coral-xyz/anchor';
|
|
20
19
|
import { AccountInfo, PublicKey } from '@solana/web3.js';
|
|
21
20
|
|
|
22
21
|
import { UserMap } from './userMap';
|
|
@@ -29,6 +28,13 @@ export class UserStatsMap {
|
|
|
29
28
|
private userStatsMap = new Map<string, UserStats>();
|
|
30
29
|
private driftClient: DriftClient;
|
|
31
30
|
private accountSubscription: UserStatsSubscriptionConfig;
|
|
31
|
+
private lastNumberOfAuthorities;
|
|
32
|
+
private syncCallback = async (state: StateAccount) => {
|
|
33
|
+
if (state.numberOfAuthorities !== this.lastNumberOfAuthorities) {
|
|
34
|
+
await this.sync();
|
|
35
|
+
this.lastNumberOfAuthorities = state.numberOfAuthorities;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
32
38
|
|
|
33
39
|
constructor(
|
|
34
40
|
driftClient: DriftClient,
|
|
@@ -38,50 +44,23 @@ export class UserStatsMap {
|
|
|
38
44
|
this.accountSubscription = accountSubscription;
|
|
39
45
|
}
|
|
40
46
|
|
|
41
|
-
public async
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const programUserAccounts =
|
|
46
|
-
(await this.driftClient.program.account.userStats.all()) as ProgramAccount<UserStatsAccount>[];
|
|
47
|
-
|
|
48
|
-
for (const programUserAccount of programUserAccounts) {
|
|
49
|
-
const userStat: UserStatsAccount = programUserAccount.account;
|
|
50
|
-
if (this.userStatsMap.has(userStat.authority.toString())) {
|
|
51
|
-
continue;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const chUserStat = new UserStats({
|
|
55
|
-
driftClient: this.driftClient,
|
|
56
|
-
userStatsAccountPublicKey: programUserAccount.publicKey,
|
|
57
|
-
accountSubscription: this.accountSubscription,
|
|
58
|
-
});
|
|
59
|
-
userStatArray.push(chUserStat);
|
|
60
|
-
userStatsAccountArray.push(userStat);
|
|
47
|
+
public async subscribe() {
|
|
48
|
+
if (this.size() > 0) {
|
|
49
|
+
return;
|
|
61
50
|
}
|
|
62
51
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
);
|
|
68
|
-
} else {
|
|
69
|
-
await Promise.all(
|
|
70
|
-
userStatArray.map((userStat, i) =>
|
|
71
|
-
userStat.subscribe(userStatsAccountArray[i])
|
|
72
|
-
)
|
|
73
|
-
);
|
|
74
|
-
}
|
|
52
|
+
await this.driftClient.subscribe();
|
|
53
|
+
this.lastNumberOfAuthorities =
|
|
54
|
+
this.driftClient.getStateAccount().numberOfAuthorities;
|
|
55
|
+
this.driftClient.eventEmitter.on('stateAccountUpdate', this.syncCallback);
|
|
75
56
|
|
|
76
|
-
|
|
77
|
-
this.userStatsMap.set(
|
|
78
|
-
userStat.getAccount().authority.toString(),
|
|
79
|
-
userStat
|
|
80
|
-
);
|
|
81
|
-
}
|
|
57
|
+
await this.sync();
|
|
82
58
|
}
|
|
83
59
|
|
|
84
|
-
public async addUserStat(
|
|
60
|
+
public async addUserStat(
|
|
61
|
+
authority: PublicKey,
|
|
62
|
+
userStatsAccount?: UserStatsAccount
|
|
63
|
+
) {
|
|
85
64
|
const userStat = new UserStats({
|
|
86
65
|
driftClient: this.driftClient,
|
|
87
66
|
userStatsAccountPublicKey: getUserStatsAccountPublicKey(
|
|
@@ -90,7 +69,7 @@ export class UserStatsMap {
|
|
|
90
69
|
),
|
|
91
70
|
accountSubscription: this.accountSubscription,
|
|
92
71
|
});
|
|
93
|
-
await userStat.subscribe();
|
|
72
|
+
await userStat.subscribe(userStatsAccount);
|
|
94
73
|
|
|
95
74
|
this.userStatsMap.set(authority.toString(), userStat);
|
|
96
75
|
}
|
|
@@ -98,7 +77,7 @@ export class UserStatsMap {
|
|
|
98
77
|
public async updateWithOrderRecord(record: OrderRecord, userMap: UserMap) {
|
|
99
78
|
const user = await userMap.mustGet(record.user.toString());
|
|
100
79
|
if (!this.has(user.getUserAccount().authority.toString())) {
|
|
101
|
-
this.addUserStat(user.getUserAccount().authority);
|
|
80
|
+
await this.addUserStat(user.getUserAccount().authority);
|
|
102
81
|
}
|
|
103
82
|
}
|
|
104
83
|
|
|
@@ -217,8 +196,28 @@ export class UserStatsMap {
|
|
|
217
196
|
|
|
218
197
|
for (const key of programAccountMap.keys()) {
|
|
219
198
|
if (!this.has(key)) {
|
|
220
|
-
|
|
199
|
+
const userStatsAccount =
|
|
200
|
+
this.driftClient.program.account.userStats.coder.accounts.decode(
|
|
201
|
+
'UserStats',
|
|
202
|
+
programAccountMap.get(key).data
|
|
203
|
+
);
|
|
204
|
+
await this.addUserStat(new PublicKey(key), userStatsAccount);
|
|
221
205
|
}
|
|
222
206
|
}
|
|
223
207
|
}
|
|
208
|
+
|
|
209
|
+
public async unsubscribe() {
|
|
210
|
+
for (const [key, userStats] of this.userStatsMap.entries()) {
|
|
211
|
+
await userStats.unsubscribe();
|
|
212
|
+
this.userStatsMap.delete(key);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
if (this.lastNumberOfAuthorities) {
|
|
216
|
+
this.driftClient.eventEmitter.removeListener(
|
|
217
|
+
'stateAccountUpdate',
|
|
218
|
+
this.syncCallback
|
|
219
|
+
);
|
|
220
|
+
this.lastNumberOfAuthorities = undefined;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
224
223
|
}
|
package/tests/dlob/helpers.ts
CHANGED
|
@@ -570,7 +570,9 @@ export class MockUserMap implements UserMapInterface {
|
|
|
570
570
|
});
|
|
571
571
|
}
|
|
572
572
|
|
|
573
|
-
public async
|
|
573
|
+
public async subscribe(): Promise<void> {}
|
|
574
|
+
|
|
575
|
+
public async unsubscribe(): Promise<void> {}
|
|
574
576
|
|
|
575
577
|
public async addPubkey(userAccountPublicKey: PublicKey): Promise<void> {
|
|
576
578
|
const user = new User({
|
package/src/assert/assert.js
DELETED
package/src/token/index.js
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.parseTokenAccount = void 0;
|
|
4
|
-
const spl_token_1 = require("@solana/spl-token");
|
|
5
|
-
const web3_js_1 = require("@solana/web3.js");
|
|
6
|
-
function parseTokenAccount(data) {
|
|
7
|
-
const accountInfo = spl_token_1.AccountLayout.decode(data);
|
|
8
|
-
accountInfo.mint = new web3_js_1.PublicKey(accountInfo.mint);
|
|
9
|
-
accountInfo.owner = new web3_js_1.PublicKey(accountInfo.owner);
|
|
10
|
-
accountInfo.amount = spl_token_1.u64.fromBuffer(accountInfo.amount);
|
|
11
|
-
if (accountInfo.delegateOption === 0) {
|
|
12
|
-
accountInfo.delegate = null;
|
|
13
|
-
// eslint-disable-next-line new-cap
|
|
14
|
-
accountInfo.delegatedAmount = new spl_token_1.u64(0);
|
|
15
|
-
}
|
|
16
|
-
else {
|
|
17
|
-
accountInfo.delegate = new web3_js_1.PublicKey(accountInfo.delegate);
|
|
18
|
-
accountInfo.delegatedAmount = spl_token_1.u64.fromBuffer(accountInfo.delegatedAmount);
|
|
19
|
-
}
|
|
20
|
-
accountInfo.isInitialized = accountInfo.state !== 0;
|
|
21
|
-
accountInfo.isFrozen = accountInfo.state === 2;
|
|
22
|
-
if (accountInfo.isNativeOption === 1) {
|
|
23
|
-
accountInfo.rentExemptReserve = spl_token_1.u64.fromBuffer(accountInfo.isNative);
|
|
24
|
-
accountInfo.isNative = true;
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
accountInfo.rentExemptReserve = null;
|
|
28
|
-
accountInfo.isNative = false;
|
|
29
|
-
}
|
|
30
|
-
if (accountInfo.closeAuthorityOption === 0) {
|
|
31
|
-
accountInfo.closeAuthority = null;
|
|
32
|
-
}
|
|
33
|
-
else {
|
|
34
|
-
accountInfo.closeAuthority = new web3_js_1.PublicKey(accountInfo.closeAuthority);
|
|
35
|
-
}
|
|
36
|
-
return accountInfo;
|
|
37
|
-
}
|
|
38
|
-
exports.parseTokenAccount = parseTokenAccount;
|
package/src/util/computeUnits.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.findComputeUnitConsumption = void 0;
|
|
13
|
-
function findComputeUnitConsumption(programId, connection, txSignature, commitment = 'confirmed') {
|
|
14
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
15
|
-
const tx = yield connection.getTransaction(txSignature, { commitment });
|
|
16
|
-
const computeUnits = [];
|
|
17
|
-
const regex = new RegExp(`Program ${programId.toString()} consumed ([0-9]{0,6}) of ([0-9]{0,7}) compute units`);
|
|
18
|
-
tx.meta.logMessages.forEach((logMessage) => {
|
|
19
|
-
const match = logMessage.match(regex);
|
|
20
|
-
if (match && match[1]) {
|
|
21
|
-
computeUnits.push(match[1]);
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
return computeUnits;
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
exports.findComputeUnitConsumption = findComputeUnitConsumption;
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getTokenAddress = void 0;
|
|
4
|
-
const spl_token_1 = require("@solana/spl-token");
|
|
5
|
-
const web3_js_1 = require("@solana/web3.js");
|
|
6
|
-
const getTokenAddress = (mintAddress, userPubKey) => {
|
|
7
|
-
return spl_token_1.Token.getAssociatedTokenAddress(spl_token_1.ASSOCIATED_TOKEN_PROGRAM_ID, spl_token_1.TOKEN_PROGRAM_ID, new web3_js_1.PublicKey(mintAddress), new web3_js_1.PublicKey(userPubKey));
|
|
8
|
-
};
|
|
9
|
-
exports.getTokenAddress = getTokenAddress;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.promiseTimeout = void 0;
|
|
4
|
-
function promiseTimeout(promise, timeoutMs) {
|
|
5
|
-
let timeoutId;
|
|
6
|
-
const timeoutPromise = new Promise((resolve) => {
|
|
7
|
-
timeoutId = setTimeout(() => resolve(null), timeoutMs);
|
|
8
|
-
});
|
|
9
|
-
return Promise.race([promise, timeoutPromise]).then((result) => {
|
|
10
|
-
clearTimeout(timeoutId);
|
|
11
|
-
return result;
|
|
12
|
-
});
|
|
13
|
-
}
|
|
14
|
-
exports.promiseTimeout = promiseTimeout;
|
package/src/util/tps.js
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.estimateTps = void 0;
|
|
13
|
-
function estimateTps(programId, connection, failed) {
|
|
14
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
15
|
-
let signatures = yield connection.getSignaturesForAddress(programId, undefined, 'finalized');
|
|
16
|
-
if (failed) {
|
|
17
|
-
signatures = signatures.filter((signature) => signature.err);
|
|
18
|
-
}
|
|
19
|
-
const numberOfSignatures = signatures.length;
|
|
20
|
-
if (numberOfSignatures === 0) {
|
|
21
|
-
return 0;
|
|
22
|
-
}
|
|
23
|
-
return (numberOfSignatures /
|
|
24
|
-
(signatures[0].blockTime - signatures[numberOfSignatures - 1].blockTime));
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
exports.estimateTps = estimateTps;
|