Skip to content

Commit 051bf47

Browse files
committed
prettify
1 parent 5846094 commit 051bf47

File tree

4 files changed

+59
-13
lines changed

4 files changed

+59
-13
lines changed

sdk/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,3 +244,4 @@ Drift Protocol v2 is licensed under [Apache 2.0](./LICENSE).
244244
Unless you explicitly state otherwise, any contribution intentionally submitted
245245
for inclusion in Drift SDK by you, as defined in the Apache-2.0 license, shall be
246246
licensed as above, without any additional terms or conditions.
247+

sdk/get_events.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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);

sdk/tests/dlob/test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
//
12
import { expect } from 'chai';
23
import { PublicKey, Keypair } from '@solana/web3.js';
34

sdk/tests/user/test.ts

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -289,8 +289,9 @@ describe('User Tests', () => {
289289
mockUser.getMaxLeverageForPerp(0).toString()
290290
);
291291
assert(mockUser.getMaxLeverageForPerp(0).eq(new BN('50000'))); // 5x
292-
assert(mockUser.getMaxLeverageForPerp(0, 'Maintenance').eq(new BN('100000'))); // 10x
293-
292+
assert(
293+
mockUser.getMaxLeverageForPerp(0, 'Maintenance').eq(new BN('100000'))
294+
); // 10x
294295
});
295296

296297
it('worst case token amount', async () => {
@@ -399,8 +400,7 @@ describe('User Tests', () => {
399400
); // -$2k
400401
});
401402

402-
403-
it('custom margin ratio (sol spot)', async() => {
403+
it('custom margin ratio (sol spot)', async () => {
404404
const myMockUserAccount = _.cloneDeep(mockUserAccount);
405405

406406
const solMarket = Object.assign({}, _.cloneDeep(mockSpotMarkets[1]), {
@@ -427,12 +427,10 @@ describe('User Tests', () => {
427427
);
428428

429429
console.log(worstCase);
430-
assert(worstCase.weight.eq(new BN(8000)));
431-
430+
assert(worstCase.weight.eq(new BN(8000)));
432431

433432
myMockUserAccount.maxMarginRatio = MARGIN_PRECISION.toNumber(); // max 1x pls
434433

435-
436434
const worstCaseAfter = getWorstCaseTokenAmounts(
437435
spotPosition,
438436
solMarket,
@@ -443,10 +441,9 @@ describe('User Tests', () => {
443441

444442
console.log(worstCaseAfter);
445443
assert(worstCaseAfter.weight.eq(new BN(0))); // not allowed to increase exposure
446-
447444
});
448445

449-
it('custom margin ratio (sol perp)', async() => {
446+
it('custom margin ratio (sol perp)', async () => {
450447
const myMockPerpMarkets = _.cloneDeep(mockPerpMarkets);
451448
const myMockSpotMarkets = _.cloneDeep(mockSpotMarkets);
452449
const myMockUserAccount = _.cloneDeep(mockUserAccount);
@@ -469,7 +466,6 @@ describe('User Tests', () => {
469466
[1, 1, 1, 1, 1, 1, 1, 1]
470467
);
471468

472-
473469
assert(mockUser.getTokenAmount(0).eq(new BN('10000000000')));
474470
assert(mockUser.getNetSpotMarketValue().eq(new BN('10000000000')));
475471
assert(
@@ -486,7 +482,9 @@ describe('User Tests', () => {
486482
assert(iLev == 5000);
487483
assert(mLev == 10000);
488484

489-
myMockUserAccount.maxMarginRatio = MARGIN_PRECISION.div(new BN(2)).toNumber(); // 2x max pls
485+
myMockUserAccount.maxMarginRatio = MARGIN_PRECISION.div(
486+
new BN(2)
487+
).toNumber(); // 2x max pls
490488

491489
const mockUser2: User = await makeMockUser(
492490
myMockPerpMarkets,
@@ -498,9 +496,8 @@ describe('User Tests', () => {
498496
iLev = mockUser2.getMaxLeverageForPerp(0, 'Initial').toNumber();
499497
mLev = mockUser2.getMaxLeverageForPerp(0, 'Maintenance').toNumber();
500498
console.log(iLev, mLev);
501-
499+
502500
assert(iLev == 2000);
503501
assert(mLev == 10000);
504-
505502
});
506503
});

0 commit comments

Comments
 (0)