@pina-rs/amm 0.0.0 → 0.2.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 (48) hide show
  1. package/README.md +27 -2
  2. package/dist/index.cjs +1744 -0
  3. package/dist/index.cjs.map +1 -0
  4. package/dist/index.d.cts +2192 -0
  5. package/dist/index.d.ts +2192 -0
  6. package/dist/index.js +1507 -0
  7. package/dist/index.js.map +1 -0
  8. package/package.json +55 -5
  9. package/src/generated/accounts/ammConfig.ts +197 -0
  10. package/src/generated/accounts/index.ts +10 -0
  11. package/src/generated/accounts/pool.ts +274 -0
  12. package/src/generated/errors/index.ts +9 -0
  13. package/src/generated/errors/pinaAmm.ts +66 -0
  14. package/src/generated/events/configCreated.ts +80 -0
  15. package/src/generated/events/configUpdated.ts +64 -0
  16. package/src/generated/events/feesCollected.ts +64 -0
  17. package/src/generated/events/index.ts +18 -0
  18. package/src/generated/events/liquidityChanged.ts +72 -0
  19. package/src/generated/events/logs.ts +732 -0
  20. package/src/generated/events/poolCreated.ts +80 -0
  21. package/src/generated/events/poolCreatorChanged.ts +56 -0
  22. package/src/generated/events/poolSynced.ts +78 -0
  23. package/src/generated/events/poolSyncedV0.ts +44 -0
  24. package/src/generated/events/swapped.ts +100 -0
  25. package/src/generated/index.ts +14 -0
  26. package/src/generated/instructions/collectCreatorFees.ts +119 -0
  27. package/src/generated/instructions/collectProtocolFees.ts +123 -0
  28. package/src/generated/instructions/createConfig.ts +142 -0
  29. package/src/generated/instructions/createPool.ts +291 -0
  30. package/src/generated/instructions/deposit.ts +139 -0
  31. package/src/generated/instructions/index.ts +20 -0
  32. package/src/generated/instructions/migrate.ts +155 -0
  33. package/src/generated/instructions/setPoolCreator.ts +90 -0
  34. package/src/generated/instructions/swapExactIn.ts +119 -0
  35. package/src/generated/instructions/swapExactOut.ts +119 -0
  36. package/src/generated/instructions/syncPool.ts +93 -0
  37. package/src/generated/instructions/updateConfig.ts +105 -0
  38. package/src/generated/instructions/withdraw.ts +139 -0
  39. package/src/generated/pdas/ammConfig.ts +18 -0
  40. package/src/generated/pdas/index.ts +12 -0
  41. package/src/generated/pdas/pool.ts +20 -0
  42. package/src/generated/pdas/poolLpMint.ts +18 -0
  43. package/src/generated/pdas/poolVault.ts +19 -0
  44. package/src/generated/pinaPodCodecs.ts +232 -0
  45. package/src/generated/programs/index.ts +9 -0
  46. package/src/generated/programs/pinaAmm.ts +124 -0
  47. package/src/index.ts +11 -0
  48. package/CHANGELOG.md +0 -5
package/dist/index.js ADDED
@@ -0,0 +1,1507 @@
1
+ import { getProgramDerivedAddress, getUtf8Encoder, getU16Encoder, getAddressEncoder, getU8Encoder, transformEncoder, getStructEncoder, getU32Encoder, getStructDecoder, getU8Decoder, getAddressDecoder, getU32Decoder, getU16Decoder, combineCodec, decodeAccount, assertAccountExists, fetchEncodedAccount, assertAccountsExist, fetchEncodedAccounts, getU64Encoder, getU128Encoder, getU64Decoder, getU128Decoder, SolanaError, SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, containsBytes, SOLANA_ERROR__PROGRAM_CLIENTS__FAILED_TO_IDENTIFY_ACCOUNT, SOLANA_ERROR__PROGRAM_CLIENTS__FAILED_TO_IDENTIFY_INSTRUCTION, SOLANA_ERROR__PROGRAM_CLIENTS__UNRECOGNIZED_INSTRUCTION_TYPE, assertIsInstructionWithAccounts, extendClient, isProgramError, getBase64Encoder, transformDecoder } from '@solana/kit';
2
+ import { getAccountMetaFactory, getAddressFromResolvedInstructionAccount, addSelfPlanAndSendFunctions, addSelfFetchFunctions } from '@solana/program-client-core';
3
+
4
+ // src/generated/pinaPodCodecs.ts
5
+ function getPinaPodDiscriminatorDecoder(expected, decoder) {
6
+ return transformDecoder(decoder, (value) => {
7
+ if (BigInt(value) !== BigInt(expected)) {
8
+ throw new RangeError(
9
+ `invalid discriminator: expected ${expected}, received ${value}`
10
+ );
11
+ }
12
+ return value;
13
+ });
14
+ }
15
+ function getPinaPodMigrationVersionDecoder(expected, decoder) {
16
+ return transformDecoder(decoder, (value) => {
17
+ if (BigInt(value) !== BigInt(expected)) {
18
+ const hint = BigInt(value) < BigInt(expected) ? "the data predates this client; migrate it by sending a transaction to the program, or decode it with a client generated from an older IDL" : "the data was written by a newer program; upgrade this client";
19
+ throw new RangeError(
20
+ `migration version mismatch: expected ${expected}, received ${value} (${hint})`
21
+ );
22
+ }
23
+ return value;
24
+ });
25
+ }
26
+ async function findAmmConfigPda(seeds, config = {}) {
27
+ const { programAddress = "pAMMzVPRwtrxQs2CjLTUUpfCAp9XdvVmwwVhpAuCobi" } = config;
28
+ return await getProgramDerivedAddress({ programAddress, seeds: [getUtf8Encoder().encode("amm_config"), getU16Encoder().encode(seeds.index)] });
29
+ }
30
+ async function findPoolPda(seeds, config = {}) {
31
+ const { programAddress = "pAMMzVPRwtrxQs2CjLTUUpfCAp9XdvVmwwVhpAuCobi" } = config;
32
+ return await getProgramDerivedAddress({ programAddress, seeds: [getUtf8Encoder().encode("pool"), getAddressEncoder().encode(seeds.ammConfig), getAddressEncoder().encode(seeds.mint0), getAddressEncoder().encode(seeds.mint1)] });
33
+ }
34
+ async function findPoolLpMintPda(seeds, config = {}) {
35
+ const { programAddress = "pAMMzVPRwtrxQs2CjLTUUpfCAp9XdvVmwwVhpAuCobi" } = config;
36
+ return await getProgramDerivedAddress({ programAddress, seeds: [getUtf8Encoder().encode("pool_lp_mint"), getAddressEncoder().encode(seeds.pool)] });
37
+ }
38
+ async function findPoolVaultPda(seeds, config = {}) {
39
+ const { programAddress = "pAMMzVPRwtrxQs2CjLTUUpfCAp9XdvVmwwVhpAuCobi" } = config;
40
+ return await getProgramDerivedAddress({ programAddress, seeds: [getUtf8Encoder().encode("pool_vault"), getAddressEncoder().encode(seeds.pool), getAddressEncoder().encode(seeds.mint)] });
41
+ }
42
+
43
+ // src/generated/accounts/ammConfig.ts
44
+ var AMM_CONFIG_DISCRIMINATOR = 1;
45
+ function getAmmConfigDiscriminatorBytes() {
46
+ return getU8Encoder().encode(AMM_CONFIG_DISCRIMINATOR);
47
+ }
48
+ var AMM_CONFIG_DISCRIMINATOR2 = 0;
49
+ function getAmmConfigDiscriminator2Bytes() {
50
+ return getU8Encoder().encode(AMM_CONFIG_DISCRIMINATOR2);
51
+ }
52
+ function getAmmConfigEncoder() {
53
+ return transformEncoder(getStructEncoder([["discriminator", getU8Encoder()], ["migrationVersion", getU8Encoder()], ["authority", getAddressEncoder()], ["poolCreatorAuthority", getAddressEncoder()], ["tradeFeeRate", getU32Encoder()], ["protocolFeeRate", getU32Encoder()], ["creatorFeeRate", getU32Encoder()], ["index", getU16Encoder()], ["bump", getU8Encoder()]]), (value) => ({ ...value, discriminator: 1, migrationVersion: 0 }));
54
+ }
55
+ function getAmmConfigDecoder() {
56
+ return getStructDecoder([["discriminator", getPinaPodDiscriminatorDecoder(AMM_CONFIG_DISCRIMINATOR, getU8Decoder())], ["migrationVersion", getPinaPodMigrationVersionDecoder(0, getU8Decoder())], ["authority", getAddressDecoder()], ["poolCreatorAuthority", getAddressDecoder()], ["tradeFeeRate", getU32Decoder()], ["protocolFeeRate", getU32Decoder()], ["creatorFeeRate", getU32Decoder()], ["index", getU16Decoder()], ["bump", getU8Decoder()]]);
57
+ }
58
+ function getAmmConfigCodec() {
59
+ return combineCodec(getAmmConfigEncoder(), getAmmConfigDecoder());
60
+ }
61
+ function decodeAmmConfig(encodedAccount) {
62
+ return decodeAccount(encodedAccount, getAmmConfigDecoder());
63
+ }
64
+ async function fetchAmmConfig(rpc, address, config) {
65
+ const maybeAccount = await fetchMaybeAmmConfig(rpc, address, config);
66
+ assertAccountExists(maybeAccount);
67
+ return maybeAccount;
68
+ }
69
+ async function fetchMaybeAmmConfig(rpc, address, config) {
70
+ const maybeAccount = await fetchEncodedAccount(rpc, address, config);
71
+ return decodeAmmConfig(maybeAccount);
72
+ }
73
+ async function fetchAllAmmConfig(rpc, addresses, config) {
74
+ const maybeAccounts = await fetchAllMaybeAmmConfig(rpc, addresses, config);
75
+ assertAccountsExist(maybeAccounts);
76
+ return maybeAccounts;
77
+ }
78
+ async function fetchAllMaybeAmmConfig(rpc, addresses, config) {
79
+ const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
80
+ return maybeAccounts.map((maybeAccount) => decodeAmmConfig(maybeAccount));
81
+ }
82
+ async function fetchAmmConfigFromSeeds(rpc, seeds, config = {}) {
83
+ const maybeAccount = await fetchMaybeAmmConfigFromSeeds(rpc, seeds, config);
84
+ assertAccountExists(maybeAccount);
85
+ return maybeAccount;
86
+ }
87
+ async function fetchMaybeAmmConfigFromSeeds(rpc, seeds, config = {}) {
88
+ const { programAddress, ...fetchConfig } = config;
89
+ const [address] = await findAmmConfigPda(seeds, { programAddress });
90
+ return await fetchMaybeAmmConfig(rpc, address, fetchConfig);
91
+ }
92
+ var AMM_CONFIG_MIGRATION_VERSION = 0;
93
+ function ammConfigNeedsMigration(data) {
94
+ if (data.length < 2) {
95
+ return false;
96
+ }
97
+ if (data[0] !== 1) {
98
+ return false;
99
+ }
100
+ return data[1] < 0;
101
+ }
102
+ var POOL_DISCRIMINATOR = 2;
103
+ function getPoolDiscriminatorBytes() {
104
+ return getU8Encoder().encode(POOL_DISCRIMINATOR);
105
+ }
106
+ var POOL_DISCRIMINATOR2 = 1;
107
+ function getPoolDiscriminator2Bytes() {
108
+ return getU8Encoder().encode(POOL_DISCRIMINATOR2);
109
+ }
110
+ function getPoolEncoder() {
111
+ return transformEncoder(getStructEncoder([["discriminator", getU8Encoder()], ["migrationVersion", getU8Encoder()], ["ammConfig", getAddressEncoder()], ["creator", getAddressEncoder()], ["mint0", getAddressEncoder()], ["mint1", getAddressEncoder()], ["vault0", getAddressEncoder()], ["vault1", getAddressEncoder()], ["lpMint", getAddressEncoder()], ["lpSupply", getU64Encoder()], ["protocolFees0", getU64Encoder()], ["protocolFees1", getU64Encoder()], ["creatorFees0", getU64Encoder()], ["creatorFees1", getU64Encoder()], ["tradeFeeRate", getU32Encoder()], ["protocolFeeRate", getU32Encoder()], ["creatorFeeRate", getU32Encoder()], ["creatorFeeMode", getU8Encoder()], ["bump", getU8Encoder()], ["price0CumulativeLast", getU128Encoder()], ["price0CumulativeHighLast", getU128Encoder()], ["lastUpdateTimestamp", getU64Encoder()], ["reserve0Last", getU64Encoder()], ["reserve1Last", getU64Encoder()]]), (value) => ({ ...value, discriminator: 2, migrationVersion: 1 }));
112
+ }
113
+ function getPoolDecoder() {
114
+ return getStructDecoder([["discriminator", getPinaPodDiscriminatorDecoder(POOL_DISCRIMINATOR, getU8Decoder())], ["migrationVersion", getPinaPodMigrationVersionDecoder(1, getU8Decoder())], ["ammConfig", getAddressDecoder()], ["creator", getAddressDecoder()], ["mint0", getAddressDecoder()], ["mint1", getAddressDecoder()], ["vault0", getAddressDecoder()], ["vault1", getAddressDecoder()], ["lpMint", getAddressDecoder()], ["lpSupply", getU64Decoder()], ["protocolFees0", getU64Decoder()], ["protocolFees1", getU64Decoder()], ["creatorFees0", getU64Decoder()], ["creatorFees1", getU64Decoder()], ["tradeFeeRate", getU32Decoder()], ["protocolFeeRate", getU32Decoder()], ["creatorFeeRate", getU32Decoder()], ["creatorFeeMode", getU8Decoder()], ["bump", getU8Decoder()], ["price0CumulativeLast", getU128Decoder()], ["price0CumulativeHighLast", getU128Decoder()], ["lastUpdateTimestamp", getU64Decoder()], ["reserve0Last", getU64Decoder()], ["reserve1Last", getU64Decoder()]]);
115
+ }
116
+ function getPoolCodec() {
117
+ return combineCodec(getPoolEncoder(), getPoolDecoder());
118
+ }
119
+ function decodePool(encodedAccount) {
120
+ return decodeAccount(encodedAccount, getPoolDecoder());
121
+ }
122
+ async function fetchPool(rpc, address, config) {
123
+ const maybeAccount = await fetchMaybePool(rpc, address, config);
124
+ assertAccountExists(maybeAccount);
125
+ return maybeAccount;
126
+ }
127
+ async function fetchMaybePool(rpc, address, config) {
128
+ const maybeAccount = await fetchEncodedAccount(rpc, address, config);
129
+ return decodePool(maybeAccount);
130
+ }
131
+ async function fetchAllPool(rpc, addresses, config) {
132
+ const maybeAccounts = await fetchAllMaybePool(rpc, addresses, config);
133
+ assertAccountsExist(maybeAccounts);
134
+ return maybeAccounts;
135
+ }
136
+ async function fetchAllMaybePool(rpc, addresses, config) {
137
+ const maybeAccounts = await fetchEncodedAccounts(rpc, addresses, config);
138
+ return maybeAccounts.map((maybeAccount) => decodePool(maybeAccount));
139
+ }
140
+ async function fetchPoolFromSeeds(rpc, seeds, config = {}) {
141
+ const maybeAccount = await fetchMaybePoolFromSeeds(rpc, seeds, config);
142
+ assertAccountExists(maybeAccount);
143
+ return maybeAccount;
144
+ }
145
+ async function fetchMaybePoolFromSeeds(rpc, seeds, config = {}) {
146
+ const { programAddress, ...fetchConfig } = config;
147
+ const [address] = await findPoolPda(seeds, { programAddress });
148
+ return await fetchMaybePool(rpc, address, fetchConfig);
149
+ }
150
+ var POOL_MIGRATION_VERSION = 1;
151
+ function poolNeedsMigration(data) {
152
+ if (data.length < 2) {
153
+ return false;
154
+ }
155
+ if (data[0] !== 2) {
156
+ return false;
157
+ }
158
+ return data[1] < 1;
159
+ }
160
+ var MIGRATE_DISCRIMINATOR = 255;
161
+ function getMigrateDiscriminatorBytes() {
162
+ return new Uint8Array([255]);
163
+ }
164
+ function getMigrateInstruction(input, config) {
165
+ const programAddress = config?.programAddress ?? PINA_AMM_PROGRAM_ADDRESS;
166
+ const originalAccounts = {
167
+ payer: { value: input.payer ?? null, isWritable: true },
168
+ systemProgram: { value: input.systemProgram ?? "11111111111111111111111111111111", isWritable: false },
169
+ ammConfig: { value: input.ammConfig ?? null, isWritable: true },
170
+ pool: { value: input.pool ?? null, isWritable: true }
171
+ };
172
+ const accounts = originalAccounts;
173
+ const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
174
+ const provided = [input.ammConfig, input.pool];
175
+ let lastProvided = -1;
176
+ for (let index = 0; index < provided.length; index += 1) {
177
+ if (provided[index] != null) {
178
+ lastProvided = index;
179
+ }
180
+ }
181
+ return Object.freeze({
182
+ accounts: [
183
+ getAccountMeta("payer", accounts.payer),
184
+ getAccountMeta("systemProgram", accounts.systemProgram),
185
+ getAccountMeta("ammConfig", accounts.ammConfig),
186
+ getAccountMeta("pool", accounts.pool)
187
+ ].slice(0, 2 + lastProvided + 1),
188
+ data: getMigrateDiscriminatorBytes(),
189
+ programAddress
190
+ });
191
+ }
192
+ var COLLECT_CREATOR_FEES_DISCRIMINATOR = 8;
193
+ function getCollectCreatorFeesDiscriminatorBytes() {
194
+ return getU8Encoder().encode(COLLECT_CREATOR_FEES_DISCRIMINATOR);
195
+ }
196
+ function getCollectCreatorFeesInstructionDataEncoder() {
197
+ return transformEncoder(getStructEncoder([["discriminator", getU8Encoder()], ["maximumAmount0", getU64Encoder()], ["maximumAmount1", getU64Encoder()]]), (value) => ({ ...value, discriminator: 8 }));
198
+ }
199
+ function getCollectCreatorFeesInstructionDataDecoder() {
200
+ return getStructDecoder([["discriminator", getPinaPodDiscriminatorDecoder(COLLECT_CREATOR_FEES_DISCRIMINATOR, getU8Decoder())], ["maximumAmount0", getU64Decoder()], ["maximumAmount1", getU64Decoder()]]);
201
+ }
202
+ function getCollectCreatorFeesInstructionDataCodec() {
203
+ return combineCodec(getCollectCreatorFeesInstructionDataEncoder(), getCollectCreatorFeesInstructionDataDecoder());
204
+ }
205
+ function getCollectCreatorFeesInstruction(input, config) {
206
+ const programAddress = config?.programAddress ?? PINA_AMM_PROGRAM_ADDRESS;
207
+ const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
208
+ const originalAccounts = { creator: { value: input.creator ?? null, isSigner: true, isWritable: false }, pool: { value: input.pool ?? null, isSigner: false, isWritable: true }, vault0: { value: input.vault0 ?? null, isSigner: false, isWritable: true }, vault1: { value: input.vault1 ?? null, isSigner: false, isWritable: true }, recipientToken0: { value: input.recipientToken0 ?? null, isSigner: false, isWritable: true }, recipientToken1: { value: input.recipientToken1 ?? null, isSigner: false, isWritable: true }, tokenProgram0: { value: input.tokenProgram0 ?? null, isSigner: false, isWritable: false }, tokenProgram1: { value: input.tokenProgram1 ?? null, isSigner: false, isWritable: false } };
209
+ const accounts = originalAccounts;
210
+ const args = { ...input };
211
+ return Object.freeze({ accounts: [getAccountMeta("creator", accounts.creator), getAccountMeta("pool", accounts.pool), getAccountMeta("vault0", accounts.vault0), getAccountMeta("vault1", accounts.vault1), getAccountMeta("recipientToken0", accounts.recipientToken0), getAccountMeta("recipientToken1", accounts.recipientToken1), getAccountMeta("tokenProgram0", accounts.tokenProgram0), getAccountMeta("tokenProgram1", accounts.tokenProgram1)], data: getCollectCreatorFeesInstructionDataEncoder().encode(args), programAddress });
212
+ }
213
+ function parseCollectCreatorFeesInstruction(instruction) {
214
+ if (instruction.accounts.length < 8) {
215
+ throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 8 });
216
+ }
217
+ let accountIndex = 0;
218
+ const getNextAccount = () => {
219
+ const accountMeta = instruction.accounts[accountIndex];
220
+ accountIndex += 1;
221
+ return accountMeta;
222
+ };
223
+ return { programAddress: instruction.programAddress, accounts: { creator: getNextAccount(), pool: getNextAccount(), vault0: getNextAccount(), vault1: getNextAccount(), recipientToken0: getNextAccount(), recipientToken1: getNextAccount(), tokenProgram0: getNextAccount(), tokenProgram1: getNextAccount() }, data: getCollectCreatorFeesInstructionDataDecoder().decode(instruction.data) };
224
+ }
225
+ var COLLECT_PROTOCOL_FEES_DISCRIMINATOR = 7;
226
+ function getCollectProtocolFeesDiscriminatorBytes() {
227
+ return getU8Encoder().encode(COLLECT_PROTOCOL_FEES_DISCRIMINATOR);
228
+ }
229
+ function getCollectProtocolFeesInstructionDataEncoder() {
230
+ return transformEncoder(getStructEncoder([["discriminator", getU8Encoder()], ["maximumAmount0", getU64Encoder()], ["maximumAmount1", getU64Encoder()]]), (value) => ({ ...value, discriminator: 7 }));
231
+ }
232
+ function getCollectProtocolFeesInstructionDataDecoder() {
233
+ return getStructDecoder([["discriminator", getPinaPodDiscriminatorDecoder(COLLECT_PROTOCOL_FEES_DISCRIMINATOR, getU8Decoder())], ["maximumAmount0", getU64Decoder()], ["maximumAmount1", getU64Decoder()]]);
234
+ }
235
+ function getCollectProtocolFeesInstructionDataCodec() {
236
+ return combineCodec(getCollectProtocolFeesInstructionDataEncoder(), getCollectProtocolFeesInstructionDataDecoder());
237
+ }
238
+ function getCollectProtocolFeesInstruction(input, config) {
239
+ const programAddress = config?.programAddress ?? PINA_AMM_PROGRAM_ADDRESS;
240
+ const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
241
+ const originalAccounts = { authority: { value: input.authority ?? null, isSigner: true, isWritable: false }, ammConfig: { value: input.ammConfig ?? null, isSigner: false, isWritable: false }, pool: { value: input.pool ?? null, isSigner: false, isWritable: true }, vault0: { value: input.vault0 ?? null, isSigner: false, isWritable: true }, vault1: { value: input.vault1 ?? null, isSigner: false, isWritable: true }, recipientToken0: { value: input.recipientToken0 ?? null, isSigner: false, isWritable: true }, recipientToken1: { value: input.recipientToken1 ?? null, isSigner: false, isWritable: true }, tokenProgram0: { value: input.tokenProgram0 ?? null, isSigner: false, isWritable: false }, tokenProgram1: { value: input.tokenProgram1 ?? null, isSigner: false, isWritable: false } };
242
+ const accounts = originalAccounts;
243
+ const args = { ...input };
244
+ return Object.freeze({ accounts: [getAccountMeta("authority", accounts.authority), getAccountMeta("ammConfig", accounts.ammConfig), getAccountMeta("pool", accounts.pool), getAccountMeta("vault0", accounts.vault0), getAccountMeta("vault1", accounts.vault1), getAccountMeta("recipientToken0", accounts.recipientToken0), getAccountMeta("recipientToken1", accounts.recipientToken1), getAccountMeta("tokenProgram0", accounts.tokenProgram0), getAccountMeta("tokenProgram1", accounts.tokenProgram1)], data: getCollectProtocolFeesInstructionDataEncoder().encode(args), programAddress });
245
+ }
246
+ function parseCollectProtocolFeesInstruction(instruction) {
247
+ if (instruction.accounts.length < 9) {
248
+ throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 9 });
249
+ }
250
+ let accountIndex = 0;
251
+ const getNextAccount = () => {
252
+ const accountMeta = instruction.accounts[accountIndex];
253
+ accountIndex += 1;
254
+ return accountMeta;
255
+ };
256
+ return { programAddress: instruction.programAddress, accounts: { authority: getNextAccount(), ammConfig: getNextAccount(), pool: getNextAccount(), vault0: getNextAccount(), vault1: getNextAccount(), recipientToken0: getNextAccount(), recipientToken1: getNextAccount(), tokenProgram0: getNextAccount(), tokenProgram1: getNextAccount() }, data: getCollectProtocolFeesInstructionDataDecoder().decode(instruction.data) };
257
+ }
258
+ var CREATE_CONFIG_DISCRIMINATOR = 0;
259
+ function getCreateConfigDiscriminatorBytes() {
260
+ return getU8Encoder().encode(CREATE_CONFIG_DISCRIMINATOR);
261
+ }
262
+ function getCreateConfigInstructionDataEncoder() {
263
+ return transformEncoder(getStructEncoder([["discriminator", getU8Encoder()], ["index", getU16Encoder()], ["tradeFeeRate", getU32Encoder()], ["protocolFeeRate", getU32Encoder()], ["creatorFeeRate", getU32Encoder()], ["authority", getAddressEncoder()], ["poolCreatorAuthority", getAddressEncoder()]]), (value) => ({ ...value, discriminator: 0 }));
264
+ }
265
+ function getCreateConfigInstructionDataDecoder() {
266
+ return getStructDecoder([["discriminator", getPinaPodDiscriminatorDecoder(CREATE_CONFIG_DISCRIMINATOR, getU8Decoder())], ["index", getU16Decoder()], ["tradeFeeRate", getU32Decoder()], ["protocolFeeRate", getU32Decoder()], ["creatorFeeRate", getU32Decoder()], ["authority", getAddressDecoder()], ["poolCreatorAuthority", getAddressDecoder()]]);
267
+ }
268
+ function getCreateConfigInstructionDataCodec() {
269
+ return combineCodec(getCreateConfigInstructionDataEncoder(), getCreateConfigInstructionDataDecoder());
270
+ }
271
+ function getCreateConfigInstruction(input, config) {
272
+ const programAddress = config?.programAddress ?? PINA_AMM_PROGRAM_ADDRESS;
273
+ const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
274
+ const originalAccounts = { payer: { value: input.payer ?? null, isSigner: true, isWritable: true }, upgradeAuthority: { value: input.upgradeAuthority ?? null, isSigner: true, isWritable: false }, programData: { value: input.programData ?? null, isSigner: false, isWritable: false }, ammConfig: { value: input.ammConfig ?? null, isSigner: false, isWritable: true }, systemProgram: { value: input.systemProgram ?? null, isSigner: false, isWritable: false } };
275
+ const accounts = originalAccounts;
276
+ const args = { ...input };
277
+ if (!accounts.systemProgram.value) {
278
+ accounts.systemProgram.value = "11111111111111111111111111111111";
279
+ }
280
+ return Object.freeze({ accounts: [getAccountMeta("payer", accounts.payer), getAccountMeta("upgradeAuthority", accounts.upgradeAuthority), getAccountMeta("programData", accounts.programData), getAccountMeta("ammConfig", accounts.ammConfig), getAccountMeta("systemProgram", accounts.systemProgram)], data: getCreateConfigInstructionDataEncoder().encode(args), programAddress });
281
+ }
282
+ function parseCreateConfigInstruction(instruction) {
283
+ if (instruction.accounts.length < 5) {
284
+ throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 5 });
285
+ }
286
+ let accountIndex = 0;
287
+ const getNextAccount = () => {
288
+ const accountMeta = instruction.accounts[accountIndex];
289
+ accountIndex += 1;
290
+ return accountMeta;
291
+ };
292
+ return { programAddress: instruction.programAddress, accounts: { payer: getNextAccount(), upgradeAuthority: getNextAccount(), programData: getNextAccount(), ammConfig: getNextAccount(), systemProgram: getNextAccount() }, data: getCreateConfigInstructionDataDecoder().decode(instruction.data) };
293
+ }
294
+ var CREATE_POOL_DISCRIMINATOR = 2;
295
+ function getCreatePoolDiscriminatorBytes() {
296
+ return getU8Encoder().encode(CREATE_POOL_DISCRIMINATOR);
297
+ }
298
+ function getCreatePoolInstructionDataEncoder() {
299
+ return transformEncoder(getStructEncoder([["discriminator", getU8Encoder()], ["amount0", getU64Encoder()], ["amount1", getU64Encoder()], ["creator", getAddressEncoder()], ["creatorFeeMode", getU8Encoder()]]), (value) => ({ ...value, discriminator: 2 }));
300
+ }
301
+ function getCreatePoolInstructionDataDecoder() {
302
+ return getStructDecoder([["discriminator", getPinaPodDiscriminatorDecoder(CREATE_POOL_DISCRIMINATOR, getU8Decoder())], ["amount0", getU64Decoder()], ["amount1", getU64Decoder()], ["creator", getAddressDecoder()], ["creatorFeeMode", getU8Decoder()]]);
303
+ }
304
+ function getCreatePoolInstructionDataCodec() {
305
+ return combineCodec(getCreatePoolInstructionDataEncoder(), getCreatePoolInstructionDataDecoder());
306
+ }
307
+ async function getCreatePoolInstructionAsync(input, config) {
308
+ const programAddress = config?.programAddress ?? PINA_AMM_PROGRAM_ADDRESS;
309
+ const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
310
+ const originalAccounts = { payer: { value: input.payer ?? null, isSigner: true, isWritable: true }, depositor: { value: input.depositor ?? null, isSigner: true, isWritable: false }, poolCreatorAuthority: { value: input.poolCreatorAuthority ?? null, isSigner: true, isWritable: false }, ammConfig: { value: input.ammConfig ?? null, isSigner: false, isWritable: false }, mint0: { value: input.mint0 ?? null, isSigner: false, isWritable: false }, mint1: { value: input.mint1 ?? null, isSigner: false, isWritable: false }, pool: { value: input.pool ?? null, isSigner: false, isWritable: true }, lpMint: { value: input.lpMint ?? null, isSigner: false, isWritable: true }, vault0: { value: input.vault0 ?? null, isSigner: false, isWritable: true }, vault1: { value: input.vault1 ?? null, isSigner: false, isWritable: true }, depositorToken0: { value: input.depositorToken0 ?? null, isSigner: false, isWritable: true }, depositorToken1: { value: input.depositorToken1 ?? null, isSigner: false, isWritable: true }, lpOwner: { value: input.lpOwner ?? null, isSigner: false, isWritable: false }, lpOwnerToken: { value: input.lpOwnerToken ?? null, isSigner: false, isWritable: true }, tokenProgram0: { value: input.tokenProgram0 ?? null, isSigner: false, isWritable: false }, tokenProgram1: { value: input.tokenProgram1 ?? null, isSigner: false, isWritable: false }, lpTokenProgram: { value: input.lpTokenProgram ?? null, isSigner: false, isWritable: false }, associatedTokenProgram: { value: input.associatedTokenProgram ?? null, isSigner: false, isWritable: false }, systemProgram: { value: input.systemProgram ?? null, isSigner: false, isWritable: false } };
311
+ const accounts = originalAccounts;
312
+ const args = { ...input };
313
+ if (!accounts.pool.value) {
314
+ accounts.pool.value = await findPoolPda({ ammConfig: getAddressFromResolvedInstructionAccount("ammConfig", accounts.ammConfig.value), mint0: getAddressFromResolvedInstructionAccount("mint0", accounts.mint0.value), mint1: getAddressFromResolvedInstructionAccount("mint1", accounts.mint1.value) }, { programAddress });
315
+ }
316
+ if (!accounts.lpTokenProgram.value) {
317
+ accounts.lpTokenProgram.value = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";
318
+ }
319
+ if (!accounts.associatedTokenProgram.value) {
320
+ accounts.associatedTokenProgram.value = "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL";
321
+ }
322
+ if (!accounts.systemProgram.value) {
323
+ accounts.systemProgram.value = "11111111111111111111111111111111";
324
+ }
325
+ return Object.freeze({ accounts: [getAccountMeta("payer", accounts.payer), getAccountMeta("depositor", accounts.depositor), getAccountMeta("poolCreatorAuthority", accounts.poolCreatorAuthority), getAccountMeta("ammConfig", accounts.ammConfig), getAccountMeta("mint0", accounts.mint0), getAccountMeta("mint1", accounts.mint1), getAccountMeta("pool", accounts.pool), getAccountMeta("lpMint", accounts.lpMint), getAccountMeta("vault0", accounts.vault0), getAccountMeta("vault1", accounts.vault1), getAccountMeta("depositorToken0", accounts.depositorToken0), getAccountMeta("depositorToken1", accounts.depositorToken1), getAccountMeta("lpOwner", accounts.lpOwner), getAccountMeta("lpOwnerToken", accounts.lpOwnerToken), getAccountMeta("tokenProgram0", accounts.tokenProgram0), getAccountMeta("tokenProgram1", accounts.tokenProgram1), getAccountMeta("lpTokenProgram", accounts.lpTokenProgram), getAccountMeta("associatedTokenProgram", accounts.associatedTokenProgram), getAccountMeta("systemProgram", accounts.systemProgram)], data: getCreatePoolInstructionDataEncoder().encode(args), programAddress });
326
+ }
327
+ function getCreatePoolInstruction(input, config) {
328
+ const programAddress = config?.programAddress ?? PINA_AMM_PROGRAM_ADDRESS;
329
+ const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
330
+ const originalAccounts = { payer: { value: input.payer ?? null, isSigner: true, isWritable: true }, depositor: { value: input.depositor ?? null, isSigner: true, isWritable: false }, poolCreatorAuthority: { value: input.poolCreatorAuthority ?? null, isSigner: true, isWritable: false }, ammConfig: { value: input.ammConfig ?? null, isSigner: false, isWritable: false }, mint0: { value: input.mint0 ?? null, isSigner: false, isWritable: false }, mint1: { value: input.mint1 ?? null, isSigner: false, isWritable: false }, pool: { value: input.pool ?? null, isSigner: false, isWritable: true }, lpMint: { value: input.lpMint ?? null, isSigner: false, isWritable: true }, vault0: { value: input.vault0 ?? null, isSigner: false, isWritable: true }, vault1: { value: input.vault1 ?? null, isSigner: false, isWritable: true }, depositorToken0: { value: input.depositorToken0 ?? null, isSigner: false, isWritable: true }, depositorToken1: { value: input.depositorToken1 ?? null, isSigner: false, isWritable: true }, lpOwner: { value: input.lpOwner ?? null, isSigner: false, isWritable: false }, lpOwnerToken: { value: input.lpOwnerToken ?? null, isSigner: false, isWritable: true }, tokenProgram0: { value: input.tokenProgram0 ?? null, isSigner: false, isWritable: false }, tokenProgram1: { value: input.tokenProgram1 ?? null, isSigner: false, isWritable: false }, lpTokenProgram: { value: input.lpTokenProgram ?? null, isSigner: false, isWritable: false }, associatedTokenProgram: { value: input.associatedTokenProgram ?? null, isSigner: false, isWritable: false }, systemProgram: { value: input.systemProgram ?? null, isSigner: false, isWritable: false } };
331
+ const accounts = originalAccounts;
332
+ const args = { ...input };
333
+ if (!accounts.lpTokenProgram.value) {
334
+ accounts.lpTokenProgram.value = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";
335
+ }
336
+ if (!accounts.associatedTokenProgram.value) {
337
+ accounts.associatedTokenProgram.value = "ATokenGPvbdGVxr1b2hvZbsiqW5xWH25efTNsLJA8knL";
338
+ }
339
+ if (!accounts.systemProgram.value) {
340
+ accounts.systemProgram.value = "11111111111111111111111111111111";
341
+ }
342
+ return Object.freeze({ accounts: [getAccountMeta("payer", accounts.payer), getAccountMeta("depositor", accounts.depositor), getAccountMeta("poolCreatorAuthority", accounts.poolCreatorAuthority), getAccountMeta("ammConfig", accounts.ammConfig), getAccountMeta("mint0", accounts.mint0), getAccountMeta("mint1", accounts.mint1), getAccountMeta("pool", accounts.pool), getAccountMeta("lpMint", accounts.lpMint), getAccountMeta("vault0", accounts.vault0), getAccountMeta("vault1", accounts.vault1), getAccountMeta("depositorToken0", accounts.depositorToken0), getAccountMeta("depositorToken1", accounts.depositorToken1), getAccountMeta("lpOwner", accounts.lpOwner), getAccountMeta("lpOwnerToken", accounts.lpOwnerToken), getAccountMeta("tokenProgram0", accounts.tokenProgram0), getAccountMeta("tokenProgram1", accounts.tokenProgram1), getAccountMeta("lpTokenProgram", accounts.lpTokenProgram), getAccountMeta("associatedTokenProgram", accounts.associatedTokenProgram), getAccountMeta("systemProgram", accounts.systemProgram)], data: getCreatePoolInstructionDataEncoder().encode(args), programAddress });
343
+ }
344
+ function parseCreatePoolInstruction(instruction) {
345
+ if (instruction.accounts.length < 19) {
346
+ throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 19 });
347
+ }
348
+ let accountIndex = 0;
349
+ const getNextAccount = () => {
350
+ const accountMeta = instruction.accounts[accountIndex];
351
+ accountIndex += 1;
352
+ return accountMeta;
353
+ };
354
+ return { programAddress: instruction.programAddress, accounts: { payer: getNextAccount(), depositor: getNextAccount(), poolCreatorAuthority: getNextAccount(), ammConfig: getNextAccount(), mint0: getNextAccount(), mint1: getNextAccount(), pool: getNextAccount(), lpMint: getNextAccount(), vault0: getNextAccount(), vault1: getNextAccount(), depositorToken0: getNextAccount(), depositorToken1: getNextAccount(), lpOwner: getNextAccount(), lpOwnerToken: getNextAccount(), tokenProgram0: getNextAccount(), tokenProgram1: getNextAccount(), lpTokenProgram: getNextAccount(), associatedTokenProgram: getNextAccount(), systemProgram: getNextAccount() }, data: getCreatePoolInstructionDataDecoder().decode(instruction.data) };
355
+ }
356
+ var DEPOSIT_DISCRIMINATOR = 3;
357
+ function getDepositDiscriminatorBytes() {
358
+ return getU8Encoder().encode(DEPOSIT_DISCRIMINATOR);
359
+ }
360
+ function getDepositInstructionDataEncoder() {
361
+ return transformEncoder(getStructEncoder([["discriminator", getU8Encoder()], ["lpAmount", getU64Encoder()], ["maximumAmount0", getU64Encoder()], ["maximumAmount1", getU64Encoder()]]), (value) => ({ ...value, discriminator: 3 }));
362
+ }
363
+ function getDepositInstructionDataDecoder() {
364
+ return getStructDecoder([["discriminator", getPinaPodDiscriminatorDecoder(DEPOSIT_DISCRIMINATOR, getU8Decoder())], ["lpAmount", getU64Decoder()], ["maximumAmount0", getU64Decoder()], ["maximumAmount1", getU64Decoder()]]);
365
+ }
366
+ function getDepositInstructionDataCodec() {
367
+ return combineCodec(getDepositInstructionDataEncoder(), getDepositInstructionDataDecoder());
368
+ }
369
+ function getDepositInstruction(input, config) {
370
+ const programAddress = config?.programAddress ?? PINA_AMM_PROGRAM_ADDRESS;
371
+ const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
372
+ const originalAccounts = { owner: { value: input.owner ?? null, isSigner: true, isWritable: false }, pool: { value: input.pool ?? null, isSigner: false, isWritable: true }, vault0: { value: input.vault0 ?? null, isSigner: false, isWritable: true }, vault1: { value: input.vault1 ?? null, isSigner: false, isWritable: true }, lpMint: { value: input.lpMint ?? null, isSigner: false, isWritable: true }, ownerToken0: { value: input.ownerToken0 ?? null, isSigner: false, isWritable: true }, ownerToken1: { value: input.ownerToken1 ?? null, isSigner: false, isWritable: true }, ownerLpToken: { value: input.ownerLpToken ?? null, isSigner: false, isWritable: true }, tokenProgram0: { value: input.tokenProgram0 ?? null, isSigner: false, isWritable: false }, tokenProgram1: { value: input.tokenProgram1 ?? null, isSigner: false, isWritable: false }, lpTokenProgram: { value: input.lpTokenProgram ?? null, isSigner: false, isWritable: false } };
373
+ const accounts = originalAccounts;
374
+ const args = { ...input };
375
+ if (!accounts.lpTokenProgram.value) {
376
+ accounts.lpTokenProgram.value = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";
377
+ }
378
+ return Object.freeze({ accounts: [getAccountMeta("owner", accounts.owner), getAccountMeta("pool", accounts.pool), getAccountMeta("vault0", accounts.vault0), getAccountMeta("vault1", accounts.vault1), getAccountMeta("lpMint", accounts.lpMint), getAccountMeta("ownerToken0", accounts.ownerToken0), getAccountMeta("ownerToken1", accounts.ownerToken1), getAccountMeta("ownerLpToken", accounts.ownerLpToken), getAccountMeta("tokenProgram0", accounts.tokenProgram0), getAccountMeta("tokenProgram1", accounts.tokenProgram1), getAccountMeta("lpTokenProgram", accounts.lpTokenProgram)], data: getDepositInstructionDataEncoder().encode(args), programAddress });
379
+ }
380
+ function parseDepositInstruction(instruction) {
381
+ if (instruction.accounts.length < 11) {
382
+ throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 11 });
383
+ }
384
+ let accountIndex = 0;
385
+ const getNextAccount = () => {
386
+ const accountMeta = instruction.accounts[accountIndex];
387
+ accountIndex += 1;
388
+ return accountMeta;
389
+ };
390
+ return { programAddress: instruction.programAddress, accounts: { owner: getNextAccount(), pool: getNextAccount(), vault0: getNextAccount(), vault1: getNextAccount(), lpMint: getNextAccount(), ownerToken0: getNextAccount(), ownerToken1: getNextAccount(), ownerLpToken: getNextAccount(), tokenProgram0: getNextAccount(), tokenProgram1: getNextAccount(), lpTokenProgram: getNextAccount() }, data: getDepositInstructionDataDecoder().decode(instruction.data) };
391
+ }
392
+ var SET_POOL_CREATOR_DISCRIMINATOR = 9;
393
+ function getSetPoolCreatorDiscriminatorBytes() {
394
+ return getU8Encoder().encode(SET_POOL_CREATOR_DISCRIMINATOR);
395
+ }
396
+ function getSetPoolCreatorInstructionDataEncoder() {
397
+ return transformEncoder(getStructEncoder([["discriminator", getU8Encoder()], ["newCreator", getAddressEncoder()]]), (value) => ({ ...value, discriminator: 9 }));
398
+ }
399
+ function getSetPoolCreatorInstructionDataDecoder() {
400
+ return getStructDecoder([["discriminator", getPinaPodDiscriminatorDecoder(SET_POOL_CREATOR_DISCRIMINATOR, getU8Decoder())], ["newCreator", getAddressDecoder()]]);
401
+ }
402
+ function getSetPoolCreatorInstructionDataCodec() {
403
+ return combineCodec(getSetPoolCreatorInstructionDataEncoder(), getSetPoolCreatorInstructionDataDecoder());
404
+ }
405
+ function getSetPoolCreatorInstruction(input, config) {
406
+ const programAddress = config?.programAddress ?? PINA_AMM_PROGRAM_ADDRESS;
407
+ const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
408
+ const originalAccounts = { creator: { value: input.creator ?? null, isSigner: true, isWritable: false }, pool: { value: input.pool ?? null, isSigner: false, isWritable: true } };
409
+ const accounts = originalAccounts;
410
+ const args = { ...input };
411
+ return Object.freeze({ accounts: [getAccountMeta("creator", accounts.creator), getAccountMeta("pool", accounts.pool)], data: getSetPoolCreatorInstructionDataEncoder().encode(args), programAddress });
412
+ }
413
+ function parseSetPoolCreatorInstruction(instruction) {
414
+ if (instruction.accounts.length < 2) {
415
+ throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 2 });
416
+ }
417
+ let accountIndex = 0;
418
+ const getNextAccount = () => {
419
+ const accountMeta = instruction.accounts[accountIndex];
420
+ accountIndex += 1;
421
+ return accountMeta;
422
+ };
423
+ return { programAddress: instruction.programAddress, accounts: { creator: getNextAccount(), pool: getNextAccount() }, data: getSetPoolCreatorInstructionDataDecoder().decode(instruction.data) };
424
+ }
425
+ var SWAP_EXACT_IN_DISCRIMINATOR = 5;
426
+ function getSwapExactInDiscriminatorBytes() {
427
+ return getU8Encoder().encode(SWAP_EXACT_IN_DISCRIMINATOR);
428
+ }
429
+ function getSwapExactInInstructionDataEncoder() {
430
+ return transformEncoder(getStructEncoder([["discriminator", getU8Encoder()], ["amountIn", getU64Encoder()], ["minimumAmountOut", getU64Encoder()]]), (value) => ({ ...value, discriminator: 5 }));
431
+ }
432
+ function getSwapExactInInstructionDataDecoder() {
433
+ return getStructDecoder([["discriminator", getPinaPodDiscriminatorDecoder(SWAP_EXACT_IN_DISCRIMINATOR, getU8Decoder())], ["amountIn", getU64Decoder()], ["minimumAmountOut", getU64Decoder()]]);
434
+ }
435
+ function getSwapExactInInstructionDataCodec() {
436
+ return combineCodec(getSwapExactInInstructionDataEncoder(), getSwapExactInInstructionDataDecoder());
437
+ }
438
+ function getSwapExactInInstruction(input, config) {
439
+ const programAddress = config?.programAddress ?? PINA_AMM_PROGRAM_ADDRESS;
440
+ const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
441
+ const originalAccounts = { trader: { value: input.trader ?? null, isSigner: true, isWritable: false }, pool: { value: input.pool ?? null, isSigner: false, isWritable: true }, inputToken: { value: input.inputToken ?? null, isSigner: false, isWritable: true }, outputToken: { value: input.outputToken ?? null, isSigner: false, isWritable: true }, inputVault: { value: input.inputVault ?? null, isSigner: false, isWritable: true }, outputVault: { value: input.outputVault ?? null, isSigner: false, isWritable: true }, inputTokenProgram: { value: input.inputTokenProgram ?? null, isSigner: false, isWritable: false }, outputTokenProgram: { value: input.outputTokenProgram ?? null, isSigner: false, isWritable: false } };
442
+ const accounts = originalAccounts;
443
+ const args = { ...input };
444
+ return Object.freeze({ accounts: [getAccountMeta("trader", accounts.trader), getAccountMeta("pool", accounts.pool), getAccountMeta("inputToken", accounts.inputToken), getAccountMeta("outputToken", accounts.outputToken), getAccountMeta("inputVault", accounts.inputVault), getAccountMeta("outputVault", accounts.outputVault), getAccountMeta("inputTokenProgram", accounts.inputTokenProgram), getAccountMeta("outputTokenProgram", accounts.outputTokenProgram)], data: getSwapExactInInstructionDataEncoder().encode(args), programAddress });
445
+ }
446
+ function parseSwapExactInInstruction(instruction) {
447
+ if (instruction.accounts.length < 8) {
448
+ throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 8 });
449
+ }
450
+ let accountIndex = 0;
451
+ const getNextAccount = () => {
452
+ const accountMeta = instruction.accounts[accountIndex];
453
+ accountIndex += 1;
454
+ return accountMeta;
455
+ };
456
+ return { programAddress: instruction.programAddress, accounts: { trader: getNextAccount(), pool: getNextAccount(), inputToken: getNextAccount(), outputToken: getNextAccount(), inputVault: getNextAccount(), outputVault: getNextAccount(), inputTokenProgram: getNextAccount(), outputTokenProgram: getNextAccount() }, data: getSwapExactInInstructionDataDecoder().decode(instruction.data) };
457
+ }
458
+ var SWAP_EXACT_OUT_DISCRIMINATOR = 6;
459
+ function getSwapExactOutDiscriminatorBytes() {
460
+ return getU8Encoder().encode(SWAP_EXACT_OUT_DISCRIMINATOR);
461
+ }
462
+ function getSwapExactOutInstructionDataEncoder() {
463
+ return transformEncoder(getStructEncoder([["discriminator", getU8Encoder()], ["amountOut", getU64Encoder()], ["maximumAmountIn", getU64Encoder()]]), (value) => ({ ...value, discriminator: 6 }));
464
+ }
465
+ function getSwapExactOutInstructionDataDecoder() {
466
+ return getStructDecoder([["discriminator", getPinaPodDiscriminatorDecoder(SWAP_EXACT_OUT_DISCRIMINATOR, getU8Decoder())], ["amountOut", getU64Decoder()], ["maximumAmountIn", getU64Decoder()]]);
467
+ }
468
+ function getSwapExactOutInstructionDataCodec() {
469
+ return combineCodec(getSwapExactOutInstructionDataEncoder(), getSwapExactOutInstructionDataDecoder());
470
+ }
471
+ function getSwapExactOutInstruction(input, config) {
472
+ const programAddress = config?.programAddress ?? PINA_AMM_PROGRAM_ADDRESS;
473
+ const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
474
+ const originalAccounts = { trader: { value: input.trader ?? null, isSigner: true, isWritable: false }, pool: { value: input.pool ?? null, isSigner: false, isWritable: true }, inputToken: { value: input.inputToken ?? null, isSigner: false, isWritable: true }, outputToken: { value: input.outputToken ?? null, isSigner: false, isWritable: true }, inputVault: { value: input.inputVault ?? null, isSigner: false, isWritable: true }, outputVault: { value: input.outputVault ?? null, isSigner: false, isWritable: true }, inputTokenProgram: { value: input.inputTokenProgram ?? null, isSigner: false, isWritable: false }, outputTokenProgram: { value: input.outputTokenProgram ?? null, isSigner: false, isWritable: false } };
475
+ const accounts = originalAccounts;
476
+ const args = { ...input };
477
+ return Object.freeze({ accounts: [getAccountMeta("trader", accounts.trader), getAccountMeta("pool", accounts.pool), getAccountMeta("inputToken", accounts.inputToken), getAccountMeta("outputToken", accounts.outputToken), getAccountMeta("inputVault", accounts.inputVault), getAccountMeta("outputVault", accounts.outputVault), getAccountMeta("inputTokenProgram", accounts.inputTokenProgram), getAccountMeta("outputTokenProgram", accounts.outputTokenProgram)], data: getSwapExactOutInstructionDataEncoder().encode(args), programAddress });
478
+ }
479
+ function parseSwapExactOutInstruction(instruction) {
480
+ if (instruction.accounts.length < 8) {
481
+ throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 8 });
482
+ }
483
+ let accountIndex = 0;
484
+ const getNextAccount = () => {
485
+ const accountMeta = instruction.accounts[accountIndex];
486
+ accountIndex += 1;
487
+ return accountMeta;
488
+ };
489
+ return { programAddress: instruction.programAddress, accounts: { trader: getNextAccount(), pool: getNextAccount(), inputToken: getNextAccount(), outputToken: getNextAccount(), inputVault: getNextAccount(), outputVault: getNextAccount(), inputTokenProgram: getNextAccount(), outputTokenProgram: getNextAccount() }, data: getSwapExactOutInstructionDataDecoder().decode(instruction.data) };
490
+ }
491
+ var SYNC_POOL_DISCRIMINATOR = 10;
492
+ function getSyncPoolDiscriminatorBytes() {
493
+ return getU8Encoder().encode(SYNC_POOL_DISCRIMINATOR);
494
+ }
495
+ function getSyncPoolInstructionDataEncoder() {
496
+ return transformEncoder(getStructEncoder([["discriminator", getU8Encoder()]]), (value) => ({ ...value, discriminator: 10 }));
497
+ }
498
+ function getSyncPoolInstructionDataDecoder() {
499
+ return getStructDecoder([["discriminator", getPinaPodDiscriminatorDecoder(SYNC_POOL_DISCRIMINATOR, getU8Decoder())]]);
500
+ }
501
+ function getSyncPoolInstructionDataCodec() {
502
+ return combineCodec(getSyncPoolInstructionDataEncoder(), getSyncPoolInstructionDataDecoder());
503
+ }
504
+ function getSyncPoolInstruction(input, config) {
505
+ const programAddress = config?.programAddress ?? PINA_AMM_PROGRAM_ADDRESS;
506
+ const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
507
+ const originalAccounts = { pool: { value: input.pool ?? null, isSigner: false, isWritable: true }, vault0: { value: input.vault0 ?? null, isSigner: false, isWritable: false }, vault1: { value: input.vault1 ?? null, isSigner: false, isWritable: false }, tokenProgram0: { value: input.tokenProgram0 ?? null, isSigner: false, isWritable: false }, tokenProgram1: { value: input.tokenProgram1 ?? null, isSigner: false, isWritable: false } };
508
+ const accounts = originalAccounts;
509
+ return Object.freeze({ accounts: [getAccountMeta("pool", accounts.pool), getAccountMeta("vault0", accounts.vault0), getAccountMeta("vault1", accounts.vault1), getAccountMeta("tokenProgram0", accounts.tokenProgram0), getAccountMeta("tokenProgram1", accounts.tokenProgram1)], data: getSyncPoolInstructionDataEncoder().encode({}), programAddress });
510
+ }
511
+ function parseSyncPoolInstruction(instruction) {
512
+ if (instruction.accounts.length < 5) {
513
+ throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 5 });
514
+ }
515
+ let accountIndex = 0;
516
+ const getNextAccount = () => {
517
+ const accountMeta = instruction.accounts[accountIndex];
518
+ accountIndex += 1;
519
+ return accountMeta;
520
+ };
521
+ return { programAddress: instruction.programAddress, accounts: { pool: getNextAccount(), vault0: getNextAccount(), vault1: getNextAccount(), tokenProgram0: getNextAccount(), tokenProgram1: getNextAccount() }, data: getSyncPoolInstructionDataDecoder().decode(instruction.data) };
522
+ }
523
+ var UPDATE_CONFIG_DISCRIMINATOR = 1;
524
+ function getUpdateConfigDiscriminatorBytes() {
525
+ return getU8Encoder().encode(UPDATE_CONFIG_DISCRIMINATOR);
526
+ }
527
+ function getUpdateConfigInstructionDataEncoder() {
528
+ return transformEncoder(getStructEncoder([["discriminator", getU8Encoder()], ["newAuthority", getAddressEncoder()], ["tradeFeeRate", getU32Encoder()], ["protocolFeeRate", getU32Encoder()], ["creatorFeeRate", getU32Encoder()]]), (value) => ({ ...value, discriminator: 1 }));
529
+ }
530
+ function getUpdateConfigInstructionDataDecoder() {
531
+ return getStructDecoder([["discriminator", getPinaPodDiscriminatorDecoder(UPDATE_CONFIG_DISCRIMINATOR, getU8Decoder())], ["newAuthority", getAddressDecoder()], ["tradeFeeRate", getU32Decoder()], ["protocolFeeRate", getU32Decoder()], ["creatorFeeRate", getU32Decoder()]]);
532
+ }
533
+ function getUpdateConfigInstructionDataCodec() {
534
+ return combineCodec(getUpdateConfigInstructionDataEncoder(), getUpdateConfigInstructionDataDecoder());
535
+ }
536
+ function getUpdateConfigInstruction(input, config) {
537
+ const programAddress = config?.programAddress ?? PINA_AMM_PROGRAM_ADDRESS;
538
+ const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
539
+ const originalAccounts = { authority: { value: input.authority ?? null, isSigner: true, isWritable: false }, ammConfig: { value: input.ammConfig ?? null, isSigner: false, isWritable: true } };
540
+ const accounts = originalAccounts;
541
+ const args = { ...input };
542
+ return Object.freeze({ accounts: [getAccountMeta("authority", accounts.authority), getAccountMeta("ammConfig", accounts.ammConfig)], data: getUpdateConfigInstructionDataEncoder().encode(args), programAddress });
543
+ }
544
+ function parseUpdateConfigInstruction(instruction) {
545
+ if (instruction.accounts.length < 2) {
546
+ throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 2 });
547
+ }
548
+ let accountIndex = 0;
549
+ const getNextAccount = () => {
550
+ const accountMeta = instruction.accounts[accountIndex];
551
+ accountIndex += 1;
552
+ return accountMeta;
553
+ };
554
+ return { programAddress: instruction.programAddress, accounts: { authority: getNextAccount(), ammConfig: getNextAccount() }, data: getUpdateConfigInstructionDataDecoder().decode(instruction.data) };
555
+ }
556
+ var WITHDRAW_DISCRIMINATOR = 4;
557
+ function getWithdrawDiscriminatorBytes() {
558
+ return getU8Encoder().encode(WITHDRAW_DISCRIMINATOR);
559
+ }
560
+ function getWithdrawInstructionDataEncoder() {
561
+ return transformEncoder(getStructEncoder([["discriminator", getU8Encoder()], ["lpAmount", getU64Encoder()], ["minimumAmount0", getU64Encoder()], ["minimumAmount1", getU64Encoder()]]), (value) => ({ ...value, discriminator: 4 }));
562
+ }
563
+ function getWithdrawInstructionDataDecoder() {
564
+ return getStructDecoder([["discriminator", getPinaPodDiscriminatorDecoder(WITHDRAW_DISCRIMINATOR, getU8Decoder())], ["lpAmount", getU64Decoder()], ["minimumAmount0", getU64Decoder()], ["minimumAmount1", getU64Decoder()]]);
565
+ }
566
+ function getWithdrawInstructionDataCodec() {
567
+ return combineCodec(getWithdrawInstructionDataEncoder(), getWithdrawInstructionDataDecoder());
568
+ }
569
+ function getWithdrawInstruction(input, config) {
570
+ const programAddress = config?.programAddress ?? PINA_AMM_PROGRAM_ADDRESS;
571
+ const getAccountMeta = getAccountMetaFactory(programAddress, "programId");
572
+ const originalAccounts = { owner: { value: input.owner ?? null, isSigner: true, isWritable: false }, pool: { value: input.pool ?? null, isSigner: false, isWritable: true }, vault0: { value: input.vault0 ?? null, isSigner: false, isWritable: true }, vault1: { value: input.vault1 ?? null, isSigner: false, isWritable: true }, lpMint: { value: input.lpMint ?? null, isSigner: false, isWritable: true }, ownerToken0: { value: input.ownerToken0 ?? null, isSigner: false, isWritable: true }, ownerToken1: { value: input.ownerToken1 ?? null, isSigner: false, isWritable: true }, ownerLpToken: { value: input.ownerLpToken ?? null, isSigner: false, isWritable: true }, tokenProgram0: { value: input.tokenProgram0 ?? null, isSigner: false, isWritable: false }, tokenProgram1: { value: input.tokenProgram1 ?? null, isSigner: false, isWritable: false }, lpTokenProgram: { value: input.lpTokenProgram ?? null, isSigner: false, isWritable: false } };
573
+ const accounts = originalAccounts;
574
+ const args = { ...input };
575
+ if (!accounts.lpTokenProgram.value) {
576
+ accounts.lpTokenProgram.value = "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA";
577
+ }
578
+ return Object.freeze({ accounts: [getAccountMeta("owner", accounts.owner), getAccountMeta("pool", accounts.pool), getAccountMeta("vault0", accounts.vault0), getAccountMeta("vault1", accounts.vault1), getAccountMeta("lpMint", accounts.lpMint), getAccountMeta("ownerToken0", accounts.ownerToken0), getAccountMeta("ownerToken1", accounts.ownerToken1), getAccountMeta("ownerLpToken", accounts.ownerLpToken), getAccountMeta("tokenProgram0", accounts.tokenProgram0), getAccountMeta("tokenProgram1", accounts.tokenProgram1), getAccountMeta("lpTokenProgram", accounts.lpTokenProgram)], data: getWithdrawInstructionDataEncoder().encode(args), programAddress });
579
+ }
580
+ function parseWithdrawInstruction(instruction) {
581
+ if (instruction.accounts.length < 11) {
582
+ throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__INSUFFICIENT_ACCOUNT_METAS, { actualAccountMetas: instruction.accounts.length, expectedAccountMetas: 11 });
583
+ }
584
+ let accountIndex = 0;
585
+ const getNextAccount = () => {
586
+ const accountMeta = instruction.accounts[accountIndex];
587
+ accountIndex += 1;
588
+ return accountMeta;
589
+ };
590
+ return { programAddress: instruction.programAddress, accounts: { owner: getNextAccount(), pool: getNextAccount(), vault0: getNextAccount(), vault1: getNextAccount(), lpMint: getNextAccount(), ownerToken0: getNextAccount(), ownerToken1: getNextAccount(), ownerLpToken: getNextAccount(), tokenProgram0: getNextAccount(), tokenProgram1: getNextAccount(), lpTokenProgram: getNextAccount() }, data: getWithdrawInstructionDataDecoder().decode(instruction.data) };
591
+ }
592
+
593
+ // src/generated/programs/pinaAmm.ts
594
+ var PINA_AMM_PROGRAM_ADDRESS = "pAMMzVPRwtrxQs2CjLTUUpfCAp9XdvVmwwVhpAuCobi";
595
+ var PinaAmmAccount = /* @__PURE__ */ ((PinaAmmAccount2) => {
596
+ PinaAmmAccount2[PinaAmmAccount2["AmmConfig"] = 0] = "AmmConfig";
597
+ PinaAmmAccount2[PinaAmmAccount2["Pool"] = 1] = "Pool";
598
+ return PinaAmmAccount2;
599
+ })(PinaAmmAccount || {});
600
+ function identifyPinaAmmAccount(account) {
601
+ const data = "data" in account ? account.data : account;
602
+ if (containsBytes(data, getU8Encoder().encode(1), 0) && containsBytes(data, getU8Encoder().encode(0), 1)) {
603
+ return 0 /* AmmConfig */;
604
+ }
605
+ if (containsBytes(data, getU8Encoder().encode(2), 0) && containsBytes(data, getU8Encoder().encode(1), 1)) {
606
+ return 1 /* Pool */;
607
+ }
608
+ throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__FAILED_TO_IDENTIFY_ACCOUNT, { accountData: data, programName: "pinaAmm" });
609
+ }
610
+ var PinaAmmEvent = /* @__PURE__ */ ((PinaAmmEvent2) => {
611
+ PinaAmmEvent2[PinaAmmEvent2["PoolCreated"] = 0] = "PoolCreated";
612
+ PinaAmmEvent2[PinaAmmEvent2["Swapped"] = 1] = "Swapped";
613
+ PinaAmmEvent2[PinaAmmEvent2["LiquidityChanged"] = 2] = "LiquidityChanged";
614
+ PinaAmmEvent2[PinaAmmEvent2["FeesCollected"] = 3] = "FeesCollected";
615
+ PinaAmmEvent2[PinaAmmEvent2["PoolSynced"] = 4] = "PoolSynced";
616
+ PinaAmmEvent2[PinaAmmEvent2["PoolSyncedV0"] = 5] = "PoolSyncedV0";
617
+ PinaAmmEvent2[PinaAmmEvent2["ConfigCreated"] = 6] = "ConfigCreated";
618
+ PinaAmmEvent2[PinaAmmEvent2["ConfigUpdated"] = 7] = "ConfigUpdated";
619
+ PinaAmmEvent2[PinaAmmEvent2["PoolCreatorChanged"] = 8] = "PoolCreatorChanged";
620
+ return PinaAmmEvent2;
621
+ })(PinaAmmEvent || {});
622
+ function identifyPinaAmmEvent(event) {
623
+ const data = "data" in event ? event.data : event;
624
+ if (containsBytes(data, getU8Encoder().encode(1), 0) && containsBytes(data, getU8Encoder().encode(0), 1)) {
625
+ return 0 /* PoolCreated */;
626
+ }
627
+ if (containsBytes(data, getU8Encoder().encode(2), 0) && containsBytes(data, getU8Encoder().encode(0), 1)) {
628
+ return 1 /* Swapped */;
629
+ }
630
+ if (containsBytes(data, getU8Encoder().encode(3), 0) && containsBytes(data, getU8Encoder().encode(0), 1)) {
631
+ return 2 /* LiquidityChanged */;
632
+ }
633
+ if (containsBytes(data, getU8Encoder().encode(4), 0) && containsBytes(data, getU8Encoder().encode(0), 1)) {
634
+ return 3 /* FeesCollected */;
635
+ }
636
+ if (containsBytes(data, getU8Encoder().encode(5), 0) && containsBytes(data, getU8Encoder().encode(1), 1)) {
637
+ return 4 /* PoolSynced */;
638
+ }
639
+ if (containsBytes(data, getU8Encoder().encode(5), 0) && containsBytes(data, getU8Encoder().encode(0), 1)) {
640
+ return 5 /* PoolSyncedV0 */;
641
+ }
642
+ if (containsBytes(data, getU8Encoder().encode(8), 0) && containsBytes(data, getU8Encoder().encode(0), 1)) {
643
+ return 6 /* ConfigCreated */;
644
+ }
645
+ if (containsBytes(data, getU8Encoder().encode(6), 0) && containsBytes(data, getU8Encoder().encode(0), 1)) {
646
+ return 7 /* ConfigUpdated */;
647
+ }
648
+ if (containsBytes(data, getU8Encoder().encode(7), 0) && containsBytes(data, getU8Encoder().encode(0), 1)) {
649
+ return 8 /* PoolCreatorChanged */;
650
+ }
651
+ throw new Error("The provided event could not be identified as a pinaAmm event.");
652
+ }
653
+ var PinaAmmInstruction = /* @__PURE__ */ ((PinaAmmInstruction2) => {
654
+ PinaAmmInstruction2[PinaAmmInstruction2["CreateConfig"] = 0] = "CreateConfig";
655
+ PinaAmmInstruction2[PinaAmmInstruction2["UpdateConfig"] = 1] = "UpdateConfig";
656
+ PinaAmmInstruction2[PinaAmmInstruction2["CreatePool"] = 2] = "CreatePool";
657
+ PinaAmmInstruction2[PinaAmmInstruction2["Deposit"] = 3] = "Deposit";
658
+ PinaAmmInstruction2[PinaAmmInstruction2["Withdraw"] = 4] = "Withdraw";
659
+ PinaAmmInstruction2[PinaAmmInstruction2["SwapExactIn"] = 5] = "SwapExactIn";
660
+ PinaAmmInstruction2[PinaAmmInstruction2["SwapExactOut"] = 6] = "SwapExactOut";
661
+ PinaAmmInstruction2[PinaAmmInstruction2["CollectProtocolFees"] = 7] = "CollectProtocolFees";
662
+ PinaAmmInstruction2[PinaAmmInstruction2["CollectCreatorFees"] = 8] = "CollectCreatorFees";
663
+ PinaAmmInstruction2[PinaAmmInstruction2["SetPoolCreator"] = 9] = "SetPoolCreator";
664
+ PinaAmmInstruction2[PinaAmmInstruction2["SyncPool"] = 10] = "SyncPool";
665
+ return PinaAmmInstruction2;
666
+ })(PinaAmmInstruction || {});
667
+ function identifyPinaAmmInstruction(instruction) {
668
+ const data = "data" in instruction ? instruction.data : instruction;
669
+ if (containsBytes(data, getU8Encoder().encode(0), 0)) {
670
+ return 0 /* CreateConfig */;
671
+ }
672
+ if (containsBytes(data, getU8Encoder().encode(1), 0)) {
673
+ return 1 /* UpdateConfig */;
674
+ }
675
+ if (containsBytes(data, getU8Encoder().encode(2), 0)) {
676
+ return 2 /* CreatePool */;
677
+ }
678
+ if (containsBytes(data, getU8Encoder().encode(3), 0)) {
679
+ return 3 /* Deposit */;
680
+ }
681
+ if (containsBytes(data, getU8Encoder().encode(4), 0)) {
682
+ return 4 /* Withdraw */;
683
+ }
684
+ if (containsBytes(data, getU8Encoder().encode(5), 0)) {
685
+ return 5 /* SwapExactIn */;
686
+ }
687
+ if (containsBytes(data, getU8Encoder().encode(6), 0)) {
688
+ return 6 /* SwapExactOut */;
689
+ }
690
+ if (containsBytes(data, getU8Encoder().encode(7), 0)) {
691
+ return 7 /* CollectProtocolFees */;
692
+ }
693
+ if (containsBytes(data, getU8Encoder().encode(8), 0)) {
694
+ return 8 /* CollectCreatorFees */;
695
+ }
696
+ if (containsBytes(data, getU8Encoder().encode(9), 0)) {
697
+ return 9 /* SetPoolCreator */;
698
+ }
699
+ if (containsBytes(data, getU8Encoder().encode(10), 0)) {
700
+ return 10 /* SyncPool */;
701
+ }
702
+ throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__FAILED_TO_IDENTIFY_INSTRUCTION, { instructionData: data, programName: "pinaAmm" });
703
+ }
704
+ function parsePinaAmmInstruction(instruction) {
705
+ const instructionType = identifyPinaAmmInstruction(instruction);
706
+ switch (instructionType) {
707
+ case 0 /* CreateConfig */: {
708
+ assertIsInstructionWithAccounts(instruction);
709
+ return { instructionType: 0 /* CreateConfig */, ...parseCreateConfigInstruction(instruction) };
710
+ }
711
+ case 1 /* UpdateConfig */: {
712
+ assertIsInstructionWithAccounts(instruction);
713
+ return { instructionType: 1 /* UpdateConfig */, ...parseUpdateConfigInstruction(instruction) };
714
+ }
715
+ case 2 /* CreatePool */: {
716
+ assertIsInstructionWithAccounts(instruction);
717
+ return { instructionType: 2 /* CreatePool */, ...parseCreatePoolInstruction(instruction) };
718
+ }
719
+ case 3 /* Deposit */: {
720
+ assertIsInstructionWithAccounts(instruction);
721
+ return { instructionType: 3 /* Deposit */, ...parseDepositInstruction(instruction) };
722
+ }
723
+ case 4 /* Withdraw */: {
724
+ assertIsInstructionWithAccounts(instruction);
725
+ return { instructionType: 4 /* Withdraw */, ...parseWithdrawInstruction(instruction) };
726
+ }
727
+ case 5 /* SwapExactIn */: {
728
+ assertIsInstructionWithAccounts(instruction);
729
+ return { instructionType: 5 /* SwapExactIn */, ...parseSwapExactInInstruction(instruction) };
730
+ }
731
+ case 6 /* SwapExactOut */: {
732
+ assertIsInstructionWithAccounts(instruction);
733
+ return { instructionType: 6 /* SwapExactOut */, ...parseSwapExactOutInstruction(instruction) };
734
+ }
735
+ case 7 /* CollectProtocolFees */: {
736
+ assertIsInstructionWithAccounts(instruction);
737
+ return { instructionType: 7 /* CollectProtocolFees */, ...parseCollectProtocolFeesInstruction(instruction) };
738
+ }
739
+ case 8 /* CollectCreatorFees */: {
740
+ assertIsInstructionWithAccounts(instruction);
741
+ return { instructionType: 8 /* CollectCreatorFees */, ...parseCollectCreatorFeesInstruction(instruction) };
742
+ }
743
+ case 9 /* SetPoolCreator */: {
744
+ assertIsInstructionWithAccounts(instruction);
745
+ return { instructionType: 9 /* SetPoolCreator */, ...parseSetPoolCreatorInstruction(instruction) };
746
+ }
747
+ case 10 /* SyncPool */: {
748
+ assertIsInstructionWithAccounts(instruction);
749
+ return { instructionType: 10 /* SyncPool */, ...parseSyncPoolInstruction(instruction) };
750
+ }
751
+ default:
752
+ throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__UNRECOGNIZED_INSTRUCTION_TYPE, { instructionType, programName: "pinaAmm" });
753
+ }
754
+ }
755
+ function pinaAmmProgram() {
756
+ return (client) => {
757
+ return extendClient(client, { pinaAmm: { accounts: { ammConfig: addSelfFetchFunctions(client, getAmmConfigCodec()), pool: addSelfFetchFunctions(client, getPoolCodec()) }, instructions: {
758
+ migrate: (input) => addSelfPlanAndSendFunctions(client, getMigrateInstruction(input)),
759
+ createConfig: (input) => addSelfPlanAndSendFunctions(client, getCreateConfigInstruction(input)),
760
+ updateConfig: (input) => addSelfPlanAndSendFunctions(client, getUpdateConfigInstruction(input)),
761
+ createPool: (input) => addSelfPlanAndSendFunctions(client, getCreatePoolInstructionAsync(input)),
762
+ deposit: (input) => addSelfPlanAndSendFunctions(client, getDepositInstruction(input)),
763
+ withdraw: (input) => addSelfPlanAndSendFunctions(client, getWithdrawInstruction(input)),
764
+ swapExactIn: (input) => addSelfPlanAndSendFunctions(client, getSwapExactInInstruction(input)),
765
+ swapExactOut: (input) => addSelfPlanAndSendFunctions(client, getSwapExactOutInstruction(input)),
766
+ collectProtocolFees: (input) => addSelfPlanAndSendFunctions(client, getCollectProtocolFeesInstruction(input)),
767
+ collectCreatorFees: (input) => addSelfPlanAndSendFunctions(client, getCollectCreatorFeesInstruction(input)),
768
+ setPoolCreator: (input) => addSelfPlanAndSendFunctions(client, getSetPoolCreatorInstruction(input)),
769
+ syncPool: (input) => addSelfPlanAndSendFunctions(client, getSyncPoolInstruction(input))
770
+ }, pdas: { ammConfig: findAmmConfigPda, pool: findPoolPda, poolVault: findPoolVaultPda, poolLpMint: findPoolLpMintPda }, identifyAccount: identifyPinaAmmAccount, identifyInstruction: identifyPinaAmmInstruction, parseInstruction: parsePinaAmmInstruction } });
771
+ };
772
+ }
773
+
774
+ // src/generated/errors/pinaAmm.ts
775
+ var PINA_AMM_ERROR__INVALID_FEE_RATES = 0;
776
+ var PINA_AMM_ERROR__UNAUTHORIZED = 1;
777
+ var PINA_AMM_ERROR__INVALID_PROGRAM_DATA = 2;
778
+ var PINA_AMM_ERROR__INVALID_MINT_ORDER = 3;
779
+ var PINA_AMM_ERROR__UNSUPPORTED_MINT = 4;
780
+ var PINA_AMM_ERROR__POOL_ACCOUNT_MISMATCH = 5;
781
+ var PINA_AMM_ERROR__INVALID_CREATOR_FEE_MODE = 6;
782
+ var PINA_AMM_ERROR__INSUFFICIENT_INITIAL_LIQUIDITY = 7;
783
+ var PINA_AMM_ERROR__ZERO_AMOUNT = 8;
784
+ var PINA_AMM_ERROR__SLIPPAGE_EXCEEDED = 9;
785
+ var PINA_AMM_ERROR__INSUFFICIENT_LIQUIDITY = 10;
786
+ var PINA_AMM_ERROR__MATH_OVERFLOW = 11;
787
+ var PINA_AMM_ERROR__INVARIANT_VIOLATION = 12;
788
+ var PINA_AMM_ERROR__VAULT_ACCOUNTING_MISMATCH = 13;
789
+ var PINA_AMM_ERROR__POOL_CREATOR_NOT_AUTHORIZED = 14;
790
+ var PINA_AMM_ERROR__DEFAULT_CREATOR = 15;
791
+ var pinaAmmErrorMessages;
792
+ if (process.env["NODE_ENV"] !== "production") {
793
+ pinaAmmErrorMessages = { [PINA_AMM_ERROR__DEFAULT_CREATOR]: `The pool creator may not be the default address, which can never sign or collect.`, [PINA_AMM_ERROR__INSUFFICIENT_INITIAL_LIQUIDITY]: `The initial deposit must mint more LP than the permanently locked minimum.`, [PINA_AMM_ERROR__INSUFFICIENT_LIQUIDITY]: `The pool cannot pay this amount from its reserves.`, [PINA_AMM_ERROR__INVALID_CREATOR_FEE_MODE]: `The creator fee mode must be 0 (input token), 1 (token 0), or 2 (token 1).`, [PINA_AMM_ERROR__INVALID_FEE_RATES]: `Fee rates are out of range: trade plus creator fee above 10% or protocol share above 100%.`, [PINA_AMM_ERROR__INVALID_MINT_ORDER]: `Pool mints must be distinct and passed in ascending byte order.`, [PINA_AMM_ERROR__INVALID_PROGRAM_DATA]: `The program-data account is not this program's, or the program is not upgradeable.`, [PINA_AMM_ERROR__INVARIANT_VIOLATION]: `The trade would decrease the pool's constant product.`, [PINA_AMM_ERROR__MATH_OVERFLOW]: `An intermediate value overflowed or did not fit its type.`, [PINA_AMM_ERROR__POOL_ACCOUNT_MISMATCH]: `A vault, LP mint, or fee tier account does not belong to this pool.`, [PINA_AMM_ERROR__POOL_CREATOR_NOT_AUTHORIZED]: `This fee tier only lets its pool-creator authority create pools.`, [PINA_AMM_ERROR__SLIPPAGE_EXCEEDED]: `The result is worse than the caller's slippage limit.`, [PINA_AMM_ERROR__UNAUTHORIZED]: `The signer is not the authority this instruction requires.`, [PINA_AMM_ERROR__UNSUPPORTED_MINT]: `The mint's token program or Token-2022 extensions are not supported.`, [PINA_AMM_ERROR__VAULT_ACCOUNTING_MISMATCH]: `A vault holds less than the fees accrued against it.`, [PINA_AMM_ERROR__ZERO_AMOUNT]: `An amount is zero or the trade rounds down to nothing.` };
794
+ }
795
+ function getPinaAmmErrorMessage(code) {
796
+ if (process.env["NODE_ENV"] !== "production") {
797
+ return pinaAmmErrorMessages[code];
798
+ }
799
+ return "Error message not available in production bundles.";
800
+ }
801
+ function isPinaAmmError(error, transactionMessage, code) {
802
+ return isProgramError(error, transactionMessage, PINA_AMM_PROGRAM_ADDRESS, code);
803
+ }
804
+ var POOL_CREATED_EVENT_DISCRIMINATOR = 1;
805
+ function getPoolCreatedEventDiscriminatorBytes() {
806
+ return getU8Encoder().encode(POOL_CREATED_EVENT_DISCRIMINATOR);
807
+ }
808
+ var POOL_CREATED_EVENT_DISCRIMINATOR2 = 0;
809
+ function getPoolCreatedEventDiscriminator2Bytes() {
810
+ return getU8Encoder().encode(POOL_CREATED_EVENT_DISCRIMINATOR2);
811
+ }
812
+ function getPoolCreatedEventEncoder() {
813
+ 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 }));
814
+ }
815
+ function getPoolCreatedEventDecoder() {
816
+ 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()]]);
817
+ }
818
+ function getPoolCreatedEventCodec() {
819
+ return combineCodec(getPoolCreatedEventEncoder(), getPoolCreatedEventDecoder());
820
+ }
821
+ function parsePoolCreatedEvent(data) {
822
+ if (containsBytes(data, getU8Encoder().encode(POOL_CREATED_EVENT_DISCRIMINATOR), 0) && containsBytes(data, getU8Encoder().encode(POOL_CREATED_EVENT_DISCRIMINATOR2), 1)) {
823
+ return getPoolCreatedEventDecoder().decode(data);
824
+ }
825
+ throw new Error('The provided data does not match the "PoolCreatedEvent" event discriminators.');
826
+ }
827
+ var SWAPPED_EVENT_DISCRIMINATOR = 2;
828
+ function getSwappedEventDiscriminatorBytes() {
829
+ return getU8Encoder().encode(SWAPPED_EVENT_DISCRIMINATOR);
830
+ }
831
+ var SWAPPED_EVENT_DISCRIMINATOR2 = 0;
832
+ function getSwappedEventDiscriminator2Bytes() {
833
+ return getU8Encoder().encode(SWAPPED_EVENT_DISCRIMINATOR2);
834
+ }
835
+ function getSwappedEventEncoder() {
836
+ 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 }));
837
+ }
838
+ function getSwappedEventDecoder() {
839
+ 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()]]);
840
+ }
841
+ function getSwappedEventCodec() {
842
+ return combineCodec(getSwappedEventEncoder(), getSwappedEventDecoder());
843
+ }
844
+ function parseSwappedEvent(data) {
845
+ if (containsBytes(data, getU8Encoder().encode(SWAPPED_EVENT_DISCRIMINATOR), 0) && containsBytes(data, getU8Encoder().encode(SWAPPED_EVENT_DISCRIMINATOR2), 1)) {
846
+ return getSwappedEventDecoder().decode(data);
847
+ }
848
+ throw new Error('The provided data does not match the "SwappedEvent" event discriminators.');
849
+ }
850
+ var LIQUIDITY_CHANGED_EVENT_DISCRIMINATOR = 3;
851
+ function getLiquidityChangedEventDiscriminatorBytes() {
852
+ return getU8Encoder().encode(LIQUIDITY_CHANGED_EVENT_DISCRIMINATOR);
853
+ }
854
+ var LIQUIDITY_CHANGED_EVENT_DISCRIMINATOR2 = 0;
855
+ function getLiquidityChangedEventDiscriminator2Bytes() {
856
+ return getU8Encoder().encode(LIQUIDITY_CHANGED_EVENT_DISCRIMINATOR2);
857
+ }
858
+ function getLiquidityChangedEventEncoder() {
859
+ 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 }));
860
+ }
861
+ function getLiquidityChangedEventDecoder() {
862
+ 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()]]);
863
+ }
864
+ function getLiquidityChangedEventCodec() {
865
+ return combineCodec(getLiquidityChangedEventEncoder(), getLiquidityChangedEventDecoder());
866
+ }
867
+ function parseLiquidityChangedEvent(data) {
868
+ if (containsBytes(data, getU8Encoder().encode(LIQUIDITY_CHANGED_EVENT_DISCRIMINATOR), 0) && containsBytes(data, getU8Encoder().encode(LIQUIDITY_CHANGED_EVENT_DISCRIMINATOR2), 1)) {
869
+ return getLiquidityChangedEventDecoder().decode(data);
870
+ }
871
+ throw new Error('The provided data does not match the "LiquidityChangedEvent" event discriminators.');
872
+ }
873
+ var FEES_COLLECTED_EVENT_DISCRIMINATOR = 4;
874
+ function getFeesCollectedEventDiscriminatorBytes() {
875
+ return getU8Encoder().encode(FEES_COLLECTED_EVENT_DISCRIMINATOR);
876
+ }
877
+ var FEES_COLLECTED_EVENT_DISCRIMINATOR2 = 0;
878
+ function getFeesCollectedEventDiscriminator2Bytes() {
879
+ return getU8Encoder().encode(FEES_COLLECTED_EVENT_DISCRIMINATOR2);
880
+ }
881
+ function getFeesCollectedEventEncoder() {
882
+ return transformEncoder(getStructEncoder([["discriminator", getU8Encoder()], ["migrationVersion", getU8Encoder()], ["pool", getAddressEncoder()], ["collector", getAddressEncoder()], ["isProtocol", getU8Encoder()], ["amount0", getU64Encoder()], ["amount1", getU64Encoder()]]), (value) => ({ ...value, discriminator: 4, migrationVersion: 0 }));
883
+ }
884
+ function getFeesCollectedEventDecoder() {
885
+ return getStructDecoder([["discriminator", getPinaPodDiscriminatorDecoder(FEES_COLLECTED_EVENT_DISCRIMINATOR, getU8Decoder())], ["migrationVersion", getPinaPodMigrationVersionDecoder(0, getU8Decoder())], ["pool", getAddressDecoder()], ["collector", getAddressDecoder()], ["isProtocol", getU8Decoder()], ["amount0", getU64Decoder()], ["amount1", getU64Decoder()]]);
886
+ }
887
+ function getFeesCollectedEventCodec() {
888
+ return combineCodec(getFeesCollectedEventEncoder(), getFeesCollectedEventDecoder());
889
+ }
890
+ function parseFeesCollectedEvent(data) {
891
+ if (containsBytes(data, getU8Encoder().encode(FEES_COLLECTED_EVENT_DISCRIMINATOR), 0) && containsBytes(data, getU8Encoder().encode(FEES_COLLECTED_EVENT_DISCRIMINATOR2), 1)) {
892
+ return getFeesCollectedEventDecoder().decode(data);
893
+ }
894
+ throw new Error('The provided data does not match the "FeesCollectedEvent" event discriminators.');
895
+ }
896
+ var POOL_SYNCED_EVENT_DISCRIMINATOR = 5;
897
+ function getPoolSyncedEventDiscriminatorBytes() {
898
+ return getU8Encoder().encode(POOL_SYNCED_EVENT_DISCRIMINATOR);
899
+ }
900
+ var POOL_SYNCED_EVENT_DISCRIMINATOR2 = 1;
901
+ function getPoolSyncedEventDiscriminator2Bytes() {
902
+ return getU8Encoder().encode(POOL_SYNCED_EVENT_DISCRIMINATOR2);
903
+ }
904
+ function getPoolSyncedEventEncoder() {
905
+ return transformEncoder(getStructEncoder([["discriminator", getU8Encoder()], ["migrationVersion", getU8Encoder()], ["pool", getAddressEncoder()], ["reserve0", getU64Encoder()], ["reserve1", getU64Encoder()], ["price0CumulativeLast", getU128Encoder()], ["price0CumulativeHighLast", getU128Encoder()], ["lastUpdateTimestamp", getU64Encoder()]]), (value) => ({ ...value, discriminator: 5, migrationVersion: 1 }));
906
+ }
907
+ function getPoolSyncedEventDecoder() {
908
+ return getStructDecoder([["discriminator", getPinaPodDiscriminatorDecoder(POOL_SYNCED_EVENT_DISCRIMINATOR, getU8Decoder())], ["migrationVersion", getPinaPodMigrationVersionDecoder(1, getU8Decoder())], ["pool", getAddressDecoder()], ["reserve0", getU64Decoder()], ["reserve1", getU64Decoder()], ["price0CumulativeLast", getU128Decoder()], ["price0CumulativeHighLast", getU128Decoder()], ["lastUpdateTimestamp", getU64Decoder()]]);
909
+ }
910
+ function getPoolSyncedEventCodec() {
911
+ return combineCodec(getPoolSyncedEventEncoder(), getPoolSyncedEventDecoder());
912
+ }
913
+ function parsePoolSyncedEvent(data) {
914
+ if (containsBytes(data, getU8Encoder().encode(POOL_SYNCED_EVENT_DISCRIMINATOR), 0) && containsBytes(data, getU8Encoder().encode(POOL_SYNCED_EVENT_DISCRIMINATOR2), 1)) {
915
+ return getPoolSyncedEventDecoder().decode(data);
916
+ }
917
+ throw new Error('The provided data does not match the "PoolSyncedEvent" event discriminators.');
918
+ }
919
+ var POOL_SYNCED_V0_EVENT_DISCRIMINATOR = 5;
920
+ function getPoolSyncedV0EventDiscriminatorBytes() {
921
+ return getU8Encoder().encode(POOL_SYNCED_V0_EVENT_DISCRIMINATOR);
922
+ }
923
+ var POOL_SYNCED_V0_EVENT_DISCRIMINATOR2 = 0;
924
+ function getPoolSyncedV0EventDiscriminator2Bytes() {
925
+ return getU8Encoder().encode(POOL_SYNCED_V0_EVENT_DISCRIMINATOR2);
926
+ }
927
+ function getPoolSyncedV0EventEncoder() {
928
+ return transformEncoder(getStructEncoder([["discriminator", getU8Encoder()], ["migrationVersion", getU8Encoder()], ["pool", getAddressEncoder()], ["reserve0", getU64Encoder()], ["reserve1", getU64Encoder()], ["price0CumulativeLast", getU128Encoder()], ["lastUpdateTimestamp", getU64Encoder()]]), (value) => ({ ...value, discriminator: 5, migrationVersion: 0 }));
929
+ }
930
+ function getPoolSyncedV0EventDecoder() {
931
+ return getStructDecoder([["discriminator", getPinaPodDiscriminatorDecoder(POOL_SYNCED_V0_EVENT_DISCRIMINATOR, getU8Decoder())], ["migrationVersion", getPinaPodMigrationVersionDecoder(0, getU8Decoder())], ["pool", getAddressDecoder()], ["reserve0", getU64Decoder()], ["reserve1", getU64Decoder()], ["price0CumulativeLast", getU128Decoder()], ["lastUpdateTimestamp", getU64Decoder()]]);
932
+ }
933
+ function getPoolSyncedV0EventCodec() {
934
+ return combineCodec(getPoolSyncedV0EventEncoder(), getPoolSyncedV0EventDecoder());
935
+ }
936
+ function parsePoolSyncedV0Event(data) {
937
+ if (containsBytes(data, getU8Encoder().encode(POOL_SYNCED_V0_EVENT_DISCRIMINATOR), 0) && containsBytes(data, getU8Encoder().encode(POOL_SYNCED_V0_EVENT_DISCRIMINATOR2), 1)) {
938
+ return getPoolSyncedV0EventDecoder().decode(data);
939
+ }
940
+ throw new Error('The provided data does not match the "PoolSyncedV0Event" event discriminators.');
941
+ }
942
+ var CONFIG_CREATED_EVENT_DISCRIMINATOR = 8;
943
+ function getConfigCreatedEventDiscriminatorBytes() {
944
+ return getU8Encoder().encode(CONFIG_CREATED_EVENT_DISCRIMINATOR);
945
+ }
946
+ var CONFIG_CREATED_EVENT_DISCRIMINATOR2 = 0;
947
+ function getConfigCreatedEventDiscriminator2Bytes() {
948
+ return getU8Encoder().encode(CONFIG_CREATED_EVENT_DISCRIMINATOR2);
949
+ }
950
+ function getConfigCreatedEventEncoder() {
951
+ return transformEncoder(getStructEncoder([["discriminator", getU8Encoder()], ["migrationVersion", getU8Encoder()], ["ammConfig", getAddressEncoder()], ["authority", getAddressEncoder()], ["poolCreatorAuthority", getAddressEncoder()], ["tradeFeeRate", getU32Encoder()], ["protocolFeeRate", getU32Encoder()], ["creatorFeeRate", getU32Encoder()], ["index", getU16Encoder()]]), (value) => ({ ...value, discriminator: 8, migrationVersion: 0 }));
952
+ }
953
+ function getConfigCreatedEventDecoder() {
954
+ return getStructDecoder([["discriminator", getPinaPodDiscriminatorDecoder(CONFIG_CREATED_EVENT_DISCRIMINATOR, getU8Decoder())], ["migrationVersion", getPinaPodMigrationVersionDecoder(0, getU8Decoder())], ["ammConfig", getAddressDecoder()], ["authority", getAddressDecoder()], ["poolCreatorAuthority", getAddressDecoder()], ["tradeFeeRate", getU32Decoder()], ["protocolFeeRate", getU32Decoder()], ["creatorFeeRate", getU32Decoder()], ["index", getU16Decoder()]]);
955
+ }
956
+ function getConfigCreatedEventCodec() {
957
+ return combineCodec(getConfigCreatedEventEncoder(), getConfigCreatedEventDecoder());
958
+ }
959
+ function parseConfigCreatedEvent(data) {
960
+ if (containsBytes(data, getU8Encoder().encode(CONFIG_CREATED_EVENT_DISCRIMINATOR), 0) && containsBytes(data, getU8Encoder().encode(CONFIG_CREATED_EVENT_DISCRIMINATOR2), 1)) {
961
+ return getConfigCreatedEventDecoder().decode(data);
962
+ }
963
+ throw new Error('The provided data does not match the "ConfigCreatedEvent" event discriminators.');
964
+ }
965
+ var CONFIG_UPDATED_EVENT_DISCRIMINATOR = 6;
966
+ function getConfigUpdatedEventDiscriminatorBytes() {
967
+ return getU8Encoder().encode(CONFIG_UPDATED_EVENT_DISCRIMINATOR);
968
+ }
969
+ var CONFIG_UPDATED_EVENT_DISCRIMINATOR2 = 0;
970
+ function getConfigUpdatedEventDiscriminator2Bytes() {
971
+ return getU8Encoder().encode(CONFIG_UPDATED_EVENT_DISCRIMINATOR2);
972
+ }
973
+ function getConfigUpdatedEventEncoder() {
974
+ return transformEncoder(getStructEncoder([["discriminator", getU8Encoder()], ["migrationVersion", getU8Encoder()], ["ammConfig", getAddressEncoder()], ["newAuthority", getAddressEncoder()], ["tradeFeeRate", getU32Encoder()], ["protocolFeeRate", getU32Encoder()], ["creatorFeeRate", getU32Encoder()]]), (value) => ({ ...value, discriminator: 6, migrationVersion: 0 }));
975
+ }
976
+ function getConfigUpdatedEventDecoder() {
977
+ return getStructDecoder([["discriminator", getPinaPodDiscriminatorDecoder(CONFIG_UPDATED_EVENT_DISCRIMINATOR, getU8Decoder())], ["migrationVersion", getPinaPodMigrationVersionDecoder(0, getU8Decoder())], ["ammConfig", getAddressDecoder()], ["newAuthority", getAddressDecoder()], ["tradeFeeRate", getU32Decoder()], ["protocolFeeRate", getU32Decoder()], ["creatorFeeRate", getU32Decoder()]]);
978
+ }
979
+ function getConfigUpdatedEventCodec() {
980
+ return combineCodec(getConfigUpdatedEventEncoder(), getConfigUpdatedEventDecoder());
981
+ }
982
+ function parseConfigUpdatedEvent(data) {
983
+ if (containsBytes(data, getU8Encoder().encode(CONFIG_UPDATED_EVENT_DISCRIMINATOR), 0) && containsBytes(data, getU8Encoder().encode(CONFIG_UPDATED_EVENT_DISCRIMINATOR2), 1)) {
984
+ return getConfigUpdatedEventDecoder().decode(data);
985
+ }
986
+ throw new Error('The provided data does not match the "ConfigUpdatedEvent" event discriminators.');
987
+ }
988
+ var POOL_CREATOR_CHANGED_EVENT_DISCRIMINATOR = 7;
989
+ function getPoolCreatorChangedEventDiscriminatorBytes() {
990
+ return getU8Encoder().encode(POOL_CREATOR_CHANGED_EVENT_DISCRIMINATOR);
991
+ }
992
+ var POOL_CREATOR_CHANGED_EVENT_DISCRIMINATOR2 = 0;
993
+ function getPoolCreatorChangedEventDiscriminator2Bytes() {
994
+ return getU8Encoder().encode(POOL_CREATOR_CHANGED_EVENT_DISCRIMINATOR2);
995
+ }
996
+ function getPoolCreatorChangedEventEncoder() {
997
+ return transformEncoder(getStructEncoder([["discriminator", getU8Encoder()], ["migrationVersion", getU8Encoder()], ["pool", getAddressEncoder()], ["previousCreator", getAddressEncoder()], ["newCreator", getAddressEncoder()]]), (value) => ({ ...value, discriminator: 7, migrationVersion: 0 }));
998
+ }
999
+ function getPoolCreatorChangedEventDecoder() {
1000
+ return getStructDecoder([["discriminator", getPinaPodDiscriminatorDecoder(POOL_CREATOR_CHANGED_EVENT_DISCRIMINATOR, getU8Decoder())], ["migrationVersion", getPinaPodMigrationVersionDecoder(0, getU8Decoder())], ["pool", getAddressDecoder()], ["previousCreator", getAddressDecoder()], ["newCreator", getAddressDecoder()]]);
1001
+ }
1002
+ function getPoolCreatorChangedEventCodec() {
1003
+ return combineCodec(getPoolCreatorChangedEventEncoder(), getPoolCreatorChangedEventDecoder());
1004
+ }
1005
+ function parsePoolCreatorChangedEvent(data) {
1006
+ if (containsBytes(data, getU8Encoder().encode(POOL_CREATOR_CHANGED_EVENT_DISCRIMINATOR), 0) && containsBytes(data, getU8Encoder().encode(POOL_CREATOR_CHANGED_EVENT_DISCRIMINATOR2), 1)) {
1007
+ return getPoolCreatorChangedEventDecoder().decode(data);
1008
+ }
1009
+ throw new Error('The provided data does not match the "PoolCreatorChangedEvent" event discriminators.');
1010
+ }
1011
+
1012
+ // src/generated/events/logs.ts
1013
+ function decodePoolCreatedEvent(data) {
1014
+ const bytes = data instanceof Uint8Array ? data : new Uint8Array(data);
1015
+ const discriminatorBytes = getPoolCreatedEventDiscriminatorBytes();
1016
+ if (bytes.length < 2) {
1017
+ throw new RangeError(
1018
+ `the provided data is too short for the "PoolCreatedEvent" event envelope`
1019
+ );
1020
+ }
1021
+ for (let index = 0; index < 1; index += 1) {
1022
+ if (bytes[index] !== discriminatorBytes[index]) {
1023
+ throw new RangeError(
1024
+ 'the provided data does not match the "PoolCreatedEvent" event discriminator.'
1025
+ );
1026
+ }
1027
+ }
1028
+ const sourceVersion = bytes[1];
1029
+ if (sourceVersion !== 0) {
1030
+ throw new RangeError(
1031
+ `event migration version mismatch: expected 0, received ${sourceVersion} (decode it with the event for that version, or regenerate this client)`
1032
+ );
1033
+ }
1034
+ return { name: "poolCreated", data: getPoolCreatedEventDecoder().decode(bytes) };
1035
+ }
1036
+ function parsePoolCreatedEventFromLog(log) {
1037
+ const prefix = "Program data: ";
1038
+ if (!log.startsWith(prefix)) {
1039
+ return null;
1040
+ }
1041
+ const bytes = getBase64Encoder().encode(log.slice(prefix.length));
1042
+ if (bytes.length < 2) {
1043
+ return null;
1044
+ }
1045
+ const discriminatorBytes = getPoolCreatedEventDiscriminatorBytes();
1046
+ for (let index = 0; index < 1; index += 1) {
1047
+ if (bytes[index] !== discriminatorBytes[index]) {
1048
+ return null;
1049
+ }
1050
+ }
1051
+ if (bytes[1] !== 0) {
1052
+ return null;
1053
+ }
1054
+ return decodePoolCreatedEvent(bytes);
1055
+ }
1056
+ function decodeSwappedEvent(data) {
1057
+ const bytes = data instanceof Uint8Array ? data : new Uint8Array(data);
1058
+ const discriminatorBytes = getSwappedEventDiscriminatorBytes();
1059
+ if (bytes.length < 2) {
1060
+ throw new RangeError(
1061
+ `the provided data is too short for the "SwappedEvent" event envelope`
1062
+ );
1063
+ }
1064
+ for (let index = 0; index < 1; index += 1) {
1065
+ if (bytes[index] !== discriminatorBytes[index]) {
1066
+ throw new RangeError(
1067
+ 'the provided data does not match the "SwappedEvent" event discriminator.'
1068
+ );
1069
+ }
1070
+ }
1071
+ const sourceVersion = bytes[1];
1072
+ if (sourceVersion !== 0) {
1073
+ throw new RangeError(
1074
+ `event migration version mismatch: expected 0, received ${sourceVersion} (decode it with the event for that version, or regenerate this client)`
1075
+ );
1076
+ }
1077
+ return { name: "swapped", data: getSwappedEventDecoder().decode(bytes) };
1078
+ }
1079
+ function parseSwappedEventFromLog(log) {
1080
+ const prefix = "Program data: ";
1081
+ if (!log.startsWith(prefix)) {
1082
+ return null;
1083
+ }
1084
+ const bytes = getBase64Encoder().encode(log.slice(prefix.length));
1085
+ if (bytes.length < 2) {
1086
+ return null;
1087
+ }
1088
+ const discriminatorBytes = getSwappedEventDiscriminatorBytes();
1089
+ for (let index = 0; index < 1; index += 1) {
1090
+ if (bytes[index] !== discriminatorBytes[index]) {
1091
+ return null;
1092
+ }
1093
+ }
1094
+ if (bytes[1] !== 0) {
1095
+ return null;
1096
+ }
1097
+ return decodeSwappedEvent(bytes);
1098
+ }
1099
+ function decodeLiquidityChangedEvent(data) {
1100
+ const bytes = data instanceof Uint8Array ? data : new Uint8Array(data);
1101
+ const discriminatorBytes = getLiquidityChangedEventDiscriminatorBytes();
1102
+ if (bytes.length < 2) {
1103
+ throw new RangeError(
1104
+ `the provided data is too short for the "LiquidityChangedEvent" event envelope`
1105
+ );
1106
+ }
1107
+ for (let index = 0; index < 1; index += 1) {
1108
+ if (bytes[index] !== discriminatorBytes[index]) {
1109
+ throw new RangeError(
1110
+ 'the provided data does not match the "LiquidityChangedEvent" event discriminator.'
1111
+ );
1112
+ }
1113
+ }
1114
+ const sourceVersion = bytes[1];
1115
+ if (sourceVersion !== 0) {
1116
+ throw new RangeError(
1117
+ `event migration version mismatch: expected 0, received ${sourceVersion} (decode it with the event for that version, or regenerate this client)`
1118
+ );
1119
+ }
1120
+ return { name: "liquidityChanged", data: getLiquidityChangedEventDecoder().decode(bytes) };
1121
+ }
1122
+ function parseLiquidityChangedEventFromLog(log) {
1123
+ const prefix = "Program data: ";
1124
+ if (!log.startsWith(prefix)) {
1125
+ return null;
1126
+ }
1127
+ const bytes = getBase64Encoder().encode(log.slice(prefix.length));
1128
+ if (bytes.length < 2) {
1129
+ return null;
1130
+ }
1131
+ const discriminatorBytes = getLiquidityChangedEventDiscriminatorBytes();
1132
+ for (let index = 0; index < 1; index += 1) {
1133
+ if (bytes[index] !== discriminatorBytes[index]) {
1134
+ return null;
1135
+ }
1136
+ }
1137
+ if (bytes[1] !== 0) {
1138
+ return null;
1139
+ }
1140
+ return decodeLiquidityChangedEvent(bytes);
1141
+ }
1142
+ function decodeFeesCollectedEvent(data) {
1143
+ const bytes = data instanceof Uint8Array ? data : new Uint8Array(data);
1144
+ const discriminatorBytes = getFeesCollectedEventDiscriminatorBytes();
1145
+ if (bytes.length < 2) {
1146
+ throw new RangeError(
1147
+ `the provided data is too short for the "FeesCollectedEvent" event envelope`
1148
+ );
1149
+ }
1150
+ for (let index = 0; index < 1; index += 1) {
1151
+ if (bytes[index] !== discriminatorBytes[index]) {
1152
+ throw new RangeError(
1153
+ 'the provided data does not match the "FeesCollectedEvent" event discriminator.'
1154
+ );
1155
+ }
1156
+ }
1157
+ const sourceVersion = bytes[1];
1158
+ if (sourceVersion !== 0) {
1159
+ throw new RangeError(
1160
+ `event migration version mismatch: expected 0, received ${sourceVersion} (decode it with the event for that version, or regenerate this client)`
1161
+ );
1162
+ }
1163
+ return { name: "feesCollected", data: getFeesCollectedEventDecoder().decode(bytes) };
1164
+ }
1165
+ function parseFeesCollectedEventFromLog(log) {
1166
+ const prefix = "Program data: ";
1167
+ if (!log.startsWith(prefix)) {
1168
+ return null;
1169
+ }
1170
+ const bytes = getBase64Encoder().encode(log.slice(prefix.length));
1171
+ if (bytes.length < 2) {
1172
+ return null;
1173
+ }
1174
+ const discriminatorBytes = getFeesCollectedEventDiscriminatorBytes();
1175
+ for (let index = 0; index < 1; index += 1) {
1176
+ if (bytes[index] !== discriminatorBytes[index]) {
1177
+ return null;
1178
+ }
1179
+ }
1180
+ if (bytes[1] !== 0) {
1181
+ return null;
1182
+ }
1183
+ return decodeFeesCollectedEvent(bytes);
1184
+ }
1185
+ function decodePoolSyncedEvent(data) {
1186
+ const bytes = data instanceof Uint8Array ? data : new Uint8Array(data);
1187
+ const discriminatorBytes = getPoolSyncedEventDiscriminatorBytes();
1188
+ if (bytes.length < 2) {
1189
+ throw new RangeError(
1190
+ `the provided data is too short for the "PoolSyncedEvent" event envelope`
1191
+ );
1192
+ }
1193
+ for (let index = 0; index < 1; index += 1) {
1194
+ if (bytes[index] !== discriminatorBytes[index]) {
1195
+ throw new RangeError(
1196
+ 'the provided data does not match the "PoolSyncedEvent" event discriminator.'
1197
+ );
1198
+ }
1199
+ }
1200
+ const sourceVersion = bytes[1];
1201
+ if (sourceVersion !== 1) {
1202
+ throw new RangeError(
1203
+ `event migration version mismatch: expected 1, received ${sourceVersion} (decode it with the event for that version, or regenerate this client)`
1204
+ );
1205
+ }
1206
+ return { name: "poolSynced", data: getPoolSyncedEventDecoder().decode(bytes) };
1207
+ }
1208
+ function parsePoolSyncedEventFromLog(log) {
1209
+ const prefix = "Program data: ";
1210
+ if (!log.startsWith(prefix)) {
1211
+ return null;
1212
+ }
1213
+ const bytes = getBase64Encoder().encode(log.slice(prefix.length));
1214
+ if (bytes.length < 2) {
1215
+ return null;
1216
+ }
1217
+ const discriminatorBytes = getPoolSyncedEventDiscriminatorBytes();
1218
+ for (let index = 0; index < 1; index += 1) {
1219
+ if (bytes[index] !== discriminatorBytes[index]) {
1220
+ return null;
1221
+ }
1222
+ }
1223
+ if (bytes[1] !== 1) {
1224
+ return null;
1225
+ }
1226
+ return decodePoolSyncedEvent(bytes);
1227
+ }
1228
+ function decodePoolSyncedV0Event(data) {
1229
+ const bytes = data instanceof Uint8Array ? data : new Uint8Array(data);
1230
+ const discriminatorBytes = getPoolSyncedV0EventDiscriminatorBytes();
1231
+ if (bytes.length < 2) {
1232
+ throw new RangeError(
1233
+ `the provided data is too short for the "PoolSyncedV0Event" event envelope`
1234
+ );
1235
+ }
1236
+ for (let index = 0; index < 1; index += 1) {
1237
+ if (bytes[index] !== discriminatorBytes[index]) {
1238
+ throw new RangeError(
1239
+ 'the provided data does not match the "PoolSyncedV0Event" event discriminator.'
1240
+ );
1241
+ }
1242
+ }
1243
+ const sourceVersion = bytes[1];
1244
+ if (sourceVersion !== 0) {
1245
+ throw new RangeError(
1246
+ `event migration version mismatch: expected 0, received ${sourceVersion} (decode it with the event for that version, or regenerate this client)`
1247
+ );
1248
+ }
1249
+ return { name: "poolSyncedV0", data: getPoolSyncedV0EventDecoder().decode(bytes) };
1250
+ }
1251
+ function parsePoolSyncedV0EventFromLog(log) {
1252
+ const prefix = "Program data: ";
1253
+ if (!log.startsWith(prefix)) {
1254
+ return null;
1255
+ }
1256
+ const bytes = getBase64Encoder().encode(log.slice(prefix.length));
1257
+ if (bytes.length < 2) {
1258
+ return null;
1259
+ }
1260
+ const discriminatorBytes = getPoolSyncedV0EventDiscriminatorBytes();
1261
+ for (let index = 0; index < 1; index += 1) {
1262
+ if (bytes[index] !== discriminatorBytes[index]) {
1263
+ return null;
1264
+ }
1265
+ }
1266
+ if (bytes[1] !== 0) {
1267
+ return null;
1268
+ }
1269
+ return decodePoolSyncedV0Event(bytes);
1270
+ }
1271
+ function decodeConfigCreatedEvent(data) {
1272
+ const bytes = data instanceof Uint8Array ? data : new Uint8Array(data);
1273
+ const discriminatorBytes = getConfigCreatedEventDiscriminatorBytes();
1274
+ if (bytes.length < 2) {
1275
+ throw new RangeError(
1276
+ `the provided data is too short for the "ConfigCreatedEvent" event envelope`
1277
+ );
1278
+ }
1279
+ for (let index = 0; index < 1; index += 1) {
1280
+ if (bytes[index] !== discriminatorBytes[index]) {
1281
+ throw new RangeError(
1282
+ 'the provided data does not match the "ConfigCreatedEvent" event discriminator.'
1283
+ );
1284
+ }
1285
+ }
1286
+ const sourceVersion = bytes[1];
1287
+ if (sourceVersion !== 0) {
1288
+ throw new RangeError(
1289
+ `event migration version mismatch: expected 0, received ${sourceVersion} (decode it with the event for that version, or regenerate this client)`
1290
+ );
1291
+ }
1292
+ return { name: "configCreated", data: getConfigCreatedEventDecoder().decode(bytes) };
1293
+ }
1294
+ function parseConfigCreatedEventFromLog(log) {
1295
+ const prefix = "Program data: ";
1296
+ if (!log.startsWith(prefix)) {
1297
+ return null;
1298
+ }
1299
+ const bytes = getBase64Encoder().encode(log.slice(prefix.length));
1300
+ if (bytes.length < 2) {
1301
+ return null;
1302
+ }
1303
+ const discriminatorBytes = getConfigCreatedEventDiscriminatorBytes();
1304
+ for (let index = 0; index < 1; index += 1) {
1305
+ if (bytes[index] !== discriminatorBytes[index]) {
1306
+ return null;
1307
+ }
1308
+ }
1309
+ if (bytes[1] !== 0) {
1310
+ return null;
1311
+ }
1312
+ return decodeConfigCreatedEvent(bytes);
1313
+ }
1314
+ function decodeConfigUpdatedEvent(data) {
1315
+ const bytes = data instanceof Uint8Array ? data : new Uint8Array(data);
1316
+ const discriminatorBytes = getConfigUpdatedEventDiscriminatorBytes();
1317
+ if (bytes.length < 2) {
1318
+ throw new RangeError(
1319
+ `the provided data is too short for the "ConfigUpdatedEvent" event envelope`
1320
+ );
1321
+ }
1322
+ for (let index = 0; index < 1; index += 1) {
1323
+ if (bytes[index] !== discriminatorBytes[index]) {
1324
+ throw new RangeError(
1325
+ 'the provided data does not match the "ConfigUpdatedEvent" event discriminator.'
1326
+ );
1327
+ }
1328
+ }
1329
+ const sourceVersion = bytes[1];
1330
+ if (sourceVersion !== 0) {
1331
+ throw new RangeError(
1332
+ `event migration version mismatch: expected 0, received ${sourceVersion} (decode it with the event for that version, or regenerate this client)`
1333
+ );
1334
+ }
1335
+ return { name: "configUpdated", data: getConfigUpdatedEventDecoder().decode(bytes) };
1336
+ }
1337
+ function parseConfigUpdatedEventFromLog(log) {
1338
+ const prefix = "Program data: ";
1339
+ if (!log.startsWith(prefix)) {
1340
+ return null;
1341
+ }
1342
+ const bytes = getBase64Encoder().encode(log.slice(prefix.length));
1343
+ if (bytes.length < 2) {
1344
+ return null;
1345
+ }
1346
+ const discriminatorBytes = getConfigUpdatedEventDiscriminatorBytes();
1347
+ for (let index = 0; index < 1; index += 1) {
1348
+ if (bytes[index] !== discriminatorBytes[index]) {
1349
+ return null;
1350
+ }
1351
+ }
1352
+ if (bytes[1] !== 0) {
1353
+ return null;
1354
+ }
1355
+ return decodeConfigUpdatedEvent(bytes);
1356
+ }
1357
+ function decodePoolCreatorChangedEvent(data) {
1358
+ const bytes = data instanceof Uint8Array ? data : new Uint8Array(data);
1359
+ const discriminatorBytes = getPoolCreatorChangedEventDiscriminatorBytes();
1360
+ if (bytes.length < 2) {
1361
+ throw new RangeError(
1362
+ `the provided data is too short for the "PoolCreatorChangedEvent" event envelope`
1363
+ );
1364
+ }
1365
+ for (let index = 0; index < 1; index += 1) {
1366
+ if (bytes[index] !== discriminatorBytes[index]) {
1367
+ throw new RangeError(
1368
+ 'the provided data does not match the "PoolCreatorChangedEvent" event discriminator.'
1369
+ );
1370
+ }
1371
+ }
1372
+ const sourceVersion = bytes[1];
1373
+ if (sourceVersion !== 0) {
1374
+ throw new RangeError(
1375
+ `event migration version mismatch: expected 0, received ${sourceVersion} (decode it with the event for that version, or regenerate this client)`
1376
+ );
1377
+ }
1378
+ return { name: "poolCreatorChanged", data: getPoolCreatorChangedEventDecoder().decode(bytes) };
1379
+ }
1380
+ function parsePoolCreatorChangedEventFromLog(log) {
1381
+ const prefix = "Program data: ";
1382
+ if (!log.startsWith(prefix)) {
1383
+ return null;
1384
+ }
1385
+ const bytes = getBase64Encoder().encode(log.slice(prefix.length));
1386
+ if (bytes.length < 2) {
1387
+ return null;
1388
+ }
1389
+ const discriminatorBytes = getPoolCreatorChangedEventDiscriminatorBytes();
1390
+ for (let index = 0; index < 1; index += 1) {
1391
+ if (bytes[index] !== discriminatorBytes[index]) {
1392
+ return null;
1393
+ }
1394
+ }
1395
+ if (bytes[1] !== 0) {
1396
+ return null;
1397
+ }
1398
+ return decodePoolCreatorChangedEvent(bytes);
1399
+ }
1400
+ function unrecognizedEventVersion(log) {
1401
+ const prefix = "Program data: ";
1402
+ if (!log.startsWith(prefix)) {
1403
+ return null;
1404
+ }
1405
+ const bytes = getBase64Encoder().encode(log.slice(prefix.length));
1406
+ if (bytes.length >= 1 && bytes[0] === 1) {
1407
+ return bytes.length < 2 ? 'event "poolCreated" log is too short for its version envelope' : `event "poolCreated" log carries migration version ${bytes[1]}, which this client cannot decode; regenerate it`;
1408
+ }
1409
+ if (bytes.length >= 1 && bytes[0] === 2) {
1410
+ return bytes.length < 2 ? 'event "swapped" log is too short for its version envelope' : `event "swapped" log carries migration version ${bytes[1]}, which this client cannot decode; regenerate it`;
1411
+ }
1412
+ if (bytes.length >= 1 && bytes[0] === 3) {
1413
+ return bytes.length < 2 ? 'event "liquidityChanged" log is too short for its version envelope' : `event "liquidityChanged" log carries migration version ${bytes[1]}, which this client cannot decode; regenerate it`;
1414
+ }
1415
+ if (bytes.length >= 1 && bytes[0] === 4) {
1416
+ return bytes.length < 2 ? 'event "feesCollected" log is too short for its version envelope' : `event "feesCollected" log carries migration version ${bytes[1]}, which this client cannot decode; regenerate it`;
1417
+ }
1418
+ if (bytes.length >= 1 && bytes[0] === 5) {
1419
+ return bytes.length < 2 ? 'event "poolSynced" log is too short for its version envelope' : `event "poolSynced" log carries migration version ${bytes[1]}, which this client cannot decode; regenerate it`;
1420
+ }
1421
+ if (bytes.length >= 1 && bytes[0] === 8) {
1422
+ return bytes.length < 2 ? 'event "configCreated" log is too short for its version envelope' : `event "configCreated" log carries migration version ${bytes[1]}, which this client cannot decode; regenerate it`;
1423
+ }
1424
+ if (bytes.length >= 1 && bytes[0] === 6) {
1425
+ return bytes.length < 2 ? 'event "configUpdated" log is too short for its version envelope' : `event "configUpdated" log carries migration version ${bytes[1]}, which this client cannot decode; regenerate it`;
1426
+ }
1427
+ if (bytes.length >= 1 && bytes[0] === 7) {
1428
+ return bytes.length < 2 ? 'event "poolCreatorChanged" log is too short for its version envelope' : `event "poolCreatorChanged" log carries migration version ${bytes[1]}, which this client cannot decode; regenerate it`;
1429
+ }
1430
+ return null;
1431
+ }
1432
+ var PINA_AMM_EVENT_SOURCE_ADDRESS = "pAMMzVPRwtrxQs2CjLTUUpfCAp9XdvVmwwVhpAuCobi";
1433
+ var PROGRAM_INVOKE_LOG = /^Program (\S+) invoke \[\d+\]$/;
1434
+ var PROGRAM_EXIT_LOG = /^Program (\S+) (?:success|failed: .*)$/;
1435
+ function parsePinaAmmEventsFromLogs(logs, programAddress = PINA_AMM_EVENT_SOURCE_ADDRESS) {
1436
+ const discovered = [];
1437
+ const frames = [];
1438
+ for (const log of logs) {
1439
+ const invoke = PROGRAM_INVOKE_LOG.exec(log);
1440
+ if (invoke !== null) {
1441
+ frames.push(invoke[1] ?? "");
1442
+ continue;
1443
+ }
1444
+ const exit = PROGRAM_EXIT_LOG.exec(log);
1445
+ if (exit !== null) {
1446
+ frames.pop();
1447
+ continue;
1448
+ }
1449
+ if (frames.length === 0 || frames[frames.length - 1] !== programAddress) {
1450
+ continue;
1451
+ }
1452
+ const poolCreated = parsePoolCreatedEventFromLog(log);
1453
+ if (poolCreated !== null) {
1454
+ discovered.push(poolCreated);
1455
+ continue;
1456
+ }
1457
+ const swapped = parseSwappedEventFromLog(log);
1458
+ if (swapped !== null) {
1459
+ discovered.push(swapped);
1460
+ continue;
1461
+ }
1462
+ const liquidityChanged = parseLiquidityChangedEventFromLog(log);
1463
+ if (liquidityChanged !== null) {
1464
+ discovered.push(liquidityChanged);
1465
+ continue;
1466
+ }
1467
+ const feesCollected = parseFeesCollectedEventFromLog(log);
1468
+ if (feesCollected !== null) {
1469
+ discovered.push(feesCollected);
1470
+ continue;
1471
+ }
1472
+ const poolSynced = parsePoolSyncedEventFromLog(log);
1473
+ if (poolSynced !== null) {
1474
+ discovered.push(poolSynced);
1475
+ continue;
1476
+ }
1477
+ const poolSyncedV0 = parsePoolSyncedV0EventFromLog(log);
1478
+ if (poolSyncedV0 !== null) {
1479
+ discovered.push(poolSyncedV0);
1480
+ continue;
1481
+ }
1482
+ const configCreated = parseConfigCreatedEventFromLog(log);
1483
+ if (configCreated !== null) {
1484
+ discovered.push(configCreated);
1485
+ continue;
1486
+ }
1487
+ const configUpdated = parseConfigUpdatedEventFromLog(log);
1488
+ if (configUpdated !== null) {
1489
+ discovered.push(configUpdated);
1490
+ continue;
1491
+ }
1492
+ const poolCreatorChanged = parsePoolCreatorChangedEventFromLog(log);
1493
+ if (poolCreatorChanged !== null) {
1494
+ discovered.push(poolCreatorChanged);
1495
+ continue;
1496
+ }
1497
+ const unknownVersion = unrecognizedEventVersion(log);
1498
+ if (unknownVersion !== null) {
1499
+ throw new RangeError(unknownVersion);
1500
+ }
1501
+ }
1502
+ return discovered;
1503
+ }
1504
+
1505
+ export { AMM_CONFIG_DISCRIMINATOR, AMM_CONFIG_DISCRIMINATOR2, AMM_CONFIG_MIGRATION_VERSION, COLLECT_CREATOR_FEES_DISCRIMINATOR, COLLECT_PROTOCOL_FEES_DISCRIMINATOR, CONFIG_CREATED_EVENT_DISCRIMINATOR, CONFIG_CREATED_EVENT_DISCRIMINATOR2, CONFIG_UPDATED_EVENT_DISCRIMINATOR, CONFIG_UPDATED_EVENT_DISCRIMINATOR2, CREATE_CONFIG_DISCRIMINATOR, CREATE_POOL_DISCRIMINATOR, DEPOSIT_DISCRIMINATOR, FEES_COLLECTED_EVENT_DISCRIMINATOR, FEES_COLLECTED_EVENT_DISCRIMINATOR2, LIQUIDITY_CHANGED_EVENT_DISCRIMINATOR, LIQUIDITY_CHANGED_EVENT_DISCRIMINATOR2, MIGRATE_DISCRIMINATOR, PINA_AMM_ERROR__DEFAULT_CREATOR, PINA_AMM_ERROR__INSUFFICIENT_INITIAL_LIQUIDITY, PINA_AMM_ERROR__INSUFFICIENT_LIQUIDITY, PINA_AMM_ERROR__INVALID_CREATOR_FEE_MODE, PINA_AMM_ERROR__INVALID_FEE_RATES, PINA_AMM_ERROR__INVALID_MINT_ORDER, PINA_AMM_ERROR__INVALID_PROGRAM_DATA, PINA_AMM_ERROR__INVARIANT_VIOLATION, PINA_AMM_ERROR__MATH_OVERFLOW, PINA_AMM_ERROR__POOL_ACCOUNT_MISMATCH, PINA_AMM_ERROR__POOL_CREATOR_NOT_AUTHORIZED, PINA_AMM_ERROR__SLIPPAGE_EXCEEDED, PINA_AMM_ERROR__UNAUTHORIZED, PINA_AMM_ERROR__UNSUPPORTED_MINT, PINA_AMM_ERROR__VAULT_ACCOUNTING_MISMATCH, PINA_AMM_ERROR__ZERO_AMOUNT, PINA_AMM_EVENT_SOURCE_ADDRESS, PINA_AMM_PROGRAM_ADDRESS, POOL_CREATED_EVENT_DISCRIMINATOR, POOL_CREATED_EVENT_DISCRIMINATOR2, POOL_CREATOR_CHANGED_EVENT_DISCRIMINATOR, POOL_CREATOR_CHANGED_EVENT_DISCRIMINATOR2, POOL_DISCRIMINATOR, POOL_DISCRIMINATOR2, POOL_MIGRATION_VERSION, POOL_SYNCED_EVENT_DISCRIMINATOR, POOL_SYNCED_EVENT_DISCRIMINATOR2, POOL_SYNCED_V0_EVENT_DISCRIMINATOR, POOL_SYNCED_V0_EVENT_DISCRIMINATOR2, PinaAmmAccount, PinaAmmEvent, PinaAmmInstruction, SET_POOL_CREATOR_DISCRIMINATOR, SWAPPED_EVENT_DISCRIMINATOR, SWAPPED_EVENT_DISCRIMINATOR2, SWAP_EXACT_IN_DISCRIMINATOR, SWAP_EXACT_OUT_DISCRIMINATOR, SYNC_POOL_DISCRIMINATOR, UPDATE_CONFIG_DISCRIMINATOR, WITHDRAW_DISCRIMINATOR, ammConfigNeedsMigration, decodeAmmConfig, decodeConfigCreatedEvent, decodeConfigUpdatedEvent, decodeFeesCollectedEvent, decodeLiquidityChangedEvent, decodePool, decodePoolCreatedEvent, decodePoolCreatorChangedEvent, decodePoolSyncedEvent, decodePoolSyncedV0Event, decodeSwappedEvent, fetchAllAmmConfig, fetchAllMaybeAmmConfig, fetchAllMaybePool, fetchAllPool, fetchAmmConfig, fetchAmmConfigFromSeeds, fetchMaybeAmmConfig, fetchMaybeAmmConfigFromSeeds, fetchMaybePool, fetchMaybePoolFromSeeds, fetchPool, fetchPoolFromSeeds, findAmmConfigPda, findPoolLpMintPda, findPoolPda, findPoolVaultPda, getAmmConfigCodec, getAmmConfigDecoder, getAmmConfigDiscriminator2Bytes, getAmmConfigDiscriminatorBytes, getAmmConfigEncoder, getCollectCreatorFeesDiscriminatorBytes, getCollectCreatorFeesInstruction, getCollectCreatorFeesInstructionDataCodec, getCollectCreatorFeesInstructionDataDecoder, getCollectCreatorFeesInstructionDataEncoder, getCollectProtocolFeesDiscriminatorBytes, getCollectProtocolFeesInstruction, getCollectProtocolFeesInstructionDataCodec, getCollectProtocolFeesInstructionDataDecoder, getCollectProtocolFeesInstructionDataEncoder, getConfigCreatedEventCodec, getConfigCreatedEventDecoder, getConfigCreatedEventDiscriminator2Bytes, getConfigCreatedEventDiscriminatorBytes, getConfigCreatedEventEncoder, getConfigUpdatedEventCodec, getConfigUpdatedEventDecoder, getConfigUpdatedEventDiscriminator2Bytes, getConfigUpdatedEventDiscriminatorBytes, getConfigUpdatedEventEncoder, getCreateConfigDiscriminatorBytes, getCreateConfigInstruction, getCreateConfigInstructionDataCodec, getCreateConfigInstructionDataDecoder, getCreateConfigInstructionDataEncoder, getCreatePoolDiscriminatorBytes, getCreatePoolInstruction, getCreatePoolInstructionAsync, getCreatePoolInstructionDataCodec, getCreatePoolInstructionDataDecoder, getCreatePoolInstructionDataEncoder, getDepositDiscriminatorBytes, getDepositInstruction, getDepositInstructionDataCodec, getDepositInstructionDataDecoder, getDepositInstructionDataEncoder, getFeesCollectedEventCodec, getFeesCollectedEventDecoder, getFeesCollectedEventDiscriminator2Bytes, getFeesCollectedEventDiscriminatorBytes, getFeesCollectedEventEncoder, getLiquidityChangedEventCodec, getLiquidityChangedEventDecoder, getLiquidityChangedEventDiscriminator2Bytes, getLiquidityChangedEventDiscriminatorBytes, getLiquidityChangedEventEncoder, getMigrateDiscriminatorBytes, getMigrateInstruction, getPinaAmmErrorMessage, getPoolCodec, getPoolCreatedEventCodec, getPoolCreatedEventDecoder, getPoolCreatedEventDiscriminator2Bytes, getPoolCreatedEventDiscriminatorBytes, getPoolCreatedEventEncoder, getPoolCreatorChangedEventCodec, getPoolCreatorChangedEventDecoder, getPoolCreatorChangedEventDiscriminator2Bytes, getPoolCreatorChangedEventDiscriminatorBytes, getPoolCreatorChangedEventEncoder, getPoolDecoder, getPoolDiscriminator2Bytes, getPoolDiscriminatorBytes, getPoolEncoder, getPoolSyncedEventCodec, getPoolSyncedEventDecoder, getPoolSyncedEventDiscriminator2Bytes, getPoolSyncedEventDiscriminatorBytes, getPoolSyncedEventEncoder, getPoolSyncedV0EventCodec, getPoolSyncedV0EventDecoder, getPoolSyncedV0EventDiscriminator2Bytes, getPoolSyncedV0EventDiscriminatorBytes, getPoolSyncedV0EventEncoder, getSetPoolCreatorDiscriminatorBytes, getSetPoolCreatorInstruction, getSetPoolCreatorInstructionDataCodec, getSetPoolCreatorInstructionDataDecoder, getSetPoolCreatorInstructionDataEncoder, getSwapExactInDiscriminatorBytes, getSwapExactInInstruction, getSwapExactInInstructionDataCodec, getSwapExactInInstructionDataDecoder, getSwapExactInInstructionDataEncoder, getSwapExactOutDiscriminatorBytes, getSwapExactOutInstruction, getSwapExactOutInstructionDataCodec, getSwapExactOutInstructionDataDecoder, getSwapExactOutInstructionDataEncoder, getSwappedEventCodec, getSwappedEventDecoder, getSwappedEventDiscriminator2Bytes, getSwappedEventDiscriminatorBytes, getSwappedEventEncoder, getSyncPoolDiscriminatorBytes, getSyncPoolInstruction, getSyncPoolInstructionDataCodec, getSyncPoolInstructionDataDecoder, getSyncPoolInstructionDataEncoder, getUpdateConfigDiscriminatorBytes, getUpdateConfigInstruction, getUpdateConfigInstructionDataCodec, getUpdateConfigInstructionDataDecoder, getUpdateConfigInstructionDataEncoder, getWithdrawDiscriminatorBytes, getWithdrawInstruction, getWithdrawInstructionDataCodec, getWithdrawInstructionDataDecoder, getWithdrawInstructionDataEncoder, identifyPinaAmmAccount, identifyPinaAmmEvent, identifyPinaAmmInstruction, isPinaAmmError, parseCollectCreatorFeesInstruction, parseCollectProtocolFeesInstruction, parseConfigCreatedEvent, parseConfigCreatedEventFromLog, parseConfigUpdatedEvent, parseConfigUpdatedEventFromLog, parseCreateConfigInstruction, parseCreatePoolInstruction, parseDepositInstruction, parseFeesCollectedEvent, parseFeesCollectedEventFromLog, parseLiquidityChangedEvent, parseLiquidityChangedEventFromLog, parsePinaAmmEventsFromLogs, parsePinaAmmInstruction, parsePoolCreatedEvent, parsePoolCreatedEventFromLog, parsePoolCreatorChangedEvent, parsePoolCreatorChangedEventFromLog, parsePoolSyncedEvent, parsePoolSyncedEventFromLog, parsePoolSyncedV0Event, parsePoolSyncedV0EventFromLog, parseSetPoolCreatorInstruction, parseSwapExactInInstruction, parseSwapExactOutInstruction, parseSwappedEvent, parseSwappedEventFromLog, parseSyncPoolInstruction, parseUpdateConfigInstruction, parseWithdrawInstruction, pinaAmmProgram, poolNeedsMigration };
1506
+ //# sourceMappingURL=index.js.map
1507
+ //# sourceMappingURL=index.js.map