@drift-labs/sdk 2.95.0-beta.7 → 2.95.0-beta.9

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 CHANGED
@@ -1 +1 @@
1
- 2.95.0-beta.7
1
+ 2.95.0-beta.9
@@ -1,2 +1,6 @@
1
1
  import { Program, Event } from '@coral-xyz/anchor';
2
2
  export declare function parseLogs(program: Program, logs: string[], programId?: string): Event[];
3
+ export declare function parseLogsWithRaw(program: Program, logs: string[], programId?: string): {
4
+ events: Event[];
5
+ rawLogs: string[];
6
+ };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.parseLogs = void 0;
3
+ exports.parseLogsWithRaw = exports.parseLogs = void 0;
4
4
  const driftProgramId = 'dRiftyHA39MWEi3m9aunc5MzRF1JYuBsbn6VPcn33UH';
5
5
  const PROGRAM_LOG = 'Program log: ';
6
6
  const PROGRAM_DATA = 'Program data: ';
@@ -27,6 +27,29 @@ function parseLogs(program, logs, programId = driftProgramId) {
27
27
  return events;
28
28
  }
29
29
  exports.parseLogs = parseLogs;
30
+ function parseLogsWithRaw(program, logs, programId = driftProgramId) {
31
+ const events = [];
32
+ const rawLogs = [];
33
+ const execution = new ExecutionContext();
34
+ for (const log of logs) {
35
+ if (log.startsWith('Log truncated')) {
36
+ break;
37
+ }
38
+ const [event, newProgram, didPop] = handleLog(execution, log, program, programId);
39
+ if (event) {
40
+ events.push(event);
41
+ rawLogs.push(log);
42
+ }
43
+ if (newProgram) {
44
+ execution.push(newProgram);
45
+ }
46
+ if (didPop) {
47
+ execution.pop();
48
+ }
49
+ }
50
+ return { events, rawLogs };
51
+ }
52
+ exports.parseLogsWithRaw = parseLogsWithRaw;
30
53
  function handleLog(execution, log, program, programId = driftProgramId) {
31
54
  // Executing program is drift program.
32
55
  if (execution.stack.length > 0 && execution.program() === programId) {
@@ -6,12 +6,16 @@ export declare function isFallbackAvailableLiquiditySource(order: Order, minAuct
6
6
  export declare function getAuctionPrice(order: Order, slot: number, oraclePrice: BN): BN;
7
7
  export declare function getAuctionPriceForFixedAuction(order: Order, slot: number): BN;
8
8
  export declare function getAuctionPriceForOracleOffsetAuction(order: Order, slot: number, oraclePrice: BN): BN;
9
- export declare function deriveOracleAuctionParams({ direction, oraclePrice, auctionStartPrice, auctionEndPrice, limitPrice, }: {
9
+ export declare function deriveOracleAuctionParams({ direction, oraclePrice, auctionStartPrice, auctionEndPrice, limitPrice, auctionPriceCaps, }: {
10
10
  direction: PositionDirection;
11
11
  oraclePrice: BN;
12
12
  auctionStartPrice: BN;
13
13
  auctionEndPrice: BN;
14
14
  limitPrice: BN;
15
+ auctionPriceCaps?: {
16
+ min: BN;
17
+ max: BN;
18
+ };
15
19
  }): {
16
20
  auctionStartPrice: BN;
17
21
  auctionEndPrice: BN;
@@ -94,7 +94,7 @@ function getAuctionPriceForOracleOffsetAuction(order, slot, oraclePrice) {
94
94
  return _1.BN.max(oraclePrice.add(priceOffset), _1.ONE);
95
95
  }
96
96
  exports.getAuctionPriceForOracleOffsetAuction = getAuctionPriceForOracleOffsetAuction;
97
- function deriveOracleAuctionParams({ direction, oraclePrice, auctionStartPrice, auctionEndPrice, limitPrice, }) {
97
+ function deriveOracleAuctionParams({ direction, oraclePrice, auctionStartPrice, auctionEndPrice, limitPrice, auctionPriceCaps, }) {
98
98
  let oraclePriceOffset;
99
99
  if (limitPrice.eq(_1.ZERO) || oraclePrice.eq(_1.ZERO)) {
100
100
  oraclePriceOffset = _1.ZERO;
@@ -114,6 +114,10 @@ function deriveOracleAuctionParams({ direction, oraclePrice, auctionStartPrice,
114
114
  catch (e) {
115
115
  oraclePriceOffsetNum = 0;
116
116
  }
117
+ if (auctionPriceCaps) {
118
+ auctionStartPrice = _1.BN.min(_1.BN.max(auctionStartPrice, auctionPriceCaps.min), auctionPriceCaps.max);
119
+ auctionEndPrice = _1.BN.min(_1.BN.max(auctionEndPrice, auctionPriceCaps.min), auctionPriceCaps.max);
120
+ }
117
121
  return {
118
122
  auctionStartPrice: auctionStartPrice.sub(oraclePrice),
119
123
  auctionEndPrice: auctionEndPrice.sub(oraclePrice),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "2.95.0-beta.7",
3
+ "version": "2.95.0-beta.9",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "crispheaney",
@@ -37,6 +37,39 @@ export function parseLogs(
37
37
  return events;
38
38
  }
39
39
 
40
+ export function parseLogsWithRaw(
41
+ program: Program,
42
+ logs: string[],
43
+ programId = driftProgramId
44
+ ): { events: Event[]; rawLogs: string[] } {
45
+ const events = [];
46
+ const rawLogs = [];
47
+ const execution = new ExecutionContext();
48
+ for (const log of logs) {
49
+ if (log.startsWith('Log truncated')) {
50
+ break;
51
+ }
52
+
53
+ const [event, newProgram, didPop] = handleLog(
54
+ execution,
55
+ log,
56
+ program,
57
+ programId
58
+ );
59
+ if (event) {
60
+ events.push(event);
61
+ rawLogs.push(log);
62
+ }
63
+ if (newProgram) {
64
+ execution.push(newProgram);
65
+ }
66
+ if (didPop) {
67
+ execution.pop();
68
+ }
69
+ }
70
+ return { events, rawLogs };
71
+ }
72
+
40
73
  function handleLog(
41
74
  execution: ExecutionContext,
42
75
  log: string,
@@ -120,12 +120,17 @@ export function deriveOracleAuctionParams({
120
120
  auctionStartPrice,
121
121
  auctionEndPrice,
122
122
  limitPrice,
123
+ auctionPriceCaps,
123
124
  }: {
124
125
  direction: PositionDirection;
125
126
  oraclePrice: BN;
126
127
  auctionStartPrice: BN;
127
128
  auctionEndPrice: BN;
128
129
  limitPrice: BN;
130
+ auctionPriceCaps?: {
131
+ min: BN;
132
+ max: BN;
133
+ };
129
134
  }): { auctionStartPrice: BN; auctionEndPrice: BN; oraclePriceOffset: number } {
130
135
  let oraclePriceOffset;
131
136
 
@@ -148,6 +153,17 @@ export function deriveOracleAuctionParams({
148
153
  oraclePriceOffsetNum = 0;
149
154
  }
150
155
 
156
+ if (auctionPriceCaps) {
157
+ auctionStartPrice = BN.min(
158
+ BN.max(auctionStartPrice, auctionPriceCaps.min),
159
+ auctionPriceCaps.max
160
+ );
161
+ auctionEndPrice = BN.min(
162
+ BN.max(auctionEndPrice, auctionPriceCaps.min),
163
+ auctionPriceCaps.max
164
+ );
165
+ }
166
+
151
167
  return {
152
168
  auctionStartPrice: auctionStartPrice.sub(oraclePrice),
153
169
  auctionEndPrice: auctionEndPrice.sub(oraclePrice),