@drift-labs/sdk 2.65.0-beta.9 → 2.66.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/VERSION +1 -1
- package/lib/adminClient.js +83 -44
- package/lib/constants/spotMarkets.js +11 -0
- package/lib/events/eventSubscriber.js +1 -1
- package/lib/events/fetchLogs.js +3 -3
- package/lib/events/parse.d.ts +1 -1
- package/lib/events/parse.js +4 -1
- package/lib/idl/drift.json +1 -1
- package/package.json +1 -1
- package/src/adminClient.ts +364 -261
- package/src/constants/spotMarkets.ts +11 -0
- package/src/events/eventSubscriber.ts +1 -1
- package/src/events/fetchLogs.ts +3 -6
- package/src/events/parse.ts +5 -5
- package/src/idl/drift.json +1 -1
- package/tests/amm/test.ts +8 -2
- package/tests/dlob/helpers.ts +40 -0
|
@@ -203,6 +203,17 @@ export const MainnetSpotMarkets: SpotMarketConfig[] = [
|
|
|
203
203
|
),
|
|
204
204
|
launchTs: 1706731200000,
|
|
205
205
|
},
|
|
206
|
+
{
|
|
207
|
+
symbol: 'RNDR',
|
|
208
|
+
marketIndex: 12,
|
|
209
|
+
oracle: new PublicKey('CYGfrBJB9HgLf9iZyN4aH5HvUAi2htQ4MjPxeXMf4Egn'),
|
|
210
|
+
oracleSource: OracleSource.PYTH,
|
|
211
|
+
mint: new PublicKey('rndrizKT3MK1iimdxRdWabcF7Zg7AR5T4nud4EkHBof'),
|
|
212
|
+
precision: new BN(10).pow(EIGHT),
|
|
213
|
+
precisionExp: EIGHT,
|
|
214
|
+
serumMarket: new PublicKey('2m7ZLEKtxWF29727DSb5D91erpXPUY1bqhRWRC3wQX7u'),
|
|
215
|
+
launchTs: 1708964021000,
|
|
216
|
+
},
|
|
206
217
|
];
|
|
207
218
|
|
|
208
219
|
export const SpotMarkets: { [key in DriftEnv]: SpotMarketConfig[] } = {
|
|
@@ -213,7 +213,7 @@ export class EventSubscriber {
|
|
|
213
213
|
): WrappedEvents {
|
|
214
214
|
const records = [];
|
|
215
215
|
// @ts-ignore
|
|
216
|
-
const events = parseLogs(this.program,
|
|
216
|
+
const events = parseLogs(this.program, logs);
|
|
217
217
|
let runningEventIndex = 0;
|
|
218
218
|
for (const event of events) {
|
|
219
219
|
// @ts-ignore
|
package/src/events/fetchLogs.ts
CHANGED
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
} from '@solana/web3.js';
|
|
10
10
|
import { WrappedEvents } from './types';
|
|
11
11
|
import { promiseTimeout } from '../util/promiseTimeout';
|
|
12
|
+
import { parseLogs } from './parse';
|
|
12
13
|
|
|
13
14
|
type Log = { txSig: TransactionSignature; slot: number; logs: string[] };
|
|
14
15
|
type FetchLogsResponse = {
|
|
@@ -153,17 +154,13 @@ export class LogParser {
|
|
|
153
154
|
|
|
154
155
|
if (!event.logs) return records;
|
|
155
156
|
|
|
156
|
-
// @ts-ignore
|
|
157
|
-
const eventGenerator = this.program._events._eventParser.parseLogs(
|
|
158
|
-
event.logs,
|
|
159
|
-
false
|
|
160
|
-
);
|
|
161
157
|
let runningEventIndex = 0;
|
|
162
|
-
for (const eventLog of
|
|
158
|
+
for (const eventLog of parseLogs(this.program, event.logs)) {
|
|
163
159
|
eventLog.data.txSig = event.txSig;
|
|
164
160
|
eventLog.data.slot = event.slot;
|
|
165
161
|
eventLog.data.eventType = eventLog.name;
|
|
166
162
|
eventLog.data.txSigIndex = runningEventIndex;
|
|
163
|
+
// @ts-ignore
|
|
167
164
|
records.push(eventLog.data);
|
|
168
165
|
runningEventIndex++;
|
|
169
166
|
}
|
package/src/events/parse.ts
CHANGED
|
@@ -7,14 +7,14 @@ const PROGRAM_DATA = 'Program data: ';
|
|
|
7
7
|
const PROGRAM_LOG_START_INDEX = PROGRAM_LOG.length;
|
|
8
8
|
const PROGRAM_DATA_START_INDEX = PROGRAM_DATA.length;
|
|
9
9
|
|
|
10
|
-
export function parseLogs(
|
|
11
|
-
program: Program,
|
|
12
|
-
slot: number,
|
|
13
|
-
logs: string[]
|
|
14
|
-
): Event[] {
|
|
10
|
+
export function parseLogs(program: Program, logs: string[]): Event[] {
|
|
15
11
|
const events = [];
|
|
16
12
|
const execution = new ExecutionContext();
|
|
17
13
|
for (const log of logs) {
|
|
14
|
+
if (log.startsWith('Log truncated')) {
|
|
15
|
+
break;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
18
|
const [event, newProgram, didPop] = handleLog(execution, log, program);
|
|
19
19
|
if (event) {
|
|
20
20
|
events.push(event);
|
package/src/idl/drift.json
CHANGED
package/tests/amm/test.ts
CHANGED
|
@@ -614,8 +614,14 @@ describe('AMM Tests', () => {
|
|
|
614
614
|
// console.log(termsSuiExample);
|
|
615
615
|
assert(termsSuiExample.effectiveLeverageCapped <= 1.000001);
|
|
616
616
|
assert(termsSuiExample.inventorySpreadScale == 1.00007);
|
|
617
|
-
assert(
|
|
618
|
-
|
|
617
|
+
assert(
|
|
618
|
+
termsSuiExample.longSpread == 259073,
|
|
619
|
+
`SUI long spread got ${termsSuiExample.longSpread}`
|
|
620
|
+
);
|
|
621
|
+
assert(
|
|
622
|
+
termsSuiExample.shortSpread == 3712,
|
|
623
|
+
`SUI short spread got ${termsSuiExample.shortSpread}`
|
|
624
|
+
);
|
|
619
625
|
|
|
620
626
|
// reset amm reserves/peg to balanced values s.t. liquidity/price is the same
|
|
621
627
|
// to avoid error prone int math
|
package/tests/dlob/helpers.ts
CHANGED
|
@@ -24,6 +24,7 @@ import {
|
|
|
24
24
|
SPOT_MARKET_CUMULATIVE_INTEREST_PRECISION,
|
|
25
25
|
SPOT_MARKET_WEIGHT_PRECISION,
|
|
26
26
|
PRICE_PRECISION,
|
|
27
|
+
DataAndSlot,
|
|
27
28
|
} from '../../src';
|
|
28
29
|
|
|
29
30
|
export const mockPerpPosition: PerpPosition = {
|
|
@@ -639,6 +640,10 @@ export class MockUserMap implements UserMapInterface {
|
|
|
639
640
|
return undefined;
|
|
640
641
|
}
|
|
641
642
|
|
|
643
|
+
public getWithSlot(_key: string): DataAndSlot<User> | undefined {
|
|
644
|
+
return undefined;
|
|
645
|
+
}
|
|
646
|
+
|
|
642
647
|
public async mustGet(_key: string): Promise<User> {
|
|
643
648
|
return new User({
|
|
644
649
|
driftClient: this.driftClient,
|
|
@@ -646,6 +651,16 @@ export class MockUserMap implements UserMapInterface {
|
|
|
646
651
|
});
|
|
647
652
|
}
|
|
648
653
|
|
|
654
|
+
public async mustGetWithSlot(_key: string): Promise<DataAndSlot<User>> {
|
|
655
|
+
return {
|
|
656
|
+
data: new User({
|
|
657
|
+
driftClient: this.driftClient,
|
|
658
|
+
userAccountPublicKey: PublicKey.default,
|
|
659
|
+
}),
|
|
660
|
+
slot: 0,
|
|
661
|
+
};
|
|
662
|
+
}
|
|
663
|
+
|
|
649
664
|
public getUserAuthority(key: string): PublicKey | undefined {
|
|
650
665
|
return new PublicKey(
|
|
651
666
|
this.userAccountToAuthority.get(key) || PublicKey.default.toBase58()
|
|
@@ -657,4 +672,29 @@ export class MockUserMap implements UserMapInterface {
|
|
|
657
672
|
public values(): IterableIterator<User> {
|
|
658
673
|
return this.userMap.values();
|
|
659
674
|
}
|
|
675
|
+
|
|
676
|
+
public *valuesWithSlot(): IterableIterator<DataAndSlot<User>> {
|
|
677
|
+
for (const user of this.userMap.values()) {
|
|
678
|
+
yield {
|
|
679
|
+
data: user,
|
|
680
|
+
slot: 0,
|
|
681
|
+
};
|
|
682
|
+
}
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
public entries(): IterableIterator<[string, User]> {
|
|
686
|
+
return this.userMap.entries();
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
public *entriesWithSlot(): IterableIterator<[string, DataAndSlot<User>]> {
|
|
690
|
+
for (const [key, user] of this.userMap.entries()) {
|
|
691
|
+
yield [
|
|
692
|
+
key,
|
|
693
|
+
{
|
|
694
|
+
data: user,
|
|
695
|
+
slot: 0,
|
|
696
|
+
},
|
|
697
|
+
];
|
|
698
|
+
}
|
|
699
|
+
}
|
|
660
700
|
}
|