@drift-labs/sdk 2.43.0-beta.2 → 2.43.0-beta.3
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/README.md +1 -0
- package/VERSION +1 -1
- package/get_events.ts +47 -0
- package/package.json +1 -1
- package/tests/dlob/test.ts +1 -0
- package/tests/user/test.ts +10 -13
package/README.md
CHANGED
|
@@ -244,3 +244,4 @@ Drift Protocol v2 is licensed under [Apache 2.0](./LICENSE).
|
|
|
244
244
|
Unless you explicitly state otherwise, any contribution intentionally submitted
|
|
245
245
|
for inclusion in Drift SDK by you, as defined in the Apache-2.0 license, shall be
|
|
246
246
|
licensed as above, without any additional terms or conditions.
|
|
247
|
+
|
package/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
2.43.0-beta.
|
|
1
|
+
2.43.0-beta.3
|
package/get_events.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Connection, Keypair, PublicKey } from '@solana/web3.js';
|
|
2
|
+
import {
|
|
3
|
+
configs,
|
|
4
|
+
DriftClient,
|
|
5
|
+
Wallet,
|
|
6
|
+
} from "@drift-labs/sdk";
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
async function main() {
|
|
10
|
+
|
|
11
|
+
const driftConfig = configs['mainnet-beta'];
|
|
12
|
+
const connection = new Connection('https://api.mainnet-beta.solana.com');
|
|
13
|
+
|
|
14
|
+
const driftClient = new DriftClient({
|
|
15
|
+
connection: connection,
|
|
16
|
+
wallet: new Wallet(new Keypair()),
|
|
17
|
+
programID: new PublicKey(driftConfig.DRIFT_PROGRAM_ID),
|
|
18
|
+
userStats: true,
|
|
19
|
+
env: 'mainnet-beta',
|
|
20
|
+
});
|
|
21
|
+
console.log(`driftClientSubscribed: ${await driftClient.subscribe()}`);
|
|
22
|
+
|
|
23
|
+
const txHash = "3gvGQufckXGHrFDv4dNWEXuXKRMy3NZkKHMyFrAhLoYScaXXTGCp9vq58kWkfyJ8oDYZrz4bTyGayjUy9PKigeLS";
|
|
24
|
+
|
|
25
|
+
const tx = await driftClient.connection.getParsedTransaction(txHash, {
|
|
26
|
+
commitment: "confirmed",
|
|
27
|
+
maxSupportedTransactionVersion: 0,
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
let logIdx = 0;
|
|
31
|
+
// @ts-ignore
|
|
32
|
+
for (const event of driftClient.program._events._eventParser.parseLogs(tx!.meta!.logMessages)) {
|
|
33
|
+
console.log("----------------------------------------");
|
|
34
|
+
console.log(`Log ${logIdx++}`);
|
|
35
|
+
console.log("----------------------------------------");
|
|
36
|
+
console.log(`${JSON.stringify(event, null, 2)}`);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
console.log("========================================");
|
|
40
|
+
console.log("Raw transaction logs");
|
|
41
|
+
console.log("========================================");
|
|
42
|
+
console.log(JSON.stringify(tx!.meta!.logMessages, null, 2));
|
|
43
|
+
|
|
44
|
+
process.exit(0);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
main().catch(console.error);
|
package/package.json
CHANGED
package/tests/dlob/test.ts
CHANGED
package/tests/user/test.ts
CHANGED
|
@@ -289,8 +289,9 @@ describe('User Tests', () => {
|
|
|
289
289
|
mockUser.getMaxLeverageForPerp(0).toString()
|
|
290
290
|
);
|
|
291
291
|
assert(mockUser.getMaxLeverageForPerp(0).eq(new BN('50000'))); // 5x
|
|
292
|
-
assert(
|
|
293
|
-
|
|
292
|
+
assert(
|
|
293
|
+
mockUser.getMaxLeverageForPerp(0, 'Maintenance').eq(new BN('100000'))
|
|
294
|
+
); // 10x
|
|
294
295
|
});
|
|
295
296
|
|
|
296
297
|
it('worst case token amount', async () => {
|
|
@@ -399,8 +400,7 @@ describe('User Tests', () => {
|
|
|
399
400
|
); // -$2k
|
|
400
401
|
});
|
|
401
402
|
|
|
402
|
-
|
|
403
|
-
it('custom margin ratio (sol spot)', async() => {
|
|
403
|
+
it('custom margin ratio (sol spot)', async () => {
|
|
404
404
|
const myMockUserAccount = _.cloneDeep(mockUserAccount);
|
|
405
405
|
|
|
406
406
|
const solMarket = Object.assign({}, _.cloneDeep(mockSpotMarkets[1]), {
|
|
@@ -427,12 +427,10 @@ describe('User Tests', () => {
|
|
|
427
427
|
);
|
|
428
428
|
|
|
429
429
|
console.log(worstCase);
|
|
430
|
-
assert(worstCase.weight.eq(new BN(8000)));
|
|
431
|
-
|
|
430
|
+
assert(worstCase.weight.eq(new BN(8000)));
|
|
432
431
|
|
|
433
432
|
myMockUserAccount.maxMarginRatio = MARGIN_PRECISION.toNumber(); // max 1x pls
|
|
434
433
|
|
|
435
|
-
|
|
436
434
|
const worstCaseAfter = getWorstCaseTokenAmounts(
|
|
437
435
|
spotPosition,
|
|
438
436
|
solMarket,
|
|
@@ -443,10 +441,9 @@ describe('User Tests', () => {
|
|
|
443
441
|
|
|
444
442
|
console.log(worstCaseAfter);
|
|
445
443
|
assert(worstCaseAfter.weight.eq(new BN(0))); // not allowed to increase exposure
|
|
446
|
-
|
|
447
444
|
});
|
|
448
445
|
|
|
449
|
-
it('custom margin ratio (sol perp)', async() => {
|
|
446
|
+
it('custom margin ratio (sol perp)', async () => {
|
|
450
447
|
const myMockPerpMarkets = _.cloneDeep(mockPerpMarkets);
|
|
451
448
|
const myMockSpotMarkets = _.cloneDeep(mockSpotMarkets);
|
|
452
449
|
const myMockUserAccount = _.cloneDeep(mockUserAccount);
|
|
@@ -469,7 +466,6 @@ describe('User Tests', () => {
|
|
|
469
466
|
[1, 1, 1, 1, 1, 1, 1, 1]
|
|
470
467
|
);
|
|
471
468
|
|
|
472
|
-
|
|
473
469
|
assert(mockUser.getTokenAmount(0).eq(new BN('10000000000')));
|
|
474
470
|
assert(mockUser.getNetSpotMarketValue().eq(new BN('10000000000')));
|
|
475
471
|
assert(
|
|
@@ -486,7 +482,9 @@ describe('User Tests', () => {
|
|
|
486
482
|
assert(iLev == 5000);
|
|
487
483
|
assert(mLev == 10000);
|
|
488
484
|
|
|
489
|
-
myMockUserAccount.maxMarginRatio = MARGIN_PRECISION.div(
|
|
485
|
+
myMockUserAccount.maxMarginRatio = MARGIN_PRECISION.div(
|
|
486
|
+
new BN(2)
|
|
487
|
+
).toNumber(); // 2x max pls
|
|
490
488
|
|
|
491
489
|
const mockUser2: User = await makeMockUser(
|
|
492
490
|
myMockPerpMarkets,
|
|
@@ -498,9 +496,8 @@ describe('User Tests', () => {
|
|
|
498
496
|
iLev = mockUser2.getMaxLeverageForPerp(0, 'Initial').toNumber();
|
|
499
497
|
mLev = mockUser2.getMaxLeverageForPerp(0, 'Maintenance').toNumber();
|
|
500
498
|
console.log(iLev, mLev);
|
|
501
|
-
|
|
499
|
+
|
|
502
500
|
assert(iLev == 2000);
|
|
503
501
|
assert(mLev == 10000);
|
|
504
|
-
|
|
505
502
|
});
|
|
506
503
|
});
|