Skip to content

Commit dbbe321

Browse files
authored
Merge pull request #4 from xTheAlex11/main
Fixed stringLayout (Causing issues when parsing CREATE on pumpfun)
2 parents e414d08 + 30a55e7 commit dbbe321

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

src/core/layout.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,20 @@ export const uint128 = (property: string): Layout<bigint> => {
3434
return uint128Layout;
3535
};
3636

37-
export const stringLayout = (property: string, maxLength: number = 32): Layout<string> => {
38-
const layout = blob(maxLength, property);
37+
export const stringLayout = (property: string): Layout<string> => {
38+
const layout = blob(4, property);
3939
const stringLayout = layout as Layout<unknown> as Layout<string>;
40-
const decode = layout.decode.bind(layout);
40+
4141
stringLayout.decode = (buffer: Buffer, offset: number) => {
42-
const src = decode(buffer, offset);
43-
return Buffer.from(src).toString('utf-8', 4).trim();
42+
const length = buffer.readUInt32LE(offset);
43+
return buffer.slice(offset + 4, offset + 4 + length).toString('utf-8');
4444
};
45+
46+
stringLayout.getSpan = (buffer: Buffer, offset: number) => {
47+
const length = buffer.readUInt32LE(offset);
48+
return 4 + length;
49+
};
50+
4551
return stringLayout;
4652
};
4753

src/parser/pumpfun/layout.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import { CreateEvent, TradeEvent, CompleteEvent } from './types';
33
import { stringLayout, pubKey, uint64, boolean } from '../../core/layout';
44

55
export const CREATE_EVENT_LAYOUT = struct<CreateEvent>([
6-
stringLayout('name', 20),
7-
stringLayout('symbol', 9),
8-
stringLayout('uri', 71),
6+
stringLayout('name'),
7+
stringLayout('symbol'),
8+
stringLayout('uri'),
99
pubKey('mint'),
1010
pubKey('bondingCurve'),
1111
pubKey('user'),

0 commit comments

Comments
 (0)