@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
@@ -0,0 +1,124 @@
1
+ /**
2
+ * This code was AUTOGENERATED using the Codama library.
3
+ * Please DO NOT EDIT THIS FILE, instead use visitors
4
+ * to add features, then rerun Codama to update it.
5
+ *
6
+ * @see https://github.com/codama-idl/codama
7
+ */
8
+
9
+ import { assertIsInstructionWithAccounts, containsBytes, extendClient, getU8Encoder, SOLANA_ERROR__PROGRAM_CLIENTS__FAILED_TO_IDENTIFY_ACCOUNT, SOLANA_ERROR__PROGRAM_CLIENTS__FAILED_TO_IDENTIFY_INSTRUCTION, SOLANA_ERROR__PROGRAM_CLIENTS__UNRECOGNIZED_INSTRUCTION_TYPE, SolanaError, type Address, type ClientWithRpc, type ClientWithTransactionPlanning, type ClientWithTransactionSending, type ExtendedClient, type GetAccountInfoApi, type GetMultipleAccountsApi, type Instruction, type InstructionWithData, type ReadonlyUint8Array } from '@solana/kit';
10
+ import { addSelfFetchFunctions, addSelfPlanAndSendFunctions, type SelfFetchFunctions, type SelfPlanAndSendFunctions } from '@solana/program-client-core';
11
+ import { getAmmConfigCodec, getPoolCodec, type AmmConfig, type AmmConfigArgs, type Pool, type PoolArgs } from '../accounts';
12
+ import { getCollectCreatorFeesInstruction, getCollectProtocolFeesInstruction, getCreateConfigInstruction, getCreatePoolInstructionAsync, getDepositInstruction, getSetPoolCreatorInstruction, getSwapExactInInstruction, getSwapExactOutInstruction, getSyncPoolInstruction, getUpdateConfigInstruction, getWithdrawInstruction, parseCollectCreatorFeesInstruction, parseCollectProtocolFeesInstruction, parseCreateConfigInstruction, parseCreatePoolInstruction, parseDepositInstruction, parseSetPoolCreatorInstruction, parseSwapExactInInstruction, parseSwapExactOutInstruction, parseSyncPoolInstruction, parseUpdateConfigInstruction, parseWithdrawInstruction, type CollectCreatorFeesInput, type CollectProtocolFeesInput, type CreateConfigInput, type CreatePoolAsyncInput, type DepositInput, type ParsedCollectCreatorFeesInstruction, type ParsedCollectProtocolFeesInstruction, type ParsedCreateConfigInstruction, type ParsedCreatePoolInstruction, type ParsedDepositInstruction, type ParsedSetPoolCreatorInstruction, type ParsedSwapExactInInstruction, type ParsedSwapExactOutInstruction, type ParsedSyncPoolInstruction, type ParsedUpdateConfigInstruction, type ParsedWithdrawInstruction, type SetPoolCreatorInput, type SwapExactInInput, type SwapExactOutInput, type SyncPoolInput, type UpdateConfigInput, type WithdrawInput } from '../instructions';
13
+ import { getMigrateInstruction, type MigrateInput } from "../instructions";
14
+
15
+ import { findAmmConfigPda, findPoolLpMintPda, findPoolPda, findPoolVaultPda } from '../pdas';
16
+
17
+ export const PINA_AMM_PROGRAM_ADDRESS = 'pAMMzVPRwtrxQs2CjLTUUpfCAp9XdvVmwwVhpAuCobi' as Address<'pAMMzVPRwtrxQs2CjLTUUpfCAp9XdvVmwwVhpAuCobi'>;
18
+
19
+ export enum PinaAmmAccount { AmmConfig, Pool }
20
+
21
+ export function identifyPinaAmmAccount(account: { data: ReadonlyUint8Array } | ReadonlyUint8Array): PinaAmmAccount {
22
+ const data = 'data' in account ? account.data : account;
23
+ if (containsBytes(data, getU8Encoder().encode(1), 0) && containsBytes(data, getU8Encoder().encode(0), 1)) { return PinaAmmAccount.AmmConfig; }
24
+ if (containsBytes(data, getU8Encoder().encode(2), 0) && containsBytes(data, getU8Encoder().encode(1), 1)) { return PinaAmmAccount.Pool; }
25
+ throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__FAILED_TO_IDENTIFY_ACCOUNT, { accountData: data, programName: "pinaAmm" });
26
+ }
27
+
28
+ export enum PinaAmmEvent { PoolCreated, Swapped, LiquidityChanged, FeesCollected, PoolSynced, PoolSyncedV0, ConfigCreated, ConfigUpdated, PoolCreatorChanged }
29
+
30
+ export function identifyPinaAmmEvent(event: { data: ReadonlyUint8Array } | ReadonlyUint8Array): PinaAmmEvent {
31
+ const data = 'data' in event ? event.data : event;
32
+ if (containsBytes(data, getU8Encoder().encode(1), 0) && containsBytes(data, getU8Encoder().encode(0), 1)) { return PinaAmmEvent.PoolCreated; }
33
+ if (containsBytes(data, getU8Encoder().encode(2), 0) && containsBytes(data, getU8Encoder().encode(0), 1)) { return PinaAmmEvent.Swapped; }
34
+ if (containsBytes(data, getU8Encoder().encode(3), 0) && containsBytes(data, getU8Encoder().encode(0), 1)) { return PinaAmmEvent.LiquidityChanged; }
35
+ if (containsBytes(data, getU8Encoder().encode(4), 0) && containsBytes(data, getU8Encoder().encode(0), 1)) { return PinaAmmEvent.FeesCollected; }
36
+ if (containsBytes(data, getU8Encoder().encode(5), 0) && containsBytes(data, getU8Encoder().encode(1), 1)) { return PinaAmmEvent.PoolSynced; }
37
+ if (containsBytes(data, getU8Encoder().encode(5), 0) && containsBytes(data, getU8Encoder().encode(0), 1)) { return PinaAmmEvent.PoolSyncedV0; }
38
+ if (containsBytes(data, getU8Encoder().encode(8), 0) && containsBytes(data, getU8Encoder().encode(0), 1)) { return PinaAmmEvent.ConfigCreated; }
39
+ if (containsBytes(data, getU8Encoder().encode(6), 0) && containsBytes(data, getU8Encoder().encode(0), 1)) { return PinaAmmEvent.ConfigUpdated; }
40
+ if (containsBytes(data, getU8Encoder().encode(7), 0) && containsBytes(data, getU8Encoder().encode(0), 1)) { return PinaAmmEvent.PoolCreatorChanged; }
41
+ throw new Error('The provided event could not be identified as a pinaAmm event.');
42
+ }
43
+
44
+ export enum PinaAmmInstruction { CreateConfig, UpdateConfig, CreatePool, Deposit, Withdraw, SwapExactIn, SwapExactOut, CollectProtocolFees, CollectCreatorFees, SetPoolCreator, SyncPool }
45
+
46
+ export function identifyPinaAmmInstruction(instruction: { data: ReadonlyUint8Array } | ReadonlyUint8Array): PinaAmmInstruction {
47
+ const data = 'data' in instruction ? instruction.data : instruction;
48
+ if (containsBytes(data, getU8Encoder().encode(0), 0)) { return PinaAmmInstruction.CreateConfig; }
49
+ if (containsBytes(data, getU8Encoder().encode(1), 0)) { return PinaAmmInstruction.UpdateConfig; }
50
+ if (containsBytes(data, getU8Encoder().encode(2), 0)) { return PinaAmmInstruction.CreatePool; }
51
+ if (containsBytes(data, getU8Encoder().encode(3), 0)) { return PinaAmmInstruction.Deposit; }
52
+ if (containsBytes(data, getU8Encoder().encode(4), 0)) { return PinaAmmInstruction.Withdraw; }
53
+ if (containsBytes(data, getU8Encoder().encode(5), 0)) { return PinaAmmInstruction.SwapExactIn; }
54
+ if (containsBytes(data, getU8Encoder().encode(6), 0)) { return PinaAmmInstruction.SwapExactOut; }
55
+ if (containsBytes(data, getU8Encoder().encode(7), 0)) { return PinaAmmInstruction.CollectProtocolFees; }
56
+ if (containsBytes(data, getU8Encoder().encode(8), 0)) { return PinaAmmInstruction.CollectCreatorFees; }
57
+ if (containsBytes(data, getU8Encoder().encode(9), 0)) { return PinaAmmInstruction.SetPoolCreator; }
58
+ if (containsBytes(data, getU8Encoder().encode(10), 0)) { return PinaAmmInstruction.SyncPool; }
59
+ throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__FAILED_TO_IDENTIFY_INSTRUCTION, { instructionData: data, programName: "pinaAmm" });
60
+ }
61
+
62
+ export type ParsedPinaAmmInstruction<TProgram extends string = 'pAMMzVPRwtrxQs2CjLTUUpfCAp9XdvVmwwVhpAuCobi'> =
63
+ | { instructionType: PinaAmmInstruction.CreateConfig } & ParsedCreateConfigInstruction<TProgram>
64
+ | { instructionType: PinaAmmInstruction.UpdateConfig } & ParsedUpdateConfigInstruction<TProgram>
65
+ | { instructionType: PinaAmmInstruction.CreatePool } & ParsedCreatePoolInstruction<TProgram>
66
+ | { instructionType: PinaAmmInstruction.Deposit } & ParsedDepositInstruction<TProgram>
67
+ | { instructionType: PinaAmmInstruction.Withdraw } & ParsedWithdrawInstruction<TProgram>
68
+ | { instructionType: PinaAmmInstruction.SwapExactIn } & ParsedSwapExactInInstruction<TProgram>
69
+ | { instructionType: PinaAmmInstruction.SwapExactOut } & ParsedSwapExactOutInstruction<TProgram>
70
+ | { instructionType: PinaAmmInstruction.CollectProtocolFees } & ParsedCollectProtocolFeesInstruction<TProgram>
71
+ | { instructionType: PinaAmmInstruction.CollectCreatorFees } & ParsedCollectCreatorFeesInstruction<TProgram>
72
+ | { instructionType: PinaAmmInstruction.SetPoolCreator } & ParsedSetPoolCreatorInstruction<TProgram>
73
+ | { instructionType: PinaAmmInstruction.SyncPool } & ParsedSyncPoolInstruction<TProgram>
74
+
75
+
76
+ export function parsePinaAmmInstruction<TProgram extends string>(
77
+ instruction: Instruction<TProgram>
78
+ & InstructionWithData<ReadonlyUint8Array>
79
+ ): ParsedPinaAmmInstruction<TProgram> {
80
+ const instructionType = identifyPinaAmmInstruction(instruction);
81
+ switch (instructionType) {
82
+ case PinaAmmInstruction.CreateConfig: { assertIsInstructionWithAccounts(instruction);
83
+ return { instructionType: PinaAmmInstruction.CreateConfig, ...parseCreateConfigInstruction(instruction) }; }
84
+ case PinaAmmInstruction.UpdateConfig: { assertIsInstructionWithAccounts(instruction);
85
+ return { instructionType: PinaAmmInstruction.UpdateConfig, ...parseUpdateConfigInstruction(instruction) }; }
86
+ case PinaAmmInstruction.CreatePool: { assertIsInstructionWithAccounts(instruction);
87
+ return { instructionType: PinaAmmInstruction.CreatePool, ...parseCreatePoolInstruction(instruction) }; }
88
+ case PinaAmmInstruction.Deposit: { assertIsInstructionWithAccounts(instruction);
89
+ return { instructionType: PinaAmmInstruction.Deposit, ...parseDepositInstruction(instruction) }; }
90
+ case PinaAmmInstruction.Withdraw: { assertIsInstructionWithAccounts(instruction);
91
+ return { instructionType: PinaAmmInstruction.Withdraw, ...parseWithdrawInstruction(instruction) }; }
92
+ case PinaAmmInstruction.SwapExactIn: { assertIsInstructionWithAccounts(instruction);
93
+ return { instructionType: PinaAmmInstruction.SwapExactIn, ...parseSwapExactInInstruction(instruction) }; }
94
+ case PinaAmmInstruction.SwapExactOut: { assertIsInstructionWithAccounts(instruction);
95
+ return { instructionType: PinaAmmInstruction.SwapExactOut, ...parseSwapExactOutInstruction(instruction) }; }
96
+ case PinaAmmInstruction.CollectProtocolFees: { assertIsInstructionWithAccounts(instruction);
97
+ return { instructionType: PinaAmmInstruction.CollectProtocolFees, ...parseCollectProtocolFeesInstruction(instruction) }; }
98
+ case PinaAmmInstruction.CollectCreatorFees: { assertIsInstructionWithAccounts(instruction);
99
+ return { instructionType: PinaAmmInstruction.CollectCreatorFees, ...parseCollectCreatorFeesInstruction(instruction) }; }
100
+ case PinaAmmInstruction.SetPoolCreator: { assertIsInstructionWithAccounts(instruction);
101
+ return { instructionType: PinaAmmInstruction.SetPoolCreator, ...parseSetPoolCreatorInstruction(instruction) }; }
102
+ case PinaAmmInstruction.SyncPool: { assertIsInstructionWithAccounts(instruction);
103
+ return { instructionType: PinaAmmInstruction.SyncPool, ...parseSyncPoolInstruction(instruction) }; }
104
+ default: throw new SolanaError(SOLANA_ERROR__PROGRAM_CLIENTS__UNRECOGNIZED_INSTRUCTION_TYPE, { instructionType: instructionType as string, programName: "pinaAmm" });
105
+ }
106
+ }
107
+
108
+ export type PinaAmmPlugin = { accounts: PinaAmmPluginAccounts; instructions: PinaAmmPluginInstructions; pdas: PinaAmmPluginPdas; identifyAccount: typeof identifyPinaAmmAccount; identifyInstruction: typeof identifyPinaAmmInstruction; parseInstruction: typeof parsePinaAmmInstruction; }
109
+
110
+ export type PinaAmmPluginAccounts = { ammConfig: ReturnType<typeof getAmmConfigCodec> & SelfFetchFunctions<AmmConfigArgs, AmmConfig>; pool: ReturnType<typeof getPoolCodec> & SelfFetchFunctions<PoolArgs, Pool>; }
111
+
112
+ export type PinaAmmPluginInstructions = { createConfig: (input: CreateConfigInput) => ReturnType<typeof getCreateConfigInstruction> & SelfPlanAndSendFunctions; updateConfig: (input: UpdateConfigInput) => ReturnType<typeof getUpdateConfigInstruction> & SelfPlanAndSendFunctions; createPool: (input: CreatePoolAsyncInput) => ReturnType<typeof getCreatePoolInstructionAsync> & SelfPlanAndSendFunctions; deposit: (input: DepositInput) => ReturnType<typeof getDepositInstruction> & SelfPlanAndSendFunctions; withdraw: (input: WithdrawInput) => ReturnType<typeof getWithdrawInstruction> & SelfPlanAndSendFunctions; swapExactIn: (input: SwapExactInInput) => ReturnType<typeof getSwapExactInInstruction> & SelfPlanAndSendFunctions; swapExactOut: (input: SwapExactOutInput) => ReturnType<typeof getSwapExactOutInstruction> & SelfPlanAndSendFunctions; collectProtocolFees: (input: CollectProtocolFeesInput) => ReturnType<typeof getCollectProtocolFeesInstruction> & SelfPlanAndSendFunctions; collectCreatorFees: (input: CollectCreatorFeesInput) => ReturnType<typeof getCollectCreatorFeesInstruction> & SelfPlanAndSendFunctions; setPoolCreator: (input: SetPoolCreatorInput) => ReturnType<typeof getSetPoolCreatorInstruction> & SelfPlanAndSendFunctions; syncPool: (input: SyncPoolInput) => ReturnType<typeof getSyncPoolInstruction> & SelfPlanAndSendFunctions; }
113
+
114
+ export type PinaAmmPluginPdas = { ammConfig: typeof findAmmConfigPda; pool: typeof findPoolPda; poolVault: typeof findPoolVaultPda; poolLpMint: typeof findPoolLpMintPda; }
115
+
116
+ export type PinaAmmPluginRequirements = ClientWithRpc<GetAccountInfoApi & GetMultipleAccountsApi> & ClientWithTransactionPlanning & ClientWithTransactionSending
117
+
118
+ export function pinaAmmProgram() {
119
+ return <T extends PinaAmmPluginRequirements>(client: T): ExtendedClient<T, { pinaAmm: PinaAmmPlugin }> => {
120
+ return extendClient(client, { pinaAmm: <PinaAmmPlugin>{ accounts: { ammConfig: addSelfFetchFunctions(client, getAmmConfigCodec()), pool: addSelfFetchFunctions(client, getPoolCodec()) }, instructions: {
121
+ migrate: (input: MigrateInput) =>
122
+ addSelfPlanAndSendFunctions(client, getMigrateInstruction(input)),createConfig: input => addSelfPlanAndSendFunctions(client, getCreateConfigInstruction(input)), updateConfig: input => addSelfPlanAndSendFunctions(client, getUpdateConfigInstruction(input)), createPool: input => addSelfPlanAndSendFunctions(client, getCreatePoolInstructionAsync(input)), deposit: input => addSelfPlanAndSendFunctions(client, getDepositInstruction(input)), withdraw: input => addSelfPlanAndSendFunctions(client, getWithdrawInstruction(input)), swapExactIn: input => addSelfPlanAndSendFunctions(client, getSwapExactInInstruction(input)), swapExactOut: input => addSelfPlanAndSendFunctions(client, getSwapExactOutInstruction(input)), collectProtocolFees: input => addSelfPlanAndSendFunctions(client, getCollectProtocolFeesInstruction(input)), collectCreatorFees: input => addSelfPlanAndSendFunctions(client, getCollectCreatorFeesInstruction(input)), setPoolCreator: input => addSelfPlanAndSendFunctions(client, getSetPoolCreatorInstruction(input)), syncPool: input => addSelfPlanAndSendFunctions(client, getSyncPoolInstruction(input)) }, pdas: { ammConfig: findAmmConfigPda, pool: findPoolPda, poolVault: findPoolVaultPda, poolLpMint: findPoolLpMintPda }, identifyAccount: identifyPinaAmmAccount, identifyInstruction: identifyPinaAmmInstruction, parseInstruction: parsePinaAmmInstruction } });
123
+ };
124
+ }
package/src/index.ts ADDED
@@ -0,0 +1,11 @@
1
+ /**
2
+ * TypeScript client for the [Pina AMM](https://github.com/pina-rs/amm).
3
+ *
4
+ * Everything under `./generated` is rendered from the program's IDL by
5
+ * `pina generate`; regenerate it instead of editing it. Decoders check
6
+ * discriminators and schema versions only, so compare an account's owner with
7
+ * `PINA_AMM_PROGRAM_ADDRESS` before trusting decoded data.
8
+ *
9
+ * @packageDocumentation
10
+ */
11
+ export * from "./generated";
package/CHANGELOG.md DELETED
@@ -1,5 +0,0 @@
1
- # Changelog
2
-
3
- ## 0.0.0
4
-
5
- Placeholder.