@pina-rs/amm 0.0.0-stage → 0.1.0

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.
Files changed (42) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +27 -2
  3. package/dist/index.cjs +1257 -0
  4. package/dist/index.cjs.map +1 -0
  5. package/dist/index.d.cts +1752 -0
  6. package/dist/index.d.ts +1752 -0
  7. package/dist/index.js +1078 -0
  8. package/dist/index.js.map +1 -0
  9. package/package.json +58 -5
  10. package/src/generated/accounts/ammConfig.ts +197 -0
  11. package/src/generated/accounts/index.ts +10 -0
  12. package/src/generated/accounts/pool.ts +218 -0
  13. package/src/generated/errors/index.ts +9 -0
  14. package/src/generated/errors/pinaAmm.ts +64 -0
  15. package/src/generated/events/feesCollected.ts +64 -0
  16. package/src/generated/events/index.ts +13 -0
  17. package/src/generated/events/liquidityChanged.ts +72 -0
  18. package/src/generated/events/logs.ts +372 -0
  19. package/src/generated/events/poolCreated.ts +80 -0
  20. package/src/generated/events/swapped.ts +100 -0
  21. package/src/generated/index.ts +14 -0
  22. package/src/generated/instructions/collectCreatorFees.ts +119 -0
  23. package/src/generated/instructions/collectProtocolFees.ts +123 -0
  24. package/src/generated/instructions/createConfig.ts +142 -0
  25. package/src/generated/instructions/createPool.ts +291 -0
  26. package/src/generated/instructions/deposit.ts +139 -0
  27. package/src/generated/instructions/index.ts +19 -0
  28. package/src/generated/instructions/migrate.ts +155 -0
  29. package/src/generated/instructions/setPoolCreator.ts +90 -0
  30. package/src/generated/instructions/swapExactIn.ts +119 -0
  31. package/src/generated/instructions/swapExactOut.ts +119 -0
  32. package/src/generated/instructions/updateConfig.ts +105 -0
  33. package/src/generated/instructions/withdraw.ts +139 -0
  34. package/src/generated/pdas/ammConfig.ts +18 -0
  35. package/src/generated/pdas/index.ts +12 -0
  36. package/src/generated/pdas/pool.ts +20 -0
  37. package/src/generated/pdas/poolLpMint.ts +18 -0
  38. package/src/generated/pdas/poolVault.ts +19 -0
  39. package/src/generated/pinaPodCodecs.ts +232 -0
  40. package/src/generated/programs/index.ts +9 -0
  41. package/src/generated/programs/pinaAmm.ts +115 -0
  42. package/src/index.ts +11 -0
@@ -0,0 +1,72 @@
1
+ /**
2
+ * This code was AUTOGENERATED using the Codama library.
3
+ * Please DO NOT EDIT THIS FILE, instead use visitors
4
+ * to add features, then rerun Codama to update it.
5
+ *
6
+ * @see https://github.com/codama-idl/codama
7
+ */
8
+
9
+ import { getPinaPodDiscriminatorDecoder, getPinaPodMigrationVersionDecoder } from "../pinaPodCodecs";
10
+ import { combineCodec, containsBytes, getAddressDecoder, getAddressEncoder, getStructDecoder, getStructEncoder, getU64Decoder, getU64Encoder, getU8Decoder, getU8Encoder, transformEncoder, type Address, type FixedSizeCodec, type FixedSizeDecoder, type FixedSizeEncoder, type ReadonlyUint8Array } from '@solana/kit';
11
+
12
+ export const LIQUIDITY_CHANGED_EVENT_DISCRIMINATOR = 3;
13
+
14
+ export function getLiquidityChangedEventDiscriminatorBytes(): ReadonlyUint8Array { return getU8Encoder().encode(LIQUIDITY_CHANGED_EVENT_DISCRIMINATOR); }
15
+
16
+ export const LIQUIDITY_CHANGED_EVENT_DISCRIMINATOR2 = 0;
17
+
18
+ export function getLiquidityChangedEventDiscriminator2Bytes(): ReadonlyUint8Array { return getU8Encoder().encode(LIQUIDITY_CHANGED_EVENT_DISCRIMINATOR2); }
19
+
20
+ /** Emitted by `Deposit` and `Withdraw`. */
21
+ export type LiquidityChangedEvent = { discriminator: number; migrationVersion: number;
22
+ /** The pool whose liquidity changed. */
23
+ pool: Address;
24
+ /** The LP owner who signed. */
25
+ owner: Address;
26
+ /** `1` for a deposit and `0` for a withdrawal. */
27
+ isDeposit: number;
28
+ /** LP minted or burned. */
29
+ lpAmount: bigint;
30
+ /** Token 0 added or removed. */
31
+ amount0: bigint;
32
+ /** Token 1 added or removed. */
33
+ amount1: bigint;
34
+ /** Economic LP supply after the change. */
35
+ lpSupply: bigint; };
36
+
37
+ export type LiquidityChangedEventArgs = {
38
+ /** The pool whose liquidity changed. */
39
+ pool: Address;
40
+ /** The LP owner who signed. */
41
+ owner: Address;
42
+ /** `1` for a deposit and `0` for a withdrawal. */
43
+ isDeposit: number;
44
+ /** LP minted or burned. */
45
+ lpAmount: number | bigint;
46
+ /** Token 0 added or removed. */
47
+ amount0: number | bigint;
48
+ /** Token 1 added or removed. */
49
+ amount1: number | bigint;
50
+ /** Economic LP supply after the change. */
51
+ lpSupply: number | bigint; };
52
+
53
+ /** Gets the encoder for {@link LiquidityChangedEventArgs} event data. */
54
+ export function getLiquidityChangedEventEncoder(): FixedSizeEncoder<LiquidityChangedEventArgs> {
55
+ return transformEncoder(getStructEncoder([['discriminator', getU8Encoder()], ['migrationVersion', getU8Encoder()], ['pool', getAddressEncoder()], ['owner', getAddressEncoder()], ['isDeposit', getU8Encoder()], ['lpAmount', getU64Encoder()], ['amount0', getU64Encoder()], ['amount1', getU64Encoder()], ['lpSupply', getU64Encoder()]]), (value) => ({ ...value, discriminator: 3, migrationVersion: 0 }));
56
+ }
57
+
58
+ /** Gets the decoder for {@link LiquidityChangedEvent} event data. */
59
+ export function getLiquidityChangedEventDecoder(): FixedSizeDecoder<LiquidityChangedEvent> {
60
+ return getStructDecoder([['discriminator', getPinaPodDiscriminatorDecoder(LIQUIDITY_CHANGED_EVENT_DISCRIMINATOR, getU8Decoder())], ['migrationVersion', getPinaPodMigrationVersionDecoder(0, getU8Decoder())], ['pool', getAddressDecoder()], ['owner', getAddressDecoder()], ['isDeposit', getU8Decoder()], ['lpAmount', getU64Decoder()], ['amount0', getU64Decoder()], ['amount1', getU64Decoder()], ['lpSupply', getU64Decoder()]]);
61
+ }
62
+
63
+ /** Gets the codec for {@link LiquidityChangedEvent} event data. */
64
+ export function getLiquidityChangedEventCodec(): FixedSizeCodec<LiquidityChangedEventArgs, LiquidityChangedEvent> {
65
+ return combineCodec(getLiquidityChangedEventEncoder(), getLiquidityChangedEventDecoder());
66
+ }
67
+
68
+ /** Parses the provided bytes into {@link LiquidityChangedEvent} event data. */
69
+ export function parseLiquidityChangedEvent(data: ReadonlyUint8Array | Uint8Array): LiquidityChangedEvent {
70
+ if (containsBytes(data, getU8Encoder().encode(LIQUIDITY_CHANGED_EVENT_DISCRIMINATOR), 0) && containsBytes(data, getU8Encoder().encode(LIQUIDITY_CHANGED_EVENT_DISCRIMINATOR2), 1)) { return getLiquidityChangedEventDecoder().decode(data); }
71
+ throw new Error('The provided data does not match the "LiquidityChangedEvent" event discriminators.');
72
+ }
@@ -0,0 +1,372 @@
1
+ /**
2
+ * This code was AUTOGENERATED using the Codama library and Pina's migration
3
+ * manifest. Please DO NOT EDIT THIS FILE, instead rerun client generation.
4
+ *
5
+ * Event log read path: decode `Program data:` log lines into typed events.
6
+ * A migration-aware event is decoded with the layout of the version that
7
+ * emitted it: each earlier version is its own `<Event>V<n>` event, and a
8
+ * version no event here describes fails instead of being misread.
9
+ */
10
+
11
+ import { getBase64Encoder, type ReadonlyUint8Array } from "@solana/kit";
12
+ import {
13
+ getPoolCreatedEventDecoder,
14
+ getPoolCreatedEventDiscriminatorBytes,
15
+ type PoolCreatedEvent,
16
+ } from "./poolCreated.js";
17
+ import {
18
+ getSwappedEventDecoder,
19
+ getSwappedEventDiscriminatorBytes,
20
+ type SwappedEvent,
21
+ } from "./swapped.js";
22
+ import {
23
+ getLiquidityChangedEventDecoder,
24
+ getLiquidityChangedEventDiscriminatorBytes,
25
+ type LiquidityChangedEvent,
26
+ } from "./liquidityChanged.js";
27
+ import {
28
+ getFeesCollectedEventDecoder,
29
+ getFeesCollectedEventDiscriminatorBytes,
30
+ type FeesCollectedEvent,
31
+ } from "./feesCollected.js";
32
+
33
+ /**
34
+ * Decode one `poolCreated` record: only records carrying this event's migration version decode.
35
+ */
36
+ export function decodePoolCreatedEvent(
37
+ data: ReadonlyUint8Array | Uint8Array,
38
+ ): DecodedPoolCreatedEvent {
39
+ const bytes = data instanceof Uint8Array ? data : new Uint8Array(data);
40
+ const discriminatorBytes = getPoolCreatedEventDiscriminatorBytes();
41
+ if (bytes.length < 2) {
42
+ throw new RangeError(
43
+ `the provided data is too short for the "PoolCreatedEvent" event envelope`,
44
+ );
45
+ }
46
+ for (let index = 0; index < 1; index += 1) {
47
+ if (bytes[index] !== discriminatorBytes[index]) {
48
+ throw new RangeError(
49
+ 'the provided data does not match the "PoolCreatedEvent" event discriminator.',
50
+ );
51
+ }
52
+ }
53
+ const sourceVersion = bytes[1];
54
+ if (sourceVersion !== 0) {
55
+ throw new RangeError(
56
+ `event migration version mismatch: expected 0, received ${sourceVersion} (decode it with the event for that version, or regenerate this client)`,
57
+ );
58
+ }
59
+ return { name: "poolCreated", data: getPoolCreatedEventDecoder().decode(bytes) };
60
+ }
61
+
62
+ /** One log entry that named this event. */
63
+ export type DecodedPoolCreatedEvent = { name: "poolCreated"; data: PoolCreatedEvent };
64
+
65
+ /**
66
+ * Decode a `Program data:` log line, or return `null` when the line is not
67
+ * this event.
68
+ */
69
+ export function parsePoolCreatedEventFromLog(log: string): DecodedPoolCreatedEvent | null {
70
+ const prefix = "Program data: ";
71
+ if (!log.startsWith(prefix)) {
72
+ return null;
73
+ }
74
+ const bytes = getBase64Encoder().encode(log.slice(prefix.length));
75
+ if (bytes.length < 2) {
76
+ return null;
77
+ }
78
+ const discriminatorBytes = getPoolCreatedEventDiscriminatorBytes();
79
+ for (let index = 0; index < 1; index += 1) {
80
+ if (bytes[index] !== discriminatorBytes[index]) {
81
+ return null;
82
+ }
83
+ }
84
+ if (bytes[1] !== 0) {
85
+ return null;
86
+ }
87
+ return decodePoolCreatedEvent(bytes);
88
+ }
89
+
90
+ /**
91
+ * Decode one `swapped` record: only records carrying this event's migration version decode.
92
+ */
93
+ export function decodeSwappedEvent(
94
+ data: ReadonlyUint8Array | Uint8Array,
95
+ ): DecodedSwappedEvent {
96
+ const bytes = data instanceof Uint8Array ? data : new Uint8Array(data);
97
+ const discriminatorBytes = getSwappedEventDiscriminatorBytes();
98
+ if (bytes.length < 2) {
99
+ throw new RangeError(
100
+ `the provided data is too short for the "SwappedEvent" event envelope`,
101
+ );
102
+ }
103
+ for (let index = 0; index < 1; index += 1) {
104
+ if (bytes[index] !== discriminatorBytes[index]) {
105
+ throw new RangeError(
106
+ 'the provided data does not match the "SwappedEvent" event discriminator.',
107
+ );
108
+ }
109
+ }
110
+ const sourceVersion = bytes[1];
111
+ if (sourceVersion !== 0) {
112
+ throw new RangeError(
113
+ `event migration version mismatch: expected 0, received ${sourceVersion} (decode it with the event for that version, or regenerate this client)`,
114
+ );
115
+ }
116
+ return { name: "swapped", data: getSwappedEventDecoder().decode(bytes) };
117
+ }
118
+
119
+ /** One log entry that named this event. */
120
+ export type DecodedSwappedEvent = { name: "swapped"; data: SwappedEvent };
121
+
122
+ /**
123
+ * Decode a `Program data:` log line, or return `null` when the line is not
124
+ * this event.
125
+ */
126
+ export function parseSwappedEventFromLog(log: string): DecodedSwappedEvent | null {
127
+ const prefix = "Program data: ";
128
+ if (!log.startsWith(prefix)) {
129
+ return null;
130
+ }
131
+ const bytes = getBase64Encoder().encode(log.slice(prefix.length));
132
+ if (bytes.length < 2) {
133
+ return null;
134
+ }
135
+ const discriminatorBytes = getSwappedEventDiscriminatorBytes();
136
+ for (let index = 0; index < 1; index += 1) {
137
+ if (bytes[index] !== discriminatorBytes[index]) {
138
+ return null;
139
+ }
140
+ }
141
+ if (bytes[1] !== 0) {
142
+ return null;
143
+ }
144
+ return decodeSwappedEvent(bytes);
145
+ }
146
+
147
+ /**
148
+ * Decode one `liquidityChanged` record: only records carrying this event's migration version decode.
149
+ */
150
+ export function decodeLiquidityChangedEvent(
151
+ data: ReadonlyUint8Array | Uint8Array,
152
+ ): DecodedLiquidityChangedEvent {
153
+ const bytes = data instanceof Uint8Array ? data : new Uint8Array(data);
154
+ const discriminatorBytes = getLiquidityChangedEventDiscriminatorBytes();
155
+ if (bytes.length < 2) {
156
+ throw new RangeError(
157
+ `the provided data is too short for the "LiquidityChangedEvent" event envelope`,
158
+ );
159
+ }
160
+ for (let index = 0; index < 1; index += 1) {
161
+ if (bytes[index] !== discriminatorBytes[index]) {
162
+ throw new RangeError(
163
+ 'the provided data does not match the "LiquidityChangedEvent" event discriminator.',
164
+ );
165
+ }
166
+ }
167
+ const sourceVersion = bytes[1];
168
+ if (sourceVersion !== 0) {
169
+ throw new RangeError(
170
+ `event migration version mismatch: expected 0, received ${sourceVersion} (decode it with the event for that version, or regenerate this client)`,
171
+ );
172
+ }
173
+ return { name: "liquidityChanged", data: getLiquidityChangedEventDecoder().decode(bytes) };
174
+ }
175
+
176
+ /** One log entry that named this event. */
177
+ export type DecodedLiquidityChangedEvent = { name: "liquidityChanged"; data: LiquidityChangedEvent };
178
+
179
+ /**
180
+ * Decode a `Program data:` log line, or return `null` when the line is not
181
+ * this event.
182
+ */
183
+ export function parseLiquidityChangedEventFromLog(log: string): DecodedLiquidityChangedEvent | null {
184
+ const prefix = "Program data: ";
185
+ if (!log.startsWith(prefix)) {
186
+ return null;
187
+ }
188
+ const bytes = getBase64Encoder().encode(log.slice(prefix.length));
189
+ if (bytes.length < 2) {
190
+ return null;
191
+ }
192
+ const discriminatorBytes = getLiquidityChangedEventDiscriminatorBytes();
193
+ for (let index = 0; index < 1; index += 1) {
194
+ if (bytes[index] !== discriminatorBytes[index]) {
195
+ return null;
196
+ }
197
+ }
198
+ if (bytes[1] !== 0) {
199
+ return null;
200
+ }
201
+ return decodeLiquidityChangedEvent(bytes);
202
+ }
203
+
204
+ /**
205
+ * Decode one `feesCollected` record: only records carrying this event's migration version decode.
206
+ */
207
+ export function decodeFeesCollectedEvent(
208
+ data: ReadonlyUint8Array | Uint8Array,
209
+ ): DecodedFeesCollectedEvent {
210
+ const bytes = data instanceof Uint8Array ? data : new Uint8Array(data);
211
+ const discriminatorBytes = getFeesCollectedEventDiscriminatorBytes();
212
+ if (bytes.length < 2) {
213
+ throw new RangeError(
214
+ `the provided data is too short for the "FeesCollectedEvent" event envelope`,
215
+ );
216
+ }
217
+ for (let index = 0; index < 1; index += 1) {
218
+ if (bytes[index] !== discriminatorBytes[index]) {
219
+ throw new RangeError(
220
+ 'the provided data does not match the "FeesCollectedEvent" event discriminator.',
221
+ );
222
+ }
223
+ }
224
+ const sourceVersion = bytes[1];
225
+ if (sourceVersion !== 0) {
226
+ throw new RangeError(
227
+ `event migration version mismatch: expected 0, received ${sourceVersion} (decode it with the event for that version, or regenerate this client)`,
228
+ );
229
+ }
230
+ return { name: "feesCollected", data: getFeesCollectedEventDecoder().decode(bytes) };
231
+ }
232
+
233
+ /** One log entry that named this event. */
234
+ export type DecodedFeesCollectedEvent = { name: "feesCollected"; data: FeesCollectedEvent };
235
+
236
+ /**
237
+ * Decode a `Program data:` log line, or return `null` when the line is not
238
+ * this event.
239
+ */
240
+ export function parseFeesCollectedEventFromLog(log: string): DecodedFeesCollectedEvent | null {
241
+ const prefix = "Program data: ";
242
+ if (!log.startsWith(prefix)) {
243
+ return null;
244
+ }
245
+ const bytes = getBase64Encoder().encode(log.slice(prefix.length));
246
+ if (bytes.length < 2) {
247
+ return null;
248
+ }
249
+ const discriminatorBytes = getFeesCollectedEventDiscriminatorBytes();
250
+ for (let index = 0; index < 1; index += 1) {
251
+ if (bytes[index] !== discriminatorBytes[index]) {
252
+ return null;
253
+ }
254
+ }
255
+ if (bytes[1] !== 0) {
256
+ return null;
257
+ }
258
+ return decodeFeesCollectedEvent(bytes);
259
+ }
260
+
261
+
262
+ /**
263
+ * Explain a `Program data:` line that names a migration-aware event but that
264
+ * no generated event claimed, or return `null` for an unrelated line.
265
+ */
266
+ function unrecognizedEventVersion(log: string): string | null {
267
+ const prefix = "Program data: ";
268
+ if (!log.startsWith(prefix)) {
269
+ return null;
270
+ }
271
+ const bytes = getBase64Encoder().encode(log.slice(prefix.length));
272
+ if (bytes.length >= 1 && bytes[0] === 1) {
273
+ return bytes.length < 2
274
+ ? 'event "poolCreated" log is too short for its version envelope'
275
+ : `event "poolCreated" log carries migration version ${bytes[1]}, which this client cannot decode; regenerate it`;
276
+ }
277
+ if (bytes.length >= 1 && bytes[0] === 2) {
278
+ return bytes.length < 2
279
+ ? 'event "swapped" log is too short for its version envelope'
280
+ : `event "swapped" log carries migration version ${bytes[1]}, which this client cannot decode; regenerate it`;
281
+ }
282
+ if (bytes.length >= 1 && bytes[0] === 3) {
283
+ return bytes.length < 2
284
+ ? 'event "liquidityChanged" log is too short for its version envelope'
285
+ : `event "liquidityChanged" log carries migration version ${bytes[1]}, which this client cannot decode; regenerate it`;
286
+ }
287
+ if (bytes.length >= 1 && bytes[0] === 4) {
288
+ return bytes.length < 2
289
+ ? 'event "feesCollected" log is too short for its version envelope'
290
+ : `event "feesCollected" log carries migration version ${bytes[1]}, which this client cannot decode; regenerate it`;
291
+ }
292
+ return null;
293
+ }
294
+
295
+ /** Every event this program can emit, as decoded from a log line. */
296
+ export type DecodedPinaAmmEvent =
297
+ | DecodedPoolCreatedEvent
298
+ | DecodedSwappedEvent
299
+ | DecodedLiquidityChangedEvent
300
+ | DecodedFeesCollectedEvent;
301
+
302
+ /** The program whose invocation frames emit the events decoded here. */
303
+ export const PINA_AMM_EVENT_SOURCE_ADDRESS = "pAMMvXaqR2VVFqznf6dgvUFQjLXXAEeL9cb48cXsGeV";
304
+
305
+ const PROGRAM_INVOKE_LOG = /^Program (\S+) invoke \[\d+\]$/;
306
+ const PROGRAM_EXIT_LOG = /^Program (\S+) (?:success|failed: .*)$/;
307
+
308
+ /**
309
+ * Decode every `Program data:` line this program emitted in a transaction's
310
+ * logs.
311
+ *
312
+ * `logs` must be the complete, ordered log messages of one transaction. The
313
+ * parser follows the runtime's `Program <address> invoke [n]` and
314
+ * `Program <address> success` / `failed` frames and decodes a data line only
315
+ * while `programAddress` is the innermost invoked program. Any program can
316
+ * write a `Program data:` line with this program's discriminator, so data
317
+ * lines from other programs (including ones this program invokes through CPI)
318
+ * and lines outside any frame are skipped rather than trusted.
319
+ *
320
+ * Unrelated lines are skipped. A line this program emitted that names an event
321
+ * but carries a version no generated event describes throws instead of being
322
+ * silently dropped. The per-event `parse*FromLog` helpers decode one line
323
+ * without this attribution and are only safe for data already known to come
324
+ * from this program.
325
+ */
326
+ export function parsePinaAmmEventsFromLogs(
327
+ logs: readonly string[],
328
+ programAddress: string = PINA_AMM_EVENT_SOURCE_ADDRESS,
329
+ ): DecodedPinaAmmEvent[] {
330
+ const discovered: DecodedPinaAmmEvent[] = [];
331
+ const frames: string[] = [];
332
+ for (const log of logs) {
333
+ const invoke = PROGRAM_INVOKE_LOG.exec(log);
334
+ if (invoke !== null) {
335
+ frames.push(invoke[1] ?? "");
336
+ continue;
337
+ }
338
+ const exit = PROGRAM_EXIT_LOG.exec(log);
339
+ if (exit !== null) {
340
+ frames.pop();
341
+ continue;
342
+ }
343
+ if (frames.length === 0 || frames[frames.length - 1] !== programAddress) {
344
+ continue;
345
+ }
346
+ const poolCreated = parsePoolCreatedEventFromLog(log);
347
+ if (poolCreated !== null) {
348
+ discovered.push(poolCreated);
349
+ continue;
350
+ }
351
+ const swapped = parseSwappedEventFromLog(log);
352
+ if (swapped !== null) {
353
+ discovered.push(swapped);
354
+ continue;
355
+ }
356
+ const liquidityChanged = parseLiquidityChangedEventFromLog(log);
357
+ if (liquidityChanged !== null) {
358
+ discovered.push(liquidityChanged);
359
+ continue;
360
+ }
361
+ const feesCollected = parseFeesCollectedEventFromLog(log);
362
+ if (feesCollected !== null) {
363
+ discovered.push(feesCollected);
364
+ continue;
365
+ }
366
+ const unknownVersion = unrecognizedEventVersion(log);
367
+ if (unknownVersion !== null) {
368
+ throw new RangeError(unknownVersion);
369
+ }
370
+ }
371
+ return discovered;
372
+ }
@@ -0,0 +1,80 @@
1
+ /**
2
+ * This code was AUTOGENERATED using the Codama library.
3
+ * Please DO NOT EDIT THIS FILE, instead use visitors
4
+ * to add features, then rerun Codama to update it.
5
+ *
6
+ * @see https://github.com/codama-idl/codama
7
+ */
8
+
9
+ import { getPinaPodDiscriminatorDecoder, getPinaPodMigrationVersionDecoder } from "../pinaPodCodecs";
10
+ import { combineCodec, containsBytes, getAddressDecoder, getAddressEncoder, getStructDecoder, getStructEncoder, getU64Decoder, getU64Encoder, getU8Decoder, getU8Encoder, transformEncoder, type Address, type FixedSizeCodec, type FixedSizeDecoder, type FixedSizeEncoder, type ReadonlyUint8Array } from '@solana/kit';
11
+
12
+ export const POOL_CREATED_EVENT_DISCRIMINATOR = 1;
13
+
14
+ export function getPoolCreatedEventDiscriminatorBytes(): ReadonlyUint8Array { return getU8Encoder().encode(POOL_CREATED_EVENT_DISCRIMINATOR); }
15
+
16
+ export const POOL_CREATED_EVENT_DISCRIMINATOR2 = 0;
17
+
18
+ export function getPoolCreatedEventDiscriminator2Bytes(): ReadonlyUint8Array { return getU8Encoder().encode(POOL_CREATED_EVENT_DISCRIMINATOR2); }
19
+
20
+ /** Emitted by `CreatePool`. */
21
+ export type PoolCreatedEvent = { discriminator: number; migrationVersion: number;
22
+ /** The new pool. */
23
+ pool: Address;
24
+ /** Fee tier the pool was created under. */
25
+ ammConfig: Address;
26
+ /** Recipient of the pool's creator fees. */
27
+ creator: Address;
28
+ /** Smaller mint of the pair. */
29
+ mint0: Address;
30
+ /** Larger mint of the pair. */
31
+ mint1: Address;
32
+ /** The pool's LP mint. */
33
+ lpMint: Address;
34
+ /** Initial reserve of token 0. */
35
+ amount0: bigint;
36
+ /** Initial reserve of token 1. */
37
+ amount1: bigint;
38
+ /** Initial economic LP supply, including the locked minimum. */
39
+ lpSupply: bigint; };
40
+
41
+ export type PoolCreatedEventArgs = {
42
+ /** The new pool. */
43
+ pool: Address;
44
+ /** Fee tier the pool was created under. */
45
+ ammConfig: Address;
46
+ /** Recipient of the pool's creator fees. */
47
+ creator: Address;
48
+ /** Smaller mint of the pair. */
49
+ mint0: Address;
50
+ /** Larger mint of the pair. */
51
+ mint1: Address;
52
+ /** The pool's LP mint. */
53
+ lpMint: Address;
54
+ /** Initial reserve of token 0. */
55
+ amount0: number | bigint;
56
+ /** Initial reserve of token 1. */
57
+ amount1: number | bigint;
58
+ /** Initial economic LP supply, including the locked minimum. */
59
+ lpSupply: number | bigint; };
60
+
61
+ /** Gets the encoder for {@link PoolCreatedEventArgs} event data. */
62
+ export function getPoolCreatedEventEncoder(): FixedSizeEncoder<PoolCreatedEventArgs> {
63
+ return transformEncoder(getStructEncoder([['discriminator', getU8Encoder()], ['migrationVersion', getU8Encoder()], ['pool', getAddressEncoder()], ['ammConfig', getAddressEncoder()], ['creator', getAddressEncoder()], ['mint0', getAddressEncoder()], ['mint1', getAddressEncoder()], ['lpMint', getAddressEncoder()], ['amount0', getU64Encoder()], ['amount1', getU64Encoder()], ['lpSupply', getU64Encoder()]]), (value) => ({ ...value, discriminator: 1, migrationVersion: 0 }));
64
+ }
65
+
66
+ /** Gets the decoder for {@link PoolCreatedEvent} event data. */
67
+ export function getPoolCreatedEventDecoder(): FixedSizeDecoder<PoolCreatedEvent> {
68
+ return getStructDecoder([['discriminator', getPinaPodDiscriminatorDecoder(POOL_CREATED_EVENT_DISCRIMINATOR, getU8Decoder())], ['migrationVersion', getPinaPodMigrationVersionDecoder(0, getU8Decoder())], ['pool', getAddressDecoder()], ['ammConfig', getAddressDecoder()], ['creator', getAddressDecoder()], ['mint0', getAddressDecoder()], ['mint1', getAddressDecoder()], ['lpMint', getAddressDecoder()], ['amount0', getU64Decoder()], ['amount1', getU64Decoder()], ['lpSupply', getU64Decoder()]]);
69
+ }
70
+
71
+ /** Gets the codec for {@link PoolCreatedEvent} event data. */
72
+ export function getPoolCreatedEventCodec(): FixedSizeCodec<PoolCreatedEventArgs, PoolCreatedEvent> {
73
+ return combineCodec(getPoolCreatedEventEncoder(), getPoolCreatedEventDecoder());
74
+ }
75
+
76
+ /** Parses the provided bytes into {@link PoolCreatedEvent} event data. */
77
+ export function parsePoolCreatedEvent(data: ReadonlyUint8Array | Uint8Array): PoolCreatedEvent {
78
+ if (containsBytes(data, getU8Encoder().encode(POOL_CREATED_EVENT_DISCRIMINATOR), 0) && containsBytes(data, getU8Encoder().encode(POOL_CREATED_EVENT_DISCRIMINATOR2), 1)) { return getPoolCreatedEventDecoder().decode(data); }
79
+ throw new Error('The provided data does not match the "PoolCreatedEvent" event discriminators.');
80
+ }
@@ -0,0 +1,100 @@
1
+ /**
2
+ * This code was AUTOGENERATED using the Codama library.
3
+ * Please DO NOT EDIT THIS FILE, instead use visitors
4
+ * to add features, then rerun Codama to update it.
5
+ *
6
+ * @see https://github.com/codama-idl/codama
7
+ */
8
+
9
+ import { getPinaPodDiscriminatorDecoder, getPinaPodMigrationVersionDecoder } from "../pinaPodCodecs";
10
+ import { combineCodec, containsBytes, getAddressDecoder, getAddressEncoder, getStructDecoder, getStructEncoder, getU64Decoder, getU64Encoder, getU8Decoder, getU8Encoder, transformEncoder, type Address, type FixedSizeCodec, type FixedSizeDecoder, type FixedSizeEncoder, type ReadonlyUint8Array } from '@solana/kit';
11
+
12
+ export const SWAPPED_EVENT_DISCRIMINATOR = 2;
13
+
14
+ export function getSwappedEventDiscriminatorBytes(): ReadonlyUint8Array { return getU8Encoder().encode(SWAPPED_EVENT_DISCRIMINATOR); }
15
+
16
+ export const SWAPPED_EVENT_DISCRIMINATOR2 = 0;
17
+
18
+ export function getSwappedEventDiscriminator2Bytes(): ReadonlyUint8Array { return getU8Encoder().encode(SWAPPED_EVENT_DISCRIMINATOR2); }
19
+
20
+ /** Emitted by `SwapExactIn` and `SwapExactOut`. */
21
+ export type SwappedEvent = { discriminator: number; migrationVersion: number;
22
+ /** The pool traded against. */
23
+ pool: Address;
24
+ /** The trader who signed. */
25
+ trader: Address;
26
+ /** `1` when the trader sold token 0 for token 1, `0` for the reverse. */
27
+ zeroForOne: number;
28
+ /** Tokens the trader paid. */
29
+ amountIn: bigint;
30
+ /** Tokens the trader received. */
31
+ amountOut: bigint;
32
+ /** Trade fee in the input token, including the protocol share. */
33
+ tradeFee: bigint;
34
+ /** Protocol share of the trade fee, in the input token. */
35
+ protocolFee: bigint;
36
+ /**
37
+ * Creator fee. It is in the input token when `creator_fee_on_input` is
38
+ * set and in the output token otherwise.
39
+ */
40
+ creatorFee: bigint;
41
+ /**
42
+ * `1` when `creator_fee` is denominated in the input token, `0` when it is
43
+ * in the output token.
44
+ */
45
+ creatorFeeOnInput: number;
46
+ /** Token 0 reserve after the swap. */
47
+ reserve0: bigint;
48
+ /** Token 1 reserve after the swap. */
49
+ reserve1: bigint; };
50
+
51
+ export type SwappedEventArgs = {
52
+ /** The pool traded against. */
53
+ pool: Address;
54
+ /** The trader who signed. */
55
+ trader: Address;
56
+ /** `1` when the trader sold token 0 for token 1, `0` for the reverse. */
57
+ zeroForOne: number;
58
+ /** Tokens the trader paid. */
59
+ amountIn: number | bigint;
60
+ /** Tokens the trader received. */
61
+ amountOut: number | bigint;
62
+ /** Trade fee in the input token, including the protocol share. */
63
+ tradeFee: number | bigint;
64
+ /** Protocol share of the trade fee, in the input token. */
65
+ protocolFee: number | bigint;
66
+ /**
67
+ * Creator fee. It is in the input token when `creator_fee_on_input` is
68
+ * set and in the output token otherwise.
69
+ */
70
+ creatorFee: number | bigint;
71
+ /**
72
+ * `1` when `creator_fee` is denominated in the input token, `0` when it is
73
+ * in the output token.
74
+ */
75
+ creatorFeeOnInput: number;
76
+ /** Token 0 reserve after the swap. */
77
+ reserve0: number | bigint;
78
+ /** Token 1 reserve after the swap. */
79
+ reserve1: number | bigint; };
80
+
81
+ /** Gets the encoder for {@link SwappedEventArgs} event data. */
82
+ export function getSwappedEventEncoder(): FixedSizeEncoder<SwappedEventArgs> {
83
+ return transformEncoder(getStructEncoder([['discriminator', getU8Encoder()], ['migrationVersion', getU8Encoder()], ['pool', getAddressEncoder()], ['trader', getAddressEncoder()], ['zeroForOne', getU8Encoder()], ['amountIn', getU64Encoder()], ['amountOut', getU64Encoder()], ['tradeFee', getU64Encoder()], ['protocolFee', getU64Encoder()], ['creatorFee', getU64Encoder()], ['creatorFeeOnInput', getU8Encoder()], ['reserve0', getU64Encoder()], ['reserve1', getU64Encoder()]]), (value) => ({ ...value, discriminator: 2, migrationVersion: 0 }));
84
+ }
85
+
86
+ /** Gets the decoder for {@link SwappedEvent} event data. */
87
+ export function getSwappedEventDecoder(): FixedSizeDecoder<SwappedEvent> {
88
+ return getStructDecoder([['discriminator', getPinaPodDiscriminatorDecoder(SWAPPED_EVENT_DISCRIMINATOR, getU8Decoder())], ['migrationVersion', getPinaPodMigrationVersionDecoder(0, getU8Decoder())], ['pool', getAddressDecoder()], ['trader', getAddressDecoder()], ['zeroForOne', getU8Decoder()], ['amountIn', getU64Decoder()], ['amountOut', getU64Decoder()], ['tradeFee', getU64Decoder()], ['protocolFee', getU64Decoder()], ['creatorFee', getU64Decoder()], ['creatorFeeOnInput', getU8Decoder()], ['reserve0', getU64Decoder()], ['reserve1', getU64Decoder()]]);
89
+ }
90
+
91
+ /** Gets the codec for {@link SwappedEvent} event data. */
92
+ export function getSwappedEventCodec(): FixedSizeCodec<SwappedEventArgs, SwappedEvent> {
93
+ return combineCodec(getSwappedEventEncoder(), getSwappedEventDecoder());
94
+ }
95
+
96
+ /** Parses the provided bytes into {@link SwappedEvent} event data. */
97
+ export function parseSwappedEvent(data: ReadonlyUint8Array | Uint8Array): SwappedEvent {
98
+ if (containsBytes(data, getU8Encoder().encode(SWAPPED_EVENT_DISCRIMINATOR), 0) && containsBytes(data, getU8Encoder().encode(SWAPPED_EVENT_DISCRIMINATOR2), 1)) { return getSwappedEventDecoder().decode(data); }
99
+ throw new Error('The provided data does not match the "SwappedEvent" event discriminators.');
100
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * This code was AUTOGENERATED using the Codama library.
3
+ * Please DO NOT EDIT THIS FILE, instead use visitors
4
+ * to add features, then rerun Codama to update it.
5
+ *
6
+ * @see https://github.com/codama-idl/codama
7
+ */
8
+
9
+ export * from './accounts';
10
+ export * from './errors';
11
+ export * from './events';
12
+ export * from './instructions';
13
+ export * from './pdas';
14
+ export * from './programs';