@drift-labs/sdk 2.38.1-beta.2 → 2.38.1-beta.4
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/fetch.js +2 -2
- package/lib/accounts/pollingUserStatsAccountSubscriber.js +2 -2
- package/lib/driftClient.js +7 -2
- package/lib/examples/loadDlob.js +3 -1
- package/lib/examples/makeTradeExample.js +3 -1
- package/lib/tokenFaucet.js +1 -0
- package/package.json +2 -2
- package/src/accounts/fetch.ts +2 -2
- package/src/accounts/pollingUserStatsAccountSubscriber.ts +10 -8
- package/src/driftClient.ts +3 -0
- package/src/examples/loadDlob.ts +1 -0
- package/src/examples/makeTradeExample.ts +1 -0
- package/src/tokenFaucet.ts +1 -0
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.38.1-beta.
|
|
1
|
+
2.38.1-beta.4
|
package/lib/accounts/fetch.js
CHANGED
|
@@ -16,7 +16,7 @@ async function fetchUserAccountsUsingKeys(connection, program, userAccountPublic
|
|
|
16
16
|
if (!accountInfo) {
|
|
17
17
|
return undefined;
|
|
18
18
|
}
|
|
19
|
-
return program.account.user.coder.accounts.
|
|
19
|
+
return program.account.user.coder.accounts.decodeUnchecked('User', accountInfo.data);
|
|
20
20
|
});
|
|
21
21
|
}
|
|
22
22
|
exports.fetchUserAccountsUsingKeys = fetchUserAccountsUsingKeys;
|
|
@@ -24,7 +24,7 @@ async function fetchUserStatsAccount(connection, program, authority) {
|
|
|
24
24
|
const userStatsPublicKey = (0, pda_1.getUserStatsAccountPublicKey)(program.programId, authority);
|
|
25
25
|
const accountInfo = await connection.getAccountInfo(userStatsPublicKey, 'confirmed');
|
|
26
26
|
return accountInfo
|
|
27
|
-
? program.account.user.coder.accounts.
|
|
27
|
+
? program.account.user.coder.accounts.decodeUnchecked('UserStats', accountInfo.data)
|
|
28
28
|
: undefined;
|
|
29
29
|
}
|
|
30
30
|
exports.fetchUserStatsAccount = fetchUserStatsAccount;
|
|
@@ -37,7 +37,7 @@ class PollingUserStatsAccountSubscriber {
|
|
|
37
37
|
if (this.userStats && this.userStats.slot > slot) {
|
|
38
38
|
return;
|
|
39
39
|
}
|
|
40
|
-
const account = this.program.account.userStats.coder.accounts.
|
|
40
|
+
const account = this.program.account.userStats.coder.accounts.decodeUnchecked('UserStats', buffer);
|
|
41
41
|
this.userStats = { data: account, slot };
|
|
42
42
|
this.eventEmitter.emit('userStatsAccountUpdate', account);
|
|
43
43
|
this.eventEmitter.emit('update');
|
|
@@ -57,7 +57,7 @@ class PollingUserStatsAccountSubscriber {
|
|
|
57
57
|
const { buffer, slot } = this.accountLoader.getBufferAndSlot(this.userStatsAccountPublicKey);
|
|
58
58
|
const currentSlot = (_b = (_a = this.userStats) === 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.userStats.coder.accounts.
|
|
60
|
+
const account = this.program.account.userStats.coder.accounts.decodeUnchecked('UserStats', buffer);
|
|
61
61
|
this.userStats = { data: account, slot };
|
|
62
62
|
}
|
|
63
63
|
}
|
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/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/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.4",
|
|
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",
|
package/src/accounts/fetch.ts
CHANGED
|
@@ -36,7 +36,7 @@ export async function fetchUserAccountsUsingKeys(
|
|
|
36
36
|
if (!accountInfo) {
|
|
37
37
|
return undefined;
|
|
38
38
|
}
|
|
39
|
-
return program.account.user.coder.accounts.
|
|
39
|
+
return program.account.user.coder.accounts.decodeUnchecked(
|
|
40
40
|
'User',
|
|
41
41
|
accountInfo.data
|
|
42
42
|
) as UserAccount;
|
|
@@ -58,7 +58,7 @@ export async function fetchUserStatsAccount(
|
|
|
58
58
|
);
|
|
59
59
|
|
|
60
60
|
return accountInfo
|
|
61
|
-
? (program.account.user.coder.accounts.
|
|
61
|
+
? (program.account.user.coder.accounts.decodeUnchecked(
|
|
62
62
|
'UserStats',
|
|
63
63
|
accountInfo.data
|
|
64
64
|
) as UserStatsAccount)
|
|
@@ -74,10 +74,11 @@ export class PollingUserStatsAccountSubscriber
|
|
|
74
74
|
return;
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
const account =
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
77
|
+
const account =
|
|
78
|
+
this.program.account.userStats.coder.accounts.decodeUnchecked(
|
|
79
|
+
'UserStats',
|
|
80
|
+
buffer
|
|
81
|
+
);
|
|
81
82
|
this.userStats = { data: account, slot };
|
|
82
83
|
this.eventEmitter.emit('userStatsAccountUpdate', account);
|
|
83
84
|
this.eventEmitter.emit('update');
|
|
@@ -102,10 +103,11 @@ export class PollingUserStatsAccountSubscriber
|
|
|
102
103
|
);
|
|
103
104
|
const currentSlot = this.userStats?.slot ?? 0;
|
|
104
105
|
if (buffer && slot > currentSlot) {
|
|
105
|
-
const account =
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
106
|
+
const account =
|
|
107
|
+
this.program.account.userStats.coder.accounts.decodeUnchecked(
|
|
108
|
+
'UserStats',
|
|
109
|
+
buffer
|
|
110
|
+
);
|
|
109
111
|
this.userStats = { data: account, slot };
|
|
110
112
|
}
|
|
111
113
|
}
|
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/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);
|