@drift-labs/sdk 2.74.0-beta.1 → 2.74.0-beta.2

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.74.0-beta.1
1
+ 2.74.0-beta.2
@@ -1,2 +1,2 @@
1
1
  import { Program, Event } from '@coral-xyz/anchor';
2
- export declare function parseLogs(program: Program, logs: string[]): Event[];
2
+ export declare function parseLogs(program: Program, logs: string[], programId?: string): Event[];
@@ -2,19 +2,18 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.parseLogs = void 0;
4
4
  const driftProgramId = 'dRiftyHA39MWEi3m9aunc5MzRF1JYuBsbn6VPcn33UH';
5
- const driftProgramStart = `Program ${driftProgramId} invoke`;
6
5
  const PROGRAM_LOG = 'Program log: ';
7
6
  const PROGRAM_DATA = 'Program data: ';
8
7
  const PROGRAM_LOG_START_INDEX = PROGRAM_LOG.length;
9
8
  const PROGRAM_DATA_START_INDEX = PROGRAM_DATA.length;
10
- function parseLogs(program, logs) {
9
+ function parseLogs(program, logs, programId = driftProgramId) {
11
10
  const events = [];
12
11
  const execution = new ExecutionContext();
13
12
  for (const log of logs) {
14
13
  if (log.startsWith('Log truncated')) {
15
14
  break;
16
15
  }
17
- const [event, newProgram, didPop] = handleLog(execution, log, program);
16
+ const [event, newProgram, didPop] = handleLog(execution, log, program, programId);
18
17
  if (event) {
19
18
  events.push(event);
20
19
  }
@@ -28,18 +27,18 @@ function parseLogs(program, logs) {
28
27
  return events;
29
28
  }
30
29
  exports.parseLogs = parseLogs;
31
- function handleLog(execution, log, program) {
30
+ function handleLog(execution, log, program, programId = driftProgramId) {
32
31
  // Executing program is drift program.
33
- if (execution.stack.length > 0 && execution.program() === driftProgramId) {
34
- return handleProgramLog(log, program);
32
+ if (execution.stack.length > 0 && execution.program() === programId) {
33
+ return handleProgramLog(log, program, programId);
35
34
  }
36
35
  // Executing program is not drift program.
37
36
  else {
38
- return [null, ...handleSystemLog(log)];
37
+ return [null, ...handleSystemLog(log, programId)];
39
38
  }
40
39
  }
41
40
  // Handles logs from *drift* program.
42
- function handleProgramLog(log, program) {
41
+ function handleProgramLog(log, program, programId = driftProgramId) {
43
42
  // This is a `msg!` log or a `sol_log_data` log.
44
43
  if (log.startsWith(PROGRAM_LOG)) {
45
44
  const logStr = log.slice(PROGRAM_LOG_START_INDEX);
@@ -52,20 +51,21 @@ function handleProgramLog(log, program) {
52
51
  return [event, null, false];
53
52
  }
54
53
  else {
55
- return [null, ...handleSystemLog(log)];
54
+ return [null, ...handleSystemLog(log, programId)];
56
55
  }
57
56
  }
58
57
  // Handles logs when the current program being executing is *not* drift.
59
- function handleSystemLog(log) {
58
+ function handleSystemLog(log, programId = driftProgramId) {
60
59
  // System component.
61
60
  const logStart = log.split(':')[0];
61
+ const programStart = `Program ${programId} invoke`;
62
62
  // Did the program finish executing?
63
63
  if (logStart.match(/^Program (.*) success/g) !== null) {
64
64
  return [null, true];
65
65
  // Recursive call.
66
66
  }
67
- else if (logStart.startsWith(driftProgramStart)) {
68
- return [driftProgramId, false];
67
+ else if (logStart.startsWith(programStart)) {
68
+ return [programId, false];
69
69
  }
70
70
  // CPI call.
71
71
  else if (logStart.includes('invoke')) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@drift-labs/sdk",
3
- "version": "2.74.0-beta.1",
3
+ "version": "2.74.0-beta.2",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "author": "crispheaney",
@@ -1,13 +1,16 @@
1
1
  import { Program, Event } from '@coral-xyz/anchor';
2
2
 
3
3
  const driftProgramId = 'dRiftyHA39MWEi3m9aunc5MzRF1JYuBsbn6VPcn33UH';
4
- const driftProgramStart = `Program ${driftProgramId} invoke`;
5
4
  const PROGRAM_LOG = 'Program log: ';
6
5
  const PROGRAM_DATA = 'Program data: ';
7
6
  const PROGRAM_LOG_START_INDEX = PROGRAM_LOG.length;
8
7
  const PROGRAM_DATA_START_INDEX = PROGRAM_DATA.length;
9
8
 
10
- export function parseLogs(program: Program, logs: string[]): Event[] {
9
+ export function parseLogs(
10
+ program: Program,
11
+ logs: string[],
12
+ programId = driftProgramId
13
+ ): Event[] {
11
14
  const events = [];
12
15
  const execution = new ExecutionContext();
13
16
  for (const log of logs) {
@@ -15,7 +18,12 @@ export function parseLogs(program: Program, logs: string[]): Event[] {
15
18
  break;
16
19
  }
17
20
 
18
- const [event, newProgram, didPop] = handleLog(execution, log, program);
21
+ const [event, newProgram, didPop] = handleLog(
22
+ execution,
23
+ log,
24
+ program,
25
+ programId
26
+ );
19
27
  if (event) {
20
28
  events.push(event);
21
29
  }
@@ -32,22 +40,24 @@ export function parseLogs(program: Program, logs: string[]): Event[] {
32
40
  function handleLog(
33
41
  execution: ExecutionContext,
34
42
  log: string,
35
- program: Program
43
+ program: Program,
44
+ programId = driftProgramId
36
45
  ): [Event | null, string | null, boolean] {
37
46
  // Executing program is drift program.
38
- if (execution.stack.length > 0 && execution.program() === driftProgramId) {
39
- return handleProgramLog(log, program);
47
+ if (execution.stack.length > 0 && execution.program() === programId) {
48
+ return handleProgramLog(log, program, programId);
40
49
  }
41
50
  // Executing program is not drift program.
42
51
  else {
43
- return [null, ...handleSystemLog(log)];
52
+ return [null, ...handleSystemLog(log, programId)];
44
53
  }
45
54
  }
46
55
 
47
56
  // Handles logs from *drift* program.
48
57
  function handleProgramLog(
49
58
  log: string,
50
- program: Program
59
+ program: Program,
60
+ programId = driftProgramId
51
61
  ): [Event | null, string | null, boolean] {
52
62
  // This is a `msg!` log or a `sol_log_data` log.
53
63
  if (log.startsWith(PROGRAM_LOG)) {
@@ -59,21 +69,25 @@ function handleProgramLog(
59
69
  const event = program.coder.events.decode(logStr);
60
70
  return [event, null, false];
61
71
  } else {
62
- return [null, ...handleSystemLog(log)];
72
+ return [null, ...handleSystemLog(log, programId)];
63
73
  }
64
74
  }
65
75
 
66
76
  // Handles logs when the current program being executing is *not* drift.
67
- function handleSystemLog(log: string): [string | null, boolean] {
77
+ function handleSystemLog(
78
+ log: string,
79
+ programId = driftProgramId
80
+ ): [string | null, boolean] {
68
81
  // System component.
69
82
  const logStart = log.split(':')[0];
83
+ const programStart = `Program ${programId} invoke`;
70
84
 
71
85
  // Did the program finish executing?
72
86
  if (logStart.match(/^Program (.*) success/g) !== null) {
73
87
  return [null, true];
74
88
  // Recursive call.
75
- } else if (logStart.startsWith(driftProgramStart)) {
76
- return [driftProgramId, false];
89
+ } else if (logStart.startsWith(programStart)) {
90
+ return [programId, false];
77
91
  }
78
92
  // CPI call.
79
93
  else if (logStart.includes('invoke')) {